-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTH_UI.lua
More file actions
277 lines (228 loc) · 7.35 KB
/
Copy pathSTH_UI.lua
File metadata and controls
277 lines (228 loc) · 7.35 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
local STH = SamisTrialHelperAddon
STH.ui = STH.ui or {}
local ui = STH.ui
local util = STH.util
local SAMID = SamisTrialAddonsDebugHelpers
ui.playerButtons = {}
ui.activePlayerButtons = {}
ui.playerButtonCount = 0
function ui.init()
SamisTrialHelperTLC:ClearAnchors()
SamisTrialHelperTLC:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, STH.settings.offsetX,
STH.settings.offsetY)
-- Create background if it doesn't exist
if not ui.background then
local bg = WINDOW_MANAGER:CreateControl("SamisTrialHelperTLCBackground", SamisTrialHelperTLC, CT_TEXTURE)
bg:SetDimensions(400, 100)
bg:SetAnchor(TOPLEFT, SamisTrialHelperTLC, TOPLEFT, 0, 0)
bg:SetDrawLevel(-1)
ui.background = bg
end
-- Create title if it doesn't exist
if not ui.title then
local title = WINDOW_MANAGER:CreateControl("SamisTrialHelperTLCTitle", SamisTrialHelperTLC, CT_LABEL)
title:SetFont("ZoFontWinH5")
title:SetColor(1, 1, 1)
title:SetText("Get yo Loot!")
title:SetAnchor(TOP, SamisTrialHelperTLC, TOP, 0, 2)
ui.title = title
end
-- Adjust label to position below title
SamisTrialHelperTLCLabel:ClearAnchors()
SamisTrialHelperTLCLabel:SetAnchor(TOPLEFT, SamisTrialHelperTLC, TOPLEFT, 8, 20)
-- Set default text color
local r, g, b = util.hexToRgb("#FFFFFF")
SamisTrialHelperTLCLabel:SetColor(r, g, b)
-- Set up the background
local bg = ui.background
local r, g, b = util.hexToRgb("#000000")
bg:SetColor(r, g, b, 255)
bg:SetHidden(false)
ui.hide()
end
function ui.hide()
SamisTrialHelperTLC:SetHidden(true)
end
function ui.show()
SamisTrialHelperTLC:SetHidden(false)
end
function ui.createPlayerButtons(allDetails)
ui.clearPlayerButtons()
SAMID:Print("Creating player buttons for player(s).")
local index = nil
for _, details in pairs(allDetails) do
index = index or 1
ui.createPlayerButton(details, index)
index = index + 1
end
if index then
SAMID:Print("Created player button(s). %d", index)
ui.show()
end
end
function ui.createPlayerButton(playerDetails, rowIndex)
local row = ui.activePlayerButtons[playerDetails.playerName]
if not rowIndex then
if row then
rowIndex = row.rowIndex
else
local count = 0
for _ in pairs(ui.activePlayerButtons) do count = count + 1 end
rowIndex = count + 1
end
end
if not row then
row = table.remove(ui.playerButtons)
end
if not row then
ui.playerButtonCount = ui.playerButtonCount + 1
local controlName = "SamisTrialHelperTLCRow" .. tostring(ui.playerButtonCount)
row = WINDOW_MANAGER:CreateControl(controlName, SamisTrialHelperTLC, CT_CONTROL)
row:SetHeight(30)
row:SetMouseEnabled(true)
row.label = WINDOW_MANAGER:CreateControl(nil, row, CT_LABEL)
row.label:SetAnchor(LEFT, row, LEFT, 0, 0)
row.label:SetFont("ZoFontWinH5")
row.closeButton = WINDOW_MANAGER:CreateControl(nil, row, CT_LABEL)
row.closeButton:SetAnchor(LEFT, row.label, RIGHT, 8, 0)
row.closeButton:SetFont("ZoFontWinH5")
row.closeButton:SetColor(1, 0.5, 0)
row.closeButton:SetText("X")
row.closeButton:SetMouseEnabled(true)
row.closeButton:SetHandler("OnMouseUp", function(self, button)
if button ~= MOUSE_BUTTON_INDEX_LEFT then return end
local parent = self:GetParent()
if not parent.playerDetails then return end
local details = parent.playerDetails
STH:RemoveUncollectedItemRecord(details)
ui.removePlayerButton(details.playerName)
end)
row.closeButton:SetHandler("OnMouseEnter", function(self)
self:SetColor(1, 0, 0)
end)
row.closeButton:SetHandler("OnMouseExit", function(self)
self:SetColor(1, 0.5, 0)
end)
row:SetHandler("OnMouseUp", function(self, button)
if button ~= MOUSE_BUTTON_INDEX_LEFT then return end
if not self.playerDetails then return end
local details = self.playerDetails
STH:SendGroupMessage(details)
ui.removePlayerButton(details.playerName)
STH:RemoveUncollectedItemRecord(details)
end)
row:SetHandler("OnMouseEnter", function(self)
self.label:SetColor(1, 0.85, 0)
end)
row:SetHandler("OnMouseExit", function(self)
self.label:SetColor(1, 1, 1)
end)
end
row.playerDetails = playerDetails
row.label:SetText(playerDetails.playerName .. " has #" .. #playerDetails.itemLinks .. " items you need")
row:SetWidth(row.label:GetTextWidth() + 50)
row:ClearAnchors()
row:SetAnchor(TOPLEFT, SamisTrialHelperTLC, TOPLEFT, 8, 20 + 30 * (rowIndex - 1))
row:SetHidden(false)
row.rowIndex = rowIndex
ui.activePlayerButtons[playerDetails.playerName] = row
ui.resizeBackground()
end
function ui.resizeBackground()
local maxWidth = 0
local count = 0
for _, row in pairs(ui.activePlayerButtons) do
local w = row:GetWidth()
if w > maxWidth then maxWidth = w end
count = count + 1
end
local bg = ui.background
bg:SetWidth(maxWidth)
bg:SetHeight(20 + 30 * count + 8)
if ui.title then
ui.title:ClearAnchors()
ui.title:SetAnchor(TOP, bg, TOP, 0, 2)
end
end
function ui.removePlayerButton(playerName)
local row = ui.activePlayerButtons[playerName]
if row then
row:SetHidden(true)
row:ClearAnchors()
row.playerDetails = nil
row.rowIndex = nil
ui.activePlayerButtons[playerName] = nil
table.insert(ui.playerButtons, row)
if next(ui.activePlayerButtons) == nil then
ui.hide()
else
ui.resizeBackground()
end
end
end
function ui.clearPlayerButtons()
local hadActiveRows = next(ui.activePlayerButtons) ~= nil
for playerName, row in pairs(ui.activePlayerButtons) do
row:SetHidden(true)
row:ClearAnchors()
row.playerDetails = nil
table.insert(ui.playerButtons, row)
end
ui.activePlayerButtons = {}
if hadActiveRows then
ui.hide()
end
end
function ui.setText(text)
SamisTrialHelperTLCLabel:SetText(text or "")
-- Resize background to match label with padding
local label = SamisTrialHelperTLCLabel
local width = label:GetWidth()
local height = label:GetHeight()
if width == 0 or height == 0 then
-- If dimensions are 0, use the control's set dimensions
width = 200
height = 100
end
-- Add padding: 8px left/right, 4px top/bottom
width = width + 16
height = height + 8
local bg = ui.background
bg:SetDimensions(width, height)
-- Recenter title after resizing
local title = ui.title
if title then
title:ClearAnchors()
title:SetAnchor(TOP, ui.background, TOP, 0, 2)
end
end
function STH.savePosition()
STH.settings.offsetX = SamisTrialHelperTLC:GetLeft()
STH.settings.offsetY = SamisTrialHelperTLC:GetTop()
end
-- function ui.updateBackgroundColor()
-- local bg = ui.background
-- if bg then
-- local r, g, b = util.hexToRgb(STH.settings.backgroundColor)
-- bg:SetColor(r, g, b, STH.settings.backgroundOpacity)
-- end
-- end
-- function ui.updateBackgroundOpacity()
-- local bg = ui.background
-- if bg then
-- local r, g, b = util.hexToRgb(STH.settings.backgroundColor)
-- bg:SetColor(r, g, b, STH.settings.backgroundOpacity)
-- end
-- end
-- function ui.updateTextColors()
-- -- Refresh the timers to apply any color changes
-- local r, g, b = util.hexToRgb(STH.settings.defaultTextColour)
-- SamisTrialHelperTLCLabel:SetColor(r, g, b)
-- STH.updateTimer()
-- end
-- function ui.updateTitleVisibility()
-- local title = ui.title
-- if title then
-- title:SetHidden(not STH.settings.showTitle)
-- end
-- end