-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
441 lines (389 loc) · 16.9 KB
/
UI.lua
File metadata and controls
441 lines (389 loc) · 16.9 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
-- Wick's Travel Form
-- UI.lua — secure click button + contextual form icon
-- Brand spec: locked palette, 10px L-bracket corners, 1px muted-purple border.
--
-- The secure button is created at file-parse-time (mirroring WicksQuestKey)
-- so it exists before any event handler can reference it. Position and
-- lock state are applied later from saved variables once they're loaded.
local _, ns = ...
local UI = {}
ns.UI = UI
-- =====================================================================
-- Wick brand palette (locked)
-- Fel #4FC778 · Void #0D0A14 · Border #383058 · Off-White #D4C8A1
-- =====================================================================
local C_BG = { 0.051, 0.039, 0.078, 0.97 }
local C_BORDER = { 0.220, 0.188, 0.345, 1 }
local C_GREEN = { 0.310, 0.780, 0.471, 1 }
local C_HOVER = { 0.310, 0.780, 0.471, 0.10 }
local C_MOVE = { 0.640, 0.210, 0.930, 0.20 }
local BRACKET, ARM = 10, 2
local function newTex(parent, layer, c)
local t = parent:CreateTexture(nil, layer)
t:SetColorTexture(unpack(c))
return t
end
local function addBorder(f)
local t = newTex(f, "BORDER", C_BORDER); t:SetPoint("TOPLEFT"); t:SetPoint("TOPRIGHT"); t:SetHeight(1)
local b = newTex(f, "BORDER", C_BORDER); b:SetPoint("BOTTOMLEFT"); b:SetPoint("BOTTOMRIGHT"); b:SetHeight(1)
local l = newTex(f, "BORDER", C_BORDER); l:SetPoint("TOPLEFT"); l:SetPoint("BOTTOMLEFT"); l:SetWidth(1)
local r = newTex(f, "BORDER", C_BORDER); r:SetPoint("TOPRIGHT"); r:SetPoint("BOTTOMRIGHT"); r:SetWidth(1)
end
local function addCornerAccents(f)
for _, anchor in ipairs({ "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" }) do
local h = newTex(f, "OVERLAY", C_GREEN); h:SetPoint(anchor); h:SetSize(BRACKET, ARM)
local v = newTex(f, "OVERLAY", C_GREEN); v:SetPoint(anchor); v:SetSize(ARM, BRACKET)
end
end
local function shortBind(key)
if not key or key == "" then return "" end
return (key:upper()
:gsub("ALT%-", "a")
:gsub("CTRL%-", "c")
:gsub("SHIFT%-", "s")
:gsub("NUMPAD", "n")
:gsub("BUTTON1", "M1")
:gsub("BUTTON2", "M2")
:gsub("BUTTON3", "M3")
:gsub("MOUSEWHEELUP", "MwU")
:gsub("MOUSEWHEELDOWN", "MwD"))
end
local TF_BINDING = "CLICK WicksTravelFormButton:LeftButton"
local locked = true
-- =====================================================================
-- Button creation (top-level — runs at file load)
-- =====================================================================
-- Architecture: a non-secure `host` Frame owns position, scale, and drag.
-- The secure `btn` (SecureActionButton) fills the host. Blizzard's secure-init
-- pipeline reverts SetSize/SetScale on secure frames during the load sequence;
-- by isolating those properties on the host we avoid that revert entirely.
-- This mirrors how WicksTotemsAndThings persists its bar scale.
local REFERENCE_SIZE = 48
local host = CreateFrame("Frame", "WicksTravelFormHost", UIParent)
host:SetSize(REFERENCE_SIZE, REFERENCE_SIZE)
host:SetFrameStrata("MEDIUM")
host:SetClampedToScreen(true)
host:SetMovable(true)
host:SetPoint("CENTER", UIParent, "CENTER", 0, -120)
local btn = CreateFrame("Button", "WicksTravelFormButton", host, "SecureActionButtonTemplate")
btn:SetAllPoints(host)
-- Mirror the WicksQuestKey pattern: type1=macro, both macrotext attrs
-- set, AnyUp+AnyDown registration. The SAB's internal macro processor
-- handles the cast so the keybind fires the same code path as a click.
btn:SetAttribute("type1", "macro")
btn:RegisterForClicks("AnyUp", "AnyDown")
local bg = newTex(btn, "BACKGROUND", C_BG); bg:SetAllPoints(btn)
addBorder(btn)
addCornerAccents(btn)
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetPoint("TOPLEFT", 4, -4)
icon:SetPoint("BOTTOMRIGHT", -4, 4)
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
btn.icon = icon
local bindLabel = btn:CreateFontString(nil, "OVERLAY")
bindLabel:SetFont("Fonts\\FRIZQT__.TTF", 11, "OUTLINE")
bindLabel:SetPoint("TOPRIGHT", btn, "TOPRIGHT", -3, -3)
bindLabel:SetTextColor(1, 1, 1, 1)
btn.bindLabel = bindLabel
local hover = newTex(btn, "HIGHLIGHT", C_HOVER); hover:SetAllPoints(btn)
local moveTint = newTex(btn, "OVERLAY", C_MOVE); moveTint:SetAllPoints(btn); moveTint:Hide()
-- Drag is wired to the host (which owns position). The button is registered
-- for drag and forwards StartMoving/StopMoving to host so the visual is
-- consistent (you grab the button, the whole thing moves).
btn:RegisterForDrag("LeftButton")
btn:SetScript("OnDragStart", function() if not locked then host:StartMoving() end end)
btn:SetScript("OnDragStop", function()
host:StopMovingOrSizing()
if WicksTravelFormDB then
local point, _, relativePoint, x, y = host:GetPoint(1)
WicksTravelFormDB.point, WicksTravelFormDB.relativePoint = point, relativePoint
WicksTravelFormDB.x, WicksTravelFormDB.y = x, y
end
end)
btn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Wick's Travel Form", 0.31, 0.78, 0.47)
local action
if ns.isInManagedForm then
action = ns.isInManagedForm() and "Cancel form" or ("Will cast: " .. ns.predictForm())
end
GameTooltip:AddLine(action or "Initializing...", 0.83, 0.78, 0.63)
GameTooltip:AddLine(" ")
if locked then
GameTooltip:AddLine("Right-click to unlock for drag and resize.", 0.42, 0.35, 0.54)
else
GameTooltip:AddLine("Drag to move · scroll to resize · right-click to lock.", 0.42, 0.35, 0.54)
end
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function() GameTooltip:Hide() end)
-- Mouse wheel resize while unlocked. Step 4px, clamped 32–96.
btn:EnableMouseWheel(true)
btn:SetScript("OnMouseWheel", function(self, delta)
if locked then return end
local cur = (WicksTravelFormDB and WicksTravelFormDB.size) or 48
local step = (delta > 0) and 4 or -4
local s = cur + step
if s < (ns.MIN_SIZE or 32) then s = ns.MIN_SIZE or 32 end
if s > (ns.MAX_SIZE or 96) then s = ns.MAX_SIZE or 96 end
if s == cur then return end
if WicksTravelFormDB then WicksTravelFormDB.size = s end
UI:ApplySize()
ApplyBarLayout()
end)
-- HookScript so Blizzard's secure OnClick still runs and fires the
-- macrotext for left-click. Right-click toggles lock.
btn:HookScript("OnClick", function(self, button, down)
if button == "RightButton" and down and not InCombatLockdown() then
UI:SetLocked(not locked)
end
end)
-- Button is visible by default. Non-druid characters get it hidden by
-- Core.lua's class check. This way the button appears even if Activate
-- never runs cleanly — failure mode is "button visible, macro stale"
-- rather than "button missing entirely".
-- =====================================================================
-- Resource bar
-- Two fixed-height segments stacked below the button host.
-- Primary slot (top): rage in Bear, energy in Cat, mana otherwise.
-- Mana slot (bottom): always mana, hidden when primary IS mana.
-- Both bars dim when the form makes them passive.
-- =====================================================================
local BAR_H_DEFAULT = 5
local BAR_GAP_DEFAULT = 2
local BAR_MARGIN_DEFAULT = 2
local function barH() return (WicksTravelFormDB and WicksTravelFormDB.barSegH) or BAR_H_DEFAULT end
local function barGap() return (WicksTravelFormDB and WicksTravelFormDB.barGap) or BAR_GAP_DEFAULT end
local function barMargin() return (WicksTravelFormDB and WicksTravelFormDB.barMargin) or BAR_MARGIN_DEFAULT end
local function fbarH() return (WicksTravelFormDB and WicksTravelFormDB.barFloatSegH) or BAR_H_DEFAULT end
local function fbarGap() return (WicksTravelFormDB and WicksTravelFormDB.barFloatGap) or BAR_GAP_DEFAULT end
local C_RAGE = { 1.00, 0.49, 0.10, 1 }
local C_ENERGY = { 1.00, 0.82, 0.10, 1 }
local C_MANA = { 0.31, 0.52, 0.90, 1 }
local C_DIM_BG = { 0.10, 0.10, 0.12, 0.6 }
-- Power type constants (UnitPowerType returns these)
local POWER_MANA = 0
local POWER_RAGE = 1
local POWER_ENERGY = 3
-- =====================================================================
-- Shared draw logic — operates on whichever bar frame is passed in.
-- Each bar frame has .priTrack, .priFill, .manaTrack, .manaFill children.
-- =====================================================================
local function MakeBarChildren(f)
local pt = f:CreateTexture(nil, "BACKGROUND"); pt:SetColorTexture(unpack(C_DIM_BG))
local pf = f:CreateTexture(nil, "ARTWORK"); pf:SetWidth(1)
local mt = f:CreateTexture(nil, "BACKGROUND"); mt:SetColorTexture(unpack(C_DIM_BG))
local mf = f:CreateTexture(nil, "ARTWORK"); mf:SetWidth(1)
f.priTrack = pt
f.priFill = pf
f.manaTrack = mt
f.manaFill = mf
end
-- pad: inset tracks inside the frame on all sides (used by float bar for bracket clearance)
local function LayoutBarChildren(f, w, h, g, pad)
pad = pad or 0
f.priTrack:ClearAllPoints()
f.priTrack:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -pad)
f.priTrack:SetPoint("TOPRIGHT", f, "TOPRIGHT", -pad, -pad)
f.priTrack:SetHeight(h)
f.priFill:ClearAllPoints()
f.priFill:SetPoint("TOPLEFT", f.priTrack, "TOPLEFT", 0, 0)
f.priFill:SetPoint("BOTTOMLEFT", f.priTrack, "BOTTOMLEFT", 0, 0)
f.manaTrack:ClearAllPoints()
f.manaTrack:SetPoint("TOPLEFT", f, "TOPLEFT", pad, -(pad + h + g))
f.manaTrack:SetPoint("TOPRIGHT", f, "TOPRIGHT", -pad, -(pad + h + g))
f.manaTrack:SetHeight(h)
f.manaFill:ClearAllPoints()
f.manaFill:SetPoint("TOPLEFT", f.manaTrack, "TOPLEFT", 0, 0)
f.manaFill:SetPoint("BOTTOMLEFT", f.manaTrack, "BOTTOMLEFT", 0, 0)
end
local function DrawBar(f)
local totalW = f._innerW or f:GetWidth()
if not totalW or totalW <= 0 then return end
local powerType = UnitPowerType("player")
local mana = UnitPower("player", POWER_MANA)
local manaMax = UnitPowerMax("player", POWER_MANA)
local manaPct = (manaMax and manaMax > 0) and (mana / manaMax) or 0
if powerType == POWER_RAGE then
local rage = UnitPower("player", POWER_RAGE)
local rageMax = UnitPowerMax("player", POWER_RAGE)
local ragePct = (rageMax and rageMax > 0) and (rage / rageMax) or 0
f.priFill:SetColorTexture(C_RAGE[1], C_RAGE[2], C_RAGE[3], 1)
f.priFill:SetWidth(math.max(1, totalW * ragePct))
f.manaFill:SetColorTexture(C_MANA[1], C_MANA[2], C_MANA[3], 0.45)
f.manaFill:SetWidth(math.max(1, totalW * manaPct))
f.manaTrack:Show(); f.manaFill:Show()
elseif powerType == POWER_ENERGY then
local energy = UnitPower("player", POWER_ENERGY)
local energyMax = UnitPowerMax("player", POWER_ENERGY)
local energyPct = (energyMax and energyMax > 0) and (energy / energyMax) or 0
f.priFill:SetColorTexture(C_ENERGY[1], C_ENERGY[2], C_ENERGY[3], 1)
f.priFill:SetWidth(math.max(1, totalW * energyPct))
f.manaFill:SetColorTexture(C_MANA[1], C_MANA[2], C_MANA[3], 0.45)
f.manaFill:SetWidth(math.max(1, totalW * manaPct))
f.manaTrack:Show(); f.manaFill:Show()
else
local formIndex = GetShapeshiftForm()
local isMoonkin = false
if formIndex > 0 then
local formName = GetShapeshiftFormInfo(formIndex)
isMoonkin = (formName == "Moonkin Form")
end
local alpha = isMoonkin and 1 or 0.55
f.priFill:SetColorTexture(C_MANA[1], C_MANA[2], C_MANA[3], alpha)
f.priFill:SetWidth(math.max(1, totalW * manaPct))
f.manaTrack:Hide(); f.manaFill:Hide()
end
end
-- =====================================================================
-- Attached bar — anchored below the button host, width = button size.
-- =====================================================================
local barHost = CreateFrame("Frame", "WicksTravelFormBarHost", UIParent)
barHost:SetFrameStrata("MEDIUM")
barHost:SetClampedToScreen(true)
barHost:Hide()
MakeBarChildren(barHost)
local function ApplyBarLayout()
if WicksTravelFormDB and WicksTravelFormDB.barEnabled == false then
barHost:Hide()
return
end
local s = (WicksTravelFormDB and WicksTravelFormDB.size) or 48
local h = barH()
local g = barGap()
local m = barMargin()
barHost:SetSize(s, h * 2 + g)
barHost:ClearAllPoints()
barHost:SetPoint("TOP", host, "BOTTOM", 0, -m)
LayoutBarChildren(barHost, s, h, g)
barHost:Show()
DrawBar(barHost)
end
ns.ApplyBarLayout = ApplyBarLayout
-- =====================================================================
-- Floating bar — independent draggable frame.
-- =====================================================================
local FLOAT_W_DEFAULT = 120
local floatBar = CreateFrame("Frame", "WicksTravelFormFloatBar", UIParent)
floatBar:SetFrameStrata("MEDIUM")
floatBar:SetClampedToScreen(true)
floatBar:SetMovable(true)
floatBar:Hide()
MakeBarChildren(floatBar)
-- Wick border + corner accents on the float bar
addBorder(floatBar)
addCornerAccents(floatBar)
floatBar:EnableMouse(true)
floatBar:RegisterForDrag("LeftButton")
floatBar:SetScript("OnDragStart", function(self)
if not locked then self:StartMoving() end
end)
floatBar:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
if WicksTravelFormDB then
local _, _, _, x, y = self:GetPoint(1)
WicksTravelFormDB.barFloatX = x
WicksTravelFormDB.barFloatY = y
end
end)
local function ApplyFloatBarLayout()
if not (WicksTravelFormDB and WicksTravelFormDB.barFloat) then
floatBar:Hide()
return
end
local w = (WicksTravelFormDB and WicksTravelFormDB.barFloatW) or FLOAT_W_DEFAULT
local h = fbarH()
local g = fbarGap()
local pad = ARM -- bracket arm thickness = inset amount
-- frame is larger than the fill area by 2*pad on each axis
floatBar:SetSize(w + pad * 2, h * 2 + g + pad * 2)
floatBar:ClearAllPoints()
local x = (WicksTravelFormDB and WicksTravelFormDB.barFloatX) or 0
local y = (WicksTravelFormDB and WicksTravelFormDB.barFloatY) or 100
floatBar:SetPoint("CENTER", UIParent, "CENTER", x, y)
LayoutBarChildren(floatBar, w, h, g, pad)
-- store inner width so DrawBar scales fills correctly
floatBar._innerW = w
floatBar:Show()
DrawBar(floatBar)
end
ns.ApplyFloatBarLayout = ApplyFloatBarLayout
-- Throttled OnUpdate drives both bars.
local elapsed = 0
local ticker = CreateFrame("Frame")
ticker:SetScript("OnUpdate", function(_, dt)
elapsed = elapsed + dt
if elapsed < 0.05 then return end
elapsed = 0
if barHost:IsShown() then DrawBar(barHost) end
if floatBar:IsShown() then DrawBar(floatBar) end
end)
local function UpdateResourceBar()
if barHost:IsShown() then DrawBar(barHost) end
if floatBar:IsShown() then DrawBar(floatBar) end
end
ns.UpdateResourceBar = UpdateResourceBar
-- =====================================================================
-- Methods
-- =====================================================================
function UI:ApplyPosition()
if not WicksTravelFormDB then return end
local db = WicksTravelFormDB
host:ClearAllPoints()
host:SetPoint(db.point or "CENTER", UIParent, db.relativePoint or "CENTER",
db.x or 0, db.y or -120)
end
function UI:ApplySize()
local s = (WicksTravelFormDB and WicksTravelFormDB.size) or REFERENCE_SIZE
local lo, hi = ns.MIN_SIZE or 32, ns.MAX_SIZE or 96
if s < lo then s = lo end
if s > hi then s = hi end
host:SetSize(s, s)
end
function UI:UpdateBindLabel()
btn.bindLabel:SetText(shortBind(GetBindingKey(TF_BINDING)))
end
function UI:Refresh()
-- Macrotext can only be set out of combat. The macro itself contains
-- runtime conditionals so the in-combat behavior is still correct
-- with whatever was set at the last out-of-combat refresh.
if not InCombatLockdown() then
local m = ns.buildMacro()
btn:SetAttribute("macrotext", m)
btn:SetAttribute("macrotext1", m)
end
btn.icon:SetTexture(ns.formIcon(ns.predictForm()))
self:UpdateBindLabel()
end
function UI:SetLocked(state)
if InCombatLockdown() then
print("|cff8a5cf6Wick's Travel Form|r: cannot change lock during combat.")
return
end
locked = state
if WicksTravelFormDB then WicksTravelFormDB.locked = state end
if locked then moveTint:Hide() else moveTint:Show() end
end
-- Called by Core.lua at PLAYER_LOGIN once we know we're a druid.
function UI:Activate()
locked = not (WicksTravelFormDB and WicksTravelFormDB.locked == false)
if locked then moveTint:Hide() else moveTint:Show() end
self:ApplyPosition()
self:ApplySize()
ApplyBarLayout()
ApplyFloatBarLayout()
self:Refresh()
host:Show()
btn:Show()
end
-- Called when we know the player isn't a druid — hide everything.
function UI:Deactivate()
host:Hide()
barHost:Hide()
floatBar:Hide()
end
-- Build is kept as an alias for /wstf show — same effect as Activate
-- but doesn't depend on having gone through PLAYER_LOGIN cleanly.
function UI:Build()
self:Activate()
end