Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
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:
29
DEF_MAP_CLIENT
(
MsnEditNavDlg
,
OnCommit
);
30
DEF_MAP_CLIENT
(
MsnEditNavDlg
,
OnCancel
);
31
DEF_MAP_CLIENT
(
MsnEditNavDlg
,
OnTabButton
);
32
DEF_MAP_CLIENT
(
MsnEditNavDlg
,
OnSystemSelect
);
33
34
// +--------------------------------------------------------------------+
35
36
MsnEditNavDlg::MsnEditNavDlg
(
Screen
* s,
FormDef
& def,
MenuScreen
* mgr)
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
{
40
RegisterControls
();
41
}
42
43
MsnEditNavDlg::~MsnEditNavDlg
()
44
{
45
}
46
47
// +--------------------------------------------------------------------+
48
49
void
50
MsnEditNavDlg::RegisterControls
()
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);
60
cmb_system
= (
ComboBox
*)
FindControl
(203);
61
cmb_region
= (
ComboBox
*)
FindControl
(204);
62
63
if
(
btn_accept
)
64
REGISTER_CLIENT
(
EID_CLICK
,
btn_accept
,
MsnEditNavDlg
,
OnCommit
);
65
66
if
(
btn_cancel
)
67
REGISTER_CLIENT
(
EID_CLICK
,
btn_cancel
,
MsnEditNavDlg
,
OnCancel
);
68
69
if
(
btn_sit
)
70
REGISTER_CLIENT
(
EID_CLICK
,
btn_sit
,
MsnEditNavDlg
,
OnTabButton
);
71
72
if
(
btn_pkg
)
73
REGISTER_CLIENT
(
EID_CLICK
,
btn_pkg
,
MsnEditNavDlg
,
OnTabButton
);
74
75
if
(
btn_map
)
76
REGISTER_CLIENT
(
EID_CLICK
,
btn_map
,
MsnEditNavDlg
,
OnTabButton
);
77
78
if
(
cmb_system
)
79
REGISTER_CLIENT
(
EID_SELECT
,
cmb_system
,
MsnEditNavDlg
,
OnSystemSelect
);
80
}
81
82
// +--------------------------------------------------------------------+
83
84
void
85
MsnEditNavDlg::Show
()
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
) {
95
cmb_system
->
ClearItems
();
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
107
txt_name
->
SetText
(
mission
->
Name
());
108
cmb_type
->
SetSelection
(
mission
->
Type
());
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
())) {
114
cmb_system
->
SetSelection
(i);
115
break
;
116
}
117
}
118
119
cmb_region
->
ClearItems
();
120
int
sel_rgn = 0;
121
122
List<OrbitalRegion>
regions
;
123
regions.
append
(sys->
AllRegions
());
124
regions.
sort
();
125
126
i = 0;
127
ListIter<OrbitalRegion>
iter =
regions
;
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
152
MsnEditNavDlg::SetMissionInfo
(
MissionInfo
* m)
153
{
154
mission_info
= m;
155
}
156
157
// +--------------------------------------------------------------------+
158
159
void
160
MsnEditNavDlg::ScrapeForm
()
161
{
162
if
(
mission
) {
163
if
(
txt_name
) {
164
mission
->
SetName
(
txt_name
->
GetText
());
165
}
166
167
if
(
cmb_type
) {
168
mission
->
SetType
(
cmb_type
->
GetSelectedIndex
());
169
170
if
(
mission_info
)
171
mission_info
->
type
=
cmb_type
->
GetSelectedIndex
();
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) {
181
mission
->
ClearSystemList
();
182
mission
->
SetStarSystem
(system);
183
184
if
(
mission_info
)
185
mission_info
->
system
= system->
Name
();
186
}
187
188
if
(
cmb_region
) {
189
mission
->
SetRegion
(
cmb_region
->
GetSelectedItem
());
190
191
if
(
mission_info
)
192
mission_info
->
region
=
cmb_region
->
GetSelectedItem
();
193
}
194
195
SetSystem
(system);
196
}
197
}
198
199
// +--------------------------------------------------------------------+
200
201
void
202
MsnEditNavDlg::ShowTab
(
int
tab
)
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
217
menu_screen
->
ShowMsnEditDlg
();
218
}
219
}
220
221
// +--------------------------------------------------------------------+
222
223
void
224
MsnEditNavDlg::OnTabButton
(
AWEvent
*
event
)
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
239
MsnEditNavDlg::OnSystemSelect
(
AWEvent
*
event
)
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
) {
259
cmb_region
->
ClearItems
();
260
261
List<OrbitalRegion>
regions
;
262
regions.
append
(sys->
AllRegions
());
263
regions.
sort
();
264
265
ListIter<OrbitalRegion>
iter =
regions
;
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
279
MsnEditNavDlg::OnCommit
(
AWEvent
*
event
)
280
{
281
if
(
mission
) {
282
ScrapeForm
();
283
284
if
(
mission_info
)
285
mission_info
->
name
=
mission
->
Name
();
286
287
mission
->
Save
();
288
}
289
290
menu_screen
->
ShowMsnSelectDlg
();
291
}
292
293
void
294
MsnEditNavDlg::OnCancel
(
AWEvent
*
event
)
295
{
296
if
(
mission
)
297
mission
->
Load
();
298
299
menu_screen
->
ShowMsnSelectDlg
();
300
}
Stars45
MsnEditNavDlg.cpp
Generated on Tue Jun 5 2012 20:46:59 for Starshatter_Open by
1.8.1