OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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  virtual bool IsFocused(C4GUI::Control *pCtrl)
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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
85  virtual void DoDropdownSelChange(int32_t idNewSelection);
86 
87  virtual void Update(); // 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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
99  virtual void DoDropdownSelChange(int32_t idNewSelection);
100 
101  virtual void Update(); // 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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
112  virtual void DoDropdownSelChange(int32_t idNewSelection);
113 
114  virtual void Update(); // 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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
125  virtual void DoDropdownSelChange(int32_t idNewSelection);
126 
127  virtual void Update(); // 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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
138  virtual void DoDropdownSelChange(int32_t idNewSelection);
139 
140  virtual void Update(); // 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  virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller);
151  virtual void DoDropdownSelChange(int32_t idNewSelection);
152 
153  virtual void Update(); // 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);
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() { 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
bool IsPreGame() const
bool IsPreGameSingle() const
virtual bool IsFocused(Control *pCtrl)
Definition: C4Gui.h:1518
Definition: C4Rect.h:29
C4GameOptionsList(const C4Rect &rcBounds, bool fActive, C4GameOptionsListSource source, class C4ScenarioParameterDefs *param_defs=nullptr, class C4ScenarioParameters *params=nullptr)
bool HasFocus()
Definition: C4Gui.h:1067
bool IsTabular() const
C4Rect rcBounds
Definition: C4Gui.h:385
Element * GetNext() const
Definition: C4Gui.h:449
C4ScenarioParameters * GetParameters()
bool IsRuntime() const
void SetParameters(C4ScenarioParameterDefs *param_defs, C4ScenarioParameters *params)
virtual bool IsFocused(Control *pCtrl)
Definition: C4Gui.h:836