From: Ingo Ruhnke Date: Tue, 20 Apr 2004 16:50:18 +0000 (+0000) Subject: - added config options for joystick buttons/axis X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=108afb08c9fe745ffecea7adc1f21529baa5a4ef;p=supertux.git - added config options for joystick buttons/axis SVN-Revision: 594 --- diff --git a/src/configfile.cpp b/src/configfile.cpp index 514c24926..c415d136b 100644 --- a/src/configfile.cpp +++ b/src/configfile.cpp @@ -90,6 +90,13 @@ void loadconfig(void) use_joystick = false; else use_joystick = true; + + reader.read_int ("joystick-x", &joystick_keymap.x_axis); + reader.read_int ("joystick-y", &joystick_keymap.y_axis); + reader.read_int ("joystick-a", &joystick_keymap.a_button); + reader.read_int ("joystick-b", &joystick_keymap.b_button); + reader.read_int ("joystick-start", &joystick_keymap.start_button); + reader.read_int ("joystick-deadzone", &joystick_keymap.dead_zone); } void saveconfig (void) @@ -112,6 +119,14 @@ void saveconfig (void) fprintf(config, "\n\t;; joystick number (-1 means no joystick):\n"); fprintf(config, "\t(joystick %d)\n", use_joystick ? joystick_num : -1); + + fprintf(config, "\t(joystick-x %d)\n", joystick_keymap.x_axis); + fprintf(config, "\t(joystick-y %d)\n", joystick_keymap.y_axis); + fprintf(config, "\t(joystick-a %d)\n", joystick_keymap.a_button); + fprintf(config, "\t(joystick-b %d)\n", joystick_keymap.b_button); + fprintf(config, "\t(joystick-start %d)\n", joystick_keymap.start_button); + fprintf(config, "\t(joystick-deadzone %d)\n", joystick_keymap.dead_zone); + fprintf(config, ")\n"); } } diff --git a/src/globals.cpp b/src/globals.cpp index 5809b4b35..50cab212f 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -27,7 +27,7 @@ JoystickKeymap::JoystickKeymap() { a_button = 0; b_button = 1; - start_button = 9; + start_button = 2; x_axis = 0; y_axis = 1; diff --git a/src/setup.cpp b/src/setup.cpp index 26fdba326..ab73581ab 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -762,8 +762,6 @@ void st_joystick_setup(void) } else { - /* Check for proper joystick configuration: */ - if (SDL_JoystickNumAxes(js) < 2) { fprintf(stderr, @@ -927,6 +925,29 @@ void parseargs(int argc, char * argv[]) assert(i+1 < argc); joystick_num = atoi(argv[++i]); } + else if (strcmp(argv[i], "--joymap") == 0) + { + assert(i+1 < argc); + if (sscanf(argv[++i], + "%d:%d:%d:%d:%d", + &joystick_keymap.x_axis, + &joystick_keymap.y_axis, + &joystick_keymap.a_button, + &joystick_keymap.b_button, + &joystick_keymap.start_button) != 5) + { + puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'"); + } + else + { + std::cout << "Using new joymap:\n" + << " X-Axis: " << joystick_keymap.x_axis << "\n" + << " Y-Axis: " << joystick_keymap.y_axis << "\n" + << " A-Button: " << joystick_keymap.a_button << "\n" + << " B-Button: " << joystick_keymap.b_button << "\n" + << " Start-Button: " << joystick_keymap.start_button << std::endl; + } + } else if (strcmp(argv[i], "--worldmap") == 0) { launch_worldmap_mode = true; @@ -1004,6 +1025,8 @@ void parseargs(int argc, char * argv[]) "\n" "Misc Options:\n" " -j, --joystick NUM Use joystick NUM (default: 0)\n" + " --joymap XAXIS:YAXIS:A:B:START\n" + " Define how joystick buttons and axis should be mapped\n" " --worldmap Start in worldmap-mode (EXPERIMENTAL)\n" " -d, --datadir DIR Load Game data from DIR (default: automatic)\n" " --debug-mode Enables the debug-mode, which is useful for developers.\n"