Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ModDlg.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: ModDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Mod Config Dialog Active Window class
13 */
14 
15 #include "MemDebug.h"
16 #include "ModDlg.h"
17 #include "ModInfoDlg.h"
18 #include "BaseScreen.h"
19 #include "ModConfig.h"
20 
21 #include "Game.h"
22 #include "DataLoader.h"
23 #include "Button.h"
24 #include "ListBox.h"
25 #include "Slider.h"
26 #include "Video.h"
27 #include "Keyboard.h"
28 #include "Mouse.h"
29 #include "ParseUtil.h"
30 
31 // +--------------------------------------------------------------------+
32 // DECLARE MAPPING FUNCTIONS:
33 
34 DEF_MAP_CLIENT(ModDlg, OnIncrease);
35 DEF_MAP_CLIENT(ModDlg, OnDecrease);
36 DEF_MAP_CLIENT(ModDlg, OnEnable);
37 DEF_MAP_CLIENT(ModDlg, OnDisable);
38 DEF_MAP_CLIENT(ModDlg, OnSelectEnabled);
39 DEF_MAP_CLIENT(ModDlg, OnSelectDisabled);
40 DEF_MAP_CLIENT(ModDlg, OnAccept);
41 DEF_MAP_CLIENT(ModDlg, OnCancel);
42 DEF_MAP_CLIENT(ModDlg, OnAudio);
43 DEF_MAP_CLIENT(ModDlg, OnVideo);
44 DEF_MAP_CLIENT(ModDlg, OnOptions);
45 DEF_MAP_CLIENT(ModDlg, OnControls);
46 DEF_MAP_CLIENT(ModDlg, OnMod);
47 
48 // +--------------------------------------------------------------------+
49 
51 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
52 lst_disabled(0), lst_enabled(0), btn_enable(0), btn_disable(0),
53 btn_increase(0), btn_decrease(0), btn_accept(0), btn_cancel(0),
54 aud_btn(0), vid_btn(0), ctl_btn(0), opt_btn(0), mod_btn(0),
55 config(0), changed(false)
56 {
58  Init(def);
59 }
60 
62 {
63 }
64 
65 // +--------------------------------------------------------------------+
66 
67 void
69 {
70  btn_accept = (Button*) FindControl( 1);
71  btn_cancel = (Button*) FindControl( 2);
72  btn_enable = (Button*) FindControl(301);
73  btn_disable = (Button*) FindControl(302);
76 
79 
80  if (btn_accept)
82 
83  if (btn_cancel)
85 
86  if (lst_enabled)
88 
89  if (lst_disabled)
91 
92  if (btn_enable) {
94  btn_enable->SetEnabled(false);
95  }
96 
97  if (btn_disable) {
99  btn_disable->SetEnabled(false);
100  }
101 
102  if (btn_increase) {
103  char up_arrow[2];
104  up_arrow[0] = Font::ARROW_UP;
105  up_arrow[1] = 0;
106  btn_increase->SetText(up_arrow);
107  btn_increase->SetEnabled(false);
109  }
110 
111  if (btn_decrease) {
112  char dn_arrow[2];
113  dn_arrow[0] = Font::ARROW_DOWN;
114  dn_arrow[1] = 0;
115  btn_decrease->SetText(dn_arrow);
116  btn_decrease->SetEnabled(false);
118  }
119 
120  vid_btn = (Button*) FindControl(901);
122 
123  aud_btn = (Button*) FindControl(902);
125 
126  ctl_btn = (Button*) FindControl(903);
128 
129  opt_btn = (Button*) FindControl(904);
131 
132  mod_btn = (Button*) FindControl(905);
133  if (mod_btn)
135 }
136 
137 // +--------------------------------------------------------------------+
138 
139 void
141 {
143  UpdateLists();
144 
145  if (vid_btn) vid_btn->SetButtonState(0);
146  if (aud_btn) aud_btn->SetButtonState(0);
147  if (ctl_btn) ctl_btn->SetButtonState(0);
148  if (opt_btn) opt_btn->SetButtonState(0);
149  if (mod_btn) mod_btn->SetButtonState(1);
150 }
151 
152 void
154 {
156 
157  if (config && lst_disabled && lst_enabled) {
160 
161  ListIter<Text> iter_d = config->DisabledMods();
162  while (++iter_d) {
163  Text* t = iter_d.value();
164  lst_disabled->AddItem(*t);
165  }
166 
167  ListIter<Text> iter_e = config->EnabledMods();
168  while (++iter_e) {
169  Text* t = iter_e.value();
170  lst_enabled->AddItem(*t);
171  }
172  }
173 
174  if (btn_disable)
175  btn_disable->SetEnabled(false);
176 
177  if (btn_enable)
178  btn_enable->SetEnabled(false);
179 
180  if (btn_increase)
181  btn_increase->SetEnabled(false);
182 
183  if (btn_decrease)
184  btn_decrease->SetEnabled(false);
185 }
186 
187 // +--------------------------------------------------------------------+
188 
189 void
191 {
192  if (Keyboard::KeyDown(VK_RETURN)) {
193  if (btn_accept && btn_accept->IsEnabled())
194  OnAccept(0);
195  }
196 }
197 
198 // +--------------------------------------------------------------------+
199 
200 void
202 {
203  static DWORD click_time = 0;
204 
205  if (lst_enabled) {
206  if (btn_disable)
208 
209  if (btn_increase)
211 
212  if (btn_decrease)
214 
215  // double-click:
216  if (Game::RealTime() - click_time < 350) {
217  if (lst_enabled->GetSelCount() == 1) {
218  int index = lst_enabled->GetSelection();
219  Text mod_name = lst_enabled->GetItemText(index);
220  ModInfo* mod_info = config->GetModInfo(mod_name);
221  ModInfoDlg* mod_info_dlg = manager->GetModInfoDlg();
222 
223  if (mod_info && mod_info_dlg) {
224  mod_info_dlg->SetModInfo(mod_info);
226  }
227  }
228  }
229  }
230 
231  click_time = Game::RealTime();
232 }
233 
234 void
236 {
237 #ifdef STARSHATTER_DEMO_RELEASE
238  if (btn_enable) {
239  btn_enable->SetEnabled(false);
240  }
241 #else
242  if (btn_enable && lst_disabled) {
244  }
245 #endif
246 }
247 
248 void
250 {
251  int index = lst_disabled->GetSelection();
252  Text mod_name = lst_disabled->GetItemText(index);
253 
254  config->EnableMod(mod_name);
255  changed = true;
256 
257  UpdateLists();
258 
259  ModInfo* mod_info = config->GetModInfo(mod_name);
260  ModInfoDlg* mod_info_dlg = manager->GetModInfoDlg();
261 
262  if (mod_info && mod_info_dlg) {
263  mod_info_dlg->SetModInfo(mod_info);
265  }
266 }
267 
268 void
270 {
271  int index = lst_enabled->GetSelection();
272  Text mod_name = lst_enabled->GetItemText(index);
273 
274  config->DisableMod(mod_name);
275  changed = true;
276 
277  UpdateLists();
278 }
279 
280 void
282 {
283  int index = lst_enabled->GetSelection();
284  config->IncreaseModPriority(index--);
285 
286  UpdateLists();
287  lst_enabled->SetSelected(index);
288  btn_disable->SetEnabled(true);
289  btn_increase->SetEnabled(index > 0);
290  btn_decrease->SetEnabled(index < lst_enabled->NumItems()-1);
291 }
292 
293 void
295 {
296  int index = lst_enabled->GetSelection();
297  config->DecreaseModPriority(index++);
298 
299  UpdateLists();
300  lst_enabled->SetSelected(index);
301  btn_disable->SetEnabled(true);
302  btn_increase->SetEnabled(index > 0);
303  btn_decrease->SetEnabled(index < lst_enabled->NumItems()-1);
304 }
305 
306 // +--------------------------------------------------------------------+
307 
313 
314 // +--------------------------------------------------------------------+
315 
316 void
318 {
319  if (changed) {
320  config->Save();
321  config->FindMods();
322  config->Redeploy();
323  changed = false;
324  }
325 }
326 
327 void
329 {
330  if (changed) {
331  config->Load();
332  config->FindMods();
333  config->Redeploy();
334  changed = false;
335  }
336 }
337 
338 // +--------------------------------------------------------------------+
339 
340 void
342 {
344 }
345 
346 void
348 {
350 }