cancel scanning input with back/escape

This commit is contained in:
thecozies 2024-03-12 08:35:58 -05:00
parent 299293ca99
commit 0784db4988
3 changed files with 28 additions and 5 deletions

View File

@ -74,7 +74,9 @@ namespace recomp {
}; };
void start_scanning_input(InputDevice device); void start_scanning_input(InputDevice device);
void stop_scanning_input();
void finish_scanning_input(InputField scanned_field); void finish_scanning_input(InputField scanned_field);
void cancel_scanning_input();
InputField get_scanned_input(); InputField get_scanned_input();
struct DefaultN64Mappings { struct DefaultN64Mappings {

View File

@ -60,6 +60,10 @@ void recomp::start_scanning_input(recomp::InputDevice device) {
scanning_device.store(device); scanning_device.store(device);
} }
void recomp::stop_scanning_input() {
scanning_device.store(recomp::InputDevice::COUNT);
}
void queue_if_enabled(SDL_Event* event) { void queue_if_enabled(SDL_Event* event) {
if (!recomp::all_input_disabled()) { if (!recomp::all_input_disabled()) {
recomp::queue_event(*event); recomp::queue_event(*event);
@ -81,8 +85,12 @@ bool sdl_event_filter(void* userdata, SDL_Event* event) {
if (keyevent->keysym.scancode == SDL_Scancode::SDL_SCANCODE_RETURN && (keyevent->keysym.mod & SDL_Keymod::KMOD_ALT)) { if (keyevent->keysym.scancode == SDL_Scancode::SDL_SCANCODE_RETURN && (keyevent->keysym.mod & SDL_Keymod::KMOD_ALT)) {
RT64ChangeWindow(); RT64ChangeWindow();
} }
if (scanning_device == recomp::InputDevice::Keyboard) { if (scanning_device != recomp::InputDevice::COUNT) {
set_scanned_input({(uint32_t)InputType::Keyboard, keyevent->keysym.scancode}); if (keyevent->keysym.scancode == SDL_Scancode::SDL_SCANCODE_ESCAPE) {
recomp::cancel_scanning_input();
} else if (scanning_device == recomp::InputDevice::Keyboard) {
set_scanned_input({(uint32_t)InputType::Keyboard, keyevent->keysym.scancode});
}
} else { } else {
queue_if_enabled(event); queue_if_enabled(event);
} }
@ -123,9 +131,13 @@ bool sdl_event_filter(void* userdata, SDL_Event* event) {
queue_if_enabled(event); queue_if_enabled(event);
break; break;
case SDL_EventType::SDL_CONTROLLERBUTTONDOWN: case SDL_EventType::SDL_CONTROLLERBUTTONDOWN:
if (scanning_device == recomp::InputDevice::Controller) { if (scanning_device != recomp::InputDevice::COUNT) {
SDL_ControllerButtonEvent* button_event = &event->cbutton; if (event->cbutton.button == SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_BACK) {
set_scanned_input({(uint32_t)InputType::ControllerDigital, button_event->button}); recomp::cancel_scanning_input();
} else if (scanning_device == recomp::InputDevice::Controller) {
SDL_ControllerButtonEvent* button_event = &event->cbutton;
set_scanned_input({(uint32_t)InputType::ControllerDigital, button_event->button});
}
} else { } else {
queue_if_enabled(event); queue_if_enabled(event);
} }

View File

@ -75,6 +75,15 @@ void recomp::finish_scanning_input(recomp::InputField scanned_field) {
controls_model_handle.DirtyVariable("active_binding_slot"); controls_model_handle.DirtyVariable("active_binding_slot");
} }
void recomp::cancel_scanning_input() {
recomp::stop_scanning_input();
scanned_input_index = -1;
scanned_binding_index = -1;
controls_model_handle.DirtyVariable("inputs");
controls_model_handle.DirtyVariable("active_binding_input");
controls_model_handle.DirtyVariable("active_binding_slot");
}
void close_config_menu() { void close_config_menu() {
recomp::save_config(); recomp::save_config();