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  if (btn_enable && lst_disabled) {
239  }
240 }
241 
242 void
244 {
245  int index = lst_disabled->GetSelection();
246  Text mod_name = lst_disabled->GetItemText(index);
247 
248  config->EnableMod(mod_name);
249  changed = true;
250 
251  UpdateLists();
252 
253  ModInfo* mod_info = config->GetModInfo(mod_name);
254  ModInfoDlg* mod_info_dlg = manager->GetModInfoDlg();
255 
256  if (mod_info && mod_info_dlg) {
257  mod_info_dlg->SetModInfo(mod_info);
259  }
260 }
261 
262 void
264 {
265  int index = lst_enabled->GetSelection();
266  Text mod_name = lst_enabled->GetItemText(index);
267 
268  config->DisableMod(mod_name);
269  changed = true;
270 
271  UpdateLists();
272 }
273 
274 void
276 {
277  int index = lst_enabled->GetSelection();
278  config->IncreaseModPriority(index--);
279 
280  UpdateLists();
281  lst_enabled->SetSelected(index);
282  btn_disable->SetEnabled(true);
283  btn_increase->SetEnabled(index > 0);
284  btn_decrease->SetEnabled(index < lst_enabled->NumItems()-1);
285 }
286 
287 void
289 {
290  int index = lst_enabled->GetSelection();
291  config->DecreaseModPriority(index++);
292 
293  UpdateLists();
294  lst_enabled->SetSelected(index);
295  btn_disable->SetEnabled(true);
296  btn_increase->SetEnabled(index > 0);
297  btn_decrease->SetEnabled(index < lst_enabled->NumItems()-1);
298 }
299 
300 // +--------------------------------------------------------------------+
301 
307 
308 // +--------------------------------------------------------------------+
309 
310 void
312 {
313  if (changed) {
314  config->Save();
315  config->FindMods();
316  config->Redeploy();
317  changed = false;
318  }
319 }
320 
321 void
323 {
324  if (changed) {
325  config->Load();
326  config->FindMods();
327  config->Redeploy();
328  changed = false;
329  }
330 }
331 
332 // +--------------------------------------------------------------------+
333 
334 void
336 {
338 }
339 
340 void
342 {
344 }