| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) RedWolf Design |
| 5 | * Copyright (c) 2005, Sven2 |
| 6 | * Copyright (c) 2017-2021, The LegacyClonk Team and contributors |
| 7 | * |
| 8 | * Distributed under the terms of the ISC license; see accompanying file |
| 9 | * "COPYING" for details. |
| 10 | * |
| 11 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 12 | * See accompanying file "TRADEMARK" for details. |
| 13 | * |
| 14 | * To redistribute this file separately, substitute the full license texts |
| 15 | * for the above references. |
| 16 | */ |
| 17 | |
| 18 | // Custom game options and configuration dialog |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "C4Gui.h" |
| 23 | #include "C4GuiListBox.h" |
| 24 | |
| 25 | // options dialog: created as listbox inside another dialog |
| 26 | // used to configure some standard runtime options, as well as custom game options |
| 27 | class C4GameOptionsList : public C4GUI::ListBox |
| 28 | { |
| 29 | public: |
| 30 | enum { IconLabelSpacing = 2 }; // space between an icon and its text |
| 31 | |
| 32 | private: |
| 33 | class Option : public C4GUI::Control |
| 34 | { |
| 35 | protected: |
| 36 | typedef C4GUI::Control BaseClass; |
| 37 | |
| 38 | // primary subcomponent: forward focus to this element |
| 39 | C4GUI::Control *pPrimarySubcomponent; |
| 40 | |
| 41 | virtual bool IsFocused(C4GUI::Control *pCtrl) override |
| 42 | { |
| 43 | // also forward own focus to primary control |
| 44 | return BaseClass::IsFocused(pCtrl) || (HasFocus() && pPrimarySubcomponent == pCtrl); |
| 45 | } |
| 46 | |
| 47 | public: |
| 48 | Option(C4GameOptionsList *pForDlg); // adds to list |
| 49 | void InitOption(C4GameOptionsList *pForDlg); // add to list and do initial update |
| 50 | |
| 51 | virtual void Update() {} // update data |
| 52 | |
| 53 | Option *GetNext() { return static_cast<Option *>(BaseClass::GetNext()); } |
| 54 | }; |
| 55 | |
| 56 | // dropdown list option |
| 57 | class OptionDropdown : public Option |
| 58 | { |
| 59 | public: |
| 60 | OptionDropdown(C4GameOptionsList *pForDlg, const char *szCaption, bool fReadOnly); |
| 61 | |
| 62 | protected: |
| 63 | C4GUI::Label *pCaption; |
| 64 | C4GUI::ComboBox *pDropdownList; |
| 65 | |
| 66 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) = 0; |
| 67 | |
| 68 | void OnDropdownFill(C4GUI::ComboBox_FillCB *pFiller) |
| 69 | { |
| 70 | DoDropdownFill(pFiller); |
| 71 | } |
| 72 | |
| 73 | virtual void DoDropdownSelChange(int32_t idNewSelection) = 0; |
| 74 | |
| 75 | bool OnDropdownSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection) |
| 76 | { |
| 77 | DoDropdownSelChange(idNewSelection); Update(); return true; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | // drop down list to specify central/decentral control mode |
| 82 | class OptionControlMode : public OptionDropdown |
| 83 | { |
| 84 | public: |
| 85 | OptionControlMode(C4GameOptionsList *pForDlg); |
| 86 | |
| 87 | protected: |
| 88 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override; |
| 89 | virtual void DoDropdownSelChange(int32_t idNewSelection) override; |
| 90 | |
| 91 | virtual void Update() override; // update data to current control rate |
| 92 | }; |
| 93 | |
| 94 | // drop down list option to adjust control rate |
| 95 | class OptionControlRate : public OptionDropdown |
| 96 | { |
| 97 | public: |
| 98 | OptionControlRate(C4GameOptionsList *pForDlg); |
| 99 | |
| 100 | protected: |
| 101 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override; |
| 102 | virtual void DoDropdownSelChange(int32_t idNewSelection) override; |
| 103 | |
| 104 | virtual void Update() override; // update data to current control rate |
| 105 | }; |
| 106 | |
| 107 | // drop down list option to adjust team usage |
| 108 | class OptionTeamDist : public OptionDropdown |
| 109 | { |
| 110 | public: |
| 111 | OptionTeamDist(C4GameOptionsList *pForDlg); |
| 112 | |
| 113 | private: |
| 114 | C4GameOptionsList *optionsList; |
| 115 | |
| 116 | protected: |
| 117 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override; |
| 118 | virtual void DoDropdownSelChange(int32_t idNewSelection) override; |
| 119 | |
| 120 | virtual void Update() override; // update data to current team mode |
| 121 | }; |
| 122 | |
| 123 | // drop down list option to adjust team color state |
| 124 | class OptionTeamColors : public OptionDropdown |
| 125 | { |
| 126 | public: |
| 127 | OptionTeamColors(C4GameOptionsList *pForDlg); |
| 128 | |
| 129 | protected: |
| 130 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override; |
| 131 | virtual void DoDropdownSelChange(int32_t idNewSelection) override; |
| 132 | |
| 133 | virtual void Update() override; // update data to current team color mode |
| 134 | }; |
| 135 | |
| 136 | // drop down list option to adjust control rate |
| 137 | class OptionRuntimeJoin : public OptionDropdown |
| 138 | { |
| 139 | public: |
| 140 | OptionRuntimeJoin(C4GameOptionsList *pForDlg); |
| 141 | |
| 142 | protected: |
| 143 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *pFiller) override; |
| 144 | virtual void DoDropdownSelChange(int32_t idNewSelection) override; |
| 145 | |
| 146 | virtual void Update() override; // update data to current runtime join state |
| 147 | }; |
| 148 | |
| 149 | class OptionRandomTeamCount : public OptionDropdown |
| 150 | { |
| 151 | public: |
| 152 | OptionRandomTeamCount(class C4GameOptionsList *forDlg); |
| 153 | |
| 154 | protected: |
| 155 | virtual void DoDropdownFill(C4GUI::ComboBox_FillCB *filler) override; |
| 156 | virtual void DoDropdownSelChange(int32_t newSelection) override; |
| 157 | |
| 158 | virtual void Update() override; // update data to current runtime join state |
| 159 | }; |
| 160 | |
| 161 | public: |
| 162 | C4GameOptionsList(const C4Rect &rcBounds, bool fActive, bool fRuntime); |
| 163 | ~C4GameOptionsList() { Deactivate(); } |
| 164 | |
| 165 | private: |
| 166 | C4Sec1TimerCallback<C4GameOptionsList> *pSec1Timer; // engine timer hook for updates |
| 167 | bool fRuntime; // set for runtime options dialog - does not provide pre-game options such as team colors |
| 168 | OptionRandomTeamCount *randomTeamCount{nullptr}; |
| 169 | |
| 170 | void InitOptions(); // creates option selection components |
| 171 | |
| 172 | public: |
| 173 | // update all option flags by current game state |
| 174 | void Update(); |
| 175 | void OnSec1Timer() { Update(); } |
| 176 | |
| 177 | // activate/deactivate periodic updates |
| 178 | void Activate(); |
| 179 | void Deactivate(); |
| 180 | |
| 181 | // config |
| 182 | bool IsTabular() const { return fRuntime; } // wide runtime dialog allows tabular layout |
| 183 | bool IsRuntime() const { return fRuntime; } |
| 184 | }; |
| 185 | |