Skip to content

Commit

Permalink
New Search Experience Part 1 (#95)
Browse files Browse the repository at this point in the history
* Added new search experience via key binds.
  • Loading branch information
Cidan authored Feb 10, 2024
1 parent ae630bf commit 0b580cc
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 75 deletions.
1 change: 1 addition & 0 deletions BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions BetterBags_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions BetterBags_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Bindings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Bindings>
<Binding name="BETTERBAGS_TOGGLESEARCH" category="BetterBags">
BetterBags_ToggleSearch()
</Binding>
</Bindings>
19 changes: 13 additions & 6 deletions animations/fade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 4 additions & 2 deletions core/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)

Expand Down
37 changes: 9 additions & 28 deletions frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 8 additions & 31 deletions frames/classic/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion frames/classic/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ local children = {
"ItemContextOverlay"
}


function itemFrame.itemProto:UpdateCooldown()
ContainerFrame_UpdateCooldown(self.frame:GetID(), self.button)
end
Expand Down Expand Up @@ -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]])
Expand Down
Loading

0 comments on commit 0b580cc

Please sign in to comment.