#include <joystick_menu.hpp>
Inherits Menu.
Public Member Functions | |
JoystickMenu (JoystickKeyboardController *controller) | |
virtual | ~JoystickMenu () |
void | update () |
std::string | get_button_name (int button) |
void | update_menu_item (Controller::Control id) |
virtual void | menu_action (MenuItem *item) |
void | check_menu () |
Public Attributes | |
JoystickKeyboardController * | controller |
Private Member Functions | |
void | recreateMenu () |
JoystickMenu (const JoystickMenu &) | |
JoystickMenu & | operator= (const JoystickMenu &) |
Definition at line 24 of file joystick_menu.hpp.
JoystickMenu::JoystickMenu | ( | JoystickKeyboardController * | controller | ) |
Definition at line 28 of file joystick_menu.cpp.
References recreateMenu().
00028 : 00029 controller(_controller) 00030 { 00031 recreateMenu(); 00032 }
JoystickMenu::~JoystickMenu | ( | ) | [virtual] |
JoystickMenu::JoystickMenu | ( | const JoystickMenu & | ) | [private] |
void JoystickMenu::update | ( | ) |
Reimplemented from Menu.
Definition at line 164 of file joystick_menu.cpp.
References Controller::ACTION, Controller::CONTROLCOUNT, controller, Controller::DOWN, Menu::get_item_by_id(), JoystickKeyboardController::joysticks, Controller::JUMP, JoystickKeyboardController::jump_with_up_joy, Controller::LEFT, Controller::PAUSE_MENU, Controller::PEEK_DOWN, Controller::PEEK_LEFT, Controller::PEEK_RIGHT, Controller::PEEK_UP, Controller::RIGHT, MenuItem::toggled, Controller::UP, and update_menu_item().
Referenced by JoystickKeyboardController::process_axis_event(), JoystickKeyboardController::process_button_event(), JoystickKeyboardController::process_hat_event(), JoystickKeyboardController::process_menu_key_event(), and recreateMenu().
00165 { 00166 if(controller->joysticks.size() == 0) 00167 return; 00168 00169 update_menu_item(Controller::UP); 00170 update_menu_item(Controller::DOWN); 00171 update_menu_item(Controller::LEFT); 00172 update_menu_item(Controller::RIGHT); 00173 00174 update_menu_item(Controller::JUMP); 00175 update_menu_item(Controller::ACTION); 00176 update_menu_item(Controller::PAUSE_MENU); 00177 update_menu_item(Controller::PEEK_LEFT); 00178 update_menu_item(Controller::PEEK_RIGHT); 00179 update_menu_item(Controller::PEEK_UP); 00180 update_menu_item(Controller::PEEK_DOWN); 00181 00182 get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_joy; 00183 }
std::string JoystickMenu::get_button_name | ( | int | button | ) |
Definition at line 76 of file joystick_menu.cpp.
References _().
Referenced by update_menu_item().
00077 { 00078 if(button < 0) 00079 return _("None"); 00080 00081 std::ostringstream name; 00082 name << "Button " << button; 00083 return name.str(); 00084 }
void JoystickMenu::update_menu_item | ( | Controller::Control | id | ) |
Definition at line 101 of file joystick_menu.cpp.
References MenuItem::change_input(), controller, get_button_name(), Menu::get_item_by_id(), JoystickKeyboardController::reversemap_joyaxis(), JoystickKeyboardController::reversemap_joybutton(), and JoystickKeyboardController::reversemap_joyhat().
Referenced by update().
00102 { 00103 int button = controller->reversemap_joybutton(id); 00104 int axis = controller->reversemap_joyaxis(id); 00105 int hat_dir = controller->reversemap_joyhat(id); 00106 00107 if (button != -1) { 00108 get_item_by_id((int)id).change_input(get_button_name(button)); 00109 } else if (axis != 0) { 00110 std::ostringstream name; 00111 00112 name << "Axis "; 00113 00114 if (axis < 0) 00115 name << "-"; 00116 else 00117 name << "+"; 00118 00119 if (abs(axis) == 1) 00120 name << "X"; 00121 else if (abs(axis) == 2) 00122 name << "Y"; 00123 else if (abs(axis) == 2) 00124 name << "X2"; 00125 else if (abs(axis) == 3) 00126 name << "Y2"; 00127 else 00128 name << abs(axis); 00129 00130 get_item_by_id((int)id).change_input(name.str()); 00131 } else if (hat_dir != -1) { 00132 std::string name; 00133 00134 switch (hat_dir) 00135 { 00136 case SDL_HAT_UP: 00137 name = "Hat Up"; 00138 break; 00139 00140 case SDL_HAT_DOWN: 00141 name = "Hat Down"; 00142 break; 00143 00144 case SDL_HAT_LEFT: 00145 name = "Hat Left"; 00146 break; 00147 00148 case SDL_HAT_RIGHT: 00149 name = "Hat Right"; 00150 break; 00151 00152 default: 00153 name = "Unknown hat_dir"; 00154 break; 00155 } 00156 00157 get_item_by_id((int)id).change_input(name); 00158 } else { 00159 get_item_by_id((int)id).change_input("None"); 00160 } 00161 }
void JoystickMenu::menu_action | ( | MenuItem * | item | ) | [virtual] |
Reimplemented from Menu.
Definition at line 87 of file joystick_menu.cpp.
References _(), MenuItem::change_input(), Controller::CONTROLCOUNT, controller, MenuItem::id, JoystickKeyboardController::jump_with_up_joy, recreateMenu(), SCAN_JOYSTICKS, MenuItem::toggled, JoystickKeyboardController::updateAvailableJoysticks(), and JoystickKeyboardController::wait_for_joystick.
00088 { 00089 if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) { 00090 item->change_input(_("Press Button")); 00091 controller->wait_for_joystick = item->id; 00092 } else if (item->id == Controller::CONTROLCOUNT) { 00093 controller->jump_with_up_joy = item->toggled; 00094 } else if( item->id == SCAN_JOYSTICKS) { 00095 controller->updateAvailableJoysticks(); 00096 recreateMenu(); 00097 } 00098 }
void JoystickMenu::check_menu | ( | ) | [inline, virtual] |
void JoystickMenu::recreateMenu | ( | ) | [private] |
Definition at line 38 of file joystick_menu.cpp.
References _(), Controller::ACTION, Menu::add_back(), Menu::add_controlfield(), Menu::add_entry(), Menu::add_hl(), Menu::add_inactive(), Menu::add_label(), Menu::add_toggle(), Menu::clear(), Controller::CONTROLCOUNT, controller, Controller::DOWN, JoystickKeyboardController::joysticks, Controller::JUMP, JoystickKeyboardController::jump_with_up_joy, Controller::LEFT, Controller::PAUSE_MENU, Controller::PEEK_DOWN, Controller::PEEK_LEFT, Controller::PEEK_RIGHT, Controller::PEEK_UP, Controller::RIGHT, SCAN_JOYSTICKS, Controller::UP, and update().
Referenced by JoystickMenu(), and menu_action().
00039 { 00040 clear(); 00041 add_label(_("Setup Joystick")); 00042 add_hl(); 00043 if(controller->joysticks.size() > 0) { 00044 add_controlfield(Controller::UP, _("Up")); 00045 add_controlfield(Controller::DOWN, _("Down")); 00046 add_controlfield(Controller::LEFT, _("Left")); 00047 add_controlfield(Controller::RIGHT, _("Right")); 00048 add_controlfield(Controller::JUMP, _("Jump")); 00049 add_controlfield(Controller::ACTION, _("Action")); 00050 add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu")); 00051 add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); 00052 add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); 00053 add_controlfield(Controller::PEEK_UP, _("Peek Up")); 00054 add_controlfield(Controller::PEEK_DOWN, _("Peek Down")); 00055 00056 add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_joy); 00057 } else { 00058 add_inactive(-1, _("No Joysticks found")); 00059 } 00060 add_inactive(-1,""); 00061 add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks")); 00062 00063 //Show Joysticks currently activated: 00064 for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin(); 00065 i != controller->joysticks.end(); ++i) { 00066 if(*i != 0) 00067 add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) ); 00068 } 00069 00070 add_hl(); 00071 add_back(_("Back")); 00072 update(); 00073 }
JoystickMenu& JoystickMenu::operator= | ( | const JoystickMenu & | ) | [private] |
Definition at line 34 of file joystick_menu.hpp.
Referenced by menu_action(), recreateMenu(), update(), and update_menu_item().