1 /*
2    Copyright (C) 2004 by James Gregory
3    Part of the GalaxyHack project
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License.
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY.
9 
10    See the COPYING file for more details.
11 */
12 
13 #ifndef GUARD_ForceSelect
14 #define GUARD_ForceSelect
15 
16 #include "Globals.h"
17 #include "GameState.h"
18 #include "DragWindow.h"
19 #include "Menu_Base.h"
20 
21 #include <string>
22 
23 #include <boost/filesystem/path.hpp>
24 
25 using std::string;
26 
27 namespace ForceSelect {
28 class ForceSelect_State: public GameState {
29 public:
30 	ForceSelect_State();
31 	~ForceSelect_State();
32 	void Main();
33 
34 	void MouseD(Uint8 button, Uint16 x, Uint16 y);
35 	void Keyboard(SDL_keysym& keysym);
36 };
37 
38 void ToStageTwo();
39 
40 void DrawWorld();
41 
42 void LoadSide(string& iName, bool newSide);
43 void SideToFile();
44 
45 void CreateNewGroupWins(const string& iName, UnitType iType, bool newFlag);
46 void AddGroups(const string& iName, UnitType iType, int number, CapShipType csType, int parentCaSh);
47 void UnitToFile(int nGroup);
48 void AllUnitsToFile();
49 void CreateNewSideDirs();
50 void CreatePictureDirs(const string& baseDir);
51 
52 void DeleteGroupCheck(int nGroup);
53 void DeleteGroup(int nGroup);
54 
55 int WhichGSharesName(int nGroup);
56 bool UnitNameSharedQ(int& currentGroup, int changedGroup, int addOrDelete);
57 
58 bool UnitGTOrEqual(UnitType typeOne, const string& nameOne, UnitType typeTwo, const string& nameTwo);
59 bool NameGTOrEqual(const string& nameOne, const string& nameTwo);
60 
61 void ChangeUnitPic(const string& unitName, const string& newPic);
62 void ChangeUnitSmallWeapons(const string& unitName, const string& newType);
63 void ChangeUnitBigWeapons(const string& unitName, const string& newType);
64 void ChangeUnitEngine(const string& unitName, const string& newStat);
65 void ChangeUnitArmour(const string& unitName, const string& newStat);
66 void ChangeUnitShield(const string& unitName, const string& newStat);
67 void ChangeUnitEquipment(const string& unitName, const string& newStat);
68 void ChangeUnitAI(const string& unitName, const string& newStat);
69 void ChangeUnitCSType(const string& unitName, CapShipType newStat);
70 
71 void ChangeGroupParentCaSh(int nGroup, int newParent);
72 
73 //1 is add, 0 is delete
74 void GroupAddDelInform(int groupNumber, int howMany);
75 
76 void TrySaveAndExit();
77 
78 ///
79 
80 class LoadSideDW: public LargeBlankDW {
81 public:
82 	LoadSideDW();
83 	~LoadSideDW();
84 };
85 
86 class LoadSideSM: public FileListMenu {
87 public:
88 	LoadSideSM(int iParentID);
89 
90 	void ExpensiveUpdate();
91 	bool SwitchOnChoice(Uint16 x, Uint16 y);
92 };
93 
94 class LoadSidePU: public PopupMenu {
95 public:
96 	LoadSidePU(int ix, int iy, const string& iSideName, int iParentID);
97 	bool SwitchOnChoice(Uint16 x, Uint16 y);
98 
99 private:
100 	string sideName;
101 };
102 
103 class DeleteFleet: public Menu_Base {
104 public:
105 	DeleteFleet(const string& iSideName, int iParentID);
106 	bool SwitchOnChoice(Uint16 x, Uint16 y);
107 
108 private:
109 	string sideName;
110 };
111 
112 class CopyFleet: public StringInputBox {
113 public:
114 	CopyFleet(const string& iSideName, int iParentID);
115 	bool Keyboard(SDL_keysym& keysym);
116 
117 private:
118 	void DoCopy(boost::filesystem::path sourcePath, boost::filesystem::path destPath);
119 
120 private:
121 	string sideName;
122 };
123 
124 class NewSideName: public StringInputBox {
125 public:
126 	NewSideName();
127 
128 	bool Keyboard(SDL_keysym& keysym);
129 };
130 
131 class ChangeCommanderName: public StringInputBox {
132 public:
133 	ChangeCommanderName();
134 
135 	bool Keyboard(SDL_keysym& keysym);
136 };
137 
138 ///
139 
140 class BasePU: public PopupMenu {
141 public:
142 	BasePU(int ix, int iy);
143 	bool SwitchOnChoice(Uint16 x, Uint16 y);
144 };
145 
146 ///
147 
148 class SideOptions: public DragWindow {
149 public:
150 	SideOptions(int ix, int iy, int flags);
151 
152 	bool MouseD(Uint8 button, Uint16 x, Uint16 y);
153 	void DrawSelf();
154 };
155 
156 class SideOptionsPU: public PopupMenu {
157 public:
158 	SideOptionsPU(int ix, int iy);
159 	bool SwitchOnChoice(Uint16 x, Uint16 y);
160 };
161 
162 
163 class AddGroupMenu: public FileListMenu {
164 public:
165 	AddGroupMenu(int iParentID);
166 
167 	void ExpensiveUpdate();
168 	bool SwitchOnChoice(Uint16 x, Uint16 y);
169 };
170 
171 class AddGroupPU: public PopupMenu {
172 public:
173 	AddGroupPU(int ix, int iy, const string& iUnitName, int iParentID);
174 
175 	bool SwitchOnChoice(Uint16 x, Uint16 y);
176 
177 private:
178 	string unitName;
179 };
180 
181 class NewGroupChoicesOK: public Menu_Base {
182 public:
183 	NewGroupChoicesOK(int ix, int iy, const string& iName, UnitType iMyType, int iIDOne, int iIDTwo, int iParentID);
184 	bool SwitchOnChoice(Uint16 x, Uint16 y);
185 
186 	string name;
187 	UnitType myType;
188 	int sliderOneID;
189 	int sliderTwoID;
190 };
191 
192 class CapShipTypeSlider: public Slider {
193 public:
194 	CapShipTypeSlider(int ix, int iy, int iParentID, int flags);
195 
196 	void DrawSelf();
197 };
198 
199 class NewGroupParentPU: public SidePU {
200 public:
201 	NewGroupParentPU(const string& iName, UnitType iType, int iNumber);
202 
203 	bool SwitchOnChoice(Uint16 x, Uint16 y);
204 
205 protected:
206 	string name;
207 	UnitType myType;
208 	int number;
209 };
210 
211 class NewUnitName: public StringInputBox {
212 public:
213 	NewUnitName(UnitType iUnitType, int iParentID);
214 
215 	bool Keyboard(SDL_keysym& keysym);
216 
217 protected:
218 	UnitType unitType;
219 };
220 
221 class EditGroup: public DragWindow {
222 public:
223 	EditGroup(int ix, int iy, int iMyGroup, int flags);
224 
225 	bool MouseD(Uint8 button, Uint16 x, Uint16 y);
226 	void DrawSelf();
227 
228 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
229 
230 protected:
231 	int myGroup;
232 };
233 
234 class EditGroupPU: public PopupMenu {
235 public:
236 	EditGroupPU(int ix, int iy, int iMyGroup);
237 	bool SwitchOnChoice(Uint16 x, Uint16 y);
238 
239 protected:
240 	int myGroup;
241 };
242 
243 class SetAIScriptMenu: public FileListMenu {
244 public:
245 	SetAIScriptMenu(int iMyGroup, int iParentID);
246 	bool SwitchOnChoice(Uint16 x, Uint16 y);
247 
248 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
249 
250 protected:
251 	int myGroup;
252 };
253 
254 class SetAIScriptPU: public Menu_Base {
255 public:
256 	SetAIScriptPU(const string& iNewScript, int iMyGroup, int iParentID);
257 	bool SwitchOnChoice(Uint16 x, Uint16 y);
258 
259 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
260 
261 protected:
262 	int myGroup;
263 	const string newScript;
264 };
265 
266 class EditUnit: public DragWindow {
267 public:
268 	EditUnit(int ix, int iy, int iMyGroup);
269 
270 	bool MouseD(Uint8 button, Uint16 x, Uint16 y);
271 	void DrawSelf();
272 
273 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
274 
275 protected:
276 	int myGroup;
277 	UnitType myType;
278 };
279 
280 class EditUnitPU: public PopupMenu {
281 public:
282 	EditUnitPU(int ix, int iy, int iMyGroup);
283 
284 	bool SwitchOnChoice(Uint16 x, Uint16 y);
285 
286 protected:
287 	int myGroup;
288 };
289 
290 ///
291 
292 class SetUnitPicMenu: public FileListMenu {
293 public:
294 	SetUnitPicMenu(int iMyGroup, int iParentID);
295 
296 	bool SwitchOnChoice(Uint16 x, Uint16 y);
297 	bool MouseM(Uint8 state, Uint16 x, Uint16 y);
298 
299 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
300 
301 protected:
302 	int myGroup;
303 	int previewWinID;
304 };
305 
306 class WeapEquipMenu_Base: public Menu_Base {
307 public:
308 	WeapEquipMenu_Base(int ix, int iy, int iMyGroup, int iParentID);
309 	virtual ~WeapEquipMenu_Base();
310 
311 	void InitEquipMenu(WindowChoice first, WindowChoice last);
312 	bool SharedSwitchOnChoice(void (*ChangeUnitFunction)(const string&, const string&));
313 	bool MouseM(Uint8 state, Uint16 x, Uint16 y);
314 
315 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
316 
317 protected:
318 	int myGroup;
319 };
320 
321 class WeaponsDW: public DragWindow {
322 public:
323 	WeaponsDW(int ix, int iy, int iMyGroup, int bBig);
324 
325 	void DrawSelf();
326 
327 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
328 
329 protected:
330 	WeaponType weaponChoice;
331 };
332 
333 class SmallWeaponsMenu: public WeapEquipMenu_Base {
334 public:
335 	SmallWeaponsMenu(int ix, int iy, int iMyGroup, int iParentID);
336 	bool SwitchOnChoice(Uint16 x, Uint16 y);
337 
338 protected:
339 	UnitType myType;
340 };
341 
342 class BigWeaponsMenu: public WeapEquipMenu_Base {
343 public:
344 	BigWeaponsMenu(int ix, int iy, int iMyGroup, int iParentID);
345 	bool SwitchOnChoice(Uint16 x, Uint16 y);
346 
347 protected:
348 	UnitType myType;
349 };
350 
351 class EquipmentDW: public DragWindow {
352 public:
353 	EquipmentDW(int ix, int iy, int iMyGroup, int equipType);
354 
355 	void DrawSelf();
356 	void WinMessage(WindowChoice theMessage, int paremOne, int paremTwo, int targetID, int sourceID);
357 
358 protected:
359 	string equipChoice;
360 };
361 
362 class EngineMenu: public WeapEquipMenu_Base {
363 public:
364 	EngineMenu(int ix, int iy, int iMyGroup, int iParentID);
365 	bool SwitchOnChoice(Uint16 x, Uint16 y);
366 
367 protected:
368 	EquipCat equipCat;
369 };
370 
371 class ArmourMenu: public WeapEquipMenu_Base {
372 public:
373 	ArmourMenu(int ix, int iy, int iMyGroup, int iParentID);
374 	bool SwitchOnChoice(Uint16 x, Uint16 y);
375 
376 protected:
377 	EquipCat equipCat;
378 };
379 
380 class ShieldMenu: public WeapEquipMenu_Base {
381 public:
382 	ShieldMenu(int ix, int iy, int iMyGroup, int iParentID);
383 	bool SwitchOnChoice(Uint16 x, Uint16 y);
384 
385 protected:
386 	EquipCat equipCat;
387 };
388 
389 class CSTypeMenu: public Menu_Base {
390 public:
391 	CSTypeMenu(int ix, int iy, int iMyGroup);
392 
393 	bool SwitchOnChoice(Uint16 x, Uint16 y);
394 
395 protected:
396 	int myGroup;
397 };
398 
399 
400 //
401 
402 class ExitNoSaveQ: public Menu_Base {
403 public:
404 	ExitNoSaveQ();
405 	bool SwitchOnChoice(Uint16 x, Uint16 y);
406 };
407 
408 class ForceExitQ: public Menu_Base {
409 public:
410 	ForceExitQ(const string& error);
411 	bool SwitchOnChoice(Uint16 x, Uint16 y);
412 };
413 
414 class WhichSaveGroup: public PopupMenu {
415 public:
416 	WhichSaveGroup(int iMyGroup, bool globalVar);
417 	bool SwitchOnChoice(Uint16 x, Uint16 y);
418 
419 private:
420 	int myGroup;
421 };
422 
423 } // end namespace
424 
425 #endif
426 
427