forked from neun0eil/wow-action-bar-profiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionBarProfiles.lua
452 lines (356 loc) · 13.6 KB
/
ActionBarProfiles.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
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
local addonName, addon = ...
LibStub("AceAddon-3.0"):NewAddon(addon, addonName, "AceConsole-3.0", "AceTimer-3.0", "AceEvent-3.0", "AceSerializer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local DEBUG = "|cffff0000Debug:|r "
local qtip = LibStub("LibQTip-1.0")
local origGetPaperDollSideBarFrame
local ABP_tabNum
function ABP_GetPaperDollSideBarFrame(index)
if index == ABP_tabNum then
return PaperDollActionBarProfilesPane;
else
return origGetPaperDollSideBarFrame(index);
end
end
function addon:cPrintf(cond, ...)
if cond then self:Printf(...) end
end
function addon:cPrint(cond, ...)
if cond then self:Print(...) end
end
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New(addonName .. "DB" .. ABP_DB_VERSION, {
profile = {
minimap = {
hide = false,
},
list = {},
replace_macros = false,
},
}, ({ UnitClass("player") })[2])
self.db.RegisterCallback(self, "OnProfileReset", "UpdateGUI")
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateGUI")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateGUI")
-- chat command
self:RegisterChatCommand("abp", "OnChatCommand")
-- settings page
LibStub("AceConfig-3.0"):RegisterOptionsTable(addonName, self:GetOptions())
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, nil, nil, "general")
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, self.options.args.profiles.name, addonName, "profiles")
-- minimap icon
self.ldb = LibStub("LibDataBroker-1.1"):NewDataObject(addonName, {
type = "launcher",
icon = "Interface\\ICONS\\INV_Misc_Book_09",
label = addonName,
OnEnter = function(...)
self:ShowTooltip(...)
end,
OnLeave = function()
end,
OnClick = function(obj, button)
if button == "RightButton" then
InterfaceOptionsFrame_OpenToCategory(addonName)
else
ToggleCharacter("PaperDollFrame")
end
end,
})
self.icon = LibStub("LibDBIcon-1.0")
self.icon:Register(addonName, self.ldb, self.db.profile.minimap)
origGetPaperDollSideBarFrame = GetPaperDollSideBarFrame
GetPaperDollSideBarFrame = ABP_GetPaperDollSideBarFrame
-- char frame
if PaperDollActionBarProfilesPane then
self:InjectPaperDollSidebarTab(L.charframe_tab, "PaperDollActionBarProfilesPane")
PaperDollActionBarProfilesPane:OnInitialize()
PaperDollActionBarProfilesSaveDialog:OnInitialize()
end
-- events
self:RegisterEvent("PLAYER_REGEN_DISABLED", function(...)
self:UpdateGUI()
end)
self:RegisterEvent("PLAYER_REGEN_ENABLED", function(...)
self:UpdateGUI()
end)
self:RegisterEvent("PLAYER_UPDATE_RESTING", function(...)
self:UpdateGUI()
end)
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", function(...)
if self.specTimer then
self:CancelTimer(self.specTimer)
end
self.specTimer = self:ScheduleTimer(function()
self.specTimer = nil
local player = UnitName("player") .. "-" .. GetRealmName("player")
local spec = GetSpecializationInfo(GetSpecialization())
if not self.prevSpec or self.prevSpec ~= spec then
self.prevSpec = spec
local list = self.db.profile.list
local profile
for profile in table.s2k_values(list) do
if profile.fav and profile.fav[player .. "-" .. spec] then
self:UseProfile(profile)
end
end
end
end, 0.1)
self:UpdateGUI()
end)
self:RegisterEvent("UNIT_AURA", function(event, target)
if target == "player" then
if self.auraTimer then
self:CancelTimer(self.auraTimer)
end
self.auraTimer = self:ScheduleTimer(function()
self.auraTimer = nil
local checkAura = {
({ GetSpellInfo(ABP_TOME_OF_CLEAR_MIND_SPELL_ID) })[1],
({ GetSpellInfo(ABP_TOME_OF_TRANQUIL_MIND_SPELL_ID) })[1],
({ GetSpellInfo(ABP_DUNGEON_PREPARE_SPELL_ID) })[1],
}
local state, index
for index = 1, 40 do
local aura = UnitAura("player", index)
if aura and (aura == checkAura[1] or aura == checkAura[2] or aura == checkAura[3]) then
state = true
end
end
if state ~= self.auraState then
self.auraState = state
self:UpdateGUI()
end
end, 0.1)
end
end)
end
function addon:ParseArgs(message)
local arg, pos = self:GetArgs(message, 1, 1)
if arg then
if pos <= #message then
return arg, message:sub(pos)
else
return arg
end
end
end
function addon:OnChatCommand(message)
local cmd, param = self:ParseArgs(message)
if not cmd then return end
if cmd == "list" or cmd == "ls" then
local list = {}
local profile
for profile in table.s2k_values({ self:GetProfiles() }) do
table.insert(list, string.format("|c%s%s|r",
RAID_CLASS_COLORS[profile.class].colorStr, profile.name
))
end
if #list > 0 then
self:Printf(L.msg_profile_list, strjoin(", ", unpack(list)))
else
self:Printf(L.msg_profile_list_empty)
end
elseif cmd == "save" or cmd == "sv" then
if param then
local profile = self:GetProfiles(param, true)
if profile then
self:UpdateProfile(profile)
else
self:SaveProfile(param)
end
end
elseif cmd == "delete" or cmd == "del" or cmd == "remove" or cmd == "rm" then
if param then
local profile = self:GetProfiles(param, true)
if profile then
self:DeleteProfile(profile.name)
else
self:Printf(L.msg_profile_not_exists, param)
end
end
elseif cmd == "use" or cmd == "load" or cmd == "ld" then
if param then
local profile = self:GetProfiles(param, true)
if profile then
self:UseProfile(profile)
else
self:Printf(L.msg_profile_not_exists, param)
end
end
end
end
function addon:ShowTooltip(anchor)
if not (InCombatLockdown() or (self.tooltip and self.tooltip:IsShown())) then
if not (qtip:IsAcquired(addonName) and self.tooltip) then
self.tooltip = qtip:Acquire(addonName, 2, "LEFT")
self.tooltip.OnRelease = function()
self.tooltip = nil
end
end
if anchor then
self.tooltip:SmartAnchorTo(anchor)
self.tooltip:SetAutoHideDelay(0.05, anchor)
end
self:UpdateTooltip(self.tooltip)
end
end
function addon:UpdateTooltip(tooltip)
tooltip:Clear()
local line = tooltip:AddHeader(ABP_ADDON_NAME)
local profiles = { addon:GetProfiles() }
if #profiles > 0 then
local class = select(2, UnitClass("player"))
local cache = addon:MakeCache()
line = tooltip:AddLine(L.tooltip_list)
tooltip:SetCellTextColor(line, 1, GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
local profile
for profile in table.s2k_values(profiles) do
local line
local name = profile.name
local color = NORMAL_FONT_COLOR
if profile.class ~= class then
color = GRAY_FONT_COLOR
else
local fail, total = addon:UseProfile(profile, true, cache)
if fail > 0 then
color = RED_FONT_COLOR
name = name .. string.format(" (%d/%d)", fail, total)
end
end
if profile.icon then
line = tooltip:AddLine(string.format(
" |T%s:14:14:0:0:32:32:0:32:0:32|t %s",
profile.icon, name
))
else
local coords = CLASS_ICON_TCOORDS[profile.class]
line = tooltip:AddLine(string.format(
" |TInterface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes:14:14:0:0:256:256:%d:%d:%d:%d|t %s",
coords[1] * 256, coords[2] * 256, coords[3] * 256, coords[4] * 256,
name
))
end
tooltip:SetCellTextColor(line, 1, color.r, color.g, color.b)
tooltip:SetLineScript(line, "OnMouseUp", function()
local fail, total = addon:UseProfile(profile, true, cache)
if fail > 0 then
if not self:ShowPopup("CONFIRM_USE_ACTION_BAR_PROFILE", fail, total, { name = profile.name }) then
UIErrorsFrame:AddMessage(ERR_CLIENT_LOCKED_OUT, 1.0, 0.1, 0.1, 1.0)
end
else
addon:UseProfile(profile, false, cache)
end
end)
end
else
line = tooltip:AddLine(L.tooltip_list_empty)
tooltip:SetCellTextColor(line, 1, GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
end
tooltip:AddLine("")
tooltip:UpdateScrolling()
tooltip:Show()
end
function addon:UpdateGUI()
if self.updateTimer then
self:CancelTimer(self.updateTimer)
end
self.updateTimer = self:ScheduleTimer(function()
self.updateTimer = nil
if PaperDollActionBarProfilesPane and PaperDollActionBarProfilesPane:IsShown() then
PaperDollActionBarProfilesPane:Update()
end
if self.tooltip and self.tooltip:IsShown() then
if InCombatLockdown() then
self.tooltip:Hide()
else
self:UpdateTooltip(self.tooltip)
end
end
end, 0.1)
end
local PET_JOURNAL_FLAGS = { LE_PET_JOURNAL_FILTER_COLLECTED, LE_PET_JOURNAL_FILTER_NOT_COLLECTED }
function addon:SavePetJournalFilters()
local saved = { flag = {}, source = {}, type = {} }
saved.text = C_PetJournal.GetSearchFilter()
local i
for i in table.s2k_values(PET_JOURNAL_FLAGS) do
saved.flag[i] = C_PetJournal.IsFilterChecked(i)
end
for i = 1, C_PetJournal.GetNumPetSources() do
saved.source[i] = C_PetJournal.IsPetSourceChecked(i)
end
for i = 1, C_PetJournal.GetNumPetTypes() do
saved.type[i] = C_PetJournal.IsPetTypeChecked(i)
end
return saved
end
function addon:RestorePetJournalFilters(saved)
C_PetJournal.SetSearchFilter(saved.text)
local i
for i in table.s2k_values(PET_JOURNAL_FLAGS) do
C_PetJournal.SetFilterChecked(i, saved.flag[i])
end
for i = 1, C_PetJournal.GetNumPetSources() do
C_PetJournal.SetPetSourceChecked(i, saved.source[i])
end
for i = 1, C_PetJournal.GetNumPetTypes() do
C_PetJournal.SetPetTypeFilter(i, saved.type[i])
end
end
function addon:InjectPaperDollSidebarTab(name, frame)
local tab = #PAPERDOLL_SIDEBARS + 1
ABP_tabNum = tab
PAPERDOLL_SIDEBARS[tab] = { name = name, icon = icon, texCoords = texCoords, IsActive = function() return true end }
-- PAPERDOLL_SIDEBARS[tab] = { name = name, frame = frame, icon = icon, texCoords = texCoords, IsActive = function() return true end }
local button = CreateFrame("Button", "PaperDollSidebarTab" .. tab, PaperDollSidebarTabs, "PaperDollActionBarProfilesButton", tab)
button:SetPoint("RIGHT", PaperDollSidebarTab1, "LEFT", -4, 0)
self:LineUpPaperDollSidebarTabs()
if not self.prevSetLevel then
self.prevSetLevel = PaperDollFrame_SetLevel
PaperDollFrame_SetLevel = function(...)
self.prevSetLevel(...)
local extra = #PAPERDOLL_SIDEBARS - ABP_DEFAULT_PAPERDOLL_NUM_TABS
if CharacterFrameInsetRight:IsVisible() then
local index
for index = 1, CharacterLevelText:GetNumPoints() do
local point, relTo, relPoint, x, y = CharacterLevelText:GetPoint(index)
if point == "CENTER" then
CharacterLevelText:SetPoint(
point, relTo, relPoint,
x - (20 + 10 * extra), y
)
end
end
end
end
end
end
function addon:LineUpPaperDollSidebarTabs()
local extra = #PAPERDOLL_SIDEBARS - ABP_DEFAULT_PAPERDOLL_NUM_TABS
local prev
local index
for index = 1, #PAPERDOLL_SIDEBARS do
local tab = _G["PaperDollSidebarTab" .. index]
if tab then
tab:ClearAllPoints()
tab:SetPoint("BOTTOMRIGHT", (extra < 2 and -20) or (extra < 3 and -10) or 0, 0)
if prev then
prev:ClearAllPoints()
prev:SetPoint("RIGHT", tab, "LEFT", -4, 0)
end
prev = tab
end
end
end
function addon:EncodeLink(data)
return data:gsub(".", function(x)
return ((x:byte() < 32 or x:byte() == 127 or x == "|" or x == ":" or x == "[" or x == "]" or x == "~") and string.format("~%02x", x:byte())) or x
end)
end
function addon:DecodeLink(data)
return data:gsub("~[0-9A-Fa-f][0-9A-Fa-f]", function(x)
return string.char(tonumber(x:sub(2), 16))
end)
end
function addon:PackMacro(macro)
return macro:gsub("^%s+", ""):gsub("%s+\n", "\n"):gsub("\n%s+", "\n"):gsub("%s+$", ""):sub(1)
end