From: Ingo Ruhnke Date: Wed, 22 Aug 2007 04:33:47 +0000 (+0000) Subject: - implemented option to switch between up-as-jump and up-as-up (needed to keep worldm... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0c391f6ce54c4cf00bbc750021c45d7bc7abfef8;p=supertux.git - implemented option to switch between up-as-jump and up-as-up (needed to keep worldmap usable) SVN-Revision: 5153 --- diff --git a/src/control/controller.hpp b/src/control/controller.hpp index 9f3a07fdc..c8b45e82f 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -30,11 +30,15 @@ public: RIGHT, UP, DOWN, + JUMP, ACTION, + PAUSE_MENU, MENU_SELECT, + CONSOLE, + PEEK_LEFT, PEEK_RIGHT, diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 252a93548..2bc549d6f 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -78,6 +78,8 @@ JoystickKeyboardController::JoystickKeyboardController() keymap[SDLK_DELETE] = PEEK_LEFT; keymap[SDLK_END] = PEEK_RIGHT; + jump_with_up = false; + int joystick_count = SDL_NumJoysticks(); min_joybuttons = -1; max_joybuttons = -1; @@ -202,7 +204,8 @@ JoystickKeyboardController::read(const lisp::Lisp& lisp) const lisp::Lisp* joystick_lisp = lisp.get_lisp("joystick"); if(joystick_lisp) { - joystick_lisp->get("dead_zone", dead_zone); + joystick_lisp->get("dead-zone", dead_zone); + joystick_lisp->get("jump-with-up", jump_with_up); lisp::ListIterator iter(joystick_lisp); while(iter.next()) { if(iter.item() == "map") { @@ -268,7 +271,8 @@ JoystickKeyboardController::write(lisp::Writer& writer) writer.end_list("keymap"); writer.start_list("joystick"); - writer.write_int("dead_zone", dead_zone); + writer.write_int("dead-zone", dead_zone); + writer.write_bool("jump-with-up", jump_with_up); for(ButtonMap::iterator i = joy_button_map.begin(); i != joy_button_map.end(); ++i) { @@ -302,6 +306,15 @@ JoystickKeyboardController::reset() } void +JoystickKeyboardController::set_joy_controls(Control id, bool value) +{ + if (jump_with_up && id == Controller::UP) + controls[Controller::JUMP] = value; + + controls[(Control)id] = value; +} + +void JoystickKeyboardController::process_event(const SDL_Event& event) { switch(event.type) { @@ -347,7 +360,7 @@ JoystickKeyboardController::process_button_event(const SDL_JoyButtonEvent& jbutt if(i == joy_button_map.end()) { log_debug << "Unmapped joybutton " << (int)jbutton.button << " pressed" << std::endl; } else { - controls[i->second] = (jbutton.state == SDL_PRESSED); + set_joy_controls(i->second, (jbutton.state == SDL_PRESSED)); } } } @@ -380,22 +393,22 @@ JoystickKeyboardController::process_axis_event(const SDL_JoyAxisEvent& jaxis) std::cout << "Unmapped joyaxis " << (int)jaxis.axis << " moved" << std::endl; } else { if (jaxis.value < -dead_zone) - controls[left->second] = true; + set_joy_controls(left->second, true); else if (jaxis.value > dead_zone) - controls[left->second] = false; + set_joy_controls(left->second, false); else - controls[left->second] = false; + set_joy_controls(left->second, false); } if(right == joy_axis_map.end()) { std::cout << "Unmapped joyaxis " << (int)jaxis.axis << " moved" << std::endl; } else { if (jaxis.value < -dead_zone) - controls[right->second] = false; + set_joy_controls(right->second, false); else if (jaxis.value > dead_zone) - controls[right->second] = true; + set_joy_controls(right->second, true); else - controls[right->second] = false; + set_joy_controls(right->second, false); } } } @@ -428,28 +441,28 @@ JoystickKeyboardController::process_hat_event(const SDL_JoyHatEvent& jhat) { HatMap::iterator it = joy_hat_map.find(SDL_HAT_UP); if (it != joy_hat_map.end()) - controls[it->second] = jhat.value & SDL_HAT_UP; + set_joy_controls(it->second, jhat.value & SDL_HAT_UP); } if (changed & SDL_HAT_DOWN) { HatMap::iterator it = joy_hat_map.find(SDL_HAT_DOWN); if (it != joy_hat_map.end()) - controls[it->second] = jhat.value & SDL_HAT_DOWN; + set_joy_controls(it->second, jhat.value & SDL_HAT_DOWN); } if (changed & SDL_HAT_LEFT) { HatMap::iterator it = joy_hat_map.find(SDL_HAT_LEFT); if (it != joy_hat_map.end()) - controls[it->second] = jhat.value & SDL_HAT_LEFT; + set_joy_controls(it->second, jhat.value & SDL_HAT_LEFT); } if (changed & SDL_HAT_RIGHT) { HatMap::iterator it = joy_hat_map.find(SDL_HAT_RIGHT); if (it != joy_hat_map.end()) - controls[it->second] = jhat.value & SDL_HAT_RIGHT; + set_joy_controls(it->second, jhat.value & SDL_HAT_RIGHT); } } @@ -868,6 +881,8 @@ JoystickKeyboardController::JoystickMenu::JoystickMenu( add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu")); add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); + + add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up); } else { add_deactive(-1, _("No Joysticks found")); } @@ -893,9 +908,12 @@ JoystickKeyboardController::JoystickMenu::get_button_name(int button) void JoystickKeyboardController::JoystickMenu::menu_action(MenuItem* item) { - assert(item->id >= 0 && item->id < Controller::CONTROLCOUNT); - item->change_input(_("Press Button")); - controller->wait_for_joystick = item->id; + 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 = item->toggled; + } } void @@ -977,4 +995,6 @@ JoystickKeyboardController::JoystickMenu::update() update_menu_item(Controller::PAUSE_MENU); update_menu_item(Controller::PEEK_LEFT); update_menu_item(Controller::PEEK_RIGHT); + + get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up; } diff --git a/src/control/joystickkeyboardcontroller.hpp b/src/control/joystickkeyboardcontroller.hpp index 7df1865f9..50225dc2d 100644 --- a/src/control/joystickkeyboardcontroller.hpp +++ b/src/control/joystickkeyboardcontroller.hpp @@ -81,9 +81,11 @@ private: int max_joyaxis; int max_joyhats; - + Uint8 hat_state; + bool jump_with_up; + SDLKey reversemap_key(Control c); int reversemap_joybutton(Control c); int reversemap_joyaxis(Control c); @@ -96,6 +98,8 @@ private: void bind_joyhat(int dir, Control c); void bind_key(SDLKey key, Control c); + void set_joy_controls(Control id, bool value); + int wait_for_key; int wait_for_joystick; diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 613c8faea..89835157e 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -341,8 +341,7 @@ Menu::update() menuaction = MENU_ACTION_DOWN; menu_repeat_time = real_time + MENU_REPEAT_RATE; } - if(main_controller->pressed(Controller::JUMP) - || main_controller->pressed(Controller::ACTION) + if(main_controller->pressed(Controller::ACTION) || main_controller->pressed(Controller::MENU_SELECT)) { menuaction = MENU_ACTION_HIT; }