#include "console.hpp"
#include "gameconfig.hpp"
+namespace{
+ const int SCAN_JOYSTICKS = Controller::CONTROLCOUNT + 1;
+}
+
class JoystickKeyboardController::JoystickMenu : public Menu
{
public:
jump_with_up_joy = false;
jump_with_up_kbd = false;
+ updateAvailableJoysticks();
+
+ dead_zone = 1000;
+
+ // Default joystick button configuration
+ joy_button_map[0] = JUMP;
+ joy_button_map[1] = ACTION;
+ // 6 or more Buttons
+ if( min_joybuttons > 5 ){
+ joy_button_map[4] = PEEK_LEFT;
+ joy_button_map[5] = PEEK_RIGHT;
+ // 8 or more
+ if(min_joybuttons > 7)
+ joy_button_map[min_joybuttons-1] = PAUSE_MENU;
+ } else {
+ // map the last 2 buttons to menu and pause
+ if(min_joybuttons > 2)
+ joy_button_map[min_joybuttons-1] = PAUSE_MENU;
+ // map all remaining joystick buttons to MENU_SELECT
+ for(int i = 2; i < max_joybuttons; ++i) {
+ if(i != min_joybuttons-1)
+ joy_button_map[i] = MENU_SELECT;
+ }
+ }
+
+ // Default joystick axis configuration
+ joy_axis_map[-1] = LEFT;
+ joy_axis_map[ 1] = RIGHT;
+ joy_axis_map[-2] = UP;
+ joy_axis_map[ 2] = DOWN;
+}
+
+JoystickKeyboardController::~JoystickKeyboardController()
+{
+ for(std::vector<SDL_Joystick*>::iterator i = joysticks.begin();
+ i != joysticks.end(); ++i) {
+ if(*i != 0)
+ SDL_JoystickClose(*i);
+ }
+
+ delete key_options_menu;
+ delete joystick_options_menu;
+}
+
+void
+JoystickKeyboardController::updateAvailableJoysticks()
+{
+ for(std::vector<SDL_Joystick*>::iterator i = joysticks.begin();
+ i != joysticks.end(); ++i) {
+ if(*i != 0)
+ SDL_JoystickClose(*i);
+ }
+ joysticks.clear();
+
int joystick_count = SDL_NumJoysticks();
min_joybuttons = -1;
max_joybuttons = -1;
SDL_Joystick* joystick = SDL_JoystickOpen(i);
bool good = true;
if(SDL_JoystickNumButtons(joystick) < 2) {
- log_info << "Joystick " << i << " has less than 2 buttons" << std::endl;
+ log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 buttons" << std::endl;
good = false;
}
if(SDL_JoystickNumAxes(joystick) < 2
&& SDL_JoystickNumHats(joystick) == 0) {
- log_info << "Joystick " << i << " has less than 2 axes and no hat" << std::endl;
+ log_info << "Joystick " << i << ": " << SDL_JoystickName(i) << " has less than 2 axes and no hat" << std::endl;
good = false;
}
if(!good) {
joysticks.push_back(joystick);
}
- dead_zone = 1000;
-
- // Default joystick button configuration
- joy_button_map[0] = JUMP;
- joy_button_map[1] = ACTION;
- // 6 or more Buttons
- if( min_joybuttons > 5 ){
- joy_button_map[4] = PEEK_LEFT;
- joy_button_map[5] = PEEK_RIGHT;
- // 8 or more
- if(min_joybuttons > 7)
- joy_button_map[min_joybuttons-1] = PAUSE_MENU;
- } else {
- // map the last 2 buttons to menu and pause
- if(min_joybuttons > 2)
- joy_button_map[min_joybuttons-1] = PAUSE_MENU;
- // map all remaining joystick buttons to MENU_SELECT
- for(int i = 2; i < max_joybuttons; ++i) {
- if(i != min_joybuttons-1)
- joy_button_map[i] = MENU_SELECT;
- }
- }
-
- // Default joystick axis configuration
- joy_axis_map[-1] = LEFT;
- joy_axis_map[ 1] = RIGHT;
- joy_axis_map[-2] = UP;
- joy_axis_map[ 2] = DOWN;
-
// some joysticks or SDL seem to produce some bogus events after being opened
Uint32 ticks = SDL_GetTicks();
while(SDL_GetTicks() - ticks < 200) {
}
}
-JoystickKeyboardController::~JoystickKeyboardController()
-{
- for(std::vector<SDL_Joystick*>::iterator i = joysticks.begin();
- i != joysticks.end(); ++i) {
- if(*i != 0)
- SDL_JoystickClose(*i);
- }
-
- delete key_options_menu;
- delete joystick_options_menu;
-}
-
void
JoystickKeyboardController::read(const lisp::Lisp& lisp)
{
controller->wait_for_key = item->id;
} else if( item->id == Controller::CONTROLCOUNT) {
controller->jump_with_up_kbd = item->toggled;
- }
+ }
}
void
} else {
add_deactive(-1, _("No Joysticks found"));
}
+ add_deactive(-1,"");
+ add_entry(SCAN_JOYSTICKS, _("Scan for Joysticks"));
add_hl();
add_back(_("Back"));
update();
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();
}
}