OpenClonk
C4GameOptions.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) 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 // Custom game options and configuration dialog
17 
18 #ifndef INC_C4GameOptions
19 #define INC_C4GameOptions
20 
21 #include "gui/C4Gui.h"
22 
23 // options dialog: created as listbox inside another dialog
24 // used to configure some standard runtime options, as well as custom game options
26 {
27 public:
28  enum { IconLabelSpacing = 2 }; // space between an icon and its text
29 
30 private:
31  class Option : public C4GUI::Control
32  {
33  protected:
34  typedef C4GUI::Control BaseClass;
35  class C4GameOptionsList *pForDlg;
36 
37  // primary subcomponent: forward focus to this element
38  C4GUI::Control *pPrimarySubcomponent;
39 
40  bool IsFocused(C4GUI::Control *pCtrl) override
41  {
42  // also forward own focus to primary control
43  return BaseClass::IsFocused(pCtrl) || (HasFocus() && pPrimarySubcomponent == pCtrl);
44  }
45 
46  public:
47  Option(class C4GameOptionsList *pForDlg); // ctor - adds to list
48  void InitOption(C4GameOptionsList *pForDlg); // add to list and do initial update
49 
50  virtual void Update() {}; // update data
51 
52  Option *GetNext() { return static_cast<Option *>(BaseClass::GetNext()); }
53  };
54 
55  // dropdown list option
56  class OptionDropdown : public Option
57  {
58  public:
59  OptionDropdown(class C4GameOptionsList *pForDlg, const char *szCaption, bool fReadOnly);
60 
61  protected:
62  C4GUI::Label *pCaption;
63  C4GUI::ComboBox *pDropdownList;
64  bool fReadOnly;
65 
66  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) = 0;
67  void OnDropdownFill(C4GUI::ComboBox_FillCB *pFiller)
68  { DoDropdownFill(pFiller); }
69  virtual void DoDropdownSelChange(int32_t idNewSelection) = 0;
70  bool OnDropdownSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection)
71  { DoDropdownSelChange(idNewSelection); Update(); return true; }
72  };
73 
74  // drop down list to specify a custom scenario parameter
75  class OptionScenarioParameter : public OptionDropdown
76  {
77  const class C4ScenarioParameterDef *ParameterDef;
78  int32_t LastValue; bool LastValueValid;
79 
80  public:
81  OptionScenarioParameter(class C4GameOptionsList *pForDlg, const class C4ScenarioParameterDef *parameter_def);
82 
83  protected:
84  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
85  void DoDropdownSelChange(int32_t idNewSelection) override;
86 
87  void Update() override; // update data to currently set option
88  };
89 
90 
91  // drop down list to specify central/decentral control mode
92  class OptionControlMode : public OptionDropdown
93  {
94  public:
95  OptionControlMode(class C4GameOptionsList *pForDlg);
96 
97  protected:
98  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
99  void DoDropdownSelChange(int32_t idNewSelection) override;
100 
101  void Update() override; // update data to current control rate
102  };
103 
104  // drop down list option to adjust control rate
105  class OptionControlRate : public OptionDropdown
106  {
107  public:
108  OptionControlRate(class C4GameOptionsList *pForDlg);
109 
110  protected:
111  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
112  void DoDropdownSelChange(int32_t idNewSelection) override;
113 
114  void Update() override; // update data to current control rate
115  };
116 
117  // drop down list option to adjust team usage
118  class OptionTeamDist : public OptionDropdown
119  {
120  public:
121  OptionTeamDist(class C4GameOptionsList *pForDlg);
122 
123  protected:
124  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
125  void DoDropdownSelChange(int32_t idNewSelection) override;
126 
127  void Update() override; // update data to current team mode
128  };
129 
130  // drop down list option to adjust team color state
131  class OptionTeamColors : public OptionDropdown
132  {
133  public:
134  OptionTeamColors(class C4GameOptionsList *pForDlg);
135 
136  protected:
137  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
138  void DoDropdownSelChange(int32_t idNewSelection) override;
139 
140  void Update() override; // update data to current team color mode
141  };
142 
143  // drop down list option to adjust control rate
144  class OptionRuntimeJoin : public OptionDropdown
145  {
146  public:
147  OptionRuntimeJoin(class C4GameOptionsList *pForDlg);
148 
149  protected:
150  void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override;
151  void DoDropdownSelChange(int32_t idNewSelection) override;
152 
153  void Update() override; // update data to current runtime join state
154  };
155 
156 public:
158  {
163  };
164 
165  C4GameOptionsList(const C4Rect &rcBounds, bool fActive, C4GameOptionsListSource source, class C4ScenarioParameterDefs *param_defs=nullptr, class C4ScenarioParameters *params=nullptr);
166  ~C4GameOptionsList() override { Deactivate(); }
167 
168 private:
169  C4GameOptionsListSource source; // where to draw options from. e.g. lobby options such as team colors aren't presented at run-time
170  class C4ScenarioParameterDefs *param_defs; // where to pull parameters and parameter definitions from
171  class C4ScenarioParameters *params;
172 
173  void InitOptions(); // creates option selection components
174  void ClearOptions(); // remove all option components
175 
176 public:
177  // update all option flags by current game state
178  void Update();
179  void OnSec1Timer() override { Update(); }
180 
181  // update to new parameter set. recreates option fields. set parameters to nullptr for no options
183 
184  // activate/deactivate periodic updates
185  void Activate();
186  void Deactivate();
187 
188  // config
189  bool IsRuntime() const { return source==GOLS_Runtime; }
190  bool IsTabular() const { return IsRuntime() || IsPreGame(); } // low lobby space doesn't allow tabular layout
191  bool IsPreGame() const { return source==GOLS_PreGameSingle || source==GOLS_PreGameNetwork; }
192  bool IsPreGameSingle() const { return source==GOLS_PreGameSingle; }
193 
194  C4ScenarioParameters *GetParameters() { return params; } // used by children
195 };
196 #endif //INC_C4GameOptions
virtual bool IsFocused(Control *pCtrl)
Definition: C4Gui.h:836
bool HasFocus()
Definition: C4Gui.h:1067
C4Rect rcBounds
Definition: C4Gui.h:385
Element * GetNext() const
Definition: C4Gui.h:449
bool IsFocused(Control *pCtrl) override
Definition: C4Gui.h:1519
bool IsPreGame() const
void OnSec1Timer() override
bool IsPreGameSingle() const
bool IsRuntime() const
C4ScenarioParameters * GetParameters()
~C4GameOptionsList() override
bool IsTabular() const
void SetParameters(C4ScenarioParameterDefs *param_defs, C4ScenarioParameters *params)
C4GameOptionsList(const C4Rect &rcBounds, bool fActive, C4GameOptionsListSource source, class C4ScenarioParameterDefs *param_defs=nullptr, class C4ScenarioParameters *params=nullptr)
Definition: C4Rect.h:28