mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-05-23 23:05:46 -04:00
Auto-enabled mods.
This commit is contained in:
+22
-2
@@ -19,6 +19,10 @@ static std::string generate_thumbnail_src_for_mod(const std::string &mod_id) {
|
||||
return "?/mods/" + mod_id + "/thumb";
|
||||
}
|
||||
|
||||
static bool is_mod_enabled_or_auto(const std::string &mod_id) {
|
||||
return recomp::mods::is_mod_enabled(mod_id) || recomp::mods::is_mod_auto_enabled(mod_id);
|
||||
}
|
||||
|
||||
// ModEntryView
|
||||
|
||||
ModEntryView::ModEntryView(Element *parent) : Element(parent) {
|
||||
@@ -80,6 +84,10 @@ void ModEntryView::set_mod_thumbnail(const std::string &thumbnail) {
|
||||
thumbnail_image->set_src(thumbnail);
|
||||
}
|
||||
|
||||
void ModEntryView::set_mod_enabled(bool enabled) {
|
||||
set_opacity(enabled ? 1.0f : 0.5f);
|
||||
}
|
||||
|
||||
void ModEntryView::set_selected(bool selected) {
|
||||
set_style_enabled(checked_state, selected);
|
||||
}
|
||||
@@ -115,6 +123,10 @@ void ModEntryButton::set_mod_thumbnail(const std::string &thumbnail) {
|
||||
view->set_mod_thumbnail(thumbnail);
|
||||
}
|
||||
|
||||
void ModEntryButton::set_mod_enabled(bool enabled) {
|
||||
view->set_mod_enabled(enabled);
|
||||
}
|
||||
|
||||
void ModEntryButton::set_selected(bool selected) {
|
||||
view->set_selected(selected);
|
||||
}
|
||||
@@ -219,6 +231,11 @@ void ModMenu::open_mods_folder() {
|
||||
void ModMenu::mod_toggled(bool enabled) {
|
||||
if (active_mod_index >= 0) {
|
||||
recomp::mods::enable_mod(mod_details[active_mod_index].mod_id, enabled);
|
||||
|
||||
// Refresh enabled status for all mods in case one of them got auto-enabled due to being a dependency.
|
||||
for (size_t i = 0; i < mod_entry_buttons.size(); i++) {
|
||||
mod_entry_buttons[i]->set_mod_enabled(is_mod_enabled_or_auto(mod_details[i].mod_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,11 +249,11 @@ void ModMenu::mod_selected(uint32_t mod_index) {
|
||||
if (active_mod_index >= 0) {
|
||||
std::string thumbnail_src = generate_thumbnail_src_for_mod(mod_details[mod_index].mod_id);
|
||||
const recomp::mods::ConfigSchema &config_schema = recomp::mods::get_mod_config_schema(mod_details[active_mod_index].mod_id);
|
||||
bool mod_enabled = recomp::mods::is_mod_enabled(mod_details[mod_index].mod_id);
|
||||
bool toggle_checked = is_mod_enabled_or_auto(mod_details[mod_index].mod_id);
|
||||
bool auto_enabled = recomp::mods::is_mod_auto_enabled(mod_details[mod_index].mod_id);
|
||||
bool toggle_enabled = !auto_enabled && (mod_details[mod_index].runtime_toggleable || !ultramodern::is_game_started());
|
||||
bool configure_enabled = !config_schema.options.empty();
|
||||
mod_details_panel->set_mod_details(mod_details[mod_index], thumbnail_src, mod_enabled, toggle_enabled, configure_enabled);
|
||||
mod_details_panel->set_mod_details(mod_details[mod_index], thumbnail_src, toggle_checked, toggle_enabled, auto_enabled, configure_enabled);
|
||||
mod_entry_buttons[active_mod_index]->set_selected(true);
|
||||
}
|
||||
}
|
||||
@@ -260,6 +277,7 @@ void ModMenu::mod_dragged(uint32_t mod_index, EventDrag drag) {
|
||||
mod_entry_floating_view->set_display(Display::Flex);
|
||||
mod_entry_floating_view->set_mod_details(mod_details[mod_index]);
|
||||
mod_entry_floating_view->set_mod_thumbnail(generate_thumbnail_src_for_mod(mod_details[mod_index].mod_id));
|
||||
mod_entry_floating_view->set_mod_enabled(is_mod_enabled_or_auto(mod_details[mod_index].mod_id));
|
||||
mod_entry_floating_view->set_left(left, Unit::Px);
|
||||
mod_entry_floating_view->set_top(top, Unit::Px);
|
||||
mod_entry_floating_view->set_width(width, Unit::Px);
|
||||
@@ -318,6 +336,7 @@ void ModMenu::mod_dragged(uint32_t mod_index, EventDrag drag) {
|
||||
for (size_t i = 0; i < mod_entry_buttons.size(); i++) {
|
||||
mod_entry_buttons[i]->set_mod_details(mod_details[i]);
|
||||
mod_entry_buttons[i]->set_mod_thumbnail(generate_thumbnail_src_for_mod(mod_details[i].mod_id));
|
||||
mod_entry_buttons[i]->set_mod_enabled(is_mod_enabled_or_auto(mod_details[i].mod_id));
|
||||
}
|
||||
|
||||
mod_entry_buttons[mod_drag_target_index]->set_selected(true);
|
||||
@@ -430,6 +449,7 @@ void ModMenu::create_mod_list() {
|
||||
mod_entry->set_mod_drag_callback(std::bind(&ModMenu::mod_dragged, this, std::placeholders::_1, std::placeholders::_2));
|
||||
mod_entry->set_mod_details(mod_details[mod_index]);
|
||||
mod_entry->set_mod_thumbnail(thumbnail_name);
|
||||
mod_entry->set_mod_enabled(is_mod_enabled_or_auto(mod_details[mod_index].mod_id));
|
||||
mod_entry_buttons.emplace_back(mod_entry);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user