Skip to content

Commit

Permalink
search box
Browse files Browse the repository at this point in the history
  • Loading branch information
fusionpit committed Nov 30, 2024
1 parent 4807bb4 commit 5163cdc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function wt:CacheSpell(spell, level, done)
local formattedSubText = (subText and subText ~= "") and
format(PARENS_TEMPLATE, subText) or ""
local name = si:GetSpellName()
local formattedFullName = (subText and subText ~= "") and format("%s %s", name, formattedSubText) or name
local formattedFullName = (subText and subText ~= "") and format("%s %s", name, formattedSubText) or name
self.spellInfoCache[spell.id] = {
id = spell.id,
name = name,
Expand All @@ -37,6 +37,7 @@ function wt:CacheSpell(spell, level, done)
level = level,
formattedLevel = format(wt.L.LEVEL_FORMAT, level),
formattedFullName = formattedFullName,
searchText = strlower(formattedFullName),
}

if self.allRanksCache[name] == nil then
Expand Down Expand Up @@ -91,7 +92,8 @@ function wt:CacheItem(item, level, done)
formattedCost = GetCoinTextureString(item.cost),
level = level,
formattedLevel = format(wt.L.LEVEL_FORMAT, level),
isItem = true
isItem = true,
searchText = strlower(ii:GetItemName())
}
done(false)
end)
Expand Down
5 changes: 4 additions & 1 deletion Localization.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ local localeText = {
BROKER_NOTHING = "Nothing left to learn!",
BROKER_CLICK_BEAST_TRAIN = "Hint: Shift-Click to open the Beast Training UI",
BROKER_CLICK_OPEN = "Hint: Click to open spellbook.",
BROKER_OPEN_IN_COMBAT = "Can't open spellbook while in combat",
OPEN_BEAST_IN_COMBAT = "Can't open Beast Training while in combat",
LEVEL_FORMAT = "Level %s",
TAB_TEXT = "What can I train?",
OPEN_BEAST_TRAINING = "Please open the Beast Training UI",
Expand All @@ -29,7 +31,8 @@ local localeText = {
NEW_IGNORE_FEATURE = "Right-click to ignore abilities",
CLICK_TO_DISMISS = "Click header to dismiss",
IGNORED_TT = "Ignored",
IGNORE_ALL_TT = "Ignore all ranks"
IGNORE_ALL_TT = "Ignore all ranks",
SEARCH_NO_RESULTS = "No results found"
},
frFR = {
AVAILABLE_HEADER = "Disponible",
Expand Down
16 changes: 15 additions & 1 deletion WhatsTraining.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ brokerCategories:Initialize()

wt.data = {}
wt.brokerData = {}
wt.filter = ''
local function matchesFilter(spellOrItem)
if wt.filter == '' then return true end
return strfind(spellOrItem, wt.filter, 1, true)
end
local function rebuildData(playerLevel, isLevelUpEvent)
categories:ClearSpells()
brokerCategories:ClearSpells()
Expand Down Expand Up @@ -203,7 +208,9 @@ local function rebuildData(playerLevel, isLevelUpEvent)
end
categoryKey = hasReqs and AVAILABLE_KEY or MISSINGREQS_KEY
end
categories:Insert(categoryKey, spellInfo)
if matchesFilter(spellInfo.searchText) then
categories:Insert(categoryKey, spellInfo)
end
brokerCategories:Insert(categoryKey, spellInfo)
end
end
Expand Down Expand Up @@ -284,6 +291,13 @@ local function rebuildData(playerLevel, isLevelUpEvent)
category.cost = totalCost
end
end
if #wt.data == 0 and wt.filter ~= '' then
tinsert(wt.data, {
formattedName = wt.L.SEARCH_NO_RESULTS,
isHeader = true,
cost = 0
})
end
local brokerAvailable = 0
local brokerComing = 0
for _, category in ipairs(brokerCategories) do
Expand Down
12 changes: 12 additions & 0 deletions WhatsTrainingUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ function wt.CreateFrame()
right:SetWidth(128)
right:SetHeight(512)
right:SetPoint("TOPRIGHT", mainFrame)
if not hasNewSpellbook then
local search = CreateFrame("EditBox", "$parentSearchBox", mainFrame, "SearchBoxTemplate")
search:SetWidth(124)
search:SetHeight(32)
search:SetPoint("TOPLEFT", mainFrame, "TOPLEFT", 81, -34)
search:SetScript("OnTextChanged", function (self)
SearchBoxTemplate_OnTextChanged(self)
local oldFilter = wt.filter
wt.filter = strlower(self:GetText())
if wt.filter ~= oldFilter then wt:RebuildData() end
end)
end
mainFrame:Hide()

if (hasNewSpellbook) then
Expand Down

0 comments on commit 5163cdc

Please sign in to comment.