vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Constants
2 TITAN_PANEL_UPDATE_BUTTON = 1;
3 TITAN_PANEL_UPDATE_TOOLTIP = 2;
4 TITAN_PANEL_UPDATE_ALL = 3;
5 TITAN_PANEL_LABEL_SEPARATOR = " "
6  
7 TITAN_PANEL_BUTTON_TYPE_TEXT = 1;
8 TITAN_PANEL_BUTTON_TYPE_ICON = 2;
9 TITAN_PANEL_BUTTON_TYPE_COMBO = 3;
10 TITAN_PANEL_BUTTON_TYPE_CUSTOM = 4;
11  
12 function TitanOptionSlider_TooltipText(text, value)
13 return text .. GREEN_FONT_COLOR_CODE .. value .. FONT_COLOR_CODE_CLOSE;
14 end
15  
16 function TitanPanelButton_OnLoad(isChildButton)
17 if (isChildButton) then
18 this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
19 else
20 TitanUtils_RegisterPlugin(this.registry);
21 local plugin = TitanUtils_GetPlugin();
22 if (plugin) then
23 this:RegisterForClicks("LeftButtonUp", "RightButtonUp");
24 local frequency = plugin.frequency;
25 if (frequency and frequency > 0) then
26 this.timer = 0;
27 this.frequency = frequency;
28 this.updateType = plugin.updateType;
29 if (not this.updateType) then
30 this.updateType = TITAN_PANEL_UPDATE_ALL;
31 end
32 end
33 end
34 end
35 end
36  
37 function TitanPanelButton_OnShow()
38 local id = TitanUtils_GetButtonID();
39 if (id) then
40 TitanPanelButton_UpdateButton(id, 1);
41 end
42 end
43  
44 function TitanPanelButton_OnClick(button, isChildButton)
45 local id = TitanUtils_Ternary(isChildButton, TitanUtils_GetParentButtonID(), TitanUtils_GetButtonID());
46  
47 if (id) then
48 local controlFrame = TitanUtils_GetControlFrame(id);
49 local rightClickMenu = getglobal("TitanPanelRightClickMenu");
50  
51 if (button == "LeftButton") then
52 local isControlFrameShown;
53 if (not controlFrame) then
54 isControlFrameShown = false;
55 elseif (controlFrame:IsVisible()) then
56 isControlFrameShown = false;
57 else
58 isControlFrameShown = true;
59 end
60  
61 TitanUtils_CloseAllControlFrames();
62 TitanPanelRightClickMenu_Close();
63  
64 local position = TitanPanelGetVar("Position");
65 local scale = TitanPanelGetVar("Scale");
66 if (isControlFrameShown) then
67 local buttonCenter = (this:GetLeft() + this:GetRight()) / 2 * scale;
68 local controlFrameRight = buttonCenter + controlFrame:GetWidth() / 2;
69 if ( position == TITAN_PANEL_PLACE_TOP ) then
70 controlFrame:ClearAllPoints();
71 controlFrame:SetPoint("TOP", "UIParent", "TOPLEFT", buttonCenter, -24 * scale);
72  
73 -- Adjust control frame position if it's off the screen
74 local offscreenX, offscreenY = TitanUtils_GetOffscreen(controlFrame);
75 if ( offscreenX == -1 ) then
76 controlFrame:ClearAllPoints();
77 controlFrame:SetPoint("TOPLEFT", "UIParent", "TOPLEFT", 0, -24 * scale);
78 elseif ( offscreenX == 1 ) then
79 controlFrame:ClearAllPoints();
80 controlFrame:SetPoint("TOPRIGHT", "UIParent", "TOPRIGHT", 0, -24 * scale);
81 end
82 else
83 controlFrame:ClearAllPoints();
84 controlFrame:SetPoint("BOTTOM", "UIParent", "BOTTOMLEFT", buttonCenter, 24 * scale);
85  
86 -- Adjust control frame position if it's off the screen
87 local offscreenX, offscreenY = TitanUtils_GetOffscreen(controlFrame);
88 if ( offscreenX == -1 ) then
89 controlFrame:ClearAllPoints();
90 controlFrame:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", 0, 24 * scale);
91 elseif ( offscreenX == 1 ) then
92 controlFrame:ClearAllPoints();
93 controlFrame:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", 0, 24 * scale);
94 end
95 end
96  
97 controlFrame:Show();
98 end
99 elseif (button == "RightButton") then
100 TitanUtils_CloseAllControlFrames();
101  
102 -- Show RightClickMenu anyway
103 if (TitanPanelRightClickMenu_IsVisible()) then
104 TitanPanelRightClickMenu_Close();
105 end
106 TitanPanelRightClickMenu_Toggle();
107 end
108  
109 GameTooltip:Hide();
110 end
111 end
112  
113 function TitanPanelButton_OnUpdate(elapsed)
114 local id = TitanUtils_GetButtonID();
115  
116 if (id) then
117 if (this.frequency) then
118 local timeLeft = this.timer - elapsed;
119 if (timeLeft <= 0) then
120 this.timer = this.frequency;
121 if (this.updateType == TITAN_PANEL_UPDATE_ALL or
122 this.updateType == TITAN_PANEL_UPDATE_BUTTON) then
123 TitanPanelButton_UpdateButton(id);
124 end
125 if (this.updateType == TITAN_PANEL_UPDATE_ALL or
126 this.updateType == TITAN_PANEL_UPDATE_TOOLTIP) then
127 TitanPanelButton_UpdateTooltip();
128 end
129 else
130 this.timer = timeLeft;
131 end
132 end
133 end
134 if TITAN_PANEL_MOVING == 3 then
135 TITAN_PANEL_MOVING = 0;
136  
137 local dropoff = TitanUtils_GetCurrentIndex(TitanPanelSettings.Buttons,TITAN_PANEL_DROPOFF_ADDON);
138 local pickup = TitanUtils_GetCurrentIndex(TitanPanelSettings.Buttons,TITAN_PANEL_MOVE_ADDON);
139 local dropoffbar = TitanUtils_GetWhichBar(TITAN_PANEL_DROPOFF_ADDON);
140 local side = TitanPanel_GetPluginSide(TITAN_PANEL_DROPOFF_ADDON);
141 local nextaddon = TitanUtils_GetNextButtonOnBar(dropoffbar,TITAN_PANEL_DROPOFF_ADDON,side);
142  
143 if dropoff ~= nil then
144 if dropoff < pickup then
145 table.remove(TitanPanelSettings.Buttons, pickup);
146 table.remove(TitanPanelSettings.Location, pickup);
147 table.insert(TitanPanelSettings.Buttons, dropoff ,TITAN_PANEL_MOVE_ADDON);
148 table.insert(TitanPanelSettings.Location, dropoff ,dropoffbar);
149  
150 else
151 table.insert(TitanPanelSettings.Buttons, dropoff ,TITAN_PANEL_MOVE_ADDON);
152 table.insert(TitanPanelSettings.Location, dropoff ,dropoffbar);
153 table.remove(TitanPanelSettings.Buttons, pickup);
154 table.remove(TitanPanelSettings.Location, pickup);
155 end
156 TitanPanel_InitPanelButtons();
157 TITAN_PANEL_MOVE_ADDON = nil;
158 TITAN_PANEL_DROPOFF_ADDON = nil;
159 TITAN_PANEL_NEXT_ADDON = nil;
160 end
161  
162 end
163 end
164  
165 function TitanPanelButton_OnEnter(isChildButton)
166 local id = TitanUtils_Ternary(isChildButton, TitanUtils_GetParentButtonID(), TitanUtils_GetButtonID());
167  
168 if (id) then
169 TitanUtils_StopAutoHideCounting(this:GetName());
170 local controlFrame = TitanUtils_GetControlFrame(id);
171 if (controlFrame and controlFrame:IsVisible()) then
172 return;
173 elseif (TitanPanelRightClickMenu_IsVisible()) then
174 return;
175 else
176 TitanPanelButton_SetTooltip(id);
177 end
178 end
179 end
180  
181 function TitanPanelButton_OnLeave(isChildButton)
182 local id = TitanUtils_Ternary(isChildButton, TitanUtils_GetParentButtonID(), TitanUtils_GetButtonID());
183  
184 if (id) then
185 TitanUtils_StartAutoHideCounting();
186 GameTooltip:Hide();
187 end
188 end
189  
190 function TitanPanelButton_UpdateButton(id, setButtonWidth)
191 local button, id = TitanUtils_GetButton(id, true);
192  
193 if ( TitanPanelButton_IsText(id) ) then
194 -- Update textButton
195 TitanPanelButton_SetButtonText(id);
196 TitanPanelButton_SetTextButtonWidth(id, setButtonWidth);
197  
198 elseif ( TitanPanelButton_IsIcon(id) ) then
199 -- Update iconButton
200 TitanPanelButton_SetButtonIcon(id);
201 TitanPanelButton_SetIconButtonWidth(id);
202  
203 elseif ( TitanPanelButton_IsCombo(id) ) then
204 -- Update comboButton
205 TitanPanelButton_SetButtonText(id);
206 TitanPanelButton_SetButtonIcon(id);
207 TitanPanelButton_SetComboButtonWidth(id, setButtonWidth);
208 end
209 end
210  
211 function TitanPanelButton_UpdateTooltip()
212 if (GameTooltip:IsOwned(this)) then
213 local id = TitanUtils_GetButtonID();
214 TitanPanelButton_SetTooltip(id);
215 end
216 end
217  
218 -- id is required
219 function TitanPanelButton_SetButtonText(id)
220 if (id and TitanUtils_IsPluginRegistered(id)) then
221 local button = TitanUtils_GetButton(id);
222 local buttonText = getglobal(button:GetName().."Text");
223 local buttonTextFunction = getglobal(TitanUtils_GetPlugin(id).buttonTextFunction);
224 if (buttonTextFunction) then
225 local label1, value1, label2, value2, label3, value3, label4, value4 = buttonTextFunction(id);
226 local text = "";
227 if ( label1 and not ( label2 or label3 or label4 or value1 or value2 or value3 or value4 ) ) then
228 text = label1;
229 elseif (TitanGetVar(id, "ShowLabelText")) then
230 if (label1 or value1) then
231 text = TitanUtils_ToString(label1)..TitanUtils_ToString(value1);
232 if (label2 or value2) then
233 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(label2)..TitanUtils_ToString(value2);
234 if (label3 or value3) then
235 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(label3)..TitanUtils_ToString(value3);
236 if (label4 or value4) then
237 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(label4)..TitanUtils_ToString(value4);
238 end
239 end
240 end
241 end
242 else
243 if (value1) then
244 text = TitanUtils_ToString(value1);
245 if (value2) then
246 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(value2);
247 if (value3) then
248 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(value3);
249 if (value4) then
250 text = text..TITAN_PANEL_LABEL_SEPARATOR..TitanUtils_ToString(value4);
251 end
252 end
253 end
254 end
255 end
256 buttonText:SetText(text);
257 end
258 end
259 end
260  
261 -- id is required
262 function TitanPanelButton_SetButtonIcon(id)
263 if (id and TitanUtils_IsPluginRegistered(id)) then
264 local button = TitanUtils_GetButton(id);
265 local icon = getglobal(button:GetName().."Icon");
266 local iconTexture = TitanUtils_GetPlugin(id).icon;
267 local iconWidth = TitanUtils_GetPlugin(id).iconWidth;
268  
269 if (iconTexture) then
270 icon:SetTexture(iconTexture);
271 end
272 if (iconWidth) then
273 icon:SetWidth(iconWidth);
274 end
275 end
276 end
277  
278 -- id is required
279 function TitanPanelButton_SetTextButtonWidth(id, setButtonWidth)
280 if (id) then
281 local button = TitanUtils_GetButton(id);
282 local text = getglobal(button:GetName().."Text");
283 if ( setButtonWidth or
284 button:GetWidth() == 0 or
285 button:GetWidth() - text:GetWidth() > TITAN_PANEL_BUTTON_WIDTH_CHANGE_TOLERANCE or
286 button:GetWidth() - text:GetWidth() < -TITAN_PANEL_BUTTON_WIDTH_CHANGE_TOLERANCE ) then
287 button:SetWidth(text:GetWidth());
288 TitanPanelButton_Justify();
289 end
290 end
291 end
292  
293 -- id is required
294 function TitanPanelButton_SetIconButtonWidth(id)
295 if (id) then
296 local button = TitanUtils_GetButton(id);
297 local icon = getglobal(button:GetName().."Icon");
298 if ( TitanUtils_GetPlugin(id).iconButtonWidth ) then
299 button:SetWidth(TitanUtils_GetPlugin(id).iconButtonWidth);
300 end
301 end
302 end
303  
304 -- id is required
305 function TitanPanelButton_SetComboButtonWidth(id, setButtonWidth)
306 if (id) then
307 local button = TitanUtils_GetButton(id);
308 local text = getglobal(button:GetName().."Text");
309 local icon = getglobal(button:GetName().."Icon");
310 local iconWidth, iconButtonWidth, newButtonWidth;
311  
312 -- Get icon button width
313 iconButtonWidth = 0;
314 if ( TitanUtils_GetPlugin(id).iconButtonWidth ) then
315 iconButtonWidth = TitanUtils_GetPlugin(id).iconButtonWidth;
316 elseif ( icon:GetWidth() ) then
317 iconButtonWidth = icon:GetWidth();
318 end
319  
320 if ( TitanGetVar(id, "ShowIcon") and ( iconButtonWidth ~= 0 ) ) then
321 icon:Show();
322 text:ClearAllPoints();
323 text:SetPoint("LEFT", icon:GetName(), "RIGHT", 2, 1);
324  
325 newButtonWidth = text:GetWidth() + iconButtonWidth + 2;
326 else
327 icon:Hide();
328 text:ClearAllPoints();
329 text:SetPoint("LEFT", button:GetName(), "Left", 0, 1);
330  
331 newButtonWidth = text:GetWidth();
332 end
333  
334 if ( setButtonWidth or
335 button:GetWidth() == 0 or
336 button:GetWidth() - newButtonWidth > TITAN_PANEL_BUTTON_WIDTH_CHANGE_TOLERANCE or
337 button:GetWidth() - newButtonWidth < -TITAN_PANEL_BUTTON_WIDTH_CHANGE_TOLERANCE ) then
338 button:SetWidth(newButtonWidth);
339 TitanPanelButton_Justify();
340 end
341 end
342 end
343  
344 -- id is required
345 function TitanPanelButton_SetTooltip(id)
346 if (id and TitanUtils_IsPluginRegistered(id)) then
347 local plugin = TitanUtils_GetPlugin(id);
348 if ( plugin.tooltipCustomFunction ) then
349 this.tooltipCustomFunction = plugin.tooltipCustomFunction;
350 TitanTooltip_SetPanelTooltip(id);
351 elseif ( plugin.tooltipTitle ) then
352 this.tooltipTitle = plugin.tooltipTitle;
353 local tooltipTextFunc = getglobal(plugin.tooltipTextFunction);
354 if ( tooltipTextFunc ) then
355 this.tooltipText = tooltipTextFunc();
356 end
357 TitanTooltip_SetPanelTooltip(id);
358 end
359 end
360 end
361  
362 function TitanPanelButton_GetType(id)
363 -- id is required
364 if (not id) then
365 return;
366 end
367  
368 local button = TitanUtils_GetButton(id);
369 local type;
370 if button then
371 local text = getglobal(button:GetName().."Text");
372 local icon = getglobal(button:GetName().."Icon");
373  
374 if (text and icon) then
375 type = TITAN_PANEL_BUTTON_TYPE_COMBO;
376 elseif (text and not icon) then
377 type = TITAN_PANEL_BUTTON_TYPE_TEXT;
378 elseif (not text and icon) then
379 type = TITAN_PANEL_BUTTON_TYPE_ICON;
380 elseif (not text and not icon) then
381 type = TITAN_PANEL_BUTTON_TYPE_CUSTOM;
382 end
383 else
384 type = TITAN_PANEL_BUTTON_TYPE_COMBO;
385 end
386  
387 return type;
388 end
389  
390 function TitanPanelButton_IsText(id)
391 if (TitanPanelButton_GetType(id) == TITAN_PANEL_BUTTON_TYPE_TEXT) then
392 return 1;
393 end
394 end
395  
396 function TitanPanelButton_IsIcon(id)
397 if (TitanPanelButton_GetType(id) == TITAN_PANEL_BUTTON_TYPE_ICON) then
398 return 1;
399 end
400 end
401  
402 function TitanPanelButton_IsCombo(id)
403 if (TitanPanelButton_GetType(id) == TITAN_PANEL_BUTTON_TYPE_COMBO) then
404 return 1;
405 end
406 end
407  
408 function TitanPanelButton_IsCustom(id)
409 if (TitanPanelButton_GetType(id) == TITAN_PANEL_BUTTON_TYPE_CUSTOM) then
410 return 1;
411 end
412 end
413  
414 function TitanPanelButton_OnMouseDown(button)
415 local frname = getglobal("TitanPanel" .. TitanUtils_GetButtonID() .. "Button");
416 if( button == "LeftButton" and IsShiftKeyDown() ) then
417 --frname:StartMoving();
418 --frname.isMoving = true;
419 TITAN_PANEL_MOVE_ADDON = TitanUtils_GetButtonID();
420 TITAN_PANEL_MOVING = 1;
421 end
422 end
423  
424 function TitanPanelButton_OnMouseUp(button)
425 local frname = getglobal("TitanPanel" .. TitanUtils_GetButtonID() .. "Button");
426 if( button == "LeftButton" and TITAN_PANEL_MOVING == 1 ) then
427 --frname:StopMovingOrSizing();
428 --frname.isMoving = false;
429 TITAN_PANEL_MOVING = 2;
430 end
431 end