mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-08-18 13:53:15 -04:00
Implemented UI for controlling autosaving, fixed general config defaults not being applied correctly
This commit is contained in:
+15
-7
@@ -160,22 +160,28 @@ void save_general_config(const std::filesystem::path& path) {
|
||||
config_json["rumble_strength"] = recomp::get_rumble_strength();
|
||||
config_json["gyro_sensitivity"] = recomp::get_gyro_sensitivity();
|
||||
config_json["mouse_sensitivity"] = recomp::get_mouse_sensitivity();
|
||||
config_json["autosave_mode"] = recomp::get_autosave_mode();
|
||||
config_json["debug_mode"] = recomp::get_debug_mode_enabled();
|
||||
config_file << std::setw(4) << config_json;
|
||||
}
|
||||
|
||||
void set_general_settings_from_json(const nlohmann::json& 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_mouse_sensitivity(from_or_default(config_json, "mouse_sensitivity", is_steam_deck ? 50 : 0));
|
||||
recomp::set_autosave_mode(from_or_default(config_json, "autosave_mode", recomp::AutosaveMode::On));
|
||||
recomp::set_debug_mode_enabled(from_or_default(config_json, "debug_mode", false));
|
||||
}
|
||||
|
||||
void load_general_config(const std::filesystem::path& path) {
|
||||
std::ifstream config_file{path};
|
||||
nlohmann::json config_json{};
|
||||
|
||||
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_mouse_sensitivity(from_or_default(config_json, "mouse_sensitivity", is_steam_deck ? 50 : 0));
|
||||
recomp::set_debug_mode_enabled(from_or_default(config_json, "debug_mode", false));
|
||||
|
||||
set_general_settings_from_json(config_json);
|
||||
}
|
||||
|
||||
void assign_mapping(recomp::InputDevice device, recomp::GameInput input, const std::vector<recomp::InputField>& value) {
|
||||
@@ -374,6 +380,8 @@ void recomp::load_config() {
|
||||
load_general_config(general_path);
|
||||
}
|
||||
else {
|
||||
// Set the general settings from an empty json to use defaults.
|
||||
set_general_settings_from_json({});
|
||||
save_general_config(general_path);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include "recomp.h"
|
||||
#include "recomp_config.h"
|
||||
#include "recomp_input.h"
|
||||
#include "recomp_ui.h"
|
||||
#include "recomp_sound.h"
|
||||
@@ -88,3 +89,7 @@ extern "C" void recomp_get_low_health_beeps_enabled(uint8_t* rdram, recomp_conte
|
||||
extern "C" void recomp_time_us(uint8_t* rdram, recomp_context* ctx) {
|
||||
_return(ctx, static_cast<u32>(std::chrono::duration_cast<std::chrono::microseconds>(ultramodern::time_since_start()).count()));
|
||||
}
|
||||
|
||||
extern "C" void recomp_autosave_enabled(uint8_t* rdram, recomp_context* ctx) {
|
||||
_return(ctx, static_cast<s32>(recomp::get_autosave_mode() == recomp::AutosaveMode::On));
|
||||
}
|
||||
|
||||
+19
-5
@@ -269,12 +269,14 @@ void recomp::open_quit_game_prompt() {
|
||||
);
|
||||
}
|
||||
|
||||
// These defaults values don't matter, as the config file handling overrides them.
|
||||
struct ControlOptionsContext {
|
||||
int rumble_strength = 50; // 0 to 100
|
||||
int gyro_sensitivity = 50; // 0 to 100
|
||||
int mouse_sensitivity = 50; // 0 to 100
|
||||
recomp::TargetingMode targeting_mode = recomp::TargetingMode::Switch;
|
||||
recomp::BackgroundInputMode background_input_mode = recomp::BackgroundInputMode::On;
|
||||
int rumble_strength; // 0 to 100
|
||||
int gyro_sensitivity; // 0 to 100
|
||||
int mouse_sensitivity; // 0 to 100
|
||||
recomp::TargetingMode targeting_mode;
|
||||
recomp::BackgroundInputMode background_input_mode;
|
||||
recomp::AutosaveMode autosave_mode;
|
||||
};
|
||||
|
||||
ControlOptionsContext control_options_context;
|
||||
@@ -340,6 +342,17 @@ void recomp::set_background_input_mode(recomp::BackgroundInputMode mode) {
|
||||
);
|
||||
}
|
||||
|
||||
recomp::AutosaveMode recomp::get_autosave_mode() {
|
||||
return control_options_context.autosave_mode;
|
||||
}
|
||||
|
||||
void recomp::set_autosave_mode(recomp::AutosaveMode mode) {
|
||||
control_options_context.autosave_mode = mode;
|
||||
if (general_model_handle) {
|
||||
general_model_handle.DirtyVariable("autosave_mode");
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -824,6 +837,7 @@ public:
|
||||
constructor.Bind("mouse_sensitivity", &control_options_context.mouse_sensitivity);
|
||||
bind_option(constructor, "targeting_mode", &control_options_context.targeting_mode);
|
||||
bind_option(constructor, "background_input_mode", &control_options_context.background_input_mode);
|
||||
bind_option(constructor, "autosave_mode", &control_options_context.autosave_mode);
|
||||
|
||||
general_model_handle = constructor.GetModelHandle();
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ public:
|
||||
if (row_byte_padding == 0) {
|
||||
// Copy row-by-row if the image is flipped.
|
||||
if (flip_y) {
|
||||
for (uint32_t row = 0; row < source_dimensions.y; row++) {
|
||||
for (int row = 0; row < source_dimensions.y; row++) {
|
||||
memcpy(dst_data + row_byte_width * (source_dimensions.y - row - 1), source + row_byte_width * row, row_byte_width);
|
||||
}
|
||||
}
|
||||
@@ -536,7 +536,7 @@ public:
|
||||
uint32_t src_stride = flip_y ? -row_pitch : row_pitch;
|
||||
size_t offset = 0;
|
||||
|
||||
for (uint32_t row = 0; row < source_dimensions.y; row++) { //(offset + increment) <= image_size_bytes) {
|
||||
for (int row = 0; row < source_dimensions.y; row++) { //(offset + increment) <= image_size_bytes) {
|
||||
memcpy(dst_data, src_data, row_pitch);
|
||||
src_data += src_stride;
|
||||
offset += row_pitch;
|
||||
@@ -581,7 +581,7 @@ public:
|
||||
mvp_ = projection_mtx_ * transform_;
|
||||
}
|
||||
|
||||
void start(RT64::RenderCommandList* list, uint32_t image_width, uint32_t image_height) {
|
||||
void start(RT64::RenderCommandList* list, int image_width, int image_height) {
|
||||
list_ = list;
|
||||
|
||||
if (multisampling_.sampleCount > 1) {
|
||||
|
||||
Reference in New Issue
Block a user