786 lines
32 KiB
C++
786 lines
32 KiB
C++
#include "menu_manager.h"
|
|
#include "fx_layers.h"
|
|
#include "game.h"
|
|
#include "kage_input.h"
|
|
#include "log.h"
|
|
#include "manager.h"
|
|
#include "render_passes.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* COLOR_MOD_SURFACE = "Menu Colormod Surface";
|
|
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
|
constexpr const char* COLOR_MOD_SHADER = "ColorMod";
|
|
|
|
// 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 int FLY_LAYER = 0;
|
|
constexpr int FLY_SHADOW_LAYER = 1;
|
|
|
|
constexpr float FADE_STEP = 0.025f;
|
|
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 float VIGNETTE_HARD = 0.5f;
|
|
constexpr float SHADOW_HEIGHT = 148;
|
|
constexpr float OVERLAY_BLEED = 0.5f;
|
|
constexpr uint32_t MENU_BACKGROUND_ARGB = 0xffccbebb;
|
|
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;
|
|
|
|
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));
|
|
}
|
|
|
|
// 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 id, 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* deviceId)
|
|
{
|
|
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 (deviceId) *deviceId = device->id;
|
|
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);
|
|
}
|
|
|
|
// 00986450 Builds the menus with the view at the sheet's origin and the color modifier off, then the surface it renders
|
|
// through. The online menus it builds are offline.
|
|
MenuManager::MenuManager()
|
|
{
|
|
fadeInColor = kcolor_argb(BLACK_ARGB);
|
|
specialSeedsViewPosition = vector_make(0, SPECIAL_SEEDS_VIEW_Y);
|
|
color_mod_surface_create();
|
|
}
|
|
|
|
// 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 and fresh seeds, lays the menus out on the sheet,
|
|
// loads the overlay, the shadow and the fly, then each menu in turn.
|
|
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();
|
|
seedsObject = Seeds();
|
|
|
|
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);
|
|
|
|
menus_init();
|
|
isViewMoving = false;
|
|
isFadeOutActive = false;
|
|
fadeOutProgress = 0;
|
|
isFadeInActive = false;
|
|
fadeInProgress = 1;
|
|
vignetteIntensity = 0;
|
|
backWidgetOffsetY = WIDGET_OFFSET_Y;
|
|
selectWidgetOffsetY = WIDGET_OFFSET_Y;
|
|
isPopupButtonsShown = true;
|
|
}
|
|
|
|
// Inits each menu at its place on the sheet, in the original order. The daily menu's record streak catches up with
|
|
// the current one. Menu_Mods is not taken over yet and starts unloaded. The key config menu's own reset of its view
|
|
// place and the view movement is left out, as Init sets both again.
|
|
void MenuManager::menus_init()
|
|
{
|
|
std::array<int, EVENT_COUNTER_COUNT>& counters = g_manager->persistentGameData.eventCounters;
|
|
|
|
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");
|
|
menuDailyChallenge.Init(menu_position_get(MENU_DAILY_RUN));
|
|
if ((uint32_t)counters[EVENT_COUNTER_DAILYS_BEST_STREAK] < (uint32_t)counters[EVENT_COUNTER_DAILYS_STREAK])
|
|
counters[EVENT_COUNTER_DAILYS_BEST_STREAK] = counters[EVENT_COUNTER_DAILYS_STREAK];
|
|
log_printf(LOG_INFO, "Menu Character Init\n");
|
|
menuCharacter.Init(menu_position_get(MENU_CHARACTER));
|
|
log_printf(LOG_INFO, "Menu SpecialSeed Init\n");
|
|
menuSpecialSeeds.Init(menu_position_get(MENU_SPECIAL_SEEDS));
|
|
log_printf(LOG_INFO, "Menu Challenge Init\n");
|
|
menuChallenge.Init(menu_position_get(MENU_CHALLENGE));
|
|
log_printf(LOG_INFO, "Menu Collection Init\n");
|
|
menuCollection.Init(menu_position_get(MENU_COLLECTION));
|
|
log_printf(LOG_INFO, "Menu Stats Init\n");
|
|
menuStats.Init(menu_position_get(MENU_STATS));
|
|
log_printf(LOG_INFO, "Menu Mods Init\n");
|
|
log_printf(LOG_INFO, "Menu Options Init\n");
|
|
menuOptions.Init(menu_position_get(MENU_OPTIONS), OPTIONS_MAIN_MENU);
|
|
log_printf(LOG_INFO, "Menu Controller Init\n");
|
|
menuControllerSelect.Init(menu_position_get(MENU_CONTROLLER_SELECT));
|
|
log_printf(LOG_INFO, "Menu Key Config Init\n");
|
|
menuKeyConfig.Init(menu_position_get(MENU_KEY_CONFIG));
|
|
log_printf(LOG_INFO, "Menu Cutscene Init\n");
|
|
menuCutscenes.Init(menu_position_get(MENU_CUTSCENES));
|
|
log_printf(LOG_INFO, "Menu Bestiary Init\n");
|
|
menuBestiary.Init(menu_position_get(MENU_BESTIARY));
|
|
log_printf(LOG_INFO, "Menu Custom Challenge Init\n");
|
|
menuCustomChallenge.Init(menu_position_get(MENU_CUSTOM_CHALLENGE));
|
|
}
|
|
|
|
// 00988ba0 Drops every menu's sprites, as a run starts. Menu_Mods is not taken over yet and holds none.
|
|
void MenuManager::unload_graphics()
|
|
{
|
|
menuTitle.titleScreenSprite.Reset();
|
|
menuSave.unload_graphics();
|
|
menuGame.gameMenuSprite.Reset();
|
|
menuGame.continueWidgetSprite.Reset();
|
|
menuCharacter.unload_graphics();
|
|
menuSpecialSeeds.specialSeedsSprite.Reset();
|
|
menuChallenge.challengeMenuSprite.Reset();
|
|
menuCollection.collectionMenuSprite.Reset();
|
|
menuCollection.deathScreenSprite.Reset();
|
|
menuStats.unload_graphics();
|
|
menuOptions.optionsSprite.Reset();
|
|
menuControllerSelect.controllerSelectSprite.Reset();
|
|
menuKeyConfig.keyConfigSprite.Reset();
|
|
menuCutscenes.cutscenesMenuSprite.Reset();
|
|
menuDailyChallenge.unload_graphics();
|
|
menuBestiary.unload_graphics();
|
|
menuCustomChallenge.customChallengeSprite.Reset();
|
|
}
|
|
|
|
// 00988d80 Loads every menu's sprites again, as the menus come back. Menu_Mods is not taken over yet and stays
|
|
// unloaded.
|
|
void MenuManager::LoadGraphics()
|
|
{
|
|
menuTitle.sprite_load();
|
|
menuTitle.load_graphics();
|
|
menuSave.LoadGraphics();
|
|
menuGame.LoadGraphics();
|
|
menuCharacter.LoadGraphics();
|
|
menuSpecialSeeds.LoadGraphics();
|
|
menuChallenge.LoadGraphics();
|
|
menuCollection.LoadGraphics();
|
|
menuStats.LoadGraphics();
|
|
menuOptions.load_menu_anm2();
|
|
menuControllerSelect.LoadGraphics();
|
|
menuKeyConfig.LoadGraphics();
|
|
menuCutscenes.LoadGraphics();
|
|
menuDailyChallenge.load_graphics();
|
|
menuBestiary.load_graphics();
|
|
menuCustomChallenge.LoadGraphics();
|
|
}
|
|
|
|
// 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(seedsObject.gameStartSeed);
|
|
}
|
|
|
|
// 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.device_find(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 = device->id;
|
|
}
|
|
}
|
|
|
|
// 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. The online menus are never selected offline.
|
|
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: menuChallenge.Update(); break;
|
|
case MENU_COLLECTION: menuCollection.Update(); break;
|
|
case MENU_STATS: menuStats.Update(); break;
|
|
case MENU_OPTIONS: menuOptions.Update(); break;
|
|
case MENU_CONTROLLER_SELECT: menuControllerSelect.Update(); break;
|
|
case MENU_KEY_CONFIG: menuKeyConfig.Update(); break;
|
|
case MENU_CUTSCENES: menuCutscenes.Update(); break;
|
|
case MENU_BESTIARY: menuBestiary.Update(); break;
|
|
case MENU_CUSTOM_CHALLENGE: menuCustomChallenge.Update(); break;
|
|
case MENU_MODS: menuMods.Update(); break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
// 006ef410 Moves each component toward the target's by at most the step's, landing on it once within reach.
|
|
void ColorModState::move_toward(float* target, float* step)
|
|
{
|
|
float* components[] = {&_red, &_green, &_blue, &_amount, &_brightness, &_contrast};
|
|
|
|
for (size_t i = 0; i < std::size(components); i++)
|
|
{
|
|
float& value = *components[i];
|
|
if (step[i] < std::fabs(value - target[i])) value += target[i] <= value ? -step[i] : step[i];
|
|
else value = target[i];
|
|
}
|
|
}
|
|
|
|
// 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.
|
|
// Menu_Mods' page waits for its takeover, and the offline online menus draw nothing.
|
|
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();
|
|
menuCutscenes.Render();
|
|
menuCustomChallenge.Render();
|
|
menuSave.Render();
|
|
menuDailyChallenge.leaderboard.Render();
|
|
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()
|
|
{
|
|
auto& 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()
|
|
{
|
|
bool isHard = menuCharacter.difficulty == DIFFICULTY_HARD || menuCharacter.difficulty == DIFFICULTY_GREEDIER;
|
|
float target = isHard ? 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, SPRITE_SHADER_COLOR_APPLY, *menuOverlayImage);
|
|
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, SPRITE_SHADER_COLOR_APPLY, *menuOverlayImage);
|
|
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) menuDailyChallenge.reset();
|
|
|
|
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();
|
|
g_manager->LoadGameState(g_manager->currentSaveSlot);
|
|
}
|
|
else if (previous == MENU_SAVE && state == MENU_GAME)
|
|
{
|
|
menuCharacter.Reset();
|
|
menuGame.Reset();
|
|
seedsObject.ClearSeedEffects();
|
|
return SEEDS_ENTRY_KEEP;
|
|
}
|
|
else if (previous == MENU_CHARACTER)
|
|
{
|
|
menuCharacter.seed_unlock_page_reset();
|
|
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 = {};
|
|
menuKeyConfig.selectedColumn = {};
|
|
menuKeyConfig.state = {};
|
|
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(CHARACTER_MENU_NORMAL);
|
|
return SEEDS_ENTRY_KEEP;
|
|
}
|
|
|
|
switch (state)
|
|
{
|
|
case MENU_DAILY_RUN: menuDailyChallenge.reset(); return SEEDS_ENTRY_KEEP;
|
|
case MENU_BESTIARY: menuBestiary.reset(); return SEEDS_ENTRY_KEEP;
|
|
case MENU_CUSTOM_CHALLENGE: menuCustomChallenge.reset(); return SEEDS_ENTRY_KEEP;
|
|
case MENU_MODS: menuMods.reset(); return SEEDS_ENTRY_KEEP;
|
|
case MENU_OPTIONS: menuOptions.reload(); return SEEDS_ENTRY_KEEP;
|
|
case MENU_ONLINE_LOBBY_LIST:
|
|
case MENU_ONLINE:
|
|
case MENU_ONLINE_OPTIONS:
|
|
case MENU_CREATE_LOBBY:
|
|
case MENU_ONLINE_AWARDS: 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)
|
|
{
|
|
menuOptions.Init(menu_position_get(MENU_OPTIONS), OPTIONS_MAIN_MENU);
|
|
}
|
|
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;
|
|
}
|