Split default input mappings by device, disabled input while menu is open, made config menu open with escape/select, made config menu close with escape
This commit is contained in:
parent
0609c82417
commit
5ee7eaed1f
|
@ -43,10 +43,13 @@ namespace recomp {
|
|||
std::vector<InputField> analog_down;
|
||||
};
|
||||
|
||||
extern const DefaultN64Mappings default_n64_mappings;
|
||||
extern const DefaultN64Mappings default_n64_keyboard_mappings;
|
||||
extern const DefaultN64Mappings default_n64_controller_mappings;
|
||||
|
||||
void get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out);
|
||||
void handle_events();
|
||||
|
||||
bool game_input_disabled();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,7 @@ namespace recomp {
|
|||
};
|
||||
|
||||
void set_current_menu(Menu menu);
|
||||
Menu get_current_menu();
|
||||
|
||||
enum class ConfigSubmenu {
|
||||
Graphics,
|
||||
|
|
|
@ -42,24 +42,44 @@ void recomp::get_n64_input(uint16_t* buttons_out, float* x_out, float* y_out) {
|
|||
float cur_x = 0.0f;
|
||||
float cur_y = 0.0f;
|
||||
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.a) ? N64Inputs::A : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.l) ? N64Inputs::L : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.r) ? N64Inputs::R : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.z) ? N64Inputs::Z : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.start) ? N64Inputs::START : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_up) ? N64Inputs::C_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
if (!recomp::game_input_disabled()) {
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.a) ? N64Inputs::A : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.l) ? N64Inputs::L : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.r) ? N64Inputs::R : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.z) ? N64Inputs::Z : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.start) ? N64Inputs::START : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_up) ? N64Inputs::C_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.a) ? N64Inputs::A : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.l) ? N64Inputs::L : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.r) ? N64Inputs::R : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.z) ? N64Inputs::Z : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.start) ? N64Inputs::START : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_up) ? N64Inputs::C_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
|
||||
cur_x = recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_left);
|
||||
cur_y = recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.analog_down);
|
||||
cur_x += recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_left);
|
||||
cur_y += recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_controller_mappings.analog_down);
|
||||
}
|
||||
|
||||
*buttons_out = cur_buttons;
|
||||
cur_x = recomp::get_input_analog(recomp::default_n64_mappings.analog_right) - recomp::get_input_analog(recomp::default_n64_mappings.analog_left);
|
||||
cur_y = recomp::get_input_analog(recomp::default_n64_mappings.analog_up) - recomp::get_input_analog(recomp::default_n64_mappings.analog_down);
|
||||
*x_out = cur_x;
|
||||
*y_out = cur_y;
|
||||
}
|
||||
|
@ -69,14 +89,25 @@ extern "C" void recomp_get_item_inputs(uint8_t* rdram, recomp_context* ctx) {
|
|||
|
||||
uint32_t cur_buttons = 0;
|
||||
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
if (!recomp::game_input_disabled()) {
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_keyboard_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.b) ? N64Inputs::B : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_left) ? N64Inputs::C_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_right) ? N64Inputs::C_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.c_down) ? N64Inputs::C_DOWN : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_left) ? N64Inputs::DPAD_LEFT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_right) ? N64Inputs::DPAD_RIGHT : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_up) ? N64Inputs::DPAD_UP : 0;
|
||||
cur_buttons |= recomp::get_input_digital(recomp::default_n64_controller_mappings.dpad_down) ? N64Inputs::DPAD_DOWN : 0;
|
||||
}
|
||||
|
||||
*buttons_out = cur_buttons;
|
||||
}
|
||||
|
@ -108,8 +139,16 @@ extern "C" void recomp_get_camera_inputs(uint8_t* rdram, recomp_context* ctx) {
|
|||
float* x_out = _arg<0, float*>(rdram, ctx);
|
||||
float* y_out = _arg<1, float*>(rdram, ctx);
|
||||
|
||||
float x_val = recomp::get_input_analog(recomp::default_n64_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_mappings.c_left);
|
||||
float y_val = recomp::get_input_analog(recomp::default_n64_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_mappings.c_down);
|
||||
float x_val = 0;
|
||||
float y_val = 0;
|
||||
|
||||
if (!recomp::game_input_disabled()) {
|
||||
x_val += recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_left);
|
||||
y_val += recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_keyboard_mappings.c_down);
|
||||
|
||||
x_val += recomp::get_input_analog(recomp::default_n64_controller_mappings.c_right) - recomp::get_input_analog(recomp::default_n64_controller_mappings.c_left);
|
||||
y_val += recomp::get_input_analog(recomp::default_n64_controller_mappings.c_up) - recomp::get_input_analog(recomp::default_n64_controller_mappings.c_down);
|
||||
}
|
||||
|
||||
*x_out = x_val;
|
||||
*y_out = y_val;
|
||||
|
|
|
@ -83,80 +83,119 @@ constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_EAST = SDL_CONTROLLER_B
|
|||
constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_WEST = SDL_CONTROLLER_BUTTON_X;
|
||||
constexpr SDL_GameControllerButton SDL_CONTROLLER_BUTTON_NORTH = SDL_CONTROLLER_BUTTON_Y;
|
||||
|
||||
const recomp::DefaultN64Mappings recomp::default_n64_mappings = {
|
||||
const recomp::DefaultN64Mappings recomp::default_n64_keyboard_mappings = {
|
||||
.a = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_SPACE}
|
||||
},
|
||||
.b = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LSHIFT}
|
||||
},
|
||||
.l = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_E}
|
||||
},
|
||||
.r = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_R}
|
||||
},
|
||||
.z = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_Q}
|
||||
},
|
||||
.start = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RETURN}
|
||||
},
|
||||
.c_left = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LEFT}
|
||||
},
|
||||
.c_right = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RIGHT}
|
||||
},
|
||||
.c_up = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_UP}
|
||||
},
|
||||
.c_down = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_DOWN}
|
||||
},
|
||||
.dpad_left = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_J}
|
||||
},
|
||||
.dpad_right = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_L}
|
||||
},
|
||||
.dpad_up = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_I}
|
||||
},
|
||||
.dpad_down = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_K}
|
||||
},
|
||||
.analog_left = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_A}
|
||||
},
|
||||
.analog_right = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_D}
|
||||
},
|
||||
.analog_up = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_W}
|
||||
},
|
||||
.analog_down = {
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_S}
|
||||
},
|
||||
};
|
||||
|
||||
const recomp::DefaultN64Mappings recomp::default_n64_controller_mappings = {
|
||||
.a = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_SOUTH},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_SPACE}
|
||||
},
|
||||
.b = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_EAST},
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_WEST},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LSHIFT}
|
||||
},
|
||||
.l = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_LEFTSHOULDER},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_E}
|
||||
},
|
||||
.r = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_TRIGGERRIGHT + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_R}
|
||||
},
|
||||
.z = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_TRIGGERLEFT + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_Q}
|
||||
},
|
||||
.start = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_START},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RETURN}
|
||||
},
|
||||
.c_left = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_RIGHTX + 1)},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_LEFT}
|
||||
},
|
||||
.c_right = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_RIGHTX + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_RIGHT}
|
||||
},
|
||||
.c_up = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_RIGHTY + 1)},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_UP}
|
||||
},
|
||||
.c_down = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_RIGHTY + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_DOWN}
|
||||
},
|
||||
.dpad_left = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_LEFT},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_J}
|
||||
},
|
||||
.dpad_right = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_L}
|
||||
},
|
||||
.dpad_up = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_UP},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_I}
|
||||
},
|
||||
.dpad_down = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerDigital, .input_id = SDL_CONTROLLER_BUTTON_DPAD_DOWN},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_K}
|
||||
},
|
||||
.analog_left = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_LEFTX + 1)},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_A}
|
||||
},
|
||||
.analog_right = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_LEFTX + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_D}
|
||||
},
|
||||
.analog_up = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = -(SDL_CONTROLLER_AXIS_LEFTY + 1)},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_W}
|
||||
},
|
||||
.analog_down = {
|
||||
{.device_type = (uint32_t)DeviceType::ControllerAnalog, .input_id = SDL_CONTROLLER_AXIS_LEFTY + 1},
|
||||
{.device_type = (uint32_t)DeviceType::Keyboard, .input_id = SDL_SCANCODE_S}
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -272,3 +311,8 @@ bool recomp::get_input_digital(const std::span<const recomp::InputField> fields)
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool recomp::game_input_disabled() {
|
||||
// Disable input if any menu is open.
|
||||
return recomp::get_current_menu() != recomp::Menu::None;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "recomp_ui.h"
|
||||
#include "../../ultramodern/config.hpp"
|
||||
#include "../../ultramodern/ultramodern.hpp"
|
||||
#include "RmlUi/Core.h"
|
||||
|
||||
ultramodern::GraphicsConfig cur_options;
|
||||
|
@ -67,6 +68,19 @@ public:
|
|||
options_handle.DirtyVariable("options_changed");
|
||||
update_graphics_config(new_options);
|
||||
});
|
||||
recomp::register_event(listener, "config_keydown",
|
||||
[](const std::string& param, Rml::Event& event) {
|
||||
if (event.GetId() == Rml::EventId::Keydown) {
|
||||
if (event.GetParameter<Rml::Input::KeyIdentifier>("key_identifier", Rml::Input::KeyIdentifier::KI_UNKNOWN) == Rml::Input::KeyIdentifier::KI_ESCAPE) {
|
||||
if (ultramodern::is_game_started()) {
|
||||
recomp::set_current_menu(recomp::Menu::None);
|
||||
}
|
||||
else {
|
||||
recomp::set_current_menu(recomp::Menu::Launcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
void make_bindings(Rml::Context* context) override {
|
||||
Rml::DataModelConstructor constructor = context->CreateDataModel("graphics_model");
|
||||
|
|
|
@ -602,7 +602,6 @@ namespace recomp {
|
|||
std::unordered_map<Rml::String, UiEventListener> listener_map_;
|
||||
public:
|
||||
Rml::EventListener* InstanceEventListener(const Rml::String& value, Rml::Element* element) override {
|
||||
printf("Instancing event listener for %s\n", value.c_str());
|
||||
// Check if a listener has already been made for the full event string and return it if so.
|
||||
auto find_listener_it = listener_map_.find(value);
|
||||
if (find_listener_it != listener_map_.end()) {
|
||||
|
@ -878,6 +877,29 @@ void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderTexture* swap_
|
|||
break;
|
||||
}
|
||||
}
|
||||
// If no menu is open and the game has been started and either the escape key or select button are pressed, open the config menu.
|
||||
if (cur_menu == recomp::Menu::None && ultramodern::is_game_started()) {
|
||||
bool open_config = false;
|
||||
|
||||
switch (cur_event.type) {
|
||||
case SDL_EventType::SDL_KEYDOWN:
|
||||
if (cur_event.key.keysym.scancode == SDL_Scancode::SDL_SCANCODE_ESCAPE) {
|
||||
open_config = true;
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_CONTROLLERBUTTONDOWN:
|
||||
if (cur_event.cbutton.button == SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_BACK) {
|
||||
open_config = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (open_config) {
|
||||
cur_menu = recomp::Menu::Config;
|
||||
open_menu.store(recomp::Menu::Config);
|
||||
UIContext.rml.swap_document(cur_menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UIContext.rml.update_focus(mouse_moved);
|
||||
|
@ -926,3 +948,7 @@ void recomp::destroy_ui() {
|
|||
Rml::Shutdown();
|
||||
UIContext.rml.unload();
|
||||
}
|
||||
|
||||
recomp::Menu recomp::get_current_menu() {
|
||||
return open_menu.load();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue