OpenClonk
C4Network2Dialogs.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2004-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-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 // dialogs for network information
17 
18 #ifndef INC_C4Network2Dialogs
19 #define INC_C4Network2Dialogs
20 
21 #include "gui/C4Gui.h"
22 
23 #include "landscape/C4Scenario.h"
24 #include "network/C4Network2Res.h"
25 
26 class C4Graph;
27 
28 // dialog showing info about a connected client
30 {
31 protected:
32  int iClientID; // ID of client info is shown about
33 
34 protected:
35  void UpdateText() override; // compose message text
36  virtual int GetUpdateInterval() { return 500; } // update every 0.5 seconds
37 
38  const char *GetID() override { return "ClientDialog"; }
39 
40 public:
41  C4Network2ClientDlg(int iForClientID); // ctor
42 };
43 
44 // resource dialog: created as listbox inside another dialog
46 {
47 public:
48  enum { IconLabelSpacing = 2 }; // space between an icon and its text
49 
50 private:
51  class ListItem : public C4GUI::Window
52  {
53  private:
54  // subcomponents
55  C4GUI::Icon *pFileIcon; // icon indicating file type
56  C4GUI::Label *pLabel; // label indicating file name
57  C4GUI::Label *pProgress; // label indicating file progress
58  C4GUI::IconButton *pSaveBtn; // file save button
59  int iResID, iProgress;
60 
61  void LocalSaveResource(bool fDoOverwrite); // called by OnButtonSave*: queried local saving of resource
62 
63  public:
64  ListItem(class C4Network2ResDlg *pForResDlg, const class C4Network2Res *pByRes); // ctor
65 
66  void Update(const class C4Network2Res *pByRes); // update data
67 
68  int GetResID() const { return iResID; }
69  bool IsSavePossible();
70 
71  C4GUI::ContextMenu *OnContext(C4GUI::Element *pListItem, int iX, int iY); // open context menu
72  void OnButtonSave(C4GUI::Control *pButton); // queried resource save
73  void OnButtonSaveConfirm(C4GUI::Element *pNull); // confirmed file overwrite
74 
75  C4Network2Res::Ref GetRefRes(); // get associated resource
76  };
77 
78 public:
79  C4Network2ResDlg(const C4Rect &rcBounds, bool fActive);
80  ~C4Network2ResDlg() override { Deactivate(); }
81 
82  // enable/disable updates by timer calls
83  void Activate(); void Deactivate();
84 
85  // update by resources
86  void OnSec1Timer() override { Update(); }
87  void Update();
88 };
89 
90 // client list dialog: created as listbox inside another dialog
92 {
93 public:
94  enum {
96  SoundIconShowTime = 1 // seconds. min time a sound icon is shown}; // space between an icon and its text
97  };
98 
99 private:
100  class ListItem : public C4GUI::Window
101  {
102  protected:
103  int32_t iClientID;
104  C4Network2ClientListBox *pForDlg;
105 
106  public:
107  ListItem(class C4Network2ClientListBox *pForDlg, int32_t iClientID) // ctor
108  : iClientID(iClientID), pForDlg(pForDlg) {}
109 
110  virtual void Update() = 0;
111  int32_t GetClientID() const { return iClientID; }
112  virtual int32_t GetConnectionID() const { return -1; }
113  };
114 
115  class ClientListItem : public ListItem
116  {
117  private:
118  // subcomponents
119  C4GUI::Icon *pStatusIcon; // client network status
120  C4GUI::Label *pName; // client name
121  C4GUI::Label *pPing; // client control ping
122  C4GUI::IconButton *pActivateBtn, *pKickBtn; // buttons for host
123  bool fShownActive;
124  time_t last_sound_time; // now() when the client last issued a sound (display as sound icon). 0 for no sound.
125 
126  public:
127  ClientListItem(class C4Network2ClientListBox *pForDlg, int iClientID); // ctor
128 
129  void Update() override; // update data
130  const C4Client *GetClient() const; // get client by associated ID
131 
132  void OnButtonActivate(C4GUI::Control *pButton);
133  void OnButtonKick(C4GUI::Control *pButton);
134 
135  void SetSoundIcon();
136  };
137 
138  class ConnectionListItem : public ListItem
139  {
140  private:
141  int32_t iConnID; // connection ID
142  // subcomponents
143  C4GUI::Label *pDesc; // connection description
144  C4GUI::Label *pPing; // connection ping
145  C4GUI::IconButton *pDisconnectBtn; // button to destroy connection
146 
147  public:
148  ConnectionListItem(class C4Network2ClientListBox *pForDlg, int32_t iClientID, int32_t iConnectionID); // ctor
149 
150  void Update() override; // update data
151  C4Network2IOConnection *GetConnection() const; // get connection by connection ID
152  int32_t GetConnectionID() const override { return iConnID; }
153 
154  void OnButtonReconnect(C4GUI::Control *pButton);
155  void OnButtonDisconnect(C4GUI::Control *pButton);
156  };
157 
158 private:
159  bool fStartup;
160 
161  ClientListItem *GetClientListItem(int32_t iForClientID);
162 
163 public:
164  C4Network2ClientListBox(C4Rect &rcBounds, bool fStartup);
165  ~C4Network2ClientListBox() override;
166 
167  // update by client list
168  void OnSec1Timer() override { Update(); }
169  void Update();
170 
171  bool IsStartup() { return fStartup; }
172 
173  void SetClientSoundIcon(int32_t client_id);
174 };
175 
176 // dialog framing the C4Network2ClientListBox and a game option list and a status label
178 {
179 private:
180  class C4GameOptionsList *pGameOptions;
181  C4GUI::Label *pStatusLabel;
182  C4Network2ClientListBox *pListBox;
183 
184  static C4Network2ClientListDlg *pInstance; // singleton-instance
185 
186  const char *GetID() override { return "ClientListDialog"; }
187 public:
189  ~C4Network2ClientListDlg() override;
190 
191  void OnSec1Timer() override { Update(); }
192  void Update();
193  void OnSound(class C4Client *singer); // mark the specified client
194 
195  static bool Toggle(); // toggle dlg on/off
196  static C4Network2ClientListDlg *GetInstance() { return pInstance; }
197 };
198 
199 // host dialog shown at initial wait
201 {
202 private:
203  C4Network2ClientListBox *pClientListBox{nullptr};
204 
205  enum { DialogWidth = 250, DialogHeight = 300 };
206 
207 protected:
208  const char *GetID() override { return "NetStartWaitDialog"; }
209 
210 public:
212  ~C4Network2StartWaitDlg() override = default;
213 };
214 
215 // button area for some game options during lobby and scenario selection time
217 {
218 private:
219  C4GUI::IconButton *btnInternet, *btnLeague, *btnPassword, *btnComment, *btnRecord;
220  bool fNetwork, fHost, fLobby, fCountdown;
221 
222 public:
223  C4GameOptionButtons(const C4Rect &rcBounds, bool fNetwork, bool fHost, bool fLobby);
224  ~C4GameOptionButtons() override = default;
225 
226  void SetCountdown(bool fToVal);
227 protected:
228  void OnBtnInternet(C4GUI::Control *btn);
229  void OnBtnLeague(C4GUI::Control *btn);
230  void OnBtnRecord(C4GUI::Control *btn);
231  void OnBtnPassword(C4GUI::Control *btn);
232  void OnPasswordSet(const StdStrBuf &rsNewPassword);
233  void OnBtnComment(C4GUI::Control *btn);
234  void OnCommentSet(const StdStrBuf &rsNewComment);
235 
236 public:
237  void UpdatePasswordBtn();
238 };
239 
240 // graph display component
241 class C4Chart : public C4GUI::Element
242 {
243 protected:
245  bool fOwnGraph;
246 
247  void DrawElement(C4TargetFacet &cgo) override; // draw the chart
248 
249 public:
251  ~C4Chart() override;
252 
253  void SetGraph(const C4Graph *pNewGraph, bool fOwn) { pDisplayGraph = pNewGraph; fOwnGraph = fOwn; }
254 };
255 
256 // C4Chart framing dialog
258 {
259 private:
260  C4GUI::Tabular *pChartTabular{nullptr};
261 
262  // singleton-stuff
263  static C4ChartDialog *pChartDlg;
264 
265  enum { DialogWidth = 400, DialogHeight = 300 };
266 
267  void AddChart(const StdStrBuf &rszName);
268 
269 protected:
270  const char *GetID() override { return "ChartDialog"; }
271 
272 public:
273  C4ChartDialog();
274 
275  // singleton-stuff
276  ~C4ChartDialog() override { if (pChartDlg==this) pChartDlg = nullptr; }
277  static void Toggle();
278 };
279 
280 #endif // INC_C4Network2Dialogs
bool fHost
Definition: TstC4NetIO.cpp:31
static void Toggle()
~C4ChartDialog() override
const char * GetID() override
const C4Graph * pDisplayGraph
C4Chart(C4Rect &rcBounds)
void SetGraph(const C4Graph *pNewGraph, bool fOwn)
void DrawElement(C4TargetFacet &cgo) override
~C4Chart() override
C4Rect rcBounds
Definition: C4Gui.h:385
void OnBtnPassword(C4GUI::Control *btn)
void OnBtnRecord(C4GUI::Control *btn)
void OnBtnComment(C4GUI::Control *btn)
~C4GameOptionButtons() override=default
void OnBtnLeague(C4GUI::Control *btn)
void OnCommentSet(const StdStrBuf &rsNewComment)
void OnPasswordSet(const StdStrBuf &rsNewPassword)
C4GameOptionButtons(const C4Rect &rcBounds, bool fNetwork, bool fHost, bool fLobby)
void SetCountdown(bool fToVal)
void OnBtnInternet(C4GUI::Control *btn)
void UpdateText() override
C4Network2ClientDlg(int iForClientID)
virtual int GetUpdateInterval()
const char * GetID() override
C4Network2ClientListBox(C4Rect &rcBounds, bool fStartup)
void SetClientSoundIcon(int32_t client_id)
void OnSound(class C4Client *singer)
static C4Network2ClientListDlg * GetInstance()
~C4Network2ResDlg() override
C4Network2ResDlg(const C4Rect &rcBounds, bool fActive)
void OnSec1Timer() override
~C4Network2StartWaitDlg() override=default
const char * GetID() override
Definition: C4Rect.h:28