diff --git a/Cache.lua b/Cache.lua index eab8518..7cf460d 100644 --- a/Cache.lua +++ b/Cache.lua @@ -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, @@ -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 @@ -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) diff --git a/Localization.lua b/Localization.lua index 369e157..c1e54f8 100644 --- a/Localization.lua +++ b/Localization.lua @@ -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", @@ -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", diff --git a/WhatsTraining.lua b/WhatsTraining.lua index 34717b4..90a03fb 100644 --- a/WhatsTraining.lua +++ b/WhatsTraining.lua @@ -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() @@ -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 @@ -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 diff --git a/WhatsTrainingUI.lua b/WhatsTrainingUI.lua index 6b148ee..6f44af9 100644 --- a/WhatsTrainingUI.lua +++ b/WhatsTrainingUI.lua @@ -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