Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
CmdMissionsDlg.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: CmdMissionsDlg.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Operational Command Dialog (Mission List Tab)
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
CmdMissionsDlg.h
"
17
#include "
CmpnScreen.h
"
18
#include "
Starshatter.h
"
19
#include "
Campaign.h
"
20
#include "
Combatant.h
"
21
#include "
CombatAssignment.h
"
22
#include "
CombatGroup.h
"
23
#include "
CombatUnit.h
"
24
#include "
CombatZone.h
"
25
#include "
Mission.h
"
26
#include "
ShipDesign.h
"
27
#include "
Player.h
"
28
29
#include "
Game.h
"
30
#include "
DataLoader.h
"
31
#include "
Button.h
"
32
#include "
ComboBox.h
"
33
#include "
ListBox.h
"
34
#include "
Slider.h
"
35
#include "
Video.h
"
36
#include "
Keyboard.h
"
37
#include "
Mouse.h
"
38
#include "
ParseUtil.h
"
39
#include "
FormatUtil.h
"
40
41
// +--------------------------------------------------------------------+
42
// DECLARE MAPPING FUNCTIONS:
43
44
DEF_MAP_CLIENT
(
CmdMissionsDlg
, OnMode);
45
DEF_MAP_CLIENT
(
CmdMissionsDlg
, OnSave);
46
DEF_MAP_CLIENT
(
CmdMissionsDlg
, OnExit);
47
DEF_MAP_CLIENT
(
CmdMissionsDlg
, OnMission);
48
DEF_MAP_CLIENT
(
CmdMissionsDlg
, OnAccept);
49
50
// +--------------------------------------------------------------------+
51
52
CmdMissionsDlg::CmdMissionsDlg
(
Screen
* s,
FormDef
& def,
CmpnScreen
* mgr)
53
:
FormWindow
(s, 0, 0, s->Width(), s->Height()),
CmdDlg
(mgr), manager(mgr),
54
lst_missions(0), txt_desc(0), btn_accept(0),
55
stars(0), campaign(0), mission(0)
56
{
57
stars
=
Starshatter::GetInstance
();
58
campaign
=
Campaign::GetCampaign
();
59
60
Init
(def);
61
}
62
63
CmdMissionsDlg::~CmdMissionsDlg
()
64
{
65
}
66
67
// +--------------------------------------------------------------------+
68
69
void
70
CmdMissionsDlg::RegisterControls
()
71
{
72
lst_missions
= (
ListBox
*)
FindControl
(401);
73
txt_desc
=
FindControl
(402);
74
btn_accept
= (
Button
*)
FindControl
(403);
75
76
RegisterCmdControls
(
this
);
77
78
if
(
btn_save
)
79
REGISTER_CLIENT
(
EID_CLICK
,
btn_save
,
CmdMissionsDlg
,
OnSave
);
80
81
if
(
btn_exit
)
82
REGISTER_CLIENT
(
EID_CLICK
,
btn_exit
,
CmdMissionsDlg
,
OnExit
);
83
84
for
(
int
i = 0; i < 5; i++) {
85
if
(
btn_mode
[i])
86
REGISTER_CLIENT
(
EID_CLICK
,
btn_mode
[i],
CmdMissionsDlg
,
OnMode
);
87
}
88
89
if
(
lst_missions
) {
90
REGISTER_CLIENT
(
EID_SELECT
,
lst_missions
,
CmdMissionsDlg
,
OnMission
);
91
}
92
93
if
(
btn_accept
) {
94
btn_accept
->
SetEnabled
(
false
);
95
REGISTER_CLIENT
(
EID_CLICK
,
btn_accept
,
CmdMissionsDlg
,
OnAccept
);
96
}
97
}
98
99
// +--------------------------------------------------------------------+
100
101
void
102
CmdMissionsDlg::Show
()
103
{
104
mode
=
MODE_MISSIONS
;
105
106
FormWindow::Show
();
107
ShowCmdDlg
();
108
109
campaign
=
Campaign::GetCampaign
();
110
111
if
(
campaign
) {
112
if
(
lst_missions
) {
113
lst_missions
->
ClearItems
();
114
115
Player
* player =
Player::GetCurrentPlayer
();
116
List<MissionInfo>
& missions =
campaign
->
GetMissionList
();
117
for
(
int
i = 0; i < missions.
size
(); i++) {
118
MissionInfo
* info = missions[i];
119
lst_missions
->
AddItemWithData
(info->
name
, info->
id
);
120
121
Mission
* m = info->
mission
;
122
if
(m) {
123
if
(m->
Type
() ==
Mission::TRAINING
&& player->
HasTrained
(m->
Identity
())) {
124
lst_missions
->
SetItemText
(i, 1,
Game::GetText
(
"CmdMissionsDlg.training"
));
125
}
126
else
{
127
lst_missions
->
SetItemText
(i, 1, m->
TypeName
());
128
}
129
}
130
131
char
start_time[64];
132
FormatDayTime
(start_time, info->
start
);
133
lst_missions
->
SetItemText
(i, 2, start_time);
134
}
135
}
136
}
137
}
138
139
void
140
CmdMissionsDlg::ExecFrame
()
141
{
142
CmdDlg::ExecFrame
();
143
144
if
(
campaign
) {
145
List<MissionInfo>
& missions =
campaign
->
GetMissionList
();
146
Player
* player =
Player::GetCurrentPlayer
();
147
148
if
(missions.
size
() >
lst_missions
->
NumItems
()) {
149
while
(missions.
size
() >
lst_missions
->
NumItems
()) {
150
MissionInfo
* info = missions[
lst_missions
->
NumItems
()];
151
int
i =
lst_missions
->
AddItemWithData
(info->
name
, info->
id
) - 1;
152
153
Mission
* m = info->
mission
;
154
if
(m) {
155
if
(m->
Type
() ==
Mission::TRAINING
&& player->
HasTrained
(m->
Identity
())) {
156
lst_missions
->
SetItemText
(i, 1,
Game::GetText
(
"CmdMissionsDlg.training"
));
157
}
158
else
{
159
lst_missions
->
SetItemText
(i, 1, m->
TypeName
());
160
}
161
}
162
163
char
start_time[64];
164
FormatDayTime
(start_time, info->
start
);
165
lst_missions
->
SetItemText
(i, 2, start_time);
166
}
167
}
168
169
else
if
(missions.
size
() <
lst_missions
->
NumItems
()) {
170
lst_missions
->
ClearItems
();
171
172
for
(
int
i = 0; i < missions.
size
(); i++) {
173
MissionInfo
* info = missions[i];
174
lst_missions
->
AddItemWithData
(info->
name
, info->
id
);
175
176
Mission
* m = info->
mission
;
177
if
(m) {
178
if
(m->
Type
() ==
Mission::TRAINING
&& player->
HasTrained
(m->
Identity
())) {
179
lst_missions
->
SetItemText
(i, 1,
Game::GetText
(
"CmdMissionsDlg.training"
));
180
}
181
else
{
182
lst_missions
->
SetItemText
(i, 1, m->
TypeName
());
183
}
184
}
185
186
char
start_time[64];
187
FormatDayTime
(start_time, info->
start
);
188
lst_missions
->
SetItemText
(i, 2, start_time);
189
}
190
}
191
192
else
if
(missions.
size
() > 0 &&
lst_missions
->
NumItems
() > 0) {
193
int
id
=
lst_missions
->
GetItemData
(0);
194
MissionInfo
* info =
campaign
->
GetMissionInfo
(
id
);
195
196
if
(!info) {
197
int
seln = -1;
198
int
seln_id = 0;
199
200
for
(
int
i = 0; i <
lst_missions
->
NumItems
(); i++)
201
if
(
lst_missions
->
IsSelected
(i))
202
seln = i;
203
204
if
(seln >= 0)
205
seln_id =
lst_missions
->
GetItemData
(seln);
206
207
lst_missions
->
ClearItems
();
208
seln = -1;
209
210
for
(
int
i = 0; i < missions.
size
(); i++) {
211
MissionInfo
* info = missions[i];
212
lst_missions
->
AddItemWithData
(info->
name
, info->
id
);
213
214
Mission
* m = info->
mission
;
215
if
(m) {
216
if
(m->
Type
() ==
Mission::TRAINING
&& player->
HasTrained
(m->
Identity
())) {
217
lst_missions
->
SetItemText
(i, 1,
Game::GetText
(
"CmdMissionsDlg.training"
));
218
}
219
else
{
220
lst_missions
->
SetItemText
(i, 1, m->
TypeName
());
221
}
222
}
223
224
char
start_time[64];
225
FormatDayTime
(start_time, info->
start
);
226
lst_missions
->
SetItemText
(i, 2, start_time);
227
228
if
(info->
id
== seln_id)
229
seln = i;
230
}
231
232
if
(seln >= 0)
233
lst_missions
->
SetSelected
(seln);
234
}
235
}
236
237
bool
found =
false
;
238
239
for
(
int
i = 0; i < missions.
size
() && !found; i++) {
240
MissionInfo
* info = missions[i];
241
if
(info->
mission
==
mission
)
242
found =
true
;
243
}
244
245
if
(!found) {
246
mission
= 0;
247
txt_desc
->
SetText
(
""
);
248
btn_accept
->
SetEnabled
(
false
);
249
}
250
}
251
}
252
253
// +--------------------------------------------------------------------+
254
255
void
256
CmdMissionsDlg::OnSave
(
AWEvent
* event)
257
{
258
CmdDlg::OnSave
(event);
259
}
260
261
void
262
CmdMissionsDlg::OnExit
(
AWEvent
* event)
263
{
264
CmdDlg::OnExit
(event);
265
}
266
267
void
268
CmdMissionsDlg::OnMode
(
AWEvent
* event)
269
{
270
CmdDlg::OnMode
(event);
271
}
272
273
274
// +--------------------------------------------------------------------+
275
276
void
277
CmdMissionsDlg::OnMission
(
AWEvent
* event)
278
{
279
if
(
campaign
&&
lst_missions
) {
280
MissionInfo
* info = 0;
281
mission
= 0;
282
283
for
(
int
i = 0; i <
lst_missions
->
NumItems
(); i++) {
284
if
(
lst_missions
->
IsSelected
(i)) {
285
int
id
=
lst_missions
->
GetItemData
(i);
286
info =
campaign
->
GetMissionInfo
(
id
);
287
}
288
}
289
290
btn_accept
->
SetEnabled
((info != 0) ?
true
:
false
);
291
292
if
(info) {
293
Text
desc
(
"<font Limerick12><color ffff80>"
);
294
desc += info->
name
;
295
desc +=
"<font Verdana><color ffffff>\n\n"
;
296
desc += info->
player_info
;
297
desc +=
"\n\n"
;
298
desc += info->
description
;
299
300
txt_desc
->
SetText
(desc);
301
mission
= info->
mission
;
302
}
303
else
{
304
txt_desc
->
SetText
(
" "
);
305
}
306
}
307
}
308
309
// +--------------------------------------------------------------------+
310
311
void
312
CmdMissionsDlg::OnAccept
(
AWEvent
* event)
313
{
314
if
(!
campaign
|| !
mission
) {
315
::Print
(
" ERROR CMD::Accept campaign=0x%08x mission=0x%08x\n"
,
campaign
,
mission
);
316
return
;
317
}
318
319
::Print
(
" CMD::Accept Mission %d\n"
,
mission
->
Identity
());
320
321
Mouse::Show
(
false
);
322
campaign
->
SetMissionId
(
mission
->
Identity
());
323
campaign
->
StartMission
();
324
stars
->
SetGameMode
(
Starshatter::PREP_MODE
);
325
}
Stars45
CmdMissionsDlg.cpp
Generated on Tue Jun 5 2012 20:46:48 for Starshatter_Open by
1.8.1