vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 GUILDADSFRAME_DEBUG = false;
2  
3 local g_playerName = "Noname";
4 local g_realmName = "None";
5  
6 local GUILDADS_NUM_GLOBAL_AD_BUTTONS = 17;
7 local GUILDADS_NUM_MY_AD_BUTTONS = 5;
8  
9 GUILDADS_ADBUTTONSIZEY = 16;
10  
11 GUILDADS_MY_ADS = 1;
12 GUILDADS_MY_FILTER = 2;
13  
14 -- Pour GuildAds_GameTooltip_AddText
15 local MAX_LINE_SIZE=60;
16  
17 local g_adtype = GUILDADS_MSG_TYPE_REQUEST; --- Which ads type
18 local g_mytype = GUILDADS_MY_ADS; --- My ads, Filter
19  
20 local g_GlobalAdSelected; --- Index of the ad currently selected
21 local g_GlobalTitleSelected; --- Index of the title currently selected
22 local g_MyAdSelected; --- Index of my ad currently selected
23  
24 local g_HideGroup = { --- Minus/Plus on title
25 [GUILDADS_MSG_TYPE_ANNONCE] = {},
26 [GUILDADS_MSG_TYPE_REQUEST] = {},
27 [GUILDADS_MSG_TYPE_AVAILABLE] = {},
28 [GUILDADS_MSG_TYPE_EVENT] = {},
29 [GUILDADS_MSG_TYPE_SKILL] = {}
30 };
31  
32 local g_AdFilters = {
33 [GUILDADS_MSG_TYPE_ANNONCE] = {},
34 [GUILDADS_MSG_TYPE_REQUEST] = {},
35 [GUILDADS_MSG_TYPE_AVAILABLE] = {},
36 [GUILDADS_MSG_TYPE_EVENT] = {},
37 [GUILDADS_MSG_TYPE_SKILL] = {}
38 };
39  
40 local g_AdColor = {
41 [GUILDADS_MSG_TYPE_ANNONCE] = { ["r"] = 1, ["g"] = 1, ["b"] = 1 },
42 [GUILDADS_MSG_TYPE_REQUEST] = { ["r"] = 1, ["g"] = 1, ["b"] = 1 },
43 [GUILDADS_MSG_TYPE_AVAILABLE] = { ["r"] = 0.75, ["g"] = 0.75, ["b"] = 1 },
44 [GUILDADS_MSG_TYPE_INVENTORY] = { ["r"] = 1, ["g"] = 0.75, ["b"] = 0.75 },
45 [GUILDADS_MSG_TYPE_EVENT] = { ["r"] = 1, ["g"] = 1, ["b"] = 1 },
46 [GUILDADS_MSG_TYPE_SKILL] = { ["r"] = 1, ["g"] = 1, ["b"] = 0.5 },
47 };
48  
49 local g_OnlineColor = {
50 [true] = { ["r"] = 1, ["g"] = 0.86, ["b"] = 0 },
51 [false] = { ["r"] = 0.5, ["g"] = 0.5, ["b"] = 0.5 },
52 };
53  
54 local SinceColor = { ["r"] = 0.3, ["g"] = 0.6, ["b"] = 1.0 };
55  
56 local g_TableToShowCache = {};
57  
58 GuildAds_ItemFilterOrder = {
59 "everything",
60 "everythingelse",
61 "gather",
62 "monster",
63 "classReagent",
64 "tradeReagent",
65 "vendor",
66 "trade"
67 };
68  
69 g_DateFilter = {
70 1,
71 60,
72 24*60,
73 24*60*2,
74 24*60*7,
75 24*60*14,
76 24*60*30
77 };
78  
79 local g_sortBySubType = false;
80  
81 -- date of the last time the GuildAds window was opened (for HideAdsOlderThan filter)
82 local g_lastInteraction = nil;
83  
84 ---------------------------------------------------------------------------------
85 --
86 -- DEBUG_MSG
87 --
88 ---------------------------------------------------------------------------------
89 local function DEBUG_MSG(msg)
90 if (GUILDADSFRAME_DEBUG) then
91 ChatFrame1:AddMessage(msg, 1.0, 1.0, 0.5);
92 end
93 end
94  
95 ---------------------------------------------------------------------------------
96 --
97 -- Listeners
98 --
99 ---------------------------------------------------------------------------------
100 function GuildAds_OnOnline(owner, status)
101 -- update UI
102 GuildAds_UpdateGlobalAdButtons(g_adtype);
103 GuildAds_UpdateMemberCount();
104  
105 -- show connected status except for my guild
106 local gowner = GuildAds_GetPlayerGuild(owner);
107 local gprofile = GuildAds_GetPlayerGuild(g_playerName);
108 if (owner ~= g_playerName and (gowner ~= gprofile or gowner == nil)) then
109 local msg;
110 if (status) then
111 if GuildAds_HasJoined(owner) then
112 msg = string.format(ERR_FRIEND_ONLINE_SS, owner, owner);
113 GuildAds_ResetHasJoined(owner);
114 end
115 else
116 msg = string.format(ERR_FRIEND_OFFLINE_S, owner);
117 end
118 if (msg) then
119 GAC_AddChatMessage(msg);
120 end
121 end
122 end
123  
124 function GuildAds_OnUpdateInventory(owner, slot)
125 local inventory = GAS_ProfileGetInventory(owner);
126 local item = inventory[slot];
127 GuildAdsInspectItemSlotButton_Update(owner, slot, item.ref, item.texture, item.count);
128 GuildAdsInspect_SetTime(owner, GAS_timeToString(inventory.creationtime));
129 end
130  
131 function GuildAds_OnAddGlobalAd(owner, adtype, ad)
132 -- update UI
133 GuildAds_UpdateGlobalAdButtons(adtype, true);
134 if adtype==GUILDADS_MSG_TYPE_ANNONCE then
135 GuildAds_UpdateMemberCount();
136 end
137  
138 -- Affichage dans la fenêtre de chat
139 if (owner ~= g_playerName) then
140 local tochat = nil;
141 if adtype==GUILDADS_MSG_TYPE_REQUEST and GuildAdsConfig_GetProfileValue("ShowNewAsk") then
142 tochat = GUILDADS_HEADER_REQUEST..": "..GuildAds_AdGetText(adtype, ad, true);
143 end
144 if adtype == GUILDADS_MSG_TYPE_AVAILABLE and GuildAdsConfig_GetProfileValue("ShowNewHave") then
145 tochat = GUILDADS_HEADER_AVAILABLE..": "..GuildAds_AdGetText(adtype, ad, true);
146 end
147 if (tochat ~= nil) then
148 GAC_AddChatMessage("["..owner.."]\32"..tochat);
149 end
150 end
151 end
152  
153 function GuildAds_OnDeleteGlobalAd(owner, adtype, id)
154 -- update UI
155 GuildAds_UpdateGlobalAdButtons(adtype, true);
156 if adtype==GUILDADS_MSG_TYPE_ANNONCE then
157 GuildAds_UpdateMemberCount();
158 end
159 end
160  
161 function GuildAds_OnAddMyAd(adtype, ad)
162 -- update UI
163 if (GuildAdsFrame:IsVisible()) then
164 GuildAds_UpdateMyFrame();
165 end
166 end
167  
168 function GuildAds_OnDeleteMyAd(adtype, id)
169 -- update UI
170 if (GuildAdsFrame:IsVisible()) then
171 GuildAds_UpdateMyFrame();
172 end
173 end
174  
175 --------------------------------------------------------------------------------
176 --
177 -- OnLoad
178 --
179 --------------------------------------------------------------------------------
180 function GuildAdsFrame_OnLoad()
181 -- Get player name
182 g_playerName = UnitName("player");
183 g_realmName = GetCVar("realmName");
184  
185 -- Init g_TableToShowCache
186 g_TableToShowCache = {};
187  
188 -- Initial selection values
189 g_GlobalAdSelected = 0;
190 g_GlobalTitleSelected = 0;
191 g_MyAdSelected = 0;
192  
193 -- UI stuff
194 GuildAdsRemoveButton:Disable();
195 PanelTemplates_SetNumTabs(GuildAdsFrame, 5);
196 PanelTemplates_SetTab(GuildAdsFrame, 1);
197 GuildAdsVersion:SetText(GuildAds_GetVersionAsString());
198  
199 tinsert(UISpecialFrames,"GuildAdsFrame");
200  
201 if ButtonHole then
202 GuildAdsMinimapButton:Show();
203 ButtonHole.application.RegisterMod({
204 id="GUILDADS",
205 name=GUILDADS_TITLE,
206 tooltip=GUILDADS_TITLE,
207 buttonFrame="GuildAdsMinimapButton",
208 updateFunction="GuildAdsMinimapButton_Update"
209 }
210 );
211 end
212 end
213  
214 --------------------------------------------------------------------------------
215 --
216 -- Init
217 --
218 --------------------------------------------------------------------------------
219 function GuildAdsFrame_Init()
220 -- Set listener
221 GAS_AddListener(GAS_EVENT_ONLINE, "GuildAds", GuildAds_OnOnline);
222 GAS_AddListener(GAS_EVENT_UPDATEINVENTORY, "GuildAds", GuildAds_OnUpdateInventory);
223 GAS_AddListener(GAS_EVENT_ADDGLOBAL, "GuildAds", GuildAds_OnAddGlobalAd);
224 GAS_AddListener(GAS_EVENT_REMOVEGLOBAL, "GuildAds", GuildAds_OnDeleteGlobalAd);
225 GAS_AddListener(GAS_EVENT_ADDMY, "GuildAds", GuildAds_OnAddMyAd);
226 GAS_AddListener(GAS_EVENT_REMOVEMY, "GuildAds", GuildAds_OnDeleteMyAd);
227  
228 -- Enable access to GuildAds
229 if not ButtonHole then
230 GuildAdsMinimapButton_Update();
231 GuildAdsMinimapButton:Show();
232 end
233  
234 -- Init date filter
235 local range = table.getn(g_DateFilter)+1;
236 GuildAds_DateFilter:SetMinMaxValues(1,range);
237 GuildAds_DateFilter:SetValueStep(1);
238 local dateFilter = GuildAdsConfig_GetProfileValue("HideAdsOlderThan", nil);
239 if dateFilter then
240 for value, time in g_DateFilter do
241 if dateFilter==time then
242 GuildAds_DateFilter:SetValue(value);
243 end
244 end
245 else
246 GuildAds_DateFilter:SetValue(range);
247 end
248  
249 -- Init g_sortBySubType
250 g_sortBySubType = GuildAdsConfig_GetProfileValue("sortBySubType", true);
251  
252 -- Init g_AdFilters
253 for id, name in GUILDADS_SKILLS do
254 tinsert(g_AdFilters[GUILDADS_MSG_TYPE_SKILL], { id=id, name=name});
255 end
256  
257 local playerFaction = GUILDADS_RACES_TO_FACTION[GAS_GetRaceId(UnitRace("player"))];
258 for id, name in GUILDADS_CLASSES do
259 if (GUILDADS_CLASS_TO_FACTION[id]==nil or GUILDADS_CLASS_TO_FACTION[id]==playerFaction) then
260 tinsert(g_AdFilters[GUILDADS_MSG_TYPE_ANNONCE], { id=id, name=name});
261 end
262 end
263  
264 local FilterNames = {};
265 if (ReagentData) then
266 FilterNames = GUILDADS_ITEMS;
267 else
268 FilterNames = GUILDADS_ITEMS_SIMPLE;
269 end
270 for i, key in GuildAds_ItemFilterOrder do
271 if (FilterNames[key]) then
272 tinsert(g_AdFilters[GUILDADS_MSG_TYPE_REQUEST], {id = key, name=FilterNames[key] });
273 tinsert(g_AdFilters[GUILDADS_MSG_TYPE_AVAILABLE], {id = key, name=FilterNames[key] });
274 end
275 end
276 end
277  
278 ----------------------------------------------------------------------------------
279 --
280 -- Called when the main window is shown
281 --
282 ---------------------------------------------------------------------------------
283 function GuildAds_OnShow()
284 DEBUG_MSG("GuildAds_OnShow");
285 -- reset UI cache because of the HideAdsOlderThan filter ?
286 local currentTime = GAS_currentTime();
287 local dateFilter = GuildAdsConfig_GetProfileValue("HideAdsOlderThan", nil);
288 if dateFilter and g_lastInteraction then
289 if currentTime-g_lastInteraction>dateFilter then
290 GuildAdsFrame_ResetCache();
291 end
292 end;
293 g_lastInteraction = currentTime;
294  
295 -- update
296 GuildAds_UpdateGlobalAdButtons(g_adtype);
297 GuildAds_UpdateMyFrame();
298 end
299  
300 ---------------------------------------------------------------------------------
301 --
302 -- Choose a tab (Available, Request, Event, ...)
303 --
304 ---------------------------------------------------------------------------------
305 function GuildAds_SelectTab(adType)
306 DEBUG_MSG("GuildAds_SelectTab("..adType..")");
307  
308 if (g_adtype == GUILDADS_MSG_TYPE_REQUEST) then
309 GuildAdsAddButtonLookFor:Hide();
310 elseif (g_adtype == GUILDADS_MSG_TYPE_AVAILABLE) then
311 GuildAdsAddButtonAvailable:Hide();
312 elseif (g_adtype == GUILDADS_MSG_TYPE_EVENT) then
313 GuildAdsAddButtonEvent:Hide();
314 end
315 -------
316 local toId = {
317 [GUILDADS_MSG_TYPE_REQUEST] = 1,
318 [GUILDADS_MSG_TYPE_AVAILABLE] = 2,
319 [GUILDADS_MSG_TYPE_SKILL] = 3,
320 [GUILDADS_MSG_TYPE_EVENT] = 4,
321 [GUILDADS_MSG_TYPE_ANNONCE] = 5
322  
323 };
324 PanelTemplates_SetTab(GuildAdsFrame, toId[adType]);
325 g_adtype = adType;
326 g_GlobalAdSelected = 0;
327 g_GlobalTitleSelected = 0;
328 GuildAds_UpdateGlobalAdButtons(adType);
329 -- GuildAds_UpdateMyFrame updated by GuildAds_MyAdsEdit
330 GuildAds_MyAdsEdit(nil);
331  
332 --------
333 if (g_adtype == GUILDADS_MSG_TYPE_REQUEST) then
334 GuildAds_DateFilter:Show();
335 GuildAdsGroupByAccountCheckButton:Hide();
336 GuildAdsGuildShowOfflinesCheckButton:Hide();
337 GuildAdsAddButtonLookFor:Show();
338 GuildAdsRemoveButton:Show();
339 GuildAdsEditBox:Show();
340 GuildAdsEditBox:SetWidth(465);
341 GuildAdsEditItem:Show();
342 GuildAds_Event_ZoneDropDown:Hide();
343 GuildAds_MyTab1:Show();
344 GuildAds_MyTab2:Show();
345 elseif (g_adtype == GUILDADS_MSG_TYPE_AVAILABLE) then
346 GuildAds_DateFilter:Show();
347 GuildAdsGroupByAccountCheckButton:Hide();
348 GuildAdsGuildShowOfflinesCheckButton:Hide();
349 GuildAdsAddButtonAvailable:Show();
350 GuildAdsRemoveButton:Show();
351 GuildAdsEditBox:Show();
352 GuildAdsEditBox:SetWidth(465);
353 GuildAdsEditItem:Show();
354 GuildAds_Event_ZoneDropDown:Hide();
355 GuildAds_MyTab1:Show();
356 GuildAds_MyTab2:Show();
357 elseif (g_adtype == GUILDADS_MSG_TYPE_SKILL) then
358 GuildAds_DateFilter:Hide();
359 GuildAdsGroupByAccountCheckButton:Hide();
360 GuildAdsGuildShowOfflinesCheckButton:Hide();
361 GuildAdsRemoveButton:Hide();
362 GuildAdsEditBox:Hide();
363 GuildAdsEditItem:Hide();
364 GuildAds_Event_ZoneDropDown:Hide();
365 GuildAds_MySelectTab(GUILDADS_MY_FILTER);
366 GuildAds_MyTab1:Hide();
367 GuildAds_MyTab2:Show();
368 elseif (g_adtype == GUILDADS_MSG_TYPE_EVENT) then
369 GuildAds_DateFilter:Show();
370 GuildAdsGroupByAccountCheckButton:Hide();
371 GuildAdsGuildShowOfflinesCheckButton:Hide();
372 GuildAdsAddButtonEvent:Show();
373 GuildAdsRemoveButton:Show();
374 GuildAdsEditBox:Show();
375 GuildAdsEditItem:Hide();
376 GuildAds_Event_ZoneDropDown:Show();
377 GuildAdsEditBox:SetWidth(330);
378 GuildAds_MySelectTab(GUILDADS_MY_ADS);
379 GuildAds_MyTab1:Show();
380 GuildAds_MyTab2:Hide();
381 elseif (g_adtype == GUILDADS_MSG_TYPE_ANNONCE) then
382 GuildAds_DateFilter:Hide();
383 if (GuildAds.Config.GroupByAccount) then
384 GuildAdsGroupByAccountCheckButton:SetChecked(1);
385 else
386 GuildAdsGroupByAccountCheckButton:SetChecked(0);
387 end
388 if (GuildAdsConfig_GetProfileValue("GuildShowOfflines")) then
389 GuildAdsGuildShowOfflinesCheckButton:SetChecked(1);
390 else
391 GuildAdsGuildShowOfflinesCheckButton:SetChecked(0);
392 end
393 GuildAdsGroupByAccountCheckButton:Show();
394 GuildAdsGuildShowOfflinesCheckButton:Show();
395 GuildAdsRemoveButton:Hide();
396 GuildAdsEditBox:Hide();
397 GuildAdsEditItem:Hide();
398 GuildAds_Event_ZoneDropDown:Hide();
399 GuildAds_MySelectTab(GUILDADS_MY_FILTER);
400 GuildAds_MyTab1:Hide();
401 GuildAds_MyTab2:Show();
402 end
403  
404 DEBUG_MSG("GuildAds_SelectTab("..adType..") End");
405 end
406  
407  
408 function GuildAdsFrame_OnChannelChange()
409 GuildAdsFrame_ResetCache();
410 GuildAds_UpdateGlobalAdButtons(g_adtype);
411 GuildAds_MyAdsEdit(nil);
412 end
413  
414 ---------------------------------------------------------------------------------
415 --
416 -- Predicate functions which can be used to compare two ads for sorting
417 -- return true if the first argument should come first in the sorted array
418 --
419 ---------------------------------------------------------------------------------
420 function GuildAds_SkillPredicate(a, b)
421 --
422 -- nil references are always less than
423 --
424 if (a == nil) then
425 if (b == nil) then
426 -- a==nil, b==nil
427 return false;
428 else
429 -- a==nil, b~=nil
430 return true;
431 end
432 elseif (b == nil) then
433 -- a~=nil, b==nil
434 return false;
435 end
436  
437 -- for skills
438 if (a.skillRank and b.skillRank) then
439 --
440 -- Sort by skill name (ie id)
441 --
442 if (a.id < b.id) then
443 return true;
444 elseif (a.id > b.id) then
445 return false;
446 end
447  
448 --
449 -- Sort by skill rank
450 --
451 if (a.skillRank < b.skillRank) then
452 return false;
453 elseif (a.skillRank > b.skillRank) then
454 return true;
455 end
456 end
457  
458 --
459 -- Sort by owner next
460 --
461 aowner = a.owner;
462 bowner = b.owner;
463 if (aowner == nil) then
464 aowner = "";
465 end
466 if (bowner == nil) then
467 bowner = "";
468 end
469  
470 if (aowner < bowner) then
471 return true;
472 elseif (aowner > bowner) then
473 return false;
474 end
475  
476 -- These ads are identical
477 return false;
478 end
479  
480 function GuildAds_AdPredicate(a, b)
481 --
482 -- nil references are always less than
483 --
484 if (a == nil) then
485 if (b == nil) then
486 -- a==nil, b==nil
487 return false;
488 else
489 -- a==nil, b~=nil
490 return true;
491 end
492 elseif (b == nil) then
493 -- a~=nil, b==nil
494 return false;
495 end
496  
497 --
498 -- Sort by item type (g_itemInfo)
499 --
500 if a.itemRef then
501 if b.itemRef then
502 local info, atype, btype;
503 info = GAS_GetItemInfo(a.itemRef);
504 atype = info.type;
505 if g_sortBySubType then
506 if info.type and info.subtype and info.type~=info.subtype then
507 atype = atype.." - "..info.subtype;
508 end
509 if info.rarity then
510 local tmp = 5-info.rarity;
511 atype = atype.." ("..tmp..") "; -- 10-[0..5] just in case
512 end
513 end
514  
515 info = GAS_GetItemInfo(b.itemRef);
516 btype = info.type;
517 if g_sortBySubType then
518 if info.type and info.subtype and info.type~=info.subtype then
519 btype = btype.." - "..info.subtype;
520 end
521 if info.rarity then
522 local tmp = 5-info.rarity;
523 btype = btype.." ("..tmp..") "; -- 10-[0..5] just in case
524 end
525 end
526  
527 if atype and btype then
528 if (atype < btype) then
529 return true;
530 elseif (atype > btype) then
531 return false;
532 end
533 else
534 if atype and not btype then
535 return true;
536 elseif not atype and btype then
537 return false;
538 end
539 end
540 else
541 -- a.itemRef~=nil, b.itemRef==nil
542 return true;
543 end
544 else
545 if b.itemRef then
546 return false;
547 end
548 end
549 -- (a.itemRef==nil AND b.itemRef==nil) OR atype==btype
550  
551 --
552 -- Sort by itemName
553 --
554 if a.itemName then
555 if b.itemName then
556 if (a.itemName < b.itemName) then
557 return true;
558 elseif (a.itemName > b.itemName) then
559 return false;
560 end
561 else
562 return true;
563 end
564 else
565 if b.itemName then
566 return false
567 end
568 end
569 -- (a.itemName==nil AND b.itemName==nil) OR a.itemName==b.itemName
570  
571 --
572 -- Sort by text
573 --
574 if (a.text and b.text) then
575 if (a.text < b.text) then
576 return true;
577 elseif (b.text < a.text) then
578 return false;
579 end
580 end
581  
582 --
583 -- Sort by owner next
584 --
585 aowner = a.owner;
586 bowner = b.owner;
587 if (aowner == nil) then
588 aowner = "";
589 end
590 if (bowner == nil) then
591 bowner = "";
592 end
593  
594 if (aowner < bowner) then
595 return true;
596 elseif (aowner > bowner) then
597 return false;
598 end
599  
600 --
601 -- Sort by Id
602 --
603 if (tostring(a.id) < tostring(b.id)) then
604 return true;
605 elseif (tostring(a.id) > tostring(b.id)) then
606 return false;
607 end
608  
609 -- These ads are identical
610 return false;
611 end
612  
613 function GuildAds_EventPredicate(a, b)
614 -- nil references are always less than
615 if (a == nil) then
616 if (b == nil) then
617 return false;
618 else
619 return true;
620 end
621 elseif (b == nil) then
622 return false;
623 end
624  
625 --
626 -- Sort by text
627 --
628 if (a.text and b.text) then
629 if (a.text < b.text) then
630 return true;
631 elseif (b.text < a.text) then
632 return false;
633 end
634 end
635  
636 -- Get profiles
637 pa = GAS_ProfileGet(a.owner);
638 pb = GAS_ProfileGet(b.owner);
639  
640 --
641 -- Sort by class
642 --
643 if pa.class and pb.class then
644 if (pa.class < pb.class) then
645 return true;
646 elseif (pa.class > pb.class) then
647 return false;
648 end
649 end
650  
651 --
652 -- sort by level (low level first)
653 --
654 if pa.level and pb.level then
655 if (pa.level > pb.level) then
656 return false;
657 elseif (pa.level < pb.level) then
658 return true;
659 end
660 end
661  
662 --
663 -- Sort by name
664 --
665 if (a.owner > b.owner) then
666 return true;
667 elseif (a.owner < b.owner) then
668 return false;
669 end
670 end
671  
672 local cacheHigherLevel = {};
673 local function getHigherlevel(accountid)
674 if accountid==nil then
675 return nil;
676 else
677 if cacheHigherLevel[accountid] then
678 return cacheHigherLevel[accountid];
679 else
680 local players = GAS_PlayersByAccount(accountid);
681 local bestUser = "";
682 local bestUserLevel = 0;
683 for _, user in players do
684 local profile = GAS_ProfileGet(user);
685 if profile.level > bestUserLevel then
686 bestUser = user;
687 bestUserLevel = profile.level;
688 end
689 end
690 cacheHigherLevel[accountid] = bestUser;
691 return bestUser;
692 end;
693 end;
694 end;
695  
696 function GuildAds_CharPredicate(a, b)
697 -- nil references are always less than
698 if (a == nil) then
699 if (b == nil) then
700 return false;
701 else
702 return true;
703 end
704 elseif (b == nil) then
705 return false;
706 end
707  
708 -- Get profiles
709 pa = GAS_ProfileGet(a.owner);
710 pb = GAS_ProfileGet(b.owner);
711  
712 --
713 -- GuildAds.Config.GroupByAccount
714 --
715  
716 if (GuildAds.Config.GroupByAccount) then
717 -- sort by accountId
718 ha = getHigherlevel(pa.accountid) or "zzzzzz";
719 hb = getHigherlevel(pb.accountid) or "zzzzzz";
720 if (ha > hb) then
721 return false;
722 elseif (ha < hb) then
723 return true;
724 end
725 end
726  
727 --
728 -- sort by level (high level first)
729 --
730 if pa.level and pb.level then
731 if (pa.level < pb.level) then
732 return false;
733 elseif (pa.level > pb.level) then
734 return true;
735 end
736 end
737  
738 --
739 -- Sort by class
740 --
741 if pa.class and pb.class then
742 if (pa.class < pb.class) then
743 return true;
744 elseif (pa.class > pb.class) then
745 return false;
746 end
747 end
748  
749 --
750 -- Sort by name
751 --
752 if (a.owner < b.owner) then
753 return true;
754 elseif (a.owner > b.owner) then
755 return false;
756 end
757  
758 return false;
759 end
760  
761 ---------------------------------------------------------------------------------
762 --
763 -- Sort ads table
764 --
765 ---------------------------------------------------------------------------------
766 function GuildAds_AdsSort(adtype, ads)
767 DEBUG_MSG("GuildAds_AdsSort");
768 local size = table.getn(ads);
769 if (size) then
770 local predicate = nil;
771 if (adtype == GUILDADS_MSG_TYPE_ANNONCE) then
772 cacheHigherLevel = {};
773 predicate = GuildAds_CharPredicate;
774 elseif (adtype == GUILDADS_MSG_TYPE_EVENT) then
775 predicate = GuildAds_EventPredicate;
776 elseif (adtype == GUILDADS_MSG_TYPE_SKILL) then
777 predicate = GuildAds_SkillPredicate;
778 else
779 predicate = GuildAds_AdPredicate;
780 end
781 table.sort(ads, predicate);
782 end
783 end
784  
785 ---------------------------------------------------------------------------------
786 --
787 -- Output data to text
788 --
789 ---------------------------------------------------------------------------------
790  
791 function GuildAds_TitleText(adType, groupValue)
792 if (adType == GUILDADS_MSG_TYPE_SKILL) then
793 return ""; -- nothing, just blank
794 elseif (adType == GUILDADS_MSG_TYPE_ANNONCE) then
795 if (groupValue == nil) then
796 return "";
797 elseif (groupValue == "") then
798 return GUILDADS_ACCOUNT_NA;
799 else
800 return getHigherlevel(groupValue);
801 end
802 elseif (adType == GUILDADS_MSG_TYPE_EVENT) then
803 return groupValue.." ("..GuildAds_GetGroupCount(adType, groupValue)..")";
804 else
805 return groupValue;
806 end
807 end
808  
809 function GuildAds_AdGetText(adType, ad, tochat)
810 if (adType == GUILDADS_MSG_TYPE_SKILL) then
811 return ""; -- done with another widget
812 elseif (adType == GUILDADS_MSG_TYPE_ANNONCE) then
813 return GuildAds_GetPlayerInfo(ad.owner);
814  
815 elseif (adType == GUILDADS_MSG_TYPE_EVENT) then
816 if (ad.owner == nil) then
817 return ad.text;
818 else
819 return GuildAds_GetPlayerInfo(ad.owner);
820 end
821  
822 elseif (adType == GUILDADS_MSG_TYPE_AVAILABLE) or (adType == GUILDADS_MSG_TYPE_REQUEST) then
823 local text = "";
824 if (ad.itemName) then
825 if (tochat) then
826 text = GAS_PackLink(ad.itemColor, ad.itemRef, ad.itemName);
827 else
828 text = "|c"..ad.itemColor.."["..ad.itemName.."]|r";
829 end
830 if (ad.count) then
831 text = text.." x "..ad.count;
832 end
833 end
834 if (ad.text) and (ad.text ~= "") then
835 if (text ~= "") then
836 text = text..", "
837 end
838 text = text..ad.text;
839 end
840 return text
841 else
842 return ad.text;
843 end
844 end
845  
846 function GuildAds_GetPlayerInfo(playerName)
847 local profile = GAS_ProfileGet(playerName);
848 if (profile.level) then
849 return LEVEL.." "..profile.level..", "..(GAS_GetRaceText(profile.race) or "")..", "..(GAS_GetClassText(profile.class) or "");
850 else
851 return "";
852 end
853 end
854  
855 function GuildAds_GetPlayerGuild(playerName)
856 local profile = GAS_ProfileGet(playerName);
857 if (profile ~= nil) then
858 return profile.guild;
859 else
860 return nil;
861 end
862 end
863  
864 ---------------------------------------------------------------------------------
865 --
866 -- Filter global ad
867 --
868 ---------------------------------------------------------------------------------
869 GuildAds_ItemFilterFunction = {
870 everything = function(ad)
871 return true;
872 end;
873  
874 everythingelse = function(ad)
875 if ad.itemName then
876 return not (
877 GuildAds_ItemFilterFunction.monster(ad)
878 or GuildAds_ItemFilterFunction.classReagent(ad)
879 or GuildAds_ItemFilterFunction.tradeReagent(ad)
880 or GuildAds_ItemFilterFunction.vendor(ad)
881 or GuildAds_ItemFilterFunction.gather(ad)
882 );
883 else
884 return true;
885 end
886 end;
887  
888 monster = function(ad)
889 if ad.itemName then
890 return ReagentData_IsMonsterDrop(ad.itemName);
891 else
892 return false;
893 end
894 end;
895  
896 classReagent = function (ad)
897 if ad.itemName then
898 return table.getn(ReagentData_ClassSpellReagent(ad.itemName))>0;
899 else
900 return false;
901 end
902 end;
903  
904 tradeReagent = function(ad)
905 if ad.itemName then
906 return table.getn(ReagentData_GetProfessions(ad.itemName))>0;
907 else
908 return false;
909 end
910 end;
911  
912 vendor = function(ad)
913 if ad.itemName then
914 return ReagentData_IsVendorItem(ad.itemName);
915 else
916 return false;
917 end
918 end;
919  
920 gather = function(ad)
921 if ad.itemName then
922 return table.getn(ReagentData_GatheredBy(ad.itemName)) > 0;
923 else
924 return false;
925 end
926 end;
927 };
928  
929 local function GuildAds_AdIsVisible(adType, ad)
930 if (not (GuildAds.Config.ShowOfflinePlayer or GAS_IsOnline(ad.owner))) then
931 return false;
932 end
933 if (not GuildAds.Config.ShowMyAds) and (g_playerName == ad.owner) then
934 return false;
935 end
936 if (adType == GUILDADS_MSG_TYPE_SKILL) then
937 if (GuildAds.Config.Filters[GUILDADS_MSG_TYPE_SKILL][ad.id]) then
938  
939 return true;
940 else
941 return false;
942 end
943 elseif (adType == GUILDADS_MSG_TYPE_REQUEST) or (adType == GUILDADS_MSG_TYPE_AVAILABLE) then
944 local dateFilter = GuildAdsConfig_GetProfileValue("HideAdsOlderThan", nil);
945 if dateFilter and ad.creationtime then
946 local currentDelta = GAS_currentTime()-ad.creationtime;
947 -- Hack to avoid wrong display. Obviously there is a bug in offline/online sync about time.
948 if currentDelta<0 then
949 return false;
950 end
951 if currentDelta>dateFilter then
952 return false;
953 end
954 end
955 for id, name in GuildAds.Config.Filters[adType] do
956 filterFunction = GuildAds_ItemFilterFunction[id];
957 if filterFunction and filterFunction(ad) then
958 return true;
959 end
960 end
961 return false;
962 elseif adType == GUILDADS_MSG_TYPE_ANNONCE then
963 if not GuildAdsConfig_GetProfileValue("GuildShowOfflines") and not GAS_IsOnline(ad.owner) then
964 return false;
965 end
966 local profile = GAS_ProfileGet(ad.owner);
967 for id, name in GuildAds.Config.Filters[adType] do
968 if id == profile.class then
969 return true;
970 end
971 end
972 return false;
973 elseif adType == GUILDADS_MSG_TYPE_EVENT then
974 local dateFilter = GuildAdsConfig_GetProfileValue("HideAdsOlderThan", nil);
975 if dateFilter and ad.creationtime then
976 local currentDelta = GAS_currentTime()-ad.creationtime;
977 -- Hack to avoid wrong display. Obviously there is a bug in offline/online sync about time.
978 if currentDelta<0 then
979 return false;
980 end
981 if currentDelta>dateFilter then
982 return false;
983 end
984 end
985 -- temporary hack to avoid a bug
986 if ad.text == nil then
987 return false;
988 end
989 end
990 return true;
991 end
992  
993 ---------------------------------------------------------------------------------
994 --
995 -- GuildAds_GetTableToShow : Return a list of item to Show
996 -- t[i].title for a title
997 -- t[i].iAd for a reference to an ad
998 -- g_TableToShowCache[g_adtype] must be set to nil, when ad are changed
999 -- (done by listeners)
1000 --
1001 ---------------------------------------------------------------------------------
1002 local function GetEventGroup(ad)
1003 if (ad) then
1004 return ad.text;
1005 else
1006 return nil
1007 end
1008 end
1009  
1010 local function GetSkillGroup(ad)
1011 if (ad) then
1012 return ad.id;
1013 else
1014 return nil;
1015 end
1016 end
1017  
1018 local function GetCharGroup(ad)
1019 if (ad) and (GuildAds.Config.GroupByAccount) then
1020 local profile = GAS_ProfileGet(ad.owner);
1021 if (profile.accountid == nil) then
1022 return "";
1023 else
1024 return profile.accountid;
1025 end
1026 else
1027 return nil;
1028 end
1029 end
1030  
1031 local function GetItemGroup(ad)
1032 if (ad) and (ad.itemRef) then
1033 local info = GAS_GetItemInfo(ad.itemRef);
1034 if info.type then
1035 if g_sortBySubType and info.subtype and info.subtype~=info.type then
1036 return info.type.." - "..info.subtype;
1037 else
1038 return info.type;
1039 end
1040 else
1041 return UNKNOWNOBJECT;
1042 end
1043 else
1044 return LABEL_NOTE;
1045 end
1046 end
1047  
1048 local GuildAdsGroupBy =
1049 {
1050 [GUILDADS_MSG_TYPE_REQUEST] = GetItemGroup;
1051 [GUILDADS_MSG_TYPE_AVAILABLE] = GetItemGroup;
1052 [GUILDADS_MSG_TYPE_SKILL] = GetSkillGroup;
1053 [GUILDADS_MSG_TYPE_EVENT] = GetEventGroup;
1054 [GUILDADS_MSG_TYPE_ANNONCE] = GetCharGroup;
1055 };
1056  
1057 function GuildAdsFrame_ResetCache()
1058 g_TableToShowCache = {};
1059 GuildAds_UpdateMemberCount();
1060 end
1061  
1062 function GuildAds_GetTableToShow(adType, updateData)
1063 local adTable = GAS_GetAds(adType);
1064  
1065 if (not g_TableToShowCache[adType] or updateData) then
1066 local getGroup = GuildAdsGroupBy[adType];
1067 GuildAds_AdsSort(adType, adTable);
1068  
1069 local linear = {};
1070 local groupCount = {};
1071 local adCount = 0;
1072  
1073 local adGroup, groupTitle, currentGroup;
1074 for adId, ad in adTable do
1075 if GuildAds_AdIsVisible(adType, ad) then
1076 if (getGroup) then
1077 adGroup = getGroup(ad);
1078 groupTitle = GuildAds_TitleText(adType, adGroup);
1079  
1080 if (currentGroup~=adGroup) then
1081 tinsert(linear, { groupId = adGroup } );
1082 currentGroup = adGroup;
1083 end
1084 if (not g_HideGroup[adType][adGroup]) then
1085 tinsert(linear, { adId = adId } );
1086 end
1087  
1088 adCount = adCount + 1;
1089 if (adGroup) then
1090 groupCount[adGroup] = (groupCount[adGroup] or 0) + 1;
1091 end
1092 else
1093 tinsert(linear, { adId = adId } );
1094 adCount = adCount + 1;
1095 end
1096 end
1097 end
1098 g_TableToShowCache[adType] = {table=linear, adCount=adCount, groupCount=groupCount};
1099 end
1100 return g_TableToShowCache[adType].table, adTable, g_TableToShowCache[adType].groupCount, g_TableToShowCache[adType].adCount;
1101 end
1102  
1103 function GuildAds_GetGroupCount(adType, groupId)
1104 if g_TableToShowCache[adType]
1105 and g_TableToShowCache[adType].groupCount
1106 and g_TableToShowCache[adType].groupCount[groupId] then
1107 return g_TableToShowCache[adType].groupCount[groupId];
1108 else
1109 return 0;
1110 end
1111 end
1112  
1113 ---------------------------------------------------------------------------------
1114 --
1115 -- Update the buttons for a given table
1116 --
1117 ---------------------------------------------------------------------------------
1118 function GuildAds_UpdateAdButtonForAd(button, selected, adType, ad)
1119 -- paranoia
1120 if (not button) then
1121 DEBUG_MSG("GuildAds_UpdateAdButtonForAd: button is nil");
1122 error("GuildAds_UpdateAdButtonForAd: button is nil", 2);
1123 return;
1124 end
1125  
1126 local buttonName= button:GetName();
1127  
1128 local ownerColor = g_OnlineColor[GAS_IsOnline(ad.owner)];
1129  
1130 local titleField = buttonName.."Title";
1131 local ownerField = buttonName.."Owner";
1132 local textField = buttonName.."Text";
1133 local classField = buttonName.."Class";
1134 local raceField = buttonName.."Race";
1135 local skillBar = buttonName.."SkillBar";
1136 local skillName = skillBar.."SkillName";
1137 local skillRank = skillBar.."SkillRank";
1138  
1139 button:SetNormalTexture("");
1140  
1141 -- color, text, owner
1142 getglobal(titleField):Hide();
1143  
1144 getglobal(ownerField):SetText(ad.owner);
1145 getglobal(ownerField):SetTextColor(ownerColor["r"], ownerColor["g"], ownerColor["b"]);
1146  
1147 -- ask/have ads
1148 if adType==GUILDADS_MSG_TYPE_REQUEST or adType==GUILDADS_MSG_TYPE_AVAILABLE then
1149 getglobal(textField):Show();
1150 getglobal(textField):SetText(GuildAds_AdGetText(adType, ad));
1151 getglobal(textField):SetTextColor(g_AdColor[adType]["r"], g_AdColor[adType]["g"], g_AdColor[adType]["b"]);
1152 else
1153 getglobal(textField):Hide();
1154 end
1155  
1156 -- skill
1157 if (adType == GUILDADS_MSG_TYPE_SKILL) then
1158 getglobal(skillBar):Show();
1159 getglobal(skillName):SetText(GAS_GetSkillText(ad.id));
1160 if (ad.skillRank) then
1161 getglobal(skillBar):SetValue(ad.skillRank);
1162 getglobal(skillRank):SetText(ad.skillRank.."/"..ad.skillMaxRank);
1163 else
1164 getglobal(skillBar):SetValue(1);
1165 getglobal(skillRank):SetText("");
1166 end
1167 else
1168 getglobal(skillBar):Hide();
1169 end
1170  
1171 -- annonce and event
1172 local profile
1173 if (adType==GUILDADS_MSG_TYPE_ANNONCE or adType==GUILDADS_MSG_TYPE_EVENT) then
1174 profile = GAS_ProfileGet(ad.owner);
1175 if (profile.level) then
1176 getglobal(textField):SetTextColor(1.0, 1.0, 1.0);
1177 getglobal(textField):Show();
1178 getglobal(textField):SetText(LEVEL.." "..profile.level);
1179 getglobal(classField):Show();
1180 getglobal(classField):SetText(GAS_GetClassText(profile.class));
1181 getglobal(raceField):Show();
1182 getglobal(raceField):SetText(GAS_GetRaceText(profile.race));
1183 end
1184 end
1185 if not (profile and profile.level) then
1186 getglobal(classField):Hide();
1187 getglobal(raceField):Hide();
1188 end
1189  
1190 -- selected
1191 if (selected) then
1192 button:LockHighlight();
1193 else
1194 button:UnlockHighlight();
1195 end
1196 end
1197  
1198 function GuildAds_UpdateAdButtonForTitle(button, selected, adType, groupId)
1199 local buttonName = button:GetName();
1200  
1201 local titleField = buttonName.."Title";
1202 local ownerField = buttonName.."Owner";
1203 local textField = buttonName.."Text";
1204 local classField = buttonName.."Class";
1205 local raceField = buttonName.."Race";
1206 local skillBar = buttonName.."SkillBar";
1207 local skillName = skillBar.."SkillName";
1208 local skillRank = skillBar.."SkillRank";
1209  
1210 local title = GuildAds_TitleText(adType, groupId);
1211 if (title and title ~= "") then
1212 if (g_HideGroup[adType][groupId]) then
1213 button:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up");
1214 else
1215 button:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up");
1216 end
1217 else
1218 button:SetNormalTexture("");
1219 end
1220  
1221 getglobal(textField):SetText("");
1222 getglobal(ownerField):SetText("");
1223 getglobal(classField):Hide();
1224 getglobal(raceField):Hide();
1225 getglobal(skillBar):Hide();
1226  
1227 getglobal(titleField):Show();
1228 getglobal(titleField):SetText(title);
1229  
1230 -- selected
1231 if (selected) then
1232 button:LockHighlight();
1233 else
1234 button:UnlockHighlight();
1235 end
1236 end
1237  
1238 ---------------------------------------------------------------------------------
1239 --
1240 -- Update global ad buttons in the UI
1241 --
1242 ---------------------------------------------------------------------------------
1243 function GuildAds_UpdateGlobalAdButtons(adType, updateData)
1244 if (GuildAdsFrame:IsVisible() and (not adType or adType==g_adtype)) then
1245 DEBUG_MSG("GuildAds_UpdateGlobalAdButtons:"..g_adtype);
1246 local offset = FauxScrollFrame_GetOffset(GuildAdsGlobalAdScrollFrame);
1247  
1248 local linear, adTable = GuildAds_GetTableToShow(g_adtype, updateData);
1249 local linearSize = table.getn(linear);
1250  
1251 -- init
1252 local i = 1;
1253 local j = i + offset;
1254  
1255 -- for each buttons
1256 while (i <= GUILDADS_NUM_GLOBAL_AD_BUTTONS) do
1257 local button = getglobal("GuildAdsGlobalAdButton"..i);
1258  
1259 if (j <= linearSize) then
1260 if (linear[j].groupId) then
1261 -- update internal data
1262 button.groupId = linear[j].groupId;
1263 button.idAd = nil;
1264 -- create a title
1265 GuildAds_UpdateAdButtonForTitle(button, g_GlobalTitleSelected==linear[j].groupId, g_adtype, linear[j].groupId);
1266 elseif (linear[j].adId) then
1267 -- update internal data
1268 button.groupId = nil;
1269 button.idAd = linear[j].adId;
1270 -- create a ads
1271 GuildAds_UpdateAdButtonForAd(button, g_GlobalAdSelected == linear[j].adId, g_adtype, adTable[linear[j].adId]);
1272 end
1273 button:Show();
1274 j = j+1;
1275 else
1276 button:Hide();
1277 end
1278  
1279 i = i+1;
1280 end
1281  
1282 FauxScrollFrame_Update(GuildAdsGlobalAdScrollFrame, linearSize, GUILDADS_NUM_GLOBAL_AD_BUTTONS, GUILDADS_ADBUTTONSIZEY);
1283 else
1284 -- update another tab than the visible one
1285 if updateData then
1286 -- but data needs to be reseted
1287 g_TableToShowCache[adType] = nil;
1288 end
1289 end
1290 end
1291  
1292 ---------------------------------------------------------------------------------
1293 --
1294 -- Update members count
1295 --
1296 ---------------------------------------------------------------------------------
1297 function GuildAds_UpdateMemberCount()
1298 local players = GAS_GetAds(GUILDADS_MSG_TYPE_ANNONCE);
1299 local count = table.getn(players);
1300 local countOnline = 0;
1301 local str;
1302 if count>1 then
1303 str = GUILD_TOTAL_P1;
1304 else
1305 str = GUILD_TOTAL;
1306 end
1307 str = string.format(str,count);
1308  
1309 for id, ad in players do
1310 if GAS_IsOnline(ad.owner) then
1311 countOnline = countOnline+1;
1312 end
1313 end
1314  
1315 str = str .." "..string.format(GUILD_TOTALONLINE, countOnline);
1316  
1317 GuildAdsCountText:SetText(str);
1318 end
1319  
1320 ---------------------------------------------------------------------------------
1321 --
1322 -- Called when a global ad is clicked
1323 --
1324 ---------------------------------------------------------------------------------
1325 function GuildAds_GlobalAdButton_OnClick(button)
1326 if this.idAd then
1327 -- an ad was clicked
1328 local newSelectedId = this.idAd;
1329 if (newSelectedId ~= g_GlobalAdSelected) then
1330 g_GlobalAdSelected = newSelectedId;
1331 g_GlobalTitleSelected = 0;
1332 GuildAds_UpdateGlobalAdButtons(g_adtype);
1333 end
1334 if button=="LeftButton" then
1335 local ad = GAS_GetAds(g_adtype)[this.idAd];
1336 if IsControlKeyDown() then
1337 if ad.itemRef then
1338 DressUpItemLink(ad.itemRef);
1339 end
1340 elseif IsShiftKeyDown() then
1341 if ad.owner == g_playerName then
1342 local myAds = GAS_GetMyAds()[g_adtype];
1343 local size = table.getn(myAds);
1344 for index=1,size do
1345 if myAds[index].id==ad.id then
1346 GuildAds_MyAdsEdit(index);
1347 end
1348 end
1349 else
1350 if ad.itemRef then
1351 GuildAds_MyAdsEdit(nil);
1352 GuildAds_setEditItem(ad.text, GAS_PackLink(ad.itemColor, ad.itemRef, ad.itemName), ad.texture, ad.count);
1353 end
1354 end
1355 end
1356 end
1357 elseif this.groupId then
1358 -- a title was clicked
1359 local updateUI = false;
1360 local updateData;
1361 if (this.groupId ~= g_GlobalTitleSelected) then
1362 g_GlobalAdSelected = 0;
1363 g_GlobalTitleSelected = this.groupId;
1364 updateUI = true;
1365 end
1366 if button == "LeftButton" then
1367 if (g_HideGroup[g_adtype][this.groupId]) then
1368 g_HideGroup[g_adtype][this.groupId] = nil;
1369 else
1370 if GuildAds_TitleText(g_adtype, this.groupId) ~= "" then
1371 g_HideGroup[g_adtype][this.groupId] = true;
1372 end
1373 end
1374 updateUI = true;
1375 updateData = true;
1376 end
1377 if updateUI then
1378 GuildAds_UpdateGlobalAdButtons(g_adtype, updateData);
1379 end
1380 end
1381 if button == "RightButton" then
1382 GuildAdsFromAdsMenu.groupId = this.groupId;
1383 ToggleDropDownMenu(1, nil, GuildAdsFromAdsMenu, "cursor");
1384 end
1385 end
1386  
1387 ---------------------------------------------------------------------------------
1388 --
1389 -- Called when mouse hover a global ad
1390 --
1391 ---------------------------------------------------------------------------------
1392 function GuildAds_GameTooltip_AddText(text, r, g, b)
1393 if text~=nil then
1394 line = "";
1395 text = string.gsub(text, "|(%w+)|H([%w:]+)|h([^|]+)|h|r", "%3");
1396 for word in string.gfind(text,"[^ ]+") do
1397 if (string.len(line) > MAX_LINE_SIZE) then
1398 GameTooltip:AddLine(line, r, g, b);
1399 line = word;
1400 else
1401 line = line.." "..word;
1402 end
1403 end
1404 if (string.len(line) > 0) then
1405 GameTooltip:AddLine(line, r, g, b);
1406 end
1407 end
1408 end
1409  
1410 function GuildAds_GameTooltip_AddTT(color, ref, name, count)
1411 if (EnhTooltip and ref and name) then
1412 local link = GAS_PackLink(color, ref, name);
1413  
1414 -- EnhTooltip.TooltipCall(frame,name,link,quality,count,price,forcePopup,hyperlink)
1415 EnhTooltip.TooltipCall(GameTooltip, name, link, -1, count, 0);
1416 end
1417 end
1418  
1419 function GuildAds_GlobalAdButton_OnEnter(obj)
1420 local id = nil;
1421 if (obj == nil) then
1422 obj = this;
1423 end;
1424 local id = obj.idAd;
1425 if (not id) then
1426 return;
1427 end
1428  
1429 local adTable = GAS_GetAds(g_adtype);
1430 local item = adTable[id];
1431 if (item and item["creationtime"]) then
1432 local creationtime = GAS_timeToString(item["creationtime"]+0);
1433  
1434 local time = string.format(GUILDADS_SINCE, creationtime);
1435  
1436 GameTooltip:SetOwner(obj, "ANCHOR_BOTTOMRIGHT");
1437  
1438 if item.itemRef then
1439 GameTooltip:SetHyperlink(item.itemRef);
1440 else
1441 if (item.itemName) then
1442 GameTooltip:AddLine(item.itemName, 1.0, 1.0, 1.0);
1443 end
1444 end
1445  
1446 if (g_adtype == GUILDADS_MSG_TYPE_ANNONCE) then
1447 local owner = item.owner;
1448 local ownerColor = g_OnlineColor[GAS_IsOnline(owner)];
1449 local profile = GAS_ProfileGet(item.owner);
1450 local higherlevelOwner;
1451 local higherColor;
1452 if profile.accountid then
1453 higherlevelOwner = getHigherlevel(profile.accountid);
1454 higherColor = g_OnlineColor[GAS_IsOnline(higherlevelOwner)];
1455 if higherlevelOwner==owner then
1456 higherlevelOwner=nil;
1457 end
1458 end
1459  
1460 if higherlevelOwner then
1461 GameTooltip:AddDoubleLine(owner, higherlevelOwner, ownerColor.r, ownerColor.g, ownerColor.b, higherColor.r, higherColor.g, higherColor.b);
1462 else
1463 GameTooltip:AddLine(owner, ownerColor.r, ownerColor.g, ownerColor.b);
1464 end
1465  
1466 local guildName = GuildAds_GetPlayerGuild(adTable[id].owner);
1467 if (guildName) then
1468 GameTooltip:AddLine(CHAT_GUILD_SEND..guildName, 1.0, 1.0, 1.0);
1469 end
1470  
1471 local flag, message = GAC_GetFlag(item.owner);
1472 if flag then
1473 GameTooltip:AddLine(flag..": "..message, 1.0, 1.0, 1.0);
1474 end
1475 end
1476  
1477 text = adTable[id].text;
1478 if (text~=nil) then
1479 GuildAds_GameTooltip_AddText(LABEL_NOTE..": "..text, SinceColor.r, SinceColor.g, SinceColor.b);
1480 end
1481  
1482 if GuildAds_ShowPlayerVersion() then
1483 local meta = GAC_GetMeta(item.owner);
1484 if meta and meta.version then
1485 GameTooltip:AddLine("Version: "..meta.version, 1.0, 1.0, 1.0);
1486 else
1487 GameTooltip:AddLine("Version: ?", 1.0, 1.0, 1.0);
1488 end
1489 end
1490  
1491 GuildAdsPlugin_OnShowAd(GameTooltip, g_adtype, item);
1492  
1493 GameTooltip:AddLine(time, SinceColor.r, SinceColor.g, SinceColor.b);
1494  
1495 GameTooltip:Show();
1496  
1497 GuildAds_GameTooltip_AddTT(adTable[id].itemColor, adTable[id].itemRef, adTable[id].itemName, adTable[id].count or 1);
1498 end
1499 end
1500  
1501 ----------------------------------------------------------------------------------
1502 --
1503 -- Get selected global ad
1504 --
1505 ----------------------------------------------------------------------------------
1506 local function getSelectedAd()
1507 if (g_GlobalAdSelected > 0) then
1508 local adTable = GAS_GetAds(g_adtype);
1509 local size = table.getn(adTable);
1510 if (g_GlobalAdSelected <= size) then
1511 return adTable[g_GlobalAdSelected];
1512 end
1513 end
1514 return nil;
1515 end
1516  
1517 ---------------------------------------------------------------------------------
1518 --
1519 -- Called when a my add is clicked
1520 --
1521 ---------------------------------------------------------------------------------
1522 function GuildAds_MyAdButton_OnClick()
1523 local id = this:GetID();
1524 local offset = FauxScrollFrame_GetOffset(GuildAdsMyAdScrollFrame);
1525 selected = id + offset;
1526 if (g_mytype == GUILDADS_MY_ADS) then
1527 if (selected == g_MyAdSelected) then
1528 GuildAds_MyAdsEdit(nil);
1529 else
1530 GuildAds_MyAdsEdit(selected);
1531 end
1532 end
1533 end
1534  
1535 ---------------------------------------------------------------------------------
1536 --
1537 -- Edit one of my ad (or none if nil)
1538 --
1539 ---------------------------------------------------------------------------------
1540 function GuildAds_MyAdsEdit(id)
1541 if (id == nil) then
1542 g_MyAdSelected = 0;
1543 GuildAds_setEditItem(nil, nil, nil, nil);
1544 GuildAdsRemoveButton:Disable();
1545 else
1546 g_MyAdSelected = id;
1547 if (g_mytype == GUILDADS_MY_ADS) then
1548 local myads = GAS_GetMyAds();
1549 local ad = myads[g_adtype][id];
1550 local link = nil;
1551 if (ad.itemName) then
1552 link = GAS_PackLink(ad.itemColor, ad.itemRef, ad.itemName);
1553 end
1554 GuildAds_setEditItem(ad.text, link, ad.texture, ad.count);
1555 end
1556 GuildAdsRemoveButton:Enable();
1557 end
1558 GuildAds_UpdateMyFrame();
1559 end
1560  
1561 ----------------------------------------------------------------------------------
1562 --
1563 -- Called when MyAds check button is clicked
1564 --
1565 ---------------------------------------------------------------------------------
1566 function GuildAds_MyCheckButton_OnClick()
1567 if ( this:GetChecked() ) then
1568 PlaySound("igMainMenuOptionCheckBoxOn");
1569 else
1570 PlaySound("igMainMenuOptionCheckBoxOff");
1571 end
1572  
1573 if (g_mytype == GUILDADS_MY_FILTER) then
1574 GuildAds_MyFilterCheckButton_OnClick();
1575 else
1576 GuildAds_MyAdsCheckButton_OnClick();
1577 end
1578 end
1579  
1580 function GuildAds_MyFilterCheckButton_OnClick()
1581 if (GuildAds.Config.Filters[g_adtype][this.m_filterIndex]) then
1582 GuildAds.Config.Filters[g_adtype][this.m_filterIndex] = nil;
1583 else
1584 GuildAds.Config.Filters[g_adtype][this.m_filterIndex] = true;
1585 end
1586 GuildAds_UpdateMyFrame();
1587 GuildAds_UpdateGlobalAdButtons(g_adtype, true);
1588 end
1589  
1590 function GuildAds_MyAdsCheckButton_OnClick()
1591 if ( this:GetChecked() ) then
1592 GAS_EnableMyAd(g_adtype, this.m_AdIndex);
1593 else
1594 GAS_DisableMyAd(g_adtype, this.m_AdIndex);
1595 end
1596 end
1597  
1598  
1599 ---------------------------------------------------------------------------------
1600 function GuildAds_GetAddButton()
1601 if (g_adtype == GUILDADS_MSG_TYPE_REQUEST) then
1602 return GuildAdsAddButtonLookFor;
1603 elseif (g_adtype == GUILDADS_MSG_TYPE_AVAILABLE) then
1604 return GuildAdsAddButtonAvailable;
1605 elseif (g_adtype == GUILDADS_MSG_TYPE_EVENT) then
1606 return GuildAdsAddButtonEvent;
1607 end
1608 end
1609  
1610 function GuildAds_AddButtonUpdate()
1611 if (GuildAdsEditBox:GetText() ~= "") then
1612 local addButton = GuildAds_GetAddButton();
1613 if (addButton) then
1614 addButton:Enable();
1615 end
1616 else
1617 if (g_editName == nil) then
1618 local addButton = GuildAds_GetAddButton();
1619 if (addButton) then
1620 addButton:Disable();
1621 end
1622 end
1623 end
1624 end
1625  
1626 function GuildAds_setEditItem(text, link, texture, count)
1627 local enableAddButton = false;
1628  
1629 if (link) then
1630 g_editColor, g_editRef, g_editName = GAS_UnpackLink(link);
1631 else
1632 g_editColor = nil;
1633 g_editRef = nil;
1634 g_editName = nil;
1635 end
1636  
1637 g_editTexture = texture;
1638 GuildAdsEditTexture:SetNormalTexture(texture);
1639  
1640 if (text) then
1641 GuildAdsEditBox:SetText(text);
1642 enableAddButton = true;
1643 else
1644 GuildAdsEditBox:SetText("");
1645 end
1646  
1647 if (count) then
1648 GuildAdsEditCount:SetText(count);
1649 enableAddButton = true;
1650 else
1651 GuildAdsEditCount:SetText("");
1652 end
1653  
1654 if (g_editName) then
1655 GuildAdsEditTextureName:SetText(g_editName);
1656 enableAddButton = true;
1657 else
1658 GuildAdsEditTextureName:SetText("");
1659 end
1660  
1661 if (g_editColor) then
1662 local r, g, b = GAS_GetRGBFromHexColor(g_editColor);
1663 GuildAdsEditTextureName:SetTextColor(r, g, b);
1664 else
1665 GuildAdsEditTextureName:SetTextColor(1.0, 1.0, 1.0);
1666 end
1667  
1668 local addButton = GuildAds_GetAddButton();
1669 if (addButton) then
1670 if enableAddButton then
1671 addButton:Enable();
1672 else
1673 addButton:Disable();
1674 end
1675 end
1676 end
1677  
1678 ----------------------------------------------------------------------------------
1679 --
1680 -- Add a new entry to MyAds
1681 --
1682 ---------------------------------------------------------------------------------
1683 function GuildAds_AddButton_OnClick(request_type)
1684 DEBUG_MSG("GuildAds_AddButton_OnClick("..NoNil(request_type)..")");
1685 --
1686 -- Add a new ad if there is text in the edit box
1687 --
1688 local text = GuildAdsEditBox:GetText();
1689 if (text ~= "") or (g_editName ~= "") then
1690 text = string.sub(text, 1, 200);
1691 if (request_type == nil) then
1692 request_type = 1;
1693 end
1694 local count = GuildAdsEditCount:GetNumber();
1695 if (count == 0) then
1696 count = nil;
1697 end
1698  
1699 if (g_editName or text~="") then
1700 local resetEdit = true;
1701  
1702 if (g_MyAdSelected == 0) then
1703 if (not GAS_AddMyAd(request_type, text, g_editColor, g_editRef, g_editName, g_editTexture, count)) then
1704 resetEdit = false;
1705 end
1706 else
1707 GAS_EditMyAd(request_type, g_MyAdSelected, text, g_editColor, g_editRef, g_editName, g_editTexture, count);
1708 end
1709  
1710 -- Reset edit box and update buttons in UI
1711 if (resetEdit) then
1712 GuildAdsEditBox:AddHistoryLine(text);
1713 GuildAds_MyAdsEdit(nil);
1714 end
1715 end
1716 end
1717 end
1718  
1719 ----------------------------------------------------------------------------------
1720 --
1721 -- Remove the currently selected MyAds
1722 --
1723 ---------------------------------------------------------------------------------
1724 function GuildAds_RemoveButton_OnClick()
1725 --
1726 -- Remove the currently selected ad only if one is selected
1727 --
1728 if (g_MyAdSelected > 0) then
1729 --
1730 -- Make sure there is something in the table
1731 --
1732 local myads = GAS_GetMyAds();
1733 local size = table.getn(myads[g_adtype]);
1734 if (g_MyAdSelected <= size) then
1735 -- Delete ads
1736 GAS_RemoveMyAd(g_adtype, myads[g_adtype][g_MyAdSelected].id);
1737  
1738 -- Adjust the selected index if the last ad in the table was deleted
1739 if (g_MyAdSelected == size) then
1740 if (g_MyAdSelected > 1) then
1741 g_MyAdSelected = g_MyAdSelected - 1;
1742 else
1743 g_MyAdSelected = nil;
1744 end
1745 end
1746  
1747 -- Make sure changes are reflected in the UI
1748 GuildAds_MyAdsEdit(g_MyAdSelected);
1749 end
1750 end
1751 end
1752  
1753 ---------------------------------------------------------------------------------
1754 --
1755 -- Toggle group by account
1756 --
1757 ---------------------------------------------------------------------------------
1758 function GuildAdsConfig_SetGroupByAccount(state)
1759 GuildAds.Config.GroupByAccount = state;
1760 g_TableToShowCache[GUILDADS_MSG_TYPE_ANNONCE] = nil;
1761 GuildAds_UpdateGlobalAdButtons(g_adtype, true);
1762 end
1763  
1764 ---------------------------------------------------------------------------------
1765 --
1766 -- Toggle show offline players
1767 --
1768 ---------------------------------------------------------------------------------
1769 function GuildAds_ShowOfflinePlayer(state)
1770 if (state) then
1771 GuildAds.Config.ShowOfflinePlayer = true;
1772 else
1773 GuildAds.Config.ShowOfflinePlayer = false;
1774 end
1775 GuildAds_UpdateGlobalAdButtons(g_adtype, true);
1776 end
1777  
1778 ---------------------------------------------------------------------------------
1779 --
1780 -- Toggle show my ads
1781 --
1782 ---------------------------------------------------------------------------------
1783 function GuildAds_ShowMyAds(state)
1784 if state then
1785 GuildAds.Config.ShowMyAds = true;
1786 else
1787 GuildAds.Config.ShowMyAds = false;
1788 end
1789 GuildAds_UpdateGlobalAdButtons(g_adtype, true);
1790 end
1791  
1792 ---------------------------------------------------------------------------------
1793 --
1794 -- Toggle sort by subtype
1795 --
1796 ---------------------------------------------------------------------------------
1797 function GuildAds_SortBySubType(state)
1798 if state then
1799 GuildAdsConfig_SetProfileValue("sortBySubType", true);
1800 else
1801 GuildAdsConfig_SetProfileValue("sortBySubType", false);
1802 end
1803 g_sortBySubType = state;
1804 GuildAdsFrame_ResetCache();
1805 GuildAds_UpdateGlobalAdButtons(g_adtype);
1806 end
1807  
1808 function GuildAds_GuildShowOfflines(state)
1809 if state then
1810 GuildAdsConfig_SetProfileValue("GuildShowOfflines", true);
1811 else
1812 GuildAdsConfig_SetProfileValue("GuildShowOfflines", nil);
1813 end
1814 GuildAds_UpdateGlobalAdButtons(g_adtype, true);
1815 end
1816  
1817 ----------------------------------------------------------------------------------
1818 --
1819 -- Update the contents of the MyAds frame
1820 --
1821 ---------------------------------------------------------------------------------
1822 function GuildAds_UpdateFiltersFrame()
1823 local offset = FauxScrollFrame_GetOffset(GuildAdsMyAdScrollFrame);
1824  
1825 local filters = g_AdFilters[g_adtype];
1826  
1827 if (not GuildAds.Config.Filters[g_adtype]) then
1828 GuildAds.Config.Filters[g_adtype] = { };
1829 end
1830 filtersSelected = GuildAds.Config.Filters[g_adtype];
1831  
1832 local size = table.getn(filters);
1833 local i = 1;
1834 while (i <= GUILDADS_NUM_MY_AD_BUTTONS) do
1835 --
1836 -- Get the index to the ad displayed in this row
1837 --
1838 local index = i + offset;
1839 --
1840 -- Get the button on this row and set the index
1841 --
1842 local button = getglobal("GuildAdsMyAdButton"..i);
1843 local checkButton = getglobal("GuildAdsMyAdButton"..i.."CheckButton");
1844 --
1845 -- Is there a valid ad on this row?
1846 --
1847 if (index <= size) then
1848 -- Set id
1849 button.m_filterIndex = filters[index].id;
1850 checkButton.m_filterIndex = filters[index].id;
1851  
1852 -- Check the check box if appropriate
1853 if (filtersSelected[filters[index].id]) then
1854 checkButton:SetChecked(1);
1855 else
1856 checkButton:SetChecked(0);
1857 end
1858 checkButton:Show();
1859  
1860 -- Update the button text
1861 button:Show();
1862 local textField = "GuildAdsMyAdButton"..i.."Text";
1863 getglobal(textField):SetText(filters[index].name);
1864  
1865 -- If this is the selected ad, highlight it
1866 if (g_MyAdSelected == filters[index].id) then
1867 button:LockHighlight();
1868 checkButton:LockHighlight();
1869 else
1870 button:UnlockHighlight();
1871 checkButton:UnlockHighlight();
1872 end
1873 else
1874 -- Hide the button
1875 button:Hide();
1876 checkButton:Hide();
1877 end
1878 -- Next row
1879 i = i + 1;
1880 end
1881  
1882 -- Update the scroll bar
1883 FauxScrollFrame_Update(GuildAdsMyAdScrollFrame, size, GUILDADS_NUM_MY_AD_BUTTONS, GUILDADS_ADBUTTONSIZEY);
1884 end
1885  
1886 function GuildAds_UpdateMyAdsFrame()
1887 --
1888 -- Sort my ads
1889 --
1890 local myads = GAS_GetMyAds();
1891 GuildAds_AdsSort(g_adtype, myads[g_adtype])
1892  
1893 --
1894 -- Determine where the scroll bar is
1895 --
1896 local offset = FauxScrollFrame_GetOffset(GuildAdsMyAdScrollFrame);
1897 --
1898 -- Walk through all the rows in the MyAds frame
1899 --
1900 local size = table.getn(myads[g_adtype]);
1901 local i = 1;
1902 while (i <= GUILDADS_NUM_MY_AD_BUTTONS) do
1903 --
1904 -- Get the index to the ad displayed in this row
1905 --
1906 local iAd = i + offset;
1907 --
1908 -- Get the button on this row and set the index
1909 --
1910 local button = getglobal("GuildAdsMyAdButton"..i);
1911 local checkButton = getglobal("GuildAdsMyAdButton"..i.."CheckButton");
1912  
1913 button.m_AdIndex = iAd;
1914 checkButton.m_AdIndex = iAd;
1915 --
1916 -- Is there a valid ad on this row?
1917 --
1918 if (iAd <= size) then
1919 local ad = myads[g_adtype][iAd];
1920 --
1921 -- Check the check box if appropriate
1922 --
1923 if (ad.m_Enabled) then
1924 checkButton:SetChecked(1);
1925 else
1926 checkButton:SetChecked(0);
1927 end
1928 checkButton:Show();
1929 --
1930 -- Update the button text
1931 --
1932 button:Show();
1933 local textField = "GuildAdsMyAdButton"..i.."Text";
1934 getglobal(textField):SetText(GuildAds_AdGetText(g_adtype, ad));
1935 --
1936 -- If this is the selected ad, highlight it
1937 --
1938 if (g_MyAdSelected == iAd) then
1939 button:LockHighlight();
1940 checkButton:LockHighlight();
1941 else
1942 button:UnlockHighlight();
1943 checkButton:UnlockHighlight();
1944 end
1945 else
1946 --
1947 -- Hide the button
1948 --
1949 button:Hide();
1950 checkButton:Hide();
1951 end
1952 --
1953 -- Next row
1954 --
1955 i = i + 1;
1956 end
1957 --
1958 -- Update the scroll bar
1959 --
1960 FauxScrollFrame_Update(GuildAdsMyAdScrollFrame, size, GUILDADS_NUM_MY_AD_BUTTONS, GUILDADS_ADBUTTONSIZEY);
1961 end
1962  
1963 function GuildAds_UpdateMyFrame()
1964 if (g_mytype == GUILDADS_MY_FILTER) then
1965 GuildAds_UpdateFiltersFrame();
1966 else
1967 GuildAds_UpdateMyAdsFrame();
1968 end
1969 end
1970  
1971 function GuildAds_MySelectTab(tab)
1972 g_mytype = tab;
1973 if (g_mytype == GUILDADS_MY_ADS) then
1974 PanelTemplates_SelectTab(GuildAds_MyTab1);
1975 PanelTemplates_DeselectTab(GuildAds_MyTab2);
1976 else
1977 PanelTemplates_SelectTab(GuildAds_MyTab2);
1978 PanelTemplates_DeselectTab(GuildAds_MyTab1);
1979 end
1980 GuildAds_MyAdsEdit(nil);
1981 GuildAds_UpdateMyFrame();
1982 end
1983  
1984 -------- Date filter ------
1985 function GuildAds_DateFilter_OnValueChanged()
1986 if g_DateFilter[this:GetValue()] then
1987 GuildAds_DateFilterLabel:SetText(GAS_timeToString(g_DateFilter[this:GetValue()], true));
1988 GuildAdsConfig_SetProfileValue("HideAdsOlderThan", g_DateFilter[this:GetValue()]);
1989 else
1990 GuildAds_DateFilterLabel:SetText(GUILDADS_ITEMS.everything);
1991 GuildAdsConfig_SetProfileValue("HideAdsOlderThan", nil);
1992 end
1993 GuildAdsFrame_ResetCache();
1994 GuildAds_UpdateGlobalAdButtons(g_adtype);
1995 end
1996  
1997  
1998 -------- Minimap button ------
1999 function GuildAdsMinimapButton_Update()
2000 if GuildAds and GuildAds.Config then
2001 GuildAdsMinimapButton:SetPoint( "TOPLEFT", "Minimap", "TOPLEFT",
2002 55 - ( ( GuildAds.Config.MinimapRadiusOffset ) * cos( GuildAds.Config.MinimapArcOffset ) ),
2003 ( ( GuildAds.Config.MinimapRadiusOffset ) * sin( GuildAds.Config.MinimapArcOffset ) ) - 55
2004 );
2005 end
2006 end
2007  
2008 ------ Bouton instance --------
2009 function GuildAds_Event_ZoneDropDown_OnShow()
2010 UIDropDownMenu_Initialize(GuildAds_Event_ZoneDropDown, GuildAds_Event_ZoneDropDown_Init);
2011 UIDropDownMenu_SetText(GUILDADS_EVENTS_TITLE, GuildAds_Event_ZoneDropDown);
2012 UIDropDownMenu_SetWidth(100, GuildAds_Event_ZoneDropDown);
2013 end
2014  
2015 function GuildAds_Event_ZoneDropDown_OnClick()
2016 GuildAdsEditBox:SetText(this.value);
2017 end
2018  
2019 function GuildAds_Event_ZoneDropDown_Init()
2020 for k,instance in GUILDADS_EVENTS do
2021 local info = { };
2022 info.text = instance;
2023 info.value = instance;
2024 info.func = GuildAds_Event_ZoneDropDown_OnClick;
2025 UIDropDownMenu_AddButton(info);
2026 end
2027 end
2028  
2029  
2030 ---------- Right click on an ads -----------------------
2031 function GuildAdsFromAdsMenu_OnLoad()
2032 HideDropDownMenu(1);
2033 GuildAdsFromAdsMenu.initialize = GuildAdsFromAdsMenu_Initialize;
2034 GuildAdsFromAdsMenu.displayMode = "MENU";
2035 GuildAdsFromAdsMenu.name = "Titre";
2036 end
2037  
2038 function GuildAdsFromAdsMenu_Initialize()
2039 if (GuildAdsFromAdsMenu.groupId) then
2040 if (g_adtype == GUILDADS_MSG_TYPE_EVENT) then
2041 GuildAdsFromAdsMenu_InitializeEvent();
2042 end
2043 else
2044 GuildAdsFromAdsMenu_InitializeOwner();
2045 end
2046 end
2047  
2048 function GuildAdsFromAdsMenu_InitializeOwner()
2049 local ad = getSelectedAd();
2050  
2051 info = { };
2052 info.text = ad.owner;
2053 info.isTitle = true;
2054 info.notCheckable = 1;
2055 UIDropDownMenu_AddButton(info, 1);
2056  
2057 info = { };
2058 info.text = WHISPER_MESSAGE;
2059 info.notCheckable = 1;
2060 info.value = ad;
2061 info.func = GuildAdsFromAdsMenu_Whisper_OnClick;
2062 --[[
2063 if not GAS_IsOnline(ad.owner) then
2064 info.disabled = 1
2065 end
2066 ]]
2067 UIDropDownMenu_AddButton(info, 1);
2068  
2069 info = { };
2070 info.text = INSPECT;
2071 info.notCheckable = 1;
2072 info.value = ad;
2073 info.func = GuildAdsFromAdsMenu_Inspect_OnClick;
2074 UIDropDownMenu_AddButton(info, 1);
2075  
2076 info = { };
2077 info.text = CHAT_INVITE_SEND;
2078 info.notCheckable = 1;
2079 info.value = ad;
2080 info.func = GuildAdsFromAdsMenu_Invite_OnClick;
2081 UIDropDownMenu_AddButton(info, 1);
2082  
2083 info = { };
2084 info.text = WHO;
2085 info.notCheckable = 1;
2086 info.value = ad;
2087 info.func = GuildAdsFromAdsMenu_Who_OnClick;
2088 UIDropDownMenu_AddButton(info, 1);
2089  
2090 GuildAdsPlugin_OnShowContextMenu(g_adtype, ad);
2091  
2092 if g_adtype==GUILDADS_MSG_TYPE_ANNONCE then
2093 info = { };
2094 info.text = IGNORE;
2095 info.notCheckable = 1;
2096 info.value = ad;
2097 info.func = GuildAdsFromAdsMenu_Ignore_OnClick;
2098 UIDropDownMenu_AddButton(info, 1);
2099 end
2100  
2101  
2102 info = { };
2103 info.text = CANCEL;
2104 info.notCheckable = 1;
2105 info.func = GuildAdsFromAdsMenu_Cancel_OnClick;
2106 UIDropDownMenu_AddButton(info, 1);
2107 end
2108  
2109 ---------- Right click on an ads (event) -----------------------
2110 function GuildAdsFromAdsMenu_InitializeEvent()
2111 info = { };
2112 info.text = GuildAdsFromAdsMenu.groupId;
2113 info.isTitle = true;
2114 info.notCheckable = 1;
2115 UIDropDownMenu_AddButton(info, 1);
2116  
2117 info = { };
2118 info.text = GUILDADS_BUTTON_ADDEVENT;
2119 info.notCheckable = 1;
2120 info.func = GuildAdsFromAdsMenu_Event_OnClick;
2121 info.value = GuildAdsFromAdsMenu.groupId;
2122 UIDropDownMenu_AddButton(info, 1);
2123  
2124 info = { };
2125 info.text = CANCEL;
2126 info.notCheckable = 1;
2127 info.func = GuildAdsFromAdsMenu_Cancel_OnClick;
2128 UIDropDownMenu_AddButton(info, 1);
2129 end
2130  
2131 function GuildAdsFromAdsMenu_Cancel_OnClick()
2132 HideDropDownMenu(1);
2133 end
2134  
2135 function GuildAdsFromAdsMenu_Event_OnClick()
2136 GAS_AddMyAd(GUILDADS_MSG_TYPE_EVENT, this.value);
2137 end
2138  
2139 function GuildAdsFromAdsMenu_Whisper_OnClick()
2140 local ad = this.value;
2141 if (ad) then
2142 if ( not ChatFrameEditBox:IsVisible() ) then
2143 ChatFrame_OpenChat("/w "..ad.owner.." ");
2144 else
2145 ChatFrameEditBox:SetText("/w "..ad.owner.." ");
2146 end
2147 ChatEdit_ParseText(ChatFrame1.editBox, 0);
2148 end
2149 end
2150  
2151 function GuildAdsFromAdsMenu_Inspect_OnClick()
2152 local ad = this.value;
2153 if (ad) then
2154 GuildAdsInspectUser(ad.owner);
2155 end
2156 end
2157  
2158 function GuildAdsFromAdsMenu_Invite_OnClick()
2159 local ad = this.value;
2160 if (ad) then
2161 InviteByName(ad.owner);
2162 end
2163 end
2164  
2165 function GuildAdsFromAdsMenu_Who_OnClick()
2166 local ad = this.value;
2167 if (ad) then
2168 local text = ChatFrameEditBox:GetText();
2169 ChatFrameEditBox:SetText("/who "..ad.owner);
2170 ChatEdit_SendText(ChatFrameEditBox);
2171 ChatFrameEditBox:SetText(text);
2172 end
2173 end
2174  
2175 function GuildAdsFromAdsMenu_Ignore_OnClick()
2176 local ad = this.value;
2177 if (ad) then
2178 GAS_ProfileIgnore(ad.owner, true);
2179 GuildAdsFrame_ResetCache();
2180 end
2181 end