annotate CensusPlayerList.lua @ 24:85bba836578e

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