fixed mystic enchants search thingy (#6)

* fixed RE search in player bags

* mystic enchants can also be searched in guildbank
This commit is contained in:
Matthew Rodrigues
2023-02-13 03:51:53 +00:00
committed by GitHub
parent 06a5c77a47
commit 4fe6ff79c3
2 changed files with 87 additions and 100 deletions
+50 -77
View File
@@ -2,7 +2,6 @@
item.lua item.lua
An item slot button An item slot button
--]] --]]
local Bagnon = LibStub('AceAddon-3.0'):GetAddon('Bagnon') local Bagnon = LibStub('AceAddon-3.0'):GetAddon('Bagnon')
local ItemSlot = Bagnon.Classy:New('Button') local ItemSlot = Bagnon.Classy:New('Button')
ItemSlot:Hide() ItemSlot:Hide()
@@ -10,16 +9,15 @@ Bagnon.ItemSlot = ItemSlot
local ItemSearch = LibStub('LibItemSearch-1.0') local ItemSearch = LibStub('LibItemSearch-1.0')
local function hasBlizzQuestHighlight() local function hasBlizzQuestHighlight()
return GetContainerItemQuestInfo and true or false return GetContainerItemQuestInfo and true or false
end end
--[[ --[[
The item widget The item widget
--]] --]]
--[[ ItemSlot Constructor ]]
--
--[[ ItemSlot Constructor ]]--
function ItemSlot:New(bag, slot, frameID, parent) function ItemSlot:New(bag, slot, frameID, parent)
local item = self:Restore() or self:Create() local item = self:Restore() or self:Create()
@@ -83,7 +81,7 @@ function ItemSlot:GetBlizzardItemSlot(id)
end end
local bag = math.ceil(id / MAX_CONTAINER_ITEMS) local bag = math.ceil(id / MAX_CONTAINER_ITEMS)
local slot = (id-1) % MAX_CONTAINER_ITEMS + 1 local slot = (id - 1) % MAX_CONTAINER_ITEMS + 1
local item = _G[format('ContainerFrame%dItem%d', bag, slot)] local item = _G[format('ContainerFrame%dItem%d', bag, slot)]
if item then if item then
@@ -118,7 +116,8 @@ end
--[[ ItemSlot Destructor ]]-- --[[ ItemSlot Destructor ]]
--
function ItemSlot:Free() function ItemSlot:Free()
self:Hide() self:Hide()
@@ -130,8 +129,8 @@ function ItemSlot:Free()
ItemSlot.unused[self] = true ItemSlot.unused[self] = true
end end
--[[ Events ]]
--[[ Events ]]-- --
function ItemSlot:ITEM_SLOT_UPDATE(msg, bag, slot) function ItemSlot:ITEM_SLOT_UPDATE(msg, bag, slot)
self:Update() self:Update()
@@ -194,8 +193,8 @@ function ItemSlot:HandleEvent(msg, ...)
end end
end end
--[[ Frame Events ]]
--[[ Frame Events ]]-- --
function ItemSlot:OnShow() function ItemSlot:OnShow()
self:Update() self:Update()
@@ -246,8 +245,8 @@ function ItemSlot:OnLeave()
ResetCursor() ResetCursor()
end end
--[[ Update Methods ]]
--[[ Update Methods ]]-- --
-- Update the texture, lock status, and other information about an item -- Update the texture, lock status, and other information about an item
@@ -344,52 +343,29 @@ function ItemSlot:SetLocked(locked)
SetItemButtonDesaturated(self, locked) SetItemButtonDesaturated(self, locked)
end end
function ItemSlot:UpdateMEName()
local reTooltip = CreateFrame("GameTooltip", "BagNonItemListREInspectTooltip", UIParent, "GameTooltipTemplate")
-- TODO: Nihilianth: This change does not affect guild bank search. Also tooltips in guild bank are not colored properly
function ItemSlot:UpdateREName()
local itemLink = self:GetItem() local itemLink = self:GetItem()
if itemLink and reTooltip then if itemLink then
self.MEName = strlower(GetREData(GetREInSlot(self:GetBag(), self:GetID()))['spellName'])
local tooltip = reTooltip return
tooltip:ClearLines() end
tooltip:SetOwner(self:GetParent(), "ANCHOR_NONE")
if self:GetBag() == -1 then
tooltip:SetInventoryItem("player", BankButtonIDToInvSlotID(self:GetID()))
else
tooltip:SetBagItem(self:GetBag(), self:GetID())
end
for line = 1, tooltip:NumLines() do
local ttLine = _G[tooltip:GetName() .. "TextLeft" .. line]
local text = ttLine:GetText()
if text and string.find(text, "Equip:") then
local descStart = text:find("( )(\-)( )")
if descStart then
self.reName = string.lower(text:sub(7, descStart - 1))
return
end
end
end
-- reTooltip:Hide()
end --else print("no item link") end
end end
function ItemSlot:UpdateLocked() function ItemSlot:UpdateLocked()
if self:IsLocked() then if self:IsLocked() then
self.reName = "" self.MEName = ""
else else
self:UpdateREName() self:UpdateMEName()
end end
self:SetLocked(self:IsLocked()) self:SetLocked(self:IsLocked())
end end
--returns true if the slot is locked, and false otherwise -- returns true if the slot is locked, and false otherwise
function ItemSlot:IsLocked() function ItemSlot:IsLocked()
return Bagnon.ItemSlotInfo:IsLocked(self:GetPlayer(), self:GetBag(), self:GetID()) return Bagnon.ItemSlotInfo:IsLocked(self:GetPlayer(), self:GetBag(), self:GetID())
end end
--colors the item border based on the quality of the item. hides it for common/poor items -- colors the item border based on the quality of the item. hides it for common/poor items
if hasBlizzQuestHighlight() then if hasBlizzQuestHighlight() then
function ItemSlot:SetBorderQuality(quality) function ItemSlot:SetBorderQuality(quality)
local border = self.border local border = self.border
@@ -486,19 +462,16 @@ function ItemSlot:AnchorTooltip()
end end
--search --search
function ItemSlot:UpdateSearch() function ItemSlot:UpdateSearch()
local shouldFade = false local shouldFade = false
local search = self:GetItemSearch() local search = self:GetItemSearch()
if search and search ~= '' then if search and search ~= '' then
local itemLink = self:GetItem() local itemLink = self:GetItem()
shouldFade = not(itemLink and (ItemSearch:Find(itemLink, search))) shouldFade = not (itemLink and (ItemSearch:Find(itemLink, search)))
if self.reName and string.find(self.reName, string.lower(search)) then if self.MEName and string.find(self.MEName, string.lower(search)) then
shouldFade = false shouldFade = false
end end
end end
if shouldFade then if shouldFade then
@@ -531,9 +504,8 @@ function ItemSlot:GetBagSearch()
return self:GetSettings():GetBagSearch() return self:GetSettings():GetBagSearch()
end end
--[[ Accessor Methods ]]
--
--[[ Accessor Methods ]]--
function ItemSlot:SetFrameID(frameID) function ItemSlot:SetFrameID(frameID)
if self:GetFrameID() ~= frameID then if self:GetFrameID() ~= frameID then
@@ -580,12 +552,13 @@ function ItemSlot:AtBank()
end end
function ItemSlot:GetItemSlotInfo() function ItemSlot:GetItemSlotInfo()
local texture, count, locked, quality, readable, lootable, link = Bagnon.ItemSlotInfo:GetItemInfo(self:GetPlayer(), self:GetBag(), self:GetID()) local texture, count, locked, quality, readable, lootable, link = Bagnon.ItemSlotInfo:GetItemInfo(self:GetPlayer(),
self:GetBag(), self:GetID())
return texture, count, locked, quality, readable, lootable, link return texture, count, locked, quality, readable, lootable, link
end end
--[[ Item Type Highlighting ]]
--[[ Item Type Highlighting ]]-- --
function ItemSlot:HighlightingItemsByQuality() function ItemSlot:HighlightingItemsByQuality()
return Bagnon.Settings:HighlightingItemsByQuality() return Bagnon.Settings:HighlightingItemsByQuality()
@@ -599,8 +572,8 @@ function ItemSlot:GetHighlightAlpha()
return Bagnon.Settings:GetHighlightOpacity() return Bagnon.Settings:GetHighlightOpacity()
end end
--returns true if the item is a quest item or not -- returns true if the item is a quest item or not
--in 3.3, includes a second return to determine if the item is a quest starter for a quest the player lacks -- in 3.3, includes a second return to determine if the item is a quest starter for a quest the player lacks
local QUEST_ITEM_SEARCH = string.format('t:%s|%s', select(12, GetAuctionItemClasses()), 'quest') local QUEST_ITEM_SEARCH = string.format('t:%s|%s', select(12, GetAuctionItemClasses()), 'quest')
if hasBlizzQuestHighlight() then if hasBlizzQuestHighlight() then
@@ -629,7 +602,8 @@ else
end end
--[[ Item Slot Coloring ]]-- --[[ Item Slot Coloring ]]
--
function ItemSlot:IsAmmoBagSlot() function ItemSlot:IsAmmoBagSlot()
return Bagnon.BagSlotInfo:IsAmmoBag(self:GetPlayer(), self:GetBag()) return Bagnon.BagSlotInfo:IsAmmoBag(self:GetPlayer(), self:GetBag())
@@ -667,15 +641,15 @@ function ItemSlot:ColoringBagSlots()
return Bagnon.Settings:ColoringBagSlots() return Bagnon.Settings:ColoringBagSlots()
end end
--[[ Empty Slot Visibility ]]
--[[ Empty Slot Visibility ]]-- --
function ItemSlot:ShowingEmptyItemSlotTexture() function ItemSlot:ShowingEmptyItemSlotTexture()
return Bagnon.Settings:ShowingEmptyItemSlotTextures() return Bagnon.Settings:ShowingEmptyItemSlotTextures()
end end
--[[ Delicious Hacks ]]
--[[ Delicious Hacks ]]-- --
-- dummy slot - A hack, used to provide a tooltip for cached items without tainting other item code -- dummy slot - A hack, used to provide a tooltip for cached items without tainting other item code
function ItemSlot:GetDummyItemSlot() function ItemSlot:GetDummyItemSlot()
@@ -726,23 +700,22 @@ function ItemSlot:CreateDummyItemSlot()
return slot return slot
end end
-- dummy bag, a hack to enforce the internal blizzard rule that item:GetParent():GetID() == bagID
--dummy bag, a hack to enforce the internal blizzard rule that item:GetParent():GetID() == bagID
function ItemSlot:GetDummyBag(parent, bag) function ItemSlot:GetDummyBag(parent, bag)
local dummyBags = parent.dummyBags local dummyBags = parent.dummyBags
--metatable magic to create a new frame on demand -- metatable magic to create a new frame on demand
if not dummyBags then if not dummyBags then
dummyBags = setmetatable({}, { dummyBags = setmetatable({}, {
__index = function(t, k) __index = function(t, k)
local f = CreateFrame('Frame', nil, parent) local f = CreateFrame('Frame', nil, parent)
f:SetID(k) f:SetID(k)
t[k] = f t[k] = f
return f return f
end end
}) })
parent.dummyBags = dummyBags parent.dummyBags = dummyBags
end end
return dummyBags[bag] return dummyBags[bag]
end end
+37 -23
View File
@@ -2,7 +2,6 @@
item.lua item.lua
A guild item slot button A guild item slot button
--]] --]]
local Bagnon = LibStub('AceAddon-3.0'):GetAddon('Bagnon') local Bagnon = LibStub('AceAddon-3.0'):GetAddon('Bagnon')
local ItemSlot = Bagnon.Classy:New('Button') local ItemSlot = Bagnon.Classy:New('Button')
ItemSlot:Hide() ItemSlot:Hide()
@@ -14,9 +13,8 @@ local ItemSearch = LibStub('LibItemSearch-1.0')
--[[ --[[
The item widget The item widget
--]] --]]
--[[ ItemSlot Constructor ]]
--
--[[ ItemSlot Constructor ]]--
function ItemSlot:New(tab, slot, frameID, parent) function ItemSlot:New(tab, slot, frameID, parent)
local item = self:Restore() or self:Create() local item = self:Restore() or self:Create()
@@ -92,7 +90,8 @@ end
--[[ ItemSlot Destructor ]]-- --[[ ItemSlot Destructor ]]
--
function ItemSlot:Free() function ItemSlot:Free()
self:Hide() self:Hide()
@@ -104,8 +103,8 @@ function ItemSlot:Free()
ItemSlot.unused[self] = true ItemSlot.unused[self] = true
end end
--[[ Events ]]
--[[ Events ]]-- --
function ItemSlot:GUILDBANK_ITEM_LOCK_CHANGED(event, tab, slot) function ItemSlot:GUILDBANK_ITEM_LOCK_CHANGED(event, tab, slot)
@@ -139,8 +138,8 @@ function ItemSlot:HandleEvent(msg, ...)
end end
end end
--[[ Frame Events ]]
--[[ Frame Events ]]-- --
function ItemSlot:OnClick(button) function ItemSlot:OnClick(button)
if HandleModifiedItemClick(self:GetItem()) then if HandleModifiedItemClick(self:GetItem()) then
@@ -202,8 +201,8 @@ function ItemSlot:OnLeave()
ResetCursor() ResetCursor()
end end
--[[ Update Methods ]]
--[[ Update Methods ]]-- --
-- Update the texture, lock status, and other information about an item -- Update the texture, lock status, and other information about an item
function ItemSlot:Update() function ItemSlot:Update()
@@ -217,7 +216,7 @@ function ItemSlot:Update()
self:UpdateBorder() self:UpdateBorder()
self:UpdateSearch() self:UpdateSearch()
-- self:UpdateBagSearch() -- self:UpdateBagSearch()
if GameTooltip:IsOwned(self) then if GameTooltip:IsOwned(self) then
self:UpdateTooltip() self:UpdateTooltip()
@@ -261,7 +260,20 @@ function ItemSlot:SetLocked(locked)
SetItemButtonDesaturated(self, locked, 0.5, 0.5, 0.5) SetItemButtonDesaturated(self, locked, 0.5, 0.5, 0.5)
end end
function ItemSlot:UpdateMEName()
local itemLink = self:GetItem()
if itemLink then
self.MEName = strlower(GetREData(GetGuildBankItemMysticEnchant(self:GetSlot()))['spellName'])
return
end
end
function ItemSlot:UpdateLocked() function ItemSlot:UpdateLocked()
if self:IsLocked() then
self.MEName = ""
else
self:UpdateMEName()
end
self:SetLocked(self:IsLocked()) self:SetLocked(self:IsLocked())
end end
@@ -337,14 +349,17 @@ function ItemSlot:AnchorTooltip()
end end
end end
--search -- search
function ItemSlot:UpdateSearch() function ItemSlot:UpdateSearch()
local shouldFade = false local shouldFade = false
local search = self:GetItemSearch() local search = self:GetItemSearch()
if search and search ~= '' then if search and search ~= '' then
local itemLink = self:GetItem() local itemLink = self:GetItem()
shouldFade = not(itemLink and ItemSearch:Find(itemLink, search)) shouldFade = not (itemLink and ItemSearch:Find(itemLink, search))
if self.MEName and string.find(self.MEName, string.lower(search)) then
shouldFade = false
end
end end
if shouldFade then if shouldFade then
@@ -355,7 +370,7 @@ function ItemSlot:UpdateSearch()
self:SetAlpha(1) self:SetAlpha(1)
self:UpdateLocked() self:UpdateLocked()
self:UpdateBorder() self:UpdateBorder()
-- self:UpdateSlotColor() -- self:UpdateSlotColor()
end end
end end
@@ -363,9 +378,8 @@ function ItemSlot:GetItemSearch()
return Bagnon.Settings:GetTextSearch() return Bagnon.Settings:GetTextSearch()
end end
--[[ Accessor Methods ]]
--
--[[ Accessor Methods ]]--
function ItemSlot:SetFrameID(frameID) function ItemSlot:SetFrameID(frameID)
if self:GetFrameID() ~= frameID then if self:GetFrameID() ~= frameID then
@@ -411,8 +425,8 @@ function ItemSlot:GetItemSlotInfo()
return texture, itemCount, locked, itemLink return texture, itemCount, locked, itemLink
end end
--[[ Item Type Highlighting ]]
--[[ Item Type Highlighting ]]-- --
function ItemSlot:HighlightingItemsByQuality() function ItemSlot:HighlightingItemsByQuality()
return Bagnon.Settings:HighlightingItemsByQuality() return Bagnon.Settings:HighlightingItemsByQuality()
@@ -436,9 +450,9 @@ function ItemSlot:IsQuestItem()
return ItemSearch:Find(itemLink, QUEST_ITEM_SEARCH) return ItemSearch:Find(itemLink, QUEST_ITEM_SEARCH)
end end
--[[ Empty Slot Visibility ]]
--[[ Empty Slot Visibility ]]-- --
function ItemSlot:ShowingEmptyItemSlotTexture() function ItemSlot:ShowingEmptyItemSlotTexture()
return Bagnon.Settings:ShowingEmptyItemSlotTextures() return Bagnon.Settings:ShowingEmptyItemSlotTextures()
end end