From 9334770f858b2e0333ac9a01ec652a89f4df8cdf Mon Sep 17 00:00:00 2001 From: inspectredc Date: Thu, 5 Oct 2023 22:14:30 +0100 Subject: [PATCH 1/3] add star macros --- src/menu/star_select.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/menu/star_select.c b/src/menu/star_select.c index 97dcac14..98e71222 100644 --- a/src/menu/star_select.c +++ b/src/menu/star_select.c @@ -27,6 +27,12 @@ * strings, act values, and star selector model rendering if a star is collected or not. */ +// The number of stars in a level (excluding the 100 coin star) +#define LEVEL_STARS_MAX 6 + +// The index for the 100 coin star +#define COIN_STAR_INDEX 6 + // Star Selector count models printed in the act selector menu. static struct Object *sStarSelectorModels[8]; @@ -89,12 +95,12 @@ void bhv_act_selector_star_type_loop(void) { * Renders the 100 coin star with an special star selector type. */ void render_100_coin_star(u8 stars) { - if (stars & (1 << 6)) { + if (stars & (1 << COIN_STAR_INDEX)) { // If the 100 coin star has been collected, create a new star selector next to the coin score. - sStarSelectorModels[6] = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_STAR, + sStarSelectorModels[COIN_STAR_INDEX] = spawn_object_abs_with_rot(gCurrentObject, 0, MODEL_STAR, bhvActSelectorStarType, 370, 24, -300, 0, 0, 0); - sStarSelectorModels[6]->oStarSelectorSize = 0.8; - sStarSelectorModels[6]->oStarSelectorType = STAR_SELECTOR_100_COINS; + sStarSelectorModels[COIN_STAR_INDEX]->oStarSelectorSize = 0.8; + sStarSelectorModels[COIN_STAR_INDEX]->oStarSelectorType = STAR_SELECTOR_100_COINS; } } @@ -127,7 +133,7 @@ void bhv_act_selector_init(void) { } // If the stars have been collected in order so far, show the next star. - if (sVisibleStars == sObtainedStars && sVisibleStars != 6) { + if (sVisibleStars == sObtainedStars && sVisibleStars != LEVEL_STARS_MAX) { selectorModelIDs[sVisibleStars] = MODEL_TRANSPARENT_STAR; sInitSelectedActNum = sVisibleStars + 1; sSelectableStarIndex = sVisibleStars; @@ -135,7 +141,7 @@ void bhv_act_selector_init(void) { } // If all stars have been collected, set the default selection to the last star. - if (sObtainedStars == 6) { + if (sObtainedStars == LEVEL_STARS_MAX) { sInitSelectedActNum = sVisibleStars; } @@ -168,7 +174,7 @@ void bhv_act_selector_loop(void) { u8 starIndexCounter; u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); - if (sObtainedStars != 6) { + if (sObtainedStars != LEVEL_STARS_MAX) { // Sometimes, stars are not selectable even if they appear on the screen. // This code filters selectable and non-selectable stars. sSelectedActIndex = 0; @@ -331,7 +337,7 @@ void print_act_selector_strings(void) { gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 255); // Print the name of the selected act. if (sVisibleStars != 0) { - selectedActName = GameEngine_LoadActName(COURSE_NUM_TO_INDEX(gCurrCourseNum) * 6 + sSelectedActIndex); + selectedActName = GameEngine_LoadActName(COURSE_NUM_TO_INDEX(gCurrCourseNum) * LEVEL_STARS_MAX + sSelectedActIndex); actNameX = get_str_x_pos_from_center(ACT_NAME_X, selectedActName, 8.0f); print_menu_generic_string(actNameX, 81, selectedActName); } @@ -374,7 +380,7 @@ s32 lvl_init_act_selector_values_and_stars(UNUSED s32 arg, UNUSED s32 unused) { save_file_get_course_star_count(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); // Don't count 100 coin star - if (stars & (1 << 6)) { + if (stars & (1 << COIN_STAR_INDEX)) { sObtainedStars--; } From 72e762ccee5b79794304db9e53d34475d7f72ada Mon Sep 17 00:00:00 2001 From: inspectredc Date: Fri, 6 Oct 2023 10:33:42 +0100 Subject: [PATCH 2/3] star select enhancement --- src/menu/star_select.c | 32 +++++++++++++++++++++++++++++--- src/port/ui/ImguiUI.cpp | 5 +++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/menu/star_select.c b/src/menu/star_select.c index 98e71222..99f6361c 100644 --- a/src/menu/star_select.c +++ b/src/menu/star_select.c @@ -58,6 +58,10 @@ static s8 sSelectableStarIndex = 0; // Act Selector menu timer that keeps counting until you choose an act. static s32 sActSelectorMenuTimer = 0; +// Helper check for the previous star selection enhancment state +// This is used to tell if the star selection enhancment has just changed +static bool sStarSelectState = false; + /** * Act Selector Star Type Loop Action * Defines a select type for a star in the act selector. @@ -115,8 +119,14 @@ void bhv_act_selector_init(void) { s32 selectorModelIDs[10]; u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); + if (CVarGetInteger("gSelectAllStars", 0)) { + sStarSelectState = false; + } else { + sStarSelectState = true; + } + sVisibleStars = 0; - while (i != sObtainedStars) { + while (i != sObtainedStars || (CVarGetInteger("gSelectAllStars", 0) && sVisibleStars != LEVEL_STARS_MAX)) { if (stars & (1 << sVisibleStars)) { // Star has been collected selectorModelIDs[sVisibleStars] = MODEL_STAR; i++; @@ -174,7 +184,23 @@ void bhv_act_selector_loop(void) { u8 starIndexCounter; u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); - if (sObtainedStars != LEVEL_STARS_MAX) { + if (!sStarSelectState && !CVarGetInteger("gSelectAllStars", 0)) { + // If the option is toggled after stars have been drawn, then we want to set the star index to a valid index + starIndexCounter = 0; + for (i = 0; i <= sSelectableStarIndex; i++) { + // Can the star be selected (is it either already completed or the first non-completed mission) + if ((stars & (1 << i)) || i + 1 == sInitSelectedActNum) { + starIndexCounter++; + } + } + sSelectableStarIndex = starIndexCounter - 1; + sStarSelectState = true; + } else if (sStarSelectState && CVarGetInteger("gSelectAllStars", 0)) { + sSelectableStarIndex = sSelectedActIndex; + sStarSelectState = false; + } + + if (sObtainedStars != LEVEL_STARS_MAX && !CVarGetInteger("gSelectAllStars", 0)) { // Sometimes, stars are not selectable even if they appear on the screen. // This code filters selectable and non-selectable stars. sSelectedActIndex = 0; @@ -406,7 +432,7 @@ s32 lvl_update_obj_and_load_act_button_actions(UNUSED s32 arg, UNUSED s32 unused queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif - if (sInitSelectedActNum >= sSelectedActIndex + 1) { + if (sInitSelectedActNum >= sSelectedActIndex + 1 || CVarGetInteger("gSelectAllStars", 0)) { sLoadedActNum = sSelectedActIndex + 1; } else { sLoadedActNum = sInitSelectedActNum; diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index 3935e75e..fe782440 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -272,6 +272,11 @@ void DrawEnhancementsMenu() { UIWidgets::Tooltip("Disable Level of Detail (LOD) to avoid models using lower poly versions at a distance"); ImGui::EndMenu(); } + if (ImGui::BeginMenu("Quality of Life")) { + UIWidgets::PaddedEnhancementCheckbox("Select any star from menu", "gSelectAllStars", true, false); + UIWidgets::Tooltip("Let's you select any star from the menu regardless of the courses completion status."); + ImGui::EndMenu(); + } ImGui::EndMenu(); } From c2f827a6ac958dd7e79c29abdeff747f9e1244b3 Mon Sep 17 00:00:00 2001 From: inspectredc Date: Fri, 6 Oct 2023 11:13:35 +0100 Subject: [PATCH 3/3] move enhancement back into gameplay --- src/port/ui/ImguiUI.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/port/ui/ImguiUI.cpp b/src/port/ui/ImguiUI.cpp index fe782440..f8b97f93 100644 --- a/src/port/ui/ImguiUI.cpp +++ b/src/port/ui/ImguiUI.cpp @@ -270,9 +270,6 @@ void DrawEnhancementsMenu() { if (ImGui::BeginMenu("Gameplay")) { UIWidgets::PaddedEnhancementCheckbox("No Level of Detail (LOD)", "gDisableLOD", true, false); UIWidgets::Tooltip("Disable Level of Detail (LOD) to avoid models using lower poly versions at a distance"); - ImGui::EndMenu(); - } - if (ImGui::BeginMenu("Quality of Life")) { UIWidgets::PaddedEnhancementCheckbox("Select any star from menu", "gSelectAllStars", true, false); UIWidgets::Tooltip("Let's you select any star from the menu regardless of the courses completion status."); ImGui::EndMenu();