1
// $Id: OptionMenu.cc,v 1.40 2002/01/14 23:37:59 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.
23
#include "PingusResource.hh"
25
#include "OptionMenu.hh"
26
#include "StringConverter.hh"
27
#include "PingusMenuManager.hh"
29
/* Headers needed for i18n / gettext */
32
#include "my_gettext.hh"
35
// Define the global option menu
36
OptionMenu option_menu (0);
38
// ----- OptionEntry -----
40
OptionEntry::OptionEntry(std::string s, bool* v, int x, int y)
42
font = PingusResource::load_font("Fonts/smallfont_h", "fonts");
51
OptionEntry::OptionEntry(std::string s, std::string* v, int x, int y)
53
font = PingusResource::load_font("Fonts/smallfont_h", "fonts");
62
OptionEntry::OptionEntry(std::string s, int* v, int x, int y)
64
font = PingusResource::load_font("Fonts/smallfont_h", "fonts");
77
CL_Display::fill_rect(x_pos - 7, y_pos - 1,
78
x_pos + CL_Display::get_width() - 35, y_pos + 11,
81
CL_Display::fill_rect(x_pos - 7, y_pos - 1,
82
x_pos + CL_Display::get_width() - 35, y_pos + 11,
83
1.0f, 0.0f, 0.0f, 0.4f);
85
font->print_left(x_pos, y_pos, str.c_str());
89
font->print_right(x_pos + CL_Display::get_width() - 35, y_pos, _("on"));
91
font->print_right(x_pos + CL_Display::get_width() - 35, y_pos, _("off"));
93
} else if (value_str) {
94
font->print_right(x_pos + CL_Display::get_width() - 35, y_pos, value_str->c_str());
95
} else if (value_int) {
97
font->print_right(x_pos + CL_Display::get_width() - 35, y_pos, to_string (*value_int).c_str ());
102
OptionEntry::toggle()
105
*(value_bool) = !*(value_bool);
106
} else if (value_str) {
107
std::cout << _("Not implemented") << std::endl;
108
} else if (value_int) {
114
OptionEntry::rtoggle()
117
*(value_bool) = !*(value_bool);
118
} else if (value_str) {
119
std::cout << _("Not implemented") << std::endl;
120
} else if (value_int) {
126
OptionEntry::mouse_over()
128
if (CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + CL_Display::get_width() - 30
129
&& CL_Mouse::get_y() > y_pos && CL_Mouse::get_y() < y_pos + 15) {
137
OptionMenu::Event::on_button_press(CL_InputDevice *device, const CL_Key &key)
142
OptionMenu::Event::on_button_release(CL_InputDevice *device, const CL_Key &key)
144
if (device == CL_Input::keyboards[0])
149
option_menu->quit = true;
152
if (verbose) std::cout << _("OptionMenu::Event: Unknown key released: id=") << key.id << std::endl;
156
else if (device == CL_Input::pointers[0])
160
case CL_MOUSE_LEFTBUTTON:
161
if (verbose) std::cout << _("Button 0 pressed") << std::endl;
163
case CL_MOUSE_MIDDLEBUTTON:
164
option_menu->quit = true;
165
if (verbose) std::cout << _("Button 1 pressed") << std::endl;
167
case CL_MOUSE_RIGHTBUTTON:
168
if (verbose) std::cout << _("Button 2 pressed") << std::endl;
171
if (verbose) std::cout << _("OptionMenu::Event: Unknown mouse button released: id=") << key.id << std::endl;
177
// ----- OptionMenu -----
179
OptionMenu::OptionMenu(PingusMenuManager* m)
186
event->option_menu = this;
189
OptionMenu::~OptionMenu()
200
//loading_screen.draw();
202
font = PingusResource::load_font("Fonts/smallfont_h", "fonts");
203
title_font = PingusResource::load_font("Fonts/pingus", "fonts");
204
background = PingusResource::load_surface("Textures/rocktile", "textures");
205
back = PingusResource::load_surface("buttons/back", "core");
212
add_entry(_("Gimmicks"), &gimmicks_enabled);
213
add_entry(_("Unlimited Actions"), &unlimited_actions);
214
add_entry(_("Print fps"), &print_fps);
215
// add_entry("Debug actions", &debug_actions);
216
add_entry(_("Cursor enabled"), &cursor_enabled);
217
add_entry(_("Fast Mode"), &fast_mode);
218
//add_entry(_("Pingus Datadir"), &pingus_datadir);
219
add_entry(_("Game Speed"), &game_speed);
220
add_entry(_("Verbose"), &verbose);
221
add_entry(_("Music"), &music_enabled);
222
add_entry(_("Sound"), &sound_enabled);
223
add_entry(_("Level Previews"), &previews_enabled);
224
add_entry(_("Draw ColMap"), &draw_collision_map);
225
//add_entry(_("Debug GameTime"), &debug_game_time);
226
//add_entry(_("Debug Tiles"), &debug_tiles);
227
add_entry(_("Auto Scrolling"), &auto_scrolling);
228
add_entry(_("Action Help Strings"), &action_help);
232
OptionMenu::add_entry(std::string e, bool* v)
234
entry.push_back(OptionEntry(e, v, entry_x, entry_y));
239
OptionMenu::add_entry(std::string e, int* v)
241
entry.push_back(OptionEntry(e, v, entry_x, entry_y));
246
OptionMenu::add_entry(std::string e, std::string* v)
248
entry.push_back(OptionEntry(e, v, entry_x, entry_y));
253
OptionMenu::draw_background()
255
for(int y=0; y < CL_Display::get_height(); y += background.get_height()) {
256
for(int x=0; x < CL_Display::get_width(); x += background.get_width()) {
257
background.put_screen(x, y);
267
title_font->print_center(CL_Display::get_width() / 2, 10, _("Pingus Option Menu"));
269
for(EntryIter item = entry.begin(); item != entry.end(); ++item) {
273
back.put_screen(0, 0);
274
if (CL_Mouse::get_x() < (int)back.get_width()
275
&& CL_Mouse::get_y() < (int)back.get_height())
276
CL_Display::fill_rect(0, 0, back.get_width(), back.get_height(),
277
1.0f, 1.0f, 1.0f, 0.3f);
281
OptionMenu::check_click()
283
for(EntryIter item = entry.begin(); item != entry.end(); ++item) {
284
if (item->mouse_over()) {
292
OptionMenu::update (float delta)
294
EntryIter item = EntryIter();
295
item = current_item();
297
if (CL_Mouse::left_pressed())
299
if (CL_Mouse::get_x() < (int)back.get_width() &&
300
CL_Mouse::get_y() < (int)back.get_height())
303
if (manager) manager->set_menu (&manager->mainmenu);
306
if (item != EntryIter())
309
while(CL_Mouse::left_pressed())
310
CL_System::keep_alive();
313
if (CL_Mouse::right_pressed())
315
if (item != EntryIter())
318
while(CL_Mouse::right_pressed())
319
CL_System::keep_alive();
324
OptionMenu::display()
329
//int temp_index = -2;
331
EntryIter item = EntryIter();
332
EntryIter temp_item = EntryIter();
334
while(CL_Mouse::left_pressed())
335
CL_System::keep_alive();
339
//CL_Input::chain_button_press.push_back(event);
340
//CL_Input::chain_button_release.push_back(event);
342
CL_Input::sig_button_press.connect (event, &OptionMenu::Event::on_button_press);
343
CL_Input::sig_button_release.connect (event, &OptionMenu::Event::on_button_release);
345
Display::set_cursor(CL_MouseCursorProvider::load("Cursors/cursor",
346
PingusResource::get("game")));
347
Display::show_cursor();
362
Display::hide_cursor();
364
//CL_Input::chain_button_release.remove(event);
365
//CL_Input::chain_button_press.remove(event);
368
std::vector<OptionEntry>::iterator
369
OptionMenu::current_item()
371
for(EntryIter item = entry.begin(); item != entry.end(); ++item) {
372
if (item->mouse_over()) {
376
return std::vector<OptionEntry>::iterator();