vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Guild Event Manager by Kiki of European Cho'gall
3 Players list - By Kiki
4 ]]
5  
6 GEM_PLAYERS_SORTBY_NAME = "name";
7 GEM_PLAYERS_SORTBY_GUILD = "guild";
8 GEM_PLAYERS_SORTBY_LOCATION = "location";
9 GEM_PLAYERS_SORTBY_LEVEL = "level";
10 GEM_PLAYERS_SORTBY_CLASS = "class";
11  
12 local GEM_PLAYERS_LASTLOG_MAX = 60*60*24*30;
13 local GEM_PLAYERS_MAXDISPLAY_EVENT = 25;
14 local sortTypePlayers = GEM_PLAYERS_SORTBY_NAME;
15 local sortDirPlayers = true;
16 local selectPlayer = nil;
17  
18 --[[
19 List Functions
20 ]]
21  
22 function GEMPlayers_PlayerOnHover()
23 local pl_name = this.playerName;
24  
25 if(pl_name)
26 then
27 GameTooltip:SetOwner(this, "ANCHOR_CURSOR");
28 GameTooltip:ClearLines();
29  
30 local color1 = "00AAFF";
31 local color2 = "FFFFFF";
32 local color3 = "E0C010";
33  
34 if(not GEM_IsPlayerConnected(GEM_DefaultSendChannel,pl_name))
35 then
36 color1 = "005588";
37 color2 = "888888";
38 color3 = "706005";
39 end
40  
41 local comment = "";
42 local rank_idx = -1;
43 local rank_name = "";
44 local version = "";
45 if(GEM_Players[GEM_Realm] and GEM_Players[GEM_Realm][GEM_DefaultSendChannel] and GEM_Players[GEM_Realm][GEM_DefaultSendChannel][pl_name])
46 then
47 comment = GEM_Players[GEM_Realm][GEM_DefaultSendChannel][pl_name].comment;
48 rank_name = GEM_Players[GEM_Realm][GEM_DefaultSendChannel][pl_name].grank_name;
49 rank_idx = GEM_Players[GEM_Realm][GEM_DefaultSendChannel][pl_name].grank_idx;
50 version = GEM_Players[GEM_Realm][GEM_DefaultSendChannel][pl_name].version;
51 end
52  
53 local lines = 0;
54  
55 lines = GEMList_AddTooltipText("|cff" .. color1 .. pl_name,lines);
56  
57 if(version and version ~= "")
58 then
59 lines = GEMList_AddTooltipText("|cff" .. color2 .. GEM_TEXT_GEM_VERSION .. " : |r|cff" ..color3..version.."|r",lines,color3);
60 end
61  
62 if(rank_name and rank_name ~= "")
63 then
64 lines = GEMList_AddTooltipText("|cff" .. color2 .. GEM_TEXT_GUILD_RANK .. " " .. rank_idx .. " : |r|cff" ..color3.. rank_name.."|r",lines,color3);
65 end
66  
67 if(comment and comment ~= "")
68 then
69 lines = GEMList_AddTooltipText("|cff" .. color2 .. GEM_TEXT_COMMENT .. " : |r|cff" ..color3..comment.."|r",lines,color3);
70 end
71  
72 if(lines > 1)
73 then
74 GameTooltip:Show();
75 else
76 GameTooltip:ClearLines();
77 end
78 end
79 end
80  
81  
82 function GEMPlayers_PlayerOnClick()
83 selectPlayer = this.playerName;
84 GEMPlayers_UpdatePlayersList();
85 end
86  
87 function GEMPlayers_PredicateName(a, b)
88 if (a.name < b.name) then
89 return true;
90 elseif (a.name > b.name) then
91 return false;
92 end
93  
94 return GEMPlayers_PredicateGuild(a, b);
95 end
96  
97 function GEMPlayers_PredicateGuild(a, b)
98 if (a.guild < b.guild) then
99 return true;
100 elseif (a.guild > b.guild) then
101 return false;
102 end
103  
104 return GEMPlayers_PredicateLocation(a, b);
105 end
106  
107 function GEMPlayers_PredicateLocation(a, b)
108 if (a.location < b.location) then
109 return true;
110 elseif (a.location > b.location) then
111 return false;
112 end
113  
114 return GEMPlayers_PredicateLevel(a, b);
115 end
116  
117 function GEMPlayers_PredicateLevel(a, b)
118 if (a.level < b.level) then
119 return true;
120 elseif (a.level > b.level) then
121 return false;
122 end
123  
124 return GEMPlayers_PredicateClass(a, b);
125 end
126  
127 function GEMPlayers_PredicateClass(a, b)
128 if (a.class < b.class) then
129 return true;
130 elseif (a.class > b.class) then
131 return false;
132 end
133  
134 return false;
135 end
136  
137 function GEMPlayers_Predicate(a, b)
138 -- a ou b est nil
139 if (a == nil) then
140 if (b == nil) then
141 return false;
142 else
143 return true;
144 end
145 elseif (b == nil) then
146 return false;
147 end
148  
149 GEM_SORTBY = {
150 [GEM_PLAYERS_SORTBY_NAME] = GEMPlayers_PredicateName,
151 [GEM_PLAYERS_SORTBY_GUILD] = GEMPlayers_PredicateGuild,
152 [GEM_PLAYERS_SORTBY_LOCATION] = GEMPlayers_PredicateLocation,
153 [GEM_PLAYERS_SORTBY_LEVEL] = GEMPlayers_PredicateLevel,
154 [GEM_PLAYERS_SORTBY_CLASS] = GEMPlayers_PredicateClass
155 };
156  
157 predicate = GEM_SORTBY[sortTypePlayers];
158 return predicate(a,b);
159 end
160  
161 function GEMPlayers_SortBy(aSortType, aSortDir)
162 sortTypePlayers = aSortType;
163 sortDirPlayers = aSortDir;
164 GEMPlayers_UpdatePlayersList();
165 end
166  
167 function GEMPlayers_OnSeeOfflineClick()
168 GEM_Events.realms[GEM_Realm].SeeOffline = GEMPlayersFrameSeeOffline:GetChecked();
169 GEMPlayers_UpdatePlayersList();
170 end
171  
172 function GEMPlayers_GetPlayers(channel)
173 local players = {};
174 local shownotconnected = GEMPlayersFrameSeeOffline:GetChecked() == 1;
175 local c_off = 0;
176 local c_on = 0;
177  
178 for name,playertab in GEM_Players[GEM_Realm][channel]
179 do
180 if(playertab.guild == nil) then playertab.guild = ""; end;
181 if(GEM_IsPlayerConnected(channel,name)) -- Connected
182 then
183 c_on = c_on + 1;
184 tinsert(players, {name=name; guild=playertab.guild; location=playertab.location; level=playertab.level; class=playertab.class, connected=true, officer=playertab.officer });
185 else
186 c_off = c_off + 1;
187 if(shownotconnected) -- Not connected
188 then
189 tinsert(players, {name=name; guild=playertab.guild; location=GEM_NA_FORMAT; level=playertab.level; class=playertab.class, connected=false, officer=playertab.officer });
190 end
191 end
192 end
193 table.sort(players,GEMPlayers_Predicate);
194 if(not sortDirPlayers)
195 then
196 players = GEMList_InvertList(players);
197 end
198 return players,c_on,c_off;
199 end
200  
201 function GEMPlayers_UpdatePlayersList()
202 if(not GEMPlayersFrame:IsVisible())
203 then
204 return;
205 end
206 local players,c_on,c_off = GEMPlayers_GetPlayers(GEM_DefaultSendChannel);
207 local size = table.getn(players);
208  
209 local enableActions = false;
210 local offset = FauxScrollFrame_GetOffset(GEMPlayerItemScrollFrame);
211 numButtons = GEM_PLAYERS_MAXDISPLAY_EVENT;
212 i = 1;
213 GEMPlayersFrameWhisper:Disable();
214 GEMPlayersFrameInvite:Disable();
215  
216 while (i <= numButtons)
217 do
218 local j = i + offset
219 local prefix = "GEMPlayerItem"..i;
220 local button = getglobal(prefix);
221  
222 if (j <= size)
223 then
224 local player = players[j];
225  
226 button.playerName = player.name;
227 getglobal(prefix.."Name"):SetText(player.name);
228 getglobal(prefix.."Guild"):SetText(player.guild);
229 getglobal(prefix.."Location"):SetText(player.location);
230 getglobal(prefix.."Level"):SetText(player.level);
231 getglobal(prefix.."Class"):SetText(player.class);
232 if(player.connected)
233 then
234 getglobal(prefix.."Name"):SetTextColor(0.9,0.8,0.10);
235 if(player.officer and player.officer ~= 0)
236 then
237 if(player.officer == 2) -- Guild leader
238 then
239 getglobal(prefix.."Guild"):SetTextColor(0.1,0.9,0.1);
240 elseif(player.officer == 1) -- Guild officer
241 then
242 getglobal(prefix.."Guild"):SetTextColor(0.3,0.3,0.9);
243 end
244 else -- Normal member
245 getglobal(prefix.."Guild"):SetTextColor(1,1,1);
246 end
247 getglobal(prefix.."Location"):SetTextColor(1,1,1);
248 getglobal(prefix.."Level"):SetTextColor(1,1,1);
249 getglobal(prefix.."Class"):SetTextColor(1,1,1);
250 else
251 getglobal(prefix.."Name"):SetTextColor(0.3,0.3,0.3);
252 getglobal(prefix.."Guild"):SetTextColor(0.3,0.3,0.3);
253 getglobal(prefix.."Location"):SetTextColor(0.3,0.3,0.3);
254 getglobal(prefix.."Level"):SetTextColor(0.3,0.3,0.3);
255 getglobal(prefix.."Class"):SetTextColor(0.3,0.3,0.3);
256 end
257 button:Show();
258  
259 -- selected
260 if (selectPlayer == player.name and selectPlayer ~= GEM_PlayerName)
261 then
262 button:LockHighlight();
263 if(player.connected)
264 then
265 enableActions = true;
266 end
267 else
268 button:UnlockHighlight();
269 end
270 else
271 button.playerName = nil;
272 button:Hide();
273 end
274 i = i + 1;
275 end
276  
277 GEMPlayersFrameCountString:SetText(string.format(GEM_TEXT_PLAYERS_COUNT,c_on,c_on+c_off));
278  
279 FauxScrollFrame_Update(GEMPlayerItemScrollFrame, size, GEM_PLAYERS_MAXDISPLAY_EVENT, 17);
280 if(enableActions)
281 then
282 GEMPlayersFrameWhisper:Enable();
283 GEMPlayersFrameInvite:Enable();
284 end
285 end
286  
287 function GEMPlayers_OnShow()
288 if(GEM_Events.realms[GEM_Realm].SeeOffline)
289 then
290 GEMPlayersFrameSeeOffline:SetChecked(1);
291 else
292 GEMPlayersFrameSeeOffline:SetChecked(0);
293 end
294  
295 GEMPlayers_UpdatePlayersList();
296 end
297  
298 function GEMPlayers_OnLoad()
299 end
300  
301 function GEMPlayers_WhisperOnClick()
302 if ( not ChatFrameEditBox:IsVisible() ) then
303 ChatFrame_OpenChat("/w "..selectPlayer.." ");
304 else
305 ChatFrameEditBox:SetText("/w "..selectPlayer.." ");
306 end
307 ChatEdit_ParseText(ChatFrame1.editBox, 0);
308 end
309  
310 function GEMPlayers_InviteOnClick()
311 InviteByName(selectPlayer);
312 end
313  
314 --------------- Exported functions ---------------
315  
316 function GEM_PLAY_GetMyPlayerInfos(channel)
317 local name = GEM_PlayerName;
318 local guild,grank_name,grank_idx = GetGuildInfo("player");
319 local officer = 0;
320 local location = GetRealZoneText();
321 local comment = GEM_Events.realms[GEM_Realm].my_names[GEM_PlayerName].comment;
322 if(location == nil)
323 then
324 location = GEM_NA_FORMAT;
325 end
326 local level = UnitLevel("player");
327 local _,class = UnitClass("player");
328 if(IsGuildLeader() == 1)
329 then
330 officer = 2;
331 elseif(CanViewOfficerNote() == 1)
332 then
333 officer = 1;
334 end
335  
336 if(guild == nil) -- No guild, set rank idx at -1
337 then
338 grank_idx = -1;
339 end
340 GEM_CheckPlayerGuild();
341 GEM_ChatDebug(GEM_DEBUG_GLOBAL,"GEM_PLAY_GetMyPlayerInfos : Channel "..tostring(channel).." for Player "..GEM_PlayerName);
342 if(GEM_Players[GEM_Realm][channel][GEM_PlayerName] == nil)
343 then
344 GEM_Players[GEM_Realm][channel][GEM_PlayerName] = {};
345 end
346 GEM_Players[GEM_Realm][channel][GEM_PlayerName].guild = guild;
347 GEM_Players[GEM_Realm][channel][GEM_PlayerName].location = location;
348 GEM_Players[GEM_Realm][channel][GEM_PlayerName].level = level;
349 GEM_Players[GEM_Realm][channel][GEM_PlayerName].class = GEM_Classes[class];
350 GEM_Players[GEM_Realm][channel][GEM_PlayerName].officer = officer;
351 GEM_Players[GEM_Realm][channel][GEM_PlayerName].grank_name = grank_name;
352 GEM_Players[GEM_Realm][channel][GEM_PlayerName].grank_idx = grank_idx;
353 GEM_Players[GEM_Realm][channel][GEM_PlayerName].version = GEM_VERSION;
354 GEM_Players[GEM_Realm][channel][GEM_PlayerName].comment = comment;
355 GEM_Players[GEM_Realm][channel][GEM_PlayerName].lastlog = time();
356  
357 return name,guild,location,level,class,officer,grank_name,grank_idx,GEM_VERSION,comment;
358 end
359  
360 function GEM_PLAY_FillPlayerInfos(channel,name,guild,location,level,class,officer,grank_name,grank_idx,version,comment)
361 if(name == nil) -- Me
362 then
363 GEM_PLAY_GetMyPlayerInfos(channel);
364 return;
365 end
366  
367 if(guild == nil)
368 then
369 guild = "";
370 end
371  
372 if(GEM_Players[GEM_Realm][channel][name] == nil)
373 then
374 GEM_Players[GEM_Realm][channel][name] = {};
375 end
376 GEM_Players[GEM_Realm][channel][name].guild = guild;
377 GEM_Players[GEM_Realm][channel][name].location = location;
378 GEM_Players[GEM_Realm][channel][name].level = level;
379 GEM_Players[GEM_Realm][channel][name].class = GEM_Classes[class];
380 GEM_Players[GEM_Realm][channel][name].officer = officer;
381 GEM_Players[GEM_Realm][channel][name].grank_name = grank_name;
382 GEM_Players[GEM_Realm][channel][name].grank_idx = grank_idx;
383 GEM_Players[GEM_Realm][channel][name].version = version;
384 GEM_Players[GEM_Realm][channel][name].comment = comment;
385 GEM_Players[GEM_Realm][channel][name].lastlog = time();
386 end
387  
388 function GEM_PLAY_GetLastLeave(channel,pl_name)
389 if(channel == nil or pl_name == nil or GEM_Players[GEM_Realm] == nil or GEM_Players[GEM_Realm][channel] == nil or GEM_Players[GEM_Realm][channel][pl_name] == nil or GEM_Players[GEM_Realm][channel][pl_name].lastleave == nil)
390 then
391 return 0;
392 end
393 return GEM_Players[GEM_Realm][channel][pl_name].lastleave;
394 end
395  
396 function GEMPlayers_CheckExpiredPlayers(channel)
397 if(GEM_Players[GEM_Realm] == nil or GEM_Players[GEM_Realm][channel] == nil)
398 then
399 return;
400 end
401  
402 GEM_ChatDebug(GEM_DEBUG_GLOBAL,"GEMPlayers_CheckExpiredPlayers : Checking expired players in channel "..channel);
403 local tim = time();
404  
405 for name,playertab in GEM_Players[GEM_Realm][channel]
406 do
407 if((playertab.lastlog + GEM_PLAYERS_LASTLOG_MAX) < tim)
408 then
409 GEM_ChatDebug(GEM_DEBUG_GLOBAL,"GEMPlayers_CheckExpiredPlayers : Too long since last log from player "..name.." in channel "..channel..", Removing !");
410 GEM_Players[GEM_Realm][channel][name] = nil;
411 end
412 end
413 end
414