vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Declard color codes for console messages
2 local RED = "|cffff0000";
3 local GREEN = "|cff00ff00";
4 local BLUE = "|cff0000ff";
5 local MAGENTA = "|cffff00ff";
6 local YELLOW = "|cffffff00";
7 local CYAN = "|cff00ffff";
8 local WHITE = "|cffffffff";
9 local ORANGE = "|cffffba00";
10  
11 TITAN_ZM_ID = "ZeppelinMaster";
12 TITAN_ZM_COUNT_FORMAT = "%d";
13 TITAN_ZM_MENU_TEXT = "ZeppelinMaster v1.87";
14 TITAN_ZM_BUTTON_LABEL = "Hello Menu Counter: ";
15 TITAN_ZM_TOOLTIP = "ZeppelinMaster";
16 TITAN_ZM_FREQUENCY = 1;
17 TITAN_ZM_ARTWORK = "Interface\\AddOns\\TitanZeppelinMaster\\Artwork\\";
18  
19 activeTransitName = "";
20 activeSelect = -1;
21 activeTransit = -1;
22  
23 -----------------------------------
24 -- local variables
25 -----------------------------------
26  
27 local dropdownvalues = {};
28 local dropdownindexes = {};
29  
30 local firstTooltip = true;
31  
32 ZM_tempText = "";
33 ZM_tempTextCount = 0;
34  
35 function TitanPanelZeppelinMasterButton_OnLoad()
36  
37 -- Make sure ZeppelinMaster loads first
38 LoadAddOn("ZeppelinMaster");
39  
40 this:RegisterEvent("VARIABLES_LOADED");
41 this:RegisterEvent("ZONE_CHANGED_NEW_AREA");
42  
43 this.registry = {
44 id = TITAN_ZM_ID,
45 category = "Information",
46 menuText = TITAN_ZM_MENU_TEXT,
47 buttonTextFunction = "TitanPanelZeppelinMasterButton_GetButtonText",
48 tooltipTitle = TITAN_ZM_TOOLTIP,
49 tooltipTextFunction = "TitanPanelZeppelinMasterButton_GetTooltipText",
50 frequency = TITAN_ZM_FREQUENCY,
51 icon = TITAN_ZM_ARTWORK.."Zeppelinmaster",
52 iconWidth = 16,
53 savedVariables = {
54 OptZoneGUI = 1,
55 OptFaction = 1,
56 OptZone = 1,
57 OptAlias = 1,
58 ShowLabelText = 1,
59 ShowIcon = 1,
60 }
61 };
62  
63 Pre_TitanToggleVar = TitanToggleVar;
64 TitanToggleVar = ZM_TitanToggleVar;
65  
66 --TitanToggleVar(id, var)
67 end
68  
69 -- Hook toggle button
70 function ZM_TitanToggleVar(id, var)
71 --local button, id = TitanUtils_GetButton(id, true);
72 --DEFAULT_CHAT_FRAME:AddMessage(var);
73 --DEFAULT_CHAT_FRAME:AddMessage(id);
74  
75 if (id == TITAN_ZM_ID) then
76 TitanPanelRightClickMenu_PrepareZeppelinMasterMenu();
77 TitanPanelRightClickMenu_Close();
78 end
79  
80 return Pre_TitanToggleVar(id, var);
81 end
82  
83 function TitanPanelZeppelinMasterButton_OnEvent ( event )
84  
85 if (event == "VARIABLES_LOADED") then
86  
87 else
88 --DEFAULT_CHAT_FRAME:AddMessage(event);
89 TitanPanelRightClickMenu_PrepareZeppelinMasterMenu();
90 TitanPanelRightClickMenu_Close();
91 end
92  
93 end
94  
95  
96 function TitanPanelZeppelinMasterButton_GetButtonText(id)
97 local button, id = TitanUtils_GetButton(id, true);
98 local lowestName;
99 local lowestTime = 500;
100 local lowestTimeStr;
101  
102 if (ZM_tempTextCount > 0) then
103 ZM_tempTextCount = ZM_tempTextCount -1;
104 return ZM_tempText;
105 end
106  
107 if ((activeTransit ~= -1) and (known_times[activeTransit] ~= nil)) then
108 local transit = activeTransit;
109 local cycle = ZSM_CalcTripCycle(transit);
110 local coord_data = ZSM_GetZepCoords(transit, cycle);
111  
112 for index, data in zsm_data[transit..'_plats'] do
113 --ZSM_CalcTripCycleTime(transit,cycle)
114 --DEFAULT_CHAT_FRAME:AddMessage(data['name']..":"..ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1));
115 local arrival_time = 0;
116 if (ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1) > (cycle*zsm_data[transit..'_time'])) then
117 arrival_time = ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1) - (cycle*zsm_data[transit..'_time']);
118 --DEFAULT_CHAT_FRAME:AddMessage("Arrival Time of "..data['name']..": "..arrival_time .." sec.");
119 else
120 arrival_time = zsm_data[transit..'_time'] - (cycle*zsm_data[transit..'_time']);
121 arrival_time = arrival_time + ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1);
122 --DEFAULT_CHAT_FRAME:AddMessage("Arrival Time of "..data['name']..": "..arrival_time .." sec.");
123 end
124 --DEFAULT_CHAT_FRAME:AddMessage(GetRealZoneText());
125  
126 local platname;
127 if (ZSM_Data['Opts']['CityAlias']) then
128 platname = data['alias'];
129 else
130 platname = data['name'];
131 end
132 getglobal("ZSMFramePlat"..(index+1).."Name"):SetText(platname);
133  
134 local coord_data = ZSM_GetZepCoords(transit, cycle);
135 local depart_time = ZSM_CalcTripCycleTime(transit,cycle) - (cycle*zsm_data[transit..'_time']) - data['adj'];
136  
137 local formated_depart_time = "";
138 if (depart_time > 59) then
139 local time_min = format("%0.0f",math.floor(depart_time/60));
140 local time_sec = format("%0.0f",depart_time-(math.floor(depart_time/60)*60));
141 formated_depart_time = time_min.."m "..time_sec.."s";
142 else
143 formated_depart_time = format("%0.0f",depart_time).."s";
144 end
145  
146 local formated_arrival_time = "";
147 if (arrival_time > 59) then
148 local time_min = format("%0.0f",math.floor(arrival_time/60));
149 local time_sec = format("%0.0f",arrival_time-(math.floor(arrival_time/60)*60));
150 formated_arrival_time = time_min.."m "..time_sec.."s";
151 else
152 formated_arrival_time = format("%0.0f",arrival_time).."s";
153 end
154  
155 if ((data['x'] == tonumber(coord_data[1])) and (data['y'] == tonumber(coord_data[2])) and (depart_time > 0)) then
156 local color;
157 if (depart_time > 30) then
158 color = YELLOW;
159 else
160 color = RED;
161 end
162 --getglobal("ZSMFramePlat"..(index+1).."ArrivalDepature"):SetText(color.."Dep: ".. formated_depart_time);
163 TitanPanelZeppelinMasterButton.registry.icon = TITAN_ZM_ARTWORK.."Loading";
164  
165 local constr = data['ebv'].. color .. " ".. formated_depart_time;
166 return constr;
167 else
168 --local color = GREEN;
169 --getglobal("ZSMFramePlat"..(index+1).."ArrivalDepature"):SetText(color.."Arr: ".. formated_arrival_time);
170 --DEFAULT_CHAT_FRAME:AddMessage(arrival_time);
171 if (arrival_time < lowestTime) then
172 lowestTime = arrival_time;
173 lowestName = data['ebv'];
174 lowestTimeStr = formated_arrival_time;
175 end
176  
177 TitanPanelZeppelinMasterButton.registry.icon = TITAN_ZM_ARTWORK.."Transit";
178 end
179 end
180 elseif ((activeTransit ~= -1) and (known_times[activeTransit] == nil)) then
181 local transit = activeTransit;
182  
183 TitanPanelZeppelinMasterButton.registry.icon = TITAN_ZM_ARTWORK.."Zeppelinmaster";
184  
185 return "N/A";
186 elseif (activeTransit == -1) then
187 TitanPanelZeppelinMasterButton.registry.icon = TITAN_ZM_ARTWORK.."Zeppelinmaster";
188 return "--";
189 end
190  
191 -- Display Departure Time
192 local constr = lowestName.. GREEN.. " " .. lowestTimeStr;
193 return constr;
194  
195 --local countText = format(TITAN_ZM_COUNT_FORMAT, button.count);
196 --return TITAN_ZM_BUTTON_LABEL, TitanUtils_GetHighlightText(countText), "test";
197 end
198  
199 function TitanPanelZeppelinMasterButton_GetTooltipText()
200  
201 if (firstTooltip) then
202 firstTooltip = false;
203 TitanPanelRightClickMenu_PrepareZeppelinMasterMenu();
204 end
205 --local countText = format(TITAN_ZM_COUNT_FORMAT, this.count);
206 --return TITAN_ZM_TOOLTIP_COUNT.."\t"..TitanUtils_GetHighlightText(countText);
207 local tooltiptext = "";
208 local lowestName;
209 local lowestTime = 500;
210 local lowestTimeStr;
211  
212 if ((activeTransit ~= -1) and (known_times[activeTransit] ~= nil)) then
213 local transit = activeTransit;
214 local cycle = ZSM_CalcTripCycle(transit);
215 local coord_data = ZSM_GetZepCoords(transit, cycle);
216  
217 tooltiptext = tooltiptext..activeTransitName.."\n\n";
218  
219 for index, data in zsm_data[transit..'_plats'] do
220 --ZSM_CalcTripCycleTime(transit,cycle)
221 --DEFAULT_CHAT_FRAME:AddMessage(data['name']..":"..ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1));
222 local arrival_time = 0;
223 if (ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1) > (cycle*zsm_data[transit..'_time'])) then
224 arrival_time = ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1) - (cycle*zsm_data[transit..'_time']);
225 --DEFAULT_CHAT_FRAME:AddMessage("Arrival Time of "..data['name']..": "..arrival_time .." sec.");
226 else
227 arrival_time = zsm_data[transit..'_time'] - (cycle*zsm_data[transit..'_time']);
228 arrival_time = arrival_time + ZSM_CalcTripCycleTimeByIndex(transit,data['index']-1);
229 --DEFAULT_CHAT_FRAME:AddMessage("Arrival Time of "..data['name']..": "..arrival_time .." sec.");
230 end
231 --DEFAULT_CHAT_FRAME:AddMessage(GetRealZoneText());
232  
233 local platname;
234 if (ZSM_Data['Opts']['CityAlias']) then
235 platname = data['alias'];
236 else
237 platname = data['name'];
238 end
239 getglobal("ZSMFramePlat"..(index+1).."Name"):SetText(platname);
240  
241 local coord_data = ZSM_GetZepCoords(transit, cycle);
242 local depart_time = ZSM_CalcTripCycleTime(transit,cycle) - (cycle*zsm_data[transit..'_time']) - data['adj'];
243  
244 local formated_depart_time = "";
245 if (depart_time > 59) then
246 local time_min = format("%0.0f",math.floor(depart_time/60));
247 local time_sec = format("%0.0f",depart_time-(math.floor(depart_time/60)*60));
248 formated_depart_time = time_min.."m, "..time_sec.."s";
249 else
250 formated_depart_time = format("%0.0f",depart_time).."s";
251 end
252  
253 local formated_arrival_time = "";
254 if (arrival_time > 59) then
255 local time_min = format("%0.0f",math.floor(arrival_time/60));
256 local time_sec = format("%0.0f",arrival_time-(math.floor(arrival_time/60)*60));
257 formated_arrival_time = time_min.."m, "..time_sec.."s";
258 else
259 formated_arrival_time = format("%0.0f",arrival_time).."s";
260 end
261  
262 if ((data['x'] == tonumber(coord_data[1])) and (data['y'] == tonumber(coord_data[2])) and (depart_time > 0)) then
263 local color;
264 if (depart_time > 30) then
265 color = YELLOW;
266 else
267 color = RED;
268 end
269 --getglobal("ZSMFramePlat"..(index+1).."ArrivalDepature"):SetText(color.."Dep: ".. formated_depart_time);
270  
271 --color .. " ".. formated_depart_time;
272 --return constr;
273 tooltiptext = tooltiptext..platname.."\n";
274 tooltiptext = tooltiptext..color.."Departure: ".. " ".. formated_depart_time.."\n\n";
275 else
276 --local color = GREEN;
277 --getglobal("ZSMFramePlat"..(index+1).."ArrivalDepature"):SetText(color.."Arr: ".. formated_arrival_time);
278 --DEFAULT_CHAT_FRAME:AddMessage(arrival_time);
279  
280 tooltiptext = tooltiptext..platname.."\n";
281 tooltiptext = tooltiptext..GREEN.."Arrival: ".. formated_arrival_time.."\n\n";
282  
283 end
284 end
285 elseif ((activeTransit ~= -1) and (known_times[activeTransit] == nil)) then
286 local transit = activeTransit;
287  
288 tooltiptext = tooltiptext..activeTransitName.."\n\n";
289  
290 for index, data in zsm_data[transit..'_plats'] do
291  
292 local platname;
293 if (ZSM_Data['Opts']['CityAlias']) then
294 platname = data['alias'];
295 else
296 platname = data['name'];
297 end
298  
299 --getglobal("ZSMFramePlat"..(index+1).."Name"):SetText(platname);
300 --getglobal("ZSMFramePlat"..(index+1).."ArrivalDepature"):SetText("-- N/A --");
301  
302  
303 tooltiptext = tooltiptext..platname.."\n";
304 tooltiptext = tooltiptext.."Not Available\n\n";
305  
306  
307 end
308 elseif (activeTransit == -1) then
309 --for index = 1, 2 do
310 -- getglobal("ZSMFramePlat"..(index).."Name"):SetText(ZSM_STR_NONESELECT);
311 -- getglobal("ZSMFramePlat"..(index).."ArrivalDepature"):SetText("-- N/A --");
312 --end
313 tooltiptext = tooltiptext.."No Transit Selected\n";
314 end
315 return tooltiptext;
316 end
317  
318 function TitanPanelRightClickMenu_PrepareZeppelinMasterMenu()
319  
320 if (TitanPanelZeppelinMasterButtonRightClickMenu) then
321 UIDropDownMenu_ClearAll(TitanPanelZeppelinMasterButtonRightClickMenu);
322 --DEFAULT_CHAT_FRAME:AddMessage("Resetting");
323 end
324 --DEFAULT_CHAT_FRAME:AddMessage("Resetting");
325 --UIDropDownMenu_Initialize(TitanPanelZeppelinMasterRightClickMenu, nil);
326  
327 --TitanPanelRightClickMenu_AddToggleIcon(TITAN_ZM_ID);
328  
329 local OptFaction = TitanGetVar(TITAN_ZM_ID, "OptFaction");
330 local OptZone = TitanGetVar(TITAN_ZM_ID, "OptZone");
331 local OptAlias = TitanGetVar(TITAN_ZM_ID, "OptAlias");
332  
333 dropdownvalues = {};
334 dropdownindexes = {};
335  
336 -- Menu title
337 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_ZM_ID].menuText);
338 TitanPanelRightClickMenu_AddSpacer();
339  
340 -- TitanPanelRightClickMenu_AddCommand() adds an entry in the menu which triggers a function when clicked
341 -- 1st parameter is the menu text
342 -- 2st parameter can be retrieved by "this.value" in the triggered function. It's like passing parameters to the function.
343 -- 3st parameter is the triggered function name
344 --TitanPanelRightClickMenu_AddCommand(TITAN_ZM_MENU_RESET_COUNT, TITAN_ZM_ID, "TitanPanelZeppelinMasterButton_ResetCount");
345  
346 TitanPanelRightClickMenu_AddCommand(RED.."Select None", -1, "TitanPanelZeppelinMasterButton_SetTransport");
347  
348 local count = 1;
349 for index, data in zsm_data['transports'] do
350  
351 local tmplabel = data['label'];
352 dropdownindexes[tmplabel] = index;
353  
354 local textdesc;
355 if (OptAlias) then
356 textdesc = zsm_data['transports'][index]['namealias'];
357 else
358 textdesc = zsm_data['transports'][index]['name'];
359 end
360  
361 local addtrans = false;
362 if (OptFaction) then
363 local faction = UnitFactionGroup("player");
364 if ((zsm_data['transports'][index]['faction'] == faction) or (zsm_data['transports'][index]['faction'] == "Nuetral")) then
365 addtrans = true;
366 end
367 else
368 addtrans = true;
369 end
370  
371 if (OptZone and (addtrans)) then
372 local zonestr = string.lower(zsm_data['transports'][index]['name']);
373 local czonestr = string.lower(GetRealZoneText());
374 if (not string.find(zonestr, czonestr)) then
375 addtrans = false;
376 end
377 end
378  
379 if ((addtrans) and (zsm_data['transports'][index]['faction'] ~= -1)) then
380 table.insert(dropdownvalues, zsm_data['transports'][index]['label']);
381  
382 label = zsm_data['transports'][index]['label'];
383  
384 if (known_times[label] ~= nil) then
385 TitanPanelRightClickMenu_AddCommand(GREEN.. textdesc, count, "TitanPanelZeppelinMasterButton_SetTransport");
386 else
387 TitanPanelRightClickMenu_AddCommand(textdesc, count, "TitanPanelZeppelinMasterButton_SetTransport");
388 end
389  
390 count = count + 1;
391 end
392 end
393  
394 -- A blank line in the menu
395 TitanPanelRightClickMenu_AddSpacer();
396  
397 TitanPanelRightClickMenu_AddToggleVar(ZSM_STR_OPT_FACTION, TITAN_ZM_ID, "OptFaction");
398 TitanPanelRightClickMenu_AddToggleVar(ZSM_STR_OPT_ZONE, TITAN_ZM_ID, "OptZone");
399 TitanPanelRightClickMenu_AddToggleVar(ZSM_STR_OPT_ALIAS, TITAN_ZM_ID, "OptAlias");
400  
401 TitanPanelRightClickMenu_AddSpacer();
402  
403 --TitanPanelRightClickMenu_AddCommand(data['name'], TITAN_ZM_ID, "TitanPanelZeppelinMasterButton_ResetCount");
404  
405 -- Generic function to toggle label text
406 --TitanPanelRightClickMenu_AddToggleLabelText(TITAN_ZM_ID);
407  
408 -- Generic function to hide the plugin
409 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_ZM_ID, TITAN_PANEL_MENU_FUNC_HIDE);
410 end
411  
412 function TitanPanelZeppelinMasterButton_OnClick( event )
413 if (event == "LeftButton") then
414  
415 if (table.getn(dropdownvalues) == 0) then
416 activeSelect = -1;
417 activeTransit = -1;
418 return;
419 elseif (activeSelect == -1) then
420 activeSelect = 1;
421 else
422 activeSelect = activeSelect+1;
423 end
424  
425 if (activeSelect > table.getn(dropdownvalues)) then
426 activeSelect = 1;
427 activeTransit = dropdownvalues[activeSelect];
428 else
429 activeTransit = dropdownvalues[activeSelect];
430 end
431  
432 local OptAlias = TitanGetVar(TITAN_ZM_ID, "OptAlias");
433 if (OptAlias) then
434 activeTransitName = zsm_data['transports'][dropdownindexes[activeTransit]]['namealias'];
435 else
436 activeTransitName = zsm_data['transports'][dropdownindexes[activeTransit]]['name'];
437 end
438  
439 local color;
440 if (known_times[activeTransit] ~= nil) then
441 color = GREEN;
442 else
443 color = RED;
444 end
445  
446 -- Set tempory button text so you know which one is currently selected
447 ZM_tempText = color..activeTransitName;
448 ZM_tempTextCount = 2;
449 TitanPanelButton_SetButtonText(TITAN_ZM_ID);
450  
451 if (known_times[activeTransit] == nil) then
452 ZSM_TransportRequestData(activeTransit);
453 end
454 end
455 end
456  
457 function TitanPanelZeppelinMasterButton_SetTransport(id)
458 --DEFAULT_CHAT_FRAME:AddMessage("blah:");
459 --DEFAULT_CHAT_FRAME:AddMessage(dropdownindexes[activeTransit]);
460  
461 if (this.value == -1) then
462 activeSelect = -1;
463 activeTransit = -1;
464 activeTransitName = "None Selected";
465 else
466 activeSelect = this.value;
467 activeTransit = dropdownvalues[this.value];
468  
469 local OptAlias = TitanGetVar(TITAN_ZM_ID, "OptAlias");
470 if (OptAlias) then
471 activeTransitName = zsm_data['transports'][dropdownindexes[activeTransit]]['namealias'];
472 else
473 activeTransitName = zsm_data['transports'][dropdownindexes[activeTransit]]['name'];
474 end
475  
476 if (known_times[activeTransit] == nil) then
477 ZSM_TransportRequestData(activeTransit);
478 end
479  
480 ZM_tempText = activeTransitName;
481 ZM_tempTextCount = 2;
482 end
483  
484 end
485