Reorganized config menu tabs, hide debug menu behind manual config file edit, added missing recompiler config file

This commit is contained in:
Mr-Wiseguy
2024-03-15 12:13:29 -04:00
parent ff5dd7f50c
commit 0775299aae
11 changed files with 706 additions and 42 deletions
+32 -7
View File
@@ -13,6 +13,7 @@
#include <pwd.h>
#endif
constexpr std::u8string_view general_filename = u8"general.json";
constexpr std::u8string_view graphics_filename = u8"graphics.json";
constexpr std::u8string_view controls_filename = u8"controls.json";
constexpr std::u8string_view sound_filename = u8"sound.json";
@@ -111,6 +112,28 @@ std::filesystem::path recomp::get_app_folder_path() {
return recomp_dir;
}
void save_general_config(const std::filesystem::path& path) {
std::ofstream config_file{path};
nlohmann::json config_json{};
recomp::to_json(config_json["targeting_mode"], recomp::get_targeting_mode());
config_json["rumble_strength"] = recomp::get_rumble_strength();
config_json["debug_mode"] = recomp::get_debug_mode_enabled();
config_file << std::setw(4) << config_json;
}
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_rumble_strength(from_or_default(config_json, "rumble_strength", 25));
recomp::set_debug_mode_enabled(from_or_default(config_json, "debug_mode", false));
}
void assign_mapping(recomp::InputDevice device, recomp::GameInput input, const std::vector<recomp::InputField>& value) {
for (size_t binding_index = 0; binding_index < std::min(value.size(), recomp::bindings_per_input); binding_index++) {
recomp::set_input_binding(input, binding_index, device, value[binding_index]);
@@ -187,10 +210,6 @@ void add_input_bindings(nlohmann::json& out, recomp::GameInput input, recomp::In
void save_controls_config(const std::filesystem::path& path) {
nlohmann::json config_json{};
config_json["options"] = {};
recomp::to_json(config_json["options"]["targeting_mode"], recomp::get_targeting_mode());
config_json["options"]["rumble_strength"] = recomp::get_rumble_strength();
config_json["keyboard"] = {};
config_json["controller"] = {};
@@ -241,9 +260,6 @@ void load_controls_config(const std::filesystem::path& path) {
nlohmann::json config_json{};
config_file >> config_json;
recomp::set_targeting_mode(from_or_default(config_json["options"], "targeting_mode", recomp::TargetingMode::Switch));
recomp::set_rumble_strength(from_or_default(config_json["options"], "rumble_strength", 25));
if (!load_input_device_from_json(config_json, recomp::InputDevice::Keyboard, "keyboard")) {
assign_all_mappings(recomp::InputDevice::Keyboard, recomp::default_n64_keyboard_mappings);
@@ -278,10 +294,18 @@ void load_sound_config(const std::filesystem::path& path) {
void recomp::load_config() {
std::filesystem::path recomp_dir = recomp::get_app_folder_path();
std::filesystem::path general_path = recomp_dir / general_filename;
std::filesystem::path graphics_path = recomp_dir / graphics_filename;
std::filesystem::path controls_path = recomp_dir / controls_filename;
std::filesystem::path sound_path = recomp_dir / sound_filename;
if (std::filesystem::exists(general_path)) {
load_general_config(general_path);
}
else {
save_general_config(general_path);
}
if (std::filesystem::exists(graphics_path)) {
load_graphics_config(graphics_path);
}
@@ -316,6 +340,7 @@ void recomp::save_config() {
std::filesystem::create_directories(recomp_dir);
save_general_config(recomp_dir / general_filename);
save_graphics_config(recomp_dir / graphics_filename);
save_controls_config(recomp_dir / controls_filename);
save_sound_config(recomp_dir / sound_filename);
+27 -12
View File
@@ -8,12 +8,12 @@
#include "RmlUi/Core.h"
ultramodern::GraphicsConfig new_options;
Rml::DataModelHandle graphics_model_handle;
Rml::DataModelHandle general_model_handle;
Rml::DataModelHandle controls_model_handle;
Rml::DataModelHandle control_options_model_handle;
Rml::DataModelHandle graphics_model_handle;
Rml::DataModelHandle sound_options_model_handle;
// True if controller config menu is open, false if keyboard config menu is open, undefined otherwise
bool configuring_controller = false;
bool configuring_controller = false;
template <typename T>
void get_option(const T& input, Rml::Variant& output) {
@@ -108,8 +108,8 @@ int recomp::get_rumble_strength() {
void recomp::set_rumble_strength(int strength) {
control_options_context.rumble_strength = strength;
if (control_options_model_handle) {
control_options_model_handle.DirtyVariable("rumble_strength");
if (general_model_handle) {
general_model_handle.DirtyVariable("rumble_strength");
}
}
@@ -119,8 +119,8 @@ recomp::TargetingMode recomp::get_targeting_mode() {
void recomp::set_targeting_mode(recomp::TargetingMode mode) {
control_options_context.targeting_mode = mode;
if (control_options_model_handle) {
control_options_model_handle.DirtyVariable("targeting_mode");
if (general_model_handle) {
general_model_handle.DirtyVariable("targeting_mode");
}
}
@@ -175,6 +175,7 @@ struct DebugContext {
int area_index = 0;
int scene_index = 0;
int entrance_index = 0;
bool debug_enabled = false;
DebugContext() {
for (const auto& area : recomp::game_warps) {
@@ -442,8 +443,8 @@ public:
controls_model_handle = constructor.GetModelHandle();
}
void make_control_options_bindings(Rml::Context* context) {
Rml::DataModelConstructor constructor = context->CreateDataModel("control_options_model");
void make_general_bindings(Rml::Context* context) {
Rml::DataModelConstructor constructor = context->CreateDataModel("general_model");
if (!constructor) {
throw std::runtime_error("Failed to make RmlUi data model for the control options menu");
}
@@ -451,7 +452,7 @@ public:
constructor.Bind("rumble_strength", &control_options_context.rumble_strength);
bind_option(constructor, "targeting_mode", &control_options_context.targeting_mode);
control_options_model_handle = constructor.GetModelHandle();
general_model_handle = constructor.GetModelHandle();
}
void make_sound_options_bindings(Rml::Context* context) {
@@ -471,6 +472,9 @@ public:
if (!constructor) {
throw std::runtime_error("Failed to make RmlUi data model for the debug menu");
}
// Bind the debug mode enabled flag.
constructor.Bind("debug_enabled", &debug_context.debug_enabled);
// Register the array type for string vectors.
constructor.RegisterArray<std::vector<std::string>>();
@@ -489,9 +493,9 @@ public:
}
void make_bindings(Rml::Context* context) override {
make_graphics_bindings(context);
make_general_bindings(context);
make_controls_bindings(context);
make_control_options_bindings(context);
make_graphics_bindings(context);
make_sound_options_bindings(context);
make_debug_bindings(context);
}
@@ -500,3 +504,14 @@ public:
std::unique_ptr<recomp::MenuController> recomp::create_config_menu() {
return std::make_unique<ConfigMenu>();
}
bool recomp::get_debug_mode_enabled() {
return debug_context.debug_enabled;
}
void recomp::set_debug_mode_enabled(bool enabled) {
debug_context.debug_enabled = enabled;
if (debug_context.model_handle) {
debug_context.model_handle.DirtyVariable("debug_enabled");
}
}
+1
View File
@@ -88,6 +88,7 @@ public:
recomp::register_event(listener, "open_settings",
[](const std::string& param, Rml::Event& event) {
recomp::set_current_menu(recomp::Menu::Config);
recomp::set_config_submenu(recomp::ConfigSubmenu::General);
}
);
recomp::register_event(listener, "exit_game",