Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
QuitView.cpp
Go to the documentation of this file.
1
/* Project Starshatter 5.0
2
Destroyer Studios LLC
3
Copyright © 1997-2007. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: QuitView.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
View class for End Mission menu
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
QuitView.h
"
17
#include "
HUDView.h
"
18
#include "
RadioView.h
"
19
#include "
Ship.h
"
20
#include "
Contact.h
"
21
#include "
Sim.h
"
22
#include "
SimEvent.h
"
23
#include "
Campaign.h
"
24
#include "
Starshatter.h
"
25
#include "
GameScreen.h
"
26
27
#include "
CameraView.h
"
28
#include "
Color.h
"
29
#include "
Window.h
"
30
#include "
Video.h
"
31
#include "
Screen.h
"
32
#include "
DataLoader.h
"
33
#include "
Scene.h
"
34
#include "
FontMgr.h
"
35
#include "
Button.h
"
36
#include "
Keyboard.h
"
37
#include "
Mouse.h
"
38
#include "
MouseController.h
"
39
#include "
Game.h
"
40
#include "
Menu.h
"
41
42
// +====================================================================+
43
44
static
bool
show_menu =
false
;
45
static
Bitmap
* menu_bmp = 0;
46
static
MouseController
* mouse_con = 0;
47
static
bool
mouse_active =
false
;
48
static
const
int
w2 = 200;
49
static
const
int
h2 = 128;
50
51
void
52
QuitView::Initialize
()
53
{
54
if
(!menu_bmp) {
55
menu_bmp =
new
(__FILE__,__LINE__)
Bitmap
;
56
57
DataLoader
* loader =
DataLoader::GetLoader
();
58
loader->
SetDataPath
(
"Screens/"
);
59
loader->
LoadBitmap
(
"QuitWin.pcx"
, *menu_bmp,
Bitmap::BMP_TRANSPARENT
);
60
loader->
SetDataPath
(0);
61
}
62
}
63
64
void
65
QuitView::Close
()
66
{
67
delete
menu_bmp;
68
}
69
70
// +====================================================================+
71
72
QuitView
*
QuitView::quit_view
= 0;
73
74
QuitView::QuitView
(
Window
* c)
75
:
View
(c), mouse_latch(false)
76
{
77
quit_view
=
this
;
78
sim
=
Sim::GetSim
();
79
80
width
=
window
->
Width
();
81
height
=
window
->
Height
();
82
xcenter
=
width
/ 2;
83
ycenter
=
height
/ 2;
84
85
mouse_con =
MouseController::GetInstance
();
86
}
87
88
QuitView::~QuitView
()
89
{
90
quit_view
= 0;
91
}
92
93
void
94
QuitView::OnWindowMove
()
95
{
96
width
=
window
->
Width
();
97
height
=
window
->
Height
();
98
xcenter
=
width
/ 2;
99
ycenter
=
height
/ 2;
100
}
101
102
// +--------------------------------------------------------------------+
103
104
void
105
QuitView::Refresh
()
106
{
107
if
(show_menu && menu_bmp) {
108
Rect
clip_rect;
109
110
clip_rect.
x
=
xcenter
- w2;
111
clip_rect.
y
=
ycenter
- h2;
112
clip_rect.
w
= w2 * 2;
113
clip_rect.
h
= h2 * 2;
114
115
window
->
ClipBitmap
(
xcenter
- w2,
116
ycenter
- h2,
117
xcenter
- w2 + menu_bmp->
Width
(),
118
ycenter
- h2 + menu_bmp->
Height
(),
119
menu_bmp,
120
Color::White
,
121
Video::BLEND_SOLID
,
122
clip_rect);
123
}
124
}
125
126
// +--------------------------------------------------------------------+
127
128
void
129
QuitView::ExecFrame
()
130
{
131
sim
=
Sim::GetSim
();
132
133
if
(show_menu) {
134
Color::SetFade
(1,
Color::Black
, 0);
135
int
action = 0;
136
137
if
(
Mouse::LButton
()) {
138
mouse_latch
=
true
;
139
}
140
else
if
(
mouse_latch
) {
141
mouse_latch
=
false
;
142
143
if
(
Mouse::X
() >
xcenter
- w2 &&
Mouse::X
() <
xcenter
+ w2) {
144
int
y0 =
ycenter
- h2;
145
146
for
(
int
i = 0; i < 4; i++)
147
if
(
Mouse::Y
() >= y0 + 75 + i * 30 &&
Mouse::Y
() <= y0 + 105 + i * 30)
148
action = i+1;
149
}
150
}
151
152
for
(
int
i = 1; i <= 4; i++) {
153
if
(
Keyboard::KeyDown
(
'0'
+ i))
154
action = i;
155
}
156
157
// was mission long enough to accept?
158
if
(action == 1 && !
CanAccept
()) {
159
Button::PlaySound
(
Button::SND_REJECT
);
160
action = 3;
161
}
162
163
// exit and accept:
164
if
(action == 1) {
165
CloseMenu
();
166
Game::SetTimeCompression
(1);
167
168
Starshatter
* stars =
Starshatter::GetInstance
();
169
stars->
SetGameMode
(
Starshatter::PLAN_MODE
);
170
}
171
172
// quit and discard results:
173
else
if
(action == 2) {
174
CloseMenu
();
175
Game::SetTimeCompression
(1);
176
177
Starshatter
* stars =
Starshatter::GetInstance
();
178
Campaign
* campaign =
Campaign::GetCampaign
();
179
180
// discard mission and events:
181
if
(
sim
)
sim
->
UnloadMission
();
182
else
ShipStats::Initialize
();
183
184
if
(campaign && campaign->
GetCampaignId
() <
Campaign::SINGLE_MISSIONS
) {
185
campaign->
RollbackMission
();
186
stars->
SetGameMode
(
Starshatter::CMPN_MODE
);
187
}
188
189
else
{
190
stars->
SetGameMode
(
Starshatter::MENU_MODE
);
191
}
192
}
193
194
// resume:
195
else
if
(action == 3) {
196
CloseMenu
();
197
}
198
199
// controls:
200
else
if
(action == 4) {
201
GameScreen
* game_screen =
GameScreen::GetInstance
();
202
203
if
(game_screen)
204
game_screen->
ShowCtlDlg
();
205
else
206
CloseMenu
();
207
}
208
}
209
}
210
211
// +--------------------------------------------------------------------+
212
213
bool
214
QuitView::IsMenuShown
()
215
{
216
return
show_menu;
217
}
218
219
// +--------------------------------------------------------------------+
220
221
bool
222
QuitView::CanAccept
()
223
{
224
sim
=
Sim::GetSim
();
225
226
if
(!
sim
||
sim
->
IsNetGame
())
227
return
true
;
228
229
Ship
* player_ship =
sim
->
GetPlayerShip
();
230
231
if
(player_ship->
MissionClock
() < 60000) {
232
RadioView::Message
(
Game::GetText
(
"QuitView.too-soon"
));
233
RadioView::Message
(
Game::GetText
(
"QuitView.abort"
));
234
return
false
;
235
}
236
237
ListIter<Contact>
iter = player_ship->
ContactList
();
238
while
(++iter) {
239
Contact
* c = iter.
value
();
240
Ship
* cship = c->
GetShip
();
241
int
ciff = c->
GetIFF
(player_ship);
242
243
if
(c->
Threat
(player_ship)) {
244
RadioView::Message
(
Game::GetText
(
"QuitView.threats-present"
));
245
RadioView::Message
(
Game::GetText
(
"QuitView.abort"
));
246
return
false
;
247
}
248
249
else
if
(cship && ciff > 0 && ciff != player_ship->
GetIFF
()) {
250
Point
delta = c->
Location
() - player_ship->
Location
();
251
double
dist = delta.
length
();
252
253
if
(cship->
IsDropship
() && dist < 50e3) {
254
RadioView::Message
(
Game::GetText
(
"QuitView.threats-present"
));
255
RadioView::Message
(
Game::GetText
(
"QuitView.abort"
));
256
return
false
;
257
}
258
259
else
if
(cship->
IsStarship
() && dist < 100e3) {
260
RadioView::Message
(
Game::GetText
(
"QuitView.threats-present"
));
261
RadioView::Message
(
Game::GetText
(
"QuitView.abort"
));
262
return
false
;
263
}
264
}
265
}
266
267
return
true
;
268
}
269
270
void
271
QuitView::ShowMenu
()
272
{
273
if
(!show_menu) {
274
show_menu =
true
;
275
276
for
(
int
i = 0; i < 10; i++) {
277
if
(
Keyboard::KeyDown
(
'1'
+ i)) {
278
// just need to clear the key down flag
279
// so we don't process old keystrokes
280
// as valid menu picks...
281
}
282
}
283
284
Button::PlaySound
(
Button::SND_CONFIRM
);
285
Starshatter::GetInstance
()->Pause(
true
);
286
287
if
(mouse_con) {
288
mouse_active = mouse_con->
Active
();
289
mouse_con->
SetActive
(
false
);
290
}
291
}
292
}
293
294
void
295
QuitView::CloseMenu
()
296
{
297
show_menu =
false
;
298
Starshatter::GetInstance
()->Pause(
false
);
299
300
if
(mouse_con)
301
mouse_con->
SetActive
(mouse_active);
302
}
Stars45
QuitView.cpp
Generated on Thu May 31 2012 16:31:14 for Starshatter_Open by
1.8.1