forked from lksj/einstein-puzzle
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmenu.cpp
More file actions
215 lines (167 loc) · 5.66 KB
/
Copy pathmenu.cpp
File metadata and controls
215 lines (167 loc) · 5.66 KB
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
// This file is part of Einstein Puzzle
// Einstein Puzzle
// Copyright (C) 2003-2005 Flowix Games
// Modified 2012-05-06 by Jordan Evens <jordan.evens@gmail.com>
// Einstein Puzzle is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// Einstein Puzzle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "descr.h"
#include "game.h"
#include "main.h"
#include "messages.h"
#include "opensave.h"
#include "options.h"
#include "topscores.h"
#include "utils.h"
#include "widgets.h"
class MenuBackground: public Area
{
public:
MenuBackground();
};
MenuBackground::MenuBackground()
{
add(new Picture(0, 0, L"nova.bmp"));
std::wstring s(msg(L"einsteinFlowix"));
add(new ManagedLabel(L"nova.ttf", 28, 0, 30, screen.getWidth(), 0,
Label::ALIGN_CENTER, Label::ALIGN_TOP, 255, 255, 255, s));
s = L"http://games.flowix.com";
add(new ManagedLabel(L"luximb.ttf", 16, 0, 60, screen.getWidth(), 0,
Label::ALIGN_CENTER, Label::ALIGN_TOP, 255, 255, 0, s));
}
class NewGameCommand: public Command
{
private:
Area *area;
public:
explicit NewGameCommand(Area *a) { area = a; }
void doAction() override {
Game game;
game.run();
area->updateMouse();
area->draw();
}
};
class LoadGameCommand: public Command
{
private:
Area *area;
public:
explicit LoadGameCommand(Area *a) { area = a; }
void doAction() override {
Game *game = loadGame(area);
if (game) {
game->run();
delete game;
}
area->updateMouse();
area->draw();
}
};
class TopScoresCommand: public Command
{
private:
Area *area;
public:
explicit TopScoresCommand(Area *a) { area = a; }
void doAction() override {
TopScores scores;
showScoresWindow(area, &scores);
area->updateMouse();
area->draw();
}
};
class RulesCommand: public Command
{
private:
Area *area;
public:
explicit RulesCommand(Area *a) { area = a; }
void doAction() override {
showDescription(area);
area->updateMouse();
area->draw();
}
};
class OptionsCommand: public Command
{
private:
Area *area;
public:
explicit OptionsCommand(Area *a) { area = a; }
void doAction() override {
showOptionsWindow(area);
area->updateMouse();
area->draw();
}
};
class AboutCommand: public Command
{
private:
Area *parentArea;
public:
explicit AboutCommand(Area *a) { parentArea = a; }
void doAction() override {
Area area;
Font titleFont(L"nova.ttf", 26);
Font font(L"laudcn2.ttf", 14);
Font urlFont(L"luximb.ttf", 16);
#define LABEL(pos, c, f, text) area.add(new Label(&f, 220, pos, 360, 20, \
Label::ALIGN_CENTER, Label::ALIGN_MIDDLE, 255,255,c, text));
area.add(parentArea);
area.add(new Window(220, 160, 360, 280, L"blue.bmp"));
area.add(new Label(&titleFont, 250, 165, 300, 40, Label::ALIGN_CENTER,
Label::ALIGN_MIDDLE, 255,255,0, msg(L"about")));
LABEL(240, 255, font, msg(L"einsteinPuzzle"))
LABEL(260, 255, font, msg(L"version"))
LABEL(280, 255, font, msg(L"copyright"))
LABEL(330, 0, urlFont, L"http://games.flowix.com")
#undef LABEL
ExitCommand exitCmd(area);
area.add(new Button(360, 400, 80, 25, &font, 255,255,0, L"blue.bmp",
msg(L"ok"), &exitCmd));
area.add(new KeyAccel(SDLK_ESCAPE, &exitCmd));
area.add(new KeyAccel(SDLK_RETURN, &exitCmd));
area.run();
parentArea->updateMouse();
parentArea->draw();
}
};
static Button* menuButton(int y, Font *font, const std::wstring &text,
Command *cmd=nullptr)
{
return new Button(550, y, 220, 30, font, 0,240,240, 30,255,255, text, cmd);
}
void menu()
{
Area area;
Font font(L"laudcn2.ttf", 20);
area.add(new MenuBackground());
area.draw();
NewGameCommand newGameCmd(&area);
area.add(menuButton(340, &font, msg(L"newGame"), &newGameCmd));
LoadGameCommand loadGameCmd(&area);
area.add(menuButton(370, &font, msg(L"loadGame"), &loadGameCmd));
TopScoresCommand topScoresCmd(&area);
area.add(menuButton(400, &font, msg(L"topScores"), &topScoresCmd));
RulesCommand rulesCmd(&area);
area.add(menuButton(430, &font, msg(L"rules"), &rulesCmd));
OptionsCommand optionsCmd(&area);
area.add(menuButton(460, &font, msg(L"options"), &optionsCmd));
AboutCommand aboutCmd(&area);
area.add(menuButton(490, &font, msg(L"about"), &aboutCmd));
ExitCommand exitMenuCmd(area);
area.add(menuButton(520, &font, msg(L"exit"), &exitMenuCmd));
area.add(new KeyAccel(SDLK_ESCAPE, &exitMenuCmd));
area.draw();
screen.addRegionToUpdate(0, 0, screen.getWidth(), screen.getHeight());
screen.flush();
area.run();
}