forked from Mortalknight/GW2_UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGW2_ui.lua
More file actions
610 lines (518 loc) · 16.3 KB
/
GW2_ui.lua
File metadata and controls
610 lines (518 loc) · 16.3 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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
local _, GW = ...
local RoundInt = GW.RoundInt
local GetSetting = GW.GetSetting
local SetSetting = GW.SetSetting
local GetDefault = GW.GetDefault
local bloodSpark = GW.BLOOD_SPARK
local CLASS_ICONS = GW.CLASS_ICONS
local IsFrameModified = GW.IsFrameModified
local Debug = GW.Debug
GW.VERSION_STRING = "GW2_UI @project-version@"
local loaded = false
local forcedMABags = false
local MOVABLE_FRAMES = {}
GW.MOVABLE_FRAMES = MOVABLE_FRAMES
local MOVABLE_FRAMES_REF = {}
local MOVABLE_FRAMES_SETTINGS_KEY = {}
local swimAnimation = 0
local lastSwimState = true
if Profiler then
_G.GW_Addon_Scope = GW
end
local function disableMABags()
local bags = GetSetting("BAGS_ENABLED")
if not bags or not MovAny or not MADB then
return
end
MADB.noBags = true
MAOptNoBags:SetEnabled(false)
forcedMABags = true
end
GW.AddForProfiling("index", "disableMABags", disableMABags)
local function lockableOnClick(name, frame, moveframe, settingsName, lockAble)
local dummyPoint = GetDefault(settingsName)
moveframe:ClearAllPoints()
moveframe:SetPoint(
dummyPoint["point"],
UIParent,
dummyPoint["relativePoint"],
dummyPoint["xOfs"],
dummyPoint["yOfs"]
)
MOVABLE_FRAMES[name] = moveframe
MOVABLE_FRAMES_REF[name] = frame
MOVABLE_FRAMES_SETTINGS_KEY[name] = settingsName
local point, _, relativePoint, xOfs, yOfs = moveframe:GetPoint()
local new_point = GetSetting(settingsName)
new_point["point"] = point
new_point["relativePoint"] = relativePoint
new_point["xOfs"] = math.floor(xOfs)
new_point["yOfs"] = math.floor(yOfs)
SetSetting(settingsName, new_point)
SetSetting(lockAble, true)
end
GW.AddForProfiling("index", "lockableOnClick", lockableOnClick)
local function lockFrame_OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:ClearLines()
GameTooltip:AddLine("Lock to default position", 1, 1, 1)
GameTooltip:Show()
end
GW.AddForProfiling("index", "lockFrame_OnEnter", lockFrame_OnEnter)
local function mover_OnDragStart(self)
self.IsMoving = true
self:StartMoving()
end
GW.AddForProfiling("index", "mover_OnDragStart", mover_OnDragStart)
local function mover_OnDragStop(self)
local settingsName = self.gw_Settings
local lockAble = self.gw_Lockable
self:StopMovingOrSizing()
local point, _, relativePoint, xOfs, yOfs = self:GetPoint()
local new_point = GetSetting(settingsName)
new_point["point"] = point
new_point["relativePoint"] = relativePoint
new_point["xOfs"] = math.floor(xOfs)
new_point["yOfs"] = math.floor(yOfs)
SetSetting(settingsName, new_point)
if lockAble ~= nil then
SetSetting(lockAble, false)
end
self.IsMoving = false
end
GW.AddForProfiling("index", "mover_OnDragStop", mover_OnDragStop)
local function RegisterMovableFrame(name, frame, settingsName, dummyFrame, lockAble)
local moveframe = CreateFrame("Frame", name .. "MoveAble", UIParent, dummyFrame)
moveframe:SetSize(frame:GetSize())
moveframe.frameName:SetText(name)
moveframe.gw_Settings = settingsName
moveframe.gw_Lockable = lockAble
local dummyPoint = GetSetting(settingsName)
moveframe:ClearAllPoints()
moveframe:SetPoint(
dummyPoint["point"],
UIParent,
dummyPoint["relativePoint"],
dummyPoint["xOfs"],
dummyPoint["yOfs"]
)
MOVABLE_FRAMES[name] = moveframe
MOVABLE_FRAMES_REF[name] = frame
MOVABLE_FRAMES_SETTINGS_KEY[name] = settingsName
moveframe:Hide()
moveframe:RegisterForDrag("LeftButton")
if lockAble ~= nil then
local lockFrame = CreateFrame("Button", name .. "LockButton", moveframe, "GwDummyLockButton")
lockFrame:SetScript("OnEnter", lockFrame_OnEnter)
lockFrame:SetScript("OnLeave", GameTooltip_Hide)
lockFrame:SetScript(
"OnClick",
function()
lockableOnClick(name, frame, moveframe, settingsName, lockAble)
end
)
end
moveframe:SetScript("OnDragStart", mover_OnDragStart)
moveframe:SetScript("OnDragStop", mover_OnDragStop)
end
GW.RegisterMovableFrame = RegisterMovableFrame
local function UpdateFramePositions()
for k, v in pairs(MOVABLE_FRAMES_REF) do
local newp = GetSetting(MOVABLE_FRAMES_SETTINGS_KEY[k])
v:ClearAllPoints()
MOVABLE_FRAMES_REF[k]:SetPoint(newp["point"], UIParent, newp["relativePoint"], newp["xOfs"], newp["yOfs"])
end
end
GW.UpdateFramePositions = UpdateFramePositions
-- https://us.battle.net/forums/en/wow/topic/6036615884
if AchievementMicroButton_Update == nil then
function AchievementMicroButton_Update()
return
end
end
local animations = {}
GW.animations = animations
local function AddToAnimation(name, from, to, start, duration, method, easeing, onCompleteCallback, doCompleteOnOverider)
newAnimation = true
if animations[name] ~= nil then
if (animations[name]["start"] + animations[name]["duration"]) > GetTime() then
newAnimation = false
end
end
if doCompleteOnOverider == nil then
newAnimation = true
end
if newAnimation == false then
animations[name]["duration"] = duration
animations[name]["to"] = to
animations[name]["progress"] = 0
animations[name]["method"] = method
animations[name]["completed"] = false
animations[name]["easeing"] = easeing
animations[name]["onCompleteCallback"] = onCompleteCallback
else
animations[name] = {}
animations[name]["start"] = start
animations[name]["duration"] = duration
animations[name]["from"] = from
animations[name]["to"] = to
animations[name]["progress"] = 0
animations[name]["method"] = method
animations[name]["completed"] = false
animations[name]["easeing"] = easeing
animations[name]["onCompleteCallback"] = onCompleteCallback
end
end
GW.AddToAnimation = AddToAnimation
local function buttonAnim(self, name, w, hover)
local prog = animations[name]["progress"]
local l = GW.lerp(0, w, prog)
hover:SetPoint("RIGHT", self, "LEFT", l, 0)
hover:SetVertexColor(1, 1, 1, GW.lerp(0, 1, ((prog) - 0.5) / 0.5))
end
GW.AddForProfiling("index", "buttonAnim", buttonAnim)
function GwStandardButton_OnEnter(self)
local name = tostring(self)
local w = self:GetWidth()
local hover = self.hover
if not hover then
return
end
hover:SetAlpha(1)
self.animationValue = 0
AddToAnimation(
name,
self.animationValue,
1,
GetTime(),
0.2,
function()
buttonAnim(self, name, w, hover)
end
)
end
function GwStandardButton_OnLeave(self)
local name = tostring(self)
local w = self:GetWidth()
local hover = self.hover
if not hover then
return
end
hover:SetAlpha(1)
self.animationValue = 1
AddToAnimation(
name,
self.animationValue,
0,
GetTime(),
0.2,
function()
buttonAnim(self, name, w, hover)
end
)
end
function gw_button_font_black_OnLoad(self)
self:SetFont(GwLocalization["FONT_BOLD"], 14)
end
local function barAnimation(self, barWidth, sparkWidth)
local snap = (animations[self.animationName]["progress"] * 100) / 5
local round_closest = 0.05 * snap
local spark_min = math.floor(snap)
local spark_current = snap
local spark_prec = spark_current - spark_min
local spark =
math.min(barWidth - sparkWidth, math.floor(barWidth * round_closest) - math.floor(sparkWidth * spark_prec))
local bI = 17 - math.max(1, RoundInt(16 * spark_prec))
self.spark:SetTexCoord(bloodSpark[bI].left, bloodSpark[bI].right, bloodSpark[bI].top, bloodSpark[bI].bottom)
self:SetValue(round_closest)
self.spark:ClearAllPoints()
self.spark:SetPoint("LEFT", spark, 0)
end
GW.AddForProfiling("index", "barAnimation", barAnimation)
local function Bar(self, value)
if self == nil then
return
end
local barWidth = self:GetWidth()
local sparkWidth = self.spark:GetWidth()
AddToAnimation(
self.animationName,
self.animationValue,
value,
GetTime(),
0.2,
function()
barAnimation(self, barWidth, sparkWidth)
end
)
self.animationValue = value
end
GW.Bar = Bar
local function SetClassIcon(self, class)
if class == nil or class > 12 then
class = 0
end
self:SetTexCoord(CLASS_ICONS[class].l, CLASS_ICONS[class].r, CLASS_ICONS[class].t, CLASS_ICONS[class].b)
end
GW.SetClassIcon = SetClassIcon
local function SetDeadIcon(self)
self:SetTexCoord(CLASS_ICONS["dead"].l, CLASS_ICONS["dead"].r, CLASS_ICONS["dead"].t, CLASS_ICONS["dead"].b)
end
GW.SetDeadIcon = SetDeadIcon
local function StopAnimation(k)
if animations[k] ~= nil then
animations[k] = nil
end
end
GW.StopAnimation = StopAnimation
local l = CreateFrame("Frame", nil, UIParent)
local function swimAnim()
local r, g, b = _G["GwActionBarHudRIGHTSWIM"]:GetVertexColor()
_G["GwActionBarHudRIGHTSWIM"]:SetVertexColor(r, g, b, animations["swimAnimation"]["progress"])
_G["GwActionBarHudLEFTSWIM"]:SetVertexColor(r, g, b, animations["swimAnimation"]["progress"])
end
GW.AddForProfiling("index", "swimAnim", swimAnim)
local updateCB = {}
local function AddUpdateCB(func, payload)
if type(func) ~= "function" then
return
end
tinsert(
updateCB,
{
["func"] = func,
["payload"] = payload
}
)
end
GW.AddUpdateCB = AddUpdateCB
local function gw_OnUpdate(self, elapsed)
local foundAnimation = false
local count = 0
for k, v in pairs(animations) do
count = count + 1
if v["completed"] == false and GetTime() >= (v["start"] + v["duration"]) then
if v["easeing"] == nil then
v["progress"] = GW.lerp(v["from"], v["to"], math.sin(1 * math.pi * 0.5))
else
v["progress"] = GW.lerp(v["from"], v["to"], 1)
end
if v["method"] ~= nil then
v["method"](v["progress"])
end
if v["onCompleteCallback"] ~= nil then
v["onCompleteCallback"]()
end
v["completed"] = true
foundAnimation = true
end
if v["completed"] == false then
if v["easeing"] == nil then
v["progress"] =
GW.lerp(v["from"], v["to"], math.sin((GetTime() - v["start"]) / v["duration"] * math.pi * 0.5))
else
v["progress"] = GW.lerp(v["from"], v["to"], (GetTime() - v["start"]) / v["duration"])
end
v["method"](v["progress"])
foundAnimation = true
end
end
if foundAnimation == false and count ~= 0 then
table.wipe(animations)
end
--Swim hud
if lastSwimState ~= IsSwimming() then
if IsSwimming() then
AddToAnimation("swimAnimation", swimAnimation, 1, GetTime(), 0.1, swimAnim)
swimAnimation = 1
else
AddToAnimation("swimAnimation", swimAnimation, 0, GetTime(), 3.0, swimAnim)
swimAnimation = 0
end
lastSwimState = IsSwimming()
end
for _, cb in ipairs(updateCB) do
cb.func(cb.payload, elapsed)
end
end
GW.AddForProfiling("index", "gw_OnUpdate", gw_OnUpdate)
local function gw_OnEvent(self, event, name)
if loaded then
return
end
if event ~= "PLAYER_LOGIN" then
return
end
loaded = true
-- setup our frame pool
GW.Pools = CreatePoolCollection()
-- disable Move Anything bag handling
disableMABags()
-- hook debug output if relevant
--@debug@
local dev_dbg_tab = GetSetting("DEV_DBG_CHAT_TAB")
if dev_dbg_tab and dev_dbg_tab > 0 and _G["ChatFrame" .. dev_dbg_tab] then
DEFAULT_CHAT_FRAME:AddMessage("hooking Debug to chat tab #" .. dev_dbg_tab)
GW.dbgTab = dev_dbg_tab
GW.AlertTestsSetup()
GW.inDebug = true
else
GW.inDebug = false
end
--@end-debug@
--[===[@non-debug@
GW.inDebug = false
--@end-non-debug@]===]
--Create Settings window
GW.LoadSettings()
GW.DisplaySettings()
--Create hud art
GW.LoadHudArt()
--Create experiencebar
if GetSetting("XPBAR_ENABLED") then
GW.LoadXPBar()
end
if GetSetting("FONTS_ENABLED") then
GW.LoadFonts()
end
if GetSetting("CASTINGBAR_ENABLED") then
GW.LoadCastingBar()
end
if GetSetting("MINIMAP_ENABLED") then
GW.LoadMinimap()
end
if GetSetting("QUESTTRACKER_ENABLED") then
GW.LoadQuestTracker()
end
if GetSetting("TOOLTIPS_ENABLED") then
GW.LoadTooltips()
end
if GetSetting("QUESTVIEW_ENABLED") then
GW.LoadQuestview()
end
if GetSetting("CHATFRAME_ENABLED") then
GW.LoadChat()
end
--Create player hud
if GetSetting("HEALTHGLOBE_ENABLED") then
GW.LoadPlayerHud()
end
if GetSetting("POWERBAR_ENABLED") then
GW.LoadPowerBar()
end
if GetSetting("CLASS_POWER") then
GW.LoadClassPowers()
end
if GetSetting("BAGS_ENABLED") then
GW.LoadBag()
GW.LoadBank()
end
--if GetSetting("USE_BATTLEGROUND_HUD") then
-- GW.LoadBattlegrounds()
--end
GW.LoadCharacter()
GW.LoadBreathMeter()
--Create unitframes
if GetSetting("FOCUS_ENABLED") then
GW.LoadFocus()
if GetSetting("focus_TARGET_ENABLED") then
GW.LoadTargetOfFocus()
end
end
if GetSetting("TARGET_ENABLED") then
GW.LoadTarget()
if GetSetting("target_TARGET_ENABLED") then
GW.LoadTargetOfTarget()
end
-- move zone text frame
if not IsFrameModified("ZoneTextFrame") then
Debug("moving ZoneTextFrame")
ZoneTextFrame:ClearAllPoints()
ZoneTextFrame:SetPoint("TOP", UIParent, "TOP", 0, -175)
end
-- move error frame
if not IsFrameModified("UIErrorsFrame") then
Debug("moving UIErrorsFrame")
UIErrorsFrame:ClearAllPoints()
UIErrorsFrame:SetPoint("TOP", UIParent, "TOP", 0, -190)
UIErrorsFrame:SetFont(STANDARD_TEXT_FONT, 14)
end
end
-- create action bars
if GetSetting("ACTIONBARS_ENABLED") then
GW.LoadActionBars()
end
-- create pet frame
if GetSetting("PETBAR_ENABLED") then
GW.LoadPetFrame()
end
-- create buff frame
if GetSetting("PLAYER_BUFFS_ENABLED") then
GW.LoadBuffs()
end
-- create new microbuttons
--[[
if GetSetting('CHATBUBBLES_ENABLED') then
GW.LoadChatBubbles()
end
--]]
GW.LoadMicroMenu()
if GetSetting("GROUP_FRAMES") then
GW.LoadPartyFrames()
GW.LoadRaidFrames()
end
GW.UpdateHudScale()
if (forcedMABags) then
GW.Notice(GwLocalization["DISABLED_MA_BAGS"])
end
l:SetScript("OnUpdate", gw_OnUpdate)
end
GW.AddForProfiling("index", "gw_OnEvent", gw_OnEvent)
l:SetScript("OnEvent", gw_OnEvent)
l:RegisterEvent("PLAYER_LOGIN")
local function AddToClique(frame)
if type(frame) == "string" then
local frameName = frame
frame = _G[frameName]
end
if frame and frame.RegisterForClicks and ClickCastFrames ~= nil then
ClickCastFrames[frame] = true
end
end
GW.AddToClique = AddToClique
local waitTable = {}
local waitFrame = nil
local function wait_OnUpdate(self, elapse)
local count = #waitTable
local i = 1
while (i <= count) do
local waitRecord = tremove(waitTable, i)
local d = tremove(waitRecord, 1)
local f = tremove(waitRecord, 1)
local p = tremove(waitRecord, 1)
if (d > elapse) then
tinsert(waitTable, i, {d - elapse, f, p})
i = i + 1
else
count = count - 1
f(unpack(p))
end
end
end
GW.AddForProfiling("index", "wait_OnUpdate", wait_OnUpdate)
local function Wait(delay, func, ...)
if type(delay) ~= "number" or type(func) ~= "function" then
return false
end
if waitFrame == nil then
waitFrame = CreateFrame("Frame", "GwWaitFrame", UIParent)
waitFrame:SetScript("OnUpdate", wait_OnUpdate)
end
tinsert(waitTable, {delay, func, {...}})
return true
end
GW.Wait = Wait
local function Self_Hide(self)
self:Hide()
end
GW.Self_Hide = Self_Hide