This repository has been archived by the owner on Apr 15, 2022. It is now read-only.
forked from Nevcairiel/Quartz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCD.lua
290 lines (262 loc) · 7.35 KB
/
GCD.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
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
--[[
Copyright (C) 2006-2007 Nymbia
Copyright (C) 2010-2017 Hendrik "Nevcairiel" Leppkes < h.leppkes@gmail.com >
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
]]
local Quartz3 = LibStub("AceAddon-3.0"):GetAddon("Quartz3")
local L = LibStub("AceLocale-3.0"):GetLocale("Quartz3")
local MODNAME = "GCD"
local GCD = Quartz3:NewModule(MODNAME, "AceEvent-3.0")
local Player = Quartz3:GetModule("Player")
----------------------------
-- Upvalues
local CreateFrame, GetTime, UIParent, GetSpellCooldown = CreateFrame, GetTime, UIParent, GetSpellCooldown
local unpack = unpack
local gcdbar, gcdbar_width, gcdspark
local starttime, duration, warned
local db, getOptions
local defaults = {
profile = {
sparkcolor = {1, 1, 1},
gcdalpha = 0.9,
gcdheight = 4,
gcdposition = "bottom",
gcdgap = -4,
deplete = false,
x = 500,
y = 300,
}
}
local function OnUpdate()
if not starttime then return gcdbar:Hide() end
gcdspark:ClearAllPoints()
local perc = (GetTime() - starttime) / duration
if perc > 1 then
return gcdbar:Hide()
else
if db.deplete then
gcdspark:SetPoint("CENTER", gcdbar, "LEFT", gcdbar_width * (1-perc), 0)
else
gcdspark:SetPoint("CENTER", gcdbar, "LEFT", gcdbar_width * perc, 0)
end
end
end
local function OnHide()
gcdbar:SetScript("OnUpdate", nil)
end
local function OnShow()
gcdbar:SetScript("OnUpdate", OnUpdate)
end
function GCD:OnInitialize()
self.db = Quartz3.db:RegisterNamespace(MODNAME, defaults)
db = self.db.profile
self:SetEnabledState(Quartz3:GetModuleEnabled(MODNAME))
Quartz3:RegisterModuleOptions(MODNAME, getOptions, L["GCD"])
end
function GCD:OnEnable()
--self:RegisterEvent("UNIT_SPELLCAST_SENT","CheckGCD")
self:RegisterEvent("UNIT_SPELLCAST_START","CheckGCD")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED","CheckGCD")
if not gcdbar then
gcdbar = CreateFrame("Frame", "Quartz3GCDBar", UIParent, "BackdropTemplate")
gcdbar:SetFrameStrata("HIGH")
gcdbar:SetScript("OnShow", OnShow)
gcdbar:SetScript("OnHide", OnHide)
gcdbar:SetMovable(true)
gcdbar:RegisterForDrag("LeftButton")
gcdbar:SetClampedToScreen(true)
gcdspark = gcdbar:CreateTexture(nil, "DIALOG")
gcdbar:Hide()
end
self:ApplySettings()
end
function GCD:OnDisable()
gcdbar:Hide()
end
function GCD:CheckGCD(event, unit, guid, spell)
if unit == "player" then
local start, dur = GetSpellCooldown(spell)
if dur and dur > 0 and dur <= 1.5 then
starttime = start
duration = dur
gcdbar:Show()
end
end
end
function GCD:ApplySettings()
db = self.db.profile
if gcdbar and self:IsEnabled() then
gcdbar:ClearAllPoints()
gcdbar:SetHeight(db.gcdheight)
gcdbar_width = Player.Bar:GetWidth() - 8
gcdbar:SetWidth(gcdbar_width)
gcdbar:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16})
gcdbar:SetBackdropColor(0,0,0)
gcdbar:SetAlpha(db.gcdalpha)
gcdbar:SetScale(Player.db.profile.scale)
if db.gcdposition == "bottom" then
gcdbar:SetPoint("TOP", Player.Bar, "BOTTOM", 0, -1 * db.gcdgap)
elseif db.gcdposition == "top" then
gcdbar:SetPoint("BOTTOM", Player.Bar, "TOP", 0, db.gcdgap)
else -- L["Free"]
gcdbar:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", db.x, db.y)
end
gcdspark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
gcdspark:SetVertexColor(unpack(db.sparkcolor))
gcdspark:SetBlendMode("ADD")
gcdspark:SetWidth(25)
gcdspark:SetHeight(db.gcdheight*2.5)
end
end
do
local locked = true
local function nothing()
end
local function dragstart()
gcdbar:StartMoving()
end
local function dragstop()
db.x = gcdbar:GetLeft()
db.y = gcdbar:GetBottom()
gcdbar:StopMovingOrSizing()
end
local function hiddennofree()
return db.gcdposition ~= "free"
end
local function setOpt(info, value)
db[info[#info]] = value
GCD:ApplySettings()
end
local function getOpt(info)
return db[info[#info]]
end
local function getColor(info)
return unpack(getOpt(info))
end
local function setColor(info, r, g, b, a)
setOpt(info, {r, g, b, a})
end
local options
function getOptions()
if not options then
options = {
type = "group",
name = L["Global Cooldown"],
order = 600,
get = getOpt,
set = setOpt,
args = {
toggle = {
type = "toggle",
name = L["Enable"],
desc = L["Enable"],
get = function()
return Quartz3:GetModuleEnabled(MODNAME)
end,
set = function(info, v)
Quartz3:SetModuleEnabled(MODNAME, v)
end,
order = 100,
},
sparkcolor = {
type = "color",
name = L["Spark Color"],
desc = L["Set the color of the GCD bar spark"],
get = getColor,
set = setColor,
order = 103,
},
gcdheight = {
type = "range",
name = L["Height"],
desc = L["Set the height of the GCD bar"],
min = 1, max = 30, step = 1,
order = 104,
},
gcdalpha = {
type = "range",
name = L["Alpha"],
desc = L["Set the alpha of the GCD bar"],
min = 0.05, max = 1, bigStep = 0.05,
isPercent = true,
order = 105,
},
gcdposition = {
type = "select",
name = L["Bar Position"],
desc = L["Set the position of the GCD bar"],
values = {["top"] = L["Top"], ["bottom"] = L["Bottom"], ["free"] = L["Free"]},
order = 106,
},
lock = {
type = "toggle",
name = L["Lock"],
desc = L["Toggle Cast Bar lock"],
get = function()
return locked
end,
set = function(info, v)
if v then
gcdbar.Hide = nil
gcdbar:EnableMouse(false)
gcdbar:SetScript("OnDragStart", nil)
gcdbar:SetScript("OnDragStop", nil)
gcdbar:Hide()
else
gcdbar:Show()
gcdbar:EnableMouse(true)
gcdbar:SetScript("OnDragStart", dragstart)
gcdbar:SetScript("OnDragStop", dragstop)
gcdbar:SetAlpha(1)
gcdbar.Hide = nothing
end
locked = v
end,
hidden = hiddennofree,
order = 107,
},
x = {
type = "range",
name = L["X"],
desc = L["Set an exact X value for this bar's position."],
min = 0, max = 2560, step = 1,
order = 108,
hidden = hiddennofree,
},
y = {
type = "range",
name = L["Y"],
desc = L["Set an exact Y value for this bar's position."],
min = 0, max = 1600, step = 1,
order = 108,
hidden = hiddennofree,
},
gcdgap = {
type = "range",
name = L["Gap"],
desc = L["Tweak the distance of the GCD bar from the cast bar"],
min = -35, max = 35, step = 1,
order = 109,
},
deplete = {
type = "toggle",
name = L["Deplete"],
desc = L["Reverses the direction of the GCD spark, causing it to move right-to-left"],
order = 110,
},
},
}
end
return options
end
end