OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GameLobby.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // the ingame-lobby
17 
18 #ifndef INC_C4GameLobby
19 #define INC_C4GameLobby
20 
21 #include "gui/C4Gui.h"
22 #include "network/C4PacketBase.h"
23 
24 namespace C4GameLobby
25 {
26  // countdown time from which the elevator sound starts and team selection becomes unavailable
27  const int32_t AlmostStartCountdownTime = 10; // seconds
28 
29  extern bool UserAbort;
30 
31  // * PID_LobbyCountdown
32  // initiates or aborts countdown
34  {
35  private:
36  int32_t iCountdown; // countdown timer, or zero for abort
37  public:
38  enum { Abort = -1 };
39 
40  C4PacketCountdown(int32_t iaCountdown) : iCountdown(iaCountdown) { } // ctor
41  C4PacketCountdown() : iCountdown(Abort) { } // std ctor
42 
43  bool IsAbort() const { return iCountdown == Abort; }
44  int32_t GetCountdown() const { return iCountdown; }
45  StdStrBuf GetCountdownMsg(bool fInitialMsg=false) const;
46 
47  virtual void CompileFunc(StdCompiler *pComp);
48  };
49 
51  {
52  private:
53  StdCopyStrBuf ID;
54  int32_t Value;
55  public:
56  C4PacketSetScenarioParameter(const char *id, int32_t v) : ID(id), Value(v) {} // ctor
57  C4PacketSetScenarioParameter() : Value(0) {} // std ctor
58 
59  const char *GetID() const { return ID.getData(); }
60  int32_t GetValue() const { return Value; }
61 
62  virtual void CompileFunc(StdCompiler *pComp);
63  };
64 
65  // scneario info tab: displays scenario description
67  {
68  private:
69  C4GUI::Label *pTitle; // scenario title or warning label if unloaded
70  C4GUI::TextWindow *pDescBox; // scenario description box
71  bool fDescFinished; // if set, scenario resource has been loaded
72 
73  void Update();
74 
75  public:
76  ScenDesc(const C4Rect &rcBounds, bool fActive); // ctor
78 
79  void OnSec1Timer() { Update(); }
80  // activate/deactivate periodic updates
81  void Activate();
82  void Deactivate();
83  };
84 
86  {
87  private:
88  time_t tLastPingUpdate; // time when pings were updated last time
89  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.)
90  int32_t iBackBufferIndex; // chat message history index
91  C4KeyBinding *pKeyHistoryUp, *pKeyHistoryDown; // keys used to scroll through chat history
92 
93  enum { SheetIdx_PlayerList = 0, SheetIdx_Res = 1, SheetIdx_Options = 2, SheetIdx_Scenario = 3 };
94  C4PlayerInfoListBox *pPlayerList;
95  C4Network2ResDlg *pResList;
96  C4GameOptionButtons *pGameOptionButtons;
97  C4GameOptionsList *pOptionsList;
98  ScenDesc *pScenarioInfo;
99  C4GUI::TextWindow *pChatBox;
100  C4GUI::Label *pRightTabLbl;
101  C4GUI::Tabular *pRightTab;
102  C4GUI::Edit *pEdt; // chat input
103  C4GUI::CallbackButton<MainDlg> *btnRun; // host only
104  C4GUI::CallbackButton<MainDlg, C4GUI::IconButton> *btnPlayers, *btnResources, *btnTeams, *btnOptions, *btnScenario, *btnChat; // right list sheet selection
105  C4GUI::CheckBox *checkReady;
106 
107  protected:
108  void OnReadyCheck(C4GUI::Element *pCheckBox); // callback: checkbox ticked
109  void OnRunBtn(C4GUI::Control *btn); // callback: run button pressed
110  void OnExitBtn(C4GUI::Control *btn); // callback: exit button pressed
111  bool KeyHistoryUpDown(bool fUp); // key callback
112  C4GUI::Edit::InputResult OnChatInput(C4GUI::Edit *edt, bool fPasting, bool fPastingMore); // callback: chat input performed
113 
114  void OnClosed(bool fOK); // callback when dlg is closed
115  void OnSec1Timer(); // timer proc; update pings
116 
117  C4GUI::ContextMenu *OnRightTabContext(C4GUI::Element *pLabel, int32_t iX, int32_t iY); // open context menu
118  void OnCtxTabPlayers(C4GUI::Element *pListItem) { OnTabPlayers(nullptr); }
119  void OnTabPlayers(C4GUI::Control *btn);
120  void OnCtxTabTeams(C4GUI::Element *pListItem) { OnTabTeams(nullptr); }
121  void OnTabTeams(C4GUI::Control *btn);
122  void OnCtxTabRes(C4GUI::Element *pListItem) { OnTabRes(nullptr); }
123  void OnTabRes(C4GUI::Control *btn);
124  void OnCtxTabOptions(C4GUI::Element *pListItem) { OnTabOptions(nullptr); }
125  void OnTabOptions(C4GUI::Control *btn);
126  void OnCtxTabScenario(C4GUI::Element *pListItem) { OnTabScenario(nullptr); }
127  void OnTabScenario(C4GUI::Control *btn);
128  void UpdateRightTab(); // update label and tooltips for sheet change
129  void OnBtnChat(C4GUI::Control *btn);
130 
131  virtual class C4GUI::Control *GetDefaultControl() { return pEdt; } // def focus chat input
132 
133  private:
134  void SetCountdownState(CountdownState eToState, int32_t iTimer);
135  int32_t ValidatedCountdownTime(int32_t iTimeout); // correct invalid timeout settings
136 
137  void UpdatePlayerList();
138 
139  public:
140  MainDlg(bool fHost); // ctor
141  ~MainDlg(); // dtor
142 
143  // callback by network system
144  void OnClientJoin(C4Client *pNewClient); // called when a new client joined (connection not necessarily ready)
145  void OnClientConnect(C4Client *pClient, C4Network2IOConnection *pConn); // called when new clinet connection is established (notice of lobby status)
146  void OnClientPart(C4Client *pPartClient); // called when a client disconnects
147  bool OnMessage(C4Client *pOfClient, const char *szMessage); // display message in chat window
148  void OnClientSound(C4Client *pOfClient); // show that someone played a sound
149  void OnLog(const char *szLogMsg, DWORD dwClr=C4GUI_LogFontClr); // log callback
150  void OnError(const char *szErrMsg); // error sound + log in red
151  void OnPlayersChange() { UpdatePlayerList(); }
152  void OnClientReadyStateChange() { UpdatePlayerList(); }
153  void OnClientAddPlayer(const char *szFilename, int32_t idClient);
154  // packet callbacks from C4Network2
155  void HandlePacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2Client *pClient);
156  void OnCountdownPacket(const C4PacketCountdown &Pkt); // called when a countdown packet is received: Update countdown state
157 
158  bool IsCountdown();
159  void Start(int32_t iCountdownTime); // host only: Do game start with specified countdown time (forwards to network system)
160  void UpdatePassword();
161  void ClearLog();
162  };
163 
164  // helper
165  void LobbyError(const char *szErrorMsg);
166 
167  // lobby countdown: Moves game from lobby to go state. Only created by host.
169  {
170  private:
171  int32_t iStartTimer; // countdown timer for round start; 0 for not started, -1 for start overdue
172 
173  public:
174  void OnSec1Timer(); // timer proc; count down; send important countdown packets
175 
176  public:
177  Countdown(int32_t iStartTimer); // ctor: Init; sends initial countdown packet
178  ~Countdown();
179 
180  void Abort();
181  };
182 
183 }
184 
185 #endif
const char * getData() const
Definition: StdBuf.h:450
virtual void CompileFunc(StdCompiler *pComp)
Definition: C4GameLobby.cpp:41
bool fHost
Definition: TstC4NetIO.cpp:34
void OnClientPart(C4Client *pPartClient)
#define C4GUI_LogFontClr
Definition: C4Gui.h:51
C4GUI::Edit::InputResult OnChatInput(C4GUI::Edit *edt, bool fPasting, bool fPastingMore)
bool KeyHistoryUpDown(bool fUp)
void OnClientJoin(C4Client *pNewClient)
ScenDesc(const C4Rect &rcBounds, bool fActive)
Definition: C4GameLobby.cpp:65
void OnClosed(bool fOK)
void OnCtxTabScenario(C4GUI::Element *pListItem)
Definition: C4GameLobby.h:126
void HandlePacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2Client *pClient)
void OnCountdownPacket(const C4PacketCountdown &Pkt)
Definition: C4Rect.h:29
void OnLog(const char *szLogMsg, DWORD dwClr=C4GUI_LogFontClr)
bool fOK
Definition: C4Gui.h:2082
void OnClientAddPlayer(const char *szFilename, int32_t idClient)
void LobbyError(const char *szErrorMsg)
bool OnMessage(C4Client *pOfClient, const char *szMessage)
void OnClientSound(C4Client *pOfClient)
void OnCtxTabPlayers(C4GUI::Element *pListItem)
Definition: C4GameLobby.h:118
C4Rect rcBounds
Definition: C4Gui.h:385
void OnRunBtn(C4GUI::Control *btn)
void OnCtxTabRes(C4GUI::Element *pListItem)
Definition: C4GameLobby.h:122
void OnTabRes(C4GUI::Control *btn)
void OnError(const char *szErrMsg)
void OnTabScenario(C4GUI::Control *btn)
void Start(int32_t iCountdownTime)
void OnReadyCheck(C4GUI::Element *pCheckBox)
C4PacketCountdown(int32_t iaCountdown)
Definition: C4GameLobby.h:40
int32_t GetCountdown() const
Definition: C4GameLobby.h:44
C4GUI::ContextMenu * OnRightTabContext(C4GUI::Element *pLabel, int32_t iX, int32_t iY)
void OnClientConnect(C4Client *pClient, C4Network2IOConnection *pConn)
void OnTabTeams(C4GUI::Control *btn)
void OnClientReadyStateChange()
Definition: C4GameLobby.h:152
void OnCtxTabOptions(C4GUI::Element *pListItem)
Definition: C4GameLobby.h:124
StdStrBuf GetCountdownMsg(bool fInitialMsg=false) const
Definition: C4GameLobby.cpp:46
Countdown(int32_t iStartTimer)
void OnTabOptions(C4GUI::Control *btn)
C4PacketSetScenarioParameter(const char *id, int32_t v)
Definition: C4GameLobby.h:56
void OnTabPlayers(C4GUI::Control *btn)
void OnBtnChat(C4GUI::Control *btn)
void OnCtxTabTeams(C4GUI::Element *pListItem)
Definition: C4GameLobby.h:120
void OnExitBtn(C4GUI::Control *btn)
virtual void CompileFunc(StdCompiler *pComp)
Definition: C4GameLobby.cpp:56
uint32_t DWORD
const int32_t AlmostStartCountdownTime
Definition: C4GameLobby.h:27
virtual class C4GUI::Control * GetDefaultControl()
Definition: C4GameLobby.h:131