OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4StartupOptionsDlg.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2011-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 // Startup screen for non-parameterized engine start: Options dialog
17 
18 #ifndef INC_C4StartupOptionsDlg
19 #define INC_C4StartupOptionsDlg
20 
21 #include "gui/C4Startup.h"
22 
23 // startup dialog: Options
25 {
26  // main dlg stuff -----------------------------------------------------
27 public:
28  C4StartupOptionsDlg(); // ctor
29  ~C4StartupOptionsDlg(); // dtor
30 
31 private:
32  class C4KeyBinding *pKeyBack;
33  bool fConfigSaved; // set when config has been saved because dlg is closed; prevents double save
34  bool fCanGoBack; // set if dlg has not been recreated yet, in which case going back to a previous dialog is not possible
35  C4GUI::Tabular *pOptionsTabular;
36 
37 protected:
38  virtual bool OnEnter() { return false; } // Enter ignored
39  virtual bool OnEscape() { DoBack(); return true; }
40  bool KeyBack() { DoBack(); return true; }
41  virtual void OnClosed(bool fOK); // callback when dlg got closed - save config
42  virtual void UserClose(bool fOK) // callback when the user tried to close the dialog (e.g., by pressing Enter in an edit) - just ignore this and save config instead
43  { if (fOK) SaveConfig(false, true); }
44 
45  void OnBackBtn(C4GUI::Control *btn) { DoBack(); }
46 
47  bool SaveConfig(bool fForce, bool fKeepOpen); // save any config fields that are not stored directly; return whether all values are OK
48 
49 public:
50  void DoBack(); // back to main menu
51 
52  virtual bool SetSubscreen(const char *szToScreen); // go to specified property sheet
53  virtual void OnKeyboardLayoutChanged(); // keyboard layout changed: update keys from scan codes
54 
55 public:
56  void RecreateDialog(bool fFade);
57 
58  // program tab --------------------------------------------------------
59 private:
60  // button without fancy background
61  class SmallButton : public C4GUI::Button
62  {
63  protected:
64  virtual void DrawElement(C4TargetFacet &cgo); // draw the button
65 
66  public:
67  SmallButton(const char *szText, const C4Rect &rtBounds) // ctor
68  : C4GUI::Button(szText, rtBounds) {}
69  static int32_t GetDefaultButtonHeight();
70  };
71 
72  class C4GUI::ComboBox *pLangCombo;
73  class C4GUI::Label *pLangInfoLabel;
74  class C4GUI::ComboBox *pFontFaceCombo, *pFontSizeCombo;
75 
76  void OnLangComboFill(C4GUI::ComboBox_FillCB *pFiller);
77  bool OnLangComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection);
78  void UpdateLanguage();
79  void OnFontFaceComboFill(C4GUI::ComboBox_FillCB *pFiller);
80  void OnFontSizeComboFill(C4GUI::ComboBox_FillCB *pFiller);
81  bool OnFontComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection);
82  void UpdateFontControls();
83  bool SetGameFont(const char *szFontFace, int32_t iFontSize);
84  void OnResetConfigBtn(C4GUI::Control *btn);
85 
86  // graphics tab -------------------------------------------------------
87 private:
88 
89  // checkbox that changes a config boolean directly
90  class BoolConfig : public C4GUI::CheckBox
91  {
92  private:
93  bool *pbVal, fInvert; int32_t *piVal, *piRestartChangeCfgVal;
94  protected:
95  void OnCheckChange(C4GUI::Element *pCheckBox);
96  public:
97  BoolConfig(const C4Rect &rcBounds, const char *szName, bool *pbVal, int32_t *piVal, bool fInvert=false, int32_t *piRestartChangeCfgVal=nullptr);
98  };
99  // editbox below descriptive label sharing one window for common tooltip
100  class EditConfig : public C4GUI::LabeledEdit
101  {
102  public:
103  EditConfig(const C4Rect &rcBounds, const char *szName, ValidatedStdCopyStrBufBase *psConfigVal, int32_t *piConfigVal, bool fMultiline);
104  private:
105  ValidatedStdCopyStrBufBase *psConfigVal;
106  int32_t *piConfigVal;
107  public:
108  void Save2Config(); // control to config
109  static bool GetControlSize(int *piWdt, int *piHgt, const char *szForText, bool fMultiline);
110  int32_t GetIntVal() { return atoi(GetEdit()->GetText()); }
111  void SetIntVal(int32_t iToVal) { GetEdit()->SetText(FormatString("%d", (int) iToVal).getData(), false); }
112  } *pNetworkNickEdit;
113  // message dialog with a timer; used to restore the resolution if the user didn't press anything for a while
114  class ResChangeConfirmDlg : public C4GUI::Dialog, private C4ApplicationSec1Timer
115  {
116  private:
117  C4GUI::Label *pOperationCancelLabel; int32_t iResChangeSwitchTime;
118  public:
119  ResChangeConfirmDlg();
120  ~ResChangeConfirmDlg();
121  void OnSec1Timer(); // update timer label
122  protected:
123  virtual bool OnEnter() { return true; } // Pressing Enter does not confirm this dialog, so "blind" users are less likely to accept their change
124  virtual const char *GetID() { return "ResChangeConfirmDialog"; }
125  };
126 
127  void OnWindowedModeComboFill(C4GUI::ComboBox_FillCB *pFiller);
128  bool OnWindowedModeComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection);
129  void OnGfxResComboFill(C4GUI::ComboBox_FillCB *pFiller);
130  bool OnGfxResComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection);
131  void OnGfxMSComboFill(C4GUI::ComboBox_FillCB *pFiller);
132  bool OnGfxMSComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection);
133  bool TryNewResolution(int32_t iResX, int32_t iResY, int32_t iRefreshRate);
134  StdStrBuf GetGfxResString(int32_t iResX, int32_t iResY); // convert resolution to string to be displayed in resolution choice combobox
135  const char * GetWindowedName(int32_t mode = -1);
136 
137  int32_t iGfxTexIndent;
138 
139  // sound tab ----------------------------------------------------------
140 private:
141  C4KeyBinding *pKeyToggleMusic; // extra key binding for music: Must also update checkbox in real-time
142  BoolConfig *pFESoundCheck;
143  C4GUI::CheckBox *pFEMusicCheck;
144 
145  void OnFEMusicCheck(C4GUI::Element *pCheckBox); // toggling frontend music is reflected immediately
146  void OnRXSoundCheck(C4GUI::Element *pCheckBox); // toggling sounds on off must init/deinit sound system
147  void OnMusicVolumeSliderChange(int32_t iNewVal);
148  void OnSoundVolumeSliderChange(int32_t iNewVal);
149 
150 protected:
151  bool KeyMusicToggle();
152 
153  // keyboard and gamepad control tabs ----------------------------------
154 private:
155  // dialog shown to user so he can select a key
156  class KeySelDialog : public C4GUI::MessageDialog
157  {
158  private:
159  class C4KeyBinding *pKeyListener;
160  C4KeyCodeEx key;
161  const class C4PlayerControlAssignment *assignment;
162  const class C4PlayerControlAssignmentSet *assignment_set;
163 
164  static StdStrBuf GetDlgMessage(const class C4PlayerControlAssignment *assignment, const class C4PlayerControlAssignmentSet *assignment_set);
165  static C4GUI::Icons GetDlgIcon(const class C4PlayerControlAssignmentSet *assignment_set);
166 
167  protected:
168  bool KeyDown(const C4KeyCodeEx &key);
169  public:
170  KeySelDialog(const class C4PlayerControlAssignment *assignment, const class C4PlayerControlAssignmentSet *assignment_set);
171  virtual ~KeySelDialog();
172 
173  C4KeyCodeEx GetKeyCode() { return key; }
174 
175  };
176 
177  // list box of definable keys
178  class ControlConfigListBox : public C4GUI::ListBox
179  {
180  private:
181  // assignment key label - change key on click
182  class ControlAssignmentLabel : public C4GUI::Label
183  {
184  private:
185  class C4PlayerControlAssignment *assignment; // pointer into assignment set (not owned!)
186  class C4PlayerControlAssignmentSet *assignment_set; // pointer to assignment set (not owned!)
187 
188  void UpdateAssignmentString();
189  public:
190  virtual void MouseInput(class C4GUI::CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam);
191 
192  ControlAssignmentLabel(class C4PlayerControlAssignment *assignment, class C4PlayerControlAssignmentSet *assignment_set, const C4Rect &bounds);
193  };
194 
195  // item in list box
196  class ListItem : public C4GUI::Window
197  {
198  private:
199  ControlConfigListBox *parent_list;
200  ControlAssignmentLabel *assignment_label;
201  bool has_extra_spacing; // if true, add a bit of spacing on top of this item to group elements
202 
203  virtual int32_t GetListItemTopSpacing() { return C4GUI::Window::GetListItemTopSpacing() + (has_extra_spacing*GetBounds().Hgt/2); }
204 
205  public:
206  ListItem(ControlConfigListBox *parent_list, class C4PlayerControlAssignment *assignment, class C4PlayerControlAssignmentSet *assignment_set, bool first_of_group);
207  };
208 
209  private:
210  class C4PlayerControlAssignmentSet *set; // assignment set being configured by this box
211  static bool sort_by_group (C4PlayerControlAssignment *i, C4PlayerControlAssignment *j) { return i->GetGUIGroup() < j->GetGUIGroup(); }
212 
213  public:
214  ControlConfigListBox(const C4Rect &rcBounds, class C4PlayerControlAssignmentSet *set);
215 
216  void SetAssignmentSet(class C4PlayerControlAssignmentSet *new_set);
217 
218  static void SetUserKey(class C4PlayerControlAssignmentSet *assignment_set, class C4PlayerControlAssignment *assignment, C4KeyCodeEx &key);
219  };
220 
221  // config area to define a keyboard set
222  class ControlConfigArea : public C4GUI::Window
223  {
224  private:
225  bool fGamepad; // if set, gamepad control sets are being configured
226  int32_t iMaxControlSets; // number of control sets configured in this area - must be smaller or equal to C4MaxControlSet
227  int32_t iSelectedCtrlSet; // keyboard or gamepad set that is currently being configured
228  class C4GUI::IconButton ** ppKeyControlSetBtns; // buttons to select configured control set - array in length of iMaxControlSets
229  class KeySelButton * KeyControlBtns[C4MaxKey]; // buttons to configure individual kbd set buttons
230  C4StartupOptionsDlg *pOptionsDlg;
231  ControlConfigListBox *control_list;
232  class C4GUI::CheckBox *pGUICtrl;
233  public:
234  ControlConfigArea(const C4Rect &rcArea, int32_t iHMargin, int32_t iVMargin, bool fGamepad, C4StartupOptionsDlg *pOptionsDlg);
235  virtual ~ControlConfigArea();
236 
237  void UpdateCtrlSet();
238 
239  protected:
240 
241  void OnCtrlSetBtn(C4GUI::Control *btn);
242  void OnResetKeysBtn(C4GUI::Control *btn);
243  void OnGUIGamepadCheckChange(C4GUI::Element *pCheckBox);
244  };
245 
246  ControlConfigArea *pControlConfigArea;
247 
248  class C4GamePadControl *GamePadCon;
249 
250  // network tab --------------------------------------------------------
251 private:
252  // checkbox to enable protocol and editbox to input port number
253  class NetworkPortConfig : public C4GUI::Window
254  {
255  public:
256  NetworkPortConfig(const C4Rect &rcBounds, const char *szName, int32_t *pConfigValue, int32_t iDefault); // ctor
257  private:
258  int32_t *pConfigValue; // pointer into config set
259  C4GUI::CheckBox *pEnableCheck; // check box for whether port is enabled
260  C4GUI::Edit *pPortEdit; // edit field for port number
261 
262  public:
263  void OnEnabledCheckChange(C4GUI::Element *pCheckBox); // callback when checkbox is ticked
264  void SavePort(); // controls to config
265  int32_t GetPort(); // get port as currently configured by control (or -1 for deactivated)
266 
267  static bool GetControlSize(int *piWdt, int *piHgt);
268  } *pPortCfgTCP, *pPortCfgUDP, *pPortCfgRef, *pPortCfgDsc;
269 
270  class NetworkServerAddressConfig : public C4GUI::Window
271  {
272  public:
273  NetworkServerAddressConfig(const C4Rect &rcBounds, const char *szName, int32_t *piConfigEnableValue, char *szConfigAddressValue, int iTabWidth); // ctor
274  private:
275  int32_t *piConfigEnableValue; char *szConfigAddressValue;
276  C4GUI::CheckBox *pEnableCheck;
277  C4GUI::Edit *pAddressEdit;
278  public:
279  void OnEnabledCheckChange(C4GUI::Element *pCheckBox); // callback when checkbox is ticked
280  void Save2Config(); // controls to config
281 
282  static bool GetControlSize(int *piWdt, int *piHgt, int *piTabPos, const char *szForText);
283  } *pLeagueServerCfg;
284 };
285 
286 
287 #endif // INC_C4StartupOptionsDlg
const char * GetText() const
Definition: C4Gui.h:1435
void OnBackBtn(C4GUI::Control *btn)
virtual const char * GetID()
Definition: C4Gui.h:2226
Definition: C4Rect.h:29
virtual void UserClose(bool fOK)
virtual int32_t GetListItemTopSpacing()
Definition: C4Gui.h:461
virtual void OnClosed(bool fOK)
bool fOK
Definition: C4Gui.h:2082
bool SetText(const char *szText, bool fUser)
Definition: C4Gui.h:1292
static bool GetControlSize(int *piWdt, int *piHgt, const char *szForText, CStdFont *pForFont, bool fMultiline)
Definition: C4GuiEdit.cpp:812
virtual bool SetSubscreen(const char *szToScreen)
virtual void DrawElement(C4TargetFacet &cgo)
C4Rect rcBounds
Definition: C4Gui.h:385
bool SaveConfig(bool fForce, bool fKeepOpen)
C4Rect & GetBounds()
Definition: C4Gui.h:445
void RecreateDialog(bool fFade)
Icons
Definition: C4Gui.h:637
C4GUI::Edit * GetEdit() const
Definition: C4Gui.h:1436
virtual void OnKeyboardLayoutChanged()
const int C4MaxKey
Definition: C4Constants.h:30
virtual void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam)
int32_t Hgt
Definition: C4Rect.h:32
uint32_t DWORD
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277