X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fmenu%2Fjoystick_menu.cpp;h=adde0c5c81a8e04c19215c4a13a5f557687a64d7;hb=313702b84f43dc98bbeea32a2261e408533dbf58;hp=96c9e03abd568306c667cffde6f1e64677038fe6;hpb=fdd4409cae442e2ccf092da87f4b7c6e0a6d7382;p=supertux.git diff --git a/src/supertux/menu/joystick_menu.cpp b/src/supertux/menu/joystick_menu.cpp index 96c9e03ab..adde0c5c8 100644 --- a/src/supertux/menu/joystick_menu.cpp +++ b/src/supertux/menu/joystick_menu.cpp @@ -1,6 +1,6 @@ // SuperTux // Copyright (C) 2006 Matthias Braun , -// 2007 Ingo Ruhnke +// 2007,2014 Ingo Ruhnke // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,82 +20,136 @@ #include #include "control/joystick_manager.hpp" +#include "supertux/gameconfig.hpp" #include "util/gettext.hpp" -JoystickMenu::JoystickMenu(InputManager* _controller) : - controller(_controller), - joysticks_available(false) +namespace { + +enum { + MNID_JUMP_WITH_UP = Controller::CONTROLCOUNT, + MNID_SCAN_JOYSTICKS, + MNID_AUTO_JOYSTICK_CFG +}; + +} // namespace + +JoystickMenu::JoystickMenu(InputManager& input_manager) : + m_input_manager(input_manager), + m_joysticks_available(false) { - recreateMenu(); + recreate_menu(); } JoystickMenu::~JoystickMenu() {} void -JoystickMenu::recreateMenu() +JoystickMenu::recreate_menu() { clear(); add_label(_("Setup Joystick")); add_hl(); - if(controller->joystick_manager->joysticks.size() > 0) { - joysticks_available = true; - - add_controlfield(Controller::UP, _("Up")); - add_controlfield(Controller::DOWN, _("Down")); - add_controlfield(Controller::LEFT, _("Left")); - add_controlfield(Controller::RIGHT, _("Right")); - add_controlfield(Controller::JUMP, _("Jump")); - add_controlfield(Controller::ACTION, _("Action")); - add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu")); - add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); - add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); - add_controlfield(Controller::PEEK_UP, _("Peek Up")); - add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); - - add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->joystick_manager->jump_with_up_joy); - } else { - add_inactive(-1, _("No Joysticks found")); - joysticks_available = false; + + add_toggle(MNID_AUTO_JOYSTICK_CFG, _("Manual Configuration"), + !m_input_manager.use_game_controller()) + ->set_help(_("Use manual configuration instead of SDL2's automatic GameController support")); + + if (m_input_manager.use_game_controller()) + { + m_joysticks_available = false; + } + else + { + if (m_input_manager.joystick_manager->get_num_joysticks() > 0) + { + m_joysticks_available = true; + + add_controlfield(Controller::UP, _("Up")); + add_controlfield(Controller::DOWN, _("Down")); + add_controlfield(Controller::LEFT, _("Left")); + add_controlfield(Controller::RIGHT, _("Right")); + add_controlfield(Controller::JUMP, _("Jump")); + add_controlfield(Controller::ACTION, _("Action")); + add_controlfield(Controller::START, _("Pause/Menu")); + add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); + add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); + add_controlfield(Controller::PEEK_UP, _("Peek Up")); + add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); + if (g_config->developer_mode || g_config->console_enabled) { + add_controlfield(Controller::CONSOLE, _("Console")); + } + if (g_config->developer_mode) { + add_controlfield(Controller::CHEAT_MENU, _("Cheat Menu")); + } + add_toggle(MNID_JUMP_WITH_UP, _("Jump with Up"), g_config->joystick_config.jump_with_up_joy); + } + else + { + m_joysticks_available = false; + + add_inactive(-1, _("No Joysticks found")); + add_entry(MNID_SCAN_JOYSTICKS, _("Scan for Joysticks")); + } } add_hl(); add_back(_("Back")); - update(); + refresh(); } std::string JoystickMenu::get_button_name(int button) { if(button < 0) + { return _("None"); - - std::ostringstream name; - name << "Button " << button; - return name.str(); + } + else + { + std::ostringstream name; + name << "Button " << button; + return name.str(); + } } void JoystickMenu::menu_action(MenuItem* item) { - if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) { + if (0 <= item->id && item->id < Controller::CONTROLCOUNT) + { item->change_input(_("Press Button")); - controller->joystick_manager->wait_for_joystick = item->id; - } else if (item->id == Controller::CONTROLCOUNT) { - controller->joystick_manager->jump_with_up_joy = item->toggled; + m_input_manager.joystick_manager->bind_next_event_to(static_cast(item->id)); + } + else if (item->id == MNID_JUMP_WITH_UP) + { + g_config->joystick_config.jump_with_up_joy = item->toggled; + } + else if (item->id == MNID_AUTO_JOYSTICK_CFG) + { + m_input_manager.use_game_controller(!item->toggled); + m_input_manager.reset(); + recreate_menu(); + } + else if(item->id == MNID_SCAN_JOYSTICKS) + { + m_input_manager.reset(); + recreate_menu(); } } void -JoystickMenu::update_menu_item(Controller::Control id) +JoystickMenu::refresh_menu_item(Controller::Control id) { - int button = controller->joystick_manager->reversemap_joybutton(id); - int axis = controller->joystick_manager->reversemap_joyaxis(id); - int hat_dir = controller->joystick_manager->reversemap_joyhat(id); + int button = g_config->joystick_config.reversemap_joybutton(id); + int axis = g_config->joystick_config.reversemap_joyaxis(id); + int hat_dir = g_config->joystick_config.reversemap_joyhat(id); - if (button != -1) { - get_item_by_id((int)id).change_input(get_button_name(button)); - } else if (axis != 0) { + if (button != -1) + { + get_item_by_id(static_cast(id)).change_input(get_button_name(button)); + } + else if (axis != 0) + { std::ostringstream name; name << "Axis "; @@ -109,15 +163,17 @@ JoystickMenu::update_menu_item(Controller::Control id) name << "X"; else if (abs(axis) == 2) name << "Y"; - else if (abs(axis) == 2) - name << "X2"; else if (abs(axis) == 3) + name << "X2"; + else if (abs(axis) == 4) name << "Y2"; else name << abs(axis); - get_item_by_id((int)id).change_input(name.str()); - } else if (hat_dir != -1) { + get_item_by_id(static_cast(id)).change_input(name.str()); + } + else if (hat_dir != -1) + { std::string name; switch (hat_dir) @@ -143,42 +199,38 @@ JoystickMenu::update_menu_item(Controller::Control id) break; } - get_item_by_id((int)id).change_input(name); - } else { - get_item_by_id((int)id).change_input("None"); + get_item_by_id(static_cast(id)).change_input(name); + } + else + { + get_item_by_id(static_cast(id)).change_input("None"); } } void -JoystickMenu::update() +JoystickMenu::refresh() { - log_info << controller->joystick_manager->joysticks.size() << std::endl; - - if(true) //controller->joysticks.size() == 0) - { - // do nothing - } - else + if (m_joysticks_available) { - if (!joysticks_available) - { - recreateMenu(); + refresh_menu_item(Controller::UP); + refresh_menu_item(Controller::DOWN); + refresh_menu_item(Controller::LEFT); + refresh_menu_item(Controller::RIGHT); + + refresh_menu_item(Controller::JUMP); + refresh_menu_item(Controller::ACTION); + refresh_menu_item(Controller::START); + refresh_menu_item(Controller::PEEK_LEFT); + refresh_menu_item(Controller::PEEK_RIGHT); + refresh_menu_item(Controller::PEEK_UP); + refresh_menu_item(Controller::PEEK_DOWN); + + if (g_config->developer_mode || g_config->console_enabled) { + refresh_menu_item(Controller::CONSOLE); + } + if (g_config->developer_mode) { + refresh_menu_item(Controller::CHEAT_MENU); } - - update_menu_item(Controller::UP); - update_menu_item(Controller::DOWN); - update_menu_item(Controller::LEFT); - update_menu_item(Controller::RIGHT); - - update_menu_item(Controller::JUMP); - update_menu_item(Controller::ACTION); - update_menu_item(Controller::PAUSE_MENU); - update_menu_item(Controller::PEEK_LEFT); - update_menu_item(Controller::PEEK_RIGHT); - update_menu_item(Controller::PEEK_UP); - update_menu_item(Controller::PEEK_DOWN); - - //get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy; } }