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 #ifdef STARSHATTER_DEMO_RELEASE
294  if (!campaign->IsTraining()) {
295  Mouse::Show(false);
298  return;
299  }
300 #endif
301 
302  // continue on to the next available campaign:
303  if (campaign->GetCampaignId() < Campaign::GetLastCampaignId()) {
304  stars->StartOrResumeGame();
305  }
306 
307  // if this was the last campaign, just go back to the menu:
308  else {
309  Mouse::Show(false);
312  return;
313  }
314  }
315  }
316 
317  if (completion_stage < 1) {
320  }
321 }
322 
323 // +--------------------------------------------------------------------+
324 
325 bool
327 {
328  bool processed = false;
329 
330  if (IsCmdMsgShown()) {
331  HideCmdMsgDlg();
332  processed = true;
333  }
334 
335  else if (IsCmpFileShown()) {
336  HideCmpFileDlg();
337  processed = true;
338  }
339 
340  return processed;
341 }
342 
343 void
345 {
346  if (!isShown) {
347  isShown = true;
348 
349  campaign = Campaign::GetCampaign();
350  completion_stage = 0;
351 
352  bool cutscene = false;
353  CombatEvent* event = 0;
354 
355  if (campaign->IsActive() && !campaign->GetEvents().isEmpty()) {
356  ListIter<CombatEvent> iter = campaign->GetEvents();
357  while (++iter) {
358  event = iter.value();
359 
360  if (event && !event->Visited() && event->SceneFile() && *event->SceneFile()) {
361  stars->ExecCutscene(event->SceneFile(), campaign->Path());
362 
363  if (stars->InCutscene()) {
364  cutscene = true;
365  ShowCmpSceneDlg();
366  }
367 
368  event->SetVisited(true);
369  break;
370  }
371  }
372  }
373 
374  if (!cutscene)
375  ShowCmdDlg();
376  }
377 }
378 
379 void
381 {
382  if (isShown) {
383  HideAll();
384  isShown = false;
385  }
386 }
387 
388 void
390 {
391  if (cmd_force_dlg) cmd_force_dlg->Hide();
392  if (cmd_missions_dlg) cmd_missions_dlg->Hide();
393  if (cmd_orders_dlg) cmd_orders_dlg->Hide();
394  if (cmd_intel_dlg) cmd_intel_dlg->Hide();
395  if (cmd_theater_dlg) cmd_theater_dlg->Hide();
396  if (cmd_msg_dlg) cmd_msg_dlg->Hide();
397  if (cmp_file_dlg) cmp_file_dlg->Hide();
398  if (cmp_end_dlg) cmp_end_dlg->Hide();
399  if (cmp_scene_dlg) cmp_scene_dlg->Hide();
400 }
401 
402 // +--------------------------------------------------------------------+
403 
404 void
406 {
408 }
409 
410 // +--------------------------------------------------------------------+
411 
412 void
414 {
415  HideAll();
416  cmd_force_dlg->Show();
417  Mouse::Show(true);
418 }
419 
420 // +--------------------------------------------------------------------+
421 
422 void
424 {
425  if (IsCmdForceShown())
426  cmd_force_dlg->Hide();
427 }
428 
429 // +--------------------------------------------------------------------+
430 
431 bool
433 {
434  return cmd_force_dlg && cmd_force_dlg->IsShown();
435 }
436 
437 // +--------------------------------------------------------------------+
438 
439 void
441 {
442  HideAll();
443  cmd_orders_dlg->Show();
444  Mouse::Show(true);
445 }
446 
447 // +--------------------------------------------------------------------+
448 
449 void
451 {
452  if (IsCmdOrdersShown())
453  cmd_orders_dlg->Hide();
454 }
455 
456 // +--------------------------------------------------------------------+
457 
458 bool
460 {
461  return cmd_orders_dlg && cmd_orders_dlg->IsShown();
462 }
463 
464 // +--------------------------------------------------------------------+
465 
466 void
468 {
469  HideAll();
470  cmd_missions_dlg->Show();
471  Mouse::Show(true);
472 }
473 
474 // +--------------------------------------------------------------------+
475 
476 void
478 {
479  if (IsCmdMissionsShown())
480  cmd_missions_dlg->Hide();
481 }
482 
483 // +--------------------------------------------------------------------+
484 
485 bool
487 {
488  return cmd_missions_dlg && cmd_missions_dlg->IsShown();
489 }
490 
491 // +--------------------------------------------------------------------+
492 
493 void
495 {
496  HideAll();
497  cmd_intel_dlg->Show();
498  Mouse::Show(true);
499 }
500 
501 // +--------------------------------------------------------------------+
502 
503 void
505 {
506  if (IsCmdIntelShown())
507  cmd_intel_dlg->Hide();
508 }
509 
510 // +--------------------------------------------------------------------+
511 
512 bool
514 {
515  return cmd_intel_dlg && cmd_intel_dlg->IsShown();
516 }
517 
518 // +--------------------------------------------------------------------+
519 
520 void
522 {
523  HideAll();
524  cmd_theater_dlg->Show();
525  Mouse::Show(true);
526 }
527 
528 // +--------------------------------------------------------------------+
529 
530 void
532 {
533  if (IsCmdTheaterShown())
534  cmd_theater_dlg->Hide();
535 }
536 
537 // +--------------------------------------------------------------------+
538 
539 bool
541 {
542  return cmd_theater_dlg && cmd_theater_dlg->IsShown();
543 }
544 
545 // +--------------------------------------------------------------------+
546 
547 void
549 {
550  cmp_file_dlg->Show();
551  Mouse::Show(true);
552 }
553 
554 // +--------------------------------------------------------------------+
555 
556 void
558 {
559  if (IsCmpFileShown())
560  cmp_file_dlg->Hide();
561 }
562 
563 // +--------------------------------------------------------------------+
564 
565 bool
567 {
568  return cmp_file_dlg && cmp_file_dlg->IsShown();
569 }
570 
571 // +--------------------------------------------------------------------+
572 
573 void
575 {
576  cmd_msg_dlg->Show();
577  Mouse::Show(true);
578 }
579 
580 // +--------------------------------------------------------------------+
581 
582 void
584 {
585  if (IsCmdMsgShown())
586  cmd_msg_dlg->Hide();
587 }
588 
589 // +--------------------------------------------------------------------+
590 
591 bool
593 {
594  return cmd_msg_dlg && cmd_msg_dlg->IsShown();
595 }
596 
597 // +--------------------------------------------------------------------+
598 
599 void
601 {
602  cmp_end_dlg->Show();
603  Mouse::Show(true);
604 }
605 
606 // +--------------------------------------------------------------------+
607 
608 void
610 {
611  if (IsCmpCompleteShown())
612  cmp_end_dlg->Hide();
613 }
614 
615 // +--------------------------------------------------------------------+
616 
617 bool
619 {
620  return cmp_end_dlg && cmp_end_dlg->IsShown();
621 }
622 
623 // +--------------------------------------------------------------------+
624 
625 void
627 {
628  cmp_scene_dlg->Show();
629  Mouse::Show(false);
630 }
631 
632 // +--------------------------------------------------------------------+
633 
634 void
636 {
637  if (IsCmpSceneShown())
638  cmp_scene_dlg->Hide();
639 }
640 
641 // +--------------------------------------------------------------------+
642 
643 bool
645 {
646  return cmp_scene_dlg && cmp_scene_dlg->IsShown();
647 }