Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
OptDlg.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: OptDlg.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Main Menu Dialog Active Window class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
OptDlg.h
"
17
#include "
MenuScreen.h
"
18
#include "
Starshatter.h
"
19
#include "
Ship.h
"
20
#include "
HUDView.h
"
21
#include "
Player.h
"
22
23
#include "
DataLoader.h
"
24
#include "
Button.h
"
25
#include "
ListBox.h
"
26
#include "
Slider.h
"
27
#include "
Video.h
"
28
#include "
Keyboard.h
"
29
#include "
MachineInfo.h
"
30
31
// +--------------------------------------------------------------------+
32
// DECLARE MAPPING FUNCTIONS:
33
34
DEF_MAP_CLIENT
(
OptDlg
, OnApply);
35
DEF_MAP_CLIENT
(
OptDlg
, OnCancel);
36
DEF_MAP_CLIENT
(
OptDlg
, OnEnter);
37
DEF_MAP_CLIENT
(
OptDlg
, OnExit);
38
DEF_MAP_CLIENT
(
OptDlg
, OnAudio);
39
DEF_MAP_CLIENT
(
OptDlg
, OnVideo);
40
DEF_MAP_CLIENT
(
OptDlg
, OnOptions);
41
DEF_MAP_CLIENT
(
OptDlg
, OnControls);
42
DEF_MAP_CLIENT
(
OptDlg
, OnMod);
43
44
// +--------------------------------------------------------------------+
45
46
OptDlg::OptDlg
(
Screen
* s,
FormDef
& def,
BaseScreen
* mgr)
47
:
FormWindow
(s, 0, 0, s->Width(), s->Height()), manager(mgr),
48
apply(0), cancel(0), vid_btn(0), aud_btn(0), ctl_btn(0), opt_btn(0), mod_btn(0),
49
closed(true)
50
{
51
Init
(def);
52
}
53
54
OptDlg::~OptDlg
()
55
{
56
}
57
58
// +--------------------------------------------------------------------+
59
60
void
61
OptDlg::RegisterControls
()
62
{
63
if
(
apply
)
64
return
;
65
66
flight_model
= (
ComboBox
*)
FindControl
(201);
67
flying_start
= (
ComboBox
*)
FindControl
(211);
68
landings
= (
ComboBox
*)
FindControl
(202);
69
ai_difficulty
= (
ComboBox
*)
FindControl
(203);
70
hud_mode
= (
ComboBox
*)
FindControl
(204);
71
hud_color
= (
ComboBox
*)
FindControl
(205);
72
ff_mode
= (
ComboBox
*)
FindControl
(206);
73
grid_mode
= (
ComboBox
*)
FindControl
(207);
74
gunsight
= (
ComboBox
*)
FindControl
(208);
75
description
=
FindControl
(500);
76
apply
= (
Button
*)
FindControl
(1);
77
cancel
= (
Button
*)
FindControl
(2);
78
vid_btn
= (
Button
*)
FindControl
(901);
79
aud_btn
= (
Button
*)
FindControl
(902);
80
ctl_btn
= (
Button
*)
FindControl
(903);
81
opt_btn
= (
Button
*)
FindControl
(904);
82
mod_btn
= (
Button
*)
FindControl
(905);
83
84
if
(
flight_model
) {
85
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
flight_model
,
OptDlg
,
OnEnter
);
86
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
flight_model
,
OptDlg
,
OnExit
);
87
}
88
89
if
(
flying_start
) {
90
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
flying_start
,
OptDlg
,
OnEnter
);
91
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
flying_start
,
OptDlg
,
OnExit
);
92
}
93
94
if
(
landings
) {
95
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
landings
,
OptDlg
,
OnEnter
);
96
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
landings
,
OptDlg
,
OnExit
);
97
}
98
99
if
(
ai_difficulty
) {
100
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
ai_difficulty
,
OptDlg
,
OnEnter
);
101
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
ai_difficulty
,
OptDlg
,
OnExit
);
102
}
103
104
if
(
hud_mode
) {
105
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
hud_mode
,
OptDlg
,
OnEnter
);
106
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
hud_mode
,
OptDlg
,
OnExit
);
107
}
108
109
if
(
hud_color
) {
110
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
hud_color
,
OptDlg
,
OnEnter
);
111
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
hud_color
,
OptDlg
,
OnExit
);
112
}
113
114
if
(
ff_mode
) {
115
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
ff_mode
,
OptDlg
,
OnEnter
);
116
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
ff_mode
,
OptDlg
,
OnExit
);
117
}
118
119
if
(
grid_mode
) {
120
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
grid_mode
,
OptDlg
,
OnEnter
);
121
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
grid_mode
,
OptDlg
,
OnExit
);
122
}
123
124
if
(
gunsight
) {
125
REGISTER_CLIENT
(
EID_MOUSE_ENTER
,
gunsight
,
OptDlg
,
OnEnter
);
126
REGISTER_CLIENT
(
EID_MOUSE_EXIT
,
gunsight
,
OptDlg
,
OnExit
);
127
}
128
129
if
(
apply
)
130
REGISTER_CLIENT
(
EID_CLICK
,
apply
,
OptDlg
,
OnApply
);
131
132
if
(
cancel
)
133
REGISTER_CLIENT
(
EID_CLICK
,
cancel
,
OptDlg
,
OnCancel
);
134
135
if
(
vid_btn
)
136
REGISTER_CLIENT
(
EID_CLICK
,
vid_btn
,
OptDlg
,
OnVideo
);
137
138
if
(
aud_btn
)
139
REGISTER_CLIENT
(
EID_CLICK
,
aud_btn
,
OptDlg
,
OnAudio
);
140
141
if
(
ctl_btn
)
142
REGISTER_CLIENT
(
EID_CLICK
,
ctl_btn
,
OptDlg
,
OnControls
);
143
144
if
(
opt_btn
)
145
REGISTER_CLIENT
(
EID_CLICK
,
opt_btn
,
OptDlg
,
OnOptions
);
146
147
if
(
mod_btn
)
148
REGISTER_CLIENT
(
EID_CLICK
,
mod_btn
,
OptDlg
,
OnMod
);
149
}
150
151
// +--------------------------------------------------------------------+
152
153
void
154
OptDlg::Show
()
155
{
156
FormWindow::Show
();
157
158
if
(
closed
) {
159
Starshatter
* stars =
Starshatter::GetInstance
();
160
161
if
(stars) {
162
if
(
flight_model
)
163
flight_model
->
SetSelection
(
Ship::GetFlightModel
());
164
165
if
(
landings
)
166
landings
->
SetSelection
(
Ship::GetLandingModel
());
167
168
if
(
hud_mode
)
169
hud_mode
->
SetSelection
(
HUDView::IsArcade
() ? 1 : 0);
170
171
if
(
hud_color
)
172
hud_color
->
SetSelection
(
HUDView::DefaultColorSet
());
173
174
if
(
ff_mode
)
175
ff_mode
->
SetSelection
((
int
) (
Ship::GetFriendlyFireLevel
() * 4));
176
}
177
178
Player
* player =
Player::GetCurrentPlayer
();
179
if
(player) {
180
if
(
flying_start
)
181
flying_start
->
SetSelection
(player->
FlyingStart
());
182
183
if
(
ai_difficulty
)
184
ai_difficulty
->
SetSelection
(
ai_difficulty
->
NumItems
() - player->
AILevel
() - 1);
185
186
if
(
grid_mode
)
187
grid_mode
->
SetSelection
(player->
GridMode
());
188
189
if
(
gunsight
)
190
gunsight
->
SetSelection
(player->
Gunsight
());
191
}
192
}
193
194
if
(
vid_btn
)
vid_btn
->
SetButtonState
(0);
195
if
(
aud_btn
)
aud_btn
->
SetButtonState
(0);
196
if
(
ctl_btn
)
ctl_btn
->
SetButtonState
(0);
197
if
(
opt_btn
)
opt_btn
->
SetButtonState
(1);
198
if
(
mod_btn
)
mod_btn
->
SetButtonState
(0);
199
200
closed
=
false
;
201
}
202
203
// +--------------------------------------------------------------------+
204
205
void
206
OptDlg::ExecFrame
()
207
{
208
if
(
Keyboard::KeyDown
(VK_RETURN)) {
209
OnApply
(0);
210
}
211
}
212
213
// +--------------------------------------------------------------------+
214
215
void
OptDlg::OnAudio
(
AWEvent
* event) {
manager
->
ShowAudDlg
(); }
216
void
OptDlg::OnVideo
(
AWEvent
* event) {
manager
->
ShowVidDlg
(); }
217
void
OptDlg::OnOptions
(
AWEvent
* event) {
manager
->
ShowOptDlg
(); }
218
void
OptDlg::OnControls
(
AWEvent
* event) {
manager
->
ShowCtlDlg
(); }
219
void
OptDlg::OnMod
(
AWEvent
* event) {
manager
->
ShowModDlg
(); }
220
221
// +--------------------------------------------------------------------+
222
223
void
224
OptDlg::OnApply
(
AWEvent
* event)
225
{
226
manager
->
ApplyOptions
();
227
}
228
229
void
230
OptDlg::OnCancel
(
AWEvent
* event)
231
{
232
manager
->
CancelOptions
();
233
}
234
235
// +--------------------------------------------------------------------+
236
237
void
238
OptDlg::OnEnter
(
AWEvent
* event)
239
{
240
ActiveWindow
* src =
event
->window;
241
242
if
(src &&
description
)
243
description
->
SetText
(src->
GetAltText
());
244
}
245
246
void
247
OptDlg::OnExit
(
AWEvent
* event)
248
{
249
ComboBox
* cmb = (
ComboBox
*) event->
window
;
250
251
if (!cmb || cmb->
IsListShowing
())
252
return
;
253
254
if
(
description
)
255
description
->
SetText
(
""
);
256
}
257
258
// +--------------------------------------------------------------------+
259
260
void
261
OptDlg::Apply
()
262
{
263
if
(
closed
)
return
;
264
265
Player
* player =
Player::GetCurrentPlayer
();
266
if
(player) {
267
if
(
flight_model
)
268
player->
SetFlightModel
(
flight_model
->
GetSelectedIndex
());
269
270
if
(
flying_start
)
271
player->
SetFlyingStart
(
flying_start
->
GetSelectedIndex
());
272
273
if
(
landings
)
274
player->
SetLandingModel
(
landings
->
GetSelectedIndex
());
275
276
if
(
ai_difficulty
)
277
player->
SetAILevel
(
ai_difficulty
->
NumItems
() -
ai_difficulty
->
GetSelectedIndex
() - 1);
278
279
if
(
hud_mode
)
280
player->
SetHUDMode
(
hud_mode
->
GetSelectedIndex
());
281
282
if
(
hud_color
)
283
player->
SetHUDColor
(
hud_color
->
GetSelectedIndex
());
284
285
if
(
ff_mode
)
286
player->
SetFriendlyFire
(
ff_mode
->
GetSelectedIndex
());
287
288
if
(
grid_mode
)
289
player->
SetGridMode
(
grid_mode
->
GetSelectedIndex
());
290
291
if
(
gunsight
)
292
player->
SetGunsight
(
gunsight
->
GetSelectedIndex
());
293
294
Player::Save
();
295
}
296
297
if
(
flight_model
)
298
Ship::SetFlightModel
(
flight_model
->
GetSelectedIndex
());
299
300
if
(
landings
)
301
Ship::SetLandingModel
(
landings
->
GetSelectedIndex
());
302
303
if
(
hud_mode
)
304
HUDView::SetArcade
(
hud_mode
->
GetSelectedIndex
() > 0);
305
306
if
(
hud_color
)
307
HUDView::SetDefaultColorSet
(
hud_color
->
GetSelectedIndex
());
308
309
if
(
ff_mode
)
310
Ship::SetFriendlyFireLevel
(
ff_mode
->
GetSelectedIndex
() / 4.0);
311
312
HUDView
* hud =
HUDView::GetInstance
();
313
if
(hud) hud->
SetHUDColorSet
(
hud_color
->
GetSelectedIndex
());
314
315
closed
=
true
;
316
}
317
318
void
319
OptDlg::Cancel
()
320
{
321
closed
=
true
;
322
}
Stars45
OptDlg.cpp
Generated on Tue Jun 5 2012 20:47:06 for Starshatter_Open by
1.8.1