2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2008 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2009 - 2016 , The OpenClonk Team and contributors
2013-12-17 20:01:09 +00:00
*
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
*
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
*
* To redistribute this file separately , substitute the full license texts
* for the above references .
*/
2009-05-08 13:28:41 +00:00
// player listbox used in lobby and game over dlg
# ifndef INC_C4PlayerInfoListBox
# define INC_C4PlayerInfoListBox
2016-04-03 18:07:56 +00:00
# include "gui/C4Gui.h"
2009-05-08 13:28:41 +00:00
class C4PlayerInfoListBox : public C4GUI : : ListBox
2010-03-28 17:58:21 +00:00
{
public :
enum Spacings
2009-05-08 13:28:41 +00:00
{
2010-03-28 17:58:21 +00:00
// some spacings
IconLabelSpacing = 2 , // space between an icon and its text
ClientListBoxSpacing = 8 , // space between two clients in the list
PlayerListBoxIndent = 3 , // indent of player list box items
NoneLabelSpacing = 20 , // indent of "- none -"-label in list box
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
SoundIconShowTime = 1 // seconds. min time a sound icon is shown
} ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// list box mode
enum Mode
{
PILBM_LobbyClientSort ,
PILBM_LobbyTeamSort ,
PILBM_Evaluation ,
PILBM_EvaluationNoWinners
} ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
private :
2009-05-08 13:28:41 +00:00
// generic player list item
class ListItem : public C4GUI : : Window
2010-03-28 17:58:21 +00:00
{
protected :
C4PlayerInfoListBox * pList ;
uint32_t dwBackground ; // not drawn if 0
public :
struct ID
2009-05-08 13:28:41 +00:00
{
2010-03-28 17:58:21 +00:00
enum IDType
{
PLI_NONE = 0 ,
PLI_SCRIPTPLR , // script player caption (ID=0) - script players themselbed are regular PLI_PLAYER
PLI_SAVEGAMEPLR , // restore savegame player (ID>0), or caption (ID=0)
PLI_PLAYER , // player
PLI_CLIENT , // client label
PLI_TEAM , // team label
PLI_REPLAY // replay player (ID>0), or caption (ID=0)
2017-05-07 11:50:00 +00:00
} idType { PLI_NONE } ;
2010-03-28 17:58:21 +00:00
2017-05-07 11:50:00 +00:00
int32_t id { 0 } ; // player file ID or team ID or client ID
2010-03-28 17:58:21 +00:00
2017-05-07 11:50:00 +00:00
ID ( ) = default ;
2010-03-28 17:58:21 +00:00
ID ( IDType eType , int32_t id ) : idType ( eType ) , id ( id ) { }
inline bool operator = = ( const ID & r2 )
{
return idType = = r2 . idType & & id = = r2 . id ;
}
2009-05-08 13:28:41 +00:00
} ;
2010-03-28 17:58:21 +00:00
ID idListItemID ;
C4GameLobby : : MainDlg * GetLobby ( ) const ;
virtual void Update ( ) { } // periodic update callback
protected :
2017-05-07 11:50:00 +00:00
void DrawElement ( C4TargetFacet & cgo ) override ; // draw background
2010-03-28 17:58:21 +00:00
bool CanLocalChooseTeams ( int32_t idPlayer = 0 ) const ; // whether the local client can change any teams
public :
ListItem ( C4PlayerInfoListBox * pList ) : C4GUI : : Window ( ) , pList ( pList ) , dwBackground ( 0 ) { }
} ;
2009-05-08 13:28:41 +00:00
// lobby information and display of joined players
class PlayerListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pIcon ; // player icon
C4GUI : : Label * pNameLabel ; // label indicating player name
C4GUI : : Label * pScoreLabel ; // label showing some player score (league)
C4GUI : : Label * pTimeLabel ; // evaluation only: label showing total playing time
C4GUI : : Label * pExtraLabel ; // evaluation only: label showing extra data set by script
C4GUI : : Icon * pRankIcon ; // league rank icon
2016-11-02 23:58:02 +00:00
C4GUI : : ComboBox * pTeamCombo ; // team selection combo - nullptr for no-team-scens
2010-03-28 17:58:21 +00:00
C4GUI : : Picture * pTeamPic ; // evaluation only: Team icon spec
bool fIconSet ; // whether custom icon has been set
bool fJoinedInfoSet ; // join info for savegame recreation
DWORD dwJoinClr , dwPlrClr ; //colors currently reflected in icon
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
int32_t idClient , idPlayer ; // referenced IDs
bool fFreeSavegamePlayer ; // if set, the player is an (unassociated) savegame player
bool fShownCollapsed ; // true if small view is shown
protected :
2017-05-07 11:50:00 +00:00
void UpdateOwnPos ( ) override ; // recalculate item positioning
int32_t GetListItemTopSpacing ( ) override ;
2010-03-28 17:58:21 +00:00
public :
PlayerListItem ( C4PlayerInfoListBox * pForListBox , int32_t idClient , int32_t idPlayer , bool fSavegamePlayer , C4GUI : : Element * pInsertBeforeElement ) ; // ctor
2017-05-07 11:50:00 +00:00
~ PlayerListItem ( ) override = default ; ; // dtor
2010-03-28 17:58:21 +00:00
void UpdateIcon ( C4PlayerInfo * pInfo , C4PlayerInfo * pJoinedInfo ) ; // update player icon
void UpdateTeam ( ) ;
void UpdateScoreLabel ( C4PlayerInfo * pInfo ) ; // update league score labels and icons
void UpdateCollapsed ( ) ;
public :
C4GUI : : ContextMenu * OnContext ( C4GUI : : Element * pListItem , int32_t iX , int32_t iY ) ; // open context menu
C4GUI : : ContextMenu * OnContextTakeOver ( C4GUI : : Element * pListItem , int32_t iX , int32_t iY ) ; // takeover savegame player submenu
void OnCtxTakeOver ( C4GUI : : Element * pListItem , const int32_t & idPlayer ) ;
void OnCtxRemove ( C4GUI : : Element * pListItem ) ;
void OnCtxNewColor ( C4GUI : : Element * pListItem ) ;
void OnTeamComboFill ( C4GUI : : ComboBox_FillCB * pFiller ) ;
bool OnTeamComboSelChange ( C4GUI : : ComboBox * pForCombo , int32_t idNewSelection ) ;
2017-05-07 11:50:00 +00:00
void Update ( ) override ; // update icon and team
2010-03-28 17:58:21 +00:00
int32_t GetInfoID ( ) const { return idPlayer ; }
C4Network2Client * GetNetClient ( ) const ; // return associated network client
C4PlayerInfo * GetPlayerInfo ( ) const ;
C4PlayerInfo * GetJoinedInfo ( ) const ; // if this player is joined or associated to a joined info, return the joined info
bool IsLocalClientPlayer ( ) const ; // whether this player is going to join locally
bool CanLocalChooseTeam ( ) const ; // whether the local client can change team for this player
} ;
2009-05-08 13:28:41 +00:00
// lobby information and display of connected clients
class ClientListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pStatusIcon ; // icon indicating client status (host, etc.)
C4GUI : : Label * pNameLabel ; // label indicating client name
2016-11-02 23:58:02 +00:00
C4GUI : : Label * pPingLabel ; // label indicating ping to client - may be nullptr
2010-03-28 17:58:21 +00:00
protected :
int32_t idClient ; // associated network interface ID
DWORD dwClientClr ; // client color used for chatting
bool fIsShownActive ; // whether client was active in last update
time_t tLastSoundTime ; // now() when the client last issued a sound (display as sound icon). 0 for no sound.
public :
ClientListItem ( C4PlayerInfoListBox * pForListBox , const C4ClientCore & rClientInfo , ListItem * pInsertBefore ) ; // ctor
2017-05-07 11:50:00 +00:00
~ ClientListItem ( ) override = default ; // dtor
2010-03-28 17:58:21 +00:00
void SetColor ( DWORD dwToClr ) // update color of client name label
{ pNameLabel - > SetColor ( ( dwClientClr = dwToClr ) | C4GUI_MessageFontAlpha ) ; }
void SetStatus ( C4GUI : : Icons icoNewStatus ) // set new status
{ pStatusIcon - > SetIcon ( icoNewStatus ) ; }
void SetPing ( int32_t iToPing ) ; // update ping label; iToPing=-1 removes the label
void UpdateCore ( const C4ClientCore & rCore ) ; // core update: re-set name and indicate whether active or not
void SetSoundIcon ( ) ; // sets the sound icon as current icon and schedules reset after some time
// spacing inserted between two client list items
2017-05-07 11:50:00 +00:00
int32_t GetListItemTopSpacing ( ) override { return ClientListBoxSpacing ; }
bool GetListItemTopSpacingBar ( ) override { return true ; }
2010-03-28 17:58:21 +00:00
public :
void Init ( const C4ClientCore & rClientInfo ) ; // init members
void UpdateInfo ( ) ; // update for changed player info
DWORD GetColor ( ) const { return dwClientClr ; } // client chat color
C4Client * GetClient ( ) const ; // get client associated with this list item
bool IsLocalClientPlayer ( ) const ; // whether this player is going to join locally
C4GUI : : Icons GetCurrentStatusIcon ( ) ; // get status icon that shows the current client state
2016-11-02 23:58:02 +00:00
class C4Network2Client * GetNetClient ( ) const ; // return assicuated network client; nullptr for local
2010-03-28 17:58:21 +00:00
bool IsLocal ( ) const ;
2017-05-07 11:50:00 +00:00
void Update ( ) override { UpdatePing ( ) ; UpdateInfo ( ) ; }
2010-03-28 17:58:21 +00:00
void UpdatePing ( ) ; // update ping label
C4GUI : : ContextMenu * OnContext ( C4GUI : : Element * pListItem , int32_t iX , int32_t iY ) ; // open context menu
void OnCtxKick ( C4GUI : : Element * pListItem ) ; // kick item selected in client ctx menu
void OnCtxActivate ( C4GUI : : Element * pListItem ) ; // toggle player/observer
void OnCtxInfo ( C4GUI : : Element * pListItem ) ; // show info dlg (modal)
2010-03-28 19:33:51 +00:00
void OnCtxIgnore ( C4GUI : : Element * pListItem ) ;
2010-03-28 17:58:21 +00:00
void OnBtnAddPlr ( C4GUI : : Control * btn ) ;
} ;
2009-05-08 13:28:41 +00:00
// team label
class TeamListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pIcon ;
C4GUI : : Label * pNameLabel ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
int32_t idTeam ; // team ID
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
2017-05-07 11:50:00 +00:00
void UpdateOwnPos ( ) override ; // recalculate item positioning
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
TeamListItem ( C4PlayerInfoListBox * pForListBox , int32_t idTeam , ListItem * pInsertBefore ) ; // ctor
2009-05-08 13:28:41 +00:00
2017-05-07 11:50:00 +00:00
void MouseInput ( C4GUI : : CMouse & rMouse , int32_t iButton , int32_t iX , int32_t iY , DWORD dwKeyParam ) override ; // input: mouse movement or buttons
2015-09-04 02:42:29 +00:00
2010-03-28 17:58:21 +00:00
// spacing inserted between of those list items; usually this is top anyway...
2017-05-07 11:50:00 +00:00
bool GetListItemTopSpacingBar ( ) override { return true ; }
int32_t GetListItemTopSpacing ( ) override { return ClientListBoxSpacing ; }
2009-05-08 13:28:41 +00:00
2017-05-07 11:50:00 +00:00
void Update ( ) override ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
private :
void MoveLocalPlayersIntoTeam ( ) ; // move all local players into team marked by this label
} ;
2009-05-08 13:28:41 +00:00
// list of unassigned savegame recreation players
class FreeSavegamePlayersListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pIcon ;
C4GUI : : Label * pNameLabel ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
FreeSavegamePlayersListItem ( C4PlayerInfoListBox * pForListBox , ListItem * pInsertBefore ) ; // ctor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// spacing inserted between of those list items; usually this is top anyway...
virtual bool ListItemTopSpacingBar ( ) { return true ; }
2017-05-07 11:50:00 +00:00
int32_t GetListItemTopSpacing ( ) override { return ClientListBoxSpacing ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
2017-05-07 11:50:00 +00:00
void Update ( ) override ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
// list of script players (both savegame recreation and regular)
class ScriptPlayersListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pIcon ;
C4GUI : : Label * pNameLabel ;
C4GUI : : IconButton * btnAddPlayer ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
ScriptPlayersListItem ( C4PlayerInfoListBox * pForListBox , ListItem * pInsertBefore ) ; // ctor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// spacing inserted between of those list items; usually this is top anyway...
virtual bool ListItemTopSpacingBar ( ) { return true ; }
2017-05-07 11:50:00 +00:00
int32_t GetListItemTopSpacing ( ) override { return ClientListBoxSpacing ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
void OnBtnAddPlr ( C4GUI : : Control * btn ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
2017-05-07 11:50:00 +00:00
void Update ( ) override ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
// list of players in record (currently not used, because replays in network are not allowed :C)
class ReplayPlayersListItem : public ListItem
2010-03-28 17:58:21 +00:00
{
private :
// subcomponents
C4GUI : : Icon * pIcon ;
C4GUI : : Label * pNameLabel ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
ReplayPlayersListItem ( C4PlayerInfoListBox * pForListBox , ListItem * pInsertBefore ) ; // ctor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
// spacing inserted between of those list items; usually this is top anyway...
2017-05-07 11:50:00 +00:00
bool GetListItemTopSpacingBar ( ) override { return true ; }
int32_t GetListItemTopSpacing ( ) override { return ClientListBoxSpacing ; }
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
// -----------------------------------------------------------------------------------------------
2010-03-28 17:58:21 +00:00
private :
Mode eMode ;
int32_t iMaxUncollapsedPlayers ; // maximum number of players that can be displayed without collapse - valid only if fIsCollapsed
bool fIsCollapsed ;
int32_t iTeamFilter ; // if nonzero, only playeers of this team are shown in the listbox
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
uint32_t dwTextColor ;
CStdFont * pCustomFont ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
enum AddMode
{
AM_Winners ,
AM_Losers ,
AM_All
} ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void UpdateSavegamePlayers ( ListItem * * ppCurrInList ) ;
void UpdateReplayPlayers ( ListItem * * ppCurrInList ) ;
void UpdateScriptPlayers ( ListItem * * ppCurrInList ) ;
void UpdatePlayersByTeam ( ListItem * * ppCurrInList ) ;
void UpdatePlayersByRandomTeam ( ListItem * * ppCurrInList ) ;
void UpdatePlayersByClient ( ListItem * * ppCurrInList ) ;
void UpdatePlayersByEvaluation ( ListItem * * ppCurrInList , bool fShowWinners ) ;
void UpdatePlayersByEvaluation ( ListItem * * ppCurrInList , C4Team * pTeam , AddMode eAddMode ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
ListItem * GetPlayerListItem ( ListItem : : ID : : IDType eType , int32_t id ) ; // search for a player list item
bool PlrListItemUpdate ( ListItem : : ID : : IDType eType , int32_t id , class ListItem * * pEnsurePos ) ; // search for player list item with given ID in the list starting at ensurepos; ensure it's positioned at given pos; update and return true if found
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
bool IsEvaluation ( ) const { return eMode = = PILBM_Evaluation | | eMode = = PILBM_EvaluationNoWinners ; }
bool IsLobby ( ) const { return eMode = = PILBM_LobbyClientSort | | eMode = = PILBM_LobbyTeamSort ; }
bool IsTeamFilter ( ) const { return ! ! iTeamFilter ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
protected :
bool IsPlayerItemCollapsed ( PlayerListItem * pItem ) ; // CB from list item: return true if it should be shown small
void OnPlrListSelChange ( class C4GUI : : Element * pEl ) { Update ( ) ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
uint32_t GetTextColor ( ) const { return dwTextColor ; }
CStdFont * GetCustomFont ( ) const { return pCustomFont ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
C4PlayerInfoListBox ( const C4Rect & rcBounds , Mode eMode , int32_t iTeamFilter = 0 ) ;
2017-05-07 11:50:00 +00:00
~ C4PlayerInfoListBox ( ) override = default ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void Update ( ) ; // update player list
void SetClientSoundIcon ( int32_t iForClientID ) ;
void SetMode ( Mode eNewMode ) ;
void SetTeamFilter ( int32_t idNewTeamFilter ) { iTeamFilter = idNewTeamFilter ; }
void SetCustomFont ( CStdFont * pNewFont , uint32_t dwTextColor ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
Mode GetMode ( ) const { return eMode ; }
2009-05-08 13:28:41 +00:00
friend class PlayerListItem ;
friend class TeamListItem ;
2010-03-28 17:58:21 +00:00
} ;
2009-05-08 13:28:41 +00:00
# endif // INC_C4PlayerInfoListBox