option to enable/disable background input
This commit is contained in:
parent
c06889c3bb
commit
8fbb7b6025
|
@ -73,6 +73,36 @@
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- targeting mode -->
|
||||
<div class="config-option" data-event-mouseover="set_cur_config_index(3)" id="conf-general__Background-Input">
|
||||
<label class="config-option__title">Background Input</label>
|
||||
<div class="config-option__list">
|
||||
<input
|
||||
type="radio"
|
||||
data-event-blur="set_cur_config_index(-1)"
|
||||
data-event-focus="set_cur_config_index(3)"
|
||||
name="background_input_mode"
|
||||
data-checked="background_input_mode"
|
||||
value="On"
|
||||
id="bg_input_enabled"
|
||||
style="nav-up: #gyro_sensitivity_input"
|
||||
/>
|
||||
<label class="config-option__tab-label" for="bg_input_enabled">On</label>
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
data-event-blur="set_cur_config_index(-1)"
|
||||
data-event-focus="set_cur_config_index(3)"
|
||||
name="background_input_mode"
|
||||
data-checked="background_input_mode"
|
||||
value="Off"
|
||||
id="bg_input_disabled"
|
||||
style="nav-up: #gyro_sensitivity_input"
|
||||
/>
|
||||
<label class="config-option__tab-label" for="bg_input_disabled">Off</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Descriptions -->
|
||||
<div class="config__wrapper">
|
||||
|
@ -85,6 +115,11 @@
|
|||
<p data-if="cur_config_index == 2">
|
||||
Controls the sensitivity of gyro when using a controller that supports it. Setting this to zero will disable gyro.
|
||||
</p>
|
||||
<p data-if="cur_config_index == 3">
|
||||
Allows the game to read controller input when out of focus.
|
||||
<br/>
|
||||
<b>This setting does not affect keyboard input.</b>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -143,6 +143,20 @@ namespace recomp {
|
|||
TargetingMode get_targeting_mode();
|
||||
void set_targeting_mode(TargetingMode mode);
|
||||
|
||||
enum class BackgroundInputMode {
|
||||
On,
|
||||
Off,
|
||||
OptionCount
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(recomp::BackgroundInputMode, {
|
||||
{recomp::BackgroundInputMode::On, "On"},
|
||||
{recomp::BackgroundInputMode::Off, "Off"}
|
||||
});
|
||||
|
||||
BackgroundInputMode get_background_input_mode();
|
||||
void set_background_input_mode(BackgroundInputMode mode);
|
||||
|
||||
bool game_input_disabled();
|
||||
bool all_input_disabled();
|
||||
|
||||
|
|
|
@ -127,6 +127,7 @@ void save_general_config(const std::filesystem::path& path) {
|
|||
nlohmann::json config_json{};
|
||||
|
||||
recomp::to_json(config_json["targeting_mode"], recomp::get_targeting_mode());
|
||||
recomp::to_json(config_json["background_input_mode"], recomp::get_background_input_mode());
|
||||
config_json["rumble_strength"] = recomp::get_rumble_strength();
|
||||
config_json["gyro_sensitivity"] = recomp::get_gyro_sensitivity();
|
||||
config_json["debug_mode"] = recomp::get_debug_mode_enabled();
|
||||
|
@ -140,6 +141,7 @@ void load_general_config(const std::filesystem::path& path) {
|
|||
config_file >> config_json;
|
||||
|
||||
recomp::set_targeting_mode(from_or_default(config_json, "targeting_mode", recomp::TargetingMode::Switch));
|
||||
recomp::set_background_input_mode(from_or_default(config_json, "background_input_mode", recomp::BackgroundInputMode::On));
|
||||
recomp::set_rumble_strength(from_or_default(config_json, "rumble_strength", 25));
|
||||
recomp::set_gyro_sensitivity(from_or_default(config_json, "gyro_sensitivity", 50));
|
||||
recomp::set_debug_mode_enabled(from_or_default(config_json, "debug_mode", false));
|
||||
|
|
|
@ -249,6 +249,7 @@ struct ControlOptionsContext {
|
|||
int rumble_strength = 50; // 0 to 100
|
||||
int gyro_sensitivity = 50; // 0 to 200
|
||||
recomp::TargetingMode targeting_mode = recomp::TargetingMode::Switch;
|
||||
recomp::BackgroundInputMode background_input_mode = recomp::BackgroundInputMode::On;
|
||||
};
|
||||
|
||||
ControlOptionsContext control_options_context;
|
||||
|
@ -286,6 +287,23 @@ void recomp::set_targeting_mode(recomp::TargetingMode mode) {
|
|||
}
|
||||
}
|
||||
|
||||
recomp::BackgroundInputMode recomp::get_background_input_mode() {
|
||||
return control_options_context.background_input_mode;
|
||||
}
|
||||
|
||||
void recomp::set_background_input_mode(recomp::BackgroundInputMode mode) {
|
||||
control_options_context.background_input_mode = mode;
|
||||
if (general_model_handle) {
|
||||
general_model_handle.DirtyVariable("background_input_mode");
|
||||
}
|
||||
SDL_SetHint(
|
||||
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
|
||||
mode == recomp::BackgroundInputMode::On
|
||||
? "1"
|
||||
: "0"
|
||||
);
|
||||
}
|
||||
|
||||
struct SoundOptionsContext {
|
||||
std::atomic<int> bgm_volume;
|
||||
std::atomic<int> low_health_beeps_enabled; // RmlUi doesn't seem to like "true"/"false" strings for setting variants so an int is used here instead.
|
||||
|
@ -737,6 +755,7 @@ public:
|
|||
constructor.Bind("rumble_strength", &control_options_context.rumble_strength);
|
||||
constructor.Bind("gyro_sensitivity", &control_options_context.gyro_sensitivity);
|
||||
bind_option(constructor, "targeting_mode", &control_options_context.targeting_mode);
|
||||
bind_option(constructor, "background_input_mode", &control_options_context.background_input_mode);
|
||||
|
||||
general_model_handle = constructor.GetModelHandle();
|
||||
}
|
||||
|
|
|
@ -1150,9 +1150,27 @@ int cont_axis_to_key(SDL_ControllerAxisEvent& axis, float value) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void apply_background_input_mode() {
|
||||
static recomp::BackgroundInputMode last_input_mode = recomp::BackgroundInputMode::OptionCount;
|
||||
|
||||
recomp::BackgroundInputMode cur_input_mode = recomp::get_background_input_mode();
|
||||
|
||||
if (last_input_mode != cur_input_mode) {
|
||||
SDL_SetHint(
|
||||
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
|
||||
cur_input_mode == recomp::BackgroundInputMode::On
|
||||
? "1"
|
||||
: "0"
|
||||
);
|
||||
}
|
||||
last_input_mode = cur_input_mode;
|
||||
}
|
||||
|
||||
void draw_hook(RT64::RenderCommandList* command_list, RT64::RenderFramebuffer* swap_chain_framebuffer) {
|
||||
std::lock_guard lock {ui_context_mutex};
|
||||
|
||||
apply_background_input_mode();
|
||||
|
||||
// Return early if the ui context has been destroyed already.
|
||||
if (!ui_context) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue