-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
executable file
·217 lines (167 loc) · 5.64 KB
/
menu.cpp
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
#include "menu.hpp"
#include "main.hpp"
#include "lobby.hpp"
#include "widget.hpp"
#include "widgetaction.hpp"
#include <fstream>
Image mainMenuBackground("mainMenu.png");
MainMenu *mainMenu = 0;
SinglePlayerMapMenu *singlePlayerMapMenu = 0;
MultiPlayerMapMenu *multiPlayerMapMenu = 0;
CreditsScreen *creditsScreen = 0;
std::string username;
std::string oldUsername;
Menu::Menu()
{
}
Menu::~Menu()
{
}
///////////////////////////////////////////////////////////////////////////
MainMenu::MainMenu()
{
}
MainMenu::~MainMenu()
{
}
void MainMenu::setupWidgets()
{
TextLabelGroup *labels = new TextLabelGroup(screenCenterX / 4, 250, 75, false);
// Single player
TextLabel *hostSP = new TextLabel("Single Player");
hostSP->setAction(new ChangeFrameAction(singlePlayerMapMenu));
labels->addTextLabel(hostSP);
// Host Multiplayer
TextLabel *hostMP = new TextLabel("Host Multiplayer");
hostMP->setAction(new ChangeFrameAction(multiPlayerMapMenu));
labels->addTextLabel(hostMP);
// Join Multiplayer
TextLabel *joinMP = new TextLabel("Join Multiplayer");
joinMP->setAction(new ChangeFrameAction(joinFrame));
labels->addTextLabel(joinMP);
// Credits
TextLabel *credits = new TextLabel("Credits");
credits->setAction(new ChangeFrameAction(creditsScreen));
labels->addTextLabel(credits);
// Quit
TextLabel *quit = new TextLabel("Quit");
quit->setAction(new ExitGameAction());
labels->addTextLabel(quit);
rootWidget->addChild(labels);
}
Image *MainMenu::getBackground() const
{
return &mainMenuBackground;
}
///////////////////////////////////////////////////////////////////////////
MapSelectionMenu::MapSelectionMenu()
{
parseMaps();
}
MapSelectionMenu::~MapSelectionMenu()
{
}
void MapSelectionMenu::parseMaps()
{
WIN32_FIND_DATA entry;
HANDLE handle = FindFirstFile("maps//*.map", &entry);
if (handle == INVALID_HANDLE_VALUE) return;
mapFileNames.push_back(strdup(entry.cFileName));
while(FindNextFile(handle,&entry))
mapFileNames.push_back(strdup(entry.cFileName));
FindClose(handle);
for(int ii = 0; ii < mapFileNames.size(); ii++)
{
Parser* temp = new Parser((std::string("maps/")+mapFileNames[ii]).c_str());
int maxPlayers = temp->getSection("Players")->size();
MapDesc desc;
desc.filename = mapFileNames[ii];
desc.maxPlayers = maxPlayers;
mapDescs.push_back(desc);
}
}
SinglePlayerMapMenu::SinglePlayerMapMenu()
{
}
SinglePlayerMapMenu::~SinglePlayerMapMenu()
{
}
void SinglePlayerMapMenu::setupWidgets()
{
rootWidget->addChild(new TextLabel("Select Map", 150, 130, false, fontMenuHeading));
ScrollPane<MapDesc> *maps = new ScrollPane<MapDesc>(100, 200, screenWidth-200, 350, mapDescs);
rootWidget->addChild(maps);
StartSinglePlayerAction *startGame = new StartSinglePlayerAction(maps);
maps->setAction(startGame);
TextLabel *okLabel = new TextLabel("OK", 300, 600, true);
okLabel->setAction(startGame);
TextLabel *backLabel = new TextLabel("Back", screenCenterX, 600, true);
backLabel->setAction(new ChangeFrameAction(mainMenu));
rootWidget->addChild(okLabel);
rootWidget->addChild(backLabel);
}
MultiPlayerMapMenu::MultiPlayerMapMenu()
{
}
MultiPlayerMapMenu::~MultiPlayerMapMenu()
{
}
void MultiPlayerMapMenu::setupWidgets()
{
rootWidget->addChild(new TextLabel("Host Game", 100, 100, false, fontMenuHeading));
ScrollPane<MapDesc> *maps = new ScrollPane<MapDesc>(100, 250, 820, 300, mapDescs);
rootWidget->addChild(maps);
TextLabel *gameNameLabel = new TextLabel("Game Name", 100, 200, false, fontDefault);
TextBox *gamename = new TextBox(250, 200, 200, "New Game");
TextLabel *playerNameLabel = new TextLabel("Player Name", 500, 200, false, fontDefault);
TextBox *playername = new TextBox(650, 200, 200, username);
rootWidget->addChild(gamename);
rootWidget->addChild(playername);
rootWidget->addChild(gameNameLabel);
rootWidget->addChild(playerNameLabel);
ShowHostLobbyAction *next = new ShowHostLobbyAction(maps, gamename, playername);
maps->setAction(next);
TextLabel *okLabel = new TextLabel("Start", 300, 700, true);
okLabel->setAction(next);
TextLabel *backLabel = new TextLabel("Back", 450, 700, true);
backLabel->setAction(new ChangeFrameAction(mainMenu));
rootWidget->addChild(okLabel);
rootWidget->addChild(backLabel);
}
///////////////////////////////////////////////////////////////////////////
CreditsScreen::CreditsScreen()
{
}
CreditsScreen::~CreditsScreen()
{
}
void CreditsScreen::setupWidgets()
{
const float titleOffsetX = 370;
const float roleOffsetX = 125;
const float nameOffsetX = 220;
rootWidget->addChild(new TextLabel("Programmers", roleOffsetX, 150.0f, false));
TextLabelGroup *programmers = new TextLabelGroup(nameOffsetX, 200.0f, 50.0f, false);
programmers->addTextLabel(new TextLabel("Ben Kalb - Project Leader"));
programmers->addTextLabel(new TextLabel("Jim Babcock - Lead Programmer"));
programmers->addTextLabel(new TextLabel("Chris Fellows - The Forgotten One"));
programmers->addTextLabel(new TextLabel("Diego Asturias - Programmer"));
programmers->addTextLabel(new TextLabel("Walter King - Map Editor Programmer"));
programmers->addTextLabel(new TextLabel("Yi Xu - Network Programmer"));
rootWidget->addChild(programmers);
rootWidget->addChild(new TextLabel("Artists", roleOffsetX, 500.0f, false));
TextLabelGroup *artists = new TextLabelGroup(nameOffsetX, 550.0f, 50.0f, false);
artists->addTextLabel(new TextLabel("Jason Liu"));
artists->addTextLabel(new TextLabel("Yuri Malitsky"));
rootWidget->addChild(artists);
}
bool CreditsScreen::mouseDown(int x, int y, int button, int mod)
{
Frame::changeFrame(mainMenu);
return true;
}
bool CreditsScreen::keyDown(SDL_keysym sym)
{
Frame::changeFrame(mainMenu);
return true;
}