/
petBar.lua
146 lines (113 loc) · 2.66 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
--[[
petBar.lua
A Dominos pet bar
--]]
--libs and omgspeed
local _G = getfenv(0)
local format = string.format
local KeyBound = LibStub('LibKeyBound-1.0')
local unused
--[[ Pet Button ]]--
local PetButton = Dominos:CreateClass('CheckButton', Dominos.BindableButton)
function PetButton:New(id)
local b = self:Restore(id) or self:Create(id)
b:UpdateHotkey()
return b
end
function PetButton:Create(id)
local b = self:Bind(_G['PetActionButton' .. id])
b.buttonType = 'BONUSACTIONBUTTON'
b:SetScript('OnEnter', self.OnEnter)
b:UnregisterEvent('UPDATE_BINDINGS')
b:Skin()
return b
end
--if we have button facade support, then skin the button that way
--otherwise, apply the dominos style to the button to make it pretty
function PetButton:Skin()
if not Dominos:Masque('Pet Bar', self) then
_G[self:GetName() .. 'Icon']:SetTexCoord(0.06, 0.94, 0.06, 0.94)
self:GetNormalTexture():SetVertexColor(1, 1, 1, 0.5)
end
end
function PetButton:Restore(id)
local b = unused and unused[id]
if b then
unused[id] = nil
b:Show()
return b
end
end
--saving them thar memories
function PetButton:Free()
if not unused then unused = {} end
unused[self:GetID()] = self
self:SetParent(nil)
self:Hide()
end
--keybound support
function PetButton:OnEnter()
if Dominos:ShowTooltips() then
PetActionButton_OnEnter(self)
end
KeyBound:Set(self)
end
--override keybinding display
hooksecurefunc('PetActionButton_SetHotkeys', PetButton.UpdateHotkey)
--[[ Pet Bar ]]--
local PetBar = Dominos:CreateClass('Frame', Dominos.Frame)
Dominos.PetBar = PetBar
function PetBar:New()
local f = self.super.New(self, 'pet')
f:LoadButtons()
f:Layout()
return f
end
function PetBar:GetShowStates()
return '[@pet,exists,nopossessbar]show;hide'
end
function PetBar:GetDefaults()
return {
point = 'CENTER',
x = 0,
y = -32,
spacing = 6
}
end
--dominos frame method overrides
function PetBar:NumButtons()
return NUM_PET_ACTION_SLOTS
end
function PetBar:AddButton(i)
local b = PetButton:New(i)
b:SetParent(self.header)
self.buttons[i] = b
end
function PetBar:RemoveButton(i)
local b = self.buttons[i]
self.buttons[i] = nil
b:Free()
end
--[[ keybound support ]]--
function PetBar:KEYBOUND_ENABLED()
self.header:SetAttribute('state-visibility', 'display')
for _,button in pairs(self.buttons) do
button:Show()
end
end
function PetBar:KEYBOUND_DISABLED()
self:UpdateShowStates()
local petBarShown = PetHasActionBar()
for _,button in pairs(self.buttons) do
if petBarShown and GetPetActionInfo(button:GetID()) then
button:Show()
else
button:Hide()
end
end
end
function PetBar:UPDATE_BINDINGS()
for _,b in pairs(self.buttons) do
b:UpdateHotkey(b.buttonType)
end
end