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 "util/gettext.hpp"
25 const int SCAN_JOYSTICKS = Controller::CONTROLCOUNT + 1;
28 JoystickMenu::JoystickMenu(JoystickKeyboardController* _controller) :
29 controller(_controller)
34 JoystickMenu::~JoystickMenu()
38 JoystickMenu::recreateMenu()
41 add_label(_("Setup Joystick"));
43 if(controller->joysticks.size() > 0) {
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->jump_with_up_joy);
58 add_inactive(-1, _("No Joysticks found"));
61 add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
62 //Show Joysticks currently activated: //edit by giby
64 if (SDL_NumJoysticks() > 0) {
65 joy = SDL_JoystickOpen(0);
68 for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
69 i != controller->joysticks.end(); ++i) {
71 add_inactive(-1, SDL_JoystickName(joy) );
80 JoystickMenu::get_button_name(int button)
85 std::ostringstream name;
86 name << "Button " << button;
91 JoystickMenu::menu_action(MenuItem* item)
93 if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) {
94 item->change_input(_("Press Button"));
95 controller->wait_for_joystick = item->id;
96 } else if (item->id == Controller::CONTROLCOUNT) {
97 controller->jump_with_up_joy = item->toggled;
98 } else if( item->id == SCAN_JOYSTICKS) {
99 controller->updateAvailableJoysticks();
105 JoystickMenu::update_menu_item(Controller::Control id)
107 int button = controller->reversemap_joybutton(id);
108 int axis = controller->reversemap_joyaxis(id);
109 int hat_dir = controller->reversemap_joyhat(id);
112 get_item_by_id((int)id).change_input(get_button_name(button));
113 } else if (axis != 0) {
114 std::ostringstream name;
125 else if (abs(axis) == 2)
127 else if (abs(axis) == 2)
129 else if (abs(axis) == 3)
134 get_item_by_id((int)id).change_input(name.str());
135 } else if (hat_dir != -1) {
157 name = "Unknown hat_dir";
161 get_item_by_id((int)id).change_input(name);
163 get_item_by_id((int)id).change_input("None");
168 JoystickMenu::update()
170 if(controller->joysticks.size() == 0)
173 update_menu_item(Controller::UP);
174 update_menu_item(Controller::DOWN);
175 update_menu_item(Controller::LEFT);
176 update_menu_item(Controller::RIGHT);
178 update_menu_item(Controller::JUMP);
179 update_menu_item(Controller::ACTION);
180 update_menu_item(Controller::PAUSE_MENU);
181 update_menu_item(Controller::PEEK_LEFT);
182 update_menu_item(Controller::PEEK_RIGHT);
183 update_menu_item(Controller::PEEK_UP);
184 update_menu_item(Controller::PEEK_DOWN);
186 get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy;