refactory: frame helpers
This commit is contained in:
@@ -24,6 +24,7 @@ Sorting\SortEngine.lua
|
||||
|
||||
# UI Lua must load before XML so OnLoad handlers exist
|
||||
UI\ItemButton.lua
|
||||
UI\FrameHelpers.lua
|
||||
UI\BagFrame.lua
|
||||
UI\BankFrame.lua
|
||||
UI\MailboxFrame.lua
|
||||
|
||||
@@ -6,6 +6,15 @@ local addon = Guda
|
||||
local BagFrame = {}
|
||||
addon.Modules.BagFrame = BagFrame
|
||||
|
||||
-- Use centralized frame helpers for section headers and bag parents
|
||||
function BagFrame:GetSectionHeader(index)
|
||||
return Guda_GetSectionHeader("Guda_BagFrame", "Guda_BagFrame_ItemContainer", index)
|
||||
end
|
||||
|
||||
function BagFrame:GetBagParent(bagID)
|
||||
return Guda_GetBagParent("Guda_BagFrame", bagParents, bagID, "Guda_BagFrame_ItemContainer")
|
||||
end
|
||||
|
||||
local currentViewChar = nil -- nil = current character
|
||||
function BagFrame:GetCurrentViewChar()
|
||||
return currentViewChar
|
||||
|
||||
+3
-34
@@ -232,44 +232,13 @@ function BankFrame:Update()
|
||||
end
|
||||
end
|
||||
|
||||
-- Helper to get or create section header
|
||||
-- Use centralized frame helpers for section headers and bag parents
|
||||
function BankFrame:GetSectionHeader(index)
|
||||
local name = "Guda_BankFrame_SectionHeader" .. index
|
||||
local header = getglobal(name)
|
||||
if not header then
|
||||
header = CreateFrame("Frame", name, getglobal("Guda_BankFrame_ItemContainer"))
|
||||
header:SetHeight(20)
|
||||
header:EnableMouse(true)
|
||||
local text = header:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
text:SetPoint("LEFT", header, "LEFT", 0, 0)
|
||||
header.text = text
|
||||
|
||||
header:SetScript("OnEnter", function()
|
||||
if this.fullName and this.isShortened then
|
||||
GameTooltip:SetOwner(this, "ANCHOR_TOP")
|
||||
GameTooltip:SetText(this.fullName)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end)
|
||||
header:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
end
|
||||
header.inUse = true
|
||||
return header
|
||||
return Guda_GetSectionHeader("Guda_BankFrame", "Guda_BankFrame_ItemContainer", index)
|
||||
end
|
||||
|
||||
-- Helper to get or create bank bag parent frame
|
||||
function BankFrame:GetBagParent(bagID)
|
||||
local itemContainer = getglobal("Guda_BankFrame_ItemContainer")
|
||||
if not bankBagParents[bagID] then
|
||||
bankBagParents[bagID] = CreateFrame("Frame", "Guda_BankFrame_BagParent"..bagID, itemContainer)
|
||||
bankBagParents[bagID]:SetAllPoints(itemContainer)
|
||||
if bankBagParents[bagID].SetID then
|
||||
bankBagParents[bagID]:SetID(bagID)
|
||||
end
|
||||
end
|
||||
return bankBagParents[bagID]
|
||||
return Guda_GetBagParent("Guda_BankFrame", bankBagParents, bagID, "Guda_BankFrame_ItemContainer")
|
||||
end
|
||||
|
||||
-- Display items by category
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
-- FrameHelpers: central utilities for frame headers and bag parents
|
||||
local addon = Guda
|
||||
|
||||
local FrameHelpers = {}
|
||||
addon.Modules.FrameHelpers = FrameHelpers
|
||||
|
||||
-- Create or return a section header for a given frame prefix and container
|
||||
function Guda_GetSectionHeader(framePrefix, containerName, index)
|
||||
local name = framePrefix .. "_SectionHeader" .. index
|
||||
local header = getglobal(name)
|
||||
if not header then
|
||||
local container = getglobal(containerName)
|
||||
header = CreateFrame("Frame", name, container)
|
||||
header:SetHeight(20)
|
||||
header:EnableMouse(true)
|
||||
local text = header:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
||||
text:SetPoint("LEFT", header, "LEFT", 0, 0)
|
||||
header.text = text
|
||||
|
||||
header:SetScript("OnEnter", function()
|
||||
if this.fullName and this.isShortened then
|
||||
GameTooltip:SetOwner(this, "ANCHOR_TOP")
|
||||
GameTooltip:SetText(this.fullName)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end)
|
||||
header:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
end
|
||||
header.inUse = true
|
||||
return header
|
||||
end
|
||||
|
||||
-- Create or return a bag parent frame for a frame prefix and bag parents table
|
||||
function Guda_GetBagParent(framePrefix, parentsTable, bagID, containerName)
|
||||
local container = getglobal(containerName)
|
||||
if not parentsTable[bagID] then
|
||||
local name = framePrefix .. "_BagParent" .. bagID
|
||||
parentsTable[bagID] = CreateFrame("Frame", name, container)
|
||||
parentsTable[bagID]:SetAllPoints(container)
|
||||
if parentsTable[bagID].SetID then
|
||||
parentsTable[bagID]:SetID(bagID)
|
||||
end
|
||||
end
|
||||
return parentsTable[bagID]
|
||||
end
|
||||
Reference in New Issue
Block a user