-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
PetBar.lua
165 lines (140 loc) · 4.89 KB
/
PetBar.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
--[[
Copyright (c) 2009-2017, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com >
All rights reserved.
]]
local _, Bartender4 = ...
local L = LibStub("AceLocale-3.0"):GetLocale("Bartender4")
-- register module
local PetBarMod = Bartender4:NewModule("PetBar", "AceEvent-3.0")
-- fetch upvalues
local ActionBars = Bartender4:GetModule("ActionBars")
local ButtonBar = Bartender4.ButtonBar.prototype
local WoWRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
local WoWWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
local WoWCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
local setmetatable, select = setmetatable, select
-- GLOBALS: InCombatLockdown, ClearOverrideBindings, GetBindingKey, SetOverrideBindingClick
-- create prototype information
local PetBar = setmetatable({}, {__index = ButtonBar})
local defaults = { profile = Bartender4.Util:Merge({
enabled = true,
hidehotkey = true,
showgrid = false,
visibility = {
nopet = true,
vehicle = true,
},
}, Bartender4.ButtonBar.defaults) }
function PetBarMod:OnInitialize()
self.db = Bartender4.db:RegisterNamespace("PetBar", defaults)
self:SetEnabledState(self.db.profile.enabled)
end
function PetBarMod:OnEnable()
if not self.bar then
self.bar = setmetatable(Bartender4.ButtonBar:Create("PetBar", self.db.profile, L["Pet Bar"]), {__index = PetBar})
local buttons = {}
for i=1,10 do
buttons[i] = Bartender4.PetButton:Create(i, self.bar)
end
self.bar.buttons = buttons
self.bar:SetScript("OnEvent", PetBar.OnEvent)
end
self.bar:Enable()
self.bar:RegisterEvent("PLAYER_CONTROL_LOST")
self.bar:RegisterEvent("PLAYER_CONTROL_GAINED")
self.bar:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED")
self.bar:RegisterEvent("UNIT_PET")
self.bar:RegisterEvent("UNIT_FLAGS")
self.bar:RegisterEvent("PET_BAR_UPDATE")
self.bar:RegisterEvent("PET_BAR_UPDATE_COOLDOWN")
self.bar:RegisterEvent("PET_BAR_UPDATE_USABLE")
self.bar:RegisterEvent("PET_UI_UPDATE")
self.bar:RegisterEvent("PLAYER_TARGET_CHANGED")
if WoWRetail or WoWWrath or WoWCata then
self.bar:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR")
end
self.bar:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED")
self.bar:RegisterUnitEvent("UNIT_AURA", "pet")
self.bar:RegisterEvent("PET_BAR_SHOWGRID")
self.bar:RegisterEvent("PET_BAR_HIDEGRID")
self:ApplyConfig()
self:ToggleOptions()
self:RegisterEvent("UPDATE_BINDINGS", "ReassignBindings")
self:ReassignBindings()
end
function PetBarMod:ReassignBindings()
if InCombatLockdown() then return end
if not self.bar or not self.bar.buttons then return end
ClearOverrideBindings(self.bar)
if not WoWRetail then
for i = 1, 10 do
local button, real_button = ("BONUSACTIONBUTTON%d"):format(i), ("CLICK BT4PetButton%d:LeftButton"):format(i)
for k=1, select('#', GetBindingKey(real_button)) do
local key = select(k, GetBindingKey(real_button))
SetOverrideBinding(self.bar, false, key, button)
end
end
else
for i = 1, 10 do
local button, real_button = ("BONUSACTIONBUTTON%d"):format(i), ("BT4PetButton%d"):format(i)
for k=1, select('#', GetBindingKey(button)) do
local key = select(k, GetBindingKey(button))
SetOverrideBindingClick(self.bar, false, key, real_button)
end
end
end
end
function PetBarMod:GetGrid()
return self.db.profile.showgrid
end
function PetBarMod:SetGrid(grid)
self.db.profile.showgrid = grid
self.bar:ForAll("ShowGrid")
self.bar:ForAll("HideGrid")
end
function PetBarMod:SetHideBorder(state)
if state ~= nil then
self.db.profile.hideborder = state
end
self.bar:ForAll("Update")
end
function PetBarMod:GetHideBorder()
return self.db.profile.hideborder
end
function PetBarMod:ApplyConfig()
if not self:IsEnabled() then return end
self.bar:ApplyConfig(self.db.profile)
self:ReassignBindings()
end
PetBar.button_width = 30
PetBar.button_height = 30
function PetBar:OnEvent(event, arg1)
if ( event == "PET_BAR_UPDATE" or (event == "UNIT_PET" and arg1 == "player") or event == "PET_UI_UPDATE" or event == "UPDATE_VEHICLE_ACTIONBAR") then
self:ForAll("Update")
elseif ( event == "PLAYER_CONTROL_LOST" or event == "PLAYER_CONTROL_GAINED" or event == "PLAYER_FARSIGHT_FOCUS_CHANGED" or event == "PET_BAR_UPDATE_USABLE" or event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_MOUNT_DISPLAY_CHANGED" ) then
self:ForAll("Update")
elseif ( (event == "UNIT_FLAGS") or (event == "UNIT_AURA") ) then
if arg1 == "pet" then
self:ForAll("Update")
end
elseif ( event =="PET_BAR_UPDATE_COOLDOWN" ) then
self:ForAll("UpdateCooldown")
elseif event == "PET_BAR_SHOWGRID" then
self:ForAll("ShowGrid")
elseif event == "PET_BAR_HIDEGRID" then
self:ForAll("HideGrid")
end
end
function PetBar:UpdateButtonConfig()
self:ForAll("Update")
end
function PetBar:ApplyConfig(config)
ButtonBar.ApplyConfig(self, config)
if not self.config.position.x then
self:ClearSetPoint("CENTER", 0, 70)
self:SavePosition()
end
self:UpdateButtonLayout()
self:ForAll("Update")
self:ForAll("ApplyStyle", self.config.style)
end