Files
isaac-port/src/menu_character.cpp
T

1259 lines
57 KiB
C++

#include "menu_character.h"
#include "game.h"
#include "kage_input.h"
#include "log.h"
#include "manager.h"
#include "menu_manager.h"
#include "texture_cache.h"
#include <SDL3/SDL_clipboard.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
// Each menu's sheets: its pages, its portraits, and the face its background shows.
struct MenuSheets
{
const char* page;
const char* portraits;
const char* face;
};
constexpr MenuSheets MENU_SHEETS[CHARACTER_MENU_COUNT] = {
{"gfx/ui/main menu/CharacterMenu.anm2", "gfx/ui/main menu/CharacterPortraits.anm2", "Face0"},
{"gfx/ui/main menu/CharacterMenuAlt.anm2", "gfx/ui/main menu/CharacterPortraitsAlt.anm2", "Face1"}};
constexpr const char* BACKGROUND_ANM2 = "gfx/ui/main menu/CharacterMenuBG.anm2";
constexpr const char* BACKGROUND_EXTRA_ANM2 = "gfx/ui/main menu/CharacterMenuBGExtra.anm2";
constexpr const char* PAGE_SWAP_ANM2 = "gfx/ui/main menu/PageSwapWidget.anm2";
constexpr const char* SEED_ENTRY_ANM2 = "gfx/ui/main menu/SeedEntry.anm2";
constexpr const char* DIFFICULTY_ANM2 = "gfx/ui/main menu/DifficultyWidget.anm2";
constexpr const char* SEED_WIDGET_ANM2 = "gfx/ui/main menu/SeedWidget.anm2";
constexpr const char* WIN_STREAK_ANM2 = "gfx/ui/main menu/WinStreakWidget.anm2";
constexpr const char* EASTER_EGG_ANM2 = "gfx/ui/main menu/SeedSelectionWidget.anm2";
constexpr const char* SEED_UNLOCK_ANM2 = "gfx/ui/main menu/SeedUnlockPaper.anm2";
constexpr const char* COMPLETION_ANM2 = "gfx/ui/completion_widget.anm2";
constexpr const char* COMPLETION_PAUSE_PNG = "gfx/ui/completion_widget_pause.png";
constexpr const char* PAGE_SNAPSHOT_NAME = "Character Paper";
constexpr const char* ANIMATION_ISAAC = "01_Isaac";
constexpr const char* ANIMATION_BLOOD_STAIN = "BloodStain";
constexpr const char* ANIMATION_GREED = "Greed";
constexpr const char* ANIMATION_NO_EGGS = "NoEggs";
constexpr const char* ANIMATION_EGGS = "Eggs";
constexpr const char* ANIMATION_GREEDIER_LOCKED = "Unlocked";
constexpr const char* ANIMATION_GREEDIER = "AB+";
constexpr const char* ANIMATION_APPEAR = "Appear";
constexpr const char* ANIMATION_DISAPPEAR = "Disappear";
constexpr const char* ANIMATION_UNLOCK_DISAPPEAR = "Dissappear";
constexpr const char* ANIMATION_SWAP_OUT = "SwapOut";
constexpr const char* ANIMATION_SWAP_IN = "SwapIn";
constexpr const char* ANIMATION_STREAK_GOOD = "Good";
constexpr const char* ANIMATION_STREAK_BAD = "Bad";
constexpr const char* EVENT_SOUND = "Sound";
constexpr const char* BUTTON_ICON_NULL = "ButtonIcon";
constexpr const char* EDEN_TOKENS_KEY = "#EDEN_TOKENS_COUNT";
constexpr const char* SEED_MENU_CATEGORY = "SeedMenu";
constexpr char STRING_KEY_PREFIX = '#';
// The wheel's characters, the game's then their tainted twins, as the exe's table at 00b24140 lists them.
constexpr Menu_Character_Entry CHARACTER_ENTRIES[CHARACTER_MENU_COUNT][CHARACTER_ENTRY_COUNT] = {
{{"00_Random", 0, false, {}},
{"01_Isaac", 0, false, {29, 0, 0}},
{"02_Magdalene", 1, false, {0, 332, 0}},
{"03_Cain", 2, false, {0, 245, 0}},
{"04_Judas", 3, false, {}},
{"06_Bluebaby", 4, true, {}},
{"05_Eve", 5, false, {0, 0, 248}},
{"07_Samson", 6, false, {0, 0, 334}},
{"08_Azazel", 7, false, {}},
{"09_Lazarus", 8, false, {0, 331, 0}},
{"10_Eden", 9, false, {}},
{"11_TheLost", 10, true, {250, 0, 0}},
{"12_Lilith", 13, false, {}},
{"13_Keeper", 14, true, {236, 237, 191}},
{"15_Apollyon", 15, false, {}},
{"16_TheForgotten", 16, true, {}},
{"17_Bethany", 18, false, {}},
{"18_JacobEsau", 19, false, {}}},
{{"00_Random", 21, false, {}},
{"01_Isaac", 21, false, {}},
{"02_Magdalene", 22, false, {}},
{"03_Cain", 23, false, {}},
{"04_Judas", 24, false, {}},
{"06_Bluebaby", 25, true, {}},
{"05_Eve", 26, false, {}},
{"07_Samson", 27, false, {}},
{"08_Azazel", 28, false, {}},
{"09_Lazarus", 29, false, {}},
{"10_Eden", 30, false, {}},
{"11_TheLost", 31, true, {}},
{"12_Lilith", 32, false, {}},
{"13_Keeper", 33, true, {}},
{"15_Apollyon", 34, false, {}},
{"16_TheForgotten", 35, true, {}},
{"17_Bethany", 36, false, {}},
{"18_JacobEsau", 37, false, {}}}};
// The page layers showing each of a character's three items, two each.
constexpr int ITEM_LAYERS[CHARACTER_ITEM_COUNT][2] = {{8, 7}, {13, 12}, {15, 14}};
// A completion mark: the completion type its counter is kept under, and the widget layer showing it.
struct CompletionMarkLayer
{
int completionType;
int layer;
};
constexpr int COMPLETION_MARK_COUNT = 12;
constexpr CompletionMarkLayer COMPLETION_MARK_LAYERS[COMPLETION_MARK_COUNT] = {
{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7, 8}, {9, 9}, {12, 0}, {13, 10}, {14, 11}};
constexpr uint32_t COMPLETION_PLAYER_TYPE_MAX = COMPLETION_PLAYER_TYPE_COUNT - 1;
constexpr int COMPLETION_TAINTED_MIN = 21;
constexpr int COMPLETION_TAINTED_FRAMES = 5;
constexpr int MARK_NORMAL = 1;
constexpr int MARK_HARD = 2;
constexpr int MARK_ONLINE_NORMAL = 4;
constexpr int MARK_ONLINE_HARD = 8;
constexpr int PLAYER_EDEN = 9;
constexpr int PLAYER_TAINTED_EDEN = 30;
constexpr int MENU_ID_RANDOM = 0;
constexpr int MENU_ID_EDEN = 10;
constexpr int EVENT_EDEN_TOKENS = 21;
constexpr int EVENT_STREAK_COUNTER = 22;
constexpr int EVENT_NEGATIVE_STREAK_COUNTER = 113;
constexpr int ACHIEVEMENT_GREEDIER = 341;
constexpr int SOUND_CHARACTER_SELECT_LEFT = 194;
constexpr int SOUND_CHARACTER_SELECT_RIGHT = 195;
constexpr int SOUND_MENU_FLIP_LIGHT = 569;
constexpr int SOUND_MENU_FLIP_DARK = 570;
constexpr int SOUND_MENU_RIP = 571;
constexpr int SOUND_DELAY = 2;
constexpr int KEYBOARD_DEVICE = 0;
constexpr int BACKGROUND_LAYER_BACK = 0;
constexpr int BACKGROUND_LAYER_FRONT = 1;
constexpr int BACKGROUND_LAYER_TOP = 2;
constexpr int BACKGROUND_LAYER_PAGE = 3;
constexpr int BACKGROUND_LAYER_EDGE = 4;
constexpr int PAGE_LAYER_LOCK = 3;
constexpr int PAGE_LAYER_DETAILS_FIRST = 4;
constexpr int PAGE_LAYER_DETAILS_END = 16;
constexpr int PAGE_LAYER_LOCKED = 16;
constexpr int SWAP_LAYER_GLYPH = 2;
constexpr int SEED_LAYER_HINT = 1;
constexpr int SEED_LAYER_KEY = 2;
constexpr int EGG_LAYER_NO_ACHIEVEMENTS = 3;
constexpr int EGG_LAYER_KEY = 4;
constexpr std::array<int, BLEND_PART_COUNT> BLEND_STAIN = {BLEND_EQUATION_ADD, BLEND_FACTOR_DST_COLOR,
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, BLEND_FACTOR_DST_COLOR,
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA};
constexpr float WHEEL_X = 240;
constexpr float WHEEL_Y = 135;
constexpr float WHEEL_RADIUS = 70;
constexpr float WHEEL_TILT = 0.4f;
constexpr float WHEEL_HEIGHT = 85;
constexpr float WHEEL_DEPTH_MIN = 2;
constexpr float WHEEL_DEPTH_GROWTH = 0.01f;
constexpr int WHEEL_CROWD = 10;
constexpr float WHEEL_WIDTH_SCALE = 1.3f;
constexpr float WHEEL_SPEED_SCALE = 50;
constexpr float FULL_TURN = 360;
constexpr float HALF_TURN = 180;
constexpr float QUARTER_TURN = 90;
constexpr float TAU = 6.2831855f;
constexpr float DEGREES_TO_RADIANS = 0.017453292f;
constexpr float SPIN_EASE_START = 60;
constexpr float SPIN_EASE_LENGTH = -60;
constexpr float SPIN_SLOWDOWN = 6;
constexpr float SPIN_FRAMES = 30;
constexpr int SPIN_TURNS = 3;
constexpr int INPUT_COOLDOWN = 10;
constexpr int SEED_TEXT_MAX = 9;
constexpr size_t SEED_HALF = 4;
constexpr int SEED_UNLOCK_FRAMES = 60;
constexpr float ALPHA_STEP = 0.05f;
constexpr float COLOR_MOD_RATE = 0.015f;
constexpr ColorModState COLOR_MOD_TAINTED = {1, 1.03f, 1.1f, 0.3f, -0.15f, 0.9f};
constexpr float PORTRAIT_FADE_RED = 231;
constexpr float PORTRAIT_FADE_GREEN = 221;
constexpr float PORTRAIT_FADE_BLUE = 220;
constexpr float CHANNEL_MAX = 255;
// Where a part of the menu sits from the menu's corner, or from another part.
struct MenuOffset
{
float x;
float y;
};
constexpr MenuOffset PAGE_SWAP_OFFSET = {54, 50};
constexpr MenuOffset COMPLETION_OFFSET = {80, 50};
constexpr MenuOffset DIFFICULTY_OFFSET = {365, 120};
constexpr MenuOffset SEED_WIDGET_OFFSET = {350, 45};
constexpr MenuOffset SEED_KEY_OFFSET = {357, 46};
constexpr MenuOffset SEED_KEY_OFFSET_SHIFTED = {365, 49};
constexpr int SEED_KEY_SHIFT_LANGUAGE = 2;
constexpr MenuOffset SEED_TEXT_OFFSET = {400, 57};
constexpr float SEED_ENTRY_TEXT_X = 185;
constexpr float SEED_ENTRY_TOP_Y = 35;
constexpr float SEED_ENTRY_BOTTOM_Y = 60;
constexpr MenuOffset WIN_STREAK_OFFSET = {45, 140};
constexpr MenuOffset STREAK_TEXT_OFFSET = {85, 162};
constexpr MenuOffset EASTER_EGG_OFFSET = {404, 238};
constexpr MenuOffset EGG_COUNT_OFFSET = {-18, -10};
constexpr MenuOffset EDEN_TOKENS_OFFSET = {240, 215};
constexpr float UNLOCK_TITLE_Y = -26;
constexpr uint32_t INK_ARGB = 0xff362f2d;
constexpr uint32_t EGG_COUNT_ARGB = 0xff3d3234;
constexpr uint32_t BLACK_ARGB = 0xff000000;
constexpr uint32_t CLEAR_ARGB = 0;
// The GLFW keys the seed entry reads.
enum SeedKey : int
{
KEY_V = 86,
KEY_BACKSPACE = 259,
KEY_KEYPAD_0 = 320,
KEY_LEFT_CONTROL = 341,
KEY_LEFT_SUPER = 343,
KEY_RIGHT_CONTROL = 345,
KEY_RIGHT_SUPER = 347
};
// A position moved by an offset.
static Vector offset_add(Vector origin, MenuOffset offset)
{
return vector_make(origin.x + offset.x, origin.y + offset.y);
}
// Whether a key of the keyboard is held, or was pressed this frame.
static bool is_key(int key, ActionTest test)
{
std::shared_ptr<KAGE::Input::InputDevice> keyboard = KAGE::Input::manager.get_device(KEYBOARD_DEVICE);
return keyboard &&
(test == ACTION_TRIGGERED ? keyboard->is_button_triggered(key) : keyboard->is_button_pressed(key));
}
// Whether the menu controller's glyph for an action was drawn at a position, which the sprites' own key art stands in
// for otherwise. The keyboard has no glyphs.
static bool is_action_glyph_rendered([[maybe_unused]] ButtonAction action, [[maybe_unused]] Vector glyphPosition)
{
if (g_menuControllerIndex == KEYBOARD_DEVICE || g_menuControllerIndex == DEVICE_NONE) return false;
reconstruction_missing("Manager::render_controller_action_glyph 0095af30, which manager.h does not declare");
}
// Shows or hides a layer of a sprite. The original assumes the layer is there.
static void layer_show(ANM2& sprite, int layerId, bool isVisible)
{
if (LayerState* layer = sprite.GetLayer(layerId)) layer->isVisible = isVisible;
}
// Loads a sprite and plays an animation on it, unless it already shows it.
static void sprite_load(ANM2& sprite, std::string_view path, std::string_view animation)
{
sprite.Load(path, GRAPHICS_LOAD);
sprite.Play(animation);
}
// Fades an overlay a step toward shown while the difficulty calls for it, else toward hidden, and tints it so.
static void overlay_fade(ANM2& sprite, float& alpha, bool isShown)
{
if (alpha < 1 && isShown) alpha += ALPHA_STEP;
else if (alpha > 0 && !isShown) alpha -= ALPHA_STEP;
sprite.color = {{1, 1, 1, alpha}, {0, 0, 0, 0}, {0, 0, 0}};
}
// Draws a line of text in a color, its left at a position.
static void text_draw(Font& font, std::string_view text, Vector textPosition, uint32_t argb)
{
FontSettings settings;
font.DrawString(text, textPosition, vector_make(1, 1), kcolor_argb(argb), settings);
}
// Draws a line of text in the paper's ink, centered on a position.
static void text_draw_centered(Font& font, std::string_view text, Vector center)
{
float width = (float)font.GetStringWidth(text);
text_draw(font, text, vector_make(center.x - width * 0.5f, center.y), INK_ARGB);
}
// Whether a player type can be picked: its achievement unlocked, and an Eden token for Eden and Tainted Eden.
// The original reads a missing player's config. A player type without one counts as available.
static bool is_player_available(int playerType)
{
Manager& manager = *g_manager;
EntityConfig_Player* player = manager.entityConfig.GetPlayer(playerType);
if (!player || player->achievement < 0) return true;
bool isEden = playerType == PLAYER_EDEN || playerType == PLAYER_TAINTED_EDEN;
bool isTokenMissing = isEden && manager.persistentGameData.eventCounters[EVENT_EDEN_TOKENS] == 0;
return manager.persistentGameData.Unlocked(player->achievement) && !isTokenMissing;
}
// Whether a game character takes a place on the wheel: shown, or hidden until unlocked and unlocked. Which ones are
// hidden is always read from the first menu, as in the original.
static bool is_on_wheel(int menuId)
{
const Menu_Character_Entry& entry = CHARACTER_ENTRIES[CHARACTER_MENU_NORMAL][menuId];
return !entry.isHidden || entry.IsCharacterAvailable();
}
// Saves the save slot when it changed, backing up the old file first, as PersistentGameData's save does.
static void progress_save()
{
PersistentGameData& data = g_manager->persistentGameData;
if (!data.isChangesMade || !data.isFileLoaded) return;
data.isChangesMade = false;
data.BackupSaveFile();
data.Save();
}
// 0098afa0 Starts easing the menus' color modifier toward a target, every channel arriving together, at a rate.
void menu_color_mod_lerp(const ColorModState& target, float rate)
{
MenuManager& menus = *g_menuManager;
const ColorModState& current = menus.currentColorModState;
menus.targetColorModState = target;
menus.lerpColorModState = {std::fabs(target._red - current._red) * rate,
std::fabs(target._green - current._green) * rate,
std::fabs(target._blue - current._blue) * rate,
std::fabs(target._amount - current._amount) * rate,
std::fabs(target._brightness - current._brightness) * rate,
std::fabs(target._contrast - current._contrast) * rate};
menus.isColorModLerping = true;
}
// 00946cd0 Whether the entry's character can be picked.
bool Menu_Character_Entry::IsCharacterAvailable() const
{
return is_player_available(playerType);
}
// 00424ef0 Loads the widget, on the pause screen's sheet for that style, playing, with no marks counted.
void CompletionWidget::Load(CompletionStyle style)
{
anm2.Load(COMPLETION_ANM2, GRAPHICS_DEFER);
if (style == COMPLETION_STYLE_PAUSE)
for (int layer = 0; layer < COMPLETION_MARK_COUNT; layer++)
anm2.ReplaceSpritesheet(layer, COMPLETION_PAUSE_PNG);
anm2.LoadGraphics();
anm2.Play(ANIMATION_IDLE);
markCount = 0;
}
// 00425130 Steps the widget every other frame and puts each mark on the difficulty the character earned it on (the
// tainted characters' Delirium mark on its own frames), counting the earned ones. Characters past the game's show
// none. Netplay is offline, so the online marks only count where no offline mark is.
void CompletionWidget::Update()
{
PersistentGameData& data = g_manager->persistentGameData;
if ((g_manager->framecount & 1) == 0) anm2.Update();
markCount = 0;
for (const CompletionMarkLayer& mark : COMPLETION_MARK_LAYERS)
{
if ((uint32_t)characterId > COMPLETION_PLAYER_TYPE_MAX)
{
anm2.SetLayerFrame(mark.layer, 0);
continue;
}
int flags = data.eventCounters[COMPLETION_MARKS[characterId][mark.completionType].counter];
int frame = flags & MARK_HARD ? 2 : flags & MARK_NORMAL;
if (frame == 0) frame = flags & MARK_ONLINE_HARD ? 2 : flags & MARK_ONLINE_NORMAL ? 1 : 0;
if (mark.layer == 0 && characterId >= COMPLETION_TAINTED_MIN) frame += COMPLETION_TAINTED_FRAMES;
anm2.SetLayerFrame(mark.layer, frame);
if (flags != 0) markCount++;
}
}
// 004252f0 Draws the widget at a scale.
void CompletionWidget::Render(Vector widgetPosition, Vector scale)
{
anm2.scale = scale;
anm2.Render({widgetPosition});
}
// 00947470 Loads every sprite of the menu on the first menu's sheets, the completion widget, and the snapshot the page
// swap turns, then resets the menu at its place. MenuManager::Init inlines it.
void Menu_Character::Init(Vector menuPosition)
{
const MenuSheets& sheets = MENU_SHEETS[CHARACTER_MENU_NORMAL];
sprite_load(bigCharPageSprite, sheets.page, ANIMATION_ISAAC);
sprite_load(difficultyOverlaySprite, sheets.page, ANIMATION_BLOOD_STAIN);
for (LayerState& layer : difficultyOverlaySprite.layerStates) layer.blendMode = BLEND_STAIN;
sprite_load(greedDecoOverlaySprite, sheets.page, ANIMATION_GREED);
sprite_load(characterMenuBGSprite, BACKGROUND_ANM2, ANIMATION_IDLE);
sprite_load(pageSwapWidgetSprite, PAGE_SWAP_ANM2, ANIMATION_IDLE);
sprite_load(taintedMenuBGDecoSprite, BACKGROUND_EXTRA_ANM2, ANIMATION_IDLE);
sprite_load(characterPortraitsSprite, sheets.portraits, ANIMATION_ISAAC);
sprite_load(seedEntrySprite, SEED_ENTRY_ANM2, ANIMATION_IDLE);
difficultyPageSprite.Load(DIFFICULTY_ANM2, GRAPHICS_LOAD);
sprite_load(seedPageSprite, SEED_WIDGET_ANM2, ANIMATION_IDLE);
sprite_load(winStreakPageSprite, WIN_STREAK_ANM2, ANIMATION_IDLE);
sprite_load(eastereggPageSprite, EASTER_EGG_ANM2, ANIMATION_NO_EGGS);
seedUnlockPageSprite.Load(SEED_UNLOCK_ANM2, GRAPHICS_LOAD);
completionWidget.Load(COMPLETION_STYLE_MENU);
menuBlackColorizeIntensity = 0;
menuYellowColorizeIntensity = 0;
KAGE::Graphics::RenderTargetDesc desc;
desc.clearColor = kcolor_argb(CLEAR_ARGB);
desc.name = PAGE_SNAPSHOT_NAME;
desc.width = (int)MENU_WIDTH;
desc.height = (int)MENU_HEIGHT;
pageSnapshot = KAGE::Graphics::manager.render_target_create(desc);
TextureCache::Add(pageSnapshot);
page_texture_set();
Reset();
position = menuPosition;
}
// Gives the background's page layer the page snapshot as its sheet, and lets the cache drop the sheet it replaced.
void Menu_Character::page_texture_set()
{
LayerState* layer = characterMenuBGSprite.GetLayer(BACKGROUND_LAYER_PAGE);
if (!layer) return;
if (pageSnapshot)
{
layer->minFilterMode = (unsigned int)pageSnapshot->minFilter;
layer->magFilterMode = (unsigned int)pageSnapshot->magFilter;
layer->wrapSMode = (unsigned int)pageSnapshot->wrapS;
layer->wrapTMode = (unsigned int)pageSnapshot->wrapT;
}
layer->spriteSheet = pageSnapshot;
if (layer->layerData) TextureCache::Release(layer->layerData->spriteSheetPath);
}
// Loads the shown menu's page, stain and portraits, with the page set up for the selection.
void Menu_Character::pages_load()
{
const MenuSheets& sheets = MENU_SHEETS[characterMenuShown];
bigCharPageSprite.Load(sheets.page, GRAPHICS_LOAD);
if (selectedCharacterID < CHARACTER_ENTRY_COUNT)
bigCharPageSprite.Play(CHARACTER_ENTRIES[characterMenuShown][selectedCharacterID].animationName);
UpdateRotations();
sprite_load(difficultyOverlaySprite, sheets.page, ANIMATION_BLOOD_STAIN);
for (LayerState& layer : difficultyOverlaySprite.layerStates) layer.blendMode = BLEND_STAIN;
sprite_load(characterPortraitsSprite, sheets.portraits, ANIMATION_ISAAC);
}
// 00948200 Loads every sprite again for the shown menu, as the menus come back: the background with the page
// snapshot on it, the tainted decoration as the save left it, the pages and the widgets.
void Menu_Character::LoadGraphics()
{
bool isTaintedSaved = g_manager->persistentGameData.characterMenuShown >= CHARACTER_MENU_TAINTED;
characterMenuBGSprite.Load(BACKGROUND_ANM2, GRAPHICS_LOAD);
page_texture_set();
characterMenuBGSprite.Play(ANIMATION_IDLE);
sprite_load(pageSwapWidgetSprite, PAGE_SWAP_ANM2, ANIMATION_IDLE);
sprite_load(taintedMenuBGDecoSprite, BACKGROUND_EXTRA_ANM2, ANIMATION_IDLE);
taintedMenuBGDecoSprite.Play(isTaintedSaved ? ANIMATION_APPEAR : ANIMATION_DISAPPEAR, PLAY_FORCED);
taintedMenuBGDecoSprite.SetLastFrame();
pages_load();
sprite_load(greedDecoOverlaySprite, MENU_SHEETS[CHARACTER_MENU_NORMAL].page, ANIMATION_GREED);
sprite_load(seedEntrySprite, SEED_ENTRY_ANM2, ANIMATION_IDLE);
bool isGreedierUnlocked = g_manager->persistentGameData.Unlocked(ACHIEVEMENT_GREEDIER);
sprite_load(difficultyPageSprite, DIFFICULTY_ANM2,
isGreedierUnlocked ? ANIMATION_GREEDIER : ANIMATION_GREEDIER_LOCKED);
sprite_load(seedPageSprite, SEED_WIDGET_ANM2, ANIMATION_IDLE);
sprite_load(winStreakPageSprite, WIN_STREAK_ANM2, ANIMATION_IDLE);
sprite_load(eastereggPageSprite, EASTER_EGG_ANM2, ANIMATION_NO_EGGS);
seedUnlockPageSprite.Load(SEED_UNLOCK_ANM2, GRAPHICS_LOAD);
}
// Drops the menu's sprites as a run starts, for MenuManager::unload_graphics, which inlines this.
void Menu_Character::unload_graphics()
{
for (ANM2* sprite :
{&bigCharPageSprite, &characterMenuBGSprite, &difficultyOverlaySprite, &greedDecoOverlaySprite,
&characterPortraitsSprite, &seedEntrySprite, &difficultyPageSprite, &seedPageSprite, &winStreakPageSprite,
&eastereggPageSprite, &seedUnlockPageSprite, &pageSwapWidgetSprite, &taintedMenuBGDecoSprite})
sprite->Reset();
}
// 00948fc0 Puts the menu back to selecting Isaac on the saved menu and difficulty: counts the wheel's characters (the
// game's on it and every modded character with no twin of its own), shapes the wheel for that many and turns it to
// Isaac, and clears the seed. A save on the tainted menu swaps to it.
// A saved menu past the two counts as the tainted one, where the original reads past its table of sheets.
void Menu_Character::Reset()
{
MenuManager& menus = *g_menuManager;
PersistentGameData& data = g_manager->persistentGameData;
std::vector<EntityConfig_Player>& players = g_manager->entityConfig.players;
status = CHARACTER_STATUS_SELECT;
difficultyPageSprite.Play(data.Unlocked(ACHIEVEMENT_GREEDIER) ? ANIMATION_GREEDIER : ANIMATION_GREEDIER_LOCKED);
menus.viewPositionSet[MENU_CHARACTER].x = 0;
menus.isViewMoving = true;
selectedCharacterID = 1;
numCharacters = 0;
for (int i = 0; i < CHARACTER_ENTRY_COUNT; i++) numCharacters += is_on_wheel(i);
modCharacters.clear();
for (size_t i = PLAYER_TYPE_COUNT; i < players.size(); i++)
if (!players[i].isHidden && players[i].bSkinParentName.empty())
modCharacters.push_back({players[i].id, players[i].moddedTaintedPlayerID});
numCharacters += (int)modCharacters.size();
float crowd = (float)std::pow((double)std::max(numCharacters - WHEEL_CROWD, 0), 2.0);
characterWheelDepth = crowd * WHEEL_DEPTH_GROWTH + WHEEL_DEPTH_MIN;
float halfDepth = (characterWheelDepth - 1) * 0.5f;
float farScale = halfDepth + 1;
float ratio = halfDepth / farScale;
characterWheelWidth = (farScale - ratio * halfDepth) * WHEEL_WIDTH_SCALE / std::sqrt(1 - ratio * ratio);
scrollSpeed = FULL_TURN / (float)numCharacters / (characterWheelWidth * WHEEL_SPEED_SCALE);
portraitPositions.assign(numCharacters, vector_make(WHEEL_X, WHEEL_Y));
portraitScales.assign(numCharacters, 1.0f);
isCharacterUnlocked = true;
isInputPossible = true;
cooldownWhenHoldDirection = INPUT_COOLDOWN;
chosenRandomCharacter = 0;
numCharactersMinusSelectedEntry = numCharacters - 1;
randomRotationVelocity = 0;
horizontalScrollPosition = (float)numCharactersMinusSelectedEntry * FULL_TURN / (float)numCharacters;
difficulty = (Difficulty)data.lastDifficulty;
seedText.clear();
menus.seedsObject.set_start_seed(Seeds::String2Seed(""));
set_character_menu_shown(data.characterMenuShown >= CHARACTER_MENU_TAINTED ? CHARACTER_MENU_TAINTED
: CHARACTER_MENU_NORMAL);
taintedMenuBGDecoSprite.Play(
data.characterMenuShown >= CHARACTER_MENU_TAINTED ? ANIMATION_APPEAR : ANIMATION_DISAPPEAR, PLAY_FORCED);
taintedMenuBGDecoSprite.SetLastFrame();
if (pageSwapWidgetSprite.color._tint[3] == 0 && characterMenuShown != CHARACTER_MENU_NORMAL) DoPageSwap();
seed_unlock_page_reset();
}
// Hides the seed unlock page and forgets its texts.
void Menu_Character::seed_unlock_page_reset()
{
seedUnlockPageState = SEED_UNLOCK_HIDDEN;
seedUnlockPageTimer = 0;
seedUnlockTitle.clear();
seedUnlockName.clear();
}
// 009495f0 Shows a menu's sheets, saving the choice, with the character layer of the music and the menus' color
// modifier of the tainted menu on it. The original also swaps the window icon, which is a Windows resource.
void Menu_Character::set_character_menu_shown(CharacterMenu menu)
{
PersistentGameData& data = g_manager->persistentGameData;
MusicManager& music = g_manager->musicManager;
characterMenuShown = menu;
pages_load();
if (selectedCharacterID >= CHARACTER_ENTRY_COUNT) bigCharPageSprite.Play(ANIMATION_ISAAC);
data.characterMenuShown = menu;
data.isChangesMade = true;
if (menu < CHARACTER_MENU_TAINTED)
{
music.DisableLayer(0);
return menu_color_mod_lerp(COLOR_MOD_NONE, COLOR_MOD_RATE);
}
music.EnableLayer(0, LAYER_FADE);
menu_color_mod_lerp(COLOR_MOD_TAINTED, COLOR_MOD_RATE);
}
// 00949b90 The player type of a wheel slot on a menu: a game character's, or a modded character's or its twin's.
int Menu_Character::GetPlayerTypeFromMenuID(int menuId, CharacterMenu menu) const
{
bool isTainted = menu != CHARACTER_MENU_NORMAL;
if (menuId < CHARACTER_ENTRY_COUNT) return CHARACTER_ENTRIES[isTainted][menuId].playerType;
const ModCharacter& character = modCharacters[menuId - CHARACTER_ENTRY_COUNT];
return isTainted ? character.taintedPlayerType : character.playerType;
}
// 00949c20 Steps the menu: the sprites every other frame (the difficulty page on the difficulty's frame), the
// background's rip sound; the run once the menus faded out, or the input and the wheel; the page swap's end, the seed
// unlock page, and the widgets for the seed effects and the streak.
void Menu_Character::Update()
{
PersistentGameData& data = g_manager->persistentGameData;
if ((g_manager->framecount & 1) == 0)
{
for (ANM2* sprite :
{&bigCharPageSprite, &characterMenuBGSprite, &difficultyPageSprite, &seedPageSprite, &winStreakPageSprite,
&difficultyOverlaySprite, &eastereggPageSprite, &seedUnlockPageSprite})
sprite->Update();
if (difficulty <= DIFFICULTY_GREEDIER) difficultyPageSprite.SetFrame((float)difficulty);
if (status == CHARACTER_STATUS_SEED_ENTRY) seedEntrySprite.Update();
taintedMenuBGDecoSprite.Update();
pageSwapWidgetSprite.Update();
if (characterMenuBGSprite.IsEventTriggered(EVENT_SOUND)) menu_sound_play(SOUND_MENU_RIP, SOUND_DELAY);
}
if (status == CHARACTER_STATUS_STARTING)
{
if (g_menuManager->fadeOutProgress > 1) run_start();
}
else
{
if (status != CHARACTER_STATUS_RANDOM_SPIN) handle_input();
UpdateRotations();
}
if (status == CHARACTER_STATUS_PAGE_SWAP && characterMenuBGSprite.IsFinished())
{
if (characterMenuBGSprite.GetAnimation() == ANIMATION_SWAP_OUT)
{
set_character_menu_shown((CharacterMenu)(CHARACTER_MENU_TAINTED - characterMenuShown));
render_page_snapshot();
characterMenuBGSprite.Play(ANIMATION_SWAP_IN);
menu_sound_play(SOUND_BOOK_PAGE_TURN_12, SOUND_DELAY);
}
else characterMenuBGSprite.Play(ANIMATION_IDLE);
status = CHARACTER_STATUS_SELECT;
}
if (characterMenuBGSprite.IsFinished()) characterMenuBGSprite.Play(ANIMATION_IDLE);
else render_page_snapshot();
if (seedUnlockPageState == SEED_UNLOCK_APPEARING)
{
seedUnlockPageSprite.Play(ANIMATION_APPEAR);
if (seedUnlockPageSprite.IsFinished()) seedUnlockPageState = SEED_UNLOCK_SHOWN;
}
else if (seedUnlockPageState == SEED_UNLOCK_SHOWN)
{
seedUnlockPageSprite.Play(ANIMATION_IDLE);
if ((g_manager->framecount & 1) == 0) seedUnlockPageTimer++;
if (seedUnlockPageTimer > SEED_UNLOCK_FRAMES)
{
seedUnlockPageState = SEED_UNLOCK_DISAPPEARING;
seedUnlockPageTimer = 0;
}
}
else if (seedUnlockPageState == SEED_UNLOCK_DISAPPEARING)
{
seedUnlockPageSprite.Play(ANIMATION_UNLOCK_DISAPPEAR);
if (seedUnlockPageSprite.IsFinished()) seedUnlockPageState = SEED_UNLOCK_HIDDEN;
}
eastereggPageSprite.Play(g_menuManager->seedsObject.CountSeedEffects() == 0 ? ANIMATION_NO_EGGS : ANIMATION_EGGS);
if (data.eventCounters[EVENT_NEGATIVE_STREAK_COUNTER] != 0) winStreakPageSprite.Play(ANIMATION_STREAK_BAD);
else if (data.eventCounters[EVENT_STREAK_COUNTER] != 0) winStreakPageSprite.Play(ANIMATION_STREAK_GOOD);
}
// Starts the run on the selected character, difficulty and seeds, spending an Eden token on Eden and ending the win
// streak when it abandons a saved run, with the save slot saved first.
void Menu_Character::run_start()
{
Manager& manager = *g_manager;
PersistentGameData& data = manager.persistentGameData;
if (selectedCharacterID == MENU_ID_EDEN) data.IncreaseEventCounter(EVENT_EDEN_TOKENS, -1);
if (manager.gamestate.isSaveAvailable)
data.IncreaseEventCounter(EVENT_STREAK_COUNTER, -data.eventCounters[EVENT_STREAK_COUNTER]);
progress_save();
int playerType = GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown);
manager.StartNewGame(playerType, 0, g_menuManager->seedsObject, difficulty);
}
// 0094d500 Shows the page swap once a tainted character is there to swap to, sets the page up for the selection
// (locked, or with the items it has unlocked), turns the wheel toward the selection a step per portrait and places
// every portrait on it, then points the completion widget at the selected character.
void Menu_Character::UpdateRotations()
{
const Menu_Character_Entry* tainted = CHARACTER_ENTRIES[CHARACTER_MENU_TAINTED];
bool isTaintedThere = std::any_of(tainted, tainted + CHARACTER_ENTRY_COUNT,
[](const Menu_Character_Entry& entry) { return entry.IsCharacterAvailable(); });
isTaintedThere =
isTaintedThere || std::any_of(modCharacters.begin(), modCharacters.end(),
[](const ModCharacter& mod) { return mod.playerType != mod.taintedPlayerType; });
pageSwapWidgetSprite.color._tint[3] = isTaintedThere ? 1.0f : 0.0f;
page_layers_update();
isInputPossible = false;
for (int i = 0; i < numCharacters; i++) wheel_rotate(i);
if (selectedCharacterID >= CHARACTER_ENTRY_COUNT) return;
completionWidget.characterId =
CHARACTER_ENTRIES[characterMenuShown != CHARACTER_MENU_NORMAL][selectedCharacterID].playerType;
completionWidget.Update();
}
// Locks the page of an unavailable game character, or shows the details of an available one with its unlocked items.
void Menu_Character::page_layers_update()
{
bool isGameCharacter = selectedCharacterID < CHARACTER_ENTRY_COUNT;
const Menu_Character_Entry* entry =
isGameCharacter ? &CHARACTER_ENTRIES[characterMenuShown][selectedCharacterID] : nullptr;
isCharacterUnlocked = !entry || entry->IsCharacterAvailable();
if (!isGameCharacter) return;
for (int layer = PAGE_LAYER_DETAILS_FIRST; layer < PAGE_LAYER_DETAILS_END; layer++)
layer_show(bigCharPageSprite, layer, isCharacterUnlocked);
if (isCharacterUnlocked)
for (int i = 0; i < CHARACTER_ITEM_COUNT; i++)
{
bool isItemUnlocked = g_manager->persistentGameData.Unlocked(entry->itemAchievements[i]);
layer_show(bigCharPageSprite, ITEM_LAYERS[i][0], isItemUnlocked);
layer_show(bigCharPageSprite, ITEM_LAYERS[i][1], isItemUnlocked);
}
layer_show(bigCharPageSprite, PAGE_LAYER_LOCKED, !isCharacterUnlocked);
layer_show(bigCharPageSprite, PAGE_LAYER_LOCK, true);
bigCharPageSprite.SetLayerFrame(PAGE_LAYER_LOCK, !isCharacterUnlocked);
}
// Turns the wheel a step toward the selection the short way round (the random spin easing from its own speed to a
// sixth of the wheel's), or once there takes input again or spins on. Then places a portrait on the tilted ellipse,
// smaller and fainter toward the back. The original does all of this once per portrait, so the wheel turns that
// many steps a frame.
void Menu_Character::wheel_rotate(int portrait)
{
float angle = -((float)portrait * TAU / (float)numCharacters);
float target = FULL_TURN / (float)numCharacters * (float)numCharactersMinusSelectedEntry;
float speed = scrollSpeed;
if (status == CHARACTER_STATUS_RANDOM_SPIN)
{
float ease = std::clamp(((float)randomRotationAmount - SPIN_EASE_START) / SPIN_EASE_LENGTH, 0.0f, 1.0f);
speed = (scrollSpeed / SPIN_SLOWDOWN - randomRotationVelocity) * ease + randomRotationVelocity;
}
float& scroll = horizontalScrollPosition;
if (target > scroll)
{
float distance = target - scroll;
scroll = distance < HALF_TURN ? scroll + std::min(distance, speed) : scroll - std::min(distance, speed);
}
else if (scroll > target)
{
float distance = scroll - target;
scroll = distance < HALF_TURN ? scroll - std::min(distance, speed) : scroll + std::min(distance, speed);
}
else if (status == CHARACTER_STATUS_RANDOM_SPIN) random_spin_step();
else isInputPossible = true;
if (scroll < 0) scroll = FULL_TURN;
else if (scroll > FULL_TURN) scroll = 0;
float angleCos = (float)std::cos((double)angle);
float angleSin = (float)std::sin((double)angle);
float turn = (QUARTER_TURN - scroll) * DEGREES_TO_RADIANS;
float turnCos = (float)std::cos((double)turn);
float turnSin = (float)std::sin((double)turn);
float depth = turnCos * angleSin + turnSin * angleCos;
float across = turnCos * angleCos - turnSin * angleSin;
float back = std::min(std::max((depth - 1) * -0.5f, 0.0f), 1.0f);
float distance = (characterWheelDepth - 1) * back + 1;
portraitScales[portrait] = 1 / distance;
portraitPositions[portrait] = vector_make(across * WHEEL_RADIUS / distance * characterWheelWidth + WHEEL_X,
depth * WHEEL_RADIUS / distance * WHEEL_TILT + WHEEL_HEIGHT);
}
// A step of the random spin landing on a slot: the run starts once the spin is spent, else the selection moves on a
// slot (past hidden ones) with a click.
void Menu_Character::random_spin_step()
{
MenuManager& menus = *g_menuManager;
if (--randomRotationAmount < 0)
{
menus.start_game(kcolor_make(0, 0, 0, 1));
status = CHARACTER_STATUS_STARTING;
menus.viewPositionSet[MENU_CHARACTER].x = 0;
menus.isViewMoving = true;
return;
}
selectedCharacterID++;
if (--numCharactersMinusSelectedEntry < 0) numCharactersMinusSelectedEntry = numCharacters - 1;
while (selectedCharacterID < CHARACTER_ENTRY_COUNT && !is_on_wheel(selectedCharacterID)) selectedCharacterID++;
if (selectedCharacterID >= CHARACTER_ENTRY_COUNT + (int)modCharacters.size()) selectedCharacterID = 0;
menu_sound_play(SOUND_CHARACTER_SELECT_RIGHT, 0);
if (selectedCharacterID < CHARACTER_ENTRY_COUNT)
bigCharPageSprite.Play(CHARACTER_ENTRIES[characterMenuShown][selectedCharacterID].animationName);
}
// 0094de50 Picks the random character among the available ones and the modded ones, and winds the spin up to land on
// it after three turns of the wheel.
// The original reads before its table with nothing to pick, which cannot happen as Isaac is always there. Random's
// own slot is picked then.
void Menu_Character::SelectRandomChar()
{
std::vector<int> candidates;
for (int i = 1; i < CHARACTER_ENTRY_COUNT; i++)
if (CHARACTER_ENTRIES[characterMenuShown][i].IsCharacterAvailable()) candidates.push_back(i);
for (int i = 0; i < (int)modCharacters.size(); i++) candidates.push_back(CHARACTER_ENTRY_COUNT + i);
int chosen = candidates.empty() ? MENU_ID_RANDOM : candidates[Random() % (uint32_t)candidates.size()];
chosenRandomCharacter = chosen;
randomRotationAmount = chosen + numCharacters * SPIN_TURNS;
randomRotationVelocity = FULL_TURN / (float)numCharacters / SPIN_FRAMES;
for (int i = 0; i < std::min(chosen, CHARACTER_ENTRY_COUNT); i++) randomRotationAmount -= !is_on_wheel(i);
EntityConfig_Player* player =
g_manager->entityConfig.GetPlayer(GetPlayerTypeFromMenuID(chosen, characterMenuShown));
log_printf(LOG_INFO, "random: %s\n", player ? player->GetDisplayName().c_str() : "");
}
// 0094c580 Reads the menu's input: the selection's, or the seed entry's, then from the selection the special seeds
// (LB), the seed entry (tab) and the page swap (RB), as they were pressed before either.
void Menu_Character::handle_input()
{
if (status == CHARACTER_STATUS_SELECT) select_input();
bool isSeedEntryPressed = is_action(ACTION_MENU_TAB, ACTION_TRIGGERED);
bool isSpecialSeedsPressed = is_action(ACTION_MENU_LB, ACTION_TRIGGERED);
bool isPageSwapPressed = is_action(ACTION_MENU_RB, ACTION_TRIGGERED);
if (status == CHARACTER_STATUS_SEED_ENTRY) seed_entry_input();
if (status != CHARACTER_STATUS_SELECT) return;
if (isSpecialSeedsPressed && Seeds::CountUnlockedSeedEffects() > 0) g_menuManager->push_menu(MENU_SPECIAL_SEEDS);
if (isSeedEntryPressed) seed_entry_open();
if (isPageSwapPressed && pageSwapWidgetSprite.color._tint[3] > 0) DoPageSwap();
}
// The selection's input: confirm spins for Random, starts the run on an unlocked character or buzzes; up and down
// change the difficulty; left and right turn the wheel (repeating while held, once the wheel stopped); back leaves.
void Menu_Character::select_input()
{
MenuManager& menus = *g_menuManager;
auto isHeld = [this](ButtonAction action) {
return is_action(action, ACTION_PRESSED) && isInputPossible && cooldownWhenHoldDirection-- < 1;
};
if (is_action(ACTION_MENU_CONFIRM, ACTION_TRIGGERED))
{
if (selectedCharacterID == MENU_ID_RANDOM)
{
status = CHARACTER_STATUS_RANDOM_SPIN;
menus.viewPositionSet[MENU_CHARACTER].x = 0;
menus.isViewMoving = true;
SelectRandomChar();
input_poll_active_device();
}
else if (!isCharacterUnlocked) menu_sound_play(SOUND_ERROR_BUZZ, SOUND_DELAY);
else
{
g_manager->selectedDifficulty = difficulty;
menus.start_game(kcolor_argb(BLACK_ARGB));
status = CHARACTER_STATUS_STARTING;
}
}
else if (is_action(ACTION_MENU_UP, ACTION_TRIGGERED)) difficulty_step(-1);
else if (is_action(ACTION_MENU_DOWN, ACTION_TRIGGERED)) difficulty_step(1);
else if (is_action(ACTION_MENU_LEFT, ACTION_TRIGGERED) || isHeld(ACTION_MENU_LEFT)) selection_step(-1);
else if (is_action(ACTION_MENU_RIGHT, ACTION_TRIGGERED) || isHeld(ACTION_MENU_RIGHT)) selection_step(1);
else if (is_action(ACTION_MENU_BACK, ACTION_TRIGGERED))
{
progress_save();
menus.pop_menu();
}
}
// Turns the wheel a slot left or right, past the hidden characters, wrapping through the modded ones.
void Menu_Character::selection_step(int step)
{
int lastId = CHARACTER_ENTRY_COUNT - 1 + (int)modCharacters.size();
cooldownWhenHoldDirection = INPUT_COOLDOWN;
selectedCharacterID += step;
numCharactersMinusSelectedEntry -= step;
if (step < 0)
{
if (selectedCharacterID < 0) selectedCharacterID = lastId;
if (numCharactersMinusSelectedEntry >= numCharacters) numCharactersMinusSelectedEntry = 0;
}
else if (numCharactersMinusSelectedEntry < 0) numCharactersMinusSelectedEntry = numCharacters - 1;
while (selectedCharacterID >= 0 && selectedCharacterID < CHARACTER_ENTRY_COUNT && !is_on_wheel(selectedCharacterID))
selectedCharacterID += step;
if (selectedCharacterID > lastId) selectedCharacterID = 0;
menu_sound_play(step < 0 ? SOUND_CHARACTER_SELECT_LEFT : SOUND_CHARACTER_SELECT_RIGHT, 0);
if (selectedCharacterID < CHARACTER_ENTRY_COUNT)
bigCharPageSprite.Play(CHARACTER_ENTRIES[characterMenuShown][selectedCharacterID].animationName);
}
// Steps the difficulty up or down through normal, hard, Greed and Greedier (once unlocked), saving the choice.
void Menu_Character::difficulty_step(int step)
{
int last = g_manager->persistentGameData.Unlocked(ACHIEVEMENT_GREEDIER) ? DIFFICULTY_GREEDIER : DIFFICULTY_GREED;
int next = (int)difficulty + step;
if (difficulty <= DIFFICULTY_GREEDIER) difficulty = (Difficulty)(next < 0 ? last : next > last ? 0 : next);
menu_sound_play(SOUND_MENU_SCROLL, SOUND_DELAY);
g_manager->persistentGameData.lastDifficulty = difficulty;
g_manager->persistentGameData.isChangesMade = true;
}
// Opens the seed entry page beside the menu, with the hotkeys off and no seed.
void Menu_Character::seed_entry_open()
{
MenuManager& menus = *g_menuManager;
status = CHARACTER_STATUS_SEED_ENTRY;
menu_sound_play(SOUND_BOOK_PAGE_TURN_12, 0);
menus.viewPositionSet[MENU_CHARACTER].x = -MENU_WIDTH;
menus.isViewMoving = true;
g_manager->isHotkeysEnabled = false;
seedText.clear();
menus.seedsObject.SetStartSeed("");
}
// Turns back from the seed entry page, with the hotkeys on.
void Menu_Character::seed_entry_close()
{
status = CHARACTER_STATUS_SELECT;
g_menuManager->viewPositionSet[MENU_CHARACTER].x = 0;
g_menuManager->isViewMoving = true;
g_manager->isHotkeysEnabled = true;
}
// The seed entry's input: confirm submits the seed, back drops it; ctrl+V (or cmd+V) pastes the clipboard over it,
// else the letter and digit keys type, and backspace erases (the space along with the character before it).
void Menu_Character::seed_entry_input()
{
if (is_action(ACTION_MENU_CONFIRM, ACTION_TRIGGERED))
{
submit_seed();
return seed_entry_close();
}
if (is_action(ACTION_MENU_BACK, ACTION_TRIGGERED))
{
menu_sound_play(SOUND_BOOK_PAGE_TURN_12, 0);
seedText.clear();
g_menuManager->seedsObject.isCustomRun = false;
return seed_entry_close();
}
bool isControl = is_key(KEY_LEFT_CONTROL, ACTION_PRESSED) || is_key(KEY_RIGHT_CONTROL, ACTION_PRESSED) ||
is_key(KEY_LEFT_SUPER, ACTION_PRESSED) || is_key(KEY_RIGHT_SUPER, ACTION_PRESSED);
if (isControl && is_key(KEY_V, ACTION_TRIGGERED))
{
char* clipboard = SDL_GetClipboardText();
if (clipboard && *clipboard)
{
seedText.clear();
for (char* character = clipboard; *character && seedText.size() < SEED_TEXT_MAX; character++)
seed_add_char(*character);
}
SDL_free(clipboard);
}
else if (seedText.size() < SEED_TEXT_MAX)
{
for (char key = 'A'; key <= 'Z'; key++)
if (is_key(key, ACTION_TRIGGERED)) seed_add_char(key);
for (char key = '0'; key <= '9'; key++)
if (is_key(key, ACTION_TRIGGERED)) seed_add_char(key);
for (int digit = 0; digit <= 9; digit++)
if (is_key(KEY_KEYPAD_0 + digit, ACTION_TRIGGERED)) seed_add_char((char)('0' + digit));
}
if (!is_key(KEY_BACKSPACE, ACTION_TRIGGERED) || seedText.empty()) return;
if (seedText.size() == SEED_HALF + 1) seedText.erase(SEED_HALF - 1, 2);
else seedText.pop_back();
}
// 0094c4e0 Types a character of a seed: letters (upper-cased) and digits but 5, with I, O and U read as 1, 0 and V,
// and the space after the first four.
void Menu_Character::seed_add_char(char character)
{
char upper = (char)std::toupper((unsigned char)character);
bool isLetter = upper >= 'A' && upper <= 'Z';
bool isDigit = upper >= '0' && upper <= '9' && upper != '5';
if (!isLetter && !isDigit) return;
if (seedText.size() == SEED_HALF) seedText.push_back(' ');
seedText.push_back(upper == 'I' ? '1' : upper == 'O' ? '0' : upper == 'U' ? 'V' : upper);
}
// 0094d040 Submits the typed seed: a special seed is found for the save slot and turned on, with the unlock page
// naming it, a run seed becomes the start seed of a custom run, and anything else buzzes and clears.
void Menu_Character::submit_seed()
{
MenuManager& menus = *g_menuManager;
Seeds& seeds = menus.seedsObject;
int effect = Seeds::GetSeedEffect(seedText);
if (effect == 0)
{
if (Seeds::String2Seed(seedText) != 0)
{
menu_sound_play(SOUND_BOOK_PAGE_TURN_12, 0);
seeds.SetStartSeed(seedText);
seeds.isCustomRun = true;
return;
}
menu_sound_play(SOUND_ERROR_BUZZ, SOUND_DELAY);
seedText.clear();
seeds.isCustomRun = false;
return;
}
PersistentGameData& data = g_manager->persistentGameData;
bool isFound = data.specialSeeds[effect];
if (!data.isReadOnly)
{
data.specialSeeds[effect] = true;
data.specialSeeds[0] = false;
data.isChangesMade = true;
log_printf(LOG_INFO, "Seed %d added to SaveState\n", effect);
}
data.Save();
seeds.RemoveBlockingSeedEffects(effect);
seeds.AddSeedEffect(effect);
menus.menuSpecialSeeds.Reset();
StringTable& table = g_manager->stringTable;
std::string_view title = isFound ? menus.menuSpecialSeeds.enableText : menus.menuSpecialSeeds.unlockText;
bool isMissing = true;
if (title.starts_with(STRING_KEY_PREFIX))
{
std::string_view localized = table.get_string(SEED_MENU_CATEGORY, table.language, title.substr(1), &isMissing);
if (!isMissing) title = localized;
}
seedUnlockTitle = title;
std::vector<SpecialSeed>& entries = menus.menuSpecialSeeds.entries;
auto found =
std::find_if(entries.begin(), entries.end(), [effect](const SpecialSeed& entry) { return entry.id == effect; });
seedUnlockName = found != entries.end() ? found->get_display_name() : "";
seedUnlockPageState = SEED_UNLOCK_APPEARING;
seedUnlockPageTimer = 0;
seedText.clear();
seeds.isCustomRun = false;
}
// 0094e210 Turns the page to the other menu: the background tears the page off, the snapshot of this page on it, and
// the tainted decoration comes or goes.
void Menu_Character::DoPageSwap()
{
bool isToTainted = characterMenuShown == CHARACTER_MENU_NORMAL;
status = CHARACTER_STATUS_PAGE_SWAP;
characterMenuBGSprite.Play(ANIMATION_SWAP_OUT);
characterMenuBGSprite.PlayOverlay(MENU_SHEETS[isToTainted ? CHARACTER_MENU_TAINTED : CHARACTER_MENU_NORMAL].face);
render_page_snapshot();
taintedMenuBGDecoSprite.Play(isToTainted ? ANIMATION_APPEAR : ANIMATION_DISAPPEAR, PLAY_FORCED);
menu_sound_play(isToTainted ? SOUND_MENU_FLIP_DARK : SOUND_MENU_FLIP_LIGHT, SOUND_DELAY);
}
// 0094e170 Draws the page, without the portraits, into the snapshot the background shows while it turns.
void Menu_Character::render_page_snapshot()
{
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
graphics.render_target_push(pageSnapshot.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
graphics.Clear();
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
render_wheel(vector_make(0, 0), WHEEL_PAGE_ONLY);
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
}
// 0094a500 Draws the menu at its place in the view: the seed entry page beside it, the background around the wheel
// (or the turning page with the portraits on it), the page swap widget, the completion marks, the difficulty and
// seed widgets, the Greed decoration, the seed, the streak, the special seeds widget and the seed unlock page.
void Menu_Character::Render()
{
Vector origin = vector_add(g_menuManager->viewPosition, position);
PersistentGameData& data = g_manager->persistentGameData;
seedEntrySprite.Render({vector_make(origin.x + MENU_WIDTH, origin.y)});
characterMenuBGSprite.RenderLayer(BACKGROUND_LAYER_BACK, {origin});
taintedMenuBGDecoSprite.Render({origin});
characterMenuBGSprite.RenderLayer(BACKGROUND_LAYER_FRONT, {origin});
characterMenuBGSprite.RenderLayer(BACKGROUND_LAYER_EDGE, {origin});
if (status == CHARACTER_STATUS_PAGE_SWAP || characterMenuBGSprite.GetAnimation() != ANIMATION_IDLE)
{
characterMenuBGSprite.RenderLayer(BACKGROUND_LAYER_PAGE, {origin});
const AnimationFrame* page = characterMenuBGSprite.animState.GetLayerFrame(BACKGROUND_LAYER_PAGE);
if (page && page->isVisible)
{
Vector offset =
vector_make(page->pos.x - page->pivot.x * page->scale.x, page->pos.y - page->scale.y * page->pivot.y);
render_portraits(origin, offset, page->scale);
}
}
else render_wheel(origin, WHEEL_WITH_PORTRAITS);
characterMenuBGSprite.RenderLayer(BACKGROUND_LAYER_TOP, {origin});
if (pageSwapWidgetSprite.color._tint[3] > 0)
{
Vector swap = offset_add(origin, PAGE_SWAP_OFFSET);
pageSwapWidgetSprite.RenderLayer(0, {swap});
pageSwapWidgetSprite.RenderLayer(1, {swap});
const NullFrame* glyph = pageSwapWidgetSprite.animState.GetNullFrameById(0);
Vector glyphPosition = glyph ? vector_add(swap, glyph->pos) : swap;
if (!is_action_glyph_rendered(ACTION_MENU_RB, glyphPosition))
pageSwapWidgetSprite.RenderLayer(SWAP_LAYER_GLYPH, {swap});
}
if (selectedCharacterID < CHARACTER_ENTRY_COUNT && selectedCharacterID != MENU_ID_RANDOM)
completionWidget.Render(offset_add(origin, COMPLETION_OFFSET), vector_make(1, 1));
difficultyPageSprite.Render({offset_add(origin, DIFFICULTY_OFFSET)});
seedPageSprite.Render({offset_add(origin, SEED_WIDGET_OFFSET)});
bool isGreed = difficulty == DIFFICULTY_GREED || difficulty == DIFFICULTY_GREEDIER;
overlay_fade(greedDecoOverlaySprite, menuYellowColorizeIntensity, isGreed);
greedDecoOverlaySprite.Render({origin});
render_seed_page(origin);
winStreakPageSprite.Render({offset_add(origin, WIN_STREAK_OFFSET)});
int streak = data.eventCounters[EVENT_STREAK_COUNTER];
int negativeStreak = data.eventCounters[EVENT_NEGATIVE_STREAK_COUNTER];
std::string streakText = streak == 0 && negativeStreak != 0 ? "-" + std::to_string((unsigned int)negativeStreak)
: std::to_string((unsigned int)streak);
text_draw_centered(g_manager->font1_TeamMeatEx10, streakText, offset_add(origin, STREAK_TEXT_OFFSET));
if (Seeds::CountUnlockedSeedEffects() > 0) render_easter_eggs(origin);
if (seedUnlockPageState != SEED_UNLOCK_HIDDEN) render_seed_unlock();
}
// The seed widget: the hint and key to type a seed while there is none, else the seed, whole on the widget and in
// its two halves on the seed entry page.
void Menu_Character::render_seed_page(Vector origin)
{
Font& small = g_manager->font1_TeamMeatEx10;
Font& large = g_manager->font3_TeamMeatEx16;
if (seedText.empty())
{
layer_show(seedPageSprite, SEED_LAYER_HINT, true);
MenuOffset key =
g_manager->stringTable.language == SEED_KEY_SHIFT_LANGUAGE ? SEED_KEY_OFFSET_SHIFTED : SEED_KEY_OFFSET;
if (const AnimationFrame* frame = seedPageSprite.animState.GetLayerFrame(SEED_LAYER_KEY))
key = {key.x + frame->pos.x, key.y + frame->pos.y};
layer_show(seedPageSprite, SEED_LAYER_KEY, !is_action_glyph_rendered(ACTION_MENU_TAB, offset_add(origin, key)));
return;
}
layer_show(seedPageSprite, SEED_LAYER_HINT, false);
layer_show(seedPageSprite, SEED_LAYER_KEY, false);
text_draw_centered(small, seedText, offset_add(origin, SEED_TEXT_OFFSET));
float entryX = origin.x + MENU_WIDTH + SEED_ENTRY_TEXT_X;
text_draw(large, seedText.substr(0, SEED_HALF), vector_make(entryX, origin.y + SEED_ENTRY_TOP_Y), INK_ARGB);
if (seedText.size() > SEED_HALF + 1)
text_draw(large, seedText.substr(SEED_HALF + 1, SEED_HALF), vector_make(entryX, origin.y + SEED_ENTRY_BOTTOM_Y),
INK_ARGB);
}
// The special seeds widget: marked when the seeds turned on disallow achievements, with the key to open them and how
// many are on.
void Menu_Character::render_easter_eggs(Vector origin)
{
Seeds& seeds = g_menuManager->seedsObject;
eastereggPagePosition = offset_add(origin, EASTER_EGG_OFFSET);
layer_show(eastereggPageSprite, EGG_LAYER_NO_ACHIEVEMENTS, seeds.AchievementUnlocksDisallowed());
eastereggPageSprite.Render({eastereggPagePosition});
if (const NullFrame* icon = eastereggPageSprite.GetNullFrame(BUTTON_ICON_NULL))
layer_show(eastereggPageSprite, EGG_LAYER_KEY,
!is_action_glyph_rendered(ACTION_MENU_LB, vector_add(icon->pos, eastereggPagePosition)));
int count = seeds.CountSeedEffects();
if (count == 0) return;
text_draw(g_manager->font1_TeamMeatEx10, std::to_string(count), offset_add(eastereggPagePosition, EGG_COUNT_OFFSET),
EGG_COUNT_ARGB);
}
// The seed unlock page at the screen's center, naming the seed found once it is fully shown.
void Menu_Character::render_seed_unlock()
{
Vector center = vector_make(g_screenWidth * 0.5f, g_screenHeight * 0.5f);
Font& font = g_manager->font1_TeamMeatEx10;
seedUnlockPageSprite.Render({center});
if (seedUnlockPageState != SEED_UNLOCK_SHOWN) return;
std::string title = seedUnlockTitle;
std::transform(title.begin(), title.end(), title.begin(),
[](unsigned char letter) { return (char)std::toupper(letter); });
text_draw_centered(font, title, vector_make(center.x, center.y + UNLOCK_TITLE_Y));
text_draw_centered(font, seedUnlockName, center);
}
// 0094bbd0 Draws the selected character's page (a modded character's own), the wheel's portraits when asked, Eden's
// token count, and the blood stain of the hard difficulties fading in or out.
void Menu_Character::render_wheel(Vector wheelPosition, WheelPortraits portraits)
{
if (selectedCharacterID < CHARACTER_ENTRY_COUNT) bigCharPageSprite.Render({wheelPosition});
else
ModManager::RenderCustomCharacterMenu(GetPlayerTypeFromMenuID(selectedCharacterID, characterMenuShown),
wheelPosition, bigCharPageSprite);
if (portraits == WHEEL_WITH_PORTRAITS) render_portraits(wheelPosition, vector_make(0, 0), vector_make(1, 1));
if (selectedCharacterID == MENU_ID_EDEN)
{
std::string_view format = string_table_translate(g_manager->stringTable, EDEN_TOKENS_KEY);
std::array<char, 128> text{};
std::snprintf(text.data(), text.size(), std::string(format).c_str(),
g_manager->persistentGameData.eventCounters[EVENT_EDEN_TOKENS]);
text_draw_centered(g_manager->font2_TeamMeatEx12, text.data(), offset_add(wheelPosition, EDEN_TOKENS_OFFSET));
}
bool isHard = difficulty == DIFFICULTY_HARD || difficulty == DIFFICULTY_GREEDIER;
overlay_fade(difficultyOverlaySprite, menuBlackColorizeIntensity, isHard);
difficultyOverlaySprite.Render({wheelPosition});
}
// 00946d50 Sorts the wheel's portraits back to front by height, as the original's quicksort orders them.
void portrait_order_sort(std::vector<WheelPortrait>& order, int low, int high)
{
while (low < high)
{
float pivot = order[high].position.y;
int left = low;
int right = high;
do
{
while (order[left].position.y < pivot) left++;
while (pivot < order[right].position.y) right--;
if (order[left].position.y == order[right].position.y) left++;
else if (left < right) std::swap(order[left], order[right]);
else break;
}
while (left < right);
portrait_order_sort(order, low, right - 1);
low = right + 1;
}
}
// 0094bee0 Draws the wheel's portraits back to front, each scaled and faded toward the paper by its depth: the game's
// characters (darkened while locked), then the modded ones as their mods draw them.
// The original writes past the wheel when a character unlocked since it was shaped. Those wait for the next reset.
void Menu_Character::render_portraits(Vector wheelPosition, Vector offset, Vector scale)
{
int slot = 0;
portraitOrder.clear();
for (int i = 0; i < CHARACTER_ENTRY_COUNT && slot < numCharacters; i++)
if (is_on_wheel(i)) portraitOrder.push_back({portraitPositions[slot], portraitScales[slot++], i});
for (int visible = slot; slot < numCharacters; slot++)
portraitOrder.push_back(
{portraitPositions[slot], portraitScales[slot], CHARACTER_ENTRY_COUNT + slot - visible});
portrait_order_sort(portraitOrder, 0, numCharacters - 1);
for (const WheelPortrait& portrait : portraitOrder)
{
float fade = 1 - portrait.scale;
ColorMod color = {{portrait.scale, portrait.scale, portrait.scale, 1},
{0, 0, 0, 0},
{fade * PORTRAIT_FADE_RED / CHANNEL_MAX, fade * PORTRAIT_FADE_GREEN / CHANNEL_MAX,
fade * PORTRAIT_FADE_BLUE / CHANNEL_MAX}};
float portraitY = portrait.position.y * scale.y + offset.y + wheelPosition.y;
Vector portraitScale = vector_make(portrait.scale * scale.x, portrait.scale * scale.y);
if (portrait.menuId >= CHARACTER_ENTRY_COUNT)
{
ModSpriteDraw draw;
draw.color = color;
draw.position = vector_make(wheelPosition.x + offset.x + scale.x * portrait.position.x, portraitY);
draw.scale = portraitScale;
g_manager->modManager.RenderCustomCharacterPortraits(
GetPlayerTypeFromMenuID(portrait.menuId, characterMenuShown), draw);
continue;
}
const Menu_Character_Entry& entry = CHARACTER_ENTRIES[characterMenuShown][portrait.menuId];
characterPortraitsSprite.Play(entry.animationName, PLAY_FORCED);
characterPortraitsSprite.SetFrame(entry.IsCharacterAvailable() ? 0.0f : 1.0f);
characterPortraitsSprite.scale = portraitScale;
characterPortraitsSprite.color = color;
characterPortraitsSprite.Render(
{vector_make(scale.x * portrait.position.x + wheelPosition.x + offset.x, portraitY)});
}
}