Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CmpFileDlg.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: CmpFileDlg.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 "CmpFileDlg.h"
17 #include "CmpnScreen.h"
18 #include "Starshatter.h"
19 #include "Campaign.h"
20 #include "CampaignSaveGame.h"
21 #include "CombatGroup.h"
22 
23 #include "Game.h"
24 #include "DataLoader.h"
25 #include "Button.h"
26 #include "EditBox.h"
27 #include "ListBox.h"
28 #include "Slider.h"
29 #include "Video.h"
30 #include "Keyboard.h"
31 #include "Mouse.h"
32 #include "FormatUtil.h"
33 #include "ParseUtil.h"
34 
35 // +--------------------------------------------------------------------+
36 // DECLARE MAPPING FUNCTIONS:
37 
38 DEF_MAP_CLIENT(CmpFileDlg, OnSave);
39 DEF_MAP_CLIENT(CmpFileDlg, OnCancel);
40 DEF_MAP_CLIENT(CmpFileDlg, OnCampaign);
41 
42 // +--------------------------------------------------------------------+
43 
45 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
46 exit_latch(false), btn_save(0), btn_cancel(0), edt_name(0), lst_campaigns(0)
47 {
48  Init(def);
49 }
50 
52 {
53 }
54 
55 // +--------------------------------------------------------------------+
56 
57 void
59 {
60  btn_save = (Button*) FindControl(1);
62 
63  if (btn_save)
65 
66  if (btn_cancel)
68 
69  edt_name = (EditBox*) FindControl(200);
70 
71  if (edt_name)
72  edt_name->SetText("");
73 
75 
76  if (lst_campaigns)
78 }
79 
80 // +--------------------------------------------------------------------+
81 
82 void
84 {
86 
87  if (lst_campaigns) {
90 
91  List<Text> save_list;
92 
94  save_list.sort();
95 
96  for (int i = 0; i < save_list.size(); i++)
97  lst_campaigns->AddItem(*save_list[i]);
98 
99  save_list.destroy();
100  }
101 
102  if (edt_name) {
103  char save_name[256];
104  save_name[0] = 0;
105 
107  if (campaign && campaign->GetPlayerGroup()) {
108  const char* op_name = campaign->Name();
109  char day[32];
110  CombatGroup* group = campaign->GetPlayerGroup();
111 
112  if (strstr(op_name, "Operation "))
113  op_name += 10;
114 
115  FormatDay(day, campaign->GetTime());
116 
117  sprintf_s(save_name, "%s %s (%s)",
118  op_name,
119  day,
120  group->GetRegion().data());
121  }
122 
123  edt_name->SetText(save_name);
124  edt_name->SetFocus();
125  }
126 }
127 
128 // +--------------------------------------------------------------------+
129 
130 void
132 {
133  if (Keyboard::KeyDown(VK_RETURN)) {
134  OnSave(0);
135  }
136 
137  if (Keyboard::KeyDown(VK_ESCAPE)) {
138  if (!exit_latch)
139  OnCancel(0);
140 
141  exit_latch = true;
142  }
143  else {
144  exit_latch = false;
145  }
146 }
147 
148 // +--------------------------------------------------------------------+
149 
150 void
152 {
153  if (edt_name && edt_name->GetText().length() > 0) {
156 
157  char filename[256];
158  strcpy_s(filename, edt_name->GetText());
159  char* newline = strchr(filename, '\n');
160  if (newline)
161  *newline = 0;
162 
163  save.Save(filename);
164  save.SaveAuto();
165 
166  if (manager)
168  }
169 }
170 
171 void
173 {
174  if (manager)
176 }
177 
178 // +--------------------------------------------------------------------+
179 
180 void
182 {
183  int n = lst_campaigns->GetSelection();
184 
185  if (n >= 0) {
186  Text cmpn = lst_campaigns->GetItemText(n);
187 
188  if (edt_name)
189  edt_name->SetText(cmpn);
190  }
191 }