#include "menu_cutscenes.h" #include "manager.h" #include "menu_manager.h" #include constexpr const char* CUTSCENES_ANM2 = "gfx/ui/main menu/EndingsMenu.anm2"; constexpr ColorMod UNSEEN_COLOR = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {0, 0, 0}}; constexpr int CURSOR_LAYER = 25; constexpr int CUTSCENE_SLOTS = 24; constexpr int CUTSCENE_ROWS = 6; constexpr int SOUND_DELAY = 2; // A slot of the page: the sprite layer drawing it and the cutscene it plays. struct CutsceneSlot { int layer; int cutscene; }; // A held direction and how far it moves the cursor around the page. struct CursorMove { ButtonAction action; int step; }; // (008cec30) The slots in cursor order, down each column of six. The layer to cutscene switch is folded in. constexpr CutsceneSlot CUTSCENE_PAGE[CUTSCENE_SLOTS] = {{7, 3}, {8, 4}, {9, 5}, {10, 6}, {11, 7}, {12, 8}, {13, 9}, {14, 10}, {15, 11}, {16, 12}, {17, 13}, {18, 14}, {19, 15}, {20, 16}, {21, 17}, {22, 18}, {23, 19}, {28, 20}, {29, 21}, {30, 23}, {31, 22}, {32, 24}, {33, 26}, {24, 2}}; // Up and down step through a column, left and right jump a column, all wrapping around the page. constexpr CursorMove CURSOR_MOVES[] = {{ACTION_MENU_UP, CUTSCENE_SLOTS - 1}, {ACTION_MENU_DOWN, 1}, {ACTION_MENU_LEFT, CUTSCENE_SLOTS - CUTSCENE_ROWS}, {ACTION_MENU_RIGHT, CUTSCENE_ROWS}}; // Whether the player saw a cutscene, which makes it playable here. static bool is_cutscene_seen(int cutscene) { return g_manager->persistentGameData.cutsceneCounters[cutscene] >= 1; } // Loads the menu and resets it, at its place on the menu sheet. Inlined in MenuManager::Init. void Menu_Cutscenes::Init(Vector menuPosition) { cutscenesMenuSprite.Load(CUTSCENES_ANM2, GRAPHICS_LOAD); reset(); position = menuPosition; } // Loads the menu again, playing. Inlined in MenuManager::LoadGraphics. void Menu_Cutscenes::LoadGraphics() { cutscenesMenuSprite.Load(CUTSCENES_ANM2, GRAPHICS_LOAD); cutscenesMenuSprite.Play(ANIMATION_IDLE); } // 008cf480 Plays the menu with the cursor on the first cutscene. void Menu_Cutscenes::reset() { cutscenesMenuSprite.Play(ANIMATION_IDLE); holdInputTimer = 0; selectedElement = 0; } // 008ced40 Steps the menu every other frame. Confirm plays the selected cutscene, or buzzes for one not seen yet, and // back leaves. A held direction moves the cursor, repeating, and the cursor layer follows. void Menu_Cutscenes::Update() { const CutsceneSlot& slot = CUTSCENE_PAGE[selectedElement]; const CursorMove* move = std::ranges::find_if(CURSOR_MOVES, [](const CursorMove& m) { return is_action(m.action, ACTION_PRESSED); }); bool isMoving = move != std::end(CURSOR_MOVES); if ((g_manager->framecount & 1) == 0) cutscenesMenuSprite.Update(); if (is_action(ACTION_MENU_CONFIRM, ACTION_TRIGGERED)) { if (is_cutscene_seen(slot.cutscene)) g_manager->ShowCutscene(slot.cutscene, CUTSCENE_KEEP_STATE, MENU_TITLE); else menu_sound_play(SOUND_ERROR_BUZZ, SOUND_DELAY); } else if (is_action(ACTION_MENU_BACK, ACTION_TRIGGERED)) g_menuManager->pop_menu(); else if (isMoving && is_key_repeat(holdInputTimer)) selectedElement = (selectedElement + move->step) % CUTSCENE_SLOTS; holdInputTimer = isMoving ? holdInputTimer + 1 : 0; cutscenesMenuSprite.SetLayerFrame(CURSOR_LAYER, selectedElement); } // 008cf0e0 Draws the menu without its cutscenes, then each cutscene's layer over it, faded until it is seen. void Menu_Cutscenes::Render() { SpriteDraw draw = g_menuManager->menu_draw_get(position); for (const CutsceneSlot& slot : CUTSCENE_PAGE) cutscenesMenuSprite.GetLayer(slot.layer)->isVisible = false; cutscenesMenuSprite.Render(draw); for (const CutsceneSlot& slot : CUTSCENE_PAGE) { cutscenesMenuSprite.color = is_cutscene_seen(slot.cutscene) ? COLOR_DEFAULT : UNSEEN_COLOR; cutscenesMenuSprite.GetLayer(slot.layer)->isVisible = true; cutscenesMenuSprite.RenderLayer(slot.layer, draw); } cutscenesMenuSprite.color = COLOR_DEFAULT; }