Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MsnEditNavDlg.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright (C) 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: MsnEditNavDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Mission Briefing Dialog Active Window class
13 */
14 
15 #include "MemDebug.h"
16 #include "MsnEditNavDlg.h"
17 #include "MsnEditDlg.h"
18 #include "MenuScreen.h"
19 #include "Campaign.h"
20 #include "Galaxy.h"
21 #include "Instruction.h"
22 #include "Mission.h"
23 #include "Ship.h"
24 #include "ShipDesign.h"
25 #include "StarSystem.h"
26 
27 // +--------------------------------------------------------------------+
28 // DECLARE MAPPING FUNCTIONS:
33 
34 // +--------------------------------------------------------------------+
35 
37 : NavDlg(s, def, mgr), menu_screen(mgr), mission_info(0),
38 btn_accept(0), btn_cancel(0), btn_sit(0), btn_pkg(0), btn_map(0)
39 {
41 }
42 
44 {
45 }
46 
47 // +--------------------------------------------------------------------+
48 
49 void
51 {
52  btn_accept = (Button*) FindControl( 1);
53  btn_cancel = (Button*) FindControl( 2);
54  btn_sit = (Button*) FindControl(301);
55  btn_pkg = (Button*) FindControl(302);
56  btn_map = (Button*) FindControl(303);
57 
58  txt_name = (EditBox*) FindControl(201);
59  cmb_type = (ComboBox*) FindControl(202);
62 
63  if (btn_accept)
65 
66  if (btn_cancel)
68 
69  if (btn_sit)
71 
72  if (btn_pkg)
74 
75  if (btn_map)
77 
78  if (cmb_system)
80 }
81 
82 // +--------------------------------------------------------------------+
83 
84 void
86 {
87  bool need_tab_update = !shown;
88 
89  NavDlg::Show();
90 
91  if (txt_name && cmb_type) {
92  txt_name->SetText("");
93 
94  if (cmb_system) {
96 
97  Galaxy* galaxy = Galaxy::GetInstance();
98  ListIter<StarSystem> iter = galaxy->GetSystemList();
99  while (++iter) {
100  cmb_system->AddItem(iter->Name());
101  }
102  }
103 
104  if (mission) {
105  int i;
106 
109 
110  StarSystem* sys = mission->GetStarSystem();
111  if (sys && cmb_system && cmb_region) {
112  for (i = 0; i < cmb_system->NumItems(); i++) {
113  if (!strcmp(cmb_system->GetItem(i), sys->Name())) {
115  break;
116  }
117  }
118 
120  int sel_rgn = 0;
121 
123  regions.append(sys->AllRegions());
124  regions.sort();
125 
126  i = 0;
128  while (++iter) {
129  OrbitalRegion* region = iter.value();
130  cmb_region->AddItem(region->Name());
131 
132  if (!strcmp(mission->GetRegion(), region->Name())) {
133  sel_rgn = i;
134  }
135 
136  i++;
137  }
138 
139  cmb_region->SetSelection(sel_rgn);
140  }
141  }
142  }
143 
144  if (need_tab_update) {
145  ShowTab(2);
146  }
147 
148  exit_latch = true;
149 }
150 
151 void
153 {
154  mission_info = m;
155 }
156 
157 // +--------------------------------------------------------------------+
158 
159 void
161 {
162  if (mission) {
163  if (txt_name) {
165  }
166 
167  if (cmb_type) {
169 
170  if (mission_info)
172  }
173 
174  Galaxy* galaxy = Galaxy::GetInstance();
175  StarSystem* system = 0;
176 
177  if (galaxy && cmb_system)
178  system = galaxy->GetSystem(cmb_system->GetSelectedItem());
179 
180  if (system) {
182  mission->SetStarSystem(system);
183 
184  if (mission_info)
185  mission_info->system = system->Name();
186  }
187 
188  if (cmb_region) {
190 
191  if (mission_info)
193  }
194 
195  SetSystem(system);
196  }
197 }
198 
199 // +--------------------------------------------------------------------+
200 
201 void
203 {
204  if (tab < 0 || tab > 2)
205  tab = 0;
206 
207  if (btn_sit) btn_sit->SetButtonState(tab == 0 ? 1 : 0);
208  if (btn_pkg) btn_pkg->SetButtonState(tab == 1 ? 1 : 0);
209  if (btn_map) btn_map->SetButtonState(tab == 2 ? 1 : 0);
210 
211  if (tab != 2) {
212  MsnEditDlg* msnEditDlg = menu_screen->GetMsnEditDlg();
213 
214  if (msnEditDlg)
215  msnEditDlg->ShowTab(tab);
216 
218  }
219 }
220 
221 // +--------------------------------------------------------------------+
222 
223 void
225 {
226  if (!event) return;
227 
228  if (event->window == btn_sit)
229  ShowTab(0);
230 
231  else if (event->window == btn_pkg)
232  ShowTab(1);
233 
234  else if (event->window == btn_map)
235  ShowTab(2);
236 }
237 
238 void
240 {
241  StarSystem* sys = 0;
242 
243  if (cmb_system) {
244  const char* name = cmb_system->GetSelectedItem();
245 
246  Galaxy* galaxy = Galaxy::GetInstance();
247  ListIter<StarSystem> iter = galaxy->GetSystemList();
248  while (++iter) {
249  StarSystem* s = iter.value();
250 
251  if (!strcmp(s->Name(), name)) {
252  sys = s;
253  break;
254  }
255  }
256  }
257 
258  if (sys && cmb_region) {
260 
262  regions.append(sys->AllRegions());
263  regions.sort();
264 
266  while (++iter) {
267  OrbitalRegion* region = iter.value();
268  cmb_region->AddItem(region->Name());
269  }
270  }
271 
272  ScrapeForm();
273 }
274 
275 
276 // +--------------------------------------------------------------------+
277 
278 void
280 {
281  if (mission) {
282  ScrapeForm();
283 
284  if (mission_info)
286 
287  mission->Save();
288  }
289 
291 }
292 
293 void
295 {
296  if (mission)
297  mission->Load();
298 
300 }