-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerUI.lua
More file actions
164 lines (140 loc) · 5.13 KB
/
ContainerUI.lua
File metadata and controls
164 lines (140 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
------------------------------------------
-- Container UI Module
------------------------------------------
local MageService = MAGESERVICE
local Blacklist = MageService.Blacklist
local Settings = MageService.Settings
------------------------------------------
-- Create the ContainerUI module
------------------------------------------
local ContainerUI = {}
------------------------------------------
-- UI Elements
------------------------------------------
-- Create a movable container frame
ContainerUI.Frame = CreateFrame("Frame", "MageServiceContainer", UIParent)
ContainerUI.Frame:SetSize(170, 200) -- Increased height to accommodate buttons
-- Initial position will be set during initialization
ContainerUI.Frame:SetMovable(true)
ContainerUI.Frame:EnableMouse(true)
ContainerUI.Frame:SetClampedToScreen(true)
ContainerUI.Frame:RegisterForDrag("LeftButton")
ContainerUI.Frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
ContainerUI.Frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
-- Save position for future sessions
local point, _, relativePoint, xOfs, yOfs = self:GetPoint()
Settings.SetContainerUIPosition({
point = point,
relativePoint = relativePoint,
xOfs = xOfs,
yOfs = yOfs
})
end)
-- Add a background and border to make it visible when empty
ContainerUI.Frame.bg = ContainerUI.Frame:CreateTexture(nil, "BACKGROUND")
ContainerUI.Frame.bg:SetAllPoints()
ContainerUI.Frame.bg:SetColorTexture(0, 0, 0, 0.5)
-- Add a header/title for dragging
ContainerUI.Frame.header = ContainerUI.Frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
ContainerUI.Frame.header:SetPoint("TOP", 0, -5)
ContainerUI.Frame.header:SetText("Mage Service")
------------------------------------------
-- Button Layout Management
------------------------------------------
-- Table to track all buttons in the container
ContainerUI.Buttons = {}
-- Function to register a button with the container
function ContainerUI.RegisterButton(button, priority)
table.insert(ContainerUI.Buttons, {
button = button,
priority = priority or 100 -- Default priority (lower values = higher in the container)
})
-- Sort buttons by priority
ContainerUI.LayoutButtons()
return button
end
-- Function to layout all buttons in the container
function ContainerUI.LayoutButtons()
-- Sort buttons by priority (lower values first)
table.sort(ContainerUI.Buttons, function(a, b)
return a.priority < b.priority
end)
local yOffset = -25 -- Start below the header
local spacing = 5 -- Space between buttons
-- Position each button
for _, buttonInfo in ipairs(ContainerUI.Buttons) do
local button = buttonInfo.button
if button then
button:ClearAllPoints()
button:SetPoint("TOP", ContainerUI.Frame, "TOP", 0, yOffset)
local _, height = button:GetSize()
yOffset = yOffset - (height + spacing)
end
end
end
-- Function to update the container size based on visible buttons
function ContainerUI.UpdateContainerSize()
local visibleButtons = 0
local totalHeight = 30 -- Header space
local buttonSpacing = 5
for _, buttonInfo in ipairs(ContainerUI.Buttons) do
if buttonInfo.button:IsShown() and buttonInfo.button:GetAlpha() > 0.1 then
visibleButtons = visibleButtons + 1
local _, height = buttonInfo.button:GetSize()
totalHeight = totalHeight + height + buttonSpacing
end
end
-- Minimum height to avoid empty container looking odd
totalHeight = math.max(totalHeight, 50)
-- Set the container height (keep width the same)
local width = ContainerUI.Frame:GetWidth()
ContainerUI.Frame:SetSize(width, totalHeight)
end
------------------------------------------
-- UI Functions
------------------------------------------
-- Function to toggle container visibility
function ContainerUI.ToggleVisibility()
if ContainerUI.Frame:IsShown() then
ContainerUI.Hide()
else
ContainerUI.Show()
end
end
-- Function to show container
function ContainerUI.Show()
ContainerUI.UpdateContainerSize()
ContainerUI.Frame:Show()
Settings.SetContainerUIVisible(true)
end
-- Function to hide container
function ContainerUI.Hide()
ContainerUI.Frame:Hide()
Settings.SetContainerUIVisible(false)
end
-- Function to initialize the container UI from saved settings
function ContainerUI.Initialize()
-- Set the position from saved settings
local position = Settings.GetContainerUIPosition()
if position then
ContainerUI.Frame:ClearAllPoints()
ContainerUI.Frame:SetPoint(
position.point,
UIParent,
position.relativePoint,
position.xOfs,
position.yOfs
)
end
-- Set visibility from saved settings
if Settings.IsContainerUIVisible() then
ContainerUI.Show()
else
ContainerUI.Hide()
end
end
------------------------------------------
-- Register the module in the addon namespace
------------------------------------------
MageService.ContainerUI = ContainerUI