-
Notifications
You must be signed in to change notification settings - Fork 12
/
BonusActionBarFrame.lua
294 lines (264 loc) · 8.17 KB
/
BonusActionBarFrame.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
BONUSACTIONBAR_SLIDETIME = 0.15;
BONUSACTIONBAR_YPOS = 43;
BONUSACTIONBAR_XPOS = 4;
NUM_BONUS_ACTION_SLOTS = 12;
NUM_SHAPESHIFT_SLOTS = 10;
NUM_POSSESS_SLOTS = 2;
POSSESS_CANCEL_SLOT = 2;
function BonusActionBar_OnLoad (self)
self:RegisterEvent("UPDATE_BONUS_ACTIONBAR");
self:SetFrameLevel(self:GetFrameLevel() + 2);
self.mode = "none";
self.completed = 1;
self.lastBonusBar = 1;
if ( GetBonusBarOffset() > 0 and GetActionBarPage() == 1 ) then
ShowBonusActionBar();
end
end
function BonusActionBar_OnEvent (self, event, ...)
if ( event == "UPDATE_BONUS_ACTIONBAR" ) then
if ( GetBonusBarOffset() > 0 ) then
self.lastBonusBar = GetBonusBarOffset();
ShowBonusActionBar();
else
HideBonusActionBar();
end
end
end
function BonusActionBar_OnUpdate(self, elapsed)
local yPos;
if ( self.slideTimer and (self.slideTimer < self.timeToSlide) ) then
-- Animating
self.completed = nil;
if ( self.mode == "show" ) then
yPos = (self.slideTimer/self.timeToSlide) * BONUSACTIONBAR_YPOS;
self:SetPoint("TOPLEFT", self:GetParent(), "BOTTOMLEFT", BONUSACTIONBAR_XPOS, yPos);
self.state = "showing";
self:Show();
elseif ( self.mode == "hide" ) then
yPos = (1 - (self.slideTimer/self.timeToSlide)) * BONUSACTIONBAR_YPOS;
self:SetPoint("TOPLEFT", self:GetParent(), "BOTTOMLEFT", BONUSACTIONBAR_XPOS, yPos);
self.state = "hiding";
end
self.slideTimer = self.slideTimer + elapsed;
else
-- Animation complete
if ( self.completed == 1 ) then
return;
else
self.completed = 1;
end
if ( self.mode == "show" ) then
self:SetPoint("TOPLEFT", self:GetParent(), "BOTTOMLEFT", BONUSACTIONBAR_XPOS, BONUSACTIONBAR_YPOS);
self.state = "top";
PlaySound("igBonusBarOpen");
elseif ( self.mode == "hide" ) then
self:SetPoint("TOPLEFT", self:GetParent(), "BOTTOMLEFT", BONUSACTIONBAR_XPOS, 0);
self.state = "bottom";
self:Hide();
end
self.mode = "none";
end
end
function ShowBonusActionBar (override)
if (( (not MainMenuBar.busy) and (not UnitHasVehicleUI("player")) ) or override) then --Don't change while we're animating out MainMenuBar for vehicle UI
if ( (BonusActionBarFrame.mode ~= "show" and BonusActionBarFrame.state ~= "top") or (not UIParent:IsShown())) then
BonusActionBarFrame:Show();
if ( BonusActionBarFrame.completed ) then
BonusActionBarFrame.slideTimer = 0;
end
BonusActionBarFrame.timeToSlide = BONUSACTIONBAR_SLIDETIME;
BonusActionBarFrame.mode = "show";
end
end
end
function HideBonusActionBar (override)
if (( (not MainMenuBar.busy) and (not UnitHasVehicleUI("player")) ) or override) then --Don't change while we're animating out MainMenuBar for vehicle UI
if ( (BonusActionBarFrame:IsShown()) or (not UIParent:IsShown())) then
if ( BonusActionBarFrame.completed ) then
BonusActionBarFrame.slideTimer = 0;
end
BonusActionBarFrame.timeToSlide = BONUSACTIONBAR_SLIDETIME;
BonusActionBarFrame.mode = "hide";
end
end
end
function BonusActionButtonUp (id)
PetActionButtonUp(id);
end
function BonusActionButtonDown (id)
PetActionButtonDown(id);
end
function ShapeshiftBar_OnLoad (self)
ShapeshiftBar_Update();
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS");
self:RegisterEvent("UPDATE_SHAPESHIFT_USABLE");
self:RegisterEvent("UPDATE_SHAPESHIFT_COOLDOWN");
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM");
self:RegisterEvent("UPDATE_INVENTORY_ALERTS"); -- Wha?? Still Wha...
self:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
end
function ShapeshiftBar_OnEvent (self, event, ...)
if ( event == "PLAYER_ENTERING_WORLD" or event == "UPDATE_SHAPESHIFT_FORMS" ) then
ShapeshiftBar_Update();
elseif ( event == "ACTIONBAR_PAGE_CHANGED" ) then
if ( GetBonusBarOffset() > 0 ) then
ShowBonusActionBar();
else
HideBonusActionBar();
end
else
ShapeshiftBar_UpdateState();
end
end
function ShapeshiftBar_Update ()
local numForms = GetNumShapeshiftForms();
if ( numForms > 0 ) then
--Setup the shapeshift bar to display the appropriate number of slots
if ( numForms == 1 ) then
ShapeshiftBarMiddle:Hide();
ShapeshiftBarRight:SetPoint("LEFT", "ShapeshiftBarLeft", "LEFT", 12, 0);
ShapeshiftButton1:SetPoint("BOTTOMLEFT", "ShapeshiftBarFrame", "BOTTOMLEFT", 12, 3);
elseif ( numForms == 2 ) then
ShapeshiftBarMiddle:Hide();
ShapeshiftBarRight:SetPoint("LEFT", "ShapeshiftBarLeft", "RIGHT", 0, 0);
else
ShapeshiftBarMiddle:Show();
ShapeshiftBarMiddle:SetPoint("LEFT", "ShapeshiftBarLeft", "RIGHT", 0, 0);
ShapeshiftBarMiddle:SetWidth(37 * (numForms-2));
ShapeshiftBarMiddle:SetTexCoord(0, numForms-2, 0, 1);
ShapeshiftBarRight:SetPoint("LEFT", "ShapeshiftBarMiddle", "RIGHT", 0, 0);
end
ShapeshiftBarFrame:Show();
else
ShapeshiftBarFrame:Hide();
end
ShapeshiftBar_UpdateState();
UIParent_ManageFramePositions();
end
function ShapeshiftBar_UpdateState ()
local numForms = GetNumShapeshiftForms();
local texture, name, isActive, isCastable;
local button, icon, cooldown;
local start, duration, enable;
for i=1, NUM_SHAPESHIFT_SLOTS do
button = _G["ShapeshiftButton"..i];
icon = _G["ShapeshiftButton"..i.."Icon"];
if ( i <= numForms ) then
texture, name, isActive, isCastable = GetShapeshiftFormInfo(i);
icon:SetTexture(texture);
--Cooldown stuffs
cooldown = _G["ShapeshiftButton"..i.."Cooldown"];
if ( texture ) then
cooldown:Show();
else
cooldown:Hide();
end
start, duration, enable = GetShapeshiftFormCooldown(i);
CooldownFrame_SetTimer(cooldown, start, duration, enable);
if ( isActive ) then
ShapeshiftBarFrame.lastSelected = button:GetID();
button:SetChecked(1);
else
button:SetChecked(0);
end
if ( isCastable ) then
icon:SetVertexColor(1.0, 1.0, 1.0);
else
icon:SetVertexColor(0.4, 0.4, 0.4);
end
button:Show();
else
button:Hide();
end
end
end
function ShapeshiftBar_ChangeForm (id)
ShapeshiftBarFrame.lastSelected = id;
CastShapeshiftForm(id);
end
function PossessBar_OnLoad (self)
PossessBar_Update();
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UPDATE_BONUS_ACTIONBAR");
self:RegisterEvent("UNIT_AURA");
self:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
end
function PossessBar_OnEvent (self, event, ...)
if ( event == "PLAYER_ENTERING_WORLD" or event == "UPDATE_BONUS_ACTIONBAR" ) then
PossessBar_Update();
elseif ( event == "ACTIONBAR_PAGE_CHANGED" ) then
if ( GetBonusBarOffset() > 0 ) then
ShowBonusActionBar();
else
HideBonusActionBar();
end
end
end
function PossessBar_Update (override)
if ( (not MainMenuBar.busy and not UnitHasVehicleUI("player")) or override ) then --Don't change while we're animating out MainMenuBar for vehicle UI
if ( IsPossessBarVisible() ) then
PossessBarFrame:Show();
ShapeshiftBarFrame:Hide();
ShowPetActionBar(true);
else
PossessBarFrame:Hide();
if(GetNumShapeshiftForms() > 0) then
ShapeshiftBarFrame:Show();
ShowPetActionBar(true);
end
end
PossessBar_UpdateState();
UIParent_ManageFramePositions();
end
end
function PossessBar_UpdateState ()
local texture, name, enabled;
local button, background, icon, cooldown;
for i=1, NUM_POSSESS_SLOTS do
-- Possess Icon
button = _G["PossessButton"..i];
background = _G["PossessBackground"..i];
icon = _G["PossessButton"..i.."Icon"];
texture, name, enabled = GetPossessInfo(i);
icon:SetTexture(texture);
--Cooldown stuffs
cooldown = _G["PossessButton"..i.."Cooldown"];
cooldown:Hide();
button:SetChecked(nil);
icon:SetVertexColor(1.0, 1.0, 1.0);
if ( enabled ) then
button:Show();
background:Show();
else
button:Hide();
background:Hide();
end
end
end
function PossessButton_OnClick (self)
self:SetChecked(nil);
local id = self:GetID();
if ( id == POSSESS_CANCEL_SLOT ) then
if ( UnitControllingVehicle("player") and CanExitVehicle() ) then
VehicleExit();
else
local texture, name = GetPossessInfo(id);
CancelUnitBuff("player", name);
end
end
end
function PossessButton_OnEnter (self)
local id = self:GetID();
if ( GetCVar("UberTooltips") == "1" ) then
GameTooltip_SetDefaultAnchor(GameTooltip, self);
else
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
end
if ( id == POSSESS_CANCEL_SLOT ) then
GameTooltip:SetText(CANCEL);
else
GameTooltip:SetPossession(id);
end
end