From 0b580cc91d7ea8959c3279b6b00fbd0d520df210 Mon Sep 17 00:00:00 2001 From: Antonio Lobato Date: Fri, 9 Feb 2024 19:56:16 -0800 Subject: [PATCH] New Search Experience Part 1 (#95) * Added new search experience via key binds. --- BetterBags.toc | 1 + BetterBags_Vanilla.toc | 1 + BetterBags_Wrath.toc | 1 + Bindings.xml | 5 ++ animations/fade.lua | 19 ++++-- core/boot.lua | 2 + core/hooks.lua | 6 +- core/init.lua | 5 +- frames/bag.lua | 37 +++------- frames/classic/bag.lua | 39 +++-------- frames/classic/item.lua | 8 ++- frames/search.lua | 117 ++++++++++++++++++++++++++++++++ templates/classic/container.xml | 73 ++++++++++++++++++++ templates/container.xml | 8 +-- 14 files changed, 247 insertions(+), 75 deletions(-) create mode 100644 Bindings.xml create mode 100644 frames/search.lua diff --git a/BetterBags.toc b/BetterBags.toc index 71ba9e96..ac5e9283 100644 --- a/BetterBags.toc +++ b/BetterBags.toc @@ -51,6 +51,7 @@ util\resize.lua util\sort.lua util\bucket.lua +frames\search.lua frames\slider.lua frames\money.lua frames\context.lua diff --git a/BetterBags_Vanilla.toc b/BetterBags_Vanilla.toc index 0694c5b2..00ccc9ec 100644 --- a/BetterBags_Vanilla.toc +++ b/BetterBags_Vanilla.toc @@ -52,6 +52,7 @@ util\resize.lua util\sort.lua util\bucket.lua +frames\search.lua frames\slider.lua frames\money.lua frames\classic\money.lua diff --git a/BetterBags_Wrath.toc b/BetterBags_Wrath.toc index e007e819..cd202f71 100644 --- a/BetterBags_Wrath.toc +++ b/BetterBags_Wrath.toc @@ -52,6 +52,7 @@ util\resize.lua util\sort.lua util\bucket.lua +frames\search.lua frames\slider.lua frames\money.lua frames\classic\money.lua diff --git a/Bindings.xml b/Bindings.xml new file mode 100644 index 00000000..fbacc582 --- /dev/null +++ b/Bindings.xml @@ -0,0 +1,5 @@ + + + BetterBags_ToggleSearch() + + \ No newline at end of file diff --git a/animations/fade.lua b/animations/fade.lua index 87a4fe5f..adfbcac8 100644 --- a/animations/fade.lua +++ b/animations/fade.lua @@ -7,8 +7,9 @@ local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) local animations = addon:NewModule('Animations') ---@param region Region +---@param nohide? boolean ---@return AnimationGroup, AnimationGroup -function animations:AttachFadeGroup(region) +function animations:AttachFadeGroup(region, nohide) local fadeInGroup = region:CreateAnimationGroup() local fadeIn = fadeInGroup:CreateAnimation('Alpha') fadeIn:SetFromAlpha(0) @@ -31,15 +32,20 @@ function animations:AttachFadeGroup(region) fadeOut:SetDuration(0.10) fadeOut:SetSmoothing('IN') fadeOutGroup:SetScript('OnFinished', function() - region:Hide() + if not nohide then + region:Hide() + else + region:SetAlpha(0) + end end) return fadeInGroup, fadeOutGroup end ---@param region Region +---@param nohide? boolean ---@return AnimationGroup, AnimationGroup -function animations:AttachFadeAndSlideLeft(region) - local fadeInGroup, fadeOutGroup = self:AttachFadeGroup(region) +function animations:AttachFadeAndSlideLeft(region, nohide) + local fadeInGroup, fadeOutGroup = self:AttachFadeGroup(region, nohide) local slideOut = fadeOutGroup:CreateAnimation('Translation') slideOut:SetOffset(10, 0) slideOut:SetDuration(0.10) @@ -48,9 +54,10 @@ function animations:AttachFadeAndSlideLeft(region) end ---@param region Region +---@param nohide? boolean ---@return AnimationGroup, AnimationGroup -function animations:AttachFadeAndSlideTop(region) - local fadeInGroup, fadeOutGroup = self:AttachFadeGroup(region) +function animations:AttachFadeAndSlideTop(region, nohide) + local fadeInGroup, fadeOutGroup = self:AttachFadeGroup(region, nohide) local slideOut = fadeOutGroup:CreateAnimation('Translation') slideOut:SetOffset(0, -10) slideOut:SetDuration(0.10) diff --git a/core/boot.lua b/core/boot.lua index 489efa92..ddcf580a 100644 --- a/core/boot.lua +++ b/core/boot.lua @@ -7,3 +7,5 @@ local addonName, root = ... --[[@type string, table]] local addon = LibStub("AceAddon-3.0"):NewAddon(root, addonName, 'AceHook-3.0') addon:SetDefaultModuleState(false) + +BINDING_NAME_BETTERBAGS_TOGGLESEARCH = "Search Bags" \ No newline at end of file diff --git a/core/hooks.lua b/core/hooks.lua index 5fe09685..c77b745c 100644 --- a/core/hooks.lua +++ b/core/hooks.lua @@ -8,6 +8,9 @@ local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) ---@class Debug: AceModule local debug = addon:GetModule('Debug') +---@class Events: AceModule +local events = addon:GetModule('Events') + addon.backpackShouldOpen = false addon.backpackShouldClose = false @@ -28,12 +31,10 @@ function addon.OnUpdate() debug:Log('Hooks', 'OnUpdate', addon.backpackShouldOpen, addon.backpackShouldClose) addon.backpackShouldOpen = false addon.backpackShouldClose = false - addon.ForceShowBlizzardBags() addon.Bags.Backpack:Show() elseif addon.backpackShouldClose then debug:Log('Hooks', 'OnUpdate', addon.backpackShouldOpen, addon.backpackShouldClose) addon.backpackShouldClose = false - addon.ForceHideBlizzardBags() addon.Bags.Backpack:Hide() end end @@ -105,6 +106,7 @@ function addon:CloseSpecialWindows(interactingFrame) addon.backpackShouldClose = true addon.Bags.Bank:Hide() addon.Bags.Bank:SwitchToBank() + events:SendMessage('addon/CloseSpecialWindows') CloseBankFrame() end diff --git a/core/init.lua b/core/init.lua index 59863330..057def71 100644 --- a/core/init.lua +++ b/core/init.lua @@ -44,6 +44,9 @@ local config = addon:GetModule('Config') ---@class Config: AceModule local currency = addon:GetModule('Currency') +---@class Search: AceModule +local search = addon:GetModule('Search') + ---@class Debug: AceModule local debug = addon:GetModule('Debug') @@ -110,8 +113,8 @@ function addon:OnEnable() config:Enable() categories:Enable() currency:Enable() + search:Enable() self:HideBlizzardBags() - addon.Bags.Backpack = BagFrame:Create(const.BAG_KIND.BACKPACK) addon.Bags.Bank = BagFrame:Create(const.BAG_KIND.BANK) diff --git a/frames/bag.lua b/frames/bag.lua index 63cef4c0..df0b7388 100644 --- a/frames/bag.lua +++ b/frames/bag.lua @@ -55,6 +55,9 @@ local Window = LibStub('LibWindow-1.1') ---@class Currency: AceModule local currency = addon:GetModule('Currency') +---@class Search: AceModule +local search = addon:GetModule('Search') + ------- --- Bag Prototype ------- @@ -91,6 +94,7 @@ function bagFrame.bagProto:Show() if self.frame:IsShown() then return end + addon.ForceShowBlizzardBags() PlaySound(self.kind == const.BAG_KIND.BANK and SOUNDKIT.IG_MAINMENU_OPEN or SOUNDKIT.IG_BACKPACK_OPEN) self.frame:Show() end @@ -99,6 +103,7 @@ function bagFrame.bagProto:Hide() if not self.frame:IsShown() then return end + addon.ForceHideBlizzardBags() PlaySound(self.kind == const.BAG_KIND.BANK and SOUNDKIT.IG_MAINMENU_CLOSE or SOUNDKIT.IG_BACKPACK_CLOSE) self.frame:Hide() if self.drawOnClose and self.kind == const.BAG_KIND.BACKPACK then @@ -206,7 +211,7 @@ function bagFrame.bagProto:Draw(dirtyItems) views:ListView(self, dirtyItems) end self.frame:SetScale(database:GetBagSizeInfo(self.kind, database:GetBagView(self.kind)).scale / 100) - local text = self.frame.SearchBox:GetText() + local text = search:GetText() self:Search(text) self:KeepBagInBounds() end @@ -478,33 +483,9 @@ function bagFrame:Create(kind) slots.frame:Hide() b.slots = slots - -- Setup the search box events. - b.frame.SearchBox:SetAlpha(0) - b.frame.SearchBox:SetScript("OnEnter", function() - b.frame.SearchBox:SetAlpha(1) - end) - b.frame.SearchBox:SetScript("OnLeave", function() - if b.frame.SearchBox:HasFocus() then return end - if b.frame.SearchBox:GetText() ~= "" then return end - b.frame.SearchBox:SetAlpha(0) - end) - b.frame.SearchBox:SetScript("OnEditFocusGained", function() - b.frame.SearchBox:SetAlpha(1) - end) - b.frame.SearchBox:SetScript("OnEditFocusLost", function() - if b.frame.SearchBox:GetText() ~= "" then return end - b.frame.SearchBox:SetAlpha(0) - end) - - b.frame.SearchBox:SetScript("OnTextChanged", function() - local text = b.frame.SearchBox:GetText() - if text == "" or text == nil then - b.frame.SearchBox.Instructions:Show() - else - b.frame.SearchBox.Instructions:Hide() - end - b:Search(text) - end) + if kind == const.BAG_KIND.BACKPACK then + search:Create(b.frame) + end if kind == const.BAG_KIND.BACKPACK then local currencyFrame = currency:Create(b.frame) diff --git a/frames/classic/bag.lua b/frames/classic/bag.lua index a0f4faf6..7a8affa2 100644 --- a/frames/classic/bag.lua +++ b/frames/classic/bag.lua @@ -55,6 +55,9 @@ local Window = LibStub('LibWindow-1.1') ---@class Currency: AceModule local currency = addon:GetModule('Currency') +---@class Search: AceModule +local search = addon:GetModule('Search') + function bagFrame.bagProto:WipeFreeSlots() self.content:RemoveCell("freeBagSlots", self.freeBagSlotsButton) self.freeSlots:RemoveCell("freeBagSlots", self.freeBagSlotsButton) @@ -79,8 +82,8 @@ function bagFrame.bagProto:Draw(dirtyItems) views:ListView(self, dirtyItems) end self.frame:SetScale(database:GetBagSizeInfo(self.kind, database:GetBagView(self.kind)).scale / 100) - --local text = self.frame.SearchBox:GetText() - --self:Search(text) + local text = search:GetText() + self:Search(text) self:KeepBagInBounds() end @@ -269,35 +272,9 @@ function bagFrame:Create(kind) slots.frame:Hide() b.slots = slots - -- Setup the search box events. - --[[ - b.frame.SearchBox:SetAlpha(0) - b.frame.SearchBox:SetScript("OnEnter", function() - b.frame.SearchBox:SetAlpha(1) - end) - b.frame.SearchBox:SetScript("OnLeave", function() - if b.frame.SearchBox:HasFocus() then return end - if b.frame.SearchBox:GetText() ~= "" then return end - b.frame.SearchBox:SetAlpha(0) - end) - b.frame.SearchBox:SetScript("OnEditFocusGained", function() - b.frame.SearchBox:SetAlpha(1) - end) - b.frame.SearchBox:SetScript("OnEditFocusLost", function() - if b.frame.SearchBox:GetText() ~= "" then return end - b.frame.SearchBox:SetAlpha(0) - end) - - b.frame.SearchBox:SetScript("OnTextChanged", function() - local text = b.frame.SearchBox:GetText() - if text == "" or text == nil then - b.frame.SearchBox.Instructions:Show() - else - b.frame.SearchBox.Instructions:Hide() - end - b:Search(text) - end) - --]] + if kind == const.BAG_KIND.BACKPACK then + search:Create(b.frame) + end -- Enable dragging of the bag frame. b.frame:SetMovable(true) diff --git a/frames/classic/item.lua b/frames/classic/item.lua index 51beed79..3cec6dc3 100644 --- a/frames/classic/item.lua +++ b/frames/classic/item.lua @@ -48,7 +48,6 @@ local children = { "ItemContextOverlay" } - function itemFrame.itemProto:UpdateCooldown() ContainerFrame_UpdateCooldown(self.frame:GetID(), self.button) end @@ -237,6 +236,13 @@ function itemFrame:_DoCreate() i.button = button i.frame = p + button.SetMatchesSearch = function(me, match) + if match then + me.searchOverlay:Hide() + else + me.searchOverlay:Show() + end + end button.ItemSlotBackground = button:CreateTexture(nil, "BACKGROUND"); button.ItemSlotBackground:SetAllPoints(button) button.ItemSlotBackground:SetTexture([[Interface\PaperDoll\UI-Backpack-EmptySlot]]) diff --git a/frames/search.lua b/frames/search.lua new file mode 100644 index 00000000..b0ba655a --- /dev/null +++ b/frames/search.lua @@ -0,0 +1,117 @@ +local addonName = ... ---@type string + +---@class BetterBags: AceAddon +local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) + +---@class Animations: AceModule +local animations = addon:GetModule('Animations') + +---@class Events: AceModule +local events = addon:GetModule('Events') + +---@class Search: AceModule +---@field searchFrame SearchFrame +local search = addon:NewModule('Search') + +---@class (exact) SearchFrame +---@field frame Frame +---@field fadeInGroup AnimationGroup +---@field fadeOutGroup AnimationGroup +---@field textBox EditBox +---@field helpText FontString +search.searchProto = {} + +-- BetterBags_ToggleSearch toggles the search view. This function is used in the +-- search key bind. +function BetterBags_ToggleSearch() + search.searchFrame:Toggle() +end + +function search.searchProto:Toggle() + if self.frame:GetAlpha() > 0 then + self.textBox:ClearFocus() + self.fadeOutGroup:Play() + else + self.textBox:ClearFocus() + addon.Bags.Backpack:Show() + self.fadeInGroup:Play() + end +end + +function search.searchProto:Hide() + if self.frame:GetAlpha() > 0 then + self.textBox:ClearFocus() + self.fadeOutGroup:Play() + end +end + +function search.searchProto:UpdateSearch() + local text = self.textBox:GetText() + if text == "" then + self.helpText:Show() + else + self.helpText:Hide() + end + addon.Bags.Backpack:Search(text) + addon.Bags.Bank:Search(text) +end + +function search:GetText() + return self.searchFrame.textBox:GetText() +end + +---@param parent Frame +---@return SearchFrame +function search:Create(parent) + local sf = setmetatable({}, {__index = search.searchProto}) + local f = CreateFrame("Frame", "BetterBagsSearchFrame", UIParent, "BetterBagsSearchPanelTemplate") --[[@as Frame]] + f:SetSize(400, 75) + f:SetPoint("BOTTOM", parent, "TOP", 0, 10) + f:SetFrameStrata("HIGH") + f:SetFrameLevel(700) + f:SetAlpha(0) + f.Inset:Hide() + f:Show() + + local textBox = CreateFrame("EditBox", nil, f) --[[@as EditBox]] + textBox:SetFontObject("GameFontNormalHuge") + textBox:SetTextColor(1, 1, 1, 1) + textBox:SetParent(f) + textBox:SetPoint("TOPLEFT", f, "TOPLEFT", 10, 0) + textBox:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -10, 0) + textBox:ClearFocus() + textBox:SetAutoFocus(false) + textBox:SetJustifyH("CENTER") + textBox:SetScript("OnEscapePressed", function(me) + ---@cast me +EditBox + me:ClearFocus() + sf:Toggle() + end) + textBox:SetScript("OnTextChanged", function() + sf:UpdateSearch() + end) + + local helpText = textBox:CreateFontString("BetterBagsSearchHelpText", "ARTWORK", "GameFontDisableLarge") + helpText:SetPoint("CENTER", textBox, "CENTER", 0, 0) + helpText:SetText("Start typing to search your bags...") + helpText:Show() + sf.helpText = helpText + + sf.fadeInGroup, sf.fadeOutGroup = animations:AttachFadeAndSlideLeft(f, true) + sf.fadeInGroup:HookScript("OnFinished", function() + textBox:SetFocus() + end) + sf.fadeOutGroup:HookScript("OnFinished", function() + textBox:SetText("") + helpText:Show() + end) + + sf.frame = f + sf.textBox = textBox + search.searchFrame = sf + + events:RegisterMessage('addon/CloseSpecialWindows', function() + sf:Hide() + end) + return sf +end diff --git a/templates/classic/container.xml b/templates/classic/container.xml index 3b269d9a..67812ed1 100644 --- a/templates/classic/container.xml +++ b/templates/classic/container.xml @@ -6,4 +6,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/container.xml b/templates/container.xml index 2fdcd815..a5d05494 100644 --- a/templates/container.xml +++ b/templates/container.xml @@ -7,14 +7,10 @@