vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Set Wrangler
4  
5 ]]
6  
7 --------------------------------------------------------------------------------------------------
8 -- Constants
9 --------------------------------------------------------------------------------------------------
10 SW_NUM_CLASSES = table.getn(SW_TEXT_CLASSNAMES);
11 SW_NUM_SET_TABS = 10;
12 SW_NUM_BUTTONS = 8;
13 SW_MAX_CACHE_ATTEMPTS = 50;
14  
15 SW_ITEMS_ON_LINE = 2;
16  
17 SW_PART_HEAD = 1;
18 SW_PART_SHOULD = 2;
19 SW_PART_CHEST = 3;
20 SW_PART_LEGS = 4;
21 SW_PART_HANDS = 5;
22 SW_PART_FEET = 6;
23 SW_PART_BELT = 7;
24 SW_PART_WRISTS = 8;
25 SW_PART_BACK = 9;
26 SW_PART_TRINKET = 10;
27 SW_PART_FINGER = 11;
28 SW_PART_HAND = 12;
29 SW_PART_OHAND = 13;
30 SW_PART_OFFHAND = 14;
31  
32 SW_PART_ZG_TRINK = 1;
33 SW_PART_ZG_NECK = 2;
34 SW_PART_ZG_CHEST = 3;
35 SW_PART_ZG_BELT = 4;
36 SW_PART_ZG_WRISTS = 5;
37  
38 SW_CACHE_TIMER = 0.5;
39  
40 SW_DEFAULT_ICON = "Interface/Icons/INV_Misc_QuestionMark";
41 SW_VERSION = "12";
42  
43 SW_WHISPER_MAX = 17;
44  
45 SW_MAX_TABS = 8;
46  
47 --------------------------------------------------------------------------------------------------
48 -- Globals
49 --------------------------------------------------------------------------------------------------
50 gaClassSetData = {};
51 gSelectedClass = 0;
52 gSelectedSet = 0;
53 gSelectedPart = 0;
54  
55 gLinkToIndex = 1;
56  
57 gDoCacheTimer = 0;
58 gCacheTimer = 0;
59 gCacheAttempts = 0;
60 gCacheData = {};
61 gCacheData.itemLink = "";
62 gCacheData.callback = "";
63 gWhisperLowerBound = 1;
64  
65 gTabSet = 0;
66  
67 gLocalPartData = {};
68  
69 local function dout(msg)
70 if( DEFAULT_CHAT_FRAME) then
71 DEFAULT_CHAT_FRAME:AddMessage(msg,1.0,0,0);
72 end
73 end
74  
75 --------------------------------------------------------------------------------------------------
76 -- Class level functions
77 --------------------------------------------------------------------------------------------------
78 function SetWrangler_LoadClass(classId,setId)
79 SetWrangler_HideInfoIcons();
80  
81 if (setId == nil) then
82 gSelectedSet = 1;
83 setId = 1;
84 end
85  
86 gTabSet = 0;
87 SetWrangler_SetTabText(classId);
88 SetWrangler_LoadSetDropDown();
89 SetWrangler_UpdateClassTabs(classId);
90 SetWrangler_LoadSet(setId);
91  
92 -- Page numbers
93 SetWranglerTabPageText:SetText(SW_TEXT_PAGE.." "..(gTabSet+1).."/"..gaClassSetData[gSelectedClass].numTabSets);
94 end
95  
96 function SetWrangler_UpdateClassTabs(classId)
97 local tabFrame;
98  
99 for i=1,SW_NUM_CLASSES do
100 tabFrame = getglobal("SetWranglerFrameTab"..i);
101  
102 if (i == classId) then
103 PanelTemplates_SelectTab(tabFrame);
104 else
105 PanelTemplates_DeselectTab(tabFrame);
106 end
107 end
108 end
109  
110 function SetWrangler_SetClassTabs()
111 local tabFrame;
112  
113 for i=1,table.getn(gaClassSetData) do
114 --dout("Setting tab: "..i..": "..gaClassSetData[i].sName);
115 tabFrame = getglobal("SetWranglerFrameTab"..i);
116  
117 tabFrame:SetText(gaClassSetData[i].sName);
118 PanelTemplates_TabResize(1,tabFrame);
119 getglobal(tabFrame:GetName().."HighlightTexture"):SetWidth(tabFrame:GetTextWidth() + 35);
120  
121 tabFrame:Show();
122 end
123 end
124  
125 --------------------------------------------------------------------------------------------------
126 -- Set level functions
127 --------------------------------------------------------------------------------------------------
128 function SetWrangler_LoadSet(setId, leaveChecks)
129 -- disable other tabs until set is loaded
130  
131 --dout("Load Set: "..setId);
132 local setSize = table.getn(gaClassSetData[gSelectedClass].aSetData);
133  
134 -- Check everything
135 if (setSize == 0) then
136 SetWrangler_LoadEmptySet();
137 else
138 if (leaveChecks == nil) then
139 SetWrangler_SetChecks(1);
140 end
141  
142 -- Hide the info icon
143 SetWranglerRankIcon:Hide();
144  
145 SetWrangler_UpdateSetTabs(setId);
146  
147 -- Title Text
148 nameLocationText = getglobal("SetWranglerButtonTitle".."ButtonTextNameLocation");
149 infoText = getglobal("SetWranglerButtonTitle".."ButtonTextInfo");
150  
151 SetWranglerButtonTitleButtonTextNameLocation:SetText(gaClassSetData[gSelectedClass].aSetData[setId].sName);
152 infoText:SetText(gaClassSetData[gSelectedClass].aSetData[setId].setInfo);
153  
154 -- Set the set stats
155 SetWranglerFrameInfoText:SetText(gaClassSetData[gSelectedClass].aSetData[setId].setStats);
156  
157 for i=1,SW_NUM_BUTTONS do
158 swButton = getglobal("SetWranglerSetTabFrameButton"..i);
159 swButton:Hide();
160 end
161  
162 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData[setId].aPartData) do
163 nameLocationText = getglobal("SetWranglerSetTabFrameButton"..i.."ButtonTextNameLocation");
164 infoText = getglobal("SetWranglerSetTabFrameButton"..i.."ButtonTextInfo");
165 icon = getglobal("SetWranglerSetTabFrameButton"..i.."Icon");
166  
167 -- Set the text
168 infoText:SetText(gaClassSetData[gSelectedClass].aSetData[setId].aPartData[i].itemInfo);
169  
170 -- Set the icon
171 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink
172  
173 if (string.find(link,"item:") ~= nil) then
174 checkButton = getglobal("SetWranglerSetTabFrameButton"..i.."CheckButton");
175 state = checkButton:GetChecked();
176  
177 if (state ~= nil) then
178 if (SetWranglerOptions.useLocalCacheOnly == nil and SetWranglerOptions.disconnectFree == nil) then
179 SetWrangler_CacheItem(link,SetWrangler_LoadSet);
180 --dout("caching");
181 end
182 end
183 local nm,_,rarity,_,_,_,_,_,tex = GetItemInfo(link);
184  
185 if (tex ~= nil) then
186 icon:SetNormalTexture(tex);
187 else
188 icon:SetNormalTexture(SW_DEFAULT_ICON);
189 end
190  
191 if (nm ~= nil) then
192 nameLocationText:SetText(SW_LINK_COLOR_OPEN..SW_LINK_COLORS[rarity]..nm..SW_LINK_COLOR_CLOSE);
193 elseif (SetWranglerOptions.disconnectFree == nil) then
194 nameLocationText:SetText("Link not cached locally...");
195 else
196 local index = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink;
197 index = string.gsub(index,"item:","");
198 nameLocationText:SetText(SW_LINK_COLOR_OPEN..SWLocalSetData[index]["c"]..SWLocalSetData[index]["i"]..SW_LINK_COLOR_CLOSE);
199 end
200 else
201 icon:SetNormalTexture(SW_DEFAULT_ICON);
202 nameLocationText:SetText("Invalid link...");
203 end
204  
205 swButton = getglobal("SetWranglerSetTabFrameButton"..i);
206 swButton:Show();
207 end
208 end
209 end
210  
211 function SetWrangler_GetItemInfo(link)
212 local part = gLocalPartData[link];
213  
214 local name, tex;
215  
216 if (part ~= nil) then
217 name = SW_LINK_COLOR_OPEN..part.color[1]..part.line[1]..SW_LINK_COLOR_CLOSE;
218 tex = part.tex;
219 else
220 name = "Invalid link...";
221 tex = nil;
222 end
223  
224 return name,tex;
225 end
226  
227  
228 function SetWrangler_SetChecks(state)
229 SetWranglerButtonTitleCheckButton:SetChecked(state);
230  
231 local checkButton;
232  
233 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData) do
234 checkButton = getglobal("SetWranglerSetTabFrameButton"..i.."CheckButton");
235 checkButton:SetChecked(state);
236 end
237 end
238  
239 function SetWrangler_LoadEmptySet()
240 SetWranglerButtonTitleCheckButton:SetChecked(nil);
241  
242 nameLocationText = getglobal("SetWranglerButtonTitle".."ButtonTextNameLocation");
243 infoText = getglobal("SetWranglerButtonTitle".."ButtonTextInfo");
244  
245 SetWranglerButtonTitleButtonTextNameLocation:SetText("Unknown Set");
246 infoText:SetText("Ensure case is handled in SetWranglerData.lua");
247  
248 for i=1,SW_NUM_BUTTONS do
249 swButton = getglobal("SetWranglerSetTabFrameButton"..i);
250 swButton:Hide();
251 end
252 end
253  
254 function SetWrangler_UpdateSetTabs(setId)
255 local tabFrame;
256  
257 setId = setId - (gTabSet * SW_MAX_TABS);
258  
259 for i=1, SW_MAX_TABS do
260 tabFrame = getglobal("SetWranglerSetTabFrameTab"..i);
261  
262 if (i == setId) then
263 PanelTemplates_SelectTab(tabFrame);
264 else
265 PanelTemplates_DeselectTab(tabFrame);
266 end
267 end
268 end
269  
270  
271 function SetWrangler_SetTabText(classId)
272 if (classId == nil) then
273 classId = gSelectedClass;
274 end
275  
276 local startIndex = (gTabSet * SW_MAX_TABS) + 1;
277 local endIndex = startIndex + SW_MAX_TABS - 1;
278  
279 if (table.getn(gaClassSetData[classId].aSetData) < endIndex) then
280 endIndex = table.getn(gaClassSetData[classId].aSetData);
281 end
282  
283 local tabFrame;
284  
285 for i=1,SW_NUM_SET_TABS do
286 tabFrame = getglobal("SetWranglerSetTabFrameTab"..i);
287 tabFrame:Hide();
288 end
289  
290 local tabIndex = 1;
291  
292 for i=startIndex,endIndex do
293 tabFrame = getglobal("SetWranglerSetTabFrameTab"..tabIndex);
294 tabIndex = tabIndex + 1;
295  
296 tabFrame:SetText(gaClassSetData[classId].aSetData[i].sTabName);
297 PanelTemplates_TabResize(0,tabFrame);
298 getglobal(tabFrame:GetName().."HighlightTexture"):SetWidth(tabFrame:GetTextWidth() + 31);
299  
300 if (SetWranglerOptions.useDropDown == nil) then
301 tabFrame:Show();
302 end
303 end
304  
305 -- button disable / enable
306 --dout(gaClassSetData[classId].numTabSets.." == "..(gTabSet + 1));
307 if (gaClassSetData[classId].numTabSets == (gTabSet + 1)) then
308 SetWranglerTabButtonNext:Disable();
309 else
310 SetWranglerTabButtonNext:Enable();
311 end
312  
313 if (gTabSet == 0) then
314 SetWranglerTabButtonBack:Disable();
315 else
316 SetWranglerTabButtonBack:Enable();
317 end
318 end
319  
320  
321 --------------------------------------------------------------------------------------------------
322 -- Utility functions
323 --------------------------------------------------------------------------------------------------
324 function SetWrangler_Toggle()
325 if SetWranglerFrame:IsVisible() then
326 HideUIPanel(SetWranglerFrame);
327 else
328 ShowUIPanel(SetWranglerFrame);
329 end
330 end
331  
332 function SetWrangler_StartCacheTimer(itemLink, callback)
333 gDoCacheTimer = 1;
334 gCacheTimer = 0;
335 --gCacheAttempts = 0;
336  
337 gCacheData.itemLink = itemLink;
338 gCacheData.callback = callback;
339 end
340  
341 function SetWrangler_MakeTextLink(itemLink)
342 local iName,iLink,iRarity,_,iType,_,_,iEquip = GetItemInfo(itemLink);
343  
344 local textLink = nil;
345  
346 if (iName == nil) then
347 --dout("Failed to cache item link");
348 else
349 --dout("Creating a link for: "..iName);
350  
351 -- New link
352 textLink = SW_LINK_COLOR_OPEN;
353 textLink = textLink..SW_LINK_COLORS[iRarity];
354 textLink = textLink..SW_LINK_HYPERLINK_OPEN;
355 textLink = textLink..itemLink;
356 textLink = textLink..SW_LINK_LINK_OPEN;
357 textLink = textLink..iName;
358 textLink = textLink..SW_LINK_LINK_CLOSE;
359 textLink = textLink..SW_LINK_COLOR_CLOSE;
360 end
361  
362 return textLink;
363 end
364  
365 function SetWrangler_CacheItem(itemLink,callback)
366 local attempts = 0;
367 local name = GetItemInfo(itemLink);
368  
369 if (name == nil) then
370 --dout("Caching: "..itemLink);
371  
372 ShowUIPanel(SWCacheTooltip);
373 if ( not SWCacheTooltip:IsVisible() ) then
374 SWCacheTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE");
375 end
376  
377 SWCacheTooltip:SetHyperlink(itemLink);
378  
379 SetWrangler_StartCacheTimer(itemLink,callback);
380 else
381 --dout(itemLink.." is already cached");
382 end
383 end
384  
385 function SetWrangler_LoadPlayerClass()
386 local playerClass = UnitClass("player");
387  
388 if (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_DRUID]) then
389 gSelectedClass = SW_CLASS_DRUID;
390 gSelectedSet = 1;
391 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_HUNTER]) then
392 gSelectedClass = SW_CLASS_HUNTER;
393 gSelectedSet = 1;
394 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_MAGE]) then
395 gSelectedClass = SW_CLASS_MAGE;
396 gSelectedSet = 1;
397 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_PALADIN]) then
398 gSelectedClass = SW_CLASS_PALADIN;
399 gSelectedSet = 1;
400 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_PRIEST]) then
401 gSelectedClass = SW_CLASS_PRIEST;
402 gSelectedSet = 1;
403 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_ROGUE]) then
404 gSelectedClass = SW_CLASS_ROGUE;
405 gSelectedSet = 1;
406 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_SHAMAN]) then
407 gSelectedClass = SW_CLASS_SHAMAN;
408 gSelectedSet = 1;
409 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_WARLOCK]) then
410 gSelectedClass = SW_CLASS_WARLOCK;
411 gSelectedSet = 1;
412 elseif (playerClass == SW_TEXT_CLASSNAMES[SW_CLASS_WARRIOR]) then
413 gSelectedClass = SW_CLASS_WARRIOR;
414 gSelectedSet = 1;
415 end
416  
417 SetWrangler_LoadClass(gSelectedClass, gSelectedSet);
418 end
419  
420  
421 function SetWrangler_Init(opposite)
422 local faction = UnitFactionGroup("player");
423 if (opposite == nil) then
424 if (string.lower(faction) == SW_TEXT_ALLIANCE) then
425 gPlayerFaction = SW_TEXT_ALLIANCE;
426 SW_TEXT_RANK_NAMES = SW_TEXT_RANK_NAMES_A;
427 else
428 gPlayerFaction = SW_TEXT_HORDE;
429 SW_TEXT_RANK_NAMES = SW_TEXT_RANK_NAMES_H;
430 end
431 else
432 if (string.lower(faction) == SW_TEXT_ALLIANCE) then
433 gPlayerFaction = SW_TEXT_HORDE;
434 SW_TEXT_RANK_NAMES = SW_TEXT_RANK_NAMES_H;
435 else
436 gPlayerFaction = SW_TEXT_ALLIANCE;
437 SW_TEXT_RANK_NAMES = SW_TEXT_RANK_NAMES_A;
438 end
439 end
440  
441 for i=1,table.getn(SW_TEXT_CLASSNAMES) do
442 gaClassSetData[i] = SetWrangler_MakeMasterData(i);
443 end
444  
445 SetWrangler_SetClassTabs();
446  
447 -- Set arrow text
448 SetWranglerTabButtonNext:SetText(">>");
449 SetWranglerTabButtonBack:SetText("<<");
450 end
451  
452 function SetWrangler_LoadSetDropDown()
453 UIDropDownMenu_Initialize(SetWranglerSetDropDown, SetWranglerSetDropDownOnInit);
454 UIDropDownMenu_SetWidth(150, SetWranglerSetDropDown);
455  
456 SetWrangler_UpdateSetDropDown();
457 end
458  
459 function SetWrangler_UpdateSetDropDown()
460 UIDropDownMenu_SetSelectedValue(SetWranglerSetDropDown, gSelectedSet);
461 UIDropDownMenu_SetText(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].sTabName,SetWranglerSetDropDown);
462 end
463  
464 --------------------------------------------------------------------------------------------------
465 -- Handler functions
466 --------------------------------------------------------------------------------------------------
467  
468 function SetWranglerOnLoad()
469 UIPanelWindows["SetWranglerFrame"] = { area = "left", pushable = 9, whileDead = 1 };
470  
471 this:RegisterEvent("VARIABLES_LOADED");
472 this:RegisterEvent("PLAYER_LOGIN");
473  
474 -- Register our slash command
475 SLASH_SETWRANGLER1 = "/setwrangler";
476 SLASH_SETWRANGLER2 = "/sw";
477 SlashCmdList["SETWRANGLER"] = function(msg)
478 SetWrangler_SlashCommandHandler(msg);
479 end
480  
481 UIDropDownMenu_Initialize(SetWranglerLinkDropDown, SetWranglerDropDownOnInit);
482 UIDropDownMenu_SetWidth(60, SetWranglerLinkDropDown);
483  
484 UIDropDownMenu_Initialize(SetWranglerRightClickMenu, SetWranglerRightClickMenu_AddItems, "MENU");
485 end
486  
487  
488 function SetWrangler_OnShow()
489 SetWranglerFrameTitleText:SetText(BINDING_HEADER_SETWRANGLER.." v"..SW_VERSION.."");
490  
491 -- Load the player's class
492 SetWrangler_LoadPlayerClass();
493  
494 -- Page numbers
495 SetWranglerTabPageText:SetText(SW_TEXT_PAGE.." "..(gTabSet+1).."/"..gaClassSetData[gSelectedClass].numTabSets);
496  
497 -- temp
498 --SetWrangler_Init();
499 --
500  
501 gLinkToIndex = 1;
502 UIDropDownMenu_SetSelectedValue(SetWranglerLinkDropDown, gLinkToIndex);
503 UIDropDownMenu_SetText(SW_TEXT_LINK_OPTIONS[gLinkToIndex],SetWranglerLinkDropDown);
504  
505 --UIDropDownMenu_SetSelectedValue(SetWranglerSetDropDown, gSelectedSet);
506 --UIDropDownMenu_SetText(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].sTabName,SetWranglerLinkDropDown);
507  
508 if (SetWranglerOptions.disconnectFree ~= nil) then
509 SetWranglerPreviewButton:Disable();
510 SetWranglerLinkButton:Disable();
511 else
512 SetWranglerPreviewButton:Enable();
513 SetWranglerLinkButton:Enable();
514 end
515 end
516  
517 function SetWranglerOnEvent(event)
518 if( event == "VARIABLES_LOADED" ) then
519 if (SetWranglerOptions == nil) then
520 SetWranglerOptions = {};
521 SetWranglerOptions.useLocalCacheOnly = 1;
522 SetWranglerOptions.useDropDown = nil;
523 end
524  
525 -- Set the check
526 SetWranglerLocalCacheCheckButton:SetChecked(SetWranglerOptions.useLocalCacheOnly);
527  
528 -- set the set drop down
529 if (SetWranglerOptions.useDropDown ~= nil) then
530 SetWrangler_ShowTabNav(false);
531 SetWrangler_ShowDropDownNav(true);
532 end
533  
534 -- see if we need to load local data
535 if (SetWranglerOptions.disconnectFree ~= nil) then
536 SetWrangler_LoadLocalData();
537 end
538 elseif( event == "PLAYER_LOGIN" ) then
539 SetWrangler_Init(SetWranglerOptions.viewOpposingFaction);
540 end
541 end
542  
543 function SetWrangler_OnInfoButtonEnter()
544 GameTooltip:SetOwner(this, "ANCHOR_NONE");
545 GameTooltip:SetPoint("TOPLEFT",this, "BOTTOMLEFT",32,0);
546  
547 local link = nil;
548  
549 if (this:GetID() == 1) then
550 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink2;
551 elseif (this:GetID() == 2) then
552 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink3;
553 elseif (this:GetID() == 3) then
554 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink4;
555 else
556 link = "";
557 end
558  
559 if (SetWranglerOptions.disconnectFree == nil) then -- do normal method
560  
561 if (string.find(link,"item:") ~= nil) then
562 if (GetItemInfo(link)) then
563 GameTooltip:SetHyperlink(link);
564 GameTooltip:Show();
565 end
566 end
567 else
568 local index = string.gsub(link,"item:","");
569 SetWrangler_SetLocalTooltip(index);
570 end
571 end
572  
573 function SetWrangler_OnButtonEnter()
574 GameTooltip:SetOwner(this, "ANCHOR_NONE");
575 GameTooltip:SetPoint("TOPLEFT",this, "BOTTOMLEFT",32,0);
576  
577 if (SetWranglerOptions.disconnectFree == nil) then -- do normal method
578 local link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[this:GetParent():GetID()].itemLink;
579  
580 if (string.find(link,"item:") ~= nil) then
581 if (GetItemInfo(link)) then
582 GameTooltip:SetHyperlink(link);
583 GameTooltip:Show();
584 end
585 end
586 else -- Do disconnect free local method
587 local index = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[this:GetParent():GetID()].itemLink;
588 index = string.gsub(index,"item:","");
589 SetWrangler_SetLocalTooltip(index);
590 end
591  
592 this:GetParent():LockHighlight();
593 end
594  
595 function SetWrangler_SetLocalTooltip(index)
596 local ttText = SWLocalSetData[index]["t"];
597 local token = "";
598  
599 if (ttText ~= nil) then
600 local color = SWLocalSetData[index]["c"];
601  
602 --dout(ttText);
603 token,ttText = SetWrangler_GetToken(ttText);
604 GameTooltip:AddLine(SW_LINK_COLOR_OPEN..color..token..SW_LINK_COLOR_CLOSE);
605  
606 -- Binding
607 token,ttText = SetWrangler_GetToken(ttText);
608 GameTooltip:AddLine(SW_LINK_COLOR_OPEN.."ffffff"..token..SW_LINK_COLOR_CLOSE);
609  
610 -- Spot and type
611 leftToken,ttText = SetWrangler_GetToken(ttText);
612 rightToken,ttText = SetWrangler_GetToken(ttText);
613 GameTooltip:AddDoubleLine(leftToken,rightToken,1,1,1,1,1,1);
614  
615 -- The bonuses
616 token,ttText = SetWrangler_GetToken(ttText);
617 --dout(token.." ("..SetWrangler_SafeLen(token)..")");
618 local lineColor = "ffffff";
619 while (SetWrangler_IsEmpty(token) == false) do
620 if (string.find(token,"Equip:") ~= nil or string.find(token,"Passive:") ~= nil or string.find(token,"Use:") ~= nil) then
621 lineColor = SW_GREEN;
622 end
623  
624 GameTooltip:AddLine(SW_LINK_COLOR_OPEN..lineColor..token..SW_LINK_COLOR_CLOSE);
625 token,ttText = SetWrangler_GetToken(ttText);
626 --dout(token.." ("..SetWrangler_SafeLen(token)..")");
627  
628 end
629  
630 local firstTime = true;
631  
632 -- Set the set text
633 token,ttText = SetWrangler_GetToken(ttText);
634 while (SetWrangler_SafeLen(token) > 0) do
635 if (firstTime == true) then
636 GameTooltip:AddLine(" ");
637 firstTime = false;
638 end
639 GameTooltip:AddLine(SW_GOLD_OPEN..token..SW_LINK_COLOR_CLOSE);
640 token,ttText = SetWrangler_GetToken(ttText);
641 end
642  
643 firstTime = true;
644  
645 -- Set the descriptive text
646 token,ttText = SetWrangler_GetToken(ttText);
647 while (SetWrangler_SafeLen(token) > 0) do
648 if (firstTime == true) then
649 GameTooltip:AddLine(" ");
650 firstTime = false;
651 end
652 GameTooltip:AddLine(SW_GREEN_OPEN..token..SW_LINK_COLOR_CLOSE);
653 token,ttText = SetWrangler_GetToken(ttText);
654 end
655  
656 GameTooltip:SetWidth(200);
657 GameTooltip:Show();
658 end
659 end
660  
661 function SetWrangler_GetToken(ttText)
662 if (ttText == nil) then
663 return nil,nil;
664 end
665  
666 local lineEnd = string.find(ttText,"·");
667  
668 if (lineEnd == nil) then
669 return "";
670 end
671  
672 if (lineEnd > 35) then
673 for i=35, SetWrangler_SafeLen(ttText) do
674 --dout(string.byte(token,i));
675 local char = string.byte(ttText,i);
676  
677 if (char > 127 or char == 32) then
678 lineEnd = i;
679 i = SetWrangler_SafeLen(ttText);
680 end
681 end
682 end
683  
684 local token = string.sub(ttText,1,lineEnd);
685 ttText = string.sub(ttText,lineEnd+1);
686  
687 return token,ttText;
688 end
689  
690 function SetWrangler_SafeLen(str)
691 if (str == nil) then
692 return 0;
693 end
694  
695 return string.len(str);
696 end
697  
698 function SetWrangler_IsEmpty(token)
699 if (SetWrangler_SafeLen(token) == 0) then
700 return true;
701 end
702  
703 for i=1, SetWrangler_SafeLen(token) do
704 --dout(string.byte(token,i));
705 local char = string.byte(token,i);
706  
707 if (char ~= 32 and char ~= 10 and char < 127) then
708 return false;
709 end
710 end
711  
712 return true;
713 end
714  
715 function SetWrangler_OnUpdate(elapse)
716 if (gDoCacheTimer == 1) then
717 --dout("Update: "..gCacheTimer);
718 gCacheTimer = gCacheTimer + elapse;
719  
720 if (gCacheTimer > SW_CACHE_TIMER) then
721 gDoCacheTimer = 0;
722 gCacheAttempts = gCacheAttempts + 1;
723  
724 if (gCacheAttempts <= SW_MAX_CACHE_ATTEMPTS) then
725 gCacheData.callback(gSelectedSet,1);
726 else
727 nameLocationText:SetText("Failed to load link...");
728 end
729 end
730 end
731 end
732  
733 function SetWranglerFunctionButton_OnEnter()
734 if( this:GetCenter() < GetScreenWidth() / 2 ) then
735 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
736 else
737 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
738 end
739  
740 if (this == SetWranglerPreviewButton) then
741 GameTooltip:SetText("Preview the checked items in the Dressing Room.");
742 elseif (this == SetWranglerLinkButton) then
743 GameTooltip:SetText("Link the checked items in the chat window.");
744 elseif (this == SetWranglerLocalCacheCheckButton or this == SWOptionsLocalCacheCheckButton) then
745 GameTooltip:SetText(SW_TEXT_CACHE_TT);
746 elseif (this == SetWranglerTabButtonNext) then
747 GameTooltip:SetText(SW_TEXT_TAB_NEXT);
748 elseif (this == SetWranglerTabButtonBack) then
749 GameTooltip:SetText(SW_TEXT_TAB_BACK);
750 elseif (this == SWOptionsDropDownCheckButton) then
751 GameTooltip:SetText(SW_TEXT_TAB_NAV);
752 elseif (this == SWOptionsMOFakeButton) then
753 GameTooltip:SetText(SW_TEXT_PMODE);
754 elseif (this == SWOptionsDisconnectFreeCheckButton) then
755 GameTooltip:SetText(SW_TEXT_DFMODE);
756 end
757  
758 end
759  
760 function SetWrangler_SlashCommandHandler(msg)
761 SetWrangler_Toggle();
762 end
763  
764 --------------------------------------------------------------------------------------------------
765 -- OnClick Handlers
766 --------------------------------------------------------------------------------------------------
767 function SetWranglerOnEventOnClassClick(classId)
768 gDoCacheTimer = 0;
769  
770 SetWrangler_HideInfoIcons();
771  
772 gSelectedClass = classId;
773  
774 if (classId <= table.getn(gaClassSetData)) then
775 SetWrangler_LoadClass(classId);
776 end
777 end
778  
779  
780 function SetWranglerOnEventOnSetClick(setId)
781 gDoCacheTimer = 0;
782  
783 SetWrangler_HideInfoIcons();
784  
785 gSelectedSet = (gTabSet * SW_MAX_TABS) + setId;
786 SetWrangler_LoadSet(gSelectedSet);
787 SetWrangler_UpdateSetDropDown();
788 end
789  
790 function SetWrangler_OnCheckButtonClick()
791 local state = this:GetChecked();
792 SetWrangler_SetChecks(state);
793 end
794  
795 function SetWrangler_OnPreview()
796 --ShowUIPanel(DressUpModel);
797 -- Dummy link to open it or Undress will not work initially
798 DressUpItemLink("");
799  
800 if (SetWranglerOptions.previewMode == 2) then -- get naked
801 DressUpModel:Undress();
802 elseif (SetWranglerOptions.previewMode == 3) then -- dress in current armor
803 DressUpModel:Dress();
804 end
805  
806 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData) do
807 checkButton = getglobal("SetWranglerSetTabFrameButton"..i.."CheckButton");
808 state = checkButton:GetChecked();
809  
810 if (state ~= nil) then
811 if (GetItemInfo(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink) ~= nil) then
812 DressUpItemLink(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink);
813 end
814 end
815 end
816 --DressUpItemLink("item:4044:0:0:0");
817 --DressUpItemLink("item:16793:0:0:0");
818 end
819  
820 function SetWrangler_OnLink()
821 --dout("Link");
822 local numOnLine = 0;
823 local line = "";
824  
825 local CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[gLinkToIndex];
826  
827 SendChatMessage(BINDING_HEADER_SETWRANGLER.." "..SW_TEXT_LINKS,CHAT_SYSTEM,nil,nil);
828 SendChatMessage(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].sName.." ("..gaClassSetData[gSelectedClass].sName..", "..gaClassSetData[gSelectedClass].aSetData[gSelectedSet].setInfo..")",CHAT_SYSTEM,nil,nil);
829 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData) do
830 checkButton = getglobal("SetWranglerSetTabFrameButton"..i.."CheckButton");
831 state = checkButton:GetChecked();
832  
833 if (state ~= nil) then
834 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink
835  
836 if (GetItemInfo(link) ~= nil) then
837 textLink = SetWrangler_MakeTextLink(link);
838  
839 if (textLink ~= nil and string.find(link,"item:") ~= nil) then
840 line = line..textLink..", ";
841 numOnLine = numOnLine + 1;
842  
843 val = math.mod(numOnLine,SW_ITEMS_ON_LINE);
844  
845 if (math.mod(numOnLine,SW_ITEMS_ON_LINE) == 0) then
846 line = string.sub(line,1,string.len(line) - 2);
847 SendChatMessage(line,CHAT_SYSTEM,nil,nil);
848 numOnLine = 0;
849 line = "";
850 end
851 end
852 end
853 end
854 end
855  
856 if (numOnLine > 0) then
857 line = string.sub(line,1,string.len(line) - 2);
858 SendChatMessage(line,system,nil,whisperName);
859 end
860 end
861  
862 function SetWrangler_OnLocalCache()
863 if (SetWranglerOptions.useLocalCacheOnly == nil) then
864 SetWranglerOptions.useLocalCacheOnly = 1;
865 else
866 SetWranglerOptions.useLocalCacheOnly = nil;
867 SetWrangler_HideInfoIcons();
868 SetWrangler_LoadSet(gSelectedSet,1);
869 end
870 end
871  
872 function SetWranglerCommand_OnLink(system, whisperName)
873 --dout("Link");
874  
875 local numOnLine = 0;
876 local line = "";
877  
878 SendChatMessage(BINDING_HEADER_SETWRANGLER.." "..SW_TEXT_LINKS,system,nil,whisperName);
879 SendChatMessage(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].sName.." ("..gaClassSetData[gSelectedClass].sName..", "..gaClassSetData[gSelectedClass].aSetData[gSelectedSet].setInfo..")",system,nil,whisperName);
880 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData) do
881 checkButton = getglobal("SetWranglerSetTabFrameButton"..i.."CheckButton");
882 state = checkButton:GetChecked();
883  
884 if (state ~= nil) then
885 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[i].itemLink
886  
887 if (GetItemInfo(link) ~= nil) then
888 textLink = SetWrangler_MakeTextLink(link);
889  
890 if (textLink ~= nil and string.find(link,"item:") ~= nil) then
891 line = line..textLink..", ";
892 numOnLine = numOnLine + 1;
893  
894 if (math.mod(numOnLine,SW_ITEMS_ON_LINE) == 0) then
895 line = string.sub(line,1,string.len(line) - 2);
896 SendChatMessage(line,system,nil,whisperName);
897 numOnLine = 0;
898 line = "";
899 end
900 end
901 end
902 end
903 end
904  
905 if (numOnLine > 0) then
906 line = string.sub(line,1,string.len(line) - 2);
907 SendChatMessage(line,system,nil,whisperName);
908 end
909 end
910  
911 function SetWrangler_HideInfoIcons()
912 -- Hide the info icons
913 SetWranglerSetTabFrameInfoIcon1:Hide();
914 SetWranglerSetTabFrameInfoIcon2:Hide();
915 SetWranglerSetTabFrameInfoIcon3:Hide();
916 end
917  
918 function SetWrangler_LoadInfoIcons()
919 local part = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart];
920  
921 SetWrangler_HideInfoIcons();
922  
923 for i=1,3 do
924 local link = nil;
925  
926 if (i == 1) then
927 link = part.itemLink2;
928 elseif (i == 2) then
929 link = part.itemLink3;
930 elseif (i == 3) then
931 link = part.itemLink4;
932 end
933  
934 local button = getglobal("SetWranglerSetTabFrameInfoIcon"..i);
935 local title = getglobal("SetWranglerInfoIconTitle"..i);
936 if (link ~= nil) then
937 if (string.find(link,"item:") ~= nil) then
938 if (SetWranglerOptions.useLocalCacheOnly == nil) then
939 SetWrangler_CacheItem(link,SetWrangler_LoadInfoIcons);
940 end
941  
942 local nm,_,rarity,_,_,_,_,_,tex = GetItemInfo(link);
943  
944 if (tex ~= nil) then
945 button:SetNormalTexture(tex);
946 else
947 button:SetNormalTexture(SW_DEFAULT_ICON);
948 end
949  
950 if (nm ~= nil) then
951 title:SetText(SW_LINK_COLOR_OPEN..SW_LINK_COLORS[rarity]..nm..SW_LINK_COLOR_CLOSE);
952 elseif (SetWranglerOptions.disconnectFree == nil) then
953 title:SetText("Link not cached locally...");
954 else
955 local index = string.gsub(link,"item:","");
956 title:SetText(SW_LINK_COLOR_OPEN..SWLocalSetData[index]["c"]..SWLocalSetData[index]["i"]..SW_LINK_COLOR_CLOSE);
957 end
958 else
959 --dout("default tex");
960 button:SetNormalTexture(SW_DEFAULT_ICON);
961 end
962  
963 button:Show();
964 end
965 end
966 end
967  
968  
969 function SetWranglerItem_OnClick(button)
970 gDoCacheTimer = 0;
971  
972 local partIndex = this:GetID();
973  
974 if (partIndex == 500) then -- then icon button
975 partIndex = this:GetParent():GetID();
976 end
977  
978 gSelectedPart = partIndex;
979  
980 if (button == "LeftButton") then
981 if (IsShiftKeyDown()) then
982 if (SetWranglerOptions.disconnectFree == nil) then
983 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink
984  
985 if (link ~= nil) then
986 if (GetItemInfo(link) ~= nil) then
987 textLink = SetWrangler_MakeTextLink(link);
988  
989 if ( not ChatFrameEditBox:IsVisible() ) then
990 ChatFrame_OpenChat(textLink);
991 else
992 ChatFrameEditBox:SetText(ChatFrameEditBox:GetText()..textLink);
993 end
994 end
995 end
996 end
997 else
998 -- see if the part has an info icon
999 local part = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[partIndex];
1000 infoIcon = part.itemInfoIcon;
1001 if (infoIcon ~= nil) then
1002 SetWranglerRankIcon:SetTexture(infoIcon);
1003 SetWranglerRankIcon:Show();
1004 else
1005 SetWranglerRankIcon:Hide();
1006 end
1007  
1008 SetWranglerFrameInfoText:SetText(part.itemStats);
1009  
1010 SetWrangler_LoadInfoIcons();
1011 end
1012 else
1013 if (SetWranglerOptions.disconnectFree == nil) then
1014 gWhisperLowerBound = 1;
1015  
1016 xOffset = 72;
1017 yOffset = (this:GetHeight() / 2);
1018  
1019 ToggleDropDownMenu(1, nil, SetWranglerRightClickMenu, "SetWranglerSetTabFrameButton"..partIndex, xOffset, yOffset);
1020 end
1021 end
1022 end
1023  
1024 function SetWranglerTitleButton_OnClick(button)
1025 SetWrangler_HideInfoIcons();
1026  
1027 -- Set the set stats
1028 gSelectedPart = 0;
1029  
1030 if (button == "LeftButton") then
1031 SetWranglerRankIcon:Hide();
1032 SetWranglerFrameInfoText:SetText(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].setStats);
1033 else
1034 gWhisperLowerBound = 1;
1035 xOffset = 40;
1036 yOffset = (this:GetHeight() / 2);
1037  
1038 ToggleDropDownMenu(1, nil, SetWranglerRightClickMenu, "SetWranglerButtonTitle", xOffset, yOffset);
1039 end
1040 end
1041  
1042 function SetWranglerRightClickMenu_OnClick()
1043 ToggleDropDownMenu(1, nil, SetWranglerRightClickMenu, "SetWranglerSetTabFrame", 100, 420);
1044  
1045 if (this.value == "preview") then
1046 if (gSelectedPart > 0) then
1047 if (GetItemInfo(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink) ~= nil) then
1048 DressUpItemLink(gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink);
1049 end
1050 else -- do whole set
1051 SetWrangler_OnPreview();
1052 end
1053 else
1054 local CHAT_SYSTEM, link;
1055  
1056 if (this.value == 1) then
1057 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[1];
1058 elseif (this.value == 2) then
1059 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[2];
1060 elseif (this.value == 3) then
1061 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[3];
1062 elseif (this.value == 4) then
1063 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[4];
1064 elseif (this.value == 5) then
1065 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[5];
1066 elseif (this.value == 6) then
1067 CHAT_SYSTEM = SW_TEXT_LINK_OPTIONS_SL[6];
1068 end
1069  
1070 if (gSelectedPart > 0) then
1071 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink;
1072  
1073 if (string.find(link,"item:") ~= nil) then
1074  
1075 SendChatMessage(BINDING_HEADER_SETWRANGLER.." "..SW_TEXT_LINKS,CHAT_SYSTEM);
1076  
1077 textLink = SetWrangler_MakeTextLink(link);
1078  
1079 if (GetItemInfo(link) ~= nil) then
1080 if (textLink ~= nil) then
1081 SendChatMessage(textLink,CHAT_SYSTEM);
1082 end
1083 end
1084 end
1085 else -- link set
1086 SetWranglerCommand_OnLink(CHAT_SYSTEM);
1087 end
1088 end
1089 end
1090  
1091 function SetWranglerWhisperRightClickMenu_OnClick()
1092 ToggleDropDownMenu(1, nil, SetWranglerRightClickMenu, "SetWranglerSetTabFrame", 100, 420);
1093  
1094 local whisper;
1095  
1096 if (this.value == 0) then
1097 whisper = UnitName("target");
1098 else
1099 whisper = this.value;
1100 end
1101  
1102 if (whisper ~= nil) and (string.len(whisper) > 0) then
1103 if (gSelectedPart > 0 and string.find(link,"item:") ~= nil) then
1104 link = gaClassSetData[gSelectedClass].aSetData[gSelectedSet].aPartData[gSelectedPart].itemLink;
1105  
1106 if (GetItemInfo(link) ~= nil) then
1107 textLink = SetWrangler_MakeTextLink(link);
1108 SendChatMessage(textLink,"WHISPER",nil,whisper);
1109 end
1110 else
1111 SetWranglerCommand_OnLink("WHISPER",whisper);
1112 end
1113 end
1114 end
1115  
1116 function SetWranglerMoreRightClickMenu_OnClick()
1117 --dout("inc and update");
1118 gWhisperLowerBound = gWhisperLowerBound + SW_WHISPER_MAX + 1;
1119  
1120 UIDropDownMenu_Initialize(SetWranglerRightClickMenu, SetWranglerRightClickMenu_AddItems, "MENU");
1121 end
1122  
1123  
1124 function SetWrangler_OnTabNavClick()
1125 if (this == SetWranglerTabButtonNext) then
1126 gTabSet = gTabSet + 1;
1127 elseif (this == SetWranglerTabButtonBack) then
1128 gTabSet = gTabSet - 1;
1129 end
1130  
1131 SetWrangler_UpdateSetTabs(gSelectedSet);
1132 SetWrangler_SetTabText();
1133 -- Page numbers
1134 SetWranglerTabPageText:SetText(SW_TEXT_PAGE.." "..(gTabSet+1).."/"..gaClassSetData[gSelectedClass].numTabSets);
1135 end
1136  
1137 function SetWrangler_OnOptions()
1138 ShowUIPanel(SWOptionsFrame);
1139 end
1140 --------------------------------------------------------------------------------------------------
1141 -- Menu functions
1142 --------------------------------------------------------------------------------------------------
1143 function SetWranglerDropDownOnInit()
1144 SetWranglerDropDownAdd(SetWranglerDropDownDropDownOnSelect);
1145 end
1146  
1147 function SetWranglerSetDropDownOnInit()
1148 SetWranglerDropDownAddSets(SetWranglerSetDropDownOnSelect);
1149 end
1150  
1151  
1152 function SetWranglerDropDownDropDownOnSelect()
1153 UIDropDownMenu_SetSelectedValue(SetWranglerLinkDropDown, this.value);
1154 UIDropDownMenu_SetText(SW_TEXT_LINK_OPTIONS[this.value],SetWranglerLinkDropDown);
1155 gLinkToIndex = this.value;
1156 end
1157  
1158 function SetWranglerSetDropDownOnSelect()
1159 UIDropDownMenu_SetSelectedValue(SetWranglerSetDropDown, this.value);
1160 UIDropDownMenu_SetText(gaClassSetData[gSelectedClass].aSetData[this.value].sTabName,SetWranglerSetDropDown);
1161  
1162 gDoCacheTimer = 0;
1163  
1164 SetWrangler_HideInfoIcons();
1165  
1166 local setId = this.value;
1167  
1168 gSelectedSet = setId;
1169  
1170 -- set the correct tab set here
1171 gTabSet = math.ceil(setId / SW_MAX_TABS) - 1;
1172 SetWrangler_UpdateSetTabs(gSelectedSet);
1173 SetWrangler_SetTabText();
1174  
1175 SetWrangler_LoadSet(setId);
1176 end
1177  
1178 function SetWranglerDropDownAdd(func)
1179 for i=1,table.getn(SW_TEXT_LINK_OPTIONS) do
1180 info = {};
1181 info.text = SW_TEXT_LINK_OPTIONS[i];
1182 info.func = func;
1183 info.value = i;
1184 UIDropDownMenu_AddButton(info);
1185 end
1186 end
1187  
1188  
1189 function SetWranglerDropDownAddSets(func)
1190 --dout(gSelectedClass);
1191 for i=1,table.getn(gaClassSetData[gSelectedClass].aSetData) do
1192 info = {};
1193 info.text = gaClassSetData[gSelectedClass].aSetData[i].sTabName;
1194 info.func = func;
1195 info.value = i;
1196 UIDropDownMenu_AddButton(info);
1197 end
1198 end
1199  
1200  
1201 function SetWranglerRightClickMenu_AddItems()
1202 --dout("Init");
1203  
1204 if (UIDROPDOWNMENU_MENU_LEVEL == 1) then
1205 SetWranglerRightClickMenu_AddTitle(BINDING_HEADER_SETWRANGLER);
1206 SetWranglerRightClickMenu_AddCommand(SW_TEXT_PREVIEW, "preview", SetWranglerRightClickMenu_OnClick, nil);
1207 SetWranglerRightClickMenu_AddNest(SW_TEXT_LINK, "2")
1208 elseif (UIDROPDOWNMENU_MENU_LEVEL == 2) then
1209 for i=1,table.getn(SW_TEXT_LINK_OPTIONS) do
1210 SetWranglerRightClickMenu_AddCommand(SW_TEXT_LINK_OPTIONS[i], i, SetWranglerRightClickMenu_OnClick, nil, UIDROPDOWNMENU_MENU_LEVEL);
1211 end
1212  
1213 SetWranglerRightClickMenu_AddNest(SW_TEXT_WHISPER, "3",2);
1214 elseif (UIDROPDOWNMENU_MENU_LEVEL == 3) then
1215 SetWranglerRightClickMenu_AddCommand(SW_LINK_COLOR_OPEN..SW_LINK_COLORS[3]..SW_TEXT_WHISPER_TARGET..SW_LINK_COLOR_CLOSE, 0, SetWranglerWhisperRightClickMenu_OnClick,nil, UIDROPDOWNMENU_MENU_LEVEL, 74, 133, 184);
1216  
1217 local bound = gWhisperLowerBound + SW_WHISPER_MAX;
1218 local addMore = 0;
1219  
1220 if (bound > GetNumFriends()) then
1221 bound = GetNumFriends();
1222 else
1223 addMore = 1;
1224 end
1225  
1226 --dout("low: "..gWhisperLowerBound);
1227 --dout("high: "..bound);
1228  
1229 for i=gWhisperLowerBound,bound do
1230 local name, level, class, area, connected = GetFriendInfo(i);
1231 if (connected == 1) then
1232 SetWranglerRightClickMenu_AddCommand(name, name, SetWranglerWhisperRightClickMenu_OnClick, nil, UIDROPDOWNMENU_MENU_LEVEL);
1233 else
1234 SetWranglerRightClickMenu_AddCommand(name, name, SetWranglerWhisperRightClickMenu_OnClick, 1, UIDROPDOWNMENU_MENU_LEVEL);
1235 end
1236 end
1237  
1238 if (addMore == 1) then
1239 SetWranglerRightClickMenu_AddMoreCommand(SW_LINK_COLOR_OPEN..SW_LINK_COLORS[3]..SW_TEXT_MORE..SW_LINK_COLOR_CLOSE, 0, SetWranglerMoreRightClickMenu_OnClick,UIDROPDOWNMENU_MENU_LEVEL);
1240 end
1241 end
1242 end
1243  
1244  
1245 function SetWranglerRightClickMenu_AddTitle(title, level)
1246 if (title) then
1247 local info = {};
1248 info.text = title;
1249 info.notClickable = 1;
1250 info.isTitle = 1;
1251 UIDropDownMenu_AddButton(info, level);
1252 end
1253 end
1254  
1255 function SetWranglerRightClickMenu_AddNest(text, value, level)
1256 local info = {};
1257 info.text = text;
1258 --info.value = value;
1259 info.func = nil;
1260 info.hasArrow = 1;
1261 info.notCheckable = 1;
1262 info.keepShownOnClick = 1;
1263 UIDropDownMenu_AddButton(info, level);
1264 end
1265  
1266 function SetWranglerRightClickMenu_AddCommand(text, value, functionName, disabled, level, r, g, b)
1267 local info = {};
1268 info.text = text;
1269 info.value = value;
1270 info.func = functionName;
1271 info.notCheckable = 1;
1272 info.disabled = disabled;
1273  
1274 info.r = r;
1275 info.g = g;
1276 info.b = b;
1277  
1278 UIDropDownMenu_AddButton(info, level);
1279 end
1280  
1281 function SetWranglerRightClickMenu_AddMoreCommand(text, value, functionName, level)
1282 local info = {};
1283 info.text = text;
1284 info.value = value;
1285 info.func = functionName;
1286 info.notCheckable = 1;
1287 info.keepShownOnClick = 1;
1288 info.checked = nil;
1289 UIDropDownMenu_AddButton(info, level);
1290 end
1291  
1292 --------------------------------------------------------------------------------------------------
1293 -- Options functions
1294 --------------------------------------------------------------------------------------------------
1295 function SWOptionsFrame_OnLoad()
1296  
1297 end
1298  
1299 function SWOptionsFrame_OnShow()
1300 SWOptionsLocalCacheCheckButton:SetChecked(SetWranglerLocalCacheCheckButton:GetChecked());
1301 SWOptionsDropDownCheckButton:SetChecked(SetWranglerOptions.useDropDown);
1302 SWOptionsDisconnectFreeCheckButton:SetChecked(SetWranglerOptions.disconnectFree);
1303  
1304 UIDropDownMenu_Initialize(SWOptionsPreviewModeDropDown, SetWrranglerPreviewModeDropDownOnInit);
1305 UIDropDownMenu_SetWidth(150, SWOptionsPreviewModeDropDown);
1306  
1307 if (SetWranglerOptions.previewMode == nil) then
1308 SetWranglerOptions.previewMode = 1;
1309 end
1310  
1311 UIDropDownMenu_SetSelectedValue(SWOptionsPreviewModeDropDown, SetWranglerOptions.previewMode);
1312 UIDropDownMenu_SetText(SW_TEXT_PREVIEW_OPTIONS[SetWranglerOptions.previewMode],SWOptionsPreviewModeDropDown);
1313 end
1314  
1315 function SWOptionsFrame_OnHide()
1316  
1317 end
1318  
1319 function SWOptionsFrame_OnOK()
1320 ---
1321 SetWranglerOptions.useLocalCacheOnly = SWOptionsLocalCacheCheckButton:GetChecked();
1322 SetWranglerLocalCacheCheckButton:SetChecked(SetWranglerOptions.useLocalCacheOnly);
1323  
1324 ---
1325 SetWranglerOptions.useDropDown = SWOptionsDropDownCheckButton:GetChecked();
1326  
1327 if (SetWranglerOptions.useDropDown ~= nil) then
1328 SetWrangler_ShowTabNav(false);
1329 SetWrangler_ShowDropDownNav(true);
1330 else
1331 SetWrangler_ShowTabNav(true);
1332 SetWrangler_ShowDropDownNav(false);
1333 end
1334  
1335 ---
1336 SetWranglerOptions.disconnectFree = SWOptionsDisconnectFreeCheckButton:GetChecked();
1337  
1338 if (SetWranglerOptions.disconnectFree ~= nil) then
1339 SetWrangler_LoadLocalData();
1340 -- Disable the preview and link buttons
1341 SetWranglerPreviewButton:Disable();
1342 SetWranglerLinkButton:Disable();
1343 SetWranglerLocalCacheCheckButton:Hide();
1344 else
1345 SetWrangler_ClearLocalData();
1346 SetWranglerPreviewButton:Enable();
1347 SetWranglerLinkButton:Enable();
1348 SetWranglerLocalCacheCheckButton:Show();
1349 end
1350 ---
1351 HideUIPanel(SWOptionsFrame);
1352  
1353 -- refresh the current set
1354 SetWrangler_LoadSet(gSelectedSet);
1355 end
1356  
1357 function SetWrangler_ShowTabNav(show)
1358 local tabFrame;
1359  
1360 if (show == false) then
1361 for i=1,SW_NUM_SET_TABS do
1362 tabFrame = getglobal("SetWranglerSetTabFrameTab"..i);
1363 tabFrame:Hide();
1364 end
1365  
1366 SetWranglerTabButtonNext:Hide();
1367 SetWranglerTabButtonBack:Hide();
1368 SetWranglerTabPageText:Hide();
1369 else
1370 SetWrangler_SetTabText(gSelectedClass);
1371  
1372 SetWranglerTabButtonNext:Show();
1373 SetWranglerTabButtonBack:Show();
1374 SetWranglerTabPageText:Show();
1375 end
1376 end
1377  
1378 function SetWrangler_ShowDropDownNav(show)
1379 if (show == false) then
1380 SetWranglerSetDropDown:Hide();
1381 else
1382 SetWranglerSetDropDown:Show();
1383 end
1384 end
1385  
1386  
1387 function SetWrranglerPreviewModeDropDownOnInit()
1388 SetWranglerPreviewModeDropDownAdd(SetWranglerPreviewModeDropDownOnSelect);
1389 end
1390  
1391 function SetWranglerPreviewModeDropDownAdd(func)
1392 for i=1,table.getn(SW_TEXT_PREVIEW_OPTIONS) do
1393 info = {};
1394 info.text = SW_TEXT_PREVIEW_OPTIONS[i];
1395 info.func = func;
1396 info.value = i;
1397 UIDropDownMenu_AddButton(info);
1398 end
1399 end
1400  
1401 function SetWranglerPreviewModeDropDownOnSelect()
1402 UIDropDownMenu_SetSelectedValue(SWOptionsPreviewModeDropDown, SetWranglerOptions.previewMode);
1403 UIDropDownMenu_SetText(SW_TEXT_PREVIEW_OPTIONS[this.value],SWOptionsPreviewModeDropDown);
1404  
1405 SetWranglerOptions.previewMode = this.value;
1406 end