Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CmpnScreen.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2006. All Rights Reserved.
4 
5  SUBSYSTEM: Stars
6  FILE: CmpnScreen.cpp
7  AUTHOR: John DiCamillo
8 
9 */
10 
11 #include "MemDebug.h"
12 #include "CmpnScreen.h"
13 
14 #include "CmdForceDlg.h"
15 #include "CmdMissionsDlg.h"
16 #include "CmdOrdersDlg.h"
17 #include "CmdTheaterDlg.h"
18 #include "CmdIntelDlg.h"
19 #include "CmpCompleteDlg.h"
20 #include "CmdMsgDlg.h"
21 #include "CmpFileDlg.h"
22 #include "CmpSceneDlg.h"
23 #include "Campaign.h"
24 #include "CombatEvent.h"
25 #include "Mission.h"
26 #include "Sim.h"
27 #include "Starshatter.h"
28 #include "StarSystem.h"
29 #include "Player.h"
30 #include "MusicDirector.h"
31 
32 #include "Game.h"
33 #include "Video.h"
34 #include "Screen.h"
35 #include "Window.h"
36 #include "ActiveWindow.h"
37 #include "FormDef.h"
38 #include "Mouse.h"
39 #include "Color.h"
40 #include "Bitmap.h"
41 #include "Font.h"
42 #include "FontMgr.h"
43 #include "EventDispatch.h"
44 #include "DataLoader.h"
45 #include "Resource.h"
46 
47 // +--------------------------------------------------------------------+
48 
50 : screen(0),
51 cmd_force_dlg(0), cmd_missions_dlg(0), cmd_orders_dlg(0),
52 cmd_intel_dlg(0), cmd_theater_dlg(0), cmd_msg_dlg(0), cmp_file_dlg(0),
53 cmp_end_dlg(0), cmp_scene_dlg(0),
54 isShown(false), campaign(0), stars(0), completion_stage(0)
55 {
56  loader = DataLoader::GetLoader();
57  stars = Starshatter::GetInstance();
58 }
59 
61 {
62  TearDown();
63 }
64 
65 // +--------------------------------------------------------------------+
66 
67 void
69 {
70  if (!s)
71  return;
72 
73  screen = s;
74 
75  loader->UseFileSystem(true);
76 
77  FormDef cmd_orders_def("CmdOrdersDlg", 0);
78  cmd_orders_def.Load("CmdOrdersDlg");
79  cmd_orders_dlg = new(__FILE__,__LINE__) CmdOrdersDlg(screen, cmd_orders_def, this);
80 
81  FormDef cmd_force_def("CmdForceDlg", 0);
82  cmd_force_def.Load("CmdForceDlg");
83  cmd_force_dlg = new(__FILE__,__LINE__) CmdForceDlg(screen, cmd_force_def, this);
84 
85  FormDef cmd_theater_def("CmdTheaterDlg", 0);
86  cmd_theater_def.Load("CmdTheaterDlg");
87  cmd_theater_dlg = new(__FILE__,__LINE__) CmdTheaterDlg(screen, cmd_theater_def, this);
88 
89  FormDef cmd_intel_def("CmdIntelDlg", 0);
90  cmd_intel_def.Load("CmdIntelDlg");
91  cmd_intel_dlg = new(__FILE__,__LINE__) CmdIntelDlg(screen, cmd_intel_def, this);
92 
93  FormDef cmd_missions_def("CmdMissionsDlg", 0);
94  cmd_missions_def.Load("CmdMissionsDlg");
95  cmd_missions_dlg = new(__FILE__,__LINE__) CmdMissionsDlg(screen, cmd_missions_def, this);
96 
97  FormDef file_def("FileDlg", 0);
98  file_def.Load("FileDlg");
99  cmp_file_dlg = new(__FILE__,__LINE__) CmpFileDlg(screen, file_def, this);
100 
101  FormDef msg_def("CmdMsgDlg", 0);
102  msg_def.Load("CmdMsgDlg");
103  cmd_msg_dlg = new(__FILE__,__LINE__) CmdMsgDlg(screen, msg_def, this);
104 
105  FormDef end_def("CmpCompleteDlg", 0);
106  end_def.Load("CmpCompleteDlg");
107  cmp_end_dlg = new(__FILE__,__LINE__) CmpCompleteDlg(screen, end_def, this);
108 
109  FormDef scene_def("CmpSceneDlg", 0);
110  scene_def.Load("CmpSceneDlg");
111  cmp_scene_dlg = new(__FILE__,__LINE__) CmpSceneDlg(screen, scene_def, this);
112 
114 
115  HideAll();
116 }
117 
118 // +--------------------------------------------------------------------+
119 
120 void
122 {
123  if (screen) {
124  screen->DelWindow(cmd_force_dlg);
125  screen->DelWindow(cmd_missions_dlg);
126  screen->DelWindow(cmd_orders_dlg);
127  screen->DelWindow(cmd_intel_dlg);
128  screen->DelWindow(cmd_theater_dlg);
129  screen->DelWindow(cmd_msg_dlg);
130  screen->DelWindow(cmp_file_dlg);
131  screen->DelWindow(cmp_end_dlg);
132  screen->DelWindow(cmp_scene_dlg);
133  }
134 
135  delete cmd_force_dlg;
136  delete cmd_missions_dlg;
137  delete cmd_orders_dlg;
138  delete cmd_intel_dlg;
139  delete cmd_theater_dlg;
140  delete cmd_msg_dlg;
141  delete cmp_file_dlg;
142  delete cmp_end_dlg;
143  delete cmp_scene_dlg;
144 
145  cmd_force_dlg = 0;
146  cmd_missions_dlg = 0;
147  cmd_orders_dlg = 0;
148  cmd_intel_dlg = 0;
149  cmd_theater_dlg = 0;
150  cmd_msg_dlg = 0;
151  cmp_file_dlg = 0;
152  cmp_end_dlg = 0;
153  cmp_scene_dlg = 0;
154  screen = 0;
155 }
156 
157 // +--------------------------------------------------------------------+
158 
159 void
161 {
162  if (cmp_scene_dlg)
163  cmp_scene_dlg->GetCameraView()->SetFieldOfView(fov);
164 }
165 
166 // +--------------------------------------------------------------------+
167 
168 double
170 {
171  if (cmp_scene_dlg)
172  return cmp_scene_dlg->GetCameraView()->GetFieldOfView();
173 
174  return 2;
175 }
176 
177 // +--------------------------------------------------------------------+
178 
179 void
181 {
183 
184  if (cmd_orders_dlg && cmd_orders_dlg->IsShown()) {
185  cmd_orders_dlg->ExecFrame();
186  }
187 
188  else if (cmd_force_dlg && cmd_force_dlg->IsShown()) {
189  cmd_force_dlg->ExecFrame();
190  }
191 
192  else if (cmd_theater_dlg && cmd_theater_dlg->IsShown()) {
193  cmd_theater_dlg->ExecFrame();
194  }
195 
196  else if (cmd_missions_dlg && cmd_missions_dlg->IsShown()) {
197  cmd_missions_dlg->ExecFrame();
198  }
199 
200  else if (cmd_intel_dlg && cmd_intel_dlg->IsShown()) {
201  cmd_intel_dlg->ExecFrame();
202  }
203 
204  if (cmp_file_dlg && cmp_file_dlg->IsShown()) {
205  cmp_file_dlg->ExecFrame();
206  }
207 
208  if (cmd_msg_dlg && cmd_msg_dlg->IsShown()) {
209  cmd_msg_dlg->ExecFrame();
210  }
211 
212  else if (cmp_end_dlg && cmp_end_dlg->IsShown()) {
213  cmp_end_dlg->ExecFrame();
214  completion_stage = 2;
215  }
216 
217  else if (cmp_scene_dlg && cmp_scene_dlg->IsShown()) {
218  cmp_scene_dlg->ExecFrame();
219 
220  if (completion_stage > 0)
221  completion_stage = 2;
222  }
223 
224  else if (campaign) {
225  // if campaign is complete
226  if (completion_stage == 0) {
227  Player* player = Player::GetCurrentPlayer();
228  char msg_info[1024];
229 
230  if (!player)
231  return;
232 
233  if (campaign->IsTraining()) {
234  int all_missions = (1<<campaign->GetMissionList().size())-1;
235 
236  if (player->Trained() >= all_missions && player->Trained() < 255) {
237  player->SetTrained(255);
238  cmd_msg_dlg->Title()->SetText(Game::GetText("CmpnScreen.training"));
239  sprintf_s(msg_info, Game::GetText("CmpnScreen.congrats"),
240  Player::RankName(player->Rank()),
241  player->Name().data());
242 
243  cmd_msg_dlg->Message()->SetText(msg_info);
244  cmd_msg_dlg->Message()->SetTextAlign(DT_LEFT);
245 
246  ShowCmdMsgDlg();
247  completion_stage = 1;
248  }
249  }
250 
251  else if (campaign->IsComplete() || campaign->IsFailed()) {
252  bool cutscene = false;
253  CombatEvent* event = campaign->GetLastEvent();
254 
255  if (event && !event->Visited() && event->SceneFile() && *event->SceneFile()) {
256  stars->ExecCutscene(event->SceneFile(), campaign->Path());
257 
258  if (stars->InCutscene()) {
259  cutscene = true;
260  ShowCmpSceneDlg();
261  }
262  }
263 
264  if (!cutscene) {
266  }
267 
268  if (campaign->IsComplete())
270  else
272 
273  completion_stage = 1;
274  }
275  }
276 
277  // if message has been shown, restart
278  else if (completion_stage > 1) {
279  completion_stage = 0;
280 
281  if (campaign->IsTraining()) {
283  Campaign* c = list[1];
284 
285  if (c) {
286  c->Load();
289  return;
290  }
291  }
292 
293  // continue on to the next available campaign:
294  if (campaign->GetCampaignId() < Campaign::GetLastCampaignId()) {
295  stars->StartOrResumeGame();
296  }
297 
298  // if this was the last campaign, just go back to the menu:
299  else {
300  Mouse::Show(false);
303  return;
304  }
305  }
306  }
307 
308  if (completion_stage < 1) {
311  }
312 }
313 
314 // +--------------------------------------------------------------------+
315 
316 bool
318 {
319  bool processed = false;
320 
321  if (IsCmdMsgShown()) {
322  HideCmdMsgDlg();
323  processed = true;
324  }
325 
326  else if (IsCmpFileShown()) {
327  HideCmpFileDlg();
328  processed = true;
329  }
330 
331  return processed;
332 }
333 
334 void
336 {
337  if (!isShown) {
338  isShown = true;
339 
340  campaign = Campaign::GetCampaign();
341  completion_stage = 0;
342 
343  bool cutscene = false;
344  CombatEvent* event = 0;
345 
346  if (campaign->IsActive() && !campaign->GetEvents().isEmpty()) {
347  ListIter<CombatEvent> iter = campaign->GetEvents();
348  while (++iter) {
349  event = iter.value();
350 
351  if (event && !event->Visited() && event->SceneFile() && *event->SceneFile()) {
352  stars->ExecCutscene(event->SceneFile(), campaign->Path());
353 
354  if (stars->InCutscene()) {
355  cutscene = true;
356  ShowCmpSceneDlg();
357  }
358 
359  event->SetVisited(true);
360  break;
361  }
362  }
363  }
364 
365  if (!cutscene)
366  ShowCmdDlg();
367  }
368 }
369 
370 void
372 {
373  if (isShown) {
374  HideAll();
375  isShown = false;
376  }
377 }
378 
379 void
381 {
382  if (cmd_force_dlg) cmd_force_dlg->Hide();
383  if (cmd_missions_dlg) cmd_missions_dlg->Hide();
384  if (cmd_orders_dlg) cmd_orders_dlg->Hide();
385  if (cmd_intel_dlg) cmd_intel_dlg->Hide();
386  if (cmd_theater_dlg) cmd_theater_dlg->Hide();
387  if (cmd_msg_dlg) cmd_msg_dlg->Hide();
388  if (cmp_file_dlg) cmp_file_dlg->Hide();
389  if (cmp_end_dlg) cmp_end_dlg->Hide();
390  if (cmp_scene_dlg) cmp_scene_dlg->Hide();
391 }
392 
393 // +--------------------------------------------------------------------+
394 
395 void
397 {
399 }
400 
401 // +--------------------------------------------------------------------+
402 
403 void
405 {
406  HideAll();
407  cmd_force_dlg->Show();
408  Mouse::Show(true);
409 }
410 
411 // +--------------------------------------------------------------------+
412 
413 void
415 {
416  if (IsCmdForceShown())
417  cmd_force_dlg->Hide();
418 }
419 
420 // +--------------------------------------------------------------------+
421 
422 bool
424 {
425  return cmd_force_dlg && cmd_force_dlg->IsShown();
426 }
427 
428 // +--------------------------------------------------------------------+
429 
430 void
432 {
433  HideAll();
434  cmd_orders_dlg->Show();
435  Mouse::Show(true);
436 }
437 
438 // +--------------------------------------------------------------------+
439 
440 void
442 {
443  if (IsCmdOrdersShown())
444  cmd_orders_dlg->Hide();
445 }
446 
447 // +--------------------------------------------------------------------+
448 
449 bool
451 {
452  return cmd_orders_dlg && cmd_orders_dlg->IsShown();
453 }
454 
455 // +--------------------------------------------------------------------+
456 
457 void
459 {
460  HideAll();
461  cmd_missions_dlg->Show();
462  Mouse::Show(true);
463 }
464 
465 // +--------------------------------------------------------------------+
466 
467 void
469 {
470  if (IsCmdMissionsShown())
471  cmd_missions_dlg->Hide();
472 }
473 
474 // +--------------------------------------------------------------------+
475 
476 bool
478 {
479  return cmd_missions_dlg && cmd_missions_dlg->IsShown();
480 }
481 
482 // +--------------------------------------------------------------------+
483 
484 void
486 {
487  HideAll();
488  cmd_intel_dlg->Show();
489  Mouse::Show(true);
490 }
491 
492 // +--------------------------------------------------------------------+
493 
494 void
496 {
497  if (IsCmdIntelShown())
498  cmd_intel_dlg->Hide();
499 }
500 
501 // +--------------------------------------------------------------------+
502 
503 bool
505 {
506  return cmd_intel_dlg && cmd_intel_dlg->IsShown();
507 }
508 
509 // +--------------------------------------------------------------------+
510 
511 void
513 {
514  HideAll();
515  cmd_theater_dlg->Show();
516  Mouse::Show(true);
517 }
518 
519 // +--------------------------------------------------------------------+
520 
521 void
523 {
524  if (IsCmdTheaterShown())
525  cmd_theater_dlg->Hide();
526 }
527 
528 // +--------------------------------------------------------------------+
529 
530 bool
532 {
533  return cmd_theater_dlg && cmd_theater_dlg->IsShown();
534 }
535 
536 // +--------------------------------------------------------------------+
537 
538 void
540 {
541  cmp_file_dlg->Show();
542  Mouse::Show(true);
543 }
544 
545 // +--------------------------------------------------------------------+
546 
547 void
549 {
550  if (IsCmpFileShown())
551  cmp_file_dlg->Hide();
552 }
553 
554 // +--------------------------------------------------------------------+
555 
556 bool
558 {
559  return cmp_file_dlg && cmp_file_dlg->IsShown();
560 }
561 
562 // +--------------------------------------------------------------------+
563 
564 void
566 {
567  cmd_msg_dlg->Show();
568  Mouse::Show(true);
569 }
570 
571 // +--------------------------------------------------------------------+
572 
573 void
575 {
576  if (IsCmdMsgShown())
577  cmd_msg_dlg->Hide();
578 }
579 
580 // +--------------------------------------------------------------------+
581 
582 bool
584 {
585  return cmd_msg_dlg && cmd_msg_dlg->IsShown();
586 }
587 
588 // +--------------------------------------------------------------------+
589 
590 void
592 {
593  cmp_end_dlg->Show();
594  Mouse::Show(true);
595 }
596 
597 // +--------------------------------------------------------------------+
598 
599 void
601 {
602  if (IsCmpCompleteShown())
603  cmp_end_dlg->Hide();
604 }
605 
606 // +--------------------------------------------------------------------+
607 
608 bool
610 {
611  return cmp_end_dlg && cmp_end_dlg->IsShown();
612 }
613 
614 // +--------------------------------------------------------------------+
615 
616 void
618 {
619  cmp_scene_dlg->Show();
620  Mouse::Show(false);
621 }
622 
623 // +--------------------------------------------------------------------+
624 
625 void
627 {
628  if (IsCmpSceneShown())
629  cmp_scene_dlg->Hide();
630 }
631 
632 // +--------------------------------------------------------------------+
633 
634 bool
636 {
637  return cmp_scene_dlg && cmp_scene_dlg->IsShown();
638 }