Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MsnSelectDlg.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: MsnSelectDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Mission Select Dialog Active Window class
13 */
14 
15 #include "MemDebug.h"
16 #include "MsnSelectDlg.h"
17 #include "MsnEditDlg.h"
18 #include "MsnEditNavDlg.h"
19 #include "ConfirmDlg.h"
20 #include "MenuScreen.h"
21 #include "Starshatter.h"
22 #include "Campaign.h"
23 #include "Mission.h"
24 
25 #include "Game.h"
26 #include "DataLoader.h"
27 #include "Button.h"
28 #include "ComboBox.h"
29 #include "ListBox.h"
30 #include "Slider.h"
31 #include "Video.h"
32 #include "Keyboard.h"
33 #include "Mouse.h"
34 #include "ParseUtil.h"
35 #include "FormatUtil.h"
36 
37 // +--------------------------------------------------------------------+
38 // DECLARE MAPPING FUNCTIONS:
39 
40 DEF_MAP_CLIENT(MsnSelectDlg, OnAccept);
41 DEF_MAP_CLIENT(MsnSelectDlg, OnCancel);
46 DEF_MAP_CLIENT(MsnSelectDlg, OnDelConfirm);
47 DEF_MAP_CLIENT(MsnSelectDlg, OnCampaignSelect);
48 DEF_MAP_CLIENT(MsnSelectDlg, OnMissionSelect);
49 
50 // +--------------------------------------------------------------------+
51 
52 static Mission* edit_mission;
53 
54 // +--------------------------------------------------------------------+
55 
57 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
58 cmb_campaigns(0), lst_campaigns(0), lst_missions(0),
59 btn_accept(0), btn_cancel(0), btn_mod(0),
60 btn_new(0), btn_edit(0), btn_del(0), editable(false),
61 description(0), stars(0), campaign(0),
62 selected_mission(-1), mission_id(0)
63 {
66  edit_mission = 0;
67 
68  Init(def);
69 }
70 
72 {
73 }
74 
75 // +--------------------------------------------------------------------+
76 
77 void
79 {
80  btn_accept = (Button*) FindControl( 1);
81  btn_cancel = (Button*) FindControl( 2);
82 
83  if (btn_accept) {
84  btn_accept->SetEnabled(false);
86  }
87 
88  if (btn_cancel) {
90  }
91 
92  btn_mod = (Button*) FindControl(300);
93  btn_new = (Button*) FindControl(301);
94  btn_edit = (Button*) FindControl(302);
95  btn_del = (Button*) FindControl(303);
96 
97  if (btn_mod)
99 
100  if (btn_new)
102 
103  if (btn_edit)
105 
106  if (btn_del) {
109  }
110 
111  description = FindControl(200);
112 
115  lst_missions = (ListBox*) FindControl(202);
116 
117  if (cmb_campaigns) {
119  }
120 
121  if (lst_campaigns) {
123 
126  }
127 
128  if (lst_missions) {
130 
133  }
134 }
135 
136 // +--------------------------------------------------------------------+
137 
138 void
140 {
143 
144  if (cmb_campaigns) {
145  int n = 0;
148  while (++iter) {
149  Campaign* c = iter.value();
150 
152  cmb_campaigns->AddItem(c->Name());
153 
157  }
158 
159  else if (campaign->GetCampaignId() == c->GetCampaignId()) {
161  }
162 
163  n++;
164  }
165  }
166  }
167 
168  else if (lst_campaigns) {
169  int n = 0;
172  while (++iter) {
173  Campaign* c = iter.value();
174 
176  lst_campaigns->AddItem(c->Name());
177 
181  }
182 
183  else if (campaign->GetCampaignId() == c->GetCampaignId()) {
185  }
186 
187  n++;
188  }
189  }
190  }
191 
192  if (campaign) {
193  int id = campaign->GetCampaignId();
196 
198  if (btn_edit) btn_edit->SetEnabled(false);
199  if (btn_del) btn_del->SetEnabled(false);
200  }
201 
202  if (description)
203  description->SetText(Game::GetText("MsnSelectDlg.choose"));
204 
205  if (lst_missions) {
207 
208  if (campaign) {
210  while (++iter) {
211  MissionInfo* info = iter.value();
212  Mission* m = info->mission;
213 
214  lst_missions->AddItem(info->name);
215 
216  if (m && m == edit_mission) {
218  }
219  }
220 
221  if (selected_mission >= 0 && lst_missions->GetSelCount() == 0) {
223  }
224  }
225 
226  OnMissionSelect(0);
227  edit_mission = 0;
228  }
229 }
230 
231 // +--------------------------------------------------------------------+
232 
233 void
235 {
236  const char* selected_campaign = 0;
237 
238  if (cmb_campaigns)
239  selected_campaign = cmb_campaigns->GetSelectedItem();
240  else if (lst_campaigns)
241  selected_campaign = lst_campaigns->GetSelectedItem();
242 
243  Campaign* c = Campaign::SelectCampaign(selected_campaign);
244 
245  if (c) {
246  campaign = c;
247 
248  if (cmb_campaigns) {
250 
252  while (++iter) {
253  cmb_campaigns->AddItem(iter->name);
254  }
255  }
256 
257  else if (lst_missions) {
259 
261  while (++iter) {
262  lst_missions->AddItem(iter->name);
263  }
264 
266  }
267 
268  if (btn_accept)
269  btn_accept->SetEnabled(false);
270 
271  if (description)
272  description->SetText(Game::GetText("MsnSelectDlg.choose"));
273 
274  int id = c->GetCampaignId();
277 
279  if (btn_edit) btn_edit->SetEnabled(false);
280  if (btn_del) btn_del->SetEnabled(false);
281  }
282 }
283 
284 void
286 {
287  selected_mission = -1;
288 
289  for (int i = 0; i < lst_missions->NumItems(); i++)
290  if (lst_missions->IsSelected(i))
291  selected_mission = i;
292 
293  if (btn_accept && description && campaign) {
294  List<MissionInfo>& mission_info_list = campaign->GetMissionList();
295 
296  if (selected_mission >= 0 && selected_mission < mission_info_list.size()) {
297  MissionInfo* info = mission_info_list[selected_mission];
298  mission_id = info->id;
299 
300  char time_buf[32];
301  FormatDayTime(time_buf, info->start);
302 
303  Text d("<font Limerick12><color ffffff>");
304  d += info->name;
305  d += "<font Verdana>\n\n<color ffff80>";
306  d += Game::GetText("MsnSelectDlg.mission-type");
307  d += "<color ffffff>\n\t";
308  d += Mission::RoleName(info->type);
309  d += "\n\n<color ffff80>";
310  d += Game::GetText("MsnSelectDlg.scenario");
311  d += "<color ffffff>\n\t";
312  d += info->description;
313  d += "\n\n<color ffff80>";
314  d += Game::GetText("MsnSelectDlg.location");
315  d += "<color ffffff>\n\t";
316  d += info->region;
317  d += " ";
318  d += Game::GetText("MsnSelectDlg.sector");
319  d += " / ";
320  d += info->system;
321  d += " ";
322  d += Game::GetText("MsnSelectDlg.system");
323  d += "\n\n<color ffff80>";
324  d += Game::GetText("MsnSelectDlg.start-time");
325  d += "<color ffffff>\n\t";
326  d += time_buf;
327 
328  description->SetText(d);
329  btn_accept->SetEnabled(true);
330 
333  }
334 
335  else {
336  description->SetText(Game::GetText("MsnSelectDlg.choose"));
337  btn_accept->SetEnabled(false);
338 
339  if (btn_edit) btn_edit->SetEnabled(false);
340  if (btn_del) btn_del->SetEnabled(false);
341  }
342  }
343 }
344 
345 // +--------------------------------------------------------------------+
346 
347 void
349 {
350  if (Keyboard::KeyDown(VK_RETURN)) {
351  if (btn_accept && btn_accept->IsEnabled())
352  OnAccept(0);
353  }
354 }
355 
356 // +--------------------------------------------------------------------+
357 
358 void
360 {
361 }
362 
363 void
365 {
366  const char* cname = 0;
367 
368  if (cmb_campaigns)
369  cname = cmb_campaigns->GetSelectedItem();
370  else if (lst_campaigns)
371  cname = lst_campaigns->GetSelectedItem();
372 
374  if (!c) return;
375 
376  MissionInfo* info = c->CreateNewMission();
377  if (!info || !info->mission)
378  return;
379 
380  mission_id = info->id;
381 
382  MsnEditDlg* editor = manager->GetMsnEditDlg();
383 
384  if (editor) {
385  edit_mission = info->mission;
386 
387  editor->SetMissionInfo(info);
388  editor->SetMission(info->mission);
390  }
391 
393 
394  if (navdlg) {
395  navdlg->SetMission(info->mission);
396  navdlg->SetMissionInfo(info);
397  }
398 }
399 
400 void
402 {
403  const char* cname = 0;
404 
405  if (cmb_campaigns)
406  cname = cmb_campaigns->GetSelectedItem();
407  else if (lst_campaigns)
408  cname = lst_campaigns->GetSelectedItem();
409 
411  if (!c) return;
412 
413  Mission* m = c->GetMission(mission_id);
414  if (!m) return;
415 
416  MsnEditDlg* editor = manager->GetMsnEditDlg();
417 
418  if (editor) {
419  edit_mission = m;
420 
422  editor->SetMission(m);
424  }
425 }
426 
427 void
429 {
430  const char* cname = 0;
431 
432  if (cmb_campaigns)
433  cname = cmb_campaigns->GetSelectedItem();
434  else if (lst_campaigns)
435  cname = lst_campaigns->GetSelectedItem();
436 
438  if (!c) return;
439 
440  Mission* m = c->GetMission(mission_id);
441  if (!m) return;
442 
443  ConfirmDlg* confirm = manager->GetConfirmDlg();
444  if (confirm) {
445  char msg[256];
446  sprintf_s(msg, Game::GetText("MsnSelectDlg.are-you-sure").data(), m->Name());
447  confirm->SetMessage(msg);
448  confirm->SetTitle(Game::GetText("MsnSelectDlg.confirm-delete"));
449  confirm->SetParentControl(btn_del);
450 
452  }
453 
454  else {
455  OnDelConfirm(event);
456  }
457 }
458 
459 void
461 {
462  const char* cname = 0;
463 
464  if (cmb_campaigns)
465  cname = cmb_campaigns->GetSelectedItem();
466  else if (lst_campaigns)
467  cname = lst_campaigns->GetSelectedItem();
468 
470  if (!c) return;
471 
472  edit_mission = 0;
474  Show();
475 }
476 
477 // +--------------------------------------------------------------------+
478 
479 void
481 {
482  if (selected_mission >= 0) {
483  Mouse::Show(false);
484 
485  int id = campaign->GetMissionList()[selected_mission]->id;
486  campaign->SetMissionId(id);
487  campaign->ReloadMission(id);
488 
490  }
491 }
492 
493 void
495 {
496  manager->ShowMenuDlg();
497 }
498 
499 // +--------------------------------------------------------------------+