comparison CensusPlayerList.lua @ 0:edfa01041183

Census+ Mod : - TLJ guild search - searchstart at Level 1 for community events
author EmFor <EmFor.hg@mroe.de>
date Tue, 30 Mar 2010 13:42:05 +0200
parents
children 10c85be19b56
comparison
equal deleted inserted replaced
-1:000000000000 0:edfa01041183
1 --[[
2 CensusPlus for World of Warcraft(tm).
3
4 Copyright 2005 - 2006 Cooper Sellers and WarcraftRealms.com
5
6 License:
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program(see GLP.txt); if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 ]]
21
22
23 ------------------------------------------------------------------------------------
24 --
25 -- CensusPlus
26 -- A WoW UI customization by Cooper Sellers
27 --
28 --
29 ------------------------------------------------------------------------------------
30
31 local g_PlayerList = {};
32 local g_PlayerLookupTable = {};
33 local CensusPlus_NumPlayerButtons = 20;
34 local g_MaxNumListed = 1000;
35
36 function CensusPlus_ShowPlayerList()
37 CP_PlayerListWindow:Show();
38 end
39
40 function CensusPlus_PlayerListOnShow()
41
42 debugprofilestart();
43
44 local guildKey = nil;
45 local raceKey = nil;
46 local classKey = nil;
47 local levelKey = nil;
48
49
50 --
51 -- Clear our character list
52 --
53 CensusPlus_ClearPlayerList();
54
55 --
56 -- Get realm and faction
57 --
58 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
59 if( realmName == nil ) then
60 return;
61 end
62
63 local factionGroup = UnitFactionGroup("player");
64 if( factionGroup == nil ) then
65 return;
66 end
67
68
69 --
70 -- Has the user made any selections?
71 --
72 if (g_GuildSelected ~= nil ) then
73 guildKey = g_GuildSelected;
74 end
75 if (g_RaceSelected > 0) then
76 local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
77 raceKey = thisFactionRaces[g_RaceSelected];
78 end
79 if (g_ClassSelected > 0) then
80 local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup);
81 classKey = thisFactionClasses[g_ClassSelected];
82 end
83 if (g_LevelSelected > 0 or g_LevelSelected < 0) then
84 levelKey = g_LevelSelected;
85 end
86
87 debugprofilestart();
88
89 CensusPlus_ForAllCharacters( realmName, factionGroup, raceKey, classKey, guildKey, levelKey, CensusPlus_AddPlayerToList);
90
91 if( CensusPlus_EnableProfiling ) then
92 CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 );
93 debugprofilestart();
94 end
95
96
97 --
98 -- Build our list
99 --
100 CensusPlus_UpdatePlayerListButtons();
101
102 local totalCharactersText = format(CENSUSPlus_TOTALCHAR, table.getn( g_PlayerList ) );
103 if( table.getn( g_PlayerList ) == g_MaxNumListed ) then
104 totalCharactersText = totalCharactersText .. " -- " .. CENSUSPlus_MAXXED;
105 end
106
107 CensusPlayerListCount:SetText(totalCharactersText);
108
109 end
110
111 ----------------------------------------------------------------------------------
112 --
113 -- Predicate function which can be used to compare two characters for sorting
114 --
115 ---------------------------------------------------------------------------------
116 local function CharacterPredicate(lhs, rhs)
117 --
118 -- nil references are always less than
119 --
120 if (lhs == nil) then
121 if (rhs == nil) then
122 return false;
123 else
124 return true;
125 end
126 elseif (rhs == nil) then
127 return false;
128 end
129 --
130 -- Sort by name
131 --
132 if (lhs.m_name < rhs.m_name) then
133 return true;
134 elseif (rhs.m_name < lhs.m_name) then
135 return false;
136 end
137
138 --
139 -- Sort by level
140 --
141 if (lhs.m_level < rhs.m_level) then
142 return true;
143 elseif (rhs.m_level < lhs.m_level) then
144 return false;
145 end
146
147 --
148 -- identical
149 --
150 return false;
151 end
152
153 local function CensusPlus_UpdatePlayerLookup( index, entry )
154 --
155 -- Have to update our table
156 --
157 g_PlayerLookupTable[entry.m_name] = index;
158 end
159
160
161
162 ----------------------------------------------------------------------------------
163 --
164 -- Update the Player button contents
165 --
166 ---------------------------------------------------------------------------------
167 function CensusPlus_UpdatePlayerListButtons()
168 --
169 -- Sort the list
170 --
171 local size = table.getn(g_PlayerList);
172 if (size) then
173 table.sort(g_PlayerList, CharacterPredicate);
174
175 table.foreach(g_PlayerList, CensusPlus_UpdatePlayerLookup );
176
177 end
178
179 --
180 -- Determine where the scroll bar is
181 --
182 local offset = FauxScrollFrame_GetOffset( CensusPlusPlayerListScrollFrame );
183 --
184 -- Walk through all the rows in the frame
185 --
186 local i = 1;
187 while( i <= CensusPlus_NumPlayerButtons ) do
188 --
189 -- Get the index to the ad displayed in this row
190 --
191 local iPlayer = i + offset;
192 --
193 -- Get the button on this row
194 --
195 local button = getglobal("CensusPlusPlayerButton"..i);
196 --
197 -- Is there a valid Player on this row?
198 --
199 if (iPlayer <= size) then
200 local player = g_PlayerList[iPlayer];
201 --
202 -- Update the button text
203 --
204 button:Show();
205 local textField = "CensusPlusPlayerButton"..i.."Name";
206 if ( player.m_name == nil or player.m_name == "") then
207 getglobal(textField):SetText( "None" );
208 else
209 getglobal(textField):SetText( player.m_name );
210 end
211
212 local textField = "CensusPlusPlayerButton"..i.."Level";
213 if ( player.m_level == nil or player.m_level == "") then
214 getglobal(textField):SetText( "n/a" );
215 else
216 getglobal(textField):SetText( player.m_level );
217 end
218
219 local textField = "CensusPlusPlayerButton"..i.."Class";
220 if ( player.m_guild == nil or player.m_guild == "") then
221 getglobal(textField):SetText( "Unguilded" );
222 else
223 getglobal(textField):SetText( player.m_guild );
224 end
225
226 local textField = "CensusPlusPlayerButton"..i.."Seen";
227 if ( player.m_seen == nil or player.m_seen == "") then
228 getglobal(textField):SetText( "UNK" );
229 else
230 getglobal(textField):SetText( player.m_seen );
231 end
232 else
233 --
234 -- Hide the button
235 --
236 button:Hide();
237 end
238 --
239 -- Next row
240 --
241 i = i + 1;
242 end
243 --
244 -- Update the scroll bar
245 --
246 FauxScrollFrame_Update(CensusPlusPlayerListScrollFrame, size, CensusPlus_NumPlayerButtons, CensusPlus_GUILDBUTTONSIZEY);
247 end
248
249 ----------------------------------------------------------------------------------
250 --
251 -- Find a characters in the g_PlayerList array by name
252 --
253 ---------------------------------------------------------------------------------
254 function CensusPlus_PlayerButton_OnClick()
255 local id = this:GetID();
256 local offset = FauxScrollFrame_GetOffset( CensusPlusPlayerListScrollFrame );
257 local newSelection = id + offset;
258
259 local player = g_PlayerList[newSelection];
260 FriendsFrame_ShowDropdown(player.m_name, 1);
261 end
262
263 ----------------------------------------------------------------------------------
264 --
265 -- Clear all the characters
266 --
267 ---------------------------------------------------------------------------------
268 function CensusPlus_ClearPlayerList()
269 g_PlayerList = nil;
270 g_PlayerList = {};
271
272 g_PlayerLookupTable = nil;
273 g_PlayerLookupTable = {};
274 end
275
276 ----------------------------------------------------------------------------------
277 --
278 -- Add a character to the list
279 --
280 ---------------------------------------------------------------------------------
281 function CensusPlus_AddPlayerToList( name, level, guild, raceName, className, lastseen )
282 local size = table.getn( g_PlayerList );
283
284 if( size >= g_MaxNumListed ) then
285 return;
286 end
287
288 local index = g_PlayerLookupTable[name];
289 if (index == nil) then
290 local size = table.getn( g_PlayerList );
291 index = size + 1;
292 g_PlayerList[index] = { m_name = name, m_level = level, m_guild = guild, m_seen = lastseen };
293 g_PlayerLookupTable[name] = index;
294 end
295 end
296