diff --git a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c index 9e853c9c08..39cd7419ce 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_kaleido_collect.c @@ -2,6 +2,8 @@ #include "assets/textures/parameter_static/parameter_static.h" #include "assets/textures/icon_item_static/icon_item_static.h" +#define SONG_MAX_LENGTH 8 + #if !PLATFORM_GC #define KALEIDO_COLOR_COLLECT_UNK_R 80 #define KALEIDO_COLOR_COLLECT_UNK_G 150 @@ -22,20 +24,21 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { // Shining medallions static s16 sMedallionsEnvColors[6 + 6][3] = { - // Target env color when sMedEnvShineState == 0 - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - { 0, 0, 0 }, - // Target env color when sMedEnvShineState == 2 - { 0, 60, 0 }, - { 90, 0, 0 }, - { 0, 40, 110 }, - { 80, 40, 0 }, - { 70, 0, 90 }, - { 90, 90, 0 }, + // Target env color when sMedallionsEnvShineState == 0 + { 0, 0, 0 }, // QUEST_MEDALLION_FOREST + { 0, 0, 0 }, // QUEST_MEDALLION_FIRE + { 0, 0, 0 }, // QUEST_MEDALLION_WATER + { 0, 0, 0 }, // QUEST_MEDALLION_SPIRIT + { 0, 0, 0 }, // QUEST_MEDALLION_SHADOW + { 0, 0, 0 }, // QUEST_MEDALLION_LIGHT + + // Target env color when sMedallionsEnvShineState == 2 + { 0, 60, 0 }, // QUEST_MEDALLION_FOREST + { 90, 0, 0 }, // QUEST_MEDALLION_FIRE + { 0, 40, 110 }, // QUEST_MEDALLION_WATER + { 80, 40, 0 }, // QUEST_MEDALLION_SPIRIT + { 70, 0, 90 }, // QUEST_MEDALLION_SHADOW + { 90, 90, 0 }, // QUEST_MEDALLION_LIGHT }; // Current (animated) env color for each medallion static s16 sMedallionsEnvRed[6] = { 255, 255, 255, 255, 255, 255 }; @@ -51,12 +54,11 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { static s16 sHpPrimTimer = 20; static s16 sHpPrimState = 0; - static s16 D_8082A11C = 0; - static s16 D_8082A120 = 0; - static u8 D_8082A124[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; - static void* D_8082A130[] = { + static s16 sPlayedSongBtnsNum = 0; + static s16 sPlaybackSongStartDelayTimer = 0; + static u8 sPlayedSongBtns[SONG_MAX_LENGTH] = { 0 }; + static s32 sUnused1 = 0; + static void* sOcarinaBtnTextures[] = { gOcarinaBtnIconATex, // OCARINA_BTN_A gOcarinaBtnIconCDownTex, // OCARINA_BTN_C_DOWN gOcarinaBtnIconCRightTex, // OCARINA_BTN_C_RIGHT @@ -66,29 +68,90 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { static u16 D_8082A144[] = { 0xFFCC, 0xFFCC, 0xFFCC, 0xFFCC, 0xFFCC, }; - static s16 D_8082A150[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - }; + static s16 sPlayedSongBtnsAlpha[SONG_MAX_LENGTH] = { 0 }; + static s32 sUnused2 = 0; static s16 sSongsPrimRed[] = { - 150, 255, 100, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 150, // QUEST_SONG_MINUET + 255, // QUEST_SONG_BOLERO + 100, // QUEST_SONG_SERENADE + 255, // QUEST_SONG_REQUIEM + 255, // QUEST_SONG_NOCTURNE + 255, // QUEST_SONG_PRELUDE + 255, // QUEST_SONG_LULLABY + 255, // QUEST_SONG_EPONA + 255, // QUEST_SONG_SARIA + 255, // QUEST_SONG_SUN + 255, // QUEST_SONG_TIME + 255, // QUEST_SONG_STORMS }; static s16 sSongsPrimGreen[] = { - 255, 80, 150, 160, 100, 240, 255, 255, 255, 255, 255, 255, + 255, // QUEST_SONG_MINUET + 80, // QUEST_SONG_BOLERO + 150, // QUEST_SONG_SERENADE + 160, // QUEST_SONG_REQUIEM + 100, // QUEST_SONG_NOCTURNE + 240, // QUEST_SONG_PRELUDE + 255, // QUEST_SONG_LULLABY + 255, // QUEST_SONG_EPONA + 255, // QUEST_SONG_SARIA + 255, // QUEST_SONG_SUN + 255, // QUEST_SONG_TIME + 255, // QUEST_SONG_STORMS }; static s16 sSongsPrimBlue[] = { - 100, 40, 255, 0, 255, 100, 255, 255, 255, 255, 255, 255, + 100, // QUEST_SONG_MINUET + 40, // QUEST_SONG_BOLERO + 255, // QUEST_SONG_SERENADE + 0, // QUEST_SONG_REQUIEM + 255, // QUEST_SONG_NOCTURNE + 100, // QUEST_SONG_PRELUDE + 255, // QUEST_SONG_LULLABY + 255, // QUEST_SONG_EPONA + 255, // QUEST_SONG_SARIA + 255, // QUEST_SONG_SUN + 255, // QUEST_SONG_TIME + 255, // QUEST_SONG_STORMS }; - static s8 D_8082A1AC[][4] = { - { 0x05, 0x01, 0x05, 0xFE }, { 0x00, 0x02, 0x02, 0xFE }, { 0xFF, 0x13, 0x03, 0x01 }, { 0x04, 0x02, 0x11, 0x02 }, - { 0x05, 0x03, 0x18, 0x05 }, { 0xFF, 0xFF, 0x04, 0x00 }, { 0x0C, 0xFF, 0xFD, 0x07 }, { 0x0D, 0xFF, 0x06, 0x08 }, - { 0x0E, 0xFF, 0x07, 0x09 }, { 0x0F, 0xFF, 0x08, 0x0A }, { 0x10, 0xFF, 0x09, 0x0B }, { 0x11, 0xFF, 0x0A, 0x12 }, - { 0x17, 0x06, 0xFD, 0x0D }, { 0x17, 0x07, 0x0C, 0x0E }, { 0x17, 0x08, 0x0D, 0x0F }, { 0x18, 0x09, 0x0E, 0x10 }, - { 0x18, 0x0A, 0x0F, 0x11 }, { 0x18, 0x0B, 0x10, 0x03 }, { 0x02, 0xFF, 0x0B, 0x13 }, { 0x02, 0xFF, 0x12, 0x14 }, - { 0x02, 0xFF, 0x13, 0xFE }, { 0xFF, 0x17, 0xFD, 0x16 }, { 0xFF, 0x17, 0x15, 0x18 }, { 0x15, 0x0C, 0xFD, 0x18 }, - { 0xFF, 0x10, 0x16, 0x04 }, { 0x00, 0x00, 0x00, 0x00 }, + enum { + /* -3 */ CURSOR_TO_LEFT = -3, // Cursor on the "scroll to left page" position + /* -2 */ CURSOR_TO_RIGHT, // Cursor on the "scroll to right page" position + /* -1 */ CURSOR_NONE // No position in that direction, cursor stays where it is }; + // Each {up, down, left, right} entry defines where the cursor can move next + static s8 sCursorPointLinks[][4] = { + /* QUEST_MEDALLION_FOREST */ + { QUEST_MEDALLION_LIGHT, QUEST_MEDALLION_FIRE, QUEST_MEDALLION_LIGHT, CURSOR_TO_RIGHT }, + /* QUEST_MEDALLION_FIRE */ + { QUEST_MEDALLION_FOREST, QUEST_MEDALLION_WATER, QUEST_MEDALLION_WATER, CURSOR_TO_RIGHT }, + /* QUEST_MEDALLION_WATER */ { CURSOR_NONE, QUEST_GORON_RUBY, QUEST_MEDALLION_SPIRIT, QUEST_MEDALLION_FIRE }, + /* QUEST_MEDALLION_SPIRIT */ + { QUEST_MEDALLION_SHADOW, QUEST_MEDALLION_WATER, QUEST_SONG_STORMS, QUEST_MEDALLION_WATER }, + /* QUEST_MEDALLION_SHADOW */ + { QUEST_MEDALLION_LIGHT, QUEST_MEDALLION_SPIRIT, QUEST_HEART_PIECE, QUEST_MEDALLION_LIGHT }, + /* QUEST_MEDALLION_LIGHT */ { CURSOR_NONE, CURSOR_NONE, QUEST_MEDALLION_SHADOW, QUEST_MEDALLION_FOREST }, + /* QUEST_SONG_MINUET */ { QUEST_SONG_LULLABY, CURSOR_NONE, CURSOR_TO_LEFT, QUEST_SONG_BOLERO }, + /* QUEST_SONG_BOLERO */ { QUEST_SONG_EPONA, CURSOR_NONE, QUEST_SONG_MINUET, QUEST_SONG_SERENADE }, + /* QUEST_SONG_SERENADE */ { QUEST_SONG_SARIA, CURSOR_NONE, QUEST_SONG_BOLERO, QUEST_SONG_REQUIEM }, + /* QUEST_SONG_REQUIEM */ { QUEST_SONG_SUN, CURSOR_NONE, QUEST_SONG_SERENADE, QUEST_SONG_NOCTURNE }, + /* QUEST_SONG_NOCTURNE */ { QUEST_SONG_TIME, CURSOR_NONE, QUEST_SONG_REQUIEM, QUEST_SONG_PRELUDE }, + /* QUEST_SONG_PRELUDE */ { QUEST_SONG_STORMS, CURSOR_NONE, QUEST_SONG_NOCTURNE, QUEST_KOKIRI_EMERALD }, + /* QUEST_SONG_LULLABY */ { QUEST_SKULL_TOKEN, QUEST_SONG_MINUET, CURSOR_TO_LEFT, QUEST_SONG_EPONA }, + /* QUEST_SONG_EPONA */ { QUEST_SKULL_TOKEN, QUEST_SONG_BOLERO, QUEST_SONG_LULLABY, QUEST_SONG_SARIA }, + /* QUEST_SONG_SARIA */ { QUEST_SKULL_TOKEN, QUEST_SONG_SERENADE, QUEST_SONG_EPONA, QUEST_SONG_SUN }, + /* QUEST_SONG_SUN */ { QUEST_HEART_PIECE, QUEST_SONG_REQUIEM, QUEST_SONG_SARIA, QUEST_SONG_TIME }, + /* QUEST_SONG_TIME */ { QUEST_HEART_PIECE, QUEST_SONG_NOCTURNE, QUEST_SONG_SUN, QUEST_SONG_STORMS }, + /* QUEST_SONG_STORMS */ { QUEST_HEART_PIECE, QUEST_SONG_PRELUDE, QUEST_SONG_TIME, QUEST_MEDALLION_SPIRIT }, + /* QUEST_KOKIRI_EMERALD */ { QUEST_MEDALLION_WATER, CURSOR_NONE, QUEST_SONG_PRELUDE, QUEST_GORON_RUBY }, + /* QUEST_GORON_RUBY */ { QUEST_MEDALLION_WATER, CURSOR_NONE, QUEST_KOKIRI_EMERALD, QUEST_ZORA_SAPPHIRE }, + /* QUEST_ZORA_SAPPHIRE */ { QUEST_MEDALLION_WATER, CURSOR_NONE, QUEST_GORON_RUBY, CURSOR_TO_RIGHT }, + /* QUEST_STONE_OF_AGONY */ { CURSOR_NONE, QUEST_SKULL_TOKEN, CURSOR_TO_LEFT, QUEST_GERUDOS_CARD }, + /* QUEST_GERUDOS_CARD */ { CURSOR_NONE, QUEST_SKULL_TOKEN, QUEST_STONE_OF_AGONY, QUEST_HEART_PIECE }, + /* QUEST_SKULL_TOKEN */ { QUEST_STONE_OF_AGONY, QUEST_SONG_LULLABY, CURSOR_TO_LEFT, QUEST_HEART_PIECE }, + /* QUEST_HEART_PIECE */ { CURSOR_NONE, QUEST_SONG_TIME, QUEST_GERUDOS_CARD, QUEST_MEDALLION_SHADOW }, + }; + static s32 sUnused3 = 0; PauseContext* pauseCtx = &play->pauseCtx; Input* input = &play->state.input[0]; @@ -96,11 +159,11 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { s16 stepGreen; s16 stepBlue; s16 stepAlpha; - s16 phi_s0; - s16 phi_s3; + s16 nextCursorPoint; + s16 prevCursorPoint; s16 bufI; s16 j; - s16 sp216; + s16 cursor; s16 i; s16 targetColorIndex; s16 pad2; @@ -112,80 +175,93 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { if ((((u32)pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE) || (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PROMPT) || (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG)) && (pauseCtx->pageIndex == PAUSE_QUEST)) { + pauseCtx->cursorColorSet = 0; if (pauseCtx->cursorSpecialPos == 0) { pauseCtx->nameColorSet = 0; if ((pauseCtx->state != PAUSE_STATE_MAIN) || ((pauseCtx->stickAdjX == 0) && (pauseCtx->stickAdjY == 0))) { - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; + // No cursor movement + cursor = pauseCtx->cursorSlot[PAUSE_QUEST]; } else { - phi_s3 = pauseCtx->cursorPoint[PAUSE_QUEST]; + // Move cursor based on stick input + + prevCursorPoint = pauseCtx->cursorPoint[PAUSE_QUEST]; if (pauseCtx->stickAdjX < -30) { - phi_s0 = D_8082A1AC[phi_s3][2]; - if (phi_s0 == -3) { + // Move cursor left + nextCursorPoint = sCursorPointLinks[prevCursorPoint][2]; + if (nextCursorPoint == CURSOR_TO_LEFT) { KaleidoScope_MoveCursorToSpecialPos(play, PAUSE_CURSOR_PAGE_LEFT); pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE; } else { - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + while (nextCursorPoint >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, nextCursorPoint)) { break; } - phi_s0 = D_8082A1AC[phi_s0][2]; + nextCursorPoint = sCursorPointLinks[nextCursorPoint][2]; } } } else if (pauseCtx->stickAdjX > 30) { - phi_s0 = D_8082A1AC[phi_s3][3]; - if (phi_s0 == -2) { + // Move cursor right + nextCursorPoint = sCursorPointLinks[prevCursorPoint][3]; + if (nextCursorPoint == CURSOR_TO_RIGHT) { KaleidoScope_MoveCursorToSpecialPos(play, PAUSE_CURSOR_PAGE_RIGHT); pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE; } else { - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + while (nextCursorPoint >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, nextCursorPoint)) { break; } - phi_s0 = D_8082A1AC[phi_s0][3]; + nextCursorPoint = sCursorPointLinks[nextCursorPoint][3]; } } } if (pauseCtx->stickAdjY < -30) { - phi_s0 = D_8082A1AC[phi_s3][1]; - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + // Move cursor down + nextCursorPoint = sCursorPointLinks[prevCursorPoint][1]; + while (nextCursorPoint >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, nextCursorPoint)) { break; } - phi_s0 = D_8082A1AC[phi_s0][1]; + nextCursorPoint = sCursorPointLinks[nextCursorPoint][1]; } } else if (pauseCtx->stickAdjY > 30) { - phi_s0 = D_8082A1AC[phi_s3][0]; - while (phi_s0 >= 0) { - if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, phi_s0) != 0) { + // Move cursor up + nextCursorPoint = sCursorPointLinks[prevCursorPoint][0]; + while (nextCursorPoint >= 0) { + if ((s16)KaleidoScope_UpdateQuestStatusPoint(pauseCtx, nextCursorPoint)) { break; } - phi_s0 = D_8082A1AC[phi_s0][0]; + nextCursorPoint = sCursorPointLinks[nextCursorPoint][0]; } } - if (phi_s3 != pauseCtx->cursorPoint[PAUSE_QUEST]) { + // if the cursor point changed + if (pauseCtx->cursorPoint[PAUSE_QUEST] != prevCursorPoint) { pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE; Audio_PlaySfxGeneral(NA_SE_SY_CURSOR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } - if (pauseCtx->cursorPoint[PAUSE_QUEST] != 0x18) { + // Update cursor item and slot + + if (pauseCtx->cursorPoint[PAUSE_QUEST] != QUEST_HEART_PIECE) { if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { - if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) { - cursorItem = ITEM_MEDALLION_FOREST + pauseCtx->cursorPoint[PAUSE_QUEST]; + if (pauseCtx->cursorPoint[PAUSE_QUEST] < QUEST_SONG_MINUET) { + cursorItem = + ITEM_MEDALLION_FOREST - QUEST_MEDALLION_FOREST + pauseCtx->cursorPoint[PAUSE_QUEST]; PRINTF("000 ccc=%d\n", cursorItem); - } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0x12) { - cursorItem = ITEM_SCALE_GOLDEN + pauseCtx->cursorPoint[PAUSE_QUEST]; + } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < QUEST_KOKIRI_EMERALD) { + cursorItem = ITEM_SONG_MINUET - QUEST_SONG_MINUET + pauseCtx->cursorPoint[PAUSE_QUEST]; PRINTF("111 ccc=%d\n", cursorItem); } else { - cursorItem = ITEM_SONG_MINUET + pauseCtx->cursorPoint[PAUSE_QUEST]; - PRINTF("222 ccc=%d (%d, %d, %d)\n", cursorItem, pauseCtx->cursorPoint[PAUSE_QUEST], 0x12, - 0x6C); + cursorItem = + ITEM_KOKIRI_EMERALD - QUEST_KOKIRI_EMERALD + pauseCtx->cursorPoint[PAUSE_QUEST]; + PRINTF("222 ccc=%d (%d, %d, %d)\n", cursorItem, pauseCtx->cursorPoint[PAUSE_QUEST], + QUEST_KOKIRI_EMERALD, ITEM_KOKIRI_EMERALD); } } else { cursorItem = PAUSE_ITEM_NONE; @@ -201,128 +277,161 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { ITEM_HEART_CONTAINER, gSaveContext.save.info.inventory.questItems & 0xF0000000); } - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; + cursor = pauseCtx->cursorPoint[PAUSE_QUEST]; pauseCtx->cursorItem[pauseCtx->pageIndex] = cursorItem; - pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; + pauseCtx->cursorSlot[pauseCtx->pageIndex] = cursor; } - KaleidoScope_SetCursorPos(pauseCtx, sp216 * 4, pauseCtx->questVtx); + // Use the appropriate QUEST_MEDALLION_FOREST-QUEST_HEART_PIECE quad (see `KaleidoScope_SetVertices`) + KaleidoScope_SetCursorPos(pauseCtx, cursor * 4, pauseCtx->questVtx); + + // Handle part of the ocarina songs playback if ((pauseCtx->state == PAUSE_STATE_MAIN) && (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE) && (pauseCtx->cursorSpecialPos == 0)) { - if ((sp216 >= QUEST_SONG_MINUET) && (sp216 < QUEST_KOKIRI_EMERALD)) { + if ((cursor >= QUEST_SONG_MINUET) && (cursor < QUEST_KOKIRI_EMERALD)) { if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; - pauseCtx->ocarinaSongIdx = gOcarinaSongItemMap[sp216 - QUEST_SONG_MINUET]; - D_8082A120 = 10; + // The cursor is on a learned song + // Set some things up for song playback - for (i = 0; i < 8; i++) { - D_8082A124[i] = 0xFF; - D_8082A150[i] = 0; + cursor = pauseCtx->cursorSlot[PAUSE_QUEST]; + pauseCtx->ocarinaSongIdx = gOcarinaSongItemMap[cursor - QUEST_SONG_MINUET]; + sPlaybackSongStartDelayTimer = 10; + + for (i = 0; i < SONG_MAX_LENGTH; i++) { + sPlayedSongBtns[i] = OCARINA_BTN_INVALID; + sPlayedSongBtnsAlpha[i] = 0; } + sPlayedSongBtnsNum = 0; - D_8082A11C = 0; + // Have the player play a song, immediately cancelled below + // Also clear the playback staff + // This has no purpose (?) AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); AudioOcarina_Start((1 << pauseCtx->ocarinaSongIdx) + 0x8000); pauseCtx->ocarinaStaff = AudioOcarina_GetPlaybackStaff(); pauseCtx->ocarinaStaff->pos = 0; pauseCtx->ocarinaStaff->state = 0xFF; - VREG(21) = -62; - VREG(22) = -56; - VREG(23) = -49; - VREG(24) = -46; - VREG(25) = -41; + + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_A) = -62; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_DOWN) = -56; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_RIGHT) = -49; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_LEFT) = -46; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_UP) = -41; + pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG; + + // Stop having the player play a song as done above AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_OFF); } } } else if (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PROMPT) { + // Abort having the player play the song if the stick is moved if ((pauseCtx->stickAdjX != 0) || (pauseCtx->stickAdjY != 0)) { pauseCtx->mainState = PAUSE_MAIN_STATE_IDLE; + AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_OFF); } } else if (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG) { - if (CHECK_BTN_ALL(input->press.button, BTN_A) && (sp216 >= QUEST_SONG_MINUET) && - (sp216 < QUEST_KOKIRI_EMERALD)) { + if (CHECK_BTN_ALL(input->press.button, BTN_A) && (cursor >= QUEST_SONG_MINUET) && + (cursor < QUEST_KOKIRI_EMERALD)) { + pauseCtx->mainState = PAUSE_MAIN_STATE_SONG_PLAYBACK_START; - D_8082A120 = 10; + + sPlaybackSongStartDelayTimer = 10; } } } else if (pauseCtx->cursorSpecialPos == PAUSE_CURSOR_PAGE_LEFT) { if (pauseCtx->stickAdjX > 30) { - pauseCtx->cursorPoint[PAUSE_QUEST] = 0x15; + // Move cursor right from the "scroll to left page" position + + pauseCtx->cursorPoint[PAUSE_QUEST] = QUEST_STONE_OF_AGONY; pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; - KaleidoScope_SetCursorPos(pauseCtx, sp216 * 4, pauseCtx->questVtx); + + cursor = pauseCtx->cursorPoint[PAUSE_QUEST]; + KaleidoScope_SetCursorPos(pauseCtx, cursor * 4, pauseCtx->questVtx); Audio_PlaySfxGeneral(NA_SE_SY_CURSOR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); + if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { - cursorItem = ITEM_SONG_MINUET + pauseCtx->cursorPoint[PAUSE_QUEST]; + cursorItem = ITEM_STONE_OF_AGONY - QUEST_STONE_OF_AGONY + pauseCtx->cursorPoint[PAUSE_QUEST]; } else { cursorItem = PAUSE_ITEM_NONE; } - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; + cursor = pauseCtx->cursorPoint[PAUSE_QUEST]; pauseCtx->cursorItem[pauseCtx->pageIndex] = cursorItem; - pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; + pauseCtx->cursorSlot[pauseCtx->pageIndex] = cursor; } - } else { + } else { // cursorSpecialPos == PAUSE_CURSOR_PAGE_RIGHT if (pauseCtx->stickAdjX < -30) { - pauseCtx->cursorPoint[PAUSE_QUEST] = 0; + // Move cursor left from the "scroll to right page" position + + pauseCtx->cursorPoint[PAUSE_QUEST] = QUEST_MEDALLION_FOREST; pauseCtx->nameDisplayTimer = 0; pauseCtx->cursorSpecialPos = 0; - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; - KaleidoScope_SetCursorPos(pauseCtx, sp216 * 4, pauseCtx->questVtx); + + cursor = pauseCtx->cursorPoint[PAUSE_QUEST]; + KaleidoScope_SetCursorPos(pauseCtx, cursor * 4, pauseCtx->questVtx); Audio_PlaySfxGeneral(NA_SE_SY_CURSOR, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); + if (CHECK_QUEST_ITEM(pauseCtx->cursorPoint[PAUSE_QUEST])) { - if (pauseCtx->cursorPoint[PAUSE_QUEST] < 6) { - cursorItem = ITEM_MEDALLION_FOREST + pauseCtx->cursorPoint[PAUSE_QUEST]; - } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < 0xC) { - cursorItem = ITEM_BOMB_BAG_30 + pauseCtx->cursorPoint[PAUSE_QUEST]; + // Only the first if may be reached, as QUEST_MEDALLION_FOREST is set above + if (pauseCtx->cursorPoint[PAUSE_QUEST] < QUEST_SONG_MINUET) { + cursorItem = + ITEM_MEDALLION_FOREST - QUEST_MEDALLION_FOREST + pauseCtx->cursorPoint[PAUSE_QUEST]; + } else if (pauseCtx->cursorPoint[PAUSE_QUEST] < QUEST_SONG_LULLABY) { + //! @bug this would result in the wrong item + cursorItem = ITEM_SCALE_GOLDEN - QUEST_SONG_MINUET + pauseCtx->cursorPoint[PAUSE_QUEST]; } else { - cursorItem = ITEM_MEDALLION_SPIRIT + pauseCtx->cursorPoint[PAUSE_QUEST]; + //! @bug this would result in the wrong item + cursorItem = ITEM_DUNGEON_COMPASS - QUEST_SONG_LULLABY + pauseCtx->cursorPoint[PAUSE_QUEST]; } } else { cursorItem = PAUSE_ITEM_NONE; } - sp216 = pauseCtx->cursorPoint[PAUSE_QUEST]; + cursor = pauseCtx->cursorPoint[PAUSE_QUEST]; pauseCtx->cursorItem[pauseCtx->pageIndex] = cursorItem; - pauseCtx->cursorSlot[pauseCtx->pageIndex] = sp216; + pauseCtx->cursorSlot[pauseCtx->pageIndex] = cursor; } } + } else if (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PLAYBACK_START) { + // After a short delay, start playing the selected song back to the player + + pauseCtx->cursorColorSet = 8; + + if (--sPlaybackSongStartDelayTimer == 0) { + for (i = 0; i < SONG_MAX_LENGTH; i++) { + sPlayedSongBtns[i] = OCARINA_BTN_INVALID; + sPlayedSongBtnsAlpha[i] = 0; + } + sPlayedSongBtnsNum = 0; + + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_A) = -62; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_DOWN) = -56; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_RIGHT) = -49; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_LEFT) = -46; + R_PAUSE_SONG_OCA_BTN_Y(OCARINA_BTN_C_UP) = -41; + + cursor = pauseCtx->cursorSlot[PAUSE_QUEST]; + AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); + AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); + pauseCtx->ocarinaSongIdx = gOcarinaSongItemMap[cursor - QUEST_SONG_MINUET]; + AudioOcarina_SetPlaybackSong(pauseCtx->ocarinaSongIdx + 1, 1); + + pauseCtx->mainState = PAUSE_MAIN_STATE_SONG_PLAYBACK; + + pauseCtx->ocarinaStaff = AudioOcarina_GetPlaybackStaff(); + pauseCtx->ocarinaStaff->pos = 0; + + cursor = pauseCtx->cursorSlot[PAUSE_QUEST]; + KaleidoScope_SetCursorPos(pauseCtx, cursor * 4, pauseCtx->questVtx); + } } else { - if (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PLAYBACK_START) { - pauseCtx->cursorColorSet = 8; - - if (--D_8082A120 == 0) { - for (i = 0; i < 8; i++) { - D_8082A124[i] = 0xFF; - D_8082A150[i] = 0; - } - - D_8082A11C = 0; - VREG(21) = -62; - VREG(22) = -56; - VREG(23) = -49; - VREG(24) = -46; - VREG(25) = -41; - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; - AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); - AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); - pauseCtx->ocarinaSongIdx = gOcarinaSongItemMap[sp216 - QUEST_SONG_MINUET]; - AudioOcarina_SetPlaybackSong(pauseCtx->ocarinaSongIdx + 1, 1); - pauseCtx->mainState = PAUSE_MAIN_STATE_SONG_PLAYBACK; - pauseCtx->ocarinaStaff = AudioOcarina_GetPlaybackStaff(); - pauseCtx->ocarinaStaff->pos = 0; - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; - KaleidoScope_SetCursorPos(pauseCtx, sp216 * 4, pauseCtx->questVtx); - } - } else { - sp216 = pauseCtx->cursorSlot[PAUSE_QUEST]; - KaleidoScope_SetCursorPos(pauseCtx, sp216 * 4, pauseCtx->questVtx); - } + cursor = pauseCtx->cursorSlot[PAUSE_QUEST]; + KaleidoScope_SetCursorPos(pauseCtx, cursor * 4, pauseCtx->questVtx); } // Draw medallions @@ -335,7 +444,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { sMedallionsEnvTimer--; - for (j = 0, bufI = 0; j < 6; j++, bufI += 4) { + for (j = 0, bufI = QUEST_MEDALLION_FOREST * 4; j < QUEST_SONG_MINUET - QUEST_MEDALLION_FOREST; j++, bufI += 4) { if ((sMedallionsEnvShineState != 1) && (sMedallionsEnvShineState != 3)) { targetColorIndex = (sMedallionsEnvShineState != 0) ? j + 6 : j; @@ -396,7 +505,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { for (j = 0; j < QUEST_KOKIRI_EMERALD - QUEST_SONG_MINUET; j++, bufI += 4) { if (CHECK_QUEST_ITEM(QUEST_SONG_MINUET + j)) { - if ((QUEST_SONG_MINUET + j) == sp216) { + if ((QUEST_SONG_MINUET + j) == cursor) { pauseCtx->questVtx[bufI + 0].v.ob[0] = pauseCtx->questVtx[bufI + 2].v.ob[0] = pauseCtx->questVtx[bufI + 0].v.ob[0] - 2; @@ -424,7 +533,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); - for (j = 0; j < 3; j++, bufI += 4) { + for (j = 0; j < QUEST_STONE_OF_AGONY - QUEST_KOKIRI_EMERALD; j++, bufI += 4) { if (CHECK_QUEST_ITEM(QUEST_KOKIRI_EMERALD + j)) { gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[bufI], 4, 0); KaleidoScope_DrawQuadTextureRGBA32(gfxCtx, gItemIcons[ITEM_KOKIRI_EMERALD + j], QUEST_ICON_WIDTH, @@ -437,7 +546,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { gDPPipeSync(POLY_OPA_DISP++); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); - for (j = 0; j < 3; j++, bufI += 4) { + for (j = 0; j < QUEST_HEART_PIECE - QUEST_STONE_OF_AGONY; j++, bufI += 4) { if (CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY + j)) { gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[bufI], 4, 0); gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); @@ -447,6 +556,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { } // Draw heart pieces + // QUEST_HEART_PIECE stepRed = ABS(sHpPrimRed - sHpPrimColors[sHpPrimState][0]) / sHpPrimTimer; stepGreen = ABS(sHpPrimGreen - sHpPrimColors[sHpPrimState][1]) / sHpPrimTimer; @@ -479,7 +589,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { sHpPrimBlue = sHpPrimColors[sHpPrimState][2]; sHpPrimAlpha = sHpPrimColors[sHpPrimState][3]; sHpPrimTimer = ZREG(24 + sHpPrimState); - if (++sHpPrimState >= 4) { + if (++sHpPrimState >= ARRAY_COUNT(sHpPrimColors)) { sHpPrimState = 0; } } @@ -510,18 +620,24 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { // if (pauseCtx->state == PAUSE_STATE_MAIN) { - bufI += 4; + bufI += (QUAD_QUEST_SONG_NOTE_A1 - QUEST_HEART_PIECE) * 4; gDPPipeSync(POLY_OPA_DISP++); gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); - if ((pauseCtx->cursorSpecialPos == 0) && (sp216 >= 6) && (sp216 < 0x12)) { - if ((pauseCtx->mainState < PAUSE_MAIN_STATE_3) || (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PROMPT) || + // Update cursor color + if ((pauseCtx->cursorSpecialPos == 0) && (cursor >= QUEST_SONG_MINUET) && (cursor < QUEST_KOKIRI_EMERALD)) { + if ((pauseCtx->mainState < PAUSE_MAIN_STATE_3) /* PAUSE_MAIN_STATE_IDLE, PAUSE_MAIN_STATE_SWITCHING_PAGE, + PAUSE_MAIN_STATE_SONG_PLAYBACK */ + || (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PROMPT) || (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG)) { if (pauseCtx->cursorItem[pauseCtx->pageIndex] != PAUSE_ITEM_NONE) { pauseCtx->cursorColorSet = 8; + // PAUSE_MAIN_STATE_SONG_PLAYBACK, PAUSE_MAIN_STATE_3, + // PAUSE_MAIN_STATE_SONG_PROMPT_INIT, PAUSE_MAIN_STATE_SONG_PROMPT, + // PAUSE_MAIN_STATE_SONG_PROMPT_DONE if ((pauseCtx->mainState >= PAUSE_MAIN_STATE_SONG_PLAYBACK) && - (pauseCtx->mainState < PAUSE_MAIN_STATE_EQUIP_CHANGED)) { + (pauseCtx->mainState <= PAUSE_MAIN_STATE_SONG_PROMPT_DONE)) { pauseCtx->cursorColorSet = 0; } } @@ -529,61 +645,72 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { } if (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PLAYBACK) { + // Draw ocarina buttons as the song playback progresses + // QUAD_QUEST_SONG_NOTE_A1 up to QUAD_QUEST_SONG_NOTE_A8 + pauseCtx->ocarinaStaff = AudioOcarina_GetPlaybackStaff(); if (pauseCtx->ocarinaStaff->pos != 0) { - if (D_8082A11C == (pauseCtx->ocarinaStaff->pos - 1)) { - D_8082A11C++; - D_8082A124[pauseCtx->ocarinaStaff->pos - 1] = pauseCtx->ocarinaStaff->buttonIndex; + if (sPlayedSongBtnsNum == (pauseCtx->ocarinaStaff->pos - 1)) { + sPlayedSongBtnsNum++; + sPlayedSongBtns[pauseCtx->ocarinaStaff->pos - 1] = pauseCtx->ocarinaStaff->buttonIndex; } - for (j = 0, i = 0; j < 8; j++, i += 4, bufI += 4) { - if (D_8082A124[j] == 0xFF) { + for (j = 0, i = 0; j < SONG_MAX_LENGTH; j++, i += 4, bufI += 4) { + if (sPlayedSongBtns[j] == OCARINA_BTN_INVALID) { break; } - if (D_8082A150[j] != 255) { - D_8082A150[j] += VREG(50); - if (D_8082A150[j] >= 255) { - D_8082A150[j] = 255; + if (sPlayedSongBtnsAlpha[j] != 255) { + sPlayedSongBtnsAlpha[j] += R_OCARINA_BUTTONS_APPEAR_ALPHA_STEP; + if (sPlayedSongBtnsAlpha[j] >= 255) { + sPlayedSongBtnsAlpha[j] = 255; } } pauseCtx->questVtx[bufI + 0].v.ob[1] = pauseCtx->questVtx[bufI + 1].v.ob[1] = - VREG(21 + D_8082A124[j]); + R_PAUSE_SONG_OCA_BTN_Y(sPlayedSongBtns[j]); pauseCtx->questVtx[bufI + 2].v.ob[1] = pauseCtx->questVtx[bufI + 3].v.ob[1] = pauseCtx->questVtx[bufI + 0].v.ob[1] - 12; gDPPipeSync(POLY_OPA_DISP++); - if (D_8082A124[j] == 0) { + if (sPlayedSongBtns[j] == OCARINA_BTN_A) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, KALEIDO_COLOR_COLLECT_UNK_R, KALEIDO_COLOR_COLLECT_UNK_G, - KALEIDO_COLOR_COLLECT_UNK_B, D_8082A150[j]); + KALEIDO_COLOR_COLLECT_UNK_B, sPlayedSongBtnsAlpha[j]); } else { - gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 50, D_8082A150[j]); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 50, sPlayedSongBtnsAlpha[j]); } gDPSetEnvColor(POLY_OPA_DISP++, 10, 10, 10, 0); gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[bufI], 4, 0); - gDPLoadTextureBlock(POLY_OPA_DISP++, D_8082A130[D_8082A124[j]], G_IM_FMT_IA, G_IM_SIZ_8b, 16, 16, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_OPA_DISP++, sOcarinaBtnTextures[sPlayedSongBtns[j]], G_IM_FMT_IA, + G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); } } } else if (((pauseCtx->mainState >= PAUSE_MAIN_STATE_SONG_PROMPT_INIT) && - (pauseCtx->mainState <= PAUSE_MAIN_STATE_SONG_PROMPT_DONE)) || + (pauseCtx->mainState <= PAUSE_MAIN_STATE_SONG_PROMPT_DONE) + /* PAUSE_MAIN_STATE_SONG_PROMPT_INIT, PAUSE_MAIN_STATE_SONG_PROMPT, + PAUSE_MAIN_STATE_SONG_PROMPT_DONE */ + ) || (pauseCtx->mainState == PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG)) { + // Draw the buttons for playing a song + // QUAD_QUEST_SONG_NOTE_A1 up to QUAD_QUEST_SONG_NOTE_A8 + // temps reused, fake? stepGreen = pauseCtx->ocarinaSongIdx; stepRed = gOcarinaSongButtons[stepGreen].numButtons; - for (j = bufI, i = 0; i < stepRed; i++, bufI += 4) { + j = bufI; + + for (i = 0; i < stepRed; i++, bufI += 4) { pauseCtx->questVtx[bufI + 0].v.ob[1] = pauseCtx->questVtx[bufI + 1].v.ob[1] = - VREG(21 + gOcarinaSongButtons[stepGreen].buttonsIndex[i]); + R_PAUSE_SONG_OCA_BTN_Y(gOcarinaSongButtons[stepGreen].buttonsIndex[i]); pauseCtx->questVtx[bufI + 2].v.ob[1] = pauseCtx->questVtx[bufI + 3].v.ob[1] = pauseCtx->questVtx[bufI + 0].v.ob[1] - 12; @@ -598,6 +725,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 50, 200); } } else { + // Gray out buttons during the player playing the song gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 150, 150, 150, 150); } @@ -605,78 +733,84 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[bufI], 4, 0); - gDPLoadTextureBlock(POLY_OPA_DISP++, D_8082A130[gOcarinaSongButtons[stepGreen].buttonsIndex[i]], - G_IM_FMT_IA, G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_OPA_DISP++, + sOcarinaBtnTextures[gOcarinaSongButtons[stepGreen].buttonsIndex[i]], G_IM_FMT_IA, + G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); } if (pauseCtx->mainState != PAUSE_MAIN_STATE_IDLE_CURSOR_ON_SONG) { + // Draw the buttons colored as the player plays the song + // QUAD_QUEST_SONG_NOTE_B1 up to QUAD_QUEST_SONG_NOTE_B8 + pauseCtx->ocarinaStaff = AudioOcarina_GetPlayingStaff(); if (pauseCtx->ocarinaStaff->pos != 0) { - if (D_8082A11C == (pauseCtx->ocarinaStaff->pos - 1)) { + if (sPlayedSongBtnsNum == (pauseCtx->ocarinaStaff->pos - 1)) { if ((pauseCtx->ocarinaStaff->buttonIndex >= OCARINA_BTN_A) && (pauseCtx->ocarinaStaff->buttonIndex <= OCARINA_BTN_C_UP)) { - D_8082A124[pauseCtx->ocarinaStaff->pos - 1] = pauseCtx->ocarinaStaff->buttonIndex; - D_8082A124[pauseCtx->ocarinaStaff->pos] = 0xFF; - D_8082A11C++; + sPlayedSongBtns[pauseCtx->ocarinaStaff->pos - 1] = pauseCtx->ocarinaStaff->buttonIndex; + sPlayedSongBtns[pauseCtx->ocarinaStaff->pos] = OCARINA_BTN_INVALID; + sPlayedSongBtnsNum++; } } } - bufI = j + 32; - i = 0; - for (; i < 8; i++, bufI += 4) { - if (D_8082A124[i] == 0xFF) { + bufI = j + ((QUAD_QUEST_SONG_NOTE_B1 - QUAD_QUEST_SONG_NOTE_A1) * 4); + + for (i = 0; i < SONG_MAX_LENGTH; i++, bufI += 4) { + if (sPlayedSongBtns[i] == OCARINA_BTN_INVALID) { continue; } - if (D_8082A150[i] != 255) { - D_8082A150[i] += VREG(50); - if (D_8082A150[i] >= 255) { - D_8082A150[i] = 255; + if (sPlayedSongBtnsAlpha[i] != 255) { + sPlayedSongBtnsAlpha[i] += R_OCARINA_BUTTONS_APPEAR_ALPHA_STEP; + if (sPlayedSongBtnsAlpha[i] >= 255) { + sPlayedSongBtnsAlpha[i] = 255; } } + pauseCtx->questVtx[bufI + 0].v.ob[1] = pauseCtx->questVtx[bufI + 1].v.ob[1] = - VREG(21 + D_8082A124[i]); + R_PAUSE_SONG_OCA_BTN_Y(sPlayedSongBtns[i]); pauseCtx->questVtx[bufI + 2].v.ob[1] = pauseCtx->questVtx[bufI + 3].v.ob[1] = pauseCtx->questVtx[bufI + 0].v.ob[1] - 12; gDPPipeSync(POLY_OPA_DISP++); - if (D_8082A124[i] == 0) { + if (sPlayedSongBtns[i] == OCARINA_BTN_A) { gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, KALEIDO_COLOR_COLLECT_UNK_R, KALEIDO_COLOR_COLLECT_UNK_G, - KALEIDO_COLOR_COLLECT_UNK_B, D_8082A150[i]); + KALEIDO_COLOR_COLLECT_UNK_B, sPlayedSongBtnsAlpha[i]); } else { - gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 50, D_8082A150[i]); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 50, sPlayedSongBtnsAlpha[i]); } gDPSetEnvColor(POLY_OPA_DISP++, 10, 10, 10, 0); gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[bufI], 4, 0); - gDPLoadTextureBlock(POLY_OPA_DISP++, D_8082A130[D_8082A124[i]], G_IM_FMT_IA, G_IM_SIZ_8b, 16, 16, 0, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock(POLY_OPA_DISP++, sOcarinaBtnTextures[sPlayedSongBtns[i]], G_IM_FMT_IA, + G_IM_SIZ_8b, 16, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); } if (pauseCtx->mainState == PAUSE_MAIN_STATE_SONG_PROMPT_INIT) { - for (i = 0; i < 8; i++) { - D_8082A124[i] = 0xFF; - D_8082A150[i] = 0; + for (i = 0; i < SONG_MAX_LENGTH; i++) { + sPlayedSongBtns[i] = OCARINA_BTN_INVALID; + sPlayedSongBtnsAlpha[i] = 0; } + sPlayedSongBtnsNum = 0; - D_8082A11C = 0; AudioOcarina_SetInstrument(OCARINA_INSTRUMENT_DEFAULT); AudioOcarina_Start((1 << pauseCtx->ocarinaSongIdx) + 0x8000); pauseCtx->ocarinaStaff = AudioOcarina_GetPlaybackStaff(); pauseCtx->ocarinaStaff->pos = 0; pauseCtx->ocarinaStaff->state = 0xFE; + pauseCtx->mainState = PAUSE_MAIN_STATE_SONG_PROMPT; } } @@ -684,6 +818,7 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { } // Draw amount of gold skulltula tokens + // QUAD_QUEST_SKULL_TOKENS_DIGIT1_SHADOW to QUAD_QUEST_SKULL_TOKENS_DIGIT3 if (CHECK_QUEST_ITEM(QUEST_SKULL_TOKEN)) { gDPPipeSync(POLY_OPA_DISP++); @@ -704,27 +839,33 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { gsTokenDigits[2] -= 10; } - gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[164], 24, 0); + gSPVertex(POLY_OPA_DISP++, &pauseCtx->questVtx[QUAD_QUEST_SKULL_TOKENS_DIGIT1_SHADOW * 4], 6 * 4, 0); for (i = 0, j = 0; i < 2; i++) { if (i == 0) { + // Text shadow gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, pauseCtx->alpha); - } else if (gSaveContext.save.info.inventory.gsTokens == 100) { - gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 200, 50, 50, pauseCtx->alpha); } else { - gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); + // Text color + if (gSaveContext.save.info.inventory.gsTokens == 100) { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 200, 50, 50, pauseCtx->alpha); + } else { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, pauseCtx->alpha); + } } - cursorItem = 0; + // Variable reused as a flag indicating all digits onwards should be displayed + cursorItem = false; + for (bufI = 0; bufI < 3; bufI++, j += 4) { - if ((bufI >= 2) || (gsTokenDigits[bufI] != 0) || (cursorItem != 0)) { + if ((bufI >= 2) || (gsTokenDigits[bufI] != 0) || cursorItem) { gDPLoadTextureBlock(POLY_OPA_DISP++, ((u8*)gCounterDigit0Tex + (8 * 16 * gsTokenDigits[bufI])), G_IM_FMT_I, G_IM_SIZ_8b, 8, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSP1Quadrangle(POLY_OPA_DISP++, j, j + 2, j + 3, j + 1, 0); - cursorItem = 1; + cursorItem = true; } } } @@ -736,5 +877,5 @@ void KaleidoScope_DrawQuestStatus(PlayState* play, GraphicsContext* gfxCtx) { s32 KaleidoScope_UpdateQuestStatusPoint(PauseContext* pauseCtx, s32 point) { pauseCtx->cursorPoint[PAUSE_QUEST] = point; - return 1; + return true; }