Merge pull request #2 from inspectredc/star-select-enhancement

Star select enhancement
This commit is contained in:
Lywx
2023-10-11 09:06:21 -06:00
committed by GitHub
2 changed files with 45 additions and 11 deletions
+43 -11
View File
@@ -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];
@@ -52,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.
@@ -89,12 +99,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;
}
}
@@ -109,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++;
@@ -127,7 +143,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 +151,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 +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 != 6) {
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;
@@ -331,7 +363,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 +406,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--;
}
@@ -400,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;
+2
View File
@@ -402,6 +402,8 @@ 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");
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.");
UIWidgets::PaddedEnhancementCheckbox("Collecting Stars Will Not Exit Level", "gStarNoExit", true, false);
UIWidgets::Tooltip("Stars act like the 100 coin star and will not take you out of the level");
UIWidgets::PaddedEnhancementCheckbox("Avoid playing peach cutscene", "gDisablePeachCutscene", true, false);