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"
28 MNID_JUMP_WITH_UP = Controller::CONTROLCOUNT,
30 MNID_AUTO_JOYSTICK_CFG
35 JoystickMenu::JoystickMenu(InputManager* input_manager) :
36 m_input_manager(input_manager),
37 m_joysticks_available(false)
42 JoystickMenu::~JoystickMenu()
46 JoystickMenu::recreate_menu()
49 add_label(_("Setup Joystick"));
52 add_toggle(MNID_AUTO_JOYSTICK_CFG, _("Manual Joystick Configuration"),
53 !m_input_manager->use_game_controller());
55 if (m_input_manager->use_game_controller())
57 m_joysticks_available = false;
61 if (m_input_manager->joystick_manager->joysticks.size() > 0)
63 m_joysticks_available = true;
65 add_controlfield(Controller::UP, _("Up"));
66 add_controlfield(Controller::DOWN, _("Down"));
67 add_controlfield(Controller::LEFT, _("Left"));
68 add_controlfield(Controller::RIGHT, _("Right"));
69 add_controlfield(Controller::JUMP, _("Jump"));
70 add_controlfield(Controller::ACTION, _("Action"));
71 add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu"));
72 add_controlfield(Controller::PEEK_LEFT, _("Peek Left"));
73 add_controlfield(Controller::PEEK_RIGHT, _("Peek Right"));
74 add_controlfield(Controller::PEEK_UP, _("Peek Up"));
75 add_controlfield(Controller::PEEK_DOWN, _("Peek Down"));
77 add_toggle(MNID_JUMP_WITH_UP, _("Jump with Up"), m_input_manager->joystick_manager->jump_with_up_joy);
81 m_joysticks_available = false;
83 add_inactive(-1, _("No Joysticks found"));
84 add_entry(MNID_SCAN_JOYSTICKS, _("Scan for Joysticks"));
94 JoystickMenu::get_button_name(int button)
102 std::ostringstream name;
103 name << "Button " << button;
109 JoystickMenu::menu_action(MenuItem* item)
111 if (0 <= item->id && item->id < Controller::CONTROLCOUNT)
113 item->change_input(_("Press Button"));
114 m_input_manager->joystick_manager->wait_for_joystick = item->id;
116 else if (item->id == MNID_JUMP_WITH_UP)
118 m_input_manager->joystick_manager->jump_with_up_joy = item->toggled;
120 else if (item->id == MNID_AUTO_JOYSTICK_CFG)
122 m_input_manager->use_game_controller(!item->toggled);
123 m_input_manager->reset();
126 else if(item->id == MNID_SCAN_JOYSTICKS)
128 m_input_manager->reset();
134 JoystickMenu::update_menu_item(Controller::Control id)
136 int button = m_input_manager->joystick_manager->reversemap_joybutton(id);
137 int axis = m_input_manager->joystick_manager->reversemap_joyaxis(id);
138 int hat_dir = m_input_manager->joystick_manager->reversemap_joyhat(id);
142 get_item_by_id(static_cast<int>(id)).change_input(get_button_name(button));
146 std::ostringstream name;
157 else if (abs(axis) == 2)
159 else if (abs(axis) == 2)
161 else if (abs(axis) == 3)
166 get_item_by_id(static_cast<int>(id)).change_input(name.str());
168 else if (hat_dir != -1)
191 name = "Unknown hat_dir";
195 get_item_by_id(static_cast<int>(id)).change_input(name);
199 get_item_by_id(static_cast<int>(id)).change_input("None");
204 JoystickMenu::update()
206 if (m_joysticks_available)
208 update_menu_item(Controller::UP);
209 update_menu_item(Controller::DOWN);
210 update_menu_item(Controller::LEFT);
211 update_menu_item(Controller::RIGHT);
213 update_menu_item(Controller::JUMP);
214 update_menu_item(Controller::ACTION);
215 update_menu_item(Controller::PAUSE_MENU);
216 update_menu_item(Controller::PEEK_LEFT);
217 update_menu_item(Controller::PEEK_RIGHT);
218 update_menu_item(Controller::PEEK_UP);
219 update_menu_item(Controller::PEEK_DOWN);