Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MsnEventDlg.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: MsnEventDlg.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 "MsnEventDlg.h"
17 #include "MsnEditDlg.h"
18 #include "MenuScreen.h"
19 #include "Campaign.h"
20 #include "Mission.h"
21 #include "MissionEvent.h"
22 #include "Instruction.h"
23 #include "Ship.h"
24 #include "ShipDesign.h"
25 #include "StarSystem.h"
26 #include "Galaxy.h"
27 
28 #include "Game.h"
29 #include "DataLoader.h"
30 #include "Button.h"
31 #include "ListBox.h"
32 #include "EditBox.h"
33 #include "Video.h"
34 #include "Keyboard.h"
35 #include "Mouse.h"
36 #include "ParseUtil.h"
37 
38 // +--------------------------------------------------------------------+
39 // DECLARE MAPPING FUNCTIONS:
40 
41 DEF_MAP_CLIENT(MsnEventDlg, OnEventSelect);
42 DEF_MAP_CLIENT(MsnEventDlg, OnAccept);
43 DEF_MAP_CLIENT(MsnEventDlg, OnCancel);
44 
45 // +--------------------------------------------------------------------+
46 
48 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
49 btn_accept(0), btn_cancel(0), mission(0), event(0)
50 {
51  Init(def);
52 }
53 
55 {
56 }
57 
58 // +--------------------------------------------------------------------+
59 
60 void
62 {
63  btn_accept = (Button*) FindControl( 1);
64  if (btn_accept)
66 
67  btn_cancel = (Button*) FindControl( 2);
68  if (btn_accept)
70 
71  lbl_id = FindControl(201);
72  edt_time = (EditBox*) FindControl(202);
73  edt_delay = (EditBox*) FindControl(203);
74  cmb_event = (ComboBox*) FindControl(204);
82 
87 
88  if (cmb_event)
90 }
91 
92 // +--------------------------------------------------------------------+
93 
94 void
96 {
98 
99  if (!event) return;
100 
103 
104  if (event->Event() == MissionEvent::JUMP)
106  else
108 
111 
112  char buf[64];
113 
114  sprintf_s(buf, "%d", event->EventID());
115  if (lbl_id) lbl_id->SetText(buf);
116 
117  if (edt_time) {
118  sprintf_s(buf, "%.1f", event->Time());
119  edt_time->SetText(buf);
120  }
121 
122  if (edt_delay) {
123  sprintf_s(buf, "%.1f", event->Delay());
124  edt_delay->SetText(buf);
125  }
126 
127  if (edt_event_chance) {
128  sprintf_s(buf, "%d", event->EventChance());
130  }
131 
132  sprintf_s(buf, "%d", event->EventParam());
134 
135  if (edt_trigger_param)
137 
138  if (edt_event_message)
140 
141  if (edt_event_sound)
143 
144  if (cmb_event) {
146 
147  for (int i = 0; i < MissionEvent::NUM_EVENTS; i++) {
149  }
150 
152  }
153 
154  if (cmb_trigger) {
156 
157  for (int i = 0; i < MissionEvent::NUM_TRIGGERS; i++) {
159  }
160 
162  }
163 }
164 
165 // +--------------------------------------------------------------------+
166 
167 void
168 MsnEventDlg::FillShipList(ComboBox* cmb, const char* seln)
169 {
170  if (!cmb) return;
171  cmb->ClearItems();
172 
173  if (!mission) return;
174 
175  int index = 1;
176  int selected_index = 0;
177  cmb->AddItem("");
178 
180  for (int i = 0; i < list.size(); i++) {
181  MissionElement* elem = list[i];
182 
183  if (elem->IsSquadron())
184  continue;
185 
186  if (elem->Count() == 1) {
187  cmb->AddItem(elem->Name());
188 
189  if (elem->Name() == seln)
190  selected_index = index;
191 
192  index++;
193  }
194  else {
195  char ship_name[256];
196 
197  for (int n = 0; n < elem->Count(); n++) {
198  sprintf_s(ship_name, "%s %d", elem->Name().data(), n+1);
199  cmb->AddItem(ship_name);
200 
201  if (!_stricmp(ship_name, seln))
202  selected_index = index;
203 
204  index++;
205  }
206  }
207  }
208 
209  cmb->SetSelection(selected_index);
210 }
211 
212 void
213 MsnEventDlg::FillRgnList(ComboBox* cmb, const char* seln)
214 {
215  if (!cmb) return;
216  cmb->ClearItems();
217 
218  if (!mission) return;
219 
220  int selected_index = 0;
221  int i = 0;
222 
224  while (++iter) {
225  StarSystem* sys = iter.value();
226 
227  ListIter<OrbitalRegion> iter2 = sys->AllRegions();
228  while (++iter2) {
229  OrbitalRegion* region = iter2.value();
230 
231  if (!strcmp(region->Name(), seln))
232  selected_index = i;
233 
234  cmb->AddItem(region->Name());
235  i++;
236  }
237  }
238 
239  cmb->SetSelection(selected_index);
240 }
241 
242 // +--------------------------------------------------------------------+
243 
244 void
246 {
247  if (Keyboard::KeyDown(VK_RETURN)) {
248  if (btn_accept && btn_accept->IsEnabled())
249  OnAccept(0);
250  }
251 }
252 
253 // +--------------------------------------------------------------------+
254 
255 void
257 {
258  mission = m;
259 }
260 
261 void
263 {
264  event = e;
265 }
266 
267 // +--------------------------------------------------------------------+
268 
269 void
271 {
274 
275  else
277 }
278 
279 // +--------------------------------------------------------------------+
280 
281 void
283 {
284  if (mission && event) {
285  char buf[64];
286  int val;
287 
288  if (edt_time) {
289  strcpy_s(buf, edt_time->GetText());
290 
291  float t = 0;
292  sscanf_s(buf, "%f", &t);
293 
294  event->time = t;
295  }
296 
297  if (edt_delay) {
298  strcpy_s(buf, edt_delay->GetText());
299 
300  float t = 0;
301  sscanf_s(buf, "%f", &t);
302 
303  event->delay = t;
304  }
305 
306  if (edt_event_param) {
307  strcpy_s(buf, edt_event_param->GetText());
308 
309  if (isdigit(*buf)) {
310  sscanf_s(buf, "%d", &val);
311  event->event_param[0] = val;
312  event->event_nparams = 1;
313  }
314  else if (*buf == '(') {
315  Parser parser(new(__FILE__,__LINE__) BlockReader(buf));
316  Term* term = parser.ParseTerm();
317 
318  if (term && term->isArray()) {
319  TermArray* val = term->isArray();
320  if (val) {
321  int nelem = val->elements()->size();
322 
323  if (nelem > 10)
324  nelem = 10;
325 
326  for (int i = 0; i < nelem; i++)
327  event->event_param[i] = (int) (val->elements()->at(i)->isNumber()->value());
328 
329  event->event_nparams = nelem;
330  }
331  }
332  }
333  }
334 
335  if (edt_event_chance) {
336  strcpy_s(buf, edt_event_chance->GetText());
337 
338  if (isdigit(*buf)) {
339  sscanf_s(buf, "%d", &val);
340  }
341  else {
342  val = 0;
343  }
344 
345  event->event_chance = val;
346  }
347 
348  if (edt_event_message)
349  event->event_message = edt_event_message->GetText();
350 
351  if (edt_event_sound)
352  event->event_sound = edt_event_sound->GetText();
353 
354  if (edt_trigger_param) {
355  strcpy_s(buf, edt_trigger_param->GetText());
356 
357  ZeroMemory(event->trigger_param, sizeof(event->trigger_param));
358 
359  if (isdigit(*buf)) {
360  sscanf_s(buf, "%d", &val);
361  event->trigger_param[0] = val;
362  event->trigger_nparams = 1;
363  }
364 
365  else if (*buf == '(') {
366  Parser parser(new(__FILE__,__LINE__) BlockReader(buf));
367  Term* term = parser.ParseTerm();
368 
369  if (term && term->isArray()) {
370  TermArray* val = term->isArray();
371  if (val) {
372  int nelem = val->elements()->size();
373 
374  if (nelem > 10)
375  nelem = 10;
376 
377  for (int i = 0; i < nelem; i++)
378  event->trigger_param[i] = (int) (val->elements()->at(i)->isNumber()->value());
379 
380  event->trigger_nparams = nelem;
381  }
382  }
383  }
384 
385  }
386 
387  if (cmb_event)
388  event->event = cmb_event->GetSelectedIndex();
389 
390  if (cmb_event_ship)
391  event->event_ship = cmb_event_ship->GetSelectedItem();
392 
393  if (cmb_event_source)
394  event->event_source = cmb_event_source->GetSelectedItem();
395 
396  if (cmb_event_target)
397  event->event_target = cmb_event_target->GetSelectedItem();
398 
399  if (cmb_trigger)
400  event->trigger = cmb_trigger->GetSelectedIndex();
401 
402  if (cmb_trigger_ship)
403  event->trigger_ship = cmb_trigger_ship->GetSelectedItem();
404 
405  if (cmb_trigger_target)
406  event->trigger_target = cmb_trigger_target->GetSelectedItem();
407  }
408 
410 }
411 
412 void
414 {
416 }