-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_requester.lua
More file actions
259 lines (243 loc) · 7.37 KB
/
Copy pathui_requester.lua
File metadata and controls
259 lines (243 loc) · 7.37 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
-- HandGuard ui_requester.lua - floating 3-icon request bar + tooltip
local HG = HandGuard
local bar
local buttons = {}
StaticPopupDialogs["HANDGUARD_DI"] = {
text = "Request Divine Intervention?\n|cffff4444The paladin will sacrifice himself!|r",
button1 = "Request",
button2 = "Cancel",
OnAccept = function() HG.RequestSpell("DI") end,
timeout = 15,
whileDead = 1,
hideOnEscape = 1,
}
-- ------------------------------------------------------------------ badges
local function UpdateBadge(btn)
local key = btn.key
local now = GetTime()
local ready = 0
local soonest = nil
for name, p in pairs(HG.paladins) do
if p.addon and p.cd[key] ~= nil then
local usable = true
if key == "DI" and (not p.reagent or p.reagent < 1) then usable = false end
if usable then
if p.cd[key] <= now then
local unit = HG.UnitIdByName(name)
if not (unit and (UnitIsDeadOrGhost(unit) or not UnitIsConnected(unit))) then
ready = ready + 1
end
else
local rem = p.cd[key] - now
if not soonest or rem < soonest then soonest = rem end
end
end
end
end
btn.count:SetText(ready)
if ready > 0 then
btn.count:SetTextColor(0.3, 1, 0.3)
pcall(btn.icon.SetDesaturated, btn.icon, nil)
btn.timer:SetText("")
else
btn.count:SetTextColor(1, 0.3, 0.3)
pcall(btn.icon.SetDesaturated, btn.icon, 1)
if soonest then
btn.timer:SetText(HG.FmtTime(soonest))
else
btn.timer:SetText("")
end
end
end
-- ------------------------------------------------------------------ tooltip
function HG.UI_Tooltip(btn)
local key = btn.key
local def = HG.SPELLS[key]
GameTooltip:SetOwner(btn, "ANCHOR_RIGHT")
GameTooltip:AddLine("HandGuard - " .. def.name, 1, 0.85, 0.3)
local now = GetTime()
local any = false
for name, p in pairs(HG.paladins) do
any = true
local status, r, g, b
if not p.addon then
if p.cd[key] and p.cd[key] > now then
status = "~" .. HG.FmtTime(p.cd[key] - now) .. " (no addon)"
r, g, b = 0.6, 0.6, 0.6
else
status = "no addon"
r, g, b = 0.5, 0.5, 0.5
end
elseif p.cd[key] == nil then
status = "not learned"
r, g, b = 0.5, 0.5, 0.5
elseif key == "DI" and (not p.reagent or p.reagent < 1) then
status = "no reagent"
r, g, b = 1, 0.4, 0.4
elseif p.cd[key] > now then
status = HG.FmtTime(p.cd[key] - now)
r, g, b = 1, 0.6, 0.2
else
status = "READY"
r, g, b = 0.3, 1, 0.3
local unit = HG.UnitIdByName(name)
if unit and UnitIsDeadOrGhost(unit) then
status = "DEAD"
r, g, b = 1, 0.3, 0.3
end
end
local cr, cg, cb = HG.ClassColor(name)
GameTooltip:AddDoubleLine(name, status, cr, cg, cb, r, g, b)
end
if not any then
GameTooltip:AddLine("No paladin in your group", 0.7, 0.7, 0.7)
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Click: request " .. def.label .. " | Right-click: options", 0.5, 0.7, 1)
GameTooltip:Show()
end
-- ------------------------------------------------------------------ build
local function MakeSpellButton(key)
local def = HG.SPELLS[key]
local btn = CreateFrame("Button", "HandGuardBtn" .. key, bar)
btn:SetWidth(36)
btn:SetHeight(36)
btn.key = key
btn:SetBackdrop({
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 12,
})
btn:SetBackdropBorderColor(def.color[1], def.color[2], def.color[3], 0.9)
btn.icon = btn:CreateTexture(nil, "ARTWORK")
btn.icon:SetPoint("TOPLEFT", btn, "TOPLEFT", 3, -3)
btn.icon:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", -3, 3)
btn.icon:SetTexture(def.icon)
btn.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
btn.count = btn:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
btn.count:SetPoint("BOTTOMRIGHT", btn, "BOTTOMRIGHT", -2, 3)
btn.timer = btn:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
btn.timer:SetPoint("CENTER", btn, "CENTER", 0, 0)
btn.timer:SetTextColor(1, 0.6, 0.2)
btn:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
btn:SetScript("OnClick", function()
if arg1 == "RightButton" then
HG.Options_Toggle()
return
end
if this.key == "DI" then
StaticPopup_Show("HANDGUARD_DI")
else
HG.RequestSpell(this.key)
end
end)
btn:RegisterForDrag("LeftButton")
btn:SetScript("OnDragStart", function()
if not HG.db.locked then bar:StartMoving() end
end)
btn:SetScript("OnDragStop", function()
bar:StopMovingOrSizing()
HG.db.posBar = HG.SavePosition(bar)
end)
btn:SetScript("OnEnter", function() HG.UI_Tooltip(this) end)
btn:SetScript("OnLeave", function() GameTooltip:Hide() end)
buttons[key] = btn
return btn
end
function HG.UI_Init()
bar = CreateFrame("Frame", "HandGuardBar", UIParent)
bar:SetWidth(130)
bar:SetHeight(48)
bar:SetFrameStrata("MEDIUM")
bar:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
bar:SetBackdropColor(0.05, 0.05, 0.08, 0.85)
bar:SetMovable(true)
bar:EnableMouse(true)
bar:RegisterForDrag("LeftButton")
bar:SetScript("OnDragStart", function()
if not HG.db.locked then bar:StartMoving() end
end)
bar:SetScript("OnDragStop", function()
bar:StopMovingOrSizing()
HG.db.posBar = HG.SavePosition(bar)
end)
-- pulse the requested icon while a request is pending
bar:SetScript("OnUpdate", function()
local pd = HG.pending
for i = 1, 3 do
local btn = buttons[HG.SPELL_ORDER[i]]
if btn and btn:IsShown() then
if pd and pd.key == btn.key then
btn:SetAlpha(0.5 + 0.5 * math.abs(math.sin(GetTime() * 5)))
elseif btn:GetAlpha() < 1 then
btn:SetAlpha(1)
end
end
end
end)
for i = 1, 3 do
MakeSpellButton(HG.SPELL_ORDER[i])
end
HG.RestorePosition(bar, HG.db.posBar, "CENTER", 0, -180)
HG.UI_ApplyScale()
HG.UI_ApplyLock()
HG.UI_Refresh()
end
-- ------------------------------------------------------------------ refresh
function HG.UI_Refresh()
if not bar or not HG.db then return end
local shown = 0
local x = 6
for i = 1, 3 do
local key = HG.SPELL_ORDER[i]
local btn = buttons[key]
if HG.db["show" .. key] then
btn:ClearAllPoints()
btn:SetPoint("LEFT", bar, "LEFT", x, 0)
x = x + 41
btn:Show()
shown = shown + 1
UpdateBadge(btn)
else
btn:Hide()
end
end
if shown > 0 then
bar:SetWidth(shown * 41 + 7)
end
local visible = shown > 0
if visible and HG.db.locked and HG.db.hideSolo and not HG.inGroup then
visible = false
end
if visible then
bar:Show()
else
bar:Hide()
end
end
-- ------------------------------------------------------------------ lock / scale
function HG.UI_ApplyLock()
if not bar then return end
if HG.db.locked then
bar:SetBackdropBorderColor(0.8, 0.7, 0.3, 0.9)
else
bar:SetBackdropBorderColor(0.2, 1, 0.2, 1)
end
HG.Alert_ApplyLock()
HG.UI_Refresh()
end
function HG.UI_ApplyScale()
if bar then bar:SetScale(HG.db.scale) end
if HandGuardAlert then HandGuardAlert:SetScale(HG.db.scale) end
end
function HG.UI_ResetPositions()
if bar then
HG.RestorePosition(bar, nil, "CENTER", 0, -180)
end
HG.Alert_ResetPosition()
end