EmFor@0: --[[ EmFor@0: CensusPlus for World of Warcraft(tm). EmFor@0: EmFor@0: Copyright 2005 - 2006 Cooper Sellers and WarcraftRealms.com EmFor@0: EmFor@0: License: EmFor@0: This program is free software; you can redistribute it and/or EmFor@0: modify it under the terms of the GNU General Public License EmFor@0: as published by the Free Software Foundation; either version 2 EmFor@0: of the License, or (at your option) any later version. EmFor@0: EmFor@0: This program is distributed in the hope that it will be useful, EmFor@0: but WITHOUT ANY WARRANTY; without even the implied warranty of EmFor@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the EmFor@0: GNU General Public License for more details. EmFor@0: EmFor@0: You should have received a copy of the GNU General Public License EmFor@0: along with this program(see GLP.txt); if not, write to the Free Software EmFor@0: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. EmFor@0: ]] EmFor@0: EmFor@0: EmFor@0: ------------------------------------------------------------------------------------ EmFor@0: -- EmFor@0: -- CensusPlus EmFor@0: -- A WoW UI customization by Cooper Sellers EmFor@0: -- EmFor@0: -- EmFor@0: ------------------------------------------------------------------------------------ EmFor@0: EmFor@0: local g_PlayerList = {}; EmFor@0: local g_PlayerLookupTable = {}; EmFor@0: local CensusPlus_NumPlayerButtons = 20; EmFor@0: local g_MaxNumListed = 1000; EmFor@0: EmFor@0: function CensusPlus_ShowPlayerList() EmFor@0: CP_PlayerListWindow:Show(); EmFor@0: end EmFor@0: EmFor@0: function CensusPlus_PlayerListOnShow() EmFor@0: EmFor@0: debugprofilestart(); EmFor@0: EmFor@0: local guildKey = nil; EmFor@0: local raceKey = nil; EmFor@0: local classKey = nil; EmFor@0: local levelKey = nil; EmFor@0: EmFor@0: EmFor@0: -- EmFor@0: -- Clear our character list EmFor@0: -- EmFor@0: CensusPlus_ClearPlayerList(); EmFor@0: EmFor@0: -- EmFor@0: -- Get realm and faction EmFor@0: -- EmFor@0: local realmName = g_CensusPlusLocale .. GetCVar("realmName"); EmFor@0: if( realmName == nil ) then EmFor@0: return; EmFor@0: end EmFor@0: EmFor@0: local factionGroup = UnitFactionGroup("player"); EmFor@0: if( factionGroup == nil ) then EmFor@0: return; EmFor@0: end EmFor@0: EmFor@0: EmFor@0: -- EmFor@0: -- Has the user made any selections? EmFor@0: -- EmFor@0: if (g_GuildSelected ~= nil ) then EmFor@0: guildKey = g_GuildSelected; EmFor@0: end EmFor@0: if (g_RaceSelected > 0) then EmFor@0: local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup); EmFor@0: raceKey = thisFactionRaces[g_RaceSelected]; EmFor@0: end EmFor@0: if (g_ClassSelected > 0) then EmFor@0: local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup); EmFor@0: classKey = thisFactionClasses[g_ClassSelected]; EmFor@0: end EmFor@0: if (g_LevelSelected > 0 or g_LevelSelected < 0) then EmFor@0: levelKey = g_LevelSelected; EmFor@0: end EmFor@0: EmFor@0: debugprofilestart(); EmFor@0: EmFor@0: CensusPlus_ForAllCharacters( realmName, factionGroup, raceKey, classKey, guildKey, levelKey, CensusPlus_AddPlayerToList); EmFor@0: EmFor@0: if( CensusPlus_EnableProfiling ) then EmFor@0: CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 ); EmFor@0: debugprofilestart(); EmFor@0: end EmFor@0: EmFor@0: EmFor@0: -- EmFor@0: -- Build our list EmFor@0: -- EmFor@0: CensusPlus_UpdatePlayerListButtons(); EmFor@0: EmFor@0: local totalCharactersText = format(CENSUSPlus_TOTALCHAR, table.getn( g_PlayerList ) ); EmFor@0: if( table.getn( g_PlayerList ) == g_MaxNumListed ) then EmFor@0: totalCharactersText = totalCharactersText .. " -- " .. CENSUSPlus_MAXXED; EmFor@0: end EmFor@0: EmFor@0: CensusPlayerListCount:SetText(totalCharactersText); EmFor@0: EmFor@0: end EmFor@0: EmFor@0: ---------------------------------------------------------------------------------- EmFor@0: -- EmFor@0: -- Predicate function which can be used to compare two characters for sorting EmFor@0: -- EmFor@0: --------------------------------------------------------------------------------- EmFor@0: local function CharacterPredicate(lhs, rhs) EmFor@0: -- EmFor@0: -- nil references are always less than EmFor@0: -- EmFor@0: if (lhs == nil) then EmFor@0: if (rhs == nil) then EmFor@0: return false; EmFor@0: else EmFor@0: return true; EmFor@0: end EmFor@0: elseif (rhs == nil) then EmFor@0: return false; EmFor@0: end EmFor@0: -- EmFor@0: -- Sort by name EmFor@0: -- EmFor@0: if (lhs.m_name < rhs.m_name) then EmFor@0: return true; EmFor@0: elseif (rhs.m_name < lhs.m_name) then EmFor@0: return false; EmFor@0: end EmFor@0: EmFor@0: -- EmFor@0: -- Sort by level EmFor@0: -- EmFor@0: if (lhs.m_level < rhs.m_level) then EmFor@0: return true; EmFor@0: elseif (rhs.m_level < lhs.m_level) then EmFor@0: return false; EmFor@0: end EmFor@0: EmFor@0: -- EmFor@0: -- identical EmFor@0: -- EmFor@0: return false; EmFor@0: end EmFor@0: EmFor@0: local function CensusPlus_UpdatePlayerLookup( index, entry ) EmFor@0: -- EmFor@0: -- Have to update our table EmFor@0: -- EmFor@0: g_PlayerLookupTable[entry.m_name] = index; EmFor@0: end EmFor@0: EmFor@0: EmFor@0: EmFor@0: ---------------------------------------------------------------------------------- EmFor@0: -- EmFor@0: -- Update the Player button contents EmFor@0: -- EmFor@0: --------------------------------------------------------------------------------- EmFor@0: function CensusPlus_UpdatePlayerListButtons() EmFor@0: -- EmFor@0: -- Sort the list EmFor@0: -- EmFor@0: local size = table.getn(g_PlayerList); EmFor@0: if (size) then EmFor@0: table.sort(g_PlayerList, CharacterPredicate); EmFor@0: EmFor@0: table.foreach(g_PlayerList, CensusPlus_UpdatePlayerLookup ); EmFor@0: EmFor@0: end EmFor@0: EmFor@0: -- EmFor@0: -- Determine where the scroll bar is EmFor@0: -- EmFor@0: local offset = FauxScrollFrame_GetOffset( CensusPlusPlayerListScrollFrame ); EmFor@0: -- EmFor@0: -- Walk through all the rows in the frame EmFor@0: -- EmFor@0: local i = 1; EmFor@0: while( i <= CensusPlus_NumPlayerButtons ) do EmFor@0: -- EmFor@0: -- Get the index to the ad displayed in this row EmFor@0: -- EmFor@0: local iPlayer = i + offset; EmFor@0: -- EmFor@0: -- Get the button on this row EmFor@0: -- EmFor@0: local button = getglobal("CensusPlusPlayerButton"..i); EmFor@0: -- EmFor@0: -- Is there a valid Player on this row? EmFor@0: -- EmFor@0: if (iPlayer <= size) then EmFor@0: local player = g_PlayerList[iPlayer]; EmFor@0: -- EmFor@0: -- Update the button text EmFor@0: -- EmFor@0: button:Show(); EmFor@0: local textField = "CensusPlusPlayerButton"..i.."Name"; EmFor@0: if ( player.m_name == nil or player.m_name == "") then EmFor@0: getglobal(textField):SetText( "None" ); EmFor@0: else EmFor@0: getglobal(textField):SetText( player.m_name ); EmFor@0: end EmFor@0: EmFor@0: local textField = "CensusPlusPlayerButton"..i.."Level"; EmFor@0: if ( player.m_level == nil or player.m_level == "") then EmFor@0: getglobal(textField):SetText( "n/a" ); EmFor@0: else EmFor@0: getglobal(textField):SetText( player.m_level ); EmFor@0: end EmFor@0: EmFor@0: local textField = "CensusPlusPlayerButton"..i.."Class"; EmFor@0: if ( player.m_guild == nil or player.m_guild == "") then EmFor@0: getglobal(textField):SetText( "Unguilded" ); EmFor@0: else EmFor@0: getglobal(textField):SetText( player.m_guild ); EmFor@0: end EmFor@0: EmFor@0: local textField = "CensusPlusPlayerButton"..i.."Seen"; EmFor@0: if ( player.m_seen == nil or player.m_seen == "") then EmFor@0: getglobal(textField):SetText( "UNK" ); EmFor@0: else EmFor@0: getglobal(textField):SetText( player.m_seen ); EmFor@0: end EmFor@0: else EmFor@0: -- EmFor@0: -- Hide the button EmFor@0: -- EmFor@0: button:Hide(); EmFor@0: end EmFor@0: -- EmFor@0: -- Next row EmFor@0: -- EmFor@0: i = i + 1; EmFor@0: end EmFor@0: -- EmFor@0: -- Update the scroll bar EmFor@0: -- EmFor@0: FauxScrollFrame_Update(CensusPlusPlayerListScrollFrame, size, CensusPlus_NumPlayerButtons, CensusPlus_GUILDBUTTONSIZEY); EmFor@0: end EmFor@0: EmFor@0: ---------------------------------------------------------------------------------- EmFor@0: -- EmFor@0: -- Find a characters in the g_PlayerList array by name EmFor@0: -- EmFor@0: --------------------------------------------------------------------------------- EmFor@0: function CensusPlus_PlayerButton_OnClick() EmFor@0: local id = this:GetID(); EmFor@0: local offset = FauxScrollFrame_GetOffset( CensusPlusPlayerListScrollFrame ); EmFor@0: local newSelection = id + offset; EmFor@0: EmFor@0: local player = g_PlayerList[newSelection]; EmFor@0: FriendsFrame_ShowDropdown(player.m_name, 1); EmFor@0: end EmFor@0: EmFor@0: ---------------------------------------------------------------------------------- EmFor@0: -- EmFor@0: -- Clear all the characters EmFor@0: -- EmFor@0: --------------------------------------------------------------------------------- EmFor@0: function CensusPlus_ClearPlayerList() EmFor@0: g_PlayerList = nil; EmFor@0: g_PlayerList = {}; EmFor@0: EmFor@0: g_PlayerLookupTable = nil; EmFor@0: g_PlayerLookupTable = {}; EmFor@0: end EmFor@0: EmFor@0: ---------------------------------------------------------------------------------- EmFor@0: -- EmFor@0: -- Add a character to the list EmFor@0: -- EmFor@0: --------------------------------------------------------------------------------- EmFor@0: function CensusPlus_AddPlayerToList( name, level, guild, raceName, className, lastseen ) EmFor@0: local size = table.getn( g_PlayerList ); EmFor@0: EmFor@0: if( size >= g_MaxNumListed ) then EmFor@0: return; EmFor@0: end EmFor@0: EmFor@0: local index = g_PlayerLookupTable[name]; EmFor@0: if (index == nil) then EmFor@0: local size = table.getn( g_PlayerList ); EmFor@0: index = size + 1; EmFor@0: g_PlayerList[index] = { m_name = name, m_level = level, m_guild = guild, m_seen = lastseen }; EmFor@0: g_PlayerLookupTable[name] = index; EmFor@0: end EmFor@0: end EmFor@0: