1
// $Id: ActionButton.cc,v 1.27 2002/01/15 22:32:05 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 1999 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.
24
#include "PingusResource.hh"
25
#include "ActionButton.hh"
35
EventButton::EventButton(int x, int y, std::string str)
37
surface = PingusResource::load_surface(str, "global");
42
EventButton::~EventButton() {}
47
if (mouse_over(CL_Vector() /* FIXME */))
49
CL_Display::fill_rect(x_pos, y_pos,
50
x_pos + surface.get_width(), y_pos + surface.get_height(),
53
surface.put_screen(x_pos, y_pos);
57
EventButton::mouse_over(const CL_Vector& pos)
59
if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
60
&& pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
70
ActionButton::ActionButton() {}
71
ActionButton::~ActionButton() {}
74
ActionButton::init(int x, int y, std::string str, int owner_id)
76
// make_action = func;
81
if (name == "digger" || name == "bomber"
82
|| name == "floater" || name == "blocker")
84
is_multi_direct = false;
88
is_multi_direct = true;
92
font = PingusResource::load_font("Fonts/courier_small", "fonts");
93
font_h = PingusResource::load_font("Fonts/smallfont","fonts");
94
font_b = PingusResource::load_font("Fonts/pingus","fonts");
97
font = PingusResource::load_font("Fonts/pingus_small", "fonts");
98
font_h = PingusResource::load_font("Fonts/pingus_small","fonts");
99
font_b = PingusResource::load_font("Fonts/pingus","fonts");
103
surface = PingusResource::load_surface("Pingus/" + str + to_string(owner_id),
107
action_c.set_size(surface.get_num_frames()/2);
111
action_c.set_size(surface.get_num_frames());
114
action_c.set_speed(50);
119
ActionButton::is_pressed()
125
ActionButton::update(float delta)
131
ActionButton::get_action_name()
137
ActionButton::set_action_holder(ActionHolder* h)
142
VerticalActionButton::VerticalActionButton(int x, int y, std::string str, int owner_id)
143
: background (PingusResource::load_surface("buttons/buttonbackground", "core")),
144
backgroundhl (PingusResource::load_surface("buttons/buttonbackgroundhl", "core"))
146
init(x, y, str, owner_id);
149
VerticalActionButton::~VerticalActionButton() {}
152
VerticalActionButton::mouse_over(const CL_Vector& pos)
154
if (pos.x > x_pos && pos.x < x_pos + 60
155
&& pos.y > y_pos && pos.y <= y_pos + 35)
166
VerticalActionButton::draw()
169
// FIXME: This could need some optimization, throwing strings all
170
// FIXME: around, doesn't look like a good idea.
171
available = action_holder->get_available(name);
173
if (unlimited_actions) {
176
str = to_string(available);
182
CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
185
//CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
186
//1.0, 1.0, 1.0, 0.5);
187
backgroundhl.put_screen (x_pos, y_pos);
189
font_h->print_center(x_pos + 46, y_pos + 10, str.c_str ());
198
background.put_screen (x_pos, y_pos);
200
font->print_center(x_pos + 46, y_pos + 10, str.c_str ());
203
// print the action name next to the button, when mouse pointer is on
206
&& CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + 60
207
&& CL_Mouse::get_y() < y_pos + 35 && CL_Mouse::get_y() > y_pos)
209
font_b->print_left (x_pos + 65, y_pos, name.c_str());
212
surface.put_screen(x_pos + 20 - surface.get_width ()/2,
213
y_pos + 17 - surface.get_height ()/2,
217
ArmageddonButton::ArmageddonButton(int x, int y)
219
surface = PingusResource::load_surface("buttons/armageddon_anim", "core");
221
background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
222
backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
224
counter.set_size(surface.get_num_frames());
231
ArmageddonButton::~ArmageddonButton() {}
234
ArmageddonButton::draw()
238
backgroundhl.put_screen (x_pos, y_pos);
239
surface.put_screen(x_pos, y_pos, ++counter);
243
background.put_screen (x_pos, y_pos);
244
surface.put_screen(x_pos, y_pos, 7);
249
ArmageddonButton::mouse_over(const CL_Vector& pos)
251
if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
252
&& pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
260
ForwardButton::ForwardButton(int x, int y)
262
surface = PingusResource::load_surface("buttons/fast_forward", "core");
263
background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
264
backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
270
ForwardButton::~ForwardButton() {}
273
ForwardButton::draw()
275
if (server->get_fast_forward())
276
backgroundhl.put_screen (x_pos, y_pos);
278
background.put_screen (x_pos, y_pos);
280
surface.put_screen(x_pos, y_pos);
284
ForwardButton::mouse_over(const CL_Vector& pos)
286
if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
287
&& pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
295
PauseButton::PauseButton(int x, int y)
297
surface = PingusResource::load_surface("buttons/pause", "core");
299
background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
300
backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
306
PauseButton::~PauseButton() {}
311
if (server->get_pause())
312
backgroundhl.put_screen (x_pos, y_pos);
314
background.put_screen (x_pos, y_pos);
316
surface.put_screen(x_pos, y_pos);
320
PauseButton::mouse_over(const CL_Vector& pos)
322
if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
323
&& pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))