-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
204 lines (183 loc) · 6.18 KB
/
Copy pathCore.lua
File metadata and controls
204 lines (183 loc) · 6.18 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
local ADDON_NAME, ns = ...
local CooldownCall = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceConsole-3.0", "AceEvent-3.0")
ns.Addon = CooldownCall
-- Default whisper message, localized by client language (German vs. English).
local function defaultMessage()
if GetLocale() == "deDE" then
return "{spell} bitte!"
end
return "Use {spell}!"
end
local defaults = {
profile = {
enabled = true,
throttle = 2, -- seconds; ignore repeat clicks of the same call (0 = off)
theme = "dark", -- "dark" or "light"
minimap = { hide = false }, -- LibDBIcon state
bar = {
width = 200,
height = 24,
locked = true,
point = nil, -- { point, relPoint, x, y }
},
calls = {}, -- array of { key, caster, class, spellID, name, role, message, enabled }
},
}
------------------------------------------------------------
-- Call helpers
------------------------------------------------------------
local function newKey()
return ("c%d"):format(math.floor(GetTime() * 1000) % 100000000)
end
function CooldownCall:AddCall(data)
local call = {
key = newKey(),
caster = data.caster,
class = data.class,
spellID = data.spellID,
name = data.name or "?",
role = data.role or "Utility",
cd = data.cd, -- known cooldown in seconds (nil = no timer)
message = defaultMessage(),
enabled = true,
}
table.insert(self.db.profile.calls, call)
return call
end
function CooldownCall:RemoveCall(key)
for i, c in ipairs(self.db.profile.calls) do
if c.key == key then
table.remove(self.db.profile.calls, i)
return true
end
end
return false
end
-- Re-resolve display names from spell ids (locale/spellbook may give a nicer
-- name now than when the call was first created).
function CooldownCall:RefreshNames()
for _, c in ipairs(self.db.profile.calls) do
if c.spellID then
c.name = ns.Spells:Name(c.spellID, c.name)
end
end
end
------------------------------------------------------------
-- Minimap button (LibDataBroker + LibDBIcon)
------------------------------------------------------------
function CooldownCall:SetupMinimap()
local ldb = LibStub("LibDataBroker-1.1", true)
local icon = LibStub("LibDBIcon-1.0", true)
if not ldb or not icon then
return
end
local dataobj = ldb:NewDataObject(ADDON_NAME, {
type = "launcher",
text = "CooldownCall",
icon = "Interface\\Icons\\Spell_Holy_PowerInfusion",
OnClick = function(_, button)
if button == "RightButton" then
CooldownCall.db.profile.enabled = not CooldownCall.db.profile.enabled
CooldownCall:Print("calls " .. (CooldownCall.db.profile.enabled and "enabled" or "disabled"))
else
ns.Options:Toggle()
end
end,
OnTooltipShow = function(tt)
tt:AddLine("CooldownCall")
tt:AddLine("|cffffff00Left-click|r open the options window", 1, 1, 1)
tt:AddLine("|cffffff00Right-click|r toggle calls on/off", 1, 1, 1)
end,
})
icon:Register(ADDON_NAME, dataobj, self.db.profile.minimap)
self.ldbIcon = icon
end
------------------------------------------------------------
-- Lifecycle
------------------------------------------------------------
function CooldownCall:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("CooldownCallDB", defaults, true)
ns.Caller:Initialize(self)
ns.CD:Initialize(self)
ns.Options:Initialize(self)
ns.Bars:Initialize(self)
self:SetupMinimap()
self:RegisterChatCommand("cooldowncall", "HandleSlashCommand")
self:RegisterChatCommand("cdcall", "HandleSlashCommand")
self:RegisterChatCommand("cc", "HandleSlashCommand")
end
function CooldownCall:OnEnable()
self:RefreshNames()
ns.Bars:Refresh()
-- Rebuild bars when the group changes (caster availability / colours), and
-- refresh the options window if it is open so Call buttons enable/disable.
local function onRosterChange()
ns.Bars:Refresh()
if ns.Options.frame and ns.Options.frame:IsShown() then
ns.Options:Refresh()
end
end
self:RegisterEvent("GROUP_ROSTER_UPDATE", onRosterChange)
self:RegisterEvent("PLAYER_ENTERING_WORLD", onRosterChange)
self:Print(("ready. %d calls set up. /cc opens the options."):format(#self.db.profile.calls))
end
------------------------------------------------------------
-- Slash commands
------------------------------------------------------------
local function help(self)
self:Print("commands:")
self:Print(" /cc open / close the options window")
self:Print(" /cc on | off enable / disable sending calls")
self:Print(" /cc lock | unlock lock / unlock the on-screen bars")
self:Print(" /cc minimap toggle the minimap button")
self:Print(" /cc status show current state")
end
function CooldownCall:HandleSlashCommand(input)
local cmd = (input or ""):trim():lower()
if cmd == "" then
ns.Options:Toggle()
elseif cmd == "on" then
self.db.profile.enabled = true
self:Print("calls enabled")
elseif cmd == "off" then
self.db.profile.enabled = false
self:Print("calls disabled")
elseif cmd == "toggle" then
self.db.profile.enabled = not self.db.profile.enabled
self:Print("calls " .. (self.db.profile.enabled and "enabled" or "disabled"))
elseif cmd == "lock" then
ns.Bars:SetLocked(true)
if ns.Options.frame then
ns.Options:UpdateLockLabel()
end
self:Print("bars locked")
elseif cmd == "unlock" then
ns.Bars:SetLocked(false)
if ns.Options.frame then
ns.Options:UpdateLockLabel()
end
self:Print("bars unlocked — drag the handle, then /cc lock")
elseif cmd == "minimap" then
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.ldbIcon then
if self.db.profile.minimap.hide then
self.ldbIcon:Hide(ADDON_NAME)
else
self.ldbIcon:Show(ADDON_NAME)
end
end
self:Print("minimap button " .. (self.db.profile.minimap.hide and "hidden" or "shown"))
elseif cmd == "status" then
self:Print(
("enabled=%s | calls=%d | theme=%s | bar=%dx%d"):format(
tostring(self.db.profile.enabled),
#self.db.profile.calls,
self.db.profile.theme,
self.db.profile.bar.width,
self.db.profile.bar.height
)
)
else
help(self)
end
end