2009-05-08 13:28:41 +00:00
/*
* OpenClonk , http : //www.openclonk.org
*
2013-12-17 20:01:09 +00:00
* Copyright ( c ) 2001 - 2009 , RedWolf Design GmbH , http : //www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright ( c ) 2013 - 2016 , The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* Distributed under the terms of the ISC license ; see accompanying file
* " COPYING " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* " Clonk " is a registered trademark of Matthes Bender , used with permission .
* See accompanying file " TRADEMARK " for details .
2009-05-08 13:28:41 +00:00
*
2013-12-17 20:01:09 +00:00
* To redistribute this file separately , substitute the full license texts
* for the above references .
2009-05-08 13:28:41 +00:00
*/
// the ingame-lobby
# ifndef INC_C4GameLobby
# define INC_C4GameLobby
2016-04-03 18:07:56 +00:00
# include "gui/C4Gui.h"
# include "network/C4PacketBase.h"
2009-05-08 13:28:41 +00:00
namespace C4GameLobby
2010-03-28 17:58:21 +00:00
{
2009-05-08 13:28:41 +00:00
// countdown time from which the elevator sound starts and team selection becomes unavailable
const int32_t AlmostStartCountdownTime = 10 ; // seconds
extern bool UserAbort ;
// * PID_LobbyCountdown
// initiates or aborts countdown
class C4PacketCountdown : public C4PacketBase
2010-03-28 17:58:21 +00:00
{
private :
int32_t iCountdown ; // countdown timer, or zero for abort
public :
enum { Abort = - 1 } ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
C4PacketCountdown ( int32_t iaCountdown ) : iCountdown ( iaCountdown ) { } // ctor
C4PacketCountdown ( ) : iCountdown ( Abort ) { } // std ctor
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
bool IsAbort ( ) const { return iCountdown = = Abort ; }
int32_t GetCountdown ( ) const { return iCountdown ; }
StdStrBuf GetCountdownMsg ( bool fInitialMsg = false ) const ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
virtual void CompileFunc ( StdCompiler * pComp ) ;
} ;
2009-05-08 13:28:41 +00:00
2014-09-23 21:02:03 +00:00
class C4PacketSetScenarioParameter : public C4PacketBase
{
private :
StdCopyStrBuf ID ;
int32_t Value ;
public :
C4PacketSetScenarioParameter ( const char * id , int32_t v ) : ID ( id ) , Value ( v ) { } // ctor
C4PacketSetScenarioParameter ( ) : Value ( 0 ) { } // std ctor
const char * GetID ( ) const { return ID . getData ( ) ; }
int32_t GetValue ( ) const { return Value ; }
virtual void CompileFunc ( StdCompiler * pComp ) ;
} ;
2009-05-08 13:28:41 +00:00
// scneario info tab: displays scenario description
class ScenDesc : public C4GUI : : Window , private C4ApplicationSec1Timer
2010-03-28 17:58:21 +00:00
{
private :
C4GUI : : Label * pTitle ; // scenario title or warning label if unloaded
C4GUI : : TextWindow * pDescBox ; // scenario description box
bool fDescFinished ; // if set, scenario resource has been loaded
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void Update ( ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
ScenDesc ( const C4Rect & rcBounds , bool fActive ) ; // ctor
~ ScenDesc ( ) { Deactivate ( ) ; }
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void OnSec1Timer ( ) { Update ( ) ; }
// activate/deactivate periodic updates
void Activate ( ) ;
void Deactivate ( ) ;
} ;
2009-05-08 13:28:41 +00:00
class MainDlg : public C4GUI : : FullscreenDialog , private C4ApplicationSec1Timer
2010-03-28 17:58:21 +00:00
{
private :
time_t tLastPingUpdate ; // time when pings were updated last time
enum CountdownState { CDS_None = 0 , CDS_LongCountdown = 1 , CDS_Countdown = 2 , CDS_Start = 3 } eCountdownState ; // nonzero when a packet was received that the game is about to start (starts elevator sound, etc.)
int32_t iBackBufferIndex ; // chat message history index
C4KeyBinding * pKeyHistoryUp , * pKeyHistoryDown ; // keys used to scroll through chat history
enum { SheetIdx_PlayerList = 0 , SheetIdx_Res = 1 , SheetIdx_Options = 2 , SheetIdx_Scenario = 3 } ;
C4PlayerInfoListBox * pPlayerList ;
C4Network2ResDlg * pResList ;
C4GameOptionButtons * pGameOptionButtons ;
C4GameOptionsList * pOptionsList ;
ScenDesc * pScenarioInfo ;
C4GUI : : TextWindow * pChatBox ;
C4GUI : : Label * pRightTabLbl ;
C4GUI : : Tabular * pRightTab ;
C4GUI : : Edit * pEdt ; // chat input
C4GUI : : CallbackButton < MainDlg > * btnRun ; // host only
C4GUI : : CallbackButton < MainDlg , C4GUI : : IconButton > * btnPlayers , * btnResources , * btnTeams , * btnOptions , * btnScenario , * btnChat ; // right list sheet selection
2015-11-19 03:49:59 +00:00
C4GUI : : CheckBox * checkReady ;
2010-03-28 17:58:21 +00:00
protected :
2015-11-19 03:49:59 +00:00
void OnReadyCheck ( C4GUI : : Element * pCheckBox ) ; // callback: checkbox ticked
2010-03-28 17:58:21 +00:00
void OnRunBtn ( C4GUI : : Control * btn ) ; // callback: run button pressed
void OnExitBtn ( C4GUI : : Control * btn ) ; // callback: exit button pressed
bool KeyHistoryUpDown ( bool fUp ) ; // key callback
C4GUI : : Edit : : InputResult OnChatInput ( C4GUI : : Edit * edt , bool fPasting , bool fPastingMore ) ; // callback: chat input performed
void OnClosed ( bool fOK ) ; // callback when dlg is closed
void OnSec1Timer ( ) ; // timer proc; update pings
C4GUI : : ContextMenu * OnRightTabContext ( C4GUI : : Element * pLabel , int32_t iX , int32_t iY ) ; // open context menu
2016-11-02 23:58:02 +00:00
void OnCtxTabPlayers ( C4GUI : : Element * pListItem ) { OnTabPlayers ( nullptr ) ; }
2010-03-28 17:58:21 +00:00
void OnTabPlayers ( C4GUI : : Control * btn ) ;
2016-11-02 23:58:02 +00:00
void OnCtxTabTeams ( C4GUI : : Element * pListItem ) { OnTabTeams ( nullptr ) ; }
2010-03-28 17:58:21 +00:00
void OnTabTeams ( C4GUI : : Control * btn ) ;
2016-11-02 23:58:02 +00:00
void OnCtxTabRes ( C4GUI : : Element * pListItem ) { OnTabRes ( nullptr ) ; }
2010-03-28 17:58:21 +00:00
void OnTabRes ( C4GUI : : Control * btn ) ;
2016-11-02 23:58:02 +00:00
void OnCtxTabOptions ( C4GUI : : Element * pListItem ) { OnTabOptions ( nullptr ) ; }
2010-03-28 17:58:21 +00:00
void OnTabOptions ( C4GUI : : Control * btn ) ;
2016-11-02 23:58:02 +00:00
void OnCtxTabScenario ( C4GUI : : Element * pListItem ) { OnTabScenario ( nullptr ) ; }
2010-03-28 17:58:21 +00:00
void OnTabScenario ( C4GUI : : Control * btn ) ;
void UpdateRightTab ( ) ; // update label and tooltips for sheet change
void OnBtnChat ( C4GUI : : Control * btn ) ;
virtual class C4GUI : : Control * GetDefaultControl ( ) { return pEdt ; } // def focus chat input
private :
void SetCountdownState ( CountdownState eToState , int32_t iTimer ) ;
int32_t ValidatedCountdownTime ( int32_t iTimeout ) ; // correct invalid timeout settings
void UpdatePlayerList ( ) ;
public :
MainDlg ( bool fHost ) ; // ctor
~ MainDlg ( ) ; // dtor
// callback by network system
void OnClientJoin ( C4Client * pNewClient ) ; // called when a new client joined (connection not necessarily ready)
void OnClientConnect ( C4Client * pClient , C4Network2IOConnection * pConn ) ; // called when new clinet connection is established (notice of lobby status)
void OnClientPart ( C4Client * pPartClient ) ; // called when a client disconnects
bool OnMessage ( C4Client * pOfClient , const char * szMessage ) ; // display message in chat window
void OnClientSound ( C4Client * pOfClient ) ; // show that someone played a sound
void OnLog ( const char * szLogMsg , DWORD dwClr = C4GUI_LogFontClr ) ; // log callback
void OnError ( const char * szErrMsg ) ; // error sound + log in red
void OnPlayersChange ( ) { UpdatePlayerList ( ) ; }
2015-11-22 04:58:15 +00:00
void OnClientReadyStateChange ( ) { UpdatePlayerList ( ) ; }
2010-03-28 17:58:21 +00:00
void OnClientAddPlayer ( const char * szFilename , int32_t idClient ) ;
// packet callbacks from C4Network2
void HandlePacket ( char cStatus , const C4PacketBase * pBasePkt , C4Network2Client * pClient ) ;
void OnCountdownPacket ( const C4PacketCountdown & Pkt ) ; // called when a countdown packet is received: Update countdown state
bool IsCountdown ( ) ;
2012-11-30 21:07:08 +00:00
void Start ( int32_t iCountdownTime ) ; // host only: Do game start with specified countdown time (forwards to network system)
2010-03-28 17:58:21 +00:00
void UpdatePassword ( ) ;
void ClearLog ( ) ;
} ;
2009-05-08 13:28:41 +00:00
// helper
void LobbyError ( const char * szErrorMsg ) ;
// lobby countdown: Moves game from lobby to go state. Only created by host.
class Countdown : private C4ApplicationSec1Timer
2010-03-28 17:58:21 +00:00
{
private :
int32_t iStartTimer ; // countdown timer for round start; 0 for not started, -1 for start overdue
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
void OnSec1Timer ( ) ; // timer proc; count down; send important countdown packets
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
public :
Countdown ( int32_t iStartTimer ) ; // ctor: Init; sends initial countdown packet
~ Countdown ( ) ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
void Abort ( ) ;
} ;
2009-05-08 13:28:41 +00:00
2010-03-28 17:58:21 +00:00
}
2009-05-08 13:28:41 +00:00
# endif