~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/start_screen.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: start_screen.cpp 3422 2007-10-31 05:02:09Z grumbel $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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.
 
19
 
 
20
#include <iostream>
 
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"
 
26
#include "gettext.h"
 
27
#include "game_session.hpp"
 
28
#include "globals.hpp"
 
29
#include "system.hpp"
 
30
#include "fonts.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"
 
39
 
 
40
class StartScreenComponent : public GUI::Component
 
41
{
 
42
private:
 
43
  PingusLevel plf;
 
44
  Sprite background;
 
45
  std::string time_str;
 
46
  std::string description;
 
47
 
 
48
public:
 
49
  StartScreenComponent(const PingusLevel& plf);
 
50
  void draw(DrawingContext& gc);
 
51
  virtual ~StartScreenComponent() {}
 
52
 
 
53
private:
 
54
  const std::string& format_description(int length);
 
55
};
 
56
 
 
57
class StartScreenOkButton : public GUI::SurfaceButton
 
58
{
 
59
private:
 
60
  StartScreen* parent;
 
61
public:
 
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")),
 
68
      parent(p)
 
69
  {
 
70
  }
 
71
 
 
72
  void draw(DrawingContext& gc) {
 
73
    SurfaceButton::draw(gc);
 
74
    gc.print_center(Fonts::chalk_normal, x_pos + 30, y_pos - 20, _("Ok"));
 
75
  }
 
76
 
 
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());
 
80
  }
 
81
 
 
82
  void on_click()
 
83
  {
 
84
    Sound::PingusSound::play_sound("yipee");
 
85
    parent->start_game();
 
86
  }
 
87
 
 
88
 
 
89
  void on_pointer_enter()
 
90
  {
 
91
    SurfaceButton::on_pointer_enter();
 
92
    Sound::PingusSound::play_sound ("tick");
 
93
  }
 
94
};
 
95
 
 
96
class StartScreenAbortButton
 
97
  : public GUI::SurfaceButton
 
98
{
 
99
private:
 
100
  StartScreen* parent;
 
101
public:
 
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")),
 
108
      parent(p)
 
109
  {
 
110
  }
 
111
 
 
112
  void draw(DrawingContext& gc) {
 
113
    SurfaceButton::draw(gc);
 
114
    gc.print_center(Fonts::chalk_normal, x_pos + 55, y_pos, _("Abort"));
 
115
  }
 
116
 
 
117
  void on_click() {
 
118
    parent->cancel_game();
 
119
  }
 
120
 
 
121
  void on_pointer_enter()
 
122
  {
 
123
    SurfaceButton::on_pointer_enter();
 
124
    Sound::PingusSound::play_sound ("tick");
 
125
  }
 
126
};
 
127
 
 
128
StartScreen::~StartScreen()
 
129
{
 
130
 
 
131
}
 
132
 
 
133
StartScreenComponent::StartScreenComponent(const PingusLevel& p)
 
134
  : plf(p)
 
135
{
 
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());
 
139
}
 
140
 
 
141
void
 
142
StartScreenComponent::draw(DrawingContext& gc)
 
143
{
 
144
  gc.draw(background, Display::get_width()/2.f, Display::get_height()/2.f);
 
145
 
 
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;
 
149
 
 
150
  gc.print_center(Fonts::chalk_large,
 
151
                  gc.get_width()/2,
 
152
                  Display::get_height()/2 - 200,
 
153
                  _(plf.get_levelname()));
 
154
 
 
155
  gc.print_left(Fonts::chalk_normal,
 
156
                Display::get_width()/2 - 290,
 
157
                Display::get_height()/2 - 150,
 
158
                format_description(800 - 230));
 
159
 
 
160
  y += 32;
 
161
  y += 30;
 
162
 
 
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()));
 
165
 
 
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()));
 
168
 
 
169
  gc.print_left (Fonts::chalk_normal, left_x,  (y += 30), _("Time: "));
 
170
  gc.print_right(Fonts::chalk_normal, right_x, y, time_str);
 
171
 
 
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");
 
174
 
 
175
  gc.print_center(Fonts::chalk_small, Display::get_width()/2,
 
176
                  Display::get_height()/2 + 270, _("Author: ") + plf.get_author());
 
177
 
 
178
  if (maintainer_mode)
 
179
    gc.print_left(Fonts::chalk_small, 110, 430, _("Filename: ") + plf.get_resname());
 
180
 
 
181
  SDL_Delay(10);
 
182
}
 
183
 
 
184
const std::string&
 
185
StartScreenComponent::format_description(int length)
 
186
{
 
187
  if (description != "")
 
188
    return description;
 
189
 
 
190
  description = _(plf.get_description());
 
191
 
 
192
  if (description == "")
 
193
    return description;
 
194
 
 
195
  description = StringFormat::break_line(description, length, Fonts::chalk_normal);
 
196
 
 
197
  return description;
 
198
}
 
199
 
 
200
 
 
201
StartScreen::StartScreen(const PingusLevel& arg_plf)
 
202
  : plf(arg_plf)
 
203
{
 
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);
 
208
}
 
209
 
 
210
void
 
211
StartScreen::on_fast_forward_press()
 
212
{
 
213
  start_game();
 
214
}
 
215
 
 
216
void
 
217
StartScreen::on_pause_press ()
 
218
{
 
219
  start_game();
 
220
}
 
221
 
 
222
void
 
223
StartScreen::on_escape_press()
 
224
{
 
225
  cancel_game();
 
226
}
 
227
 
 
228
void
 
229
StartScreen::start_game()
 
230
{
 
231
  PingusGameSession* game_session = new PingusGameSession(plf, true);
 
232
  ScreenManager::instance()->replace_screen(game_session, true);
 
233
}
 
234
 
 
235
void
 
236
StartScreen::cancel_game()
 
237
{
 
238
  ScreenManager::instance()->pop_screen();
 
239
}
 
240
 
 
241
 
 
242
/* EOF */