2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
3 // 2007 Ingo Ruhnke <grumbel@gmx.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "supertux/menu/joystick_menu.hpp"
22 #include "control/joystick_manager.hpp"
23 #include "util/gettext.hpp"
25 JoystickMenu::JoystickMenu(JoystickKeyboardController* _controller) :
26 controller(_controller),
27 joysticks_available(false)
32 JoystickMenu::~JoystickMenu()
36 JoystickMenu::recreateMenu()
39 add_label(_("Setup Joystick"));
41 if(controller->joystick_manager->joysticks.size() > 0) {
42 joysticks_available = true;
44 add_controlfield(Controller::UP, _("Up"));
45 add_controlfield(Controller::DOWN, _("Down"));
46 add_controlfield(Controller::LEFT, _("Left"));
47 add_controlfield(Controller::RIGHT, _("Right"));
48 add_controlfield(Controller::JUMP, _("Jump"));
49 add_controlfield(Controller::ACTION, _("Action"));
50 add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu"));
51 add_controlfield(Controller::PEEK_LEFT, _("Peek Left"));
52 add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
53 add_controlfield(Controller::PEEK_UP, _("Peek Up"));
54 add_controlfield(Controller::PEEK_DOWN, _("Peek Down"));
56 add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->joystick_manager->jump_with_up_joy);
58 add_inactive(-1, _("No Joysticks found"));
59 joysticks_available = false;
68 JoystickMenu::get_button_name(int button)
73 std::ostringstream name;
74 name << "Button " << button;
79 JoystickMenu::menu_action(MenuItem* item)
81 if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) {
82 item->change_input(_("Press Button"));
83 controller->joystick_manager->wait_for_joystick = item->id;
84 } else if (item->id == Controller::CONTROLCOUNT) {
85 controller->joystick_manager->jump_with_up_joy = item->toggled;
90 JoystickMenu::update_menu_item(Controller::Control id)
92 int button = controller->joystick_manager->reversemap_joybutton(id);
93 int axis = controller->joystick_manager->reversemap_joyaxis(id);
94 int hat_dir = controller->joystick_manager->reversemap_joyhat(id);
97 get_item_by_id((int)id).change_input(get_button_name(button));
98 } else if (axis != 0) {
99 std::ostringstream name;
110 else if (abs(axis) == 2)
112 else if (abs(axis) == 2)
114 else if (abs(axis) == 3)
119 get_item_by_id((int)id).change_input(name.str());
120 } else if (hat_dir != -1) {
142 name = "Unknown hat_dir";
146 get_item_by_id((int)id).change_input(name);
148 get_item_by_id((int)id).change_input("None");
153 JoystickMenu::update()
155 log_info << controller->joystick_manager->joysticks.size() << std::endl;
157 if(true) //controller->joysticks.size() == 0)
163 if (!joysticks_available)
168 update_menu_item(Controller::UP);
169 update_menu_item(Controller::DOWN);
170 update_menu_item(Controller::LEFT);
171 update_menu_item(Controller::RIGHT);
173 update_menu_item(Controller::JUMP);
174 update_menu_item(Controller::ACTION);
175 update_menu_item(Controller::PAUSE_MENU);
176 update_menu_item(Controller::PEEK_LEFT);
177 update_menu_item(Controller::PEEK_RIGHT);
178 update_menu_item(Controller::PEEK_UP);
179 update_menu_item(Controller::PEEK_DOWN);
181 //get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy;