-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathguimanager.h
324 lines (291 loc) · 10.2 KB
/
guimanager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
Copyright (C) 2012-2015 - Voidious
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GUI_MANAGER_H
#define GUI_MANAGER_H
#include <SFML/Graphics.hpp>
#include "gfxmanager.h"
#include "filemanager.h"
#include "guigamerunner.h"
#include "newmatch.h"
#include "packagedialog.h"
#include "packageship.h"
#include "packagestage.h"
#include "runnerdialog.h"
#include "outputconsole.h"
#include "stagepreview.h"
#include "menubarmaker.h"
#include "guiprinthandler.h"
#include "resultsdialog.h"
#include "replaybuilder.h"
#include "runnerform.h"
#define ITEM_STAGE 1
#define ITEM_SHIP 2
#define ITEM_RUNNER 3
#define NEXT_NEW_MATCH 1
#define NEXT_PACKAGE_STAGE 2
#define NEXT_PACKAGE_SHIP 3
#define NEXT_GAME_RUNNER 4
#define NEXT_RESUME_MATCH 5
class GuiListener {
public:
virtual void onAllWindowsClosed() = 0;
virtual ~GuiListener() {};
};
class GuiManager {
GuiListener *listener_;
NewMatchDialog *newMatchDialog_;
PackageShipDialog *packageShipDialog_;
PackageStageDialog *packageStageDialog_;
RunnerDialog *runnerDialog_;
sf::RenderWindow *window_;
// Logically, the preview window should be managed by StagePreview. But on
// OS X, the creation and deletion of the SFML windows needs to be carefully
// managed in relation to the app's wxWidgets operations, otherwise the SFML
// window will cause the app to crash when deleted. I believe it's some kind
// of driver issue, but I don't really know.
sf::RenderWindow *previewWindow_;
GuiPrintHandler *guiPrintHandler_;
OutputConsole *stageConsole_;
OutputConsole **teamConsoles_;
OutputConsole *packagingConsole_;
OutputConsole *errorConsole_;
OutputConsole *runnerConsole_;
StagePreview *stagePreview_;
ConsoleListener *runnerConsoleListener_;
ResultsDialog *resultsDialog_;
MenuBarMaker *menuBarMaker_;
GfxManager *gfxManager_;
GfxViewListener *viewListener_;
sf::Image windowIcon_;
Zipper *zipper_;
FileManager *fileManager_;
GuiGameRunner *gameRunner_;
NewMatchListener *newMatchListener_;
PackageDialogListener *shipPackager_;
PackageDialogListener *stagePackager_;
RunnerDialogListener *runnerLauncher_;
PackagingListener *packageReporter_;
BerryBotsEngine *engine_;
char *currentStagePath_;
char **currentTeamPaths_;
int currentNumTeams_;
unsigned int viewWidth_;
unsigned int viewHeight_;
GfxEventHandler *gfxHandler_;
// Interrupted means the user brought up a modal dialog (eg, "New Match")...
// The run loop exits but everything stays initialized. Match may be resumed
// if user closes the New Match window, or clobbered to start a new match.
bool interrupted_;
// Paused means the game engine is not executing the match, but the SFML
// window is still being drawn and listening for events. (Either the user
// paused the game or it ended and they haven't done anything yet.)
bool paused_;
bool restarting_;
bool quitting_;
bool showedResults_;
bool runnerRunning_;
int nextWindow_;
double tpsFactor_;
double nextDrawTime_;
int numStages_;
int numShips_;
int numRunners_;
public:
GuiManager(GuiListener *listener);
~GuiManager();
void reloadBaseDirs();
void loadStages();
bool isValidStageFile(const char *srcFilename, BerryBotsEngine *engine);
void loadShips();
bool isValidShipFile(const char *srcFilename, BerryBotsEngine *engine);
void loadRunners();
bool isValidRunnerFile(const char *srcFilename, BerryBotsEngine *engine);
void startMatch(const char *stageName, char **teamNames, int numTeams);
void runNewMatch(const char *stageName, char **teamNames, int numTeams);
void processMainWindowEvents(sf::RenderWindow *window,
GfxManager *gfxManager, int viewWidth, int viewHeight);
void launchGameRunner(const char *runnerName);
void abortGameRunner();
void showNewMatchDialog();
void showPackageShipDialog();
void showPackageStageDialog();
void showGameRunnerDialog();
void showStageConsole();
void showTeamConsole(int teamIndex);
void showErrorConsole();
void showStagePreview(const char *stageName);
void closeStagePreview();
void previewNextStage();
void previewPreviousStage();
void selectStage(const char *stageName);
void hideNewMatchDialog();
void hidePackageShipDialog();
void hidePackageStageDialog();
void hideGameRunnerDialog();
void hidePackagingConsole();
void hideErrorConsole();
void dialogClosed();
void dialogEscaped();
void newMatchInitialFocus();
void packageShipInitialFocus();
void packageStageInitialFocus();
void gameRunnerInitialFocus();
void togglePause();
void restartMatch();
void setTpsFactor(double tpsFactor);
void quit();
void redrawMainWindow();
char* getStagesDirCopy();
char* getShipsDirCopy();
char* getCacheDirCopy();
char* getTmpDirCopy();
private:
sf::RenderWindow* initMainWindow(unsigned int width, unsigned int height);
sf::RenderWindow* initPreviewWindow(unsigned int width,
unsigned int height);
void runCurrentMatch();
void drawFrame(sf::RenderWindow *window);
void showResults(ReplayBuilder *replayBuilder);
void clearTeamErroredForActiveConsoles(BerryBotsEngine *engine);
void resumeMatch();
void showDialog(wxFrame *dialog);
bool confirmDialogSwitch(int nextWindow);
void destroyStageConsole();
void destroyResultsDialog();
void saveCurrentMatchSettings(
const char *stageName, char **teamNames, int numTeams);
void deleteCurrentMatchSettings();
int loadItemsFromDir(const char *baseDir, const char *loadDir,
int itemType, void *itemDialog, BerryBotsEngine *engine);
void updateFramerate();
void logErrorMessage(lua_State *L, const char *formatString);
};
class MatchStarter : public NewMatchListener {
GuiManager *guiManager_;
public:
MatchStarter(GuiManager *guiManager);
virtual void startMatch(const char *stageName, char **teamNames,
int numTeams);
virtual void previewStage(const char *stagePath);
virtual void refreshFiles();
virtual void onClose();
virtual void onEscape();
virtual void onUpdateUi();
virtual void reloadBaseDirs();
};
class ShipPackager : public PackageDialogListener {
GuiManager *guiManager_;
FileManager *fileManager_;
OutputConsole *packagingConsole_;
public:
ShipPackager(GuiManager *guiManager, FileManager *fileManager,
OutputConsole *packagingConsole);
virtual void package(const char *shipName, const char *version,
bool obfuscate);
virtual void refreshFiles();
virtual void onClose();
virtual void onEscape();
virtual void onUpdateUi();
};
class StagePackager : public PackageDialogListener {
GuiManager *guiManager_;
FileManager *fileManager_;
OutputConsole *packagingConsole_;
public:
StagePackager(GuiManager *guiManager, FileManager *fileManager,
OutputConsole *packagingConsole);
virtual void package(const char *stageName, const char *version,
bool obfuscate);
virtual void refreshFiles();
virtual void onClose();
virtual void onEscape();
virtual void onUpdateUi();
};
class RunnerLauncher : public RunnerDialogListener {
GuiManager *guiManager_;
FileManager *fileManager_;
OutputConsole *runnerConsole_;
public:
RunnerLauncher(GuiManager *guiManager, FileManager *fileManager,
OutputConsole *runnerConsole);
virtual void launch(const char *runnerName);
virtual void refreshFiles();
virtual void onClose();
virtual void onEscape();
virtual void onUpdateUi();
};
class PackageReporter : public PackagingListener {
OutputConsole *packagingConsole_;
public:
PackageReporter(OutputConsole *packagingConsole);
virtual void packagingComplete(char **sourceFiles, int numFiles,
bool obfuscate, const char *destinationFile);
};
class StageConsoleListener : public ConsoleListener {
Stage *stage_;
public:
StageConsoleListener(Stage *stage);
virtual void onActive() {};
virtual void onClose() {};
virtual void onCheck(bool checked);
virtual void onAbort() {};
virtual ~StageConsoleListener() {};
};
class PreviewInputListener : public StagePreviewListener {
GuiManager *guiManager_;
public:
PreviewInputListener(GuiManager *guiManager);
virtual void onClose();
virtual void onUp();
virtual void onDown();
};
class RunnerConsoleListener : public ConsoleListener {
GuiManager *guiManager_;
public:
RunnerConsoleListener(GuiManager *guiManager);
virtual void onActive() {};
virtual void onClose();
virtual void onCheck(bool checked) {};
virtual void onAbort();
virtual ~RunnerConsoleListener() {};
};
class ResultsRestarter : public ResultsDialogListener {
GuiManager *guiManager_;
public:
ResultsRestarter(GuiManager *guiManager);
virtual void onRestart();
};
class RunnerFormRedrawer : public RunnerFormListener {
GuiManager *guiManager_;
public:
RunnerFormRedrawer(GuiManager *guiManager);
virtual void onUpdateUi();
};
class ViewListener : public GfxViewListener {
GuiManager *guiManager_;
public:
ViewListener(GuiManager *guiManager);
virtual void onNewMatch();
virtual void onPackageShip();
virtual void onPackageStage();
virtual void onStageClick();
virtual void onTeamClick(int teamIndex);
virtual void onPauseUnpause();
virtual void onRestart();
virtual void onTpsChange(double tpsFactor);
};
#endif