-//----------------------------------------------------------------------------
-
-JoystickKeyboardController::KeyboardMenu::KeyboardMenu(
- JoystickKeyboardController* _controller)
- : controller(_controller)
-{
- add_label(_("Setup Keyboard"));
- add_hl();
- 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::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->console_enabled) {
- add_controlfield(Controller::CONSOLE, _("Console"));
- }
- add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_kbd);
- add_hl();
- add_back(_("Back"));
- update();
-}
-
-JoystickKeyboardController::KeyboardMenu::~KeyboardMenu()
-{}
-
-std::string
-JoystickKeyboardController::KeyboardMenu::get_key_name(SDLKey key)
-{
- switch(key) {
- case SDLK_UNKNOWN:
- return _("None");
- case SDLK_UP:
- return _("Up cursor");
- case SDLK_DOWN:
- return _("Down cursor");
- case SDLK_LEFT:
- return _("Left cursor");
- case SDLK_RIGHT:
- return _("Right cursor");
- case SDLK_RETURN:
- return _("Return");
- case SDLK_SPACE:
- return _("Space");
- case SDLK_RSHIFT:
- return _("Right Shift");
- case SDLK_LSHIFT:
- return _("Left Shift");
- case SDLK_RCTRL:
- return _("Right Control");
- case SDLK_LCTRL:
- return _("Left Control");
- case SDLK_RALT:
- return _("Right Alt");
- case SDLK_LALT:
- return _("Left Alt");
- default:
- return SDL_GetKeyName((SDLKey) key);
- }
-}
-
-void
-JoystickKeyboardController::KeyboardMenu::menu_action(MenuItem* item)
-{
- if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){
- item->change_input(_("Press Key"));
- controller->wait_for_key = item->id;
- } else if( item->id == Controller::CONTROLCOUNT) {
- controller->jump_with_up_kbd = item->toggled;
- }
-}
-
-void
-JoystickKeyboardController::KeyboardMenu::update()
-{
- // update menu
- get_item_by_id((int) Controller::UP).change_input(get_key_name(
- controller->reversemap_key(Controller::UP)));
- get_item_by_id((int) Controller::DOWN).change_input(get_key_name(
- controller->reversemap_key(Controller::DOWN)));
- get_item_by_id((int) Controller::LEFT).change_input(get_key_name(
- controller->reversemap_key(Controller::LEFT)));
- get_item_by_id((int) Controller::RIGHT).change_input(get_key_name(
- controller->reversemap_key(Controller::RIGHT)));
- get_item_by_id((int) Controller::JUMP).change_input(get_key_name(
- controller->reversemap_key(Controller::JUMP)));
- get_item_by_id((int) Controller::ACTION).change_input(get_key_name(
- controller->reversemap_key(Controller::ACTION)));
- get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name(
- controller->reversemap_key(Controller::PEEK_LEFT)));
- get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name(
- controller->reversemap_key(Controller::PEEK_RIGHT)));
- get_item_by_id((int) Controller::PEEK_UP).change_input(get_key_name(
- controller->reversemap_key(Controller::PEEK_UP)));
- get_item_by_id((int) Controller::PEEK_DOWN).change_input(get_key_name(
- controller->reversemap_key(Controller::PEEK_DOWN)));
- if (g_config->console_enabled) {
- get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name(
- controller->reversemap_key(Controller::CONSOLE)));
- }
- get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_kbd;
-}
-
-//---------------------------------------------------------------------------
-
-JoystickKeyboardController::JoystickMenu::JoystickMenu(
- JoystickKeyboardController* _controller)
- : controller(_controller)
-{
- recreateMenu();
-}
-
-JoystickKeyboardController::JoystickMenu::~JoystickMenu()
-{}
-
-void
-JoystickKeyboardController::JoystickMenu::recreateMenu()
-{
- clear();
- add_label(_("Setup Joystick"));
- add_hl();
- if(controller->joysticks.size() > 0) {
- 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->jump_with_up_joy);
- } else {
- add_inactive(-1, _("No Joysticks found"));
- }
- add_inactive(-1,"");
- add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
-
- //Show Joysticks currently activated:
- for(std::vector<SDL_Joystick*>::iterator i = controller->joysticks.begin();
- i != controller->joysticks.end(); ++i) {
- if(*i != 0)
- add_inactive(-1, SDL_JoystickName(SDL_JoystickIndex(*i)) );
- }
-
- add_hl();
- add_back(_("Back"));
- update();
-}
-
-std::string
-JoystickKeyboardController::JoystickMenu::get_button_name(int button)
-{
- if(button < 0)
- return _("None");
-
- std::ostringstream name;
- name << "Button " << button;
- return name.str();
-}
-
-void
-JoystickKeyboardController::JoystickMenu::menu_action(MenuItem* item)
-{
- if (item->id >= 0 && item->id < Controller::CONTROLCOUNT) {
- item->change_input(_("Press Button"));
- controller->wait_for_joystick = item->id;
- } else if (item->id == Controller::CONTROLCOUNT) {
- controller->jump_with_up_joy = item->toggled;
- } else if( item->id == SCAN_JOYSTICKS) {
- controller->updateAvailableJoysticks();
- recreateMenu();
- }
-}
-
-void
-JoystickKeyboardController::JoystickMenu::update_menu_item(Control id)
-{
- int button = controller->reversemap_joybutton(id);
- int axis = controller->reversemap_joyaxis(id);
- int hat_dir = controller->reversemap_joyhat(id);
-
- if (button != -1) {
- get_item_by_id((int)id).change_input(get_button_name(button));
- } else if (axis != 0) {
- std::ostringstream name;
-
- name << "Axis ";
-
- if (axis < 0)
- name << "-";
- else
- name << "+";
-
- if (abs(axis) == 1)
- name << "X";
- else if (abs(axis) == 2)
- name << "Y";
- else if (abs(axis) == 2)
- name << "X2";
- else if (abs(axis) == 3)
- name << "Y2";
- else
- name << abs(axis);
-
- get_item_by_id((int)id).change_input(name.str());
- } else if (hat_dir != -1) {
- std::string name;
-
- switch (hat_dir)
- {
- case SDL_HAT_UP:
- name = "Hat Up";
- break;
-
- case SDL_HAT_DOWN:
- name = "Hat Down";
- break;
-
- case SDL_HAT_LEFT:
- name = "Hat Left";
- break;
-
- case SDL_HAT_RIGHT:
- name = "Hat Right";
- break;
-
- default:
- name = "Unknown hat_dir";
- break;
- }
-
- get_item_by_id((int)id).change_input(name);
- } else {
- get_item_by_id((int)id).change_input("None");
- }
-}
-
-void
-JoystickKeyboardController::JoystickMenu::update()
-{
- if(controller->joysticks.size() == 0)
- return;
-
- 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;
-}
-