1
// $Id: client.cxx,v 1.43 2003/03/25 00:37:44 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.
21
#include <ClanLib/Display/Display/display.h>
22
#include <ClanLib/Display/Display/mousecursor_provider.h>
23
#include "globals.hxx"
24
#include "playfield.hxx"
26
#include "pingus_resource.hxx"
27
#include "sound/sound.hxx"
28
#include "time_display.hxx"
29
#include "pingus_counter.hxx"
30
#include "smallmap.hxx"
32
#include "hurry_up.hxx"
33
#include "path_manager.hxx"
34
#include "gui/cursor.hxx"
35
#include "true_server.hxx"
36
#include "button_panel.hxx"
37
#include "gui/gui_manager.hxx"
39
Client::Client (TrueServer * s)
44
unplayable ("misc/unplayable2", "core"),
51
//cursor (new Cursor ("cursors/animcross", "core", controller))
53
//Display::add_flip_screen_hook(cursor);
55
unplayable.set_align_center();
57
Timer timer("Client UI generation");
59
Display::set_cursor(CL_MouseCursorProvider::load("Cursors/cursor",
60
PingusResource::get("game")));
62
// These object will get deleted by the gui_manager
63
button_panel = new ButtonPanel(this, 2, CL_Display::get_height()/2);
64
playfield = new Playfield(this);
65
hurry_up = new HurryUp(this);
66
pcounter = new PingusCounter(get_server());
67
small_map = new SmallMap(this);
68
time_display = new TimeDisplay(this);
70
gui_manager->add (playfield, true);
71
gui_manager->add (button_panel, true);
72
gui_manager->add (hurry_up, true);
73
gui_manager->add (pcounter, true);
74
gui_manager->add (small_map, true);
75
gui_manager->add (time_display, true);
77
gui_manager->add (new ArmageddonButton(server, CL_Display::get_width() - 40, CL_Display::get_height() - 62), true);
78
gui_manager->add (new ForwardButton (server, CL_Display::get_width() - 40 * 2, CL_Display::get_height() - 62), true);
79
gui_manager->add (new PauseButton (server, CL_Display::get_width() - 40 * 3, CL_Display::get_height() - 62), true);
80
// Connect the button_panel with the playfield
81
playfield->set_buttons(button_panel);
82
playfield->set_server(server);
92
Client::update (const GameDelta& delta)
94
GUIScreen::update (delta);
95
process_events(delta);
99
Client::process_events (const GameDelta& delta)
101
const Input::EventLst& events = delta.get_events ();
103
for (Input::EventLst::const_iterator i = events.begin ();
107
//std::cout << "Events: " << (*i)->get_type () << std::endl;
111
case Input::ButtonEventType:
113
const Input::ButtonEvent& ev = i->button;
115
if (ev.state == Input::pressed)
117
if (ev.name >= Input::action_1 && ev.name <= Input::action_10)
119
button_panel->set_button(ev.name - Input::action_1);
121
else if (ev.name == Input::action_down)
123
button_panel->next_action();
125
else if (ev.name == Input::action_up)
127
button_panel->previous_action();
133
case Input::PointerEventType:
134
// Ignore, is handled in GUIScreen
135
//process_pointer_event (dynamic_cast<class Input::PointerEvent* const>(*i));
138
case Input::AxisEventType:
140
process_axis_event (i->axis);
143
case Input::ScrollEventType:
144
process_scroll_event(i->scroll);
149
std::cout << "Client::process_events (): unhandled event: " << i->type << std::endl;
156
Client::process_scroll_event (const Input::ScrollEvent& ev)
158
std::cout << "Client::process_scroll_event ()" << std::endl;
159
playfield->scroll(static_cast<int>(ev.x_delta),
160
static_cast<int>(ev.y_delta));
164
Client::process_axis_event (const Input::AxisEvent& event)
166
std::cout << "Client::process_axis_event ()" << std::endl;
180
server->set_finished();
190
Client::set_finished()
193
server->set_finished();
198
Client::on_keyboard_button_press(const CL_Key& /*key*/)
200
if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT)
201
|| CL_Keyboard::get_keycode(CL_KEY_RSHIFT))
203
playfield->scroll_speed = 50;
207
playfield->scroll_speed = 15;
212
Client::on_keyboard_button_release(const CL_Key& key)
214
std::cout << "Keyboard pressed: " << key.id << std::endl;
219
Display::hide_cursor();
220
option_menu.display ();
221
Display::show_cursor();
225
// Playfield scrolling
227
playfield->view[playfield->current_view]->set_x_offset(playfield->view[playfield->current_view]->get_x_offset() + playfield->scroll_speed);
231
playfield->view[playfield->current_view]->set_x_offset(playfield->view[playfield->current_view]->get_x_offset() - playfield->scroll_speed);
235
playfield->view[playfield->current_view]->set_y_offset(playfield->view[playfield->current_view]->get_y_offset() + playfield->scroll_speed);
239
playfield->view[playfield->current_view]->set_y_offset(playfield->view[playfield->current_view]->get_y_offset() - playfield->scroll_speed);
243
case CL_KEY_PAGEDOWN:
244
playfield->view[playfield->current_view]->set_zoom(playfield->view[playfield->current_view]->get_zoom() / 1.05);
248
playfield->view[playfield->current_view]->set_zoom(playfield->view[playfield->current_view]->get_zoom() / 0.95);
252
playfield->view[playfield->current_view]->set_zoom(1.0);
258
server->set_pause(pause);
262
server->send_armageddon_event();
270
set_fast_forward(!get_fast_forward());
274
server->set_finished();
278
button_panel->set_button(0);
281
button_panel->set_button(1);
284
button_panel->set_button(2);
287
button_panel->set_button(3);
290
button_panel->set_button(4);
293
button_panel->set_button(5);
296
button_panel->set_button(6);
299
button_panel->set_button(7);
302
if (verbose > 1) std::cout << "Client: Got unknown button: ID=" << key.id << " ASCII=" << char(key.ascii) << std::endl;
308
Client:: on_escape_press ()
310
server->set_finished();
314
Client:: on_pause_press ()
316
server->set_pause (!server->get_pause ());
320
Client::on_fast_forward_press ()
322
server->set_fast_forward(!server->get_fast_forward());
326
Client::on_armageddon_press ()
328
server->send_armageddon_event();
332
Client::on_action_axis_move (float move)
335
button_panel->next_action ();
337
button_panel->previous_action ();
341
Client::draw (GraphicContext& gc)
343
GUIScreen::draw (gc);
344
if (!server->get_plf()->get_playable())
345
gc.draw(unplayable, Vector(400, 50));
350
Client::on_startup ()
352
/** Hide the system cursor and show the software one */
353
Display::show_cursor();
354
// FIXME: using this twice will crash with an X Error
355
//CL_MouseCursor::hide ();
362
std::cout << "Starting Music: " << server->get_plf()->get_music() << std::endl;
364
if (server->get_plf()->get_music() == "none")
366
PingusSound::stop_music();
370
PingusSound::play_music(server->get_plf ()->get_music());
374
std::cout << "Client: Entering main_loop. Startup time: "
375
<< CL_System::get_time() << " msec." << std::endl;
379
Client::on_shutdown ()
381
Display::hide_cursor();