OpenClonk
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() override; // dtor
30 
31 private:
32  class C4KeyBinding *pKeyBack;
33  bool fConfigSaved{false}; // set when config has been saved because dlg is closed; prevents double save
34  bool fCanGoBack{true}; // 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  bool OnEnter() override { return false; } // Enter ignored
39  bool OnEscape() override { DoBack(); return true; }
40  bool KeyBack() { DoBack(); return true; }
41  void OnClosed(bool fOK) override; // callback when dlg got closed - save config
42  void UserClose(bool fOK) override // 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  bool SetSubscreen(const char *szToScreen) override; // go to specified property sheet
53  void OnKeyboardLayoutChanged() override; // 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  void DrawElement(C4TargetFacet &cgo) override; // 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() override;
121  void OnSec1Timer() override; // update timer label
122  protected:
123  bool OnEnter() override { return true; } // Pressing Enter does not confirm this dialog, so "blind" users are less likely to accept their change
124  const char *GetID() override { 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  std::unique_ptr<C4KeyBinding> KeyListeners;
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) { return KeyPress(key, true); };
169  bool KeyUp(const C4KeyCodeEx &key) { return KeyPress(key, false); };
170  bool KeyPress(const C4KeyCodeEx &key, bool fDown);
171  void MouseInput(C4GUI::CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override;
172  public:
173  KeySelDialog(const class C4PlayerControlAssignment *assignment, const class C4PlayerControlAssignmentSet *assignment_set);
174  ~KeySelDialog() override = default;
175 
176  C4KeyCodeEx GetKeyCode() { return key; }
177 
178  };
179 
180  // list box of definable keys
181  class ControlConfigListBox : public C4GUI::ListBox
182  {
183  private:
184  // assignment key label - change key on click
185  class ControlAssignmentLabel : public C4GUI::Label
186  {
187  private:
188  class C4PlayerControlAssignment *assignment; // pointer into assignment set (not owned!)
189  class C4PlayerControlAssignmentSet *assignment_set; // pointer to assignment set (not owned!)
190 
191  void UpdateAssignmentString();
192  public:
193  void MouseInput(class C4GUI::CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override;
194 
195  ControlAssignmentLabel(class C4PlayerControlAssignment *assignment, class C4PlayerControlAssignmentSet *assignment_set, const C4Rect &bounds);
196  };
197 
198  // item in list box
199  class ListItem : public C4GUI::Window
200  {
201  private:
202  ControlAssignmentLabel *assignment_label;
203  bool has_extra_spacing; // if true, add a bit of spacing on top of this item to group elements
204 
205  int32_t GetListItemTopSpacing() override { return C4GUI::Window::GetListItemTopSpacing() + (has_extra_spacing*GetBounds().Hgt/2); }
206 
207  public:
208  ListItem(ControlConfigListBox *parent_list, class C4PlayerControlAssignment *assignment, class C4PlayerControlAssignmentSet *assignment_set, bool first_of_group);
209  };
210 
211  private:
212  class C4PlayerControlAssignmentSet *set; // assignment set being configured by this box
213  static bool sort_by_group (C4PlayerControlAssignment *i, C4PlayerControlAssignment *j) { return i->GetGUIGroup() < j->GetGUIGroup(); }
214 
215  public:
216  ControlConfigListBox(const C4Rect &rcBounds, class C4PlayerControlAssignmentSet *set);
217 
218  void SetAssignmentSet(class C4PlayerControlAssignmentSet *new_set);
219 
220  static void SetUserKey(class C4PlayerControlAssignmentSet *assignment_set, class C4PlayerControlAssignment *assignment, C4KeyCodeEx &key);
221  };
222 
223  // config area to define a keyboard set
224  class ControlConfigArea : public C4GUI::Window
225  {
226  private:
227  bool fGamepad; // if set, gamepad control sets are being configured
228  int32_t iMaxControlSets; // number of control sets configured in this area - must be smaller or equal to C4MaxControlSet
229  int32_t iSelectedCtrlSet; // keyboard or gamepad set that is currently being configured
230  class C4GUI::IconButton ** ppKeyControlSetBtns; // buttons to select configured control set - array in length of iMaxControlSets
231  class KeySelButton * KeyControlBtns[C4MaxKey]; // buttons to configure individual kbd set buttons
232  C4StartupOptionsDlg *pOptionsDlg;
233  ControlConfigListBox *control_list;
234  class C4GUI::CheckBox *pGUICtrl;
235  public:
236  ControlConfigArea(const C4Rect &rcArea, int32_t iHMargin, int32_t iVMargin, bool fGamepad, C4StartupOptionsDlg *pOptionsDlg);
237  ~ControlConfigArea() override;
238 
239  void UpdateCtrlSet();
240 
241  protected:
242 
243  void OnCtrlSetBtn(C4GUI::Control *btn);
244  void OnResetKeysBtn(C4GUI::Control *btn);
245  void OnGUIGamepadCheckChange(C4GUI::Element *pCheckBox);
246  };
247 
248  ControlConfigArea *pControlConfigArea;
249 
250  class C4GamePadControl *GamePadCon;
251 
252  // network tab --------------------------------------------------------
253 private:
254  // checkbox to enable protocol and editbox to input port number
255  class NetworkPortConfig : public C4GUI::Window
256  {
257  public:
258  NetworkPortConfig(const C4Rect &rcBounds, const char *szName, int32_t *pConfigValue, int32_t iDefault); // ctor
259  private:
260  int32_t *pConfigValue; // pointer into config set
261  C4GUI::CheckBox *pEnableCheck; // check box for whether port is enabled
262  C4GUI::Edit *pPortEdit; // edit field for port number
263 
264  public:
265  void OnEnabledCheckChange(C4GUI::Element *pCheckBox); // callback when checkbox is ticked
266  void SavePort(); // controls to config
267  int32_t GetPort(); // get port as currently configured by control (or -1 for deactivated)
268 
269  static bool GetControlSize(int *piWdt, int *piHgt);
270  } *pPortCfgTCP, *pPortCfgUDP, *pPortCfgRef, *pPortCfgDsc;
271 
272  class NetworkServerAddressConfig : public C4GUI::Window
273  {
274  public:
275  NetworkServerAddressConfig(const C4Rect &rcBounds, const char *szName, int32_t *piConfigEnableValue, char *szConfigAddressValue, int iTabWidth); // ctor
276  virtual ~NetworkServerAddressConfig() {};
277  protected:
278  int32_t *piConfigEnableValue; char *szConfigAddressValue;
279  C4GUI::CheckBox *pEnableCheck;
280  C4GUI::Edit *pAddressEdit;
281  public:
282  virtual void OnEnabledCheckChange(C4GUI::Element *pCheckBox); // callback when checkbox is ticked
283  void Save2Config(); // controls to config
284 
285  static bool GetControlSize(int *piWdt, int *piHgt, int *piTabPos, const char *szForText);
286  } *pLeagueServerCfg;
287 
288  class NetworkModDatabaseServerAddressConfig : public NetworkServerAddressConfig
289  {
290  public:
291  NetworkModDatabaseServerAddressConfig(const C4Rect &rcBounds, const char *szName, int32_t *piConfigEnableValue, char *szConfigAddressValue, int iTabWidth); // ctor
292  private:
293  virtual void OnEnabledCheckChange(C4GUI::Element *pCheckBox) override; // callback when checkbox is ticked
294  } *pModDatabaseServerCfg;
295 };
296 
297 
298 #endif // INC_C4StartupOptionsDlg
const int C4MaxKey
Definition: C4Constants.h:30
uint32_t DWORD
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
void MouseInput(CMouse &rMouse, int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam) override
bool fOK
Definition: C4Gui.h:2083
bool SetText(const char *szText, bool fUser)
Definition: C4Gui.h:1293
C4Rect rcBounds
Definition: C4Gui.h:385
C4Rect & GetBounds()
Definition: C4Gui.h:445
virtual int32_t GetListItemTopSpacing()
Definition: C4Gui.h:461
const char * GetID() override
Definition: C4Gui.h:2227
void DrawElement(C4TargetFacet &cgo) override
static bool GetControlSize(int *piWdt, int *piHgt, const char *szForText, CStdFont *pForFont, bool fMultiline)
Definition: C4GuiEdit.cpp:812
C4GUI::Edit * GetEdit() const
Definition: C4Gui.h:1437
const char * GetText() const
Definition: C4Gui.h:1436
Definition: C4Rect.h:28
int32_t Hgt
Definition: C4Rect.h:30
void UserClose(bool fOK) override
bool SetSubscreen(const char *szToScreen) override
bool OnEscape() override
void RecreateDialog(bool fFade)
void OnClosed(bool fOK) override
void OnKeyboardLayoutChanged() override
bool SaveConfig(bool fForce, bool fKeepOpen)
bool OnEnter() override
void OnBackBtn(C4GUI::Control *btn)
Icons
Definition: C4Gui.h:638