Curation round 3: Lua engine, Manager, sound, menus, cutscenes, rooms, item pools, saves; boots past LuaEngine::Init
Seven agents took over LuaEngine (the mod API registration deferred), the rest of Manager (LoadConfigs, fonts, render surfaces, Update/Render), MusicManager/SFXManager, MenuManager with the title/save/game menus, Cutscene/NightmareScene/ Backdrop, RoomConfig (src/rooms ported and retired) with ItemPool, and PersistentGameData (the original binary save format) with InfoDisplay. An integration pass moved call sites to the new APIs, declared the taken-over free functions, fixed two data.cpp crashes (an empty children array, null attribute strings), and made the generator keep a header's own name where a prototype names another address. Clean build (0 warnings with -Wall -Wextra). build/isaac runs the game's Lua scripts (without the mod API yet) and stops at reload_resource_paths. 901 functions taken over, boot path 204/615. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7061306fa
commit
ddf913f304
137 files changed
+12684
-50687
No files matched your search
@@ -0,0 +1,776 @@
|
||||
#include "menu_manager.h"
|
||||
#include "kage_input.h"
|
||||
#include "log.h"
|
||||
#include "manager.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
constexpr const char* EMPTY_SCREEN_PNG = "gfx/ui/main menu/EmptyScreen.png";
|
||||
constexpr const char* MENU_OVERLAY_PNG = "gfx/ui/main menu/MenuOverlay.png";
|
||||
constexpr const char* MENU_SHADOW_ANM2 = "gfx/ui/main menu/MenuShadow.anm2";
|
||||
constexpr const char* FLY_ANM2 = "gfx/ui/main menu/fly.anm2";
|
||||
constexpr const char* ONLINE_STATS_ANM2 = "gfx/ui/main menu/OnlineStatsMenu.anm2";
|
||||
constexpr const char* COLOR_MOD_SURFACE = "Menu Colormod Surface";
|
||||
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
||||
constexpr const char* COLOR_MOD_SHADER = "ColorMod";
|
||||
constexpr const char* CURSOR_LAYER = "Cursor";
|
||||
|
||||
// Where each menu sits on the menu sheet, by MenuState. The special seeds' place moves and is kept apart.
|
||||
constexpr float VIEW_POSITIONS[MENU_COUNT][2] = {
|
||||
{0, 0}, {0, 0}, {0, -270}, {0, -540}, {-960, -810}, {0, -810}, {0, 0}, {480, -405},
|
||||
{0, -1080}, {480, -1350}, {-480, -1080}, {-480, -1755}, {-960, -1890}, {-480, -270}, {480, -1670}, {950, -290},
|
||||
{1440, -290}, {-960, -270}, {-960, -540}, {-480, -540}, {-960, -1350}, {-1440, -540}, {480, -2160}};
|
||||
constexpr float SPECIAL_SEEDS_VIEW_Y = -1350;
|
||||
constexpr float KEY_CONFIG_VIEW_Y = -1890;
|
||||
constexpr float OPTIONS_VIEW_Y = -1080;
|
||||
constexpr float ONLINE_OPTIONS_VIEW_Y = -1350;
|
||||
constexpr int OPTIONS_ROWS_ABOVE = 3;
|
||||
constexpr int OPTIONS_ROWS_BELOW = 4;
|
||||
constexpr float OPTIONS_ROW_HEIGHT = 20;
|
||||
constexpr float VIEW_SNAP_DISTANCE = 1;
|
||||
constexpr float VIEW_EASE = 0.1f;
|
||||
constexpr float VIEW_STEP_MIN = 1;
|
||||
|
||||
constexpr float FLY_DRIFT = 0.004f;
|
||||
constexpr float FLY_X = 364;
|
||||
constexpr float FLY_Y = 176;
|
||||
constexpr int FLY_FLAP_FRAMES = 80;
|
||||
constexpr float FLY_HEIGHT = 8;
|
||||
constexpr float FLY_SHADOW_SCALE = 0.4f;
|
||||
constexpr float TAU = 6.2831855f;
|
||||
constexpr int FLY_LAYER = 0;
|
||||
constexpr int FLY_SHADOW_LAYER = 1;
|
||||
|
||||
constexpr float FADE_STEP = 0.025f;
|
||||
constexpr int MUSIC_TITLE_REPENTANCE = 63;
|
||||
constexpr int MUSIC_JINGLE_GAME_START_ALT = 64;
|
||||
constexpr int MUSIC_JINGLE_GAME_START = 95;
|
||||
constexpr float WIDGET_OFFSET_Y = 90;
|
||||
constexpr float BUTTON_SHOWN = 0;
|
||||
constexpr float BUTTON_RAISED = 25;
|
||||
constexpr float BUTTON_HIDDEN = 96;
|
||||
constexpr int DIFFICULTY_HARD = 1;
|
||||
constexpr int DIFFICULTY_GREEDIER = 3;
|
||||
constexpr float VIGNETTE_HARD = 0.5f;
|
||||
constexpr float SHADOW_HEIGHT = 148;
|
||||
constexpr float OVERLAY_BLEED = 0.5f;
|
||||
constexpr uint32_t MENU_BACKGROUND_ARGB = 0xffccbebb;
|
||||
constexpr uint32_t WHITE_ARGB = 0xffffffff;
|
||||
constexpr uint32_t BLACK_ARGB = 0xff000000;
|
||||
constexpr float CHANNEL_MAX = 255;
|
||||
constexpr int CLAMP_TO_EDGE = 1;
|
||||
constexpr int FILTER_LINEAR = 1;
|
||||
constexpr int KEY_REPEAT_DELAY = 49;
|
||||
constexpr int KEY_REPEAT_INTERVAL = 10;
|
||||
constexpr int CHARACTER_MENU_SHOWN = 1;
|
||||
constexpr int MUSIC_LAYER_CHARACTER = 0;
|
||||
constexpr int OPTIONS_NOT_PAUSED = 0;
|
||||
|
||||
KAGE::Graphics::ImagePtr menuColorModSurface;
|
||||
|
||||
// A color from its channels. KColor declares a constructor it does not define yet, so it is built member by member.
|
||||
KColor kcolor_make(float red, float green, float blue, float alpha)
|
||||
{
|
||||
KColor color;
|
||||
color._red = red;
|
||||
color._green = green;
|
||||
color._blue = blue;
|
||||
color._alpha = alpha;
|
||||
color._unk = 0;
|
||||
return color;
|
||||
}
|
||||
|
||||
// A color from packed ARGB bytes, as KColor::SetFromARGB unpacks them.
|
||||
KColor kcolor_argb(uint32_t argb)
|
||||
{
|
||||
auto channel = [argb](int shift) { return (float)((argb >> shift) & 0xff) / CHANNEL_MAX; };
|
||||
return kcolor_make(channel(16), channel(8), channel(0), channel(24));
|
||||
}
|
||||
|
||||
Vector vector_add(Vector a, Vector b)
|
||||
{
|
||||
return vector_make(a.x + b.x, a.y + b.y);
|
||||
}
|
||||
|
||||
// Whether a device's default bindings meet the test for an action: KeyConfigs' saved bindings and the analog action
|
||||
// values the device keeps are not taken over yet.
|
||||
static bool is_device_action(const KAGE::Input::InputDevice& device, ButtonAction action, ActionTest test)
|
||||
{
|
||||
const InputBindings& bindings = platform.bindings;
|
||||
const std::vector<ActionBinding>& table =
|
||||
device.type == KAGE::Input::DEVICE_KEYBOARD ? bindings.keyboard : bindings.controller;
|
||||
|
||||
if (!device.isConnected || action >= (int)table.size()) return false;
|
||||
for (int button : table[action])
|
||||
{
|
||||
if (button == KAGE::Input::BUTTON_NONE) continue;
|
||||
if (test == ACTION_TRIGGERED ? device.is_button_triggered(button) : device.is_button_pressed(button)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether any device has the action held or pressed this frame, giving the first such device's index, as KAGE's
|
||||
// input manager asks every device in turn (its query slot with the pressed or triggered test).
|
||||
bool is_action(ButtonAction action, ActionTest test, int* deviceIndex)
|
||||
{
|
||||
KAGE::Input::Manager& input = KAGE::Input::manager;
|
||||
|
||||
for (int i = 0; i < input.get_device_count(); i++)
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = input.get_device(i);
|
||||
if (!device || !is_device_action(*device, action, test)) continue;
|
||||
|
||||
if (deviceIndex) *deviceIndex = i;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether a held direction acts this frame: on the first frame, then every tenth once held past the delay.
|
||||
bool is_key_repeat(int heldFrames)
|
||||
{
|
||||
return heldFrames == 0 || (heldFrames > KEY_REPEAT_DELAY && heldFrames % KEY_REPEAT_INTERVAL == 0);
|
||||
}
|
||||
|
||||
// Plays a menu sound at full volume, unless the seeds swap it for a fart.
|
||||
void menu_sound_play(int sound, int frameDelay)
|
||||
{
|
||||
int id = sound;
|
||||
SoundPlay play;
|
||||
|
||||
play.frameDelay = frameDelay;
|
||||
seed_fart_sound_override(&id);
|
||||
g_manager->sfxManager.Play(id, play);
|
||||
}
|
||||
|
||||
// Makes one of the game's shaders current when it is loaded, as the game picks them by their place in its list.
|
||||
void shader_select(std::string_view shaderName)
|
||||
{
|
||||
KAGE::Graphics::Shader* shader = KAGE::Graphics::manager.shader_find(shaderName);
|
||||
if (shader) KAGE::Graphics::manager.currentShader = shader;
|
||||
}
|
||||
|
||||
// 00987360 Creates the screen-sized surface the menus and the game render into for the color modifier, once.
|
||||
void color_mod_surface_create()
|
||||
{
|
||||
if (menuColorModSurface) return;
|
||||
|
||||
KAGE::Graphics::RenderTargetDesc desc;
|
||||
desc.clearColor = kcolor_argb(0);
|
||||
desc.name = COLOR_MOD_SURFACE;
|
||||
desc.width = g_framebufferWidth;
|
||||
desc.height = (int)DAT_00c79114;
|
||||
menuColorModSurface = KAGE::Graphics::manager.render_target_create(desc);
|
||||
if (menuColorModSurface->wrapS != CLAMP_TO_EDGE || menuColorModSurface->wrapT != CLAMP_TO_EDGE)
|
||||
menuColorModSurface->wrap_set(CLAMP_TO_EDGE, CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
// A fresh run's seeds, as Seeds' constructor builds them. Seeds is not taken over yet, and classes.h gives its
|
||||
// constructor no object to build.
|
||||
static void seeds_reset(Seeds&)
|
||||
{
|
||||
reconstruction_missing("Seeds::constructor 009e9290 on MenuManager::seedsObject");
|
||||
}
|
||||
|
||||
// 00986450 Builds the menus with the view at the sheet's origin and the color modifier off, then the surface it renders
|
||||
// through. The other menus' construction, inlined here, is theirs: the ones classes.h declares run here.
|
||||
MenuManager::MenuManager()
|
||||
{
|
||||
fadeInColor = kcolor_argb(BLACK_ARGB);
|
||||
specialSeedsViewPosition = vector_make(0, SPECIAL_SEEDS_VIEW_Y);
|
||||
seeds_reset(seedsObject);
|
||||
Leaderboard::constructor();
|
||||
menuCharacter.constructor();
|
||||
menuOptions.constructor();
|
||||
reconstruction_missing("MenuManager::MenuManager 00986450: the online menus' construction, inlined");
|
||||
onlineOptions.constructor();
|
||||
color_mod_surface_create();
|
||||
}
|
||||
|
||||
// 00986f30 Frees the menus. Own members free themselves, and so do the other menus classes.h gives a destructor.
|
||||
// The ones it gives a plain destructor method free here, in the original order.
|
||||
MenuManager::~MenuManager()
|
||||
{
|
||||
FUN_008dc3c0();
|
||||
FUN_008e7630();
|
||||
FUN_008e4a20();
|
||||
FUN_008c5d70();
|
||||
FUN_008c9e10();
|
||||
Menu_Collection::destructor();
|
||||
Menu_Challenge::destructor();
|
||||
FUN_008f0120();
|
||||
menuCharacter.destructor();
|
||||
FUN_008cf510();
|
||||
}
|
||||
|
||||
// Where a menu's view lands: its place on the sheet, the menu area centered in the screen.
|
||||
Vector MenuManager::view_target_get(MenuState menu)
|
||||
{
|
||||
Vector place = viewPositionSet[menu];
|
||||
return vector_make((g_screenWidth - MENU_WIDTH) * 0.5f + place.x, (g_screenHeight - MENU_HEIGHT) * 0.5f + place.y);
|
||||
}
|
||||
|
||||
// Where a menu draws from on the sheet: the opposite of its view place.
|
||||
Vector MenuManager::menu_position_get(MenuState menu)
|
||||
{
|
||||
return vector_make(-viewPositionSet[menu].x, -viewPositionSet[menu].y);
|
||||
}
|
||||
|
||||
// Where a menu at a sheet position draws in the current view.
|
||||
SpriteDraw MenuManager::menu_draw_get(Vector position)
|
||||
{
|
||||
SpriteDraw draw;
|
||||
draw.position = vector_add(viewPosition, position);
|
||||
return draw;
|
||||
}
|
||||
|
||||
// 00987450 Opens the menus on nothing selected with the title music, lays the menus out on the sheet, loads the overlay,
|
||||
// the shadow and the fly, then each menu in turn. The menus after the game menu are not taken over yet.
|
||||
void MenuManager::Init()
|
||||
{
|
||||
Manager& manager = *g_manager;
|
||||
|
||||
selectedMenuId = MENU_NONE;
|
||||
log_printf(LOG_INFO, "Menu Manager preCrossfade\n");
|
||||
manager.musicManager.Crossfade(MUSIC_TITLE_REPENTANCE, MUSIC_FADE_RATE);
|
||||
if (manager.persistentGameData.characterMenuShown == CHARACTER_MENU_SHOWN)
|
||||
manager.musicManager.EnableLayer(MUSIC_LAYER_CHARACTER, LAYER_INSTANT);
|
||||
log_printf(LOG_INFO, "Menu Manager Init\n");
|
||||
manager.popupButtons.reset(0);
|
||||
seeds_reset(seedsObject);
|
||||
|
||||
for (int i = 0; i < MENU_COUNT; i++) viewPositionSet[i] = vector_make(VIEW_POSITIONS[i][0], VIEW_POSITIONS[i][1]);
|
||||
viewPositionSet[MENU_SPECIAL_SEEDS] = specialSeedsViewPosition;
|
||||
viewPosition = view_target_get(selectedMenuId);
|
||||
|
||||
// The original draws the overlay without checking it loaded. A missing one is skipped instead.
|
||||
emptyScreenImage = KAGE::Graphics::manager.image_load(EMPTY_SCREEN_PNG);
|
||||
menuOverlayImage = KAGE::Graphics::manager.image_load(MENU_OVERLAY_PNG);
|
||||
if (menuOverlayImage && (menuOverlayImage->minFilter != FILTER_LINEAR || menuOverlayImage->magFilter != FILTER_LINEAR))
|
||||
menuOverlayImage->filter_set(FILTER_LINEAR, FILTER_LINEAR);
|
||||
menuShadowSprite.Load(MENU_SHADOW_ANM2, GRAPHICS_LOAD);
|
||||
menuShadowSprite.Play(ANIMATION_IDLE);
|
||||
flySprite.Load(FLY_ANM2, GRAPHICS_LOAD);
|
||||
flySprite.Play(ANIMATION_IDLE);
|
||||
|
||||
log_printf(LOG_INFO, "Menu Title Init\n");
|
||||
menuTitle.Init(menu_position_get(MENU_TITLE));
|
||||
log_printf(LOG_INFO, "Menu Save Init\n");
|
||||
menuSave.Init(menu_position_get(MENU_SAVE));
|
||||
log_printf(LOG_INFO, "Menu Game Init\n");
|
||||
menuGame.Init(menu_position_get(MENU_GAME));
|
||||
log_printf(LOG_INFO, "Menu Daily Init\n");
|
||||
reconstruction_missing("MenuManager::Init 00987450: the Init of the menus from Menu_DailyChallenge on, inlined");
|
||||
|
||||
isViewMoving = false;
|
||||
isFadeOutActive = false;
|
||||
fadeOutProgress = 0;
|
||||
isFadeInActive = false;
|
||||
fadeInProgress = 1;
|
||||
vignetteIntensity = 0;
|
||||
backWidgetOffsetY = WIDGET_OFFSET_Y;
|
||||
selectWidgetOffsetY = WIDGET_OFFSET_Y;
|
||||
isPopupButtonsShown = true;
|
||||
}
|
||||
|
||||
// 00988ba0 Drops every menu's sprites, as a run starts.
|
||||
void MenuManager::unload_graphics()
|
||||
{
|
||||
menuTitle.titleScreenSprite.Reset();
|
||||
menuSave.unload_graphics();
|
||||
menuGame.gameMenuSprite.Reset();
|
||||
menuGame.continueWidgetSprite.Reset();
|
||||
reconstruction_missing("MenuManager::unload_graphics 00988ba0: the other menus' sprites, inlined");
|
||||
onlineStatsMenuSprite.Reset();
|
||||
}
|
||||
|
||||
// 00988d80 Loads every menu's sprites again, as the menus come back.
|
||||
void MenuManager::LoadGraphics()
|
||||
{
|
||||
menuTitle.sprite_load();
|
||||
menuTitle.load_graphics();
|
||||
menuSave.LoadGraphics();
|
||||
menuGame.LoadGraphics();
|
||||
menuCharacter.LoadGraphics();
|
||||
reconstruction_missing("MenuManager::LoadGraphics 00988d80: the other menus' sprites, inlined");
|
||||
onlineStatsMenuSprite.Load(ONLINE_STATS_ANM2, GRAPHICS_LOAD);
|
||||
onlineStatsMenuSprite.Play(ANIMATION_IDLE);
|
||||
}
|
||||
|
||||
// 00989750 Fades the menus out into the run to the start jingle, loading the loading screen for the start seed.
|
||||
void MenuManager::start_game(KColor fadeColor)
|
||||
{
|
||||
Manager& manager = *g_manager;
|
||||
bool isCharacterMenuShown = manager.persistentGameData.characterMenuShown == CHARACTER_MENU_SHOWN;
|
||||
|
||||
fadeInColor = fadeColor;
|
||||
isFadeOutActive = true;
|
||||
input_poll_active_device();
|
||||
manager.musicManager.Crossfade(isCharacterMenuShown ? MUSIC_JINGLE_GAME_START_ALT : MUSIC_JINGLE_GAME_START,
|
||||
MUSIC_FADE_RATE);
|
||||
if (seedsObject._gameStartSeed == 0) log_printf(LOG_ASSERT, "Error: Game Start Seed was not set.\n");
|
||||
loading_images_load();
|
||||
}
|
||||
|
||||
// Eases the view toward the selected menu's place, a tenth of the way and at least a point each frame, snapping
|
||||
// within a point, or holds it there once it arrived.
|
||||
void MenuManager::view_update()
|
||||
{
|
||||
Vector target = view_target_get(selectedMenuId);
|
||||
if (!isViewMoving)
|
||||
{
|
||||
viewPosition = target;
|
||||
return;
|
||||
}
|
||||
|
||||
float gapX = target.x - viewPosition.x;
|
||||
float gapY = target.y - viewPosition.y;
|
||||
float distance = std::sqrt(gapX * gapX + gapY * gapY);
|
||||
if (distance <= VIEW_SNAP_DISTANCE)
|
||||
{
|
||||
viewPosition = target;
|
||||
isViewMoving = false;
|
||||
return;
|
||||
}
|
||||
|
||||
float step = std::max(VIEW_STEP_MIN, distance * VIEW_EASE);
|
||||
viewPosition.y = step * (gapY * (1 / distance)) + viewPosition.y;
|
||||
viewPosition.x = step * (gapX * (1 / distance)) + viewPosition.x;
|
||||
}
|
||||
|
||||
// Flies the title fly off the farther the view is from the title, flapping it and its shadow.
|
||||
void MenuManager::fly_update()
|
||||
{
|
||||
Vector title = view_target_get(MENU_TITLE);
|
||||
float gapX = title.x - viewPosition.x;
|
||||
float gapY = title.y - viewPosition.y;
|
||||
float distance = std::sqrt(gapY * gapY + gapX * gapX);
|
||||
float flap = std::sin((float)(g_manager->framecount % FLY_FLAP_FRAMES) * TAU / FLY_FLAP_FRAMES) + FLY_HEIGHT;
|
||||
|
||||
scrollInterpolationY = distance * FLY_DRIFT + FLY_Y + viewPositionSet[MENU_TITLE].y;
|
||||
scrollInterpolationX = distance * FLY_DRIFT * distance + FLY_X + viewPositionSet[MENU_TITLE].x;
|
||||
flySprite.GetLayer(FLY_LAYER)->pos.y = -flap;
|
||||
LayerState* shadow = flySprite.GetLayer(FLY_SHADOW_LAYER);
|
||||
shadow->pos.x = flap * FLY_SHADOW_SCALE;
|
||||
shadow->pos.y = flap * FLY_SHADOW_SCALE;
|
||||
flySprite.Update();
|
||||
}
|
||||
|
||||
// Hides the popup buttons once the menu controller is used past the save menu, then hands the menus to whichever
|
||||
// device pressed something, except while keys are being bound.
|
||||
void MenuManager::controller_update()
|
||||
{
|
||||
KAGE::Input::Manager& input = KAGE::Input::manager;
|
||||
|
||||
if (isPopupButtonsShown && selectedMenuId > MENU_TITLE && input.is_device_connected(g_menuControllerIndex) &&
|
||||
(!isViewMoving || selectedMenuId > MENU_SAVE))
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = input.get_device(g_menuControllerIndex);
|
||||
if (device && device->is_any_pressed()) isPopupButtonsShown = false;
|
||||
}
|
||||
if (selectedMenuId == MENU_KEY_CONFIG) return;
|
||||
|
||||
for (int i = 0; i < input.get_device_count(); i++)
|
||||
{
|
||||
std::shared_ptr<KAGE::Input::InputDevice> device = input.get_device(i);
|
||||
if (device && device->button_triggered_get() != KAGE::Input::BUTTON_NONE) g_menuControllerIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
// 009897d0 Steps the menus: the shadow, the fly, the view, the controller, the fades, then the selected menu and the
|
||||
// color modifier's easing.
|
||||
void MenuManager::Update()
|
||||
{
|
||||
menuShadowSprite.Update();
|
||||
fly_update();
|
||||
view_update();
|
||||
controller_update();
|
||||
if (isFadeOutActive) fadeOutProgress += FADE_STEP;
|
||||
if (isFadeInActive) fadeInProgress -= FADE_STEP;
|
||||
if (selectedMenuId == MENU_NONE) return;
|
||||
|
||||
menu_update();
|
||||
color_mod_update();
|
||||
}
|
||||
|
||||
// Steps the selected menu.
|
||||
void MenuManager::menu_update()
|
||||
{
|
||||
switch (selectedMenuId)
|
||||
{
|
||||
case MENU_TITLE: menuTitle.Update(); break;
|
||||
case MENU_SAVE: menuSave.Update(); break;
|
||||
case MENU_GAME: menuGame.Update(); break;
|
||||
case MENU_DAILY_RUN: menuDailyChallenge.Update(); break;
|
||||
case MENU_CHARACTER: menuCharacter.Update(); break;
|
||||
case MENU_SPECIAL_SEEDS: menuSpecialSeeds.Update(); break;
|
||||
case MENU_CHALLENGE: Menu_Challenge::Update(); break;
|
||||
case MENU_COLLECTION: Menu_Collection::Update(); break;
|
||||
case MENU_STATS: menuStats.Update(); break;
|
||||
case MENU_OPTIONS: menuOptions.Update(); break;
|
||||
case MENU_CONTROLLER_SELECT: Menu_ControllerSelect::Update(); break;
|
||||
case MENU_KEY_CONFIG: menuKeyConfig.Update(); break;
|
||||
case MENU_CUTSCENES: Menu_Cutscenes::Update(); break;
|
||||
case MENU_BESTIARY: menuBestiary.Update(); break;
|
||||
case MENU_CUSTOM_CHALLENGE: menuCustomChallenge.Update(); break;
|
||||
case MENU_MODS: menuMods.Update(); break;
|
||||
case MENU_ONLINE_LOBBY: Menu_OnlineLobby::Update(); break;
|
||||
case MENU_ONLINE_LOBBY_LIST: menuOnlineLobbyList.Update(); break;
|
||||
case MENU_ONLINE: menuOnline.Update(); break;
|
||||
case MENU_ONLINE_OPTIONS: onlineOptions.Update(); break;
|
||||
case MENU_CREATE_LOBBY: reconstruction_missing("Menu_OnlineMode::Update 008cbfe0 on MenuManager::menuCreateLobby");
|
||||
case MENU_ONLINE_AWARDS:
|
||||
if ((g_manager->framecount & 1) == 0) onlineStatsMenuSprite.Update();
|
||||
Menu_OnlineAwards::Update();
|
||||
onlineStatsMenuSprite.SetLayerFrame(CURSOR_LAYER, onlineAwardsCursor);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Eases the color modifier toward its target while asked to, stopping once it is there.
|
||||
void MenuManager::color_mod_update()
|
||||
{
|
||||
if (!isColorModLerping) return;
|
||||
|
||||
ColorModState& current = currentColorModState;
|
||||
const ColorModState& target = targetColorModState;
|
||||
current.move_toward(&targetColorModState._red, &lerpColorModState._red);
|
||||
if (current._red == target._red && current._green == target._green && current._blue == target._blue &&
|
||||
current._amount == target._amount && current._brightness == target._brightness &&
|
||||
current._contrast == target._contrast)
|
||||
isColorModLerping = false;
|
||||
}
|
||||
|
||||
// 0098a040 Draws the menu sheet over its paper color: every menu at its place, the fly, then the overlay, the shadow
|
||||
// and the vignette, all through the color modifier when it is on, then the fades.
|
||||
void MenuManager::Render()
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
bool isColorModifierEnabled = g_manager->optionsConfig.render.isColorModifierEnabled;
|
||||
|
||||
if (isColorModifierEnabled)
|
||||
graphics.render_target_push(menuColorModSurface.get(), KAGE::Graphics::TARGET_SCREEN_SIZE,
|
||||
KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.Clear();
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
KAGE::Graphics::ColorQuad paper = KAGE::Graphics::color_quad_rect(
|
||||
vector_make(0, 0), vector_make(g_screenWidth, g_screenHeight), kcolor_argb(MENU_BACKGROUND_ARGB));
|
||||
render_color_shader_pass(&paper);
|
||||
|
||||
menuTitle.Render();
|
||||
menuChallenge.Render();
|
||||
menuDailyChallenge.Render();
|
||||
menuCollection.Render();
|
||||
menuBestiary.Render();
|
||||
menuStats.Render();
|
||||
menuCharacter.Render();
|
||||
menuGame.Render();
|
||||
menuSpecialSeeds.Render();
|
||||
menuControllerSelect.Render();
|
||||
menuKeyConfig.Render();
|
||||
menuOptions.Render();
|
||||
Menu_Cutscenes::Render();
|
||||
menuCustomChallenge.Render();
|
||||
reconstruction_missing("Menu_Mods::Render 008e3db0 (AnimationLayer::RenderFrame in classes.h) and the lobby menus' "
|
||||
"Render 008ddae0 and 008e8af0");
|
||||
menuOnline.Render();
|
||||
onlineOptions.Render();
|
||||
Menu_Online::render_mode_select();
|
||||
Menu_Online::render_descriptions();
|
||||
menuSave.Render();
|
||||
reconstruction_missing("Leaderboard::Render 00858050 on Menu_DailyChallenge's leaderboard");
|
||||
flySprite.Render(menu_draw_get(vector_make(scrollInterpolationX, scrollInterpolationY)));
|
||||
|
||||
popup_buttons_place();
|
||||
vignette_update();
|
||||
overlay_render();
|
||||
if (isColorModifierEnabled) color_mod_render();
|
||||
graphics.shader_default_set();
|
||||
fades_render();
|
||||
}
|
||||
|
||||
// Slides the popup buttons (back and select) to where the selected menu shows them, or away.
|
||||
void MenuManager::popup_buttons_place()
|
||||
{
|
||||
PopupButton* buttons = g_manager->popupButtons._buttons;
|
||||
|
||||
if (!isPopupButtonsShown || selectedMenuId == MENU_TITLE)
|
||||
{
|
||||
buttons[0]._targetSlideOffset = BUTTON_HIDDEN;
|
||||
buttons[1]._targetSlideOffset = BUTTON_HIDDEN;
|
||||
return;
|
||||
}
|
||||
switch (selectedMenuId)
|
||||
{
|
||||
case MENU_SAVE:
|
||||
case MENU_GAME:
|
||||
case MENU_CHARACTER:
|
||||
case MENU_SPECIAL_SEEDS:
|
||||
case MENU_CHALLENGE:
|
||||
case MENU_OPTIONS:
|
||||
case MENU_CONTROLLER_SELECT:
|
||||
case MENU_KEY_CONFIG:
|
||||
buttons[0]._targetSlideOffset = BUTTON_SHOWN;
|
||||
buttons[1]._targetSlideOffset = BUTTON_SHOWN;
|
||||
break;
|
||||
case MENU_DAILY_RUN:
|
||||
case MENU_COLLECTION:
|
||||
case MENU_CUTSCENES:
|
||||
case MENU_BESTIARY:
|
||||
buttons[0]._targetSlideOffset = BUTTON_RAISED;
|
||||
buttons[1]._targetSlideOffset = BUTTON_HIDDEN;
|
||||
break;
|
||||
case MENU_STATS:
|
||||
buttons[0]._targetSlideOffset = BUTTON_SHOWN;
|
||||
buttons[1]._targetSlideOffset = menuStats._isAchievementScreenVisible ? BUTTON_HIDDEN : BUTTON_SHOWN;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
// Darkens the edges toward half on the hard difficulties, a fortieth a frame.
|
||||
void MenuManager::vignette_update()
|
||||
{
|
||||
int difficulty = menuCharacter.Difficulty;
|
||||
float target = difficulty == DIFFICULTY_HARD || difficulty == DIFFICULTY_GREEDIER ? VIGNETTE_HARD : 0;
|
||||
|
||||
if (std::abs(vignetteIntensity - target) > FADE_STEP)
|
||||
target = target <= vignetteIntensity ? vignetteIntensity - FADE_STEP : vignetteIntensity + FADE_STEP;
|
||||
vignetteIntensity = target;
|
||||
}
|
||||
|
||||
// Draws the overlay over the whole screen, the shadow along its bottom, and the overlay again as the vignette.
|
||||
// The original also tints the shadow by the vignette for the second pass and puts it back after. Nothing draws the
|
||||
// shadow in between, so that is left out.
|
||||
void MenuManager::overlay_render()
|
||||
{
|
||||
Vector origin = vector_make(-OVERLAY_BLEED, -OVERLAY_BLEED);
|
||||
Vector size = vector_make(g_screenWidth + OVERLAY_BLEED, g_screenHeight + OVERLAY_BLEED);
|
||||
KColor white = kcolor_argb(WHITE_ARGB);
|
||||
KColor unset = kcolor_make(-1, -1, -1, -1);
|
||||
ColorMod plain = COLOR_DEFAULT;
|
||||
|
||||
shader_select(COLOR_OFFSET_SHADER);
|
||||
if (menuOverlayImage)
|
||||
{
|
||||
apply_sprite_shader_params(&plain, 1, menuOverlayImage.get(), nullptr);
|
||||
menuOverlayImage->Render(KAGE::Graphics::color_quad_rect(origin, size, white), unset);
|
||||
}
|
||||
|
||||
SpriteDraw shadowDraw;
|
||||
shadowDraw.position = vector_make(0, g_screenHeight - SHADOW_HEIGHT);
|
||||
menuShadowSprite.Render(shadowDraw);
|
||||
if (vignetteIntensity <= 0 || !menuOverlayImage) return;
|
||||
|
||||
shader_select(COLOR_OFFSET_SHADER);
|
||||
apply_sprite_shader_params(&plain, 1, menuOverlayImage.get(), nullptr);
|
||||
menuOverlayImage->Render(KAGE::Graphics::color_quad_rect(origin, size, white),
|
||||
kcolor_make(1, 1, 1, vignetteIntensity));
|
||||
}
|
||||
|
||||
// Draws the surface the menus went into onto the screen through the color modifier shader, opaque, tinted by the
|
||||
// modifier's color.
|
||||
void MenuManager::color_mod_render()
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
KAGE::Graphics::Shader* shader = nullptr;
|
||||
|
||||
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
||||
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
||||
graphics.Clear();
|
||||
shader_select(COLOR_MOD_SHADER);
|
||||
graphics.blendMode = KAGE::Graphics::BLEND_MODE_OPAQUE;
|
||||
shader = graphics.currentShader;
|
||||
if (shader)
|
||||
{
|
||||
shader->set_uniform("Amount", KAGE::Graphics::UNIFORM_FLOAT, ¤tColorModState._amount);
|
||||
shader->set_uniform("Brightness", KAGE::Graphics::UNIFORM_FLOAT, ¤tColorModState._brightness);
|
||||
shader->set_uniform("Contrast", KAGE::Graphics::UNIFORM_FLOAT, ¤tColorModState._contrast);
|
||||
}
|
||||
|
||||
SourceQuad whole = KAGE::Graphics::source_quad_rect(vector_make(0, 0), vector_make(1, 1));
|
||||
whole._coordinateSpace = KAGE::Graphics::COORDINATES_NORMALIZED;
|
||||
KAGE::Graphics::ColorQuad screen = KAGE::Graphics::color_quad_rect(
|
||||
vector_make(0, 0), vector_make(g_screenWidth, g_screenHeight), kcolor_argb(WHITE_ARGB));
|
||||
menuColorModSurface->Render(whole, screen,
|
||||
kcolor_make(currentColorModState._red, currentColorModState._green,
|
||||
currentColorModState._blue, 1));
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
}
|
||||
|
||||
// Darkens the screen as the menus fade out into the run, with the loading icon, and fades the screen in from the
|
||||
// fade color, ending the fade in once it is clear.
|
||||
void MenuManager::fades_render()
|
||||
{
|
||||
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
||||
Vector origin = vector_make(0, 0);
|
||||
Vector size = vector_make(g_screenWidth, g_screenHeight);
|
||||
|
||||
if (isFadeOutActive)
|
||||
{
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
KAGE::Graphics::ColorQuad dark = KAGE::Graphics::color_quad_rect(origin, size, kcolor_make(0, 0, 0, fadeOutProgress));
|
||||
render_color_shader_pass(&dark);
|
||||
Manager::render_loading_icon(fadeOutProgress);
|
||||
}
|
||||
if (!isFadeInActive) return;
|
||||
|
||||
graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL);
|
||||
KColor color = fadeInColor;
|
||||
color._alpha = fadeInProgress;
|
||||
KAGE::Graphics::ColorQuad fade = KAGE::Graphics::color_quad_rect(origin, size, color);
|
||||
render_color_shader_pass(&fade);
|
||||
if (fadeInProgress > 0) return;
|
||||
|
||||
isFadeInActive = false;
|
||||
fadeInProgress = 0;
|
||||
}
|
||||
|
||||
// The history leading to a menu: the title, the save files and the game menu as far as the menu is from them, then the
|
||||
// online menu before the lobby.
|
||||
void MenuManager::history_rebuild(MenuState state)
|
||||
{
|
||||
if (!menuStateHistory.empty() && menuStateHistory.back() == MENU_DAILY_RUN) FUN_008d0730();
|
||||
|
||||
menuStateHistory.clear();
|
||||
for (int menu = MENU_TITLE; menu <= state && menu <= MENU_GAME; menu++) menuStateHistory.push_back((MenuState)menu);
|
||||
if (state <= MENU_GAME) return;
|
||||
|
||||
if (state == MENU_ONLINE_LOBBY)
|
||||
{
|
||||
menuStateHistory.push_back(MENU_ONLINE);
|
||||
menuStateHistory.push_back(MENU_ONLINE_LOBBY);
|
||||
}
|
||||
else if (state == MENU_ONLINE) menuStateHistory.push_back(MENU_ONLINE);
|
||||
else log_printf(LOG_ASSERT, "Unhandled Menu State trying to create a menu stack");
|
||||
}
|
||||
|
||||
// 0098aa30 Switches to a menu, turning the page with the view moving, and lets the menus left and entered reset.
|
||||
// Leaving or entering the special seeds resets them.
|
||||
void MenuManager::SetState(MenuState state, MenuHistory history)
|
||||
{
|
||||
MenuState previous = selectedMenuId;
|
||||
|
||||
if (history == HISTORY_REBUILD) history_rebuild(state);
|
||||
else if (menuStateHistory.empty() && state != MENU_TITLE)
|
||||
log_printf(LOG_WARN, "Setting the intitial menu state to %d, are you sure about that? \n", state);
|
||||
|
||||
if (previous != MENU_NONE && state != MENU_NONE)
|
||||
{
|
||||
menu_sound_play(SOUND_BOOK_PAGE_TURN_12, 0);
|
||||
isViewMoving = true;
|
||||
}
|
||||
SeedsEntry entry = transition_apply(previous, state);
|
||||
if (previous == MENU_SPECIAL_SEEDS || (entry == SEEDS_ENTRY_RESET && state == MENU_SPECIAL_SEEDS))
|
||||
menuSpecialSeeds.Reset();
|
||||
selectedMenuId = state;
|
||||
}
|
||||
|
||||
// What leaving one menu for another does, and whether entering the special seeds resets them on this path.
|
||||
SeedsEntry MenuManager::transition_apply(MenuState previous, MenuState state)
|
||||
{
|
||||
if (previous == MENU_MODS && state == MENU_GAME)
|
||||
{
|
||||
reconstruction_missing("MenuManager::SetState 0098aa30: Menu_Mods' changed flag, inlined");
|
||||
g_manager->modManager.Reset();
|
||||
FUN_00959fa0();
|
||||
}
|
||||
else if (previous == MENU_SAVE && state == MENU_GAME)
|
||||
{
|
||||
menuCharacter.Reset();
|
||||
menuGame.Reset();
|
||||
seedsObject.ClearSeedEffects();
|
||||
return SEEDS_ENTRY_KEEP;
|
||||
}
|
||||
else if (previous == MENU_CHARACTER)
|
||||
{
|
||||
menuCharacter._seedUnlockPageState = 0;
|
||||
menuCharacter._seedUnlockPageTimer = 0;
|
||||
reconstruction_missing("MenuManager::SetState 0098aa30: clearing Menu_Character's seed entry texts, inlined");
|
||||
return SEEDS_ENTRY_RESET;
|
||||
}
|
||||
return transition_other_apply(previous, state);
|
||||
}
|
||||
|
||||
// The resets of every other switch. Entering the special seeds resets them unless the entered menu reset itself.
|
||||
SeedsEntry MenuManager::transition_other_apply(MenuState previous, MenuState state)
|
||||
{
|
||||
if (state == MENU_CHALLENGE || previous == MENU_CHALLENGE)
|
||||
{
|
||||
menuChallenge.reset();
|
||||
return SEEDS_ENTRY_RESET;
|
||||
}
|
||||
if (previous == MENU_KEY_CONFIG)
|
||||
{
|
||||
menuKeyConfig.SelectedElement = 0;
|
||||
menuKeyConfig.SelectedColumn = 0;
|
||||
menuKeyConfig.State = 0;
|
||||
viewPositionSet[MENU_KEY_CONFIG].y = KEY_CONFIG_VIEW_Y;
|
||||
isViewMoving = true;
|
||||
return SEEDS_ENTRY_RESET;
|
||||
}
|
||||
if (previous == MENU_GAME && state == MENU_SAVE)
|
||||
{
|
||||
int index = (int)g_manager->currentSaveSlot - 1;
|
||||
menuSave.slot_read(index);
|
||||
menuSave.update_save_drawings();
|
||||
menuSave.drawingSprites[index].LoadGraphics();
|
||||
menuCharacter.set_character_menu_shown(0);
|
||||
return SEEDS_ENTRY_KEEP;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MENU_DAILY_RUN: FUN_008d0730(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_BESTIARY: FUN_008c8760(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_CUSTOM_CHALLENGE: reconstruction_missing("Menu_ModChallenges::reset 008ceb90 on menuCustomChallenge");
|
||||
case MENU_MODS: menuMods.reset(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_ONLINE_LOBBY_LIST: menuOnlineLobbyList.reset(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_ONLINE: menuOnline.enter(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_OPTIONS: menuOptions.reload(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_ONLINE_OPTIONS: onlineOptions.reload(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_CREATE_LOBBY: FUN_008cc530(); return SEEDS_ENTRY_KEEP;
|
||||
case MENU_ONLINE_AWARDS: FUN_008e71c0(); return SEEDS_ENTRY_KEEP;
|
||||
default: return SEEDS_ENTRY_RESET;
|
||||
}
|
||||
}
|
||||
|
||||
// 0098ae20 Opens a menu over the current one, keeping it in the history. Leaving the save files sets the options up.
|
||||
void MenuManager::push_menu(MenuState menu)
|
||||
{
|
||||
if (selectedMenuId == menu) return;
|
||||
|
||||
if (selectedMenuId == MENU_SAVE)
|
||||
{
|
||||
Vector optionsPosition = menu_position_get(MENU_OPTIONS);
|
||||
menuOptions.Init(&optionsPosition, OPTIONS_NOT_PAUSED);
|
||||
}
|
||||
menuStateHistory.push_back(menu);
|
||||
SetState(menu, HISTORY_KEEP);
|
||||
}
|
||||
|
||||
// 0098aec0 Goes back to the menu before the current one, staying on the first.
|
||||
// The original reads before an empty history. This does nothing then.
|
||||
void MenuManager::pop_menu()
|
||||
{
|
||||
if (menuStateHistory.empty()) return;
|
||||
if (menuStateHistory.size() > 1) menuStateHistory.pop_back();
|
||||
SetState(menuStateHistory.back(), HISTORY_KEEP);
|
||||
}
|
||||
|
||||
// 0098af10 Scrolls an options menu down to keep its selected row in view, three rows above it and four below.
|
||||
// The original writes past the places for an unknown menu after logging. This only logs.
|
||||
void MenuManager::scroll_options_menu(MenuState menu, int selectedRow, int rowCount)
|
||||
{
|
||||
if (menu == MENU_OPTIONS) viewPositionSet[MENU_OPTIONS].y = OPTIONS_VIEW_Y;
|
||||
else if (menu == MENU_ONLINE_OPTIONS) viewPositionSet[MENU_ONLINE_OPTIONS].y = ONLINE_OPTIONS_VIEW_Y;
|
||||
else log_printf(LOG_ASSERT, "Unknown options menu specified\n");
|
||||
|
||||
if (selectedRow > OPTIONS_ROWS_ABOVE && menu >= MENU_NONE && menu < MENU_COUNT)
|
||||
{
|
||||
int row = std::min(selectedRow, rowCount - OPTIONS_ROWS_BELOW);
|
||||
viewPositionSet[menu].y -= (float)(row - OPTIONS_ROWS_ABOVE) * OPTIONS_ROW_HEIGHT;
|
||||
}
|
||||
isViewMoving = true;
|
||||
}
|
||||
Reference in new issue
Block a user