diff --git a/src/main.cpp b/src/main.cpp index f396376..6e8b846 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1127,6 +1127,22 @@ string get_current_mapping() { } +string get_current_mapping_explicit(bool type, unsigned int index) { + // similar to the above but you can manually specify which index and type to get + // used only for options.cpp right now, and probably not necessary with a refactor, but this is the easiest way to implement it + + if (type == true) { + return SDL_GetKeyName(keymap[index]); + } + + if (type == false) { + return SDL_GameControllerGetStringForButton(buttonmap[index]); + } + + return "?"; + +} + string get_input_name() { // used in the options menu when rebinding // returns a string of the abstract controller that everything is mapped onto; named after the PS1 pad diff --git a/src/main.h b/src/main.h index f3a238c..b0dd8bd 100644 --- a/src/main.h +++ b/src/main.h @@ -13,6 +13,7 @@ std::string get_cpu_sequence(); std::string get_player_sequence(); std::string get_version_string(); std::string get_current_mapping(); +std::string get_current_mapping_explicit(bool, unsigned int); std::string get_input_name(); void save_settings(); diff --git a/src/options.cpp b/src/options.cpp index 16f45c0..5845820 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -51,11 +51,14 @@ int controller_index = 0; unsigned int current_rebind_index = 0; bool rebinding_keys = false; bool rebinding_controller = false; +bool rebinding_single = false; enum option_id { OPT_SUB_VIDEO, OPT_SUB_AUDIO, OPT_SUB_CONTROLS, + OPT_SUB_KEYBOARD, + OPT_SUB_CONTROLLER, OPT_SUB_GAMEPLAY, OPT_SUB_MISC, OPT_MUSIC, @@ -74,9 +77,34 @@ enum option_id { OPT_REBIND_CONTROLLER, OPT_RESET_KEYBOARD, OPT_RESET_CONTROLLER, + OPT_REBIND_KB_UP, + OPT_REBIND_KB_DOWN, + OPT_REBIND_KB_LEFT, + OPT_REBIND_KB_RIGHT, + OPT_REBIND_KB_CROSS, + OPT_REBIND_KB_CIRCLE, + OPT_REBIND_KB_SQUARE, + OPT_REBIND_KB_TRIANGLE, + OPT_REBIND_KB_LB, + OPT_REBIND_KB_RB, + OPT_REBIND_KB_START, + OPT_REBIND_KB_BACK, + OPT_REBIND_CTRL_UP, + OPT_REBIND_CTRL_DOWN, + OPT_REBIND_CTRL_LEFT, + OPT_REBIND_CTRL_RIGHT, + OPT_REBIND_CTRL_CROSS, + OPT_REBIND_CTRL_CIRCLE, + OPT_REBIND_CTRL_SQUARE, + OPT_REBIND_CTRL_TRIANGLE, + OPT_REBIND_CTRL_LB, + OPT_REBIND_CTRL_RB, + OPT_REBIND_CTRL_START, + OPT_REBIND_CTRL_BACK, OPT_SAVE, OPT_EXIT, OPT_BACK, + OPT_CONTROLS_BACK, OPT_NONE, }; @@ -89,7 +117,7 @@ struct option_item { option_item option_back = { OPT_BACK, "Back", - "Return to the main options menu" + "Return to the main options menu." }; vector options_main = { @@ -99,7 +127,7 @@ vector options_main = { {OPT_SUB_GAMEPLAY, "Gameplay Settings", "Change gameplay settings here."}, // {OPT_SUB_MISC, "Other Settings", "Change other settings here."}, {OPT_NONE}, - {OPT_SAVE, "Save Settings", "Saves your settings and returns to the main menu."}, + {OPT_SAVE, "Save & Exit", "Saves your settings and returns to the main menu."}, {OPT_EXIT, "Exit", "Returns to the main menu. No changes will be saved."} }; @@ -121,8 +149,8 @@ vector options_audio = { }; vector options_controls = { - {OPT_REBIND_KEYBOARD, "Rebind Keyboard", "Sets all bindings for the keyboard."}, - {OPT_REBIND_CONTROLLER, "Rebind Controller", "Sets all bindings for the controller."}, + {OPT_SUB_KEYBOARD, "Rebind Keyboard", "Set bindings for the keyboard."}, + {OPT_SUB_CONTROLLER, "Rebind Controller", "Set bindings for the controller."}, {OPT_TOGGLE_RUMBLE, "Controller Rumble", "Rumbles the controller on every other beat."}, {OPT_CONTROLLER_ID, "Controller Index", "Sets which game controller to use."}, {OPT_NONE}, @@ -132,6 +160,42 @@ vector options_controls = { option_back }; +vector options_controls_kb = { + {OPT_REBIND_KB_UP, "Up", "Rebind this keyboard button."}, + {OPT_REBIND_KB_DOWN, "Down", "Rebind this keyboard button."}, + {OPT_REBIND_KB_LEFT, "Left", "Rebind this keyboard button."}, + {OPT_REBIND_KB_RIGHT, "Right", "Rebind this keyboard button."}, + {OPT_REBIND_KB_CROSS, "Cross", "Rebind this keyboard button."}, + {OPT_REBIND_KB_CIRCLE, "Circle", "Rebind this keyboard button."}, + {OPT_REBIND_KB_SQUARE, "Square", "Rebind this keyboard button."}, + {OPT_REBIND_KB_TRIANGLE, "Triangle", "Rebind this keyboard button."}, + {OPT_REBIND_KB_LB, "L1", "Rebind this keyboard button."}, + {OPT_REBIND_KB_RB, "R1", "Rebind this keyboard button."}, + {OPT_REBIND_KB_START, "Start", "Rebind this keyboard button."}, + {OPT_REBIND_KB_BACK, "Back", "Rebind this keyboard button."}, + {OPT_NONE}, + {OPT_REBIND_KEYBOARD, "Rebind All", "Set all bindings for the keyboard."}, + {OPT_CONTROLS_BACK, "Back", "Return to the controls menu."} +}; + +vector options_controls_ctrl = { + {OPT_REBIND_CTRL_UP, "Up", "Rebind this controller button."}, + {OPT_REBIND_CTRL_DOWN, "Down", "Rebind this controller button."}, + {OPT_REBIND_CTRL_LEFT, "Left", "Rebind this controller button."}, + {OPT_REBIND_CTRL_RIGHT, "Right", "Rebind this controller button."}, + {OPT_REBIND_CTRL_CROSS, "Cross", "Rebind this controller button."}, + {OPT_REBIND_CTRL_CIRCLE, "Circle", "Rebind this controller button."}, + {OPT_REBIND_CTRL_SQUARE, "Square", "Rebind this controller button."}, + {OPT_REBIND_CTRL_TRIANGLE, "Triangle", "Rebind this controller button."}, + {OPT_REBIND_CTRL_LB, "L1", "Rebind this controller button."}, + {OPT_REBIND_CTRL_RB, "R1", "Rebind this controller button."}, + {OPT_REBIND_CTRL_START, "Start", "Rebind this controller button."}, + {OPT_REBIND_CTRL_BACK, "Back", "Rebind this controller button."}, + {OPT_NONE}, + {OPT_REBIND_CONTROLLER, "Rebind All", "Set all bindings for the controller."}, + {OPT_CONTROLS_BACK, "Back", "Return to the controls menu."} +}; + vector options_gameplay = { {OPT_TOGGLE_GRID, "Display Grid", "Displays the shape grid overlay."}, {OPT_TOGGLE_HUD, "Display HUD", "Displays the heads-up display."}, @@ -183,6 +247,14 @@ void set_option_menu(option_id id) { options = options_controls; break; + case OPT_SUB_KEYBOARD: + options = options_controls_kb; + break; + + case OPT_SUB_CONTROLLER: + options = options_controls_ctrl; + break; + case OPT_SUB_GAMEPLAY: options = options_gameplay; break; @@ -199,17 +271,17 @@ void set_option_menu(option_id id) { options = options_main; break; + case OPT_CONTROLS_BACK: + option_submenu_id = OPT_SUB_CONTROLS; + options = options_controls; + break; + default: break; } return; } -void increment_rebind_index() { - current_rebind_index++; - return; -} - void reset_options_menu() { option_selected = 0; set_option_menu(OPT_NONE); @@ -220,6 +292,13 @@ void reset_rebind_flags() { current_rebind_index = 0; rebinding_keys = false; rebinding_controller = false; + rebinding_single = false; + return; +} + +void increment_rebind_index() { + current_rebind_index++; + if (rebinding_single) {reset_rebind_flags();} return; } @@ -251,6 +330,30 @@ string get_option_value(int index) { case OPT_TOGGLE_BLINDFOLD: return blindfold_toggle ? "Enabled" : "Disabled"; case OPT_TOGGLE_RUMBLE: return rumble_toggle ? "Enabled" : "Disabled"; case OPT_CONTROLLER_ID: return to_string(controller_index); + case OPT_REBIND_KB_UP: return get_current_mapping_explicit(true, 0); + case OPT_REBIND_KB_DOWN: return get_current_mapping_explicit(true, 1); + case OPT_REBIND_KB_LEFT: return get_current_mapping_explicit(true, 2); + case OPT_REBIND_KB_RIGHT: return get_current_mapping_explicit(true, 3); + case OPT_REBIND_KB_CROSS: return get_current_mapping_explicit(true, 4); + case OPT_REBIND_KB_CIRCLE: return get_current_mapping_explicit(true, 5); + case OPT_REBIND_KB_SQUARE: return get_current_mapping_explicit(true, 6); + case OPT_REBIND_KB_TRIANGLE: return get_current_mapping_explicit(true, 7); + case OPT_REBIND_KB_LB: return get_current_mapping_explicit(true, 8); + case OPT_REBIND_KB_RB: return get_current_mapping_explicit(true, 9); + case OPT_REBIND_KB_START: return get_current_mapping_explicit(true, 10); + case OPT_REBIND_KB_BACK: return get_current_mapping_explicit(true, 11); + case OPT_REBIND_CTRL_UP: return get_current_mapping_explicit(false, 0); + case OPT_REBIND_CTRL_DOWN: return get_current_mapping_explicit(false, 1); + case OPT_REBIND_CTRL_LEFT: return get_current_mapping_explicit(false, 2); + case OPT_REBIND_CTRL_RIGHT: return get_current_mapping_explicit(false, 3); + case OPT_REBIND_CTRL_CROSS: return get_current_mapping_explicit(false, 4); + case OPT_REBIND_CTRL_CIRCLE: return get_current_mapping_explicit(false, 5); + case OPT_REBIND_CTRL_SQUARE: return get_current_mapping_explicit(false, 6); + case OPT_REBIND_CTRL_TRIANGLE: return get_current_mapping_explicit(false, 7); + case OPT_REBIND_CTRL_LB: return get_current_mapping_explicit(false, 8); + case OPT_REBIND_CTRL_RB: return get_current_mapping_explicit(false, 9); + case OPT_REBIND_CTRL_START: return get_current_mapping_explicit(false, 10); + case OPT_REBIND_CTRL_BACK: return get_current_mapping_explicit(false, 11); default: return ""; } } @@ -310,9 +413,12 @@ int modify_current_option_button() { case OPT_SUB_VIDEO: case OPT_SUB_AUDIO: case OPT_SUB_CONTROLS: + case OPT_SUB_CONTROLLER: + case OPT_SUB_KEYBOARD: case OPT_SUB_GAMEPLAY: case OPT_SUB_MISC: case OPT_BACK: + case OPT_CONTROLS_BACK: set_option_menu(current_selection); break; @@ -369,6 +475,151 @@ int modify_current_option_button() { reset_controller_binds(); break; + // lord forgive me for what im about to program + case OPT_REBIND_KB_UP: + current_rebind_index = 0; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_DOWN: + current_rebind_index = 1; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_LEFT: + current_rebind_index = 2; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_RIGHT: + current_rebind_index = 3; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_CROSS: + current_rebind_index = 4; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_CIRCLE: + current_rebind_index = 5; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_SQUARE: + current_rebind_index = 6; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_TRIANGLE: + current_rebind_index = 7; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_LB: + current_rebind_index = 8; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_RB: + current_rebind_index = 9; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_START: + current_rebind_index = 10; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_KB_BACK: + current_rebind_index = 11; + rebinding_keys = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_UP: + current_rebind_index = 0; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_DOWN: + current_rebind_index = 1; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_LEFT: + current_rebind_index = 2; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_RIGHT: + current_rebind_index = 3; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_CROSS: + current_rebind_index = 4; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_CIRCLE: + current_rebind_index = 5; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_SQUARE: + current_rebind_index = 6; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_TRIANGLE: + current_rebind_index = 7; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_LB: + current_rebind_index = 8; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_RB: + current_rebind_index = 9; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_START: + current_rebind_index = 10; + rebinding_controller = true; + rebinding_single = true; + break; + + case OPT_REBIND_CTRL_BACK: + current_rebind_index = 11; + rebinding_controller = true; + rebinding_single = true; + break; + case OPT_SAVE: save_settings(); return 1; @@ -383,7 +634,12 @@ int modify_current_option_button() { } int options_back_button() { - if (option_submenu_id == OPT_NONE) {return 1;} else {reset_options_menu(); return 0;} + if (option_submenu_id == OPT_NONE) {return 1;} else { + if (option_submenu_id == OPT_SUB_CONTROLLER || option_submenu_id == OPT_SUB_KEYBOARD) { + set_option_menu(OPT_CONTROLS_BACK); + } else reset_options_menu(); + } + return 0; } void move_option_selection(int x) {