1
// $Id: start_screen.cxx,v 1.17 2003/04/12 15:52:17 torangan Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include "gui/gui_manager.hxx"
23
#include "gui/surface_button.hxx"
24
#include "gui/component.hxx"
25
#include "gui/screen_manager.hxx"
26
#include "my_gettext.hxx"
27
#include "game_session.hxx"
28
#include "globals.hxx"
29
#include "string_converter.hxx"
33
#include "pingus_resource.hxx"
34
#include "start_screen.hxx"
35
#include "game_time.hxx"
36
#include "sound/sound.hxx"
38
class StartScreenComponent : public GUI::Component
44
std::string description;
47
StartScreenComponent(PLFHandle plf);
48
void draw(GraphicContext& gc);
49
virtual ~StartScreenComponent() {}
52
const std::string& format_description(int length);
55
class StartScreenOkButton : public GUI::SurfaceButton
60
StartScreenOkButton(StartScreen* p)
61
: GUI::SurfaceButton(CL_Display::get_width()/2 + 225,
62
CL_Display::get_height()/2 + 125,
63
ResDescriptor("start/ok", "core", ResDescriptor::RD_RESOURCE),
64
ResDescriptor("start/ok_clicked", "core", ResDescriptor::RD_RESOURCE),
65
ResDescriptor("start/ok_hover", "core", ResDescriptor::RD_RESOURCE)),
70
void draw(GraphicContext& gc) {
71
SurfaceButton::draw(gc);
72
gc.print_center(Fonts::chalk_normal, x_pos + 32, y_pos - 17, _("Ok"));
77
PingusSound::play_sound("yipee");
82
void on_pointer_enter()
84
SurfaceButton::on_pointer_enter();
85
PingusSound::play_sound ("tick");
90
class StartScreenAbortButton
91
: public GUI::SurfaceButton
96
StartScreenAbortButton(StartScreen* p)
97
: GUI::SurfaceButton(CL_Display::get_width()/2 - 278,
98
CL_Display::get_height()/2 + 144,
99
ResDescriptor("start/back", "core", ResDescriptor::RD_RESOURCE),
100
ResDescriptor("start/back_clicked", "core", ResDescriptor::RD_RESOURCE),
101
ResDescriptor("start/back_hover", "core", ResDescriptor::RD_RESOURCE)),
106
void draw(GraphicContext& gc) {
107
SurfaceButton::draw(gc);
108
gc.print_center(Fonts::chalk_normal, x_pos + 55, y_pos, _("Abort"));
112
parent->cancel_game();
115
void on_pointer_enter()
117
SurfaceButton::on_pointer_enter();
118
PingusSound::play_sound ("tick");
122
StartScreen::~StartScreen()
127
StartScreenComponent::StartScreenComponent(PLFHandle p)
130
background = Sprite("menu/startscreenbg", "core");
131
background.set_align_center();
132
time_str = GameTime::ticks_to_realtime_string(plf->get_time());
136
StartScreenComponent::draw(GraphicContext& gc)
139
background.put_screen(CL_Display::get_width()/2,CL_Display::get_height()/2);
141
int left_x = CL_Display::get_width()/2 - 120;
142
int right_x = CL_Display::get_width()/2 + 120;
143
int y = CL_Display::get_height()/2 + 10;
145
gc.print_center(Fonts::chalk_large,
147
CL_Display::get_height()/2 - 200,
148
System::translate(plf->get_levelname()));
150
gc.print_left(Fonts::chalk_normal,
151
CL_Display::get_width()/2 - 290,
152
CL_Display::get_height()/2 - 140,
153
format_description(800 - 230));
155
gc.print_left (Fonts::chalk_normal, left_x, y, _("Number of Pingus: "));
156
gc.print_right(Fonts::chalk_normal, right_x, y, to_string(plf->get_pingus()));
158
gc.print_left (Fonts::chalk_normal, left_x, y += 30, _("Number to Save: "));
159
gc.print_right(Fonts::chalk_normal, right_x, y, to_string(plf->get_number_to_save()));
161
gc.print_left (Fonts::chalk_normal, left_x, y += 30, _("Time: "));
162
gc.print_right(Fonts::chalk_normal, right_x, y, time_str);
164
gc.print_left (Fonts::chalk_normal, left_x, y += 30, _("Difficulty:"));
165
gc.print_right(Fonts::chalk_normal, right_x, y, to_string(plf->get_difficulty()) + "/100");
167
/*for (int i = 0; plf->get_difficulty())
171
gc.print_center(Fonts::chalk_small, CL_Display::get_width()/2,
172
CL_Display::get_height()/2 + 270, _("Author: ") + plf->get_author());
175
gc.print_left(Fonts::chalk_small, 110, 430, _("Filename: ") + plf->get_resname());
177
CL_System::sleep(30);
181
StartScreenComponent::format_description(int length)
183
if (description != "")
186
description = System::translate(plf->get_description());
188
if (description == "")
191
std::string::size_type pos = 0;
192
while ((pos = description.find('\t', pos)) != std::string::npos)
193
description.replace(pos, 1, 1, ' ');
196
while ((pos = description.find(" ", pos)) != std::string::npos)
197
description.replace(pos, 2, 1, ' ');
200
while ((pos = description.find('\n', pos)) != std::string::npos)
202
if (pos < description.length() && description[pos + 1] == '\n') // double enter marks paragraph
204
description.replace(pos, 2, 1, '\n'); // replace the two \n by one
206
else if (pos < description.length() - 1 && description[pos + 1] == ' ' && description[pos + 2] == '\n')
208
description.replace(pos, 3, 1, '\n'); // whitespace between the two \n doesn't matter
212
description.replace(pos, 1, 1, ' ');
213
continue; // no \n here anymore, so continue searching
216
if (pos && description[pos - 1] == ' ')
217
description.replace(pos - 1, 2, 1, '\n'); // no whitespace in front
219
if (pos < description.length() && description[pos + 1] == ' ')
220
description.replace(pos, 2, 1, '\n'); // no whitespace behind
222
++pos; // we don't want to find it again
226
while ((pos = description.find(" ", pos)) != std::string::npos)
227
description.replace(pos, 2, 1, ' ');
231
int previous_space = 0;
233
while ((pos = description.find(' ', pos + 1)) != std::string::npos)
235
if (Fonts::chalk_normal->get_text_width(description.substr(start_pos, pos - start_pos)) > length)
237
description[previous_space] = '\n';
238
start_pos = previous_space + 1;
240
else if (Fonts::chalk_normal->get_text_width(description.substr(start_pos, description.length())) <= length)
243
previous_space = pos;
250
StartScreen::StartScreen(PLFHandle arg_plf)
253
StartScreenComponent* comp = new StartScreenComponent(plf);
254
gui_manager->add(comp);
255
gui_manager->add(new StartScreenOkButton(this));
256
gui_manager->add(new StartScreenAbortButton(this));
260
StartScreen::on_fast_forward_press()
266
StartScreen::on_pause_press ()
272
StartScreen::on_escape_press()
278
StartScreen::start_game()
280
PingusGameSession* game_session = new PingusGameSession(plf, true);
281
ScreenManager::instance()->replace_screen(game_session, true);
285
StartScreen::cancel_game()
287
ScreenManager::instance()->pop_screen();