for SpellID, Name in pairs(SpellList) do
if strfind(Name, SearchSt) then
if ActiveButtons < PredictorLines then
-- fill in the next button
ActiveButtons = ActiveButtons + 1
else
break
end
end
...do this first to fill in a list of matches:
local matches = {}
for SpellID, Name in pairs(SpellList) do
if strfind(Name, SearchSt) then
matches[#matches+1] = SpellID
end
end
...and then update your buttons based on that + the scroll offset.
On a side note, you should use string.find instead of string.match in your search code -- when all you need to know is "does this string contain this other string?" it's almost twice as fast to find instead of match.
Also, your current code will show the matches in undefined order, so you may want to sort the matches by spell name before you update your buttons:
-- define once:
local function sortMatches(a, b)
return SpellList[a] < SpellList[b]
end
-- call later in search routine:
table.sort(matches, sortMatches)
You could also take advantage of the fact that string.find tells you where in the string the search term was found, and prioritize spells that start with the search term over spells that just contain the search term:
local matches, prioritize = {}, {}
for SpellID, Name in pairs(SpellList) do
local start = strfind(Name, SearchSt)
if start then
matches[#matches+1] = SpellID
prioritize[SpellID] = start == 1
end
end
local function sortMatches(a, b)
if prioritize[a] == prioritize[b] then
return SpellList[a] < SpellList[b]
else
return prioritize[a] and a or b
end
end
Just got back to this today. I made the changes for the matches. Looks a lot better sorted. But the scroller. This code uses aceGUI. So I assume the scrollbar, scroller is built in. Just not sure how to access it. Your code looks like its doing it from scratch.
But how do I do this in this code with aceGUI ?
Looks like this is not using aceGUI for the menu, but doing its self. I may be able to figure this out.
Got it all working. Heres a screen shot. The white spell means that my mod already saw that spell cast on me. So the player can easily pick their own buffs/debuffs. Scroll bar will hide if the menu is below 10 items. http://i219.photobucket.com/albums/cc28/Teyasio/SpellsList.jpg
Had to change lot of code. Now its an awesome spell selector.
Thanks
This was one part of the mod that really needed improving, really like the result.
Let me know if theres something I'm not doing right. Some parts use aceGUI that I dont fully understand. It works though.
This would be so much better if I could make it have a scrollbar in the pulldown. I tried this last year, but gave up. Couldn't figure it out.
http://pastebin.com/GRwhKeDA
Thanks
Creating:
https://github.com/Phanx/PhanxConfig-Dropdown/blob/master/PhanxConfig-Dropdown.lua#L271
Updating:
https://github.com/Phanx/PhanxConfig-Dropdown/blob/master/PhanxConfig-Dropdown.lua#L197
Then in your code, instead of doing this:
...do this first to fill in a list of matches:
...and then update your buttons based on that + the scroll offset.
On a side note, you should use string.find instead of string.match in your search code -- when all you need to know is "does this string contain this other string?" it's almost twice as fast to find instead of match.
Also, your current code will show the matches in undefined order, so you may want to sort the matches by spell name before you update your buttons:
You could also take advantage of the fact that string.find tells you where in the string the search term was found, and prioritize spells that start with the search term over spells that just contain the search term:
But how do I do this in this code with aceGUI ?
Looks like this is not using aceGUI for the menu, but doing its self. I may be able to figure this out.
Thanks
http://i219.photobucket.com/albums/cc28/Teyasio/SpellsList.jpg
Had to change lot of code. Now its an awesome spell selector.
Thanks
Updated code
http://pastebin.com/U0qd1bYb
This was one part of the mod that really needed improving, really like the result.
Let me know if theres something I'm not doing right. Some parts use aceGUI that I dont fully understand. It works though.