Skip to content

Commit

Permalink
Search Expanded (again!) (#212)
Browse files Browse the repository at this point in the history
* Added optional in-bag search for bank and bag.

* Fixed a few bugs around categories not refreshing for bags.
  • Loading branch information
Cidan authored Feb 23, 2024
1 parent 131d922 commit 5b182aa
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 12 deletions.
14 changes: 14 additions & 0 deletions config/classic/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ function config:GetGeneralOptions()
name = L:G("General"),
order = 0,
args = {
inBagSearch = {
type = "toggle",
width = "full",
order = 0,
name = L:G("Enable In-Bag Search"),
desc = L:G("If enabled, a search bar will appear at the top of your bags."),
get = function()
return DB:GetInBagSearch()
end,
set = function(_, value)
DB:SetInBagSearch(value)
events:SendMessage('search/SetInFrame', value)
end,
},
newItemTime = {
type = "range",
order = 2,
Expand Down
18 changes: 16 additions & 2 deletions config/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,24 @@ function config:GetGeneralOptions()
name = L:G("General"),
order = 0,
args = {
inBagSearch = {
type = "toggle",
width = "full",
order = 0,
name = L:G("Enable In-Bag Search"),
desc = L:G("If enabled, a search bar will appear at the top of your bags."),
get = function()
return DB:GetInBagSearch()
end,
set = function(_, value)
DB:SetInBagSearch(value)
events:SendMessage('search/SetInFrame', value)
end,
},
showBagButton = {
type = "toggle",
width = "full",
order = 1,
order = 2,
name = L:G("Show Blizzard Bag Button"),
desc = L:G("Show or hide the default Blizzard bag button."),
get = DB.GetShowBagButton,
Expand All @@ -84,7 +98,7 @@ function config:GetGeneralOptions()
},
newItemTime = {
type = "range",
order = 2,
order = 3,
name = L:G("New Item Duration"),
desc = L:G("The time, in minutes, to consider an item a new item."),
min = 0,
Expand Down
4 changes: 2 additions & 2 deletions config/itemlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local function SetList(self, values)
local list = self:GetUserData("values")
DB:SaveItemToCategory(itemid, list.name)
self:SetList(DB:GetItemCategory(list.name))
items:RefreshAll()
items:FullRefreshAll()
end

if #itemList == 0 then
Expand Down Expand Up @@ -108,7 +108,7 @@ local function SetList(self, values)
local list = self:GetUserData("values")
DB:DeleteItemFromCategory(v.itemInfo.itemID, list.name)
self:SetList(DB:GetItemCategory(list.name))
items:RefreshAll()
items:FullRefreshAll()
end
}})
end
Expand Down
1 change: 1 addition & 0 deletions core/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ const.DATABASE_DEFAULTS = {
enabled = true,
showBagButton = true,
debug = false,
inBagSearch = false,
itemLevel = {
[const.BAG_KIND.BACKPACK] = {
enabled = true,
Expand Down
10 changes: 10 additions & 0 deletions core/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ function DB:GetDebugMode()
return DB.data.profile.debug
end

---@param enabled boolean
function DB:SetInBagSearch(enabled)
DB.data.profile.inBagSearch = enabled
end

---@return boolean
function DB:GetInBagSearch()
return DB.data.profile.inBagSearch
end

function DB:Migrate()
--[[
Migration of the custom category filters from single filter to per-bag filter.
Expand Down
4 changes: 2 additions & 2 deletions data/categories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ end
function categories:DeleteCategory(category)
database:DeleteItemCategory(category)
events:SendMessage('categories/Changed')
items:RefreshAll()
items:FullRefreshAll()
end

-- GetCustomCategory returns the custom category for an item, or nil if it doesn't have one.
Expand Down Expand Up @@ -177,5 +177,5 @@ end
-- reprocessed and re-categorized.
function categories:ReprocessAllItems()
wipe(self.itemsWithNoCategory)
items:RefreshAll()
items:FullRefreshAll()
end
40 changes: 37 additions & 3 deletions frames/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ local search = addon:GetModule('Search')
---@field toRelease Item[]
---@field toReleaseSections Section[]
---@field views table<BagView, view>
---@field searchBox SearchFrame
bagFrame.bagProto = {}

function bagFrame.bagProto:Show()
Expand Down Expand Up @@ -240,14 +241,24 @@ function bagFrame.bagProto:ToggleReagentBank()
self.isReagentBank = not self.isReagentBank
if self.isReagentBank then
BankFrame.selectedTab = 2
self.frame:SetTitle(L:G("Reagent Bank"))
if self.searchBox.frame:IsShown() then
self.frame:SetTitle("")
self.searchBox.helpText:SetText(L:G("Search Reagent Bank"))
else
self.frame:SetTitle(L:G("Reagent Bank"))
end
self.currentItemCount = -1
--self:ClearRecentItems()
self:Wipe()
items:RefreshReagentBank()
else
BankFrame.selectedTab = 1
self.frame:SetTitle(L:G("Bank"))
if self.searchBox.frame:IsShown() then
self.frame:SetTitle("")
self.searchBox.helpText:SetText(L:G("Search Bank"))
else
self.frame:SetTitle(L:G("Bank"))
end
self.currentItemCount = -1
--self:ClearRecentItems()
self:Wipe()
Expand All @@ -259,7 +270,12 @@ function bagFrame.bagProto:SwitchToBank()
if self.kind == const.BAG_KIND.BACKPACK then return end
self.isReagentBank = false
BankFrame.selectedTab = 1
self.frame:SetTitle(L:G("Bank"))
if self.searchBox.frame:IsShown() then
self.frame:SetTitle("")
self.searchBox.helpText:SetText(L:G("Search Bank"))
else
self.frame:SetTitle(L:G("Bank"))
end
self:Wipe()
end

Expand Down Expand Up @@ -429,6 +445,15 @@ function bagFrame:Create(kind)
search:Create(b.frame)
end

local searchBox = search:CreateBox(kind, b.frame)
searchBox.frame:SetPoint("TOP", b.frame, "TOP", 0, -2)
searchBox.frame:SetSize(150, 20)
if database:GetInBagSearch() then
searchBox.frame:Show()
b.frame:SetTitle("")
end
b.searchBox = searchBox

if kind == const.BAG_KIND.BACKPACK then
local currencyFrame = currency:Create(b.frame)
currencyFrame:Hide()
Expand Down Expand Up @@ -464,5 +489,14 @@ function bagFrame:Create(kind)
events:BucketEvent('BAG_UPDATE_COOLDOWN',function(_) b:OnCooldown() end)
end

events:RegisterMessage('search/SetInFrame', function (_, shown)
if shown then
b.searchBox.frame:Show()
b.frame:SetTitle("")
else
b.searchBox.frame:Hide()
b.frame:SetTitle(L:G(kind == const.BAG_KIND.BACKPACK and "Backpack" or "Bank"))
end
end)
return b
end
18 changes: 18 additions & 0 deletions frames/classic/bag.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ function bagFrame:Create(kind)
search:Create(b.frame)
end

local searchBox = search:CreateBox(kind, b.frame)
searchBox.frame:SetPoint("TOP", b.frame, "TOP", 0, -2)
searchBox.frame:SetSize(150, 20)
if database:GetInBagSearch() then
searchBox.frame:Show()
b.frame:SetTitle("")
end
b.searchBox = searchBox

-- Enable dragging of the bag frame.
b.frame:SetMovable(true)
b.frame:EnableMouse(true)
Expand Down Expand Up @@ -259,5 +268,14 @@ function bagFrame:Create(kind)
events:BucketEvent('BAG_UPDATE_COOLDOWN',function(_) b:OnCooldown() end)
end

events:RegisterMessage('search/SetInFrame', function (_, shown)
if shown then
b.searchBox.frame:Show()
b.frame:SetTitle("")
else
b.searchBox.frame:Hide()
b.frame:SetTitle(L:G(kind == const.BAG_KIND.BACKPACK and "Backpack" or "Bank"))
end
end)
return b
end
3 changes: 2 additions & 1 deletion frames/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ local function matchFilter(filter, data)
-- If no prefix is provided, assume the filter is a name or type filter.
if value == nil then
if
data.itemInfo.itemName and (
string.find(data.itemInfo.itemName:lower(), prefix, 1, true) or
string.find(data.itemInfo.itemType:lower(), prefix, 1, true) or
string.find(data.itemInfo.itemSubType:lower(), prefix, 1, true) then
string.find(data.itemInfo.itemSubType:lower(), prefix, 1, true)) then
return true
end
return false
Expand Down
52 changes: 50 additions & 2 deletions frames/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ local animations = addon:GetModule('Animations')
---@class Events: AceModule
local events = addon:GetModule('Events')

---@class Constants: AceModule
local const = addon:GetModule('Constants')

---@class Search: AceModule
---@field searchFrame SearchFrame
local search = addon:NewModule('Search')
Expand All @@ -19,6 +22,7 @@ local search = addon:NewModule('Search')
---@field fadeOutGroup AnimationGroup
---@field textBox EditBox
---@field helpText FontString
---@field kind BagKind
search.searchProto = {}

-- BetterBags_ToggleSearch toggles the search view. This function is used in the
Expand Down Expand Up @@ -53,8 +57,16 @@ function search.searchProto:UpdateSearch()
else
self.helpText:Hide()
end
addon.Bags.Backpack:Search(text)
addon.Bags.Bank:Search(text)
if self.kind ~= nil then
if self.kind == const.BAG_KIND.BACKPACK then
addon.Bags.Backpack:Search(text)
else
addon.Bags.Bank:Search(text)
end
else
addon.Bags.Backpack:Search(text)
addon.Bags.Bank:Search(text)
end
end

function search:GetText()
Expand Down Expand Up @@ -116,3 +128,39 @@ function search:Create(parent)
end)
return sf
end

---@param kind BagKind
---@param parent Frame
---@return SearchFrame
function search:CreateBox(kind, parent)
local sf = setmetatable({}, {__index = search.searchProto})
sf.frame = CreateFrame("Frame", nil, parent) --[[@as Frame]]
sf.frame:SetFrameLevel(2000)
local textBox = CreateFrame("EditBox", nil, sf.frame, "BagSearchBoxTemplate") --[[@as SearchBox]]
textBox:SetFontObject("GameFontNormal")
textBox:SetTextColor(1, 1, 1, 1)
textBox:ClearFocus()
textBox:SetAutoFocus(false)
textBox:SetJustifyH("LEFT")
textBox:SetScript("OnEscapePressed", function(me)
---@cast me +EditBox
me:ClearFocus()
end)
textBox:SetScript("OnTextChanged", function()
sf:UpdateSearch()
end)
textBox:SetAllPoints()

sf.kind = kind
sf.helpText = textBox.Instructions
sf.textBox = textBox
if kind == const.BAG_KIND.BACKPACK then
sf.helpText:SetText("Search Backpack")
else
sf.helpText:SetText("Search Bank")
end
sf.helpText:ClearAllPoints()
sf.helpText:SetPoint("CENTER")
sf.frame:Hide()
return sf
end

0 comments on commit 5b182aa

Please sign in to comment.