#include "pause_screen.h" #include "entity_pickup.h" #include "entity_player.h" #include "fx_layers.h" #include "game.h" #include "hud.h" #include "kage_input.h" #include "log.h" #include "manager.h" #include "menu_manager.h" #include "platform.h" #include "room.h" #include constexpr const char* PAUSE_ANM2 = "gfx/ui/PauseScreen_small.anm2"; constexpr const char* MY_STUFF_ANM2 = "gfx/ui/PauseScreen_MyStuff.anm2"; constexpr const char* DIARY_ANM2 = "gfx/ui/Death Screen.anm2"; constexpr const char* CHARGE_ICONS_ANM2 = "gfx/ui/ui_charge_icons.anm2"; constexpr const char* ROOM_ICONS_ANM2 = "gfx/ui/minimap_icons.anm2"; constexpr const char* SECTION_CURSOR_PNG = "gfx/ui/MyStuff_SectionCursor.png"; constexpr const char* DESCRIPTION_FONT = "font/TeamMeatEx/TeamMeatEx12.fnt"; constexpr const char* ANIMATION_APPEAR = "Appear"; constexpr const char* ANIMATION_DISAPPEAR = "Dissapear"; constexpr const char* ANIMATION_CURSOR = "Cursor"; constexpr const char* ANIMATION_DIARY = "Diary"; constexpr const char* ANIMATION_CHARGE_ICON = "ChargeIcon"; constexpr const char* LAYER_CURSOR = "Cursor"; constexpr const char* LAYER_ITEMS = "Items"; constexpr const char* LAYER_BACK_KEY = "BackKey"; constexpr const char* LAYER_SEED_PAPER = "SeedPaper"; constexpr const char* LAYER_MENU_TITLE = "Menu Title"; constexpr const char* LAYER_BLOOD = "Blood"; constexpr const char* NULL_SEED = "Seed"; constexpr const char* NULL_COMPLETION_WIDGET = "CompletionWidget"; constexpr const char* START_SEED_UNSET = "Error: Game Start Seed was not set.\n"; // The layers only an online lobby shows. constexpr const char* LAYER_INVITE = "Invite"; constexpr const char* LAYER_KICK = "Kick"; constexpr const char* ONLINE_LAYERS[] = {LAYER_INVITE, LAYER_KICK, "InviteKey", "KickKey", "PasswordPaper", "ShowPassword", "ShowPasswordKey", "StuffArrow1", "StuffArrow2"}; constexpr const char* QUIT_DAILY_LINES[] = {"#QUIT_DAILY_RUN_1", "#QUIT_DAILY_RUN_2", "#QUIT_DAILY_RUN_3", "#QUIT_DAILY_RUN_4"}; constexpr float DESCRIPTION_LINE_SPACING = 0.9f; constexpr float PAPER_X = 0.7f; constexpr float PAPER_BOTTOM_MARGIN = 0.025f; constexpr float SEED_LINE_HEIGHT = 15; constexpr size_t SEED_HALF_LENGTH = 4; constexpr size_t SEED_SECOND_HALF = 5; constexpr uint32_t PAPER_TEXT_ARGB = 0xff362f2d; constexpr float SOUND_VOLUME = 0.7f; constexpr int SOUND_PAPER_IN = 17; constexpr int SOUND_PAPER_OUT = 18; constexpr float FADE_SPEED = 0.08f; constexpr int FADE_TARGET_MENU = 2; constexpr int KEYBOARD = 0; // Whether an action holds on one device, as KAGE's input manager asks. bool is_controller_action(int deviceId, ButtonAction action, ActionTest test) { std::shared_ptr device = KAGE::Input::manager.device_find(deviceId); if (!device || !device->isConnected) return false; const InputBindings& bindings = platform.bindings; const std::vector& table = device->type == KAGE::Input::DEVICE_KEYBOARD ? bindings.keyboard : bindings.controller; if (action >= (int)table.size()) return false; return std::ranges::any_of(table[action], [&](int button) { if (button == KAGE::Input::BUTTON_NONE) return false; return test == ACTION_TRIGGERED ? device->is_button_triggered(button) : device->is_button_pressed(button); }); } // Shows or hides a layer of a sprite, if it has one of that name. static void layer_show(ANM2& sprite, std::string_view name, bool isVisible) { if (LayerState* layer = sprite.GetLayer(name)) layer->isVisible = isVisible; } // Plays a pause screen sound at its volume, unless the seeds swap it for a fart. static void menu_sound_play(int sound) { SoundPlay play; play.volume = SOUND_VOLUME; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound, play); } // Fades the run out to the menus. static void game_fade_out() { Game& game = *g_game; KColor black = kcolor_argb(BLACK_ARGB); game.fadeSpeed = FADE_SPEED; game.fadeOutTarget = FADE_TARGET_MENU; game.fadeOutColor = kcolor_make(black._red, black._green, black._blue, game.fadeOutColor._alpha + FADE_SPEED); } // 008d2ca0 Resets the page and loads its font, sheet (idle, cursor hidden), diary, charge icons, room icons and // section cursor. void PauseScreen_MyStuff::Init() { reset(); descriptionText.load_font(DESCRIPTION_FONT); descriptionText.lineSpacing = DESCRIPTION_LINE_SPACING; pageSprite.Load(MY_STUFF_ANM2, GRAPHICS_LOAD); pageSprite.Play(ANIMATION_IDLE); layer_show(pageSprite, LAYER_CURSOR, false); diary_load(); chargeSprite.Load(CHARGE_ICONS_ANM2, GRAPHICS_LOAD); chargeSprite.Play(ANIMATION_CHARGE_ICON); iconsSprite.Load(ROOM_ICONS_ANM2, GRAPHICS_LOAD); sectionCursorImage = Manager::LoadImage(SECTION_CURSOR_PNG); } // Loads the diary the page sits on, showing only its items layer. void PauseScreen_MyStuff::diary_load() { diarySprite.Load(DIARY_ANM2, GRAPHICS_LOAD); diarySprite.Play(ANIMATION_DIARY); for (LayerState& layer : diarySprite.layerStates) layer.isVisible = false; layer_show(diarySprite, LAYER_ITEMS, true); } // 008d3250 Closes the page, hides its cursor and forgets the item images its descriptions loaded. // The item lists and selection it also clears belong to the page's update, not written yet. void PauseScreen_MyStuff::reset() { isOpen = false; if (pageSprite.isLoaded) layer_show(pageSprite, LAYER_CURSOR, false); if (descriptionText.icons) descriptionText.icons->images.clear(); } void PauseScreen_MyStuff::Update() { reconstruction_missing("PauseScreen_MyStuff::Update 008d3360 (with 008d3890, 008d4040, 008d42a0, 008d84f0)"); } void PauseScreen_MyStuff::Render() { reconstruction_missing("PauseScreen_MyStuff::Render 008d3640 (with render_entry 008d5990)"); } // 009b5840 Loads the options, My Stuff, the completion marks, the menu paper and the prompt, closed on Resume. void PauseScreen::Init() { menuOptions.Init({}, OPTIONS_PAUSE); myStuff.Init(); completionWidget.Load(COMPLETION_STYLE_PAUSE); state = PAUSE_HIDDEN; selectedElement = PAUSE_ITEM_RESUME; menuSprite.Load(PAUSE_ANM2, GRAPHICS_LOAD); genericPrompt.Initialize(PROMPT_SMALL); } // 009b7a20 Loads the paper, the prompt, the options sheet and My Stuff's diary again, as the graphics reload. void PauseScreen::load_graphics() { menuSprite.Load(PAUSE_ANM2, GRAPHICS_LOAD); genericPrompt.Initialize(PROMPT_SMALL); menuOptions.load_menu_anm2(); myStuff.diary_load(); } // Drops the sprites load_graphics loads. void PauseScreen::unload_graphics() { menuSprite.Reset(); genericPrompt.sprite.Reset(); genericPrompt.isOnlineVote = false; menuOptions.optionsSprite.Reset(); myStuff.diarySprite.Reset(); } // 00954690 Drops the pause screen's sprites while a run exists, as the mods reload. void pause_screen_unload_sprites() { if (g_game) g_game->pauseScreen.unload_graphics(); } // 00954710 Loads the pause screen's sprites (during a run), the button prompts, the fonts and the achievement popup // again. void graphics_reload() { Manager& manager = *g_manager; if (g_game) g_game->pauseScreen.load_graphics(); manager.popupButtons.load_graphics(); manager.load_fonts(); manager.achievementOverlay.load_graphics(); } // 009b7680 Opens the menu on Resume for the first player: the options set up for the pause screen, looping sounds // stopped, the paper appearing with the blood of hard mode and the player's completion marks. // The original also logs two profiling counters here, left out. void PauseScreen::Show() { menuOptions.Init({}, OPTIONS_PAUSE); playerIdx = 0; g_manager->sfxManager.StopLoopingSounds(); state = PAUSE_MENU; selectedElement = PAUSE_ITEM_RESUME; menuSprite.Play(ANIMATION_APPEAR, PLAY_FORCED); completionWidget.characterId = g_game->GetPlayer(playerIdx)->playerType; menu_sound_play(SOUND_PAPER_IN); layer_show(menuSprite, LAYER_INVITE, false); layer_show(menuSprite, LAYER_KICK, false); layer_show(menuSprite, LAYER_BLOOD, g_game->difficulty == DIFFICULTY_HARD); } // 009b7500 Plays the paper away while open, unless it already is. void PauseScreen::hide() { if (state == PAUSE_HIDDEN || menuSprite.GetAnimation() == ANIMATION_DISAPPEAR) return; menu_sound_play(SOUND_PAPER_OUT); menuSprite.Play(ANIMATION_DISAPPEAR); menuSprite.overlayAnimState.SetAnimationData(nullptr); } // 009b7650 Whether the screen is open and pauses the run, as it does offline. bool PauseScreen::is_pausing() { return state != PAUSE_HIDDEN; } // The paused player's controller. Netplay is offline, so it is always a local player's. int PauseScreen::controller_get() { return g_game->GetPlayer(playerIdx)->controllerIndex; } // 009b5d20 Steps the open page, opens the menu on pause (or back on the keyboard, while no emote menu is up), runs the // menu or leaves the options on back, then the prompt. A quit prompt played out answered yes ends the run. // Nothing happens while a blocking popup is up. void PauseScreen::Update() { if (g_manager->popupQueue.is_blocking()) return; if (state == PAUSE_OPTIONS) menuOptions.Update(); else if (state == PAUSE_MY_STUFF) { myStuff.Update(); if (!myStuff.isOpen) { state = PAUSE_MENU; return; } } int controller = controller_get(); if (state == PAUSE_HIDDEN) { bool isKeyboardBack = controller == KEYBOARD && g_game->emoteMenuState == 0 && is_controller_action(KEYBOARD, ACTION_MENU_BACK, ACTION_TRIGGERED); if (is_controller_action(controller, ACTION_PAUSE, ACTION_TRIGGERED) || isKeyboardBack) Show(); } else if (state == PAUSE_MENU) { if (is_controller_action(controller, ACTION_PAUSE, ACTION_TRIGGERED) || is_controller_action(controller, ACTION_MENU_BACK, ACTION_TRIGGERED)) { hide(); g_manager->isWindowFocused = true; return; } if (menu_update(controller)) return; } else if (state == PAUSE_OPTIONS && is_controller_action(controller, ACTION_MENU_BACK, ACTION_TRIGGERED)) state = PAUSE_MENU; genericPrompt.Update(PROMPT_INPUT_READ); bool isPromptStopped = !genericPrompt.sprite.animState.animData || !genericPrompt.sprite.animState.isPlaying; if (!isPromptStopped || state != PAUSE_QUIT_PROMPT) return; state = PAUSE_MENU; if (genericPrompt.submittedSelection == PROMPT_ANSWER_YES) reconstruction_missing("Game::End 006f9770"); } // Moves the cursor up and down the entries (wrapping) and confirms the one it is on. True once Resume is confirmed. bool PauseScreen::menu_update(int controller) { if (is_controller_action(controller, ACTION_MENU_UP, ACTION_TRIGGERED)) selectedElement = selectedElement == 0 ? PAUSE_ITEM_COUNT - 1 : selectedElement - 1; else if (is_controller_action(controller, ACTION_MENU_DOWN, ACTION_TRIGGERED)) selectedElement = selectedElement == PAUSE_ITEM_COUNT - 1 ? 0 : selectedElement + 1; menuSprite.SetOverlayFrame(selectedElement); if (!is_controller_action(controller, ACTION_MENU_CONFIRM, ACTION_TRIGGERED)) return false; if (selectedElement == PAUSE_ITEM_RESUME) { hide(); return true; } selection_confirm(controller); return false; } // Opens the options or My Stuff once the cursor shows, or quits: a daily run asks first, any other fades // out to the menus, forgetting the saved run when the first player is dead for good. void PauseScreen::selection_confirm(int controller) { bool isCursorShown = menuSprite.overlayAnimState.animData; switch (selectedElement) { case PAUSE_ITEM_OPTIONS: if (!isCursorShown) break; state = PAUSE_OPTIONS; menuOptions.reload(); break; case PAUSE_ITEM_MY_STUFF: if (!isCursorShown) break; state = PAUSE_MY_STUFF; myStuff.reset(); layer_show(myStuff.pageSprite, LAYER_BACK_KEY, controller == KEYBOARD); myStuff.isOpen = true; break; case PAUSE_ITEM_EXIT: { if (g_game->dailyChallenge._id != 0) { std::array lines; for (size_t i = 0; i < std::size(QUIT_DAILY_LINES); i++) lines[i] = string_table_translate(g_manager->stringTable, QUIT_DAILY_LINES[i]); genericPrompt.SetText(lines); genericPrompt.Show(PROMPT_LOCAL); state = PAUSE_QUIT_PROMPT; break; } menuSprite.overlayAnimState.SetAnimationData(nullptr); Entity_Player* player = g_game->GetPlayer(0); if (player->isDead && player->GetExtraLives() < 1) game_save_delete(); game_fade_out(); break; } default: break; } } // 009b6840 Each frame the screen is open outside a boss intro: cycles the items on the floor while a player holds // Glitched Crown, steps the completion marks, refreshes the HUD, plays the paper (idling with the cursor on the // selection once it appeared, closing once it disappeared) and hides the online lobby's layers. void PauseScreen::animation_update() { Game& game = *g_game; if (state == PAUSE_HIDDEN || (game.roomTransition.mode != 0 && game.roomTransition.bossIntroBossId != 0)) return; if (game.playerManager.FirstCollectibleOwner(COLLECTIBLE_GLITCHED_CROWN, LAZARUS_SHARE_CHECK)) { for (Entity* entity : game.room->entityList.updateEL) { if (entity->type == ENTITY_PICKUP && entity->variant == PICKUP_COLLECTIBLE) static_cast(entity)->update_cycle_collectible(0); } } completionWidget.Update(); game.hud.refresh_request(HUD_REFRESH_PLAYER); const AnimationState& animation = menuSprite.animState; bool isStopped = animation.animData && !animation.isPlaying; if (isStopped && menuSprite.GetAnimation() == ANIMATION_APPEAR) { menuSprite.Play(ANIMATION_IDLE); menuSprite.animState.isPlaying = false; menuSprite.SetOverlayAnimation(ANIMATION_CURSOR); menuSprite.SetOverlayFrame(selectedElement); } else if (isStopped && menuSprite.GetAnimation() == ANIMATION_DISAPPEAR) state = PAUSE_HIDDEN; for (const char* layer : ONLINE_LAYERS) layer_show(menuSprite, layer, false); menuSprite.Update(); } // 009b7190 Draws the open page outside a boss intro: the paper at the bottom right with its seed and completion marks // (outside the no HUD seed, once marks are earned, in a run that can unlock), the options or My Stuff, then the prompt. void PauseScreen::Render() { Game& game = *g_game; if (game.roomTransition.mode != 0 && game.roomTransition.bossIntroBossId != 0) return; layer_show(menuSprite, LAYER_MENU_TITLE, false); layer_show(menuSprite, LAYER_SEED_PAPER, game.dailyChallenge._id == 0); Vector position = vector_make(g_screenWidth * PAPER_X, g_screenHeight - g_screenHeight * PAPER_BOTTOM_MARGIN); switch (state) { case PAUSE_MENU: case PAUSE_QUIT_PROMPT: { menuSprite.Render({position}); render_seed_paper(position); Seeds& seeds = game.seedEffects; bool isMarksShown = !seeds.HasSeedEffect(SEED_NO_HUD) && completionWidget.markCount > 0 && !seeds.isCustomRun && !seeds.AchievementUnlocksDisallowed(); const NullFrame* widget = isMarksShown && menuSprite.animState.animData ? menuSprite.animState.GetNullFrame(NULL_COMPLETION_WIDGET) : nullptr; if (widget) completionWidget.Render(vector_add(position, widget->pos), widget->scale); break; } case PAUSE_OPTIONS: menuOptions.Render(); break; case PAUSE_MY_STUFF: myStuff.Render(); break; default: break; } genericPrompt.Render(); } // 009b8130 Shows the seed paper outside a daily run and writes the run's seed on it in two halves, a line apart. void PauseScreen::render_seed_paper(Vector position) { LayerState* paper = menuSprite.GetLayer(LAYER_SEED_PAPER); if (!paper) return; paper->isVisible = g_game->dailyChallenge._id == 0; const NullFrame* seed = paper->isVisible ? menuSprite.animState.GetNullFrame(NULL_SEED) : nullptr; if (!seed) return; Seeds& seeds = g_game->seedEffects; if (seeds.gameStartSeed == 0) KAGE_LogMessage(LOG_ASSERT, (uint8_t*)START_SEED_UNSET); std::string text = Seeds::Seed2String(seeds.gameStartSeed); std::string_view first = std::string_view(text).substr(0, SEED_HALF_LENGTH); std::string_view second = text.size() > SEED_SECOND_HALF ? std::string_view(text).substr(SEED_SECOND_HALF, SEED_HALF_LENGTH) : std::string_view(); Vector firstLine = vector_add(seed->pos, position); Vector secondLine = vector_make(firstLine.x, firstLine.y + SEED_LINE_HEIGHT); Font& font = g_manager->font2_TeamMeatEx12; FontSettings settings; font.DrawString(first, firstLine, vector_make(1, 1), kcolor_argb(PAPER_TEXT_ARGB), settings); font.DrawString(second, secondLine, vector_make(1, 1), kcolor_argb(PAPER_TEXT_ARGB), settings); }