1
// $Id: start_screen.cpp 3422 2007-10-31 05:02:09Z grumbel $
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.
21
#include "gui/gui_manager.hpp"
22
#include "gui/surface_button.hpp"
23
#include "gui/component.hpp"
24
#include "screen/screen_manager.hpp"
25
#include "blitter.hpp"
27
#include "game_session.hpp"
28
#include "globals.hpp"
31
#include "resource.hpp"
32
#include "start_screen.hpp"
33
#include "game_time.hpp"
34
#include "sound/sound.hpp"
35
#include "pingus_level.hpp"
36
#include "string_format.hpp"
37
#include "display/display.hpp"
38
#include "string_util.hpp"
40
class StartScreenComponent : public GUI::Component
46
std::string description;
49
StartScreenComponent(const PingusLevel& plf);
50
void draw(DrawingContext& gc);
51
virtual ~StartScreenComponent() {}
54
const std::string& format_description(int length);
57
class StartScreenOkButton : public GUI::SurfaceButton
62
StartScreenOkButton(StartScreen* p)
63
: GUI::SurfaceButton(Display::get_width()/2 + 225,
64
Display::get_height()/2 + 125,
65
ResDescriptor("core/start/ok"),
66
ResDescriptor("core/start/ok_clicked"),
67
ResDescriptor("core/start/ok_hover")),
72
void draw(DrawingContext& gc) {
73
SurfaceButton::draw(gc);
74
gc.print_center(Fonts::chalk_normal, x_pos + 30, y_pos - 20, _("Ok"));
77
bool is_at(int x, int y) {
78
return x > x_pos && x < x_pos + int(button_surface.get_width())
79
&& y > y_pos - 20 && y < y_pos + int(button_surface.get_height());
84
Sound::PingusSound::play_sound("yipee");
89
void on_pointer_enter()
91
SurfaceButton::on_pointer_enter();
92
Sound::PingusSound::play_sound ("tick");
96
class StartScreenAbortButton
97
: public GUI::SurfaceButton
102
StartScreenAbortButton(StartScreen* p)
103
: GUI::SurfaceButton(Display::get_width()/2 - 300,
104
Display::get_height()/2 + 144,
105
ResDescriptor("core/start/back"),
106
ResDescriptor("core/start/back_clicked"),
107
ResDescriptor("core/start/back_hover")),
112
void draw(DrawingContext& gc) {
113
SurfaceButton::draw(gc);
114
gc.print_center(Fonts::chalk_normal, x_pos + 55, y_pos, _("Abort"));
118
parent->cancel_game();
121
void on_pointer_enter()
123
SurfaceButton::on_pointer_enter();
124
Sound::PingusSound::play_sound ("tick");
128
StartScreen::~StartScreen()
133
StartScreenComponent::StartScreenComponent(const PingusLevel& p)
136
background = Resource::load_sprite("core/menu/startscreenbg");
137
background.scale(Display::get_width(), Display::get_height());
138
time_str = GameTime::ticks_to_realtime_string(plf.get_time());
142
StartScreenComponent::draw(DrawingContext& gc)
144
gc.draw(background, Display::get_width()/2.f, Display::get_height()/2.f);
146
int left_x = Display::get_width()/2 - 150;
147
int right_x = Display::get_width()/2 + 150;
148
int y = Display::get_height()/2 + 40;
150
gc.print_center(Fonts::chalk_large,
152
Display::get_height()/2 - 200,
153
_(plf.get_levelname()));
155
gc.print_left(Fonts::chalk_normal,
156
Display::get_width()/2 - 290,
157
Display::get_height()/2 - 150,
158
format_description(800 - 230));
163
gc.print_left (Fonts::chalk_normal, left_x, y, _("Number of Pingus: "));
164
gc.print_right(Fonts::chalk_normal, right_x, y, StringUtil::to_string(plf.get_number_of_pingus()));
166
gc.print_left (Fonts::chalk_normal, left_x, (y += 30), _("Number to Save: "));
167
gc.print_right(Fonts::chalk_normal, right_x, y, StringUtil::to_string(plf.get_number_to_save()));
169
gc.print_left (Fonts::chalk_normal, left_x, (y += 30), _("Time: "));
170
gc.print_right(Fonts::chalk_normal, right_x, y, time_str);
172
//gc.print_left (Fonts::chalk_normal, left_x, (y += 30), _("Difficulty:"));
173
//gc.print_right(Fonts::chalk_normal, right_x, y, StringUtil::to_string(plf.get_difficulty()) + "/100");
175
gc.print_center(Fonts::chalk_small, Display::get_width()/2,
176
Display::get_height()/2 + 270, _("Author: ") + plf.get_author());
179
gc.print_left(Fonts::chalk_small, 110, 430, _("Filename: ") + plf.get_resname());
185
StartScreenComponent::format_description(int length)
187
if (description != "")
190
description = _(plf.get_description());
192
if (description == "")
195
description = StringFormat::break_line(description, length, Fonts::chalk_normal);
201
StartScreen::StartScreen(const PingusLevel& arg_plf)
204
StartScreenComponent* comp = new StartScreenComponent(plf);
205
gui_manager->add(comp, true);
206
gui_manager->add(new StartScreenOkButton(this), true);
207
gui_manager->add(new StartScreenAbortButton(this), true);
211
StartScreen::on_fast_forward_press()
217
StartScreen::on_pause_press ()
223
StartScreen::on_escape_press()
229
StartScreen::start_game()
231
PingusGameSession* game_session = new PingusGameSession(plf, true);
232
ScreenManager::instance()->replace_screen(game_session, true);
236
StartScreen::cancel_game()
238
ScreenManager::instance()->pop_screen();