-
Notifications
You must be signed in to change notification settings - Fork 8
/
UI.lua
134 lines (113 loc) · 3.61 KB
/
UI.lua
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
local RaidNotifier = RaidNotifier
local UI = RaidNotifier.UI
do
local UI_FRAGMENT
local function GetKey(c, s)
return c.."_"..s
end
function UI.AddFragment()
if not UI_FRAGMENT then
UI_FRAGMENT = ZO_HUDFadeSceneFragment:New(RaidNotifierUI)
end
HUD_SCENE:AddFragment(UI_FRAGMENT)
HUD_UI_SCENE:AddFragment(UI_FRAGMENT)
UI.LoadElements()
end
function UI.RemoveFragment()
if not UI_FRAGMENT then
UI_FRAGMENT = ZO_HUDFadeSceneFragment:New(RaidNotifierUI)
end
HUD_SCENE:RemoveFragment(UI_FRAGMENT)
HUD_UI_SCENE:RemoveFragment(UI_FRAGMENT)
end
local elements = {}
function UI.RegisterElement(control, hidden)
elements[GetKey(control.category, control.setting)] = control
control:SetHandler("OnMoveStop", UI.SaveElement)
-- update handler, name of handler as string in the "RaidNotifier.UI" namespace
if control.onUpdate ~= nil then
control:SetHandler("OnUpdate", function() UI[control.onUpdate](control) end)
end
if hidden ~= nil then
control:SetHidden(hidden)
end
end
function UI.LoadElements()
local parent = RaidNotifierUI
for k, elem in pairs(elements) do
local settings = RaidNotifier.Vars[elem.category]
elem:ClearAnchors()
elem:SetAnchor(TOPLEFT, parent, TOPLEFT, unpack(settings[elem.setting]))
end
end
function UI.SaveElement(control)
local settings = RaidNotifier.Vars[control.category]
settings[control.setting] = {control:GetLeft(), control:GetTop()}
end
function UI.SetElementHidden(category, setting, hidden)
local control = elements[GetKey(category, setting)]
if control then -- and control:IsHidden() ~= hidden then
control:SetHidden(hidden)
end
end
function UI.GetElement(category, setting)
return elements[GetKey(category, setting)]
end
end
-- -----------------
-- -- GLYPH WINDOW
do -----------------
local window = nil
function UI.StartGlyphTimer(index, cooldown)
window = window or UI.GetElement("mawLorkhaj", "zhaj_glyph_window")
if not window then return end
local glyph = window.glyphs[index]
if not glyph then return end
glyph.timer:SetText(ZO_FormatTimeMilliseconds(cooldown, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL_SHOW_TENTHS_SECS))
glyph.start = GetFrameTimeMilliseconds()
glyph.cooldown = cooldown
glyph.timer:SetHidden(false)
glyph.overlay:SetHidden(true)
end
function UI.StopGlyphTimer(index)
window = window or UI.GetElement("mawLorkhaj", "zhaj_glyph_window")
if not window then return end
local glyph = window.glyphs[index]
if not glyph then return end
glyph.timer:SetHidden(true)
glyph.start = 0
glyph.overlay:SetHidden(false)
end
function UI.SetupGlyphWindow(window, inverted)
window = window or UI.GetElement("mawLorkhaj", "zhaj_glyph_window")
if not window then return end
for _, control in ipairs(window.glyphs) do
local isValidAnchor, point, relativeTo, relativePoint, offsetX, offsetY = control:GetAnchor()
control:ClearAnchors()
offsetY = math.abs(offsetY)
if inverted then
point = BOTTOM
offsetY = offsetY * -1
else
point = TOP
end
control:SetAnchor(point, nil, nil, offsetX, offsetY)
end
end
function UI.GlyphUpdateHandler(window)
window = window or UI.GetElement("mawLorkhaj", "zhaj_glyph_window")
if not window then return end
for i, glyph in ipairs(window.glyphs) do
if glyph.start > 0 then
local duration = glyph.start + glyph.cooldown - GetFrameTimeMilliseconds()
if duration <= 0 then
glyph.start = 0
glyph.timer:SetHidden(true)
glyph.overlay:SetHidden(false)
else
glyph.timer:SetText(ZO_FormatTimeMilliseconds(duration, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL_SHOW_TENTHS_SECS))
end
end
end
end
end