/
Bartender4.lua
executable file
·442 lines (380 loc) · 13.7 KB
/
Bartender4.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
--[[
Copyright (c) 2009, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com >
All rights reserved.
]]
local AceAddon = LibStub("AceAddon-3.0")
Bartender4 = AceAddon:NewAddon("Bartender4", "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4")
local LDB = LibStub("LibDataBroker-1.1", true)
local LDBIcon = LibStub("LibDBIcon-1.0", true)
local defaults = {
profile = {
tooltip = "enabled",
buttonlock = false,
outofrange = "button",
colors = { range = { r = 0.8, g = 0.1, b = 0.1 }, mana = { r = 0.5, g = 0.5, b = 1.0 } },
selfcastmodifier = true,
focuscastmodifier = true,
selfcastrightclick = false,
snapping = true,
blizzardVehicle = false,
minimapIcon = {},
}
}
Bartender4.CONFIG_VERSION = 3
function Bartender4:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("Bartender4DB", defaults)
self.db.RegisterCallback(self, "OnNewProfile", "InitializeProfile")
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateModuleConfigs")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateModuleConfigs")
self.db.RegisterCallback(self, "OnProfileReset", "UpdateModuleConfigs")
self:SetupOptions()
self.Locked = true
self:RegisterEvent("PLAYER_REGEN_DISABLED", "CombatLockdown")
self:HideBlizzard()
self:UpdateBlizzardVehicle()
if LDB then
createLDBLauncher()
end
BINDING_HEADER_Bartender4 = "Bartender4"
BINDING_CATEGORY_Bartender4 = "Action Bars"
BINDING_NAME_BTTOGGLEACTIONBARLOCK = BINDING_NAME_TOGGLEACTIONBARLOCK
for i=1,10 do
if i > 1 then
_G[("BINDING_CATEGORY_BT4BLANK%d"):format(i)] = "Action Bars" -- myBindings2 compat
_G[("BINDING_HEADER_BT4BLANK%d"):format(i)] = "Bartender4 " .. L["Bar %s"]:format(i)
end
for k=1,12 do
_G[("BINDING_NAME_CLICK BT4Button%d:LeftButton"):format(((i-1)*12)+k)] = ("Bartender4 %s %s"):format(L["Bar %s"]:format(i), L["Button %s"]:format(k))
end
end
BINDING_HEADER_BT4PET = "Bartender4 " .. L["Pet Bar"]
BINDING_CATEGORY_BT4PET = "Action Bars"
BINDING_HEADER_BT4STANCE = "Bartender4 " .. L["Stance Bar"]
BINDING_CATEGORY_BT4STANCE = "Action Bars"
for k=1,10 do
_G[("BINDING_NAME_CLICK BT4PetButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Pet Bar"], L["Button %s"]:format(k))
_G[("BINDING_NAME_CLICK BT4StanceButton%d:LeftButton"):format(k)] = ("Bartender4 %s %s"):format(L["Stance Bar"], L["Button %s"]:format(k))
end
end
function Bartender4:HideBlizzard()
-- Hidden parent frame
local UIHider = CreateFrame("Frame")
UIHider:Hide()
self.UIHider = UIHider
MultiBarBottomLeft:SetParent(UIHider)
MultiBarBottomRight:SetParent(UIHider)
MultiBarLeft:SetParent(UIHider)
MultiBarRight:SetParent(UIHider)
-- Hide MultiBar Buttons, but keep the bars alive
for i=1,12 do
_G["ActionButton" .. i]:Hide()
_G["ActionButton" .. i]:UnregisterAllEvents()
_G["ActionButton" .. i]:SetAttribute("statehidden", true)
_G["MultiBarBottomLeftButton" .. i]:Hide()
_G["MultiBarBottomLeftButton" .. i]:UnregisterAllEvents()
_G["MultiBarBottomLeftButton" .. i]:SetAttribute("statehidden", true)
_G["MultiBarBottomRightButton" .. i]:Hide()
_G["MultiBarBottomRightButton" .. i]:UnregisterAllEvents()
_G["MultiBarBottomRightButton" .. i]:SetAttribute("statehidden", true)
_G["MultiBarRightButton" .. i]:Hide()
_G["MultiBarRightButton" .. i]:UnregisterAllEvents()
_G["MultiBarRightButton" .. i]:SetAttribute("statehidden", true)
_G["MultiBarLeftButton" .. i]:Hide()
_G["MultiBarLeftButton" .. i]:UnregisterAllEvents()
_G["MultiBarLeftButton" .. i]:SetAttribute("statehidden", true)
end
--UIPARENT_MANAGED_FRAME_POSITIONS["MultiBarRight"] = nil
--UIPARENT_MANAGED_FRAME_POSITIONS["MultiBarLeft"] = nil
--UIPARENT_MANAGED_FRAME_POSITIONS["MultiBarBottomLeft"] = nil
--UIPARENT_MANAGED_FRAME_POSITIONS["MultiBarBottomRight"] = nil
UIPARENT_MANAGED_FRAME_POSITIONS["MainMenuBar"] = nil
UIPARENT_MANAGED_FRAME_POSITIONS["ShapeshiftBarFrame"] = nil
UIPARENT_MANAGED_FRAME_POSITIONS["PossessBarFrame"] = nil
UIPARENT_MANAGED_FRAME_POSITIONS["PETACTIONBAR_YPOS"] = nil
MainMenuBar:UnregisterAllEvents()
MainMenuBar:Hide()
MainMenuBar:SetParent(UIHider)
--MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
--MainMenuBarArtFrame:UnregisterEvent("BAG_UPDATE")
MainMenuBarArtFrame:UnregisterEvent("ACTIONBAR_PAGE_CHANGED")
--MainMenuBarArtFrame:UnregisterEvent("KNOWN_CURRENCY_TYPES_UPDATE")
--MainMenuBarArtFrame:UnregisterEvent("CURRENCY_DISPLAY_UPDATE")
MainMenuBarArtFrame:UnregisterEvent("ADDON_LOADED")
--MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE")
--MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE")
--MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE")
--MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE")
MainMenuBarArtFrame:Hide()
MainMenuBarArtFrame:SetParent(UIHider)
--MainMenuExpBar:UnregisterAllEvents()
--MainMenuExpBar:Hide()
ShapeshiftBarFrame:UnregisterAllEvents()
ShapeshiftBarFrame:Hide()
ShapeshiftBarFrame:SetParent(UIHider)
BonusActionBarFrame:UnregisterAllEvents()
BonusActionBarFrame:Hide()
BonusActionBarFrame:SetParent(UIHider)
PossessBarFrame:UnregisterAllEvents()
PossessBarFrame:Hide()
PossessBarFrame:SetParent(UIHider)
PetActionBarFrame:UnregisterAllEvents()
PetActionBarFrame:Hide()
PetActionBarFrame:SetParent(UIHider)
if PlayerTalentFrame then
PlayerTalentFrame:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
else
hooksecurefunc("TalentFrame_LoadUI", function() PlayerTalentFrame:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") end)
end
end
function Bartender4:InitializeProfile()
local PresetMod = self:GetModule("Presets")
if not self.finishedLoading then
PresetMod.applyBlizzardOnEnable = true
else
PresetMod:ResetProfile("BLIZZARD")
end
end
function Bartender4:RegisterDefaultsKey(key, subdefaults)
defaults.profile[key] = subdefaults
self.db:RegisterDefaults(defaults)
end
function Bartender4:UpdateModuleConfigs()
local unlock = false
if not self.Locked then
self:Lock()
unlock = true
end
for k,v in AceAddon:IterateModulesOfAddon(self) do
v:ToggleModule()
if v:IsEnabled() and type(v.ApplyConfig) == "function" then
v:ApplyConfig()
end
end
if LDB and LDBIcon then
LDBIcon:Refresh("Bartender4", Bartender4.db.profile.minimapIcon)
end
self:UpdateBlizzardVehicle()
if unlock then
self:Unlock()
end
end
function Bartender4:UpdateBlizzardVehicle()
if self.db.profile.blizzardVehicle then
MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERING_VEHICLE")
MainMenuBarArtFrame:RegisterEvent("UNIT_ENTERED_VEHICLE")
MainMenuBarArtFrame:RegisterEvent("UNIT_EXITING_VEHICLE")
MainMenuBarArtFrame:RegisterEvent("UNIT_EXITED_VEHICLE")
MainMenuBarArtFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
local vehicleModule = Bartender4:GetModule("Vehicle", true)
vehicleModule:Disable()
vehicleModule.blizzardVehicle = true
if not self.vehicleController then
self.vehicleController = CreateFrame("Frame", nil, UIParent, "SecureHandlerStateTemplate")
self.vehicleController:SetAttribute("_onstate-vehicle", [[
if newstate == "vehicle" then
for i=1,6 do
local button, vbutton = ("CLICK BT4Button%d:LeftButton"):format(i), ("VehicleMenuBarActionButton%d"):format(i)
for k=1,select("#", GetBindingKey(button)) do
local key = select(k, GetBindingKey(button))
self:SetBindingClick(true, key, vbutton)
end
-- do the same for the default UIs bindings
button = ("ACTIONBUTTON%d"):format(i)
for k=1,select("#", GetBindingKey(button)) do
local key = select(k, GetBindingKey(button))
self:SetBindingClick(true, key, vbutton)
end
end
else
self:ClearBindings()
end
]])
end
RegisterStateDriver(self.vehicleController, "vehicle", "[vehicleui]vehicle;novehicle")
else
MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERING_VEHICLE")
MainMenuBarArtFrame:UnregisterEvent("UNIT_ENTERED_VEHICLE")
MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITING_VEHICLE")
MainMenuBarArtFrame:UnregisterEvent("UNIT_EXITED_VEHICLE")
MainMenuBarArtFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
local vehicleModule = Bartender4:GetModule("Vehicle")
vehicleModule.blizzardVehicle = nil
if vehicleModule.db and vehicleModule.db.profile.enabled then
vehicleModule:Enable()
end
if self.vehicleController then
UnregisterStateDriver(self.vehicleController, "vehicle")
end
end
end
function Bartender4:CombatLockdown()
self:Lock()
LibStub("AceConfigDialog-3.0"):Close("Bartender4")
end
function Bartender4:ToggleLock()
if self.Locked then
self:Unlock()
else
self:Lock()
end
end
local getSnap, setSnap
do
function getSnap()
return Bartender4.db.profile.snapping
end
function setSnap(value)
Bartender4.Bar:ForAll("StopDragging")
Bartender4.db.profile.snapping = value
LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4")
end
end
function Bartender4:ShowUnlockDialog()
if not self.unlock_dialog then
local f = CreateFrame("Frame", "Bartender4Dialog", UIParent)
f:SetFrameStrata("DIALOG")
f:SetToplevel(true)
f:EnableMouse(true)
f:SetClampedToScreen(true)
f:SetWidth(360)
f:SetHeight(110)
f:SetBackdrop{
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background" ,
edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
insets = {left = 11, right = 12, top = 12, bottom = 11},
tileSize = 32,
edgeSize = 32,
}
f:SetPoint("TOP", 0, -50)
f:Hide()
f:SetScript("OnShow", function() PlaySound("igMainMenuOption") end)
f:SetScript("OnHide", function() PlaySound("gsTitleOptionExit") end)
local tr = f:CreateTitleRegion()
tr:SetAllPoints(f)
local header = f:CreateTexture(nil, "ARTWORK")
header:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
header:SetWidth(256); header:SetHeight(64)
header:SetPoint("TOP", 0, 12)
local title = f:CreateFontString("ARTWORK")
title:SetFontObject("GameFontNormal")
title:SetPoint("TOP", header, "TOP", 0, -14)
title:SetText(L["Bartender4"])
local desc = f:CreateFontString("ARTWORK")
desc:SetFontObject("GameFontHighlight")
desc:SetJustifyV("TOP")
desc:SetJustifyH("LEFT")
desc:SetPoint("TOPLEFT", 18, -32)
desc:SetPoint("BOTTOMRIGHT", -18, 48)
desc:SetText(L["Bars unlocked. Move them now and click Lock when you are done."])
local snapping = CreateFrame("CheckButton", "Bartender4Snapping", f, "OptionsCheckButtonTemplate")
_G[snapping:GetName() .. "Text"]:SetText(L["Bar Snapping"])
snapping:SetScript("OnShow", function(self)
self:SetChecked(getSnap())
end)
snapping:SetScript("OnClick", function(self)
setSnap(snapping:GetChecked())
end)
local lockBars = CreateFrame("CheckButton", "Bartender4DialogLock", f, "OptionsButtonTemplate")
getglobal(lockBars:GetName() .. "Text"):SetText(L["Lock"])
lockBars:SetScript("OnClick", function(self)
Bartender4:Lock()
LibStub("AceConfigRegistry-3.0"):NotifyChange("Bartender4")
end)
--position buttons
snapping:SetPoint("BOTTOMLEFT", 14, 10)
lockBars:SetPoint("BOTTOMRIGHT", -14, 14)
self.unlock_dialog = f
end
self.unlock_dialog:Show()
end
function Bartender4:HideUnlockDialog()
if self.unlock_dialog then
self.unlock_dialog:Hide()
end
end
function Bartender4:Unlock()
if self.Locked then
self.Locked = false
Bartender4.Bar:ForAll("Unlock")
self:ShowUnlockDialog()
end
end
function Bartender4:Lock()
if not self.Locked then
self.Locked = true
Bartender4.Bar:ForAll("Lock")
self:HideUnlockDialog()
end
end
function Bartender4:Merge(target, source)
if type(target) ~= "table" then target = {} end
for k,v in pairs(source) do
if type(v) == "table" then
target[k] = self:Merge(target[k], v)
elseif not target[k] then
target[k] = v
end
end
return target
end
Bartender4.modulePrototype = {}
function Bartender4.modulePrototype:ToggleModule(info, value)
if value ~= nil then
self.db.profile.enabled = value
else
value = self.db.profile.enabled
end
if value and not self:IsEnabled() then
self:Enable()
elseif not value and self:IsEnabled() then
self:Disable()
end
end
function Bartender4.modulePrototype:ToggleOptions()
if self.options then
self.options.args = self:IsEnabled() and self.optionobject.table or self.disabledoptions
end
end
function Bartender4.modulePrototype:OnDisable()
if not self.bar then return end
-- assign new config table
self.bar.config = self.db.profile
self.bar:Disable()
self:ToggleOptions()
end
Bartender4:SetDefaultModulePrototype(Bartender4.modulePrototype)
function createLDBLauncher()
local L_BT_LEFT = L["|cffffff00Click|r to toggle bar lock"]
local L_BT_RIGHT = L["|cffffff00Right-click|r to open the options menu"]
local LDBObj = LibStub("LibDataBroker-1.1"):NewDataObject("Bartender4", {
type = "launcher",
label = "Bartender4",
OnClick = function(_, msg)
if msg == "LeftButton" then
if Bartender4.Locked then
Bartender4["Unlock"](Bartender4)
else
Bartender4["Lock"](Bartender4)
end
elseif msg == "RightButton" then
if LibStub("AceConfigDialog-3.0").OpenFrames["Bartender4"] then
LibStub("AceConfigDialog-3.0"):Close("Bartender4")
else
LibStub("AceConfigDialog-3.0"):Open("Bartender4")
end
end
end,
icon = "Interface\\Icons\\INV_Drink_05",
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine("Bartender4")
tooltip:AddLine(L_BT_LEFT)
tooltip:AddLine(L_BT_RIGHT)
end,
})
if LDBIcon then
LDBIcon:Register("Bartender4", LDBObj, Bartender4.db.profile.minimapIcon)
end
end