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