// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#include <config.h>
#include <sstream>
-#include "joystickkeyboardcontroller.h"
-#include "gui/menu.h"
-#include "app/gettext.h"
-#include "lisp/lisp.h"
-#include "lisp/list_iterator.h"
-#include "game_session.h"
+#include "joystickkeyboardcontroller.hpp"
+#include "gui/menu.hpp"
+#include "gettext.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/list_iterator.hpp"
+#include "game_session.hpp"
class JoystickKeyboardController::JoystickMenu : public Menu
{
};
JoystickKeyboardController::JoystickKeyboardController()
- : wait_for_key(-1), wait_for_joybutton(-1)
+ : wait_for_key(-1), wait_for_joybutton(-1), key_options_menu(0),
+ joystick_options_menu(0)
{
- memset(last_keys, 0, sizeof(last_keys));
+ memset(last_keys, 0, sizeof(last_keys));
// initialize default keyboard map
keymap.insert(std::make_pair(SDLK_LEFT, LEFT));
keymap.insert(std::make_pair(SDLK_RETURN, MENU_SELECT));
keymap.insert(std::make_pair(SDLK_KP_ENTER, MENU_SELECT));
- joystick_count = SDL_NumJoysticks();
+ int joystick_count = SDL_NumJoysticks();
min_joybuttons = -1;
max_joybuttons = -1;
-#ifdef DEBUG
- std::cout << "Found " << joystick_count << " joysticks.\n";
-#endif
for(int i = 0; i < joystick_count; ++i) {
SDL_Joystick* joystick = SDL_JoystickOpen(i);
bool good = true;
}
if(!good) {
SDL_JoystickClose(joystick);
- joysticks.push_back(0);
- joystick_names.push_back("");
continue;
}
max_joybuttons = SDL_JoystickNumButtons(joystick);
}
- joystick_names.push_back(SDL_JoystickName(i));
joysticks.push_back(joystick);
}
if(i != min_joybuttons-1)
joy_button_map.insert(std::make_pair(i, MENU_SELECT));
}
+
+ // some joysticks or SDL seem to produce some bogus events after being opened
+ Uint32 ticks = SDL_GetTicks();
+ while(SDL_GetTicks() - ticks < 200) {
+ SDL_Event event;
+ SDL_PollEvent(&event);
+ }
}
JoystickKeyboardController::~JoystickKeyboardController()
}
void
+JoystickKeyboardController::reset()
+{
+ Controller::reset();
+ for(size_t i = 0; i < sizeof(last_keys); ++i)
+ last_keys[i] = 0;
+}
+
+void
JoystickKeyboardController::process_event(const SDL_Event& event)
{
switch(event.type) {
{
add_label(_("Joystick Setup"));
add_hl();
- add_controlfield(Controller::JUMP, _("Jump"));
- add_controlfield(Controller::ACTION, _("Shoot/Run"));
- add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu"));
+ if(controller->joysticks.size() > 0) {
+ add_controlfield(Controller::JUMP, _("Jump"));
+ add_controlfield(Controller::ACTION, _("Shoot/Run"));
+ add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu"));
+ } else {
+ add_deactive(-1, _("No Joysticks found"));
+ }
add_hl();
add_back(_("Back"));
update();
void
JoystickKeyboardController::JoystickMenu::update()
{
+ if(controller->joysticks.size() == 0)
+ return;
+
// update menu
get_item_by_id((int) Controller::JUMP).change_input(get_button_name(
controller->reversemap_joybutton(Controller::JUMP)));