Add special config option id to control texture pack state for code mods

This commit is contained in:
Mr-Wiseguy
2025-04-09 03:51:26 -04:00
parent 8382fa3d65
commit 7407bebf6e
7 changed files with 162 additions and 21 deletions
+32
View File
@@ -1,6 +1,7 @@
#include "ui_mod_menu.h"
#include "recomp_ui.h"
#include "zelda_support.h"
#include "zelda_render.h"
#include "librecomp/mods.hpp"
@@ -384,6 +385,22 @@ ContextId get_config_sub_menu_context_id() {
return sub_menu_context;
}
bool ModMenu::handle_special_config_options(const recomp::mods::ConfigOption& option, const recomp::mods::ConfigValueVariant& config_value) {
if (zelda64::renderer::is_texture_pack_enable_config_option(option, true)) {
const recomp::mods::ConfigOptionEnum &option_enum = std::get<recomp::mods::ConfigOptionEnum>(option.variant);
config_sub_menu->add_radio_option(option.id, option.name, option.description, std::get<uint32_t>(config_value), option_enum.options,
[this](const std::string &id, uint32_t value) {
mod_enum_option_changed(id, value);
mod_hd_textures_enabled_changed(value);
});
return true;
}
return false;
}
void ModMenu::mod_configure_requested() {
if (active_mod_index >= 0) {
// Record the context that was open when this function was called and close it.
@@ -401,6 +418,10 @@ void ModMenu::mod_configure_requested() {
continue;
}
if (handle_special_config_options(option, config_value)) {
continue;
}
switch (option.type) {
case recomp::mods::ConfigOptionType::Enum: {
const recomp::mods::ConfigOptionEnum &option_enum = std::get<recomp::mods::ConfigOptionEnum>(option.variant);
@@ -455,6 +476,17 @@ void ModMenu::mod_number_option_changed(const std::string &id, double value) {
}
}
void ModMenu::mod_hd_textures_enabled_changed(uint32_t value) {
if (active_mod_index >= 0) {
if (value) {
zelda64::renderer::secondary_enable_texture_pack(mod_details[active_mod_index].mod_id);
}
else {
zelda64::renderer::secondary_disable_texture_pack(mod_details[active_mod_index].mod_id);
}
}
}
void ModMenu::create_mod_list() {
ContextId context = get_current_context();
+2
View File
@@ -74,9 +74,11 @@ private:
void mod_selected(uint32_t mod_index);
void mod_dragged(uint32_t mod_index, EventDrag drag);
void mod_configure_requested();
bool handle_special_config_options(const recomp::mods::ConfigOption& option, const recomp::mods::ConfigValueVariant& config_value);
void mod_enum_option_changed(const std::string &id, uint32_t value);
void mod_string_option_changed(const std::string &id, const std::string &value);
void mod_number_option_changed(const std::string &id, double value);
void mod_hd_textures_enabled_changed(uint32_t value);
void create_mod_list();
void process_event(const Event &e) override;
+18
View File
@@ -234,6 +234,8 @@ void recompui::open_choice_prompt(
std::function<void()> prev_cancel_action = std::move(prompt_state.cancel_action);
ContextId prev_context = try_close_current_context();
prompt_state.ui_context.open();
prompt_state.prompt_header->set_text(header_text);
@@ -252,6 +254,10 @@ void recompui::open_choice_prompt(
prompt_state.ui_context.close();
if (prev_context != ContextId::null()) {
prev_context.open();
}
show_prompt(prev_cancel_action, focus_on_cancel);
}
@@ -267,6 +273,8 @@ void recompui::open_info_prompt(
std::function<void()> prev_cancel_action = std::move(prompt_state.cancel_action);
ContextId prev_context = try_close_current_context();
prompt_state.ui_context.open();
prompt_state.prompt_header->set_text(header_text);
@@ -283,6 +291,10 @@ void recompui::open_info_prompt(
prompt_state.ui_context.close();
if (prev_context != ContextId::null()) {
prev_context.open();
}
show_prompt(prev_cancel_action, true);
}
@@ -295,6 +307,8 @@ void recompui::open_notification(
std::function<void()> prev_cancel_action = std::move(prompt_state.cancel_action);
ContextId prev_context = try_close_current_context();
prompt_state.ui_context.open();
prompt_state.prompt_header->set_text(header_text);
@@ -308,6 +322,10 @@ void recompui::open_notification(
prompt_state.ui_context.close();
if (prev_context != ContextId::null()) {
prev_context.open();
}
show_prompt(prev_cancel_action, false);
}