1587 lines
64 KiB
C++
1587 lines
64 KiB
C++
#include "hud.h"
|
|
#include "boss_pool.h"
|
|
#include "fx_layers.h"
|
|
#include "item_pickup.h"
|
|
#include "entity_player.h"
|
|
#include "game.h"
|
|
#include "level.h"
|
|
#include "log.h"
|
|
#include "manager.h"
|
|
#include "minimap.h"
|
|
#include "platform.h"
|
|
#include "render_passes.h"
|
|
#include "room.h"
|
|
#include "string_table.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cctype>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <cwctype>
|
|
|
|
constexpr const char* MPLUS_FONT = "font/MPlus_12b.fnt";
|
|
constexpr const char* KOREAN_FONT = "font/KR_Font14.fnt";
|
|
constexpr const char* STREAK_ANM2 = "gfx/ui/ui_streak.anm2";
|
|
constexpr const char* HEARTS_ANM2 = "gfx/ui/ui_hearts.anm2";
|
|
constexpr const char* PICKUPS_ANM2 = "gfx/ui/hudpickups.anm2";
|
|
constexpr const char* CHARGE_BAR_ANM2 = "gfx/ui/ui_chargebar.anm2";
|
|
constexpr const char* CHARGE_BAR_SMALL_ANM2 = "gfx/ui/ui_chargebar_small.anm2";
|
|
constexpr const char* CARDS_PILLS_ANM2 = "gfx/ui/ui_cardspills.anm2";
|
|
constexpr const char* STATS_ANM2 = "gfx/ui/hudstats.anm2";
|
|
constexpr const char* STATS_PANEL_ANM2 = "gfx/ui/hudstats2.anm2";
|
|
constexpr const char* FORTUNE_ANM2 = "gfx/ui/ui_FortunePaper.anm2";
|
|
constexpr const char* COOP_MENU_ANM2 = "gfx/ui/coop menu.anm2";
|
|
constexpr const char* INVENTORY_ANM2 = "gfx/ui/ui_inventory.anm2";
|
|
constexpr const char* CRAFTING_ANM2 = "gfx/ui/ui_crafting.anm2";
|
|
constexpr const char* POOPS_ANM2 = "gfx/ui/ui_poops.anm2";
|
|
constexpr const char* BOSS_BAR_PNG = "gfx/ui/ui_bosshealthbar.png";
|
|
constexpr const char* BOSS_BAR_MINI_PNG = "gfx/ui/ui_bosshealthbar_mini.png";
|
|
constexpr const char* BOSS_BAR_STATIC_PNG = "gfx/ui/ui_bosshealthbar_static.png";
|
|
constexpr const char* BOSS_BAR_STONE_PNG = "gfx/ui/ui_bosshealthbar_stone.png";
|
|
constexpr const char* BOSS_BAR_RUSH_PNG = "gfx/ui/ui_bosshealthbar_rush.png";
|
|
constexpr const char* SPIDER_MOD_BAR_PNG = "gfx/Spidermod_Healthbar.png";
|
|
constexpr const char* COOP_MENU_PNG = "gfx/ui/coop menu.png";
|
|
constexpr const char* MESSAGE_SURFACE = "HUD_Message Text Surface";
|
|
constexpr const char* FORTUNE_SURFACE = "Fortune Text Surface";
|
|
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
|
constexpr const char* COLOR_OFFSET_DOGMA_SHADER = "ColorOffsetDogma";
|
|
|
|
constexpr const char* ANIMATION_IDLE = "Idle";
|
|
constexpr const char* ANIMATION_MAIN = "Main";
|
|
constexpr const char* ANIMATION_ARROWS = "Arrows";
|
|
constexpr const char* ANIMATION_TEXT = "Text";
|
|
constexpr const char* ANIMATION_TEXT_IN = "TextIn";
|
|
constexpr const char* ANIMATION_TEXT_STAY = "TextStay";
|
|
constexpr const char* ANIMATION_TEXT_OUT = "TextOut";
|
|
constexpr const char* ANIMATION_DESTINATION = "Destination";
|
|
constexpr const char* EVENT_SLIDE_IN = "SlideIn";
|
|
constexpr const char* EVENT_SLIDE_OUT = "SlideOut";
|
|
|
|
constexpr int TEXT_SURFACE_WIDTH = 400;
|
|
constexpr int TEXT_SURFACE_HEIGHT = 128;
|
|
constexpr char16_t RICH_TEXT_MARK = 1;
|
|
constexpr int CURSE_LAYER = 1;
|
|
constexpr float TITLE_Y_LOCALIZED = 2;
|
|
constexpr float SUBTITLE_Y = 18;
|
|
constexpr float SUBTITLE_Y_CURSE = 26;
|
|
constexpr float STREAK_TEXT_RISE = 9;
|
|
constexpr KAGE::Graphics::BlendMode BLEND_MODE_PREMULTIPLIED = {
|
|
KAGE::Graphics::EQUATION_ADD, KAGE::Graphics::FACTOR_ONE, KAGE::Graphics::FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
KAGE::Graphics::FACTOR_ONE, KAGE::Graphics::FACTOR_ONE_MINUS_SRC_ALPHA};
|
|
|
|
constexpr int FILTER_LINEAR = 1;
|
|
constexpr int CHARGE_BAR_FLASH_FRAMES = 8;
|
|
constexpr int SOUND_FORTUNE_PAPER = 252;
|
|
|
|
// The fortune paper's writing: the width a wrapped line fits, the line height, the size past which the text halves,
|
|
// and the mark that breaks a fortune's lines.
|
|
constexpr int FORTUNE_LINE_WIDTH = 270;
|
|
constexpr float FORTUNE_LINE_HEIGHT = 21;
|
|
constexpr int FORTUNE_MAX_WIDTH = 273;
|
|
constexpr float FORTUNE_MAX_HEIGHT = 63;
|
|
constexpr char FORTUNE_LINE_BREAK = '|';
|
|
constexpr float FORTUNE_SOUND_VOLUME = 0.5f;
|
|
constexpr float FORTUNE_SLIDE_IN_PITCH = 1.5f;
|
|
constexpr float STATS_ALPHA = 0.5f;
|
|
|
|
constexpr int COLOR_INDEX_NONE = 5;
|
|
constexpr int STB_HOME = 35;
|
|
constexpr int BOSS_GREAT_GIDEON = 83;
|
|
constexpr uint32_t ROOM_FLAG_CLEAR = 1;
|
|
constexpr int ONLINE_HUD_COMPACT = 1;
|
|
constexpr int ONLINE_HUD_HIDDEN = 2;
|
|
constexpr int TEXT_BUFFER_SIZE = 16;
|
|
constexpr int UTF16_HIGH_HALF_SHIFT = 16;
|
|
|
|
// The pickup counter rows, the run icons and the destination icon, as frames of hudpickups.anm2.
|
|
enum PickupFrame : int
|
|
{
|
|
FRAME_COIN,
|
|
FRAME_KEY,
|
|
FRAME_BOMB,
|
|
FRAME_GOLDEN_KEY,
|
|
FRAME_HARD,
|
|
FRAME_ACHIEVEMENTS_OFF,
|
|
FRAME_GOLDEN_BOMB,
|
|
FRAME_GREED,
|
|
FRAME_DAILY,
|
|
FRAME_GREED_DONATION,
|
|
FRAME_VICTORY_LAP,
|
|
FRAME_GREEDIER,
|
|
FRAME_SOUL_CHARGE,
|
|
FRAME_GIGA_BOMB = 14,
|
|
FRAME_BLOOD_CHARGE,
|
|
FRAME_POOP
|
|
};
|
|
|
|
// The final boss a challenge leads to: frames of the "Destination" animation.
|
|
enum DestinationFrame : int
|
|
{
|
|
DESTINATION_MOM,
|
|
DESTINATION_MOMS_HEART,
|
|
DESTINATION_SATAN,
|
|
DESTINATION_ISAAC,
|
|
DESTINATION_LAMB,
|
|
DESTINATION_BLUE_BABY,
|
|
DESTINATION_MEGA_SATAN,
|
|
DESTINATION_DELIRIUM = 9,
|
|
DESTINATION_MOTHER = 11,
|
|
DESTINATION_BEAST
|
|
};
|
|
|
|
// The end stages a challenge's destination icon tells apart.
|
|
enum ChallengeEndStage : int
|
|
{
|
|
END_STAGE_DEPTHS = 6,
|
|
END_STAGE_WOMB = 8,
|
|
END_STAGE_SHEOL = 10,
|
|
END_STAGE_DARK_ROOM = 11,
|
|
END_STAGE_VOID = 12
|
|
};
|
|
|
|
// A HUD position: its x and y.
|
|
static Vector at_make(float x, float y)
|
|
{
|
|
return vector_make(x, y);
|
|
}
|
|
|
|
// Whether a player leads its pair of twins (Jacob over Esau), as one with no twin does.
|
|
static bool is_main_twin(Entity_Player& player)
|
|
{
|
|
Entity_Player* twin = player.twin_get();
|
|
return !twin || twin->playerIndex == -1 || player.playerIndex <= twin->playerIndex;
|
|
}
|
|
|
|
// Whether a player is Jacob or Esau.
|
|
static bool is_jacob_or_esau(Entity_Player* player)
|
|
{
|
|
return player && (player->playerType == PLAYER_JACOB || player->playerType == PLAYER_ESAU);
|
|
}
|
|
|
|
// The online HUD style (009a84c0): the options' while online and out of a versus match, else compact or offline.
|
|
int online_hud_mode()
|
|
{
|
|
if (!g_manager->netplayManager.is_online()) return ONLINE_HUD_OFFLINE;
|
|
if (!g_game->deathmatchManager.is_active()) return g_manager->optionsConfig.onlineHud;
|
|
return 0;
|
|
}
|
|
|
|
// UTF-8 text as the game's UTF-16, which ends at the first character it cannot decode.
|
|
static std::u16string utf16_from(std::string_view text)
|
|
{
|
|
std::u16string result;
|
|
const char* end = text.data() + text.size();
|
|
|
|
for (const char* cursor = text.data(); cursor < end;)
|
|
{
|
|
uint32_t character = 0;
|
|
cursor = utf8_decode_next(cursor, &character, end);
|
|
if (!character) break;
|
|
|
|
result.push_back((char16_t)character);
|
|
if (character >> UTF16_HIGH_HALF_SHIFT) result.push_back((char16_t)(character >> UTF16_HIGH_HALF_SHIFT));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// A channel cut to the 8 bits of an ARGB color, as KColor's round trip through one cuts it.
|
|
static float channel_quantize(float channel)
|
|
{
|
|
constexpr float CHANNEL_MAX = 255;
|
|
return (float)(uint8_t)(uint32_t)(channel * CHANNEL_MAX) / CHANNEL_MAX;
|
|
}
|
|
|
|
// The text drawn the way the HUD draws text, white with default settings at its own size.
|
|
static void text_draw(Font& font, std::string_view text, Vector at)
|
|
{
|
|
FontSettings settings;
|
|
font.DrawString(text, at, vector_make(1, 1), WHITE, settings);
|
|
}
|
|
|
|
// A sprite drawn at a position with no clamping.
|
|
static void sprite_draw(const ANM2& sprite, Vector at)
|
|
{
|
|
sprite.Render({at, {}, {}});
|
|
}
|
|
|
|
// 008407a0 Loads the streak, a new text surface and the two fonts through the mods' redirection, then empties the
|
|
// banner at its default place and size.
|
|
void HUD_Message::load_graphics()
|
|
{
|
|
ModManager& mods = g_manager->modManager;
|
|
|
|
streakSprite.Load(STREAK_ANM2, GRAPHICS_LOAD);
|
|
textImage = KAGE::Graphics::manager.render_target_create(
|
|
{.clearColor = {}, .name = MESSAGE_SURFACE, .height = TEXT_SURFACE_HEIGHT, .width = TEXT_SURFACE_WIDTH});
|
|
font.Load(mods.TryRedirectPath(MPLUS_FONT));
|
|
fontKR.Load(mods.TryRedirectPath(KOREAN_FONT));
|
|
position = {};
|
|
scale = 1;
|
|
free_text_buffers();
|
|
}
|
|
|
|
// 00840f70 Forgets the title and subtitle.
|
|
void HUD_Message::free_text_buffers()
|
|
{
|
|
text.clear();
|
|
subtext.clear();
|
|
}
|
|
|
|
// 00841000 Sets the title (line 0) or the subtitle (line 1).
|
|
void HUD_Message::set_text_line(std::u16string_view line, int lineIndex)
|
|
{
|
|
(lineIndex ? subtext : text) = line;
|
|
}
|
|
|
|
// 00840b00 Shows a title, and a subtitle when given (else the last one stays), playing out the banner shown first.
|
|
// An auto hiding banner plays "Text" through, a sticky one stops on "TextStay" until text_out.
|
|
void HUD_Message::Show(const char* title, const char* subtitle, bool isAutoHideOn, bool isCurse)
|
|
{
|
|
if (!title)
|
|
return log_printf(LOG_ERROR, "HUD_Message::Show() recieved NULL messageText (This will have no effect) \n");
|
|
|
|
text_out();
|
|
set_text_line(utf16_from(title), 0);
|
|
if (subtitle) set_text_line(utf16_from(subtitle), 1);
|
|
isCurseDisplay = isCurse;
|
|
isAutoHide = isAutoHideOn;
|
|
if (streakSprite.SetAnimation(isAutoHideOn ? ANIMATION_TEXT : ANIMATION_TEXT_IN))
|
|
{
|
|
streakSprite.animState.Rewind();
|
|
streakSprite.animState.isPlaying = true;
|
|
}
|
|
|
|
// The original writes the curse layer without checking it. A streak without one shows no curse mark.
|
|
if (LayerState* curseLayer = streakSprite.GetLayer(CURSE_LAYER)) curseLayer->isVisible = isCurse;
|
|
UpdateTextImage();
|
|
isShowing = true;
|
|
}
|
|
|
|
// 00840c60 Plays a shown banner out, unless it is already playing out.
|
|
void HUD_Message::text_out()
|
|
{
|
|
if (!isShowing) return;
|
|
|
|
const AnimationState& state = streakSprite.animState;
|
|
if (state.animData && state.isPlaying && state.animData->name == ANIMATION_TEXT_OUT) return;
|
|
if (!streakSprite.SetAnimation(ANIMATION_TEXT_OUT)) return;
|
|
|
|
streakSprite.animState.Rewind();
|
|
streakSprite.animState.isPlaying = true;
|
|
}
|
|
|
|
// 00840ce0 Plays the streak on: a finished "TextIn" stays on "TextStay", a finished "TextOut" or "Text" hides the
|
|
// banner.
|
|
void HUD_Message::Update()
|
|
{
|
|
if (!isShowing) return;
|
|
|
|
streakSprite.Update();
|
|
const AnimationData* data = streakSprite.animState.animData;
|
|
if (!data || streakSprite.animState.isPlaying) return;
|
|
|
|
if (data->name == ANIMATION_TEXT_IN) return streakSprite.Play(ANIMATION_TEXT_STAY);
|
|
if (data->name != ANIMATION_TEXT_OUT && data->name != ANIMATION_TEXT) return;
|
|
|
|
free_text_buffers();
|
|
isShowing = false;
|
|
}
|
|
|
|
// 008410c0 Draws the title and subtitle centered into the text surface: the title in the large font, the subtitle in
|
|
// the small one, black and lower in the curse font when it is a curse. The title sits lower when either of the
|
|
// banner's own fonts loaded. Rich text (starting with character 1) is drawn with its icons.
|
|
// The original draws into a missing surface. Here a banner whose graphics never loaded draws nothing.
|
|
void HUD_Message::UpdateTextImage()
|
|
{
|
|
if (!textImage) return;
|
|
|
|
Manager& manager = *g_manager;
|
|
Font& titleFont = manager.font7_Upheaval;
|
|
Font& subtitleFont = isCurseDisplay ? manager.font1_TeamMeatEx10 : manager.font9_PFTempestaSevenCondensedAgain;
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
FontSettings settings;
|
|
|
|
graphics.render_target_push(textImage.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
|
|
graphics.Clear();
|
|
graphics.blendMode = BLEND_MODE_PREMULTIPLIED;
|
|
|
|
float centerX = (float)((unsigned int)textImage->width >> 1);
|
|
auto line_draw = [&](Font& lineFont, std::u16string_view line, float y, KColor color)
|
|
{
|
|
if (line[0] == RICH_TEXT_MARK) return render_text_image(lineFont, line.substr(1), at_make(centerX, y), color);
|
|
|
|
float halfWidth = (float)((unsigned int)lineFont.GetStringWidth(line) >> 1);
|
|
lineFont.DrawString(line, at_make(centerX - halfWidth, y), vector_make(1, 1), color, settings);
|
|
};
|
|
|
|
if (!text.empty()) line_draw(titleFont, text, font.isLoaded || fontKR.isLoaded ? TITLE_Y_LOCALIZED : 0, WHITE);
|
|
if (!subtext.empty())
|
|
{
|
|
float y = isCurseDisplay ? SUBTITLE_Y_CURSE : SUBTITLE_Y;
|
|
line_draw(subtitleFont, subtext, y, isCurseDisplay ? BLACK : WHITE);
|
|
}
|
|
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
|
}
|
|
|
|
// 00840e10 Draws a shown banner at a position and size: the streak, and the text surface where the streak's null 0
|
|
// puts it, shaken with the screen.
|
|
void HUD_Message::Render(Vector at, float atScale)
|
|
{
|
|
position = at;
|
|
scale = atScale;
|
|
if (!isShowing) return;
|
|
|
|
streakSprite.scale = vector_make(atScale, atScale);
|
|
sprite_draw(streakSprite, position);
|
|
if (!streakSprite.animState.animData || !textImage) return;
|
|
|
|
const NullFrame* frame = streakSprite.animState.GetNullFrameById(0);
|
|
if (!frame) return;
|
|
|
|
Vector shake = g_game->screenShakeOffset;
|
|
Vector size = at_make((float)textImage->width * frame->scale.x * scale,
|
|
(float)textImage->height * frame->scale.y * scale);
|
|
Vector corner = at_make(frame->pos.x + position.x - size.x * 0.5f + shake.x,
|
|
position.y + frame->pos.y - scale * STREAK_TEXT_RISE + shake.y);
|
|
textImage->Render(KAGE::Graphics::color_quad_rect(corner, size, WHITE), WHITE);
|
|
}
|
|
|
|
// 008413a0 Draws rich text, its icons from the HUD's sprites, centered at a point of the text surface.
|
|
void HUD_Message::render_text_image(Font&, std::u16string_view, Vector, KColor)
|
|
{
|
|
reconstruction_missing("HUD_Message::render_text_image 008413a0");
|
|
}
|
|
|
|
// 0083abb0 Forgets both players' recent items.
|
|
void HistoryHUD::clear()
|
|
{
|
|
for (HistoryHUDPlayer& slot : players) slot = {};
|
|
isComputed = false;
|
|
}
|
|
|
|
// 0083ac20 Draws the recent items at a position, full size or mini.
|
|
void HistoryHUD::Render(Vector, bool)
|
|
{
|
|
reconstruction_missing("HistoryHUD::Render 0083ac20");
|
|
}
|
|
|
|
// 0083b280 Recomputes one player's recent items.
|
|
void HistoryHUD::Recompute(int, bool)
|
|
{
|
|
reconstruction_missing("HistoryHUD::Recompute 0083b280");
|
|
}
|
|
|
|
// 0083b850 Recomputes both players' recent items.
|
|
void HistoryHUD::RecomputeAll(bool)
|
|
{
|
|
reconstruction_missing("HistoryHUD::RecomputeAll 0083b850");
|
|
}
|
|
|
|
// 009a1970 Loads the graphics again, empties the HUD and loads the item info panel.
|
|
void HUD::graphics_reload()
|
|
{
|
|
isGraphicsLoaded = false;
|
|
LoadGraphics();
|
|
reset();
|
|
itemInfoHUD.load_graphics();
|
|
}
|
|
|
|
// 009a19a0 Hides the boss bar, asks for a full refresh, empties every player corner, the recent items and the stats,
|
|
// and shows the HUD.
|
|
void HUD::reset()
|
|
{
|
|
bossHPBarFill = BOSS_BAR_HIDDEN;
|
|
bossHPBarDamageFlash = FLASH_OFF;
|
|
bossHPBarHealFlash = FLASH_OFF;
|
|
isBossBarBottom = false;
|
|
hudRefreshType = HUD_REFRESH_FULL;
|
|
hudRefreshCountdown = 2;
|
|
isRefreshTick = false;
|
|
for (int i = 0; i < PLAYER_HUD_COUNT; i++)
|
|
{
|
|
playerHUD[i].playerHudIndex = (int16_t)i;
|
|
playerHUD[i].hud = this;
|
|
playerHUD[i].reset();
|
|
}
|
|
historyHUD.clear();
|
|
isVisible = true;
|
|
statHUD.reset();
|
|
}
|
|
|
|
// 009a1a30 Loads the fonts through the mods' redirection, the sprites, boss bars and banners, and the fortune and
|
|
// co-op surfaces, once until unload_graphics. The stats are half transparent.
|
|
void HUD::LoadGraphics()
|
|
{
|
|
if (isGraphicsLoaded) return;
|
|
|
|
ModManager& mods = g_manager->modManager;
|
|
font.Load(mods.TryRedirectPath(MPLUS_FONT));
|
|
fontKR.Load(mods.TryRedirectPath(KOREAN_FONT));
|
|
heartsSprite.Load(HEARTS_ANM2, GRAPHICS_LOAD);
|
|
pickupHUDSprite.Load(PICKUPS_ANM2, GRAPHICS_LOAD);
|
|
chargeBarSprite.Load(CHARGE_BAR_ANM2, GRAPHICS_LOAD);
|
|
chargeBarSmallSprite.Load(CHARGE_BAR_SMALL_ANM2, GRAPHICS_LOAD);
|
|
cardsPillsSprite.Load(CARDS_PILLS_ANM2, GRAPHICS_LOAD);
|
|
statsSprite.Load(STATS_ANM2, GRAPHICS_LOAD);
|
|
statsSprite.color = COLOR_DEFAULT;
|
|
statsSprite.color._tint[3] = STATS_ALPHA;
|
|
|
|
bossHealthBarImage = Manager::LoadImage(BOSS_BAR_PNG);
|
|
bossHealthBarMiniImage = Manager::LoadImage(BOSS_BAR_MINI_PNG);
|
|
bossHealthBarStaticImage = Manager::LoadImage(BOSS_BAR_STATIC_PNG);
|
|
bossHealthBarStoneImage = Manager::LoadImage(BOSS_BAR_STONE_PNG);
|
|
bossHealthBarRushImage = Manager::LoadImage(BOSS_BAR_RUSH_PNG);
|
|
|
|
fortuneSprite.Load(FORTUNE_ANM2, GRAPHICS_LOAD);
|
|
coopMenuSprite.Load(COOP_MENU_ANM2, GRAPHICS_LOAD);
|
|
coopMenuSprite.Play(ANIMATION_MAIN);
|
|
coopMenuSprite.PlayOverlay(ANIMATION_ARROWS);
|
|
std::pair<ANM2*, const char*> idleSprites[] = {
|
|
{&inventorySprite, INVENTORY_ANM2}, {&craftingTableSprite, CRAFTING_ANM2}, {&poopSpellsSprite, POOPS_ANM2}};
|
|
for (auto [sprite, path] : idleSprites)
|
|
{
|
|
sprite->Load(path, GRAPHICS_LOAD);
|
|
sprite->Play(ANIMATION_IDLE);
|
|
}
|
|
|
|
messageMain.load_graphics();
|
|
for (HUD_Message& message : messageStack) message.load_graphics();
|
|
for (HUD_Message& message : messagePlayerHUD) message.load_graphics();
|
|
|
|
spiderModHealthBarImage = Manager::LoadImage(SPIDER_MOD_BAR_PNG);
|
|
fortuneTextImage = KAGE::Graphics::manager.render_target_create(
|
|
{.clearColor = {}, .name = FORTUNE_SURFACE, .height = TEXT_SURFACE_HEIGHT, .width = TEXT_SURFACE_WIDTH});
|
|
coopMenuImage = Manager::LoadImage(COOP_MENU_PNG);
|
|
if (coopMenuImage->minFilter != FILTER_LINEAR || coopMenuImage->magFilter != FILTER_LINEAR)
|
|
coopMenuImage->filter_set(FILTER_LINEAR, FILTER_LINEAR);
|
|
|
|
statHUD.sprite.Load(STATS_PANEL_ANM2, GRAPHICS_LOAD);
|
|
statHUD.sprite.SetFrame(ANIMATION_IDLE, 0);
|
|
isGraphicsLoaded = true;
|
|
}
|
|
|
|
// Unloads a banner's graphics and hides it.
|
|
static void message_unload(HUD_Message& message)
|
|
{
|
|
message.free_text_buffers();
|
|
message.streakSprite.Reset();
|
|
message.textImage.reset();
|
|
message.isShowing = false;
|
|
}
|
|
|
|
// 009a27d0 Unloads the fonts, sprites, boss bars, banners and surfaces, and empties every player corner, the recent
|
|
// items and the stats. The Spider Mod bar stays.
|
|
void HUD::unload_graphics()
|
|
{
|
|
font.Unload();
|
|
fontKR.Unload();
|
|
for (ANM2* sprite : {&chargeBarSprite, &chargeBarSmallSprite, &heartsSprite, &pickupHUDSprite, &statsSprite})
|
|
sprite->Reset();
|
|
for (KAGE::Graphics::ImagePtr* image : {&bossHealthBarImage, &bossHealthBarMiniImage, &bossHealthBarStaticImage,
|
|
&bossHealthBarStoneImage, &bossHealthBarRushImage})
|
|
image->reset();
|
|
for (ANM2* sprite : {&cardsPillsSprite, &fortuneSprite, &inventorySprite, &craftingTableSprite, &poopSpellsSprite,
|
|
&coopMenuSprite})
|
|
sprite->Reset();
|
|
|
|
message_unload(messageMain);
|
|
for (HUD_Message& message : messageStack) message_unload(message);
|
|
for (HUD_Message& message : messagePlayerHUD) message_unload(message);
|
|
for (PlayerHUD& hud : playerHUD) hud.reset();
|
|
fortuneTextImage.reset();
|
|
coopMenuImage.reset();
|
|
isGraphicsLoaded = false;
|
|
historyHUD.clear();
|
|
statHUD.reset();
|
|
}
|
|
|
|
// 009a2990 Counts the refresh and the boss bar flashes down, plays the banners and the fortune paper on (with its
|
|
// paper sound as it slides in and out), then updates the item info panel.
|
|
void HUD::Update()
|
|
{
|
|
if (isRefreshTick)
|
|
{
|
|
hudRefreshCountdown--;
|
|
isRefreshTick = false;
|
|
if (hudRefreshCountdown < 1) hudRefreshType = HUD_REFRESH_NONE;
|
|
}
|
|
if (bossHPBarDamageFlash > FLASH_OFF) bossHPBarDamageFlash--;
|
|
if (bossHPBarHealFlash > FLASH_OFF) bossHPBarHealFlash--;
|
|
|
|
messageMain.Update();
|
|
for (HUD_Message& message : messageStack) message.Update();
|
|
for (HUD_Message& message : messagePlayerHUD) message.Update();
|
|
|
|
fortuneSprite.Update();
|
|
AnimationState& fortune = fortuneSprite.animState;
|
|
if (fortune.animData)
|
|
{
|
|
bool isSlidingIn = fortune.IsEventTriggered(EVENT_SLIDE_IN) && fortune.isPlaying;
|
|
if (isSlidingIn || (fortune.IsEventTriggered(EVENT_SLIDE_OUT) && fortune.isPlaying))
|
|
{
|
|
int sound = SOUND_FORTUNE_PAPER;
|
|
seed_fart_sound_override(&sound);
|
|
g_manager->sfxManager.Play(
|
|
sound, {.volume = FORTUNE_SOUND_VOLUME, .pitch = isSlidingIn ? FORTUNE_SLIDE_IN_PITCH : 1});
|
|
}
|
|
}
|
|
itemInfoHUD.Update();
|
|
}
|
|
|
|
// 009a2b30 Updates the player corners, then the recent items (computed once, then each dirty player) when they show,
|
|
// then the stats.
|
|
void HUD::PostUpdate()
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
if (hud.player) hud.Update();
|
|
|
|
if (g_manager->optionsConfig.historyHudMode > EXTRA_HUD_STYLE_OFF)
|
|
{
|
|
if (!historyHUD.isComputed)
|
|
{
|
|
historyHUD.isComputed = true;
|
|
historyHUD.RecomputeAll(false);
|
|
}
|
|
for (int i = 0; i < HISTORY_PLAYER_COUNT; i++)
|
|
if (historyHUD.players[i].isDirty) historyHUD.Recompute(i, true);
|
|
}
|
|
statHUD.Update();
|
|
}
|
|
|
|
// 009a6110 Asks for a refresh over the next two frames, unless a full one is pending and this one is lighter.
|
|
void HUD::refresh_request(HudRefresh type)
|
|
{
|
|
if (hudRefreshType == HUD_REFRESH_FULL && type != HUD_REFRESH_FULL) return;
|
|
|
|
hudRefreshType = type;
|
|
hudRefreshCountdown = 2;
|
|
}
|
|
|
|
// 009a2bc0 Flashes the charge bar of a player's active slot.
|
|
void HUD::FlashChargeBar(Entity_Player* player, int activeSlot)
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
{
|
|
if (hud.player != player) continue;
|
|
if (activeSlot >= 0 && activeSlot < PLAYER_HUD_ACTIVE_COUNT)
|
|
hud.activeItems[activeSlot].chargeBarFlash = CHARGE_BAR_FLASH_FRAMES;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 009a2c00 Has a player's active slot, or all of them for a negative slot, reload its item.
|
|
void HUD::InvalidateActiveItem(Entity_Player* player, int activeSlot)
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
{
|
|
if (hud.player != player) continue;
|
|
if (activeSlot >= PLAYER_HUD_ACTIVE_COUNT) return;
|
|
|
|
if (activeSlot >= 0) hud.activeItems[activeSlot].id = 0;
|
|
else
|
|
for (PlayerHUDActiveItem& item : hud.activeItems) item.id = 0;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 009a2c70 Has a player's crafting bag, or every shown player's for none, redraw its items.
|
|
void HUD::InvalidateCraftingItem(Entity_Player* player)
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
{
|
|
if (player ? hud.player != player : !hud.player) continue;
|
|
hud.isCraftingItemDirty = true;
|
|
if (player) return;
|
|
}
|
|
}
|
|
|
|
// 009a8970 Has every shown player corner redraw, then the recent items rebuild when they show, emptied first when
|
|
// asked. Hidden, they are emptied when they hold a player.
|
|
void HUD::mark_all_slots_dirty(HistoryRebuild rebuild, HistoryClear clearing)
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
if (hud.player) hud.isDirty = true;
|
|
|
|
if (g_manager->optionsConfig.historyHudMode == EXTRA_HUD_STYLE_OFF)
|
|
{
|
|
if (historyHUD.players[0].player) historyHUD.clear();
|
|
return;
|
|
}
|
|
if (clearing == HISTORY_CLEAR_ITEMS) historyHUD.clear();
|
|
historyHUD.RecomputeAll(rebuild == HISTORY_REBUILD_ICONS);
|
|
}
|
|
|
|
// 004aaee0 Shows or hides the HUD.
|
|
void HUD::SetVisible(bool isShown)
|
|
{
|
|
isVisible = isShown;
|
|
}
|
|
|
|
// 0085e1c0 Whether the HUD shows.
|
|
bool HUD::IsVisible()
|
|
{
|
|
return isVisible;
|
|
}
|
|
|
|
// 009a2d20 Shows an item's name and description on the stacked banners, or on its player's corner in co-op.
|
|
void HUD::ShowItemText(Entity_Player* player, ItemConfig_Item* item)
|
|
{
|
|
item_text_show(*this, player, item);
|
|
}
|
|
|
|
// 0085e750 Lua's HUD:ShowItemText, for a player and item or a title and description.
|
|
int HUD::lua_show_item_text(void*)
|
|
{
|
|
reconstruction_missing("HUD::ShowItemText 0085e750 (Lua's HUD:ShowItemText)");
|
|
}
|
|
|
|
// 009a3410 Shows a pill's name, online on its player's banner, else on the first free stacked banner (none when all
|
|
// six show).
|
|
// The original shows a player without a corner on the banner before the first. Here it shows none.
|
|
void HUD::show_pill_name(Entity_Player* player, const char* title, const char* subtitle)
|
|
{
|
|
if (g_manager->netplayManager.is_online() && !g_game->deathmatchManager.is_active())
|
|
{
|
|
int hudIndex = GetPlayerHudIndex(player);
|
|
if (hudIndex >= 0) messagePlayerHUD[hudIndex].Show(title, subtitle, true, false);
|
|
return;
|
|
}
|
|
ShowStackedItemTextCustom(title, subtitle);
|
|
}
|
|
|
|
// 009a34a0 (HUD::ShowStackedItemTextCustomUTF16) Shows a title and subtitle on the first free stacked banner, none
|
|
// when all six show.
|
|
void HUD::ShowStackedItemTextCustom(const char* title, const char* subtitle)
|
|
{
|
|
for (HUD_Message& message : messageStack)
|
|
if (!message.isShowing) return message.Show(title, subtitle, true, false);
|
|
}
|
|
|
|
// 0085eca0 Lua's HUD:ShowFortuneText: shows a fortune's lines on the fortune paper.
|
|
void HUD::ShowFortuneText(const std::vector<std::string>& lines)
|
|
{
|
|
render_fortune_text(lines);
|
|
}
|
|
|
|
// 009a3590 Shows one line on the fortune paper (a curse's name, a notice).
|
|
void HUD::show_fortune_line(const char* text)
|
|
{
|
|
render_fortune_text({text});
|
|
}
|
|
|
|
// The font the fortune paper writes in: the HUD's own, the Korean one, or Upheaval when neither loaded.
|
|
static Font& fortune_font(HUD& hud)
|
|
{
|
|
if (hud.font.isLoaded) return hud.font;
|
|
return hud.fontKR.isLoaded ? hud.fontKR : g_manager->font7_Upheaval;
|
|
}
|
|
|
|
// 009a36d0 Shows a text on the fortune paper wrapped into lines that fit it, breaking after the last space before the
|
|
// edge, or inside a word with no space.
|
|
void HUD::show_fortune_text_impl(const char* text)
|
|
{
|
|
Font& font = fortune_font(*this);
|
|
std::vector<std::string> lines;
|
|
const char* end = text + std::strlen(text);
|
|
const char* lineStart = text;
|
|
const char* lastSpace = text;
|
|
int width = 0;
|
|
for (const char* cursor = text; cursor < end;)
|
|
{
|
|
uint32_t character = 0;
|
|
const char* next = utf8_decode_next(cursor, &character, end);
|
|
if (!character) break;
|
|
|
|
if (std::iswspace((wint_t)character)) lastSpace = cursor;
|
|
width += font.GetStringWidth(std::string_view(cursor, (size_t)(next - cursor)));
|
|
if (width <= FORTUNE_LINE_WIDTH)
|
|
{
|
|
cursor = next;
|
|
continue;
|
|
}
|
|
|
|
bool isAtSpace = lastSpace != lineStart;
|
|
lines.emplace_back(lineStart, isAtSpace ? lastSpace : cursor);
|
|
if (isAtSpace) cursor = utf8_decode_next(lastSpace, &character, end);
|
|
lineStart = cursor;
|
|
lastSpace = cursor;
|
|
width = 0;
|
|
}
|
|
lines.emplace_back(lineStart, end);
|
|
render_fortune_text(lines);
|
|
}
|
|
|
|
// 009a3ac0 Writes a fortune's lines centred into the fortune surface in black, at half size when they are too wide or
|
|
// too many, and plays the paper that fits them (Text, Text2 or Text3). No lines leave the plain paper, empty.
|
|
void HUD::render_fortune_text(const std::vector<std::string>& lines)
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Font& font = fortune_font(*this);
|
|
float textScale = 1;
|
|
float lineHeight = FORTUNE_LINE_HEIGHT;
|
|
int maxWidth = 0;
|
|
for (const std::string& line : lines) maxWidth = std::max(maxWidth, font.GetStringWidth(line));
|
|
|
|
float textHeight = (float)lines.size() * FORTUNE_LINE_HEIGHT;
|
|
if (maxWidth > FORTUNE_MAX_WIDTH || textHeight > FORTUNE_MAX_HEIGHT)
|
|
{
|
|
textScale = 0.5f;
|
|
lineHeight = FORTUNE_LINE_HEIGHT * 0.5f;
|
|
textHeight *= 0.5f;
|
|
}
|
|
const char* paper = textHeight > FORTUNE_LINE_HEIGHT * 2 ? "Text3" : textHeight > FORTUNE_LINE_HEIGHT ? "Text2" : "Text";
|
|
fortuneSprite.Play(lines.empty() ? "Text" : paper, PLAY_FORCED);
|
|
if (!fortuneTextImage) return;
|
|
|
|
graphics.render_target_push(fortuneTextImage.get(), KAGE::Graphics::TARGET_OWN_SIZE, KAGE::Graphics::PRESENT_FLUSH);
|
|
graphics.Clear();
|
|
if (!lines.empty())
|
|
{
|
|
graphics.blendMode = BLEND_MODE_PREMULTIPLIED;
|
|
FontSettings settings(ALIGN_TOP_CENTER);
|
|
float centerX = (float)fortuneTextImage->width * 0.5f;
|
|
float y = 0;
|
|
for (const std::string& line : lines)
|
|
{
|
|
font.DrawString(line, vector_make(centerX, y), vector_make(textScale, textScale), BLACK, settings);
|
|
y += lineHeight;
|
|
}
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
}
|
|
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
|
}
|
|
|
|
// 009807a0 (Game::ShowFortuneText) A random line of a string table category on the fortune paper, its '|' marks
|
|
// starting new lines.
|
|
void fortune_text_show(RNG& rng, std::string_view category)
|
|
{
|
|
StringTable& table = g_manager->stringTable;
|
|
std::string key(category);
|
|
std::ranges::transform(key, key.begin(), [](unsigned char c) { return (char)std::tolower(c); });
|
|
auto found = table.categories.find(key);
|
|
size_t count = found == table.categories.end() ? 0 : found->second.keys.size();
|
|
std::string_view text = table.get_string_by_index(category, table.language, rng.RandomInt((uint32_t)count));
|
|
|
|
std::vector<std::string> lines;
|
|
std::string line;
|
|
for (char character : text)
|
|
{
|
|
if (character != FORTUNE_LINE_BREAK)
|
|
{
|
|
line += character;
|
|
continue;
|
|
}
|
|
lines.push_back(line);
|
|
line.clear();
|
|
}
|
|
if (!line.empty()) lines.push_back(line);
|
|
g_game->hud.render_fortune_text(lines);
|
|
}
|
|
|
|
// (005b1870, 0065d070, 00753d00 Game::ShowFortune, the seeds' fortune and Game::ShowRule) A line of a fortune category
|
|
// from the run's fortune generator.
|
|
void fortune_show(std::string_view category)
|
|
{
|
|
fortune_text_show(g_game->fortuneRNG, category);
|
|
}
|
|
|
|
// 009a3eb0 Draws the HUD unless it is hidden or the run plays "No HUD": the recent items and minimap, the Boss Rush
|
|
// wave counter, the pickup counters, the run icons and Greed counters, the stats, the banners, every player corner,
|
|
// the co-op join carousel and the boss bar. Every corner forgets the box it covered first.
|
|
void HUD::Render()
|
|
{
|
|
for (PlayerHUD& hud : playerHUD) hud.bounds_reset();
|
|
if (!isVisible) return;
|
|
|
|
Game& game = *g_game;
|
|
if (game.seedEffects.HasSeedEffect(SEED_NO_HUD)) return;
|
|
|
|
const RoomConfig_Room* roomData = game.room->descriptor->data;
|
|
bool isHomeDungeon = roomData && roomData->type == ROOM_DUNGEON && roomData->stageId == STB_HOME;
|
|
Vector shake = game.screenShakeOffset;
|
|
update_hud_offset();
|
|
|
|
OptionsConfig& options = g_manager->optionsConfig;
|
|
if (options.historyHudMode > EXTRA_HUD_STYLE_OFF && !isHomeDungeon)
|
|
{
|
|
constexpr float HISTORY_RIGHT = 87;
|
|
constexpr float HISTORY_SHIFT_X = 24;
|
|
constexpr float HISTORY_SHIFT_Y = -14;
|
|
constexpr float HISTORY_GAP = 32;
|
|
float offset = 1 - options.hudOffset;
|
|
Vector mapSize = game.minimap.GetDisplayedSize();
|
|
Vector at = at_make(g_screenWidth - HISTORY_RIGHT + offset * HISTORY_SHIFT_X,
|
|
offset * HISTORY_SHIFT_Y + (mapSize.y + HISTORY_GAP));
|
|
historyHUD.Render(at, options.historyHudMode == EXTRA_HUD_STYLE_ON_MINI);
|
|
}
|
|
|
|
if (!game.deathmatchManager.is_active())
|
|
{
|
|
game.minimap.Render();
|
|
if (game.ambush.isActive && game.room->roomType == ROOM_BOSSRUSH)
|
|
{
|
|
constexpr float WAVE_BOX_WIDTH = 64;
|
|
constexpr float WAVE_BOX_HEIGHT = 32;
|
|
constexpr float WAVE_TOP = 20;
|
|
constexpr float WAVE_SHIFT_Y = -24;
|
|
constexpr float WAVE_LINE = 20;
|
|
constexpr float WAVE_TEXT_RIGHT = 53;
|
|
constexpr float WAVE_TEXT_Y = 7;
|
|
Font& font6 = g_manager->font6_PFTempestaSevenCondensed;
|
|
Vector at = at_make((g_screenWidth - WAVE_BOX_WIDTH) * 0.5f + shake.x,
|
|
(1 - options.hudOffset) * WAVE_SHIFT_Y + WAVE_TOP + shake.y);
|
|
if (game.minimap.configs[MINIMAP_SIZE_LARGE].alpha > 0) at.y += WAVE_LINE;
|
|
if (game.dailyChallenge._id != 0) at.y += WAVE_LINE;
|
|
Vector box = at_make(WAVE_BOX_WIDTH, WAVE_BOX_HEIGHT);
|
|
bossHealthBarRushImage->Render(KAGE::Graphics::color_quad_rect(at, box, WHITE), WHITE);
|
|
|
|
char waves[TEXT_BUFFER_SIZE];
|
|
std::snprintf(waves, sizeof(waves), "%d/%d", game.ambush.currentWave, game.ambush.maxWaves);
|
|
float width = (float)(unsigned int)font6.GetStringWidth(waves);
|
|
text_draw(font6, waves, at_make(at.x + WAVE_TEXT_RIGHT - width, at.y + WAVE_TEXT_Y));
|
|
}
|
|
}
|
|
|
|
Vector cursor = at_make(cornerOffsets[0].x + 20, cornerOffsets[0].y + 46);
|
|
float statsX = 0;
|
|
// The original reads past an empty player list after the log. Here the HUD stops there.
|
|
if (game.playerManager.playerList.empty())
|
|
log_printf(LOG_ASSERT, "PlayerManager::GetPlayer() : There are no players! \n");
|
|
render_counters(cursor, shake);
|
|
if (game.playerManager.playerList.empty() || !game.playerManager.playerList[0]) return;
|
|
render_run_icons(cursor, shake, statsX);
|
|
|
|
cursor.x = statsX;
|
|
if (!isHomeDungeon) statHUD.Render(at_make(statsX + 0, cursor.y + 16));
|
|
|
|
render_streak_texts();
|
|
for (int i = 0; i < PLAYER_HUD_COUNT; i++)
|
|
{
|
|
bool isShownOnline = online_hud_mode() != ONLINE_HUD_OFFLINE || i == 0 || i == MAIN_PLAYER_HUD_COUNT;
|
|
bool isShown = !g_manager->netplayManager.is_online() || isShownOnline;
|
|
if (isShown && playerHUD[i].player) render_player_hud(i, GetPlayerHUDLayout(i, playerHUD[i].player));
|
|
}
|
|
// Online the original also draws the lobby members still joining here. Netplay is offline.
|
|
|
|
render_coop_carousel();
|
|
render_boss_health_bar(cursor);
|
|
}
|
|
|
|
// The pickup counters of HUD::Render, a row each from the cursor down: coins (three digits with Deep Pockets), bombs
|
|
// (unless every player is Tainted ???), Tainted ???'s poops, keys, Tainted Bethany's blood charges and Bethany's
|
|
// soul charges. The cursor ends on the last row. The rows are tighter with any of the last three characters, and
|
|
// Jacob's start lower. They count the first player's pickups, or in an online versus match the local player's.
|
|
void HUD::render_counters(Vector& cursor, Vector shake)
|
|
{
|
|
constexpr float ROW_HEIGHT = 12;
|
|
constexpr float ROW_HEIGHT_TIGHT = 11;
|
|
constexpr float JACOB_SHIFT = 14;
|
|
constexpr float TEXT_OFFSET_X = 16;
|
|
constexpr float TEXT_OFFSET_Y = 1;
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
Entity_Player* player = players.playerList.empty() ? nullptr : players.playerList[0];
|
|
if (!player) return;
|
|
|
|
if (player->playerType == PLAYER_JACOB) cursor.y += JACOB_SHIFT;
|
|
Entity_Player* bethany = players.FirstPlayerByType(PLAYER_BETHANY);
|
|
Entity_Player* bethanyB = players.FirstPlayerByType(PLAYER_BETHANY_B);
|
|
bool isAllBlueBabyB = players.are_all_players_tainted_blue_baby();
|
|
Entity_Player* blueBabyB = players.FirstPlayerByType(PLAYER_BLUEBABY_B);
|
|
float rowHeight = bethany || bethanyB || (blueBabyB && !isAllBlueBabyB) ? ROW_HEIGHT_TIGHT : ROW_HEIGHT;
|
|
|
|
Font& font6 = g_manager->font6_PFTempestaSevenCondensed;
|
|
char count[TEXT_BUFFER_SIZE];
|
|
bool isFirst = true;
|
|
auto row = [&](const char* format, int value)
|
|
{
|
|
if (!isFirst) cursor.y += rowHeight;
|
|
isFirst = false;
|
|
sprite_draw(pickupHUDSprite, cursor);
|
|
|
|
Vector at = at_make(shake.x + cursor.x, shake.y + cursor.y);
|
|
std::snprintf(count, sizeof(count), format, value);
|
|
text_draw(font6, count, at_make(at.x + TEXT_OFFSET_X, at.y + TEXT_OFFSET_Y));
|
|
cursor = at_make(at.x - shake.x, at.y - shake.y);
|
|
};
|
|
|
|
pickupHUDSprite.SetFrame(ANIMATION_IDLE, FRAME_COIN);
|
|
bool isDeepPockets = players.FirstCollectibleOwner(COLLECTIBLE_DEEP_POCKETS, LAZARUS_SHARE_CHECK);
|
|
row(isDeepPockets ? "%03d" : "%02d", player->numCoins);
|
|
if (!isAllBlueBabyB)
|
|
{
|
|
pickupHUDSprite.SetFrame((float)(player->numGigaBombs ? FRAME_GIGA_BOMB
|
|
: player->hasGoldenBomb ? FRAME_GOLDEN_BOMB
|
|
: FRAME_BOMB));
|
|
row("%02d", player->numBombs);
|
|
}
|
|
if (blueBabyB)
|
|
{
|
|
pickupHUDSprite.SetFrame((float)FRAME_POOP);
|
|
row(players.FirstBirthrightOwner(PLAYER_BLUEBABY_B) ? "%02d" : "%d", player->poopMana);
|
|
}
|
|
pickupHUDSprite.SetFrame((float)(player->hasGoldenKey ? FRAME_GOLDEN_KEY : FRAME_KEY));
|
|
row("%02d", player->numKeys);
|
|
if (bethanyB)
|
|
{
|
|
pickupHUDSprite.SetFrame((float)FRAME_BLOOD_CHARGE);
|
|
row("%02d", player->effectiveBloodCharge);
|
|
}
|
|
if (bethany)
|
|
{
|
|
pickupHUDSprite.SetFrame((float)FRAME_SOUL_CHARGE);
|
|
row("%02d", player->effectiveSoulCharge);
|
|
}
|
|
}
|
|
|
|
// The run icons of HUD::Render under the counters (hard mode, achievements off or daily, Greed or Greedier, the
|
|
// donation machine), a single one nudged right outside challenges and before Ultra Greed's floor, then the victory
|
|
// lap count, a challenge's destination or Greed's wave and donation jam counters. statsX keeps where the stats start.
|
|
void HUD::render_run_icons(Vector& cursor, Vector shake, float& statsX)
|
|
{
|
|
constexpr float ICON_GAP = 16;
|
|
constexpr float SINGLE_ICON_NUDGE = 4;
|
|
constexpr float LAP_TEXT_X = 18;
|
|
constexpr float GREED_TEXT_X = 4;
|
|
constexpr float ROUNDING = 0.5f;
|
|
constexpr int GREED_WAVES = 10;
|
|
|
|
Game& game = *g_game;
|
|
Font& font6 = g_manager->font6_PFTempestaSevenCondensed;
|
|
char text[TEXT_BUFFER_SIZE];
|
|
bool isAchievementsOff = game.seedEffects.isCustomRun || game.seedEffects.AchievementUnlocksDisallowed() ||
|
|
Manager::AchievementUnlocksDisallowed() || game.isRerun || game.challenge != 0;
|
|
bool isDaily = game.dailyChallenge._id != 0;
|
|
bool isChallenge = isDaily || game.challenge != 0;
|
|
bool isHard = game.difficulty == DIFFICULTY_HARD && !isChallenge;
|
|
bool isGreed = !isHard && game.IsGreedMode() && !game.deathmatchManager.is_active();
|
|
bool isGreedBossCleared = false;
|
|
if (isGreed)
|
|
{
|
|
// Rebirth's Level is the front of Game, and Game declares none of its methods yet.
|
|
RoomDescriptor* room = game.GetRoomByIdx(game.currentRoomIdx, -1);
|
|
isGreedBossCleared = room->listIndex == game.lastBossRoomListIdx &&
|
|
(game.room->descriptor->flags & ROOM_FLAG_CLEAR) && game.stage == STAGE_ULTRA_GREED;
|
|
}
|
|
|
|
std::vector<int> icons;
|
|
icons.reserve(3);
|
|
if (isHard) icons.push_back(FRAME_HARD);
|
|
if (isDaily) icons.push_back(FRAME_DAILY);
|
|
else if (isAchievementsOff) icons.push_back(FRAME_ACHIEVEMENTS_OFF);
|
|
if (isGreed)
|
|
icons.push_back(isGreedBossCleared ? FRAME_GREED_DONATION
|
|
: game.difficulty == DIFFICULTY_GREEDIER ? FRAME_GREEDIER
|
|
: FRAME_GREED);
|
|
|
|
Vector nudge = {};
|
|
statsX = cursor.x;
|
|
if (!icons.empty())
|
|
{
|
|
cursor.y += ICON_GAP;
|
|
if (icons.size() == 1 && !isChallenge && (!isGreed || game.stage >= STAGE_ULTRA_GREED))
|
|
nudge.x = SINGLE_ICON_NUDGE;
|
|
float iconY = cursor.y + nudge.y;
|
|
for (int frame : icons)
|
|
{
|
|
pickupHUDSprite.SetFrame((float)frame);
|
|
sprite_draw(pickupHUDSprite, at_make(nudge.x + cursor.x, iconY));
|
|
cursor.x += ICON_GAP;
|
|
}
|
|
}
|
|
|
|
if (isGreed)
|
|
{
|
|
Vector at = at_make(shake.x + cursor.x, shake.y + cursor.y);
|
|
bool isShown = true;
|
|
if (game.stage < STAGE_ULTRA_GREED)
|
|
{
|
|
int waves = GREED_WAVES + (game.difficulty == DIFFICULTY_GREEDIER);
|
|
std::snprintf(text, sizeof(text), "%d/%d", game.greedModeWave, waves);
|
|
}
|
|
else if (isGreedBossCleared)
|
|
{
|
|
// Online the original reads the donations of the lobby host's profile. Netplay is offline.
|
|
PersistentGameData& data = g_manager->persistentGameData;
|
|
float jamChance = game.GetPlayer(0)->GetGreedDonationJamChance(data);
|
|
std::snprintf(text, sizeof(text), "%d%%", (int)(jamChance + ROUNDING));
|
|
}
|
|
else isShown = false;
|
|
if (isShown) text_draw(font6, text, at_make(at.x + GREED_TEXT_X, at.y));
|
|
cursor.y = at.y - shake.y;
|
|
return;
|
|
}
|
|
|
|
if (!isChallenge)
|
|
{
|
|
if (game.victoryLap <= 0) return;
|
|
|
|
pickupHUDSprite.SetFrame((float)FRAME_VICTORY_LAP);
|
|
sprite_draw(pickupHUDSprite, cursor);
|
|
float textY = shake.y + cursor.y;
|
|
std::snprintf(text, sizeof(text), "%d", game.victoryLap);
|
|
text_draw(font6, text, at_make(shake.x + cursor.x + LAP_TEXT_X, textY));
|
|
cursor.y = textY - shake.y;
|
|
return;
|
|
}
|
|
|
|
pickupHUDSprite.Play(ANIMATION_DESTINATION);
|
|
ChallengeParam& params = game.GetChallengeParams();
|
|
int destination = -1;
|
|
if (params.isMegaSatan) destination = DESTINATION_MEGA_SATAN;
|
|
else if (params.pathType == PATH_TYPE_HOME) destination = DESTINATION_BEAST;
|
|
else
|
|
switch (params.endStage)
|
|
{
|
|
case END_STAGE_DEPTHS: destination = DESTINATION_MOM; break;
|
|
case END_STAGE_WOMB:
|
|
destination = params.pathType == PATH_TYPE_REPENTANCE ? DESTINATION_MOTHER : DESTINATION_MOMS_HEART;
|
|
break;
|
|
case END_STAGE_SHEOL:
|
|
destination = params.pathType == PATH_TYPE_CATHEDRAL ? DESTINATION_ISAAC : DESTINATION_SATAN;
|
|
break;
|
|
case END_STAGE_DARK_ROOM:
|
|
destination = params.pathType == PATH_TYPE_CATHEDRAL ? DESTINATION_BLUE_BABY : DESTINATION_LAMB;
|
|
break;
|
|
case END_STAGE_VOID: destination = DESTINATION_DELIRIUM; break;
|
|
}
|
|
if (destination >= 0) pickupHUDSprite.SetFrame((float)destination);
|
|
sprite_draw(pickupHUDSprite, at_make(nudge.x + cursor.x, nudge.y + cursor.y));
|
|
pickupHUDSprite.Play(ANIMATION_IDLE);
|
|
}
|
|
|
|
// The co-op join carousel of HUD::Render: each joining controller's seat shows the characters around its choice,
|
|
// fading and shrinking away from it, with its arrows blinking every ten frames.
|
|
void HUD::render_coop_carousel()
|
|
{
|
|
constexpr float PORTRAIT_GAP = 24;
|
|
constexpr float FADE_PER_STEP = 0.5f;
|
|
constexpr float SHRINK_PER_STEP = 0.25f;
|
|
constexpr float SCALE_MIN = 0.5f;
|
|
constexpr int BLINK_PERIOD = 20;
|
|
constexpr int BLINK_ON = 9;
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
for (int seat = 0; seat < COOP_SLOT_COUNT; seat++)
|
|
{
|
|
const CoopJoinSlot& slot = players.coopSlots[seat];
|
|
if (slot.controllerIndex < 0 || slot.state < 0) continue;
|
|
|
|
Vector base = playerHudPositions[seat];
|
|
if (base.x < 0) base.x += g_screenWidth;
|
|
if (base.y < 0) base.y += g_screenHeight;
|
|
|
|
int last = (int)(slot.menuPosition + 1);
|
|
for (int choice = (int)(slot.menuPosition - 1); choice <= last; choice++)
|
|
{
|
|
float distance = (float)choice - slot.menuPosition;
|
|
float offsetX = distance * PORTRAIT_GAP;
|
|
float alpha = std::max(0.0f, 1 - std::abs(distance) * FADE_PER_STEP);
|
|
float portraitScale = std::max(SCALE_MIN, 1 - std::abs(distance) * SHRINK_PER_STEP);
|
|
if (alpha <= 0) continue;
|
|
|
|
// The original divides by the empty list of co-op characters. Here an empty list shows no portraits.
|
|
auto typeCount = (unsigned int)players.coopPlayerTypes.size();
|
|
if (!typeCount) continue;
|
|
int playerType = players.coopPlayerTypes[(unsigned int)(choice + typeCount) % typeCount];
|
|
Vector at = at_make(offsetX + base.x, base.y + 0);
|
|
if (playerType >= PLAYER_TYPE_COUNT)
|
|
{
|
|
ColorMod color = COLOR_DEFAULT;
|
|
color._tint[3] = alpha;
|
|
render_modded_coop_portrait(playerType, at, vector_make(portraitScale, portraitScale), color);
|
|
continue;
|
|
}
|
|
|
|
AnimationState& state = coopMenuSprite.animState;
|
|
if (state.animData) state.SetLayerFrame(0, playerType + 1);
|
|
coopMenuSprite.color._tint[3] = alpha;
|
|
coopMenuSprite.scale = vector_make(portraitScale, portraitScale);
|
|
state.RenderLayer(0, {at, {}, {}}, coopMenuSprite);
|
|
}
|
|
|
|
coopMenuSprite.color._tint[3] = 1;
|
|
coopMenuSprite.scale = vector_make(1, 1);
|
|
AnimationState& arrows = coopMenuSprite.overlayAnimState;
|
|
if (arrows.animData) arrows.SetFrameFloat((float)(g_game->frameCount % BLINK_PERIOD > BLINK_ON));
|
|
arrows.Render({base, {}, {}}, coopMenuSprite);
|
|
}
|
|
}
|
|
|
|
// 009a6a70 Draws the banners: the main one at the bottom (sticky) or top of the screen, the stacked ones in rows
|
|
// below it, each player's small one by its corner in its player's color (closed when the corner lost its player),
|
|
// and the fortune paper with its text where its null 0 puts it.
|
|
void HUD::render_streak_texts()
|
|
{
|
|
constexpr float BANNER_EDGE = 48;
|
|
constexpr float STACK_TOP_UNDER_STICKY = 83;
|
|
constexpr float STACK_ROW = 35;
|
|
constexpr float PLAYER_BANNER_SCALE = 0.5f;
|
|
constexpr float FORTUNE_TOP = 64;
|
|
constexpr float FORTUNE_TEXT_RISE = 16;
|
|
|
|
float centerX = g_screenWidth * 0.5f;
|
|
float stackTop = BANNER_EDGE;
|
|
if (messageMain.isShowing)
|
|
{
|
|
messageMain.Render(at_make(centerX, messageMain.isAutoHide ? BANNER_EDGE : g_screenHeight - BANNER_EDGE), 1);
|
|
if (!messageMain.isAutoHide) stackTop = STACK_TOP_UNDER_STICKY;
|
|
}
|
|
for (unsigned int i = 0; i < MESSAGE_STACK_COUNT; i++)
|
|
if (messageStack[i].isShowing) messageStack[i].Render(at_make(centerX + 0, (float)i * STACK_ROW + stackTop), 1);
|
|
|
|
for (int i = 0; i < MAIN_PLAYER_HUD_COUNT; i++)
|
|
{
|
|
HUD_Message& message = messagePlayerHUD[i];
|
|
Entity_Player* player = playerHUD[i].player;
|
|
if (!message.isShowing) continue;
|
|
if (!player)
|
|
{
|
|
message.free_text_buffers();
|
|
message.isShowing = false;
|
|
continue;
|
|
}
|
|
|
|
constexpr float BELOW = 35;
|
|
constexpr float BELOW_TWINS = 65;
|
|
constexpr float ABOVE = 30;
|
|
constexpr float ABOVE_TWINS = 50;
|
|
constexpr float SHIFT_LEFT_CORNER = 35;
|
|
constexpr float SHIFT_RIGHT_CORNER = 20;
|
|
bool isTwins = is_jacob_or_esau(player);
|
|
Vector at = get_player_hud_position(i, HUD_LAYOUT_COMPACT);
|
|
if (i < 2) at.y += isTwins ? BELOW_TWINS : BELOW;
|
|
else at.y -= isTwins ? ABOVE_TWINS : ABOVE;
|
|
at.x += i == 0 || i == 2 ? SHIFT_LEFT_CORNER : SHIFT_RIGHT_CORNER;
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
int colorIndex = COLOR_INDEX_NONE;
|
|
for (int j = 0; j < COOP_SLOT_COUNT; j++)
|
|
if (players.colorControllers[j] == player->controllerIndex)
|
|
{
|
|
colorIndex = j;
|
|
break;
|
|
}
|
|
KColor color = PlayerManager::GetPlayerColorValue(colorIndex);
|
|
message.streakColor = kcolor_rgba(channel_quantize(color._red), channel_quantize(color._green),
|
|
channel_quantize(color._blue), channel_quantize(color._alpha));
|
|
message.Render(at, PLAYER_BANNER_SCALE);
|
|
}
|
|
|
|
AnimationState& fortune = fortuneSprite.animState;
|
|
if (!fortune.animData || !fortune.isPlaying) return;
|
|
|
|
Vector at = at_make(centerX, FORTUNE_TOP);
|
|
sprite_draw(fortuneSprite, at);
|
|
// The original reads a missing null 0. A paper without one shows no text.
|
|
const NullFrame* frame = fortune.GetNullFrameById(0);
|
|
if (!frame || !fortuneTextImage) return;
|
|
|
|
Vector shake = g_game->screenShakeOffset;
|
|
Vector size = at_make((float)fortuneTextImage->width * frame->scale.x,
|
|
(float)fortuneTextImage->height * frame->scale.y);
|
|
Vector corner = at_make(at.x + frame->pos.x - size.x * 0.5f + shake.x,
|
|
at.y + frame->pos.y - FORTUNE_TEXT_RISE + shake.y);
|
|
fortuneTextImage->Render(KAGE::Graphics::color_quad_rect(corner, size, WHITE), WHITE);
|
|
}
|
|
|
|
// 009a6fe0 Draws a player's corner in its layout: the online status, the hearts, then (for a real player, not a
|
|
// co-op baby) the actives, trinkets, Tainted Isaac's inventory or Tainted ???'s spells and the pockets. Twins fade
|
|
// the one not in control, and Curse of the Mist fades the actives.
|
|
void HUD::render_player_hud(int playerHudIndex, PlayerHudLayout layout)
|
|
{
|
|
constexpr float TWIN_FADE = 0.7f;
|
|
constexpr float TWIN_FADE_MIN = 0.3f;
|
|
constexpr float MIST_ALPHA = 0.2f;
|
|
constexpr float SMALL = 0.5f;
|
|
constexpr float TRINKET_STEP = 16;
|
|
constexpr float POCKET_RISE = 1;
|
|
|
|
Vector hudPos = get_player_hud_position(playerHudIndex, layout);
|
|
PlayerHUD& hud = playerHUD[playerHudIndex];
|
|
Entity_Player* player = hud.player;
|
|
if (!player) return;
|
|
|
|
bool isOnline = g_manager->netplayManager.is_online();
|
|
if (isOnline && is_main_twin(*player)) render_player_net_status(playerHudIndex, hudPos);
|
|
Vector extent;
|
|
hud.RenderHearts(extent, heartsSprite, layout, 1, hudPos);
|
|
bool isMainCorner = playerHudIndex == 0 || playerHudIndex == MAIN_PLAYER_HUD_COUNT;
|
|
if (isOnline && !g_game->deathmatchManager.is_active() && g_manager->optionsConfig.onlineHud == ONLINE_HUD_HIDDEN &&
|
|
!isMainCorner)
|
|
return;
|
|
if (player->variant != 0) return;
|
|
|
|
float activeAlpha = 1;
|
|
float pocketAlpha = 1;
|
|
if (is_jacob_or_esau(player))
|
|
{
|
|
float fade = hud.dropHoldFade * TWIN_FADE;
|
|
Entity_Player* twin = player->twin_get();
|
|
if (g_manager->optionsConfig.jacobEsauControls == 0)
|
|
{
|
|
if (twin)
|
|
{
|
|
activeAlpha = 1 - fade;
|
|
pocketAlpha = fade + TWIN_FADE_MIN;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
activeAlpha = twin && is_main_twin(*player) ? 1 - fade : fade + TWIN_FADE_MIN;
|
|
pocketAlpha = activeAlpha;
|
|
}
|
|
}
|
|
if (player->hasCurseMistEffect) activeAlpha = MIST_ALPHA;
|
|
bool isNetCompact = isOnline && online_hud_mode() == ONLINE_HUD_COMPACT && !isMainCorner;
|
|
|
|
if (layout == HUD_LAYOUT_NORMAL)
|
|
{
|
|
hud.RenderActiveItem(1, at_make(hudPos.x - 53, hudPos.y - 12), layout, 1, activeAlpha);
|
|
hud.RenderActiveItem(0, at_make(hudPos.x - 44, hudPos.y - 12), layout, 1, activeAlpha);
|
|
Vector corner = cornerOffsets[2];
|
|
hud.RenderTrinket(1, at_make(corner.x + 20, g_screenHeight - 52 - 16 + corner.y), 1, false);
|
|
hud.RenderTrinket(0, at_make(corner.x + 44, g_screenHeight - 28 - 16 + corner.y), 1, false);
|
|
if (player->playerType == PLAYER_ISAAC_B)
|
|
hud.render_inventory(at_make(cornerOffsets[0].x + 58, cornerOffsets[0].y + 45), 1);
|
|
else if (player->playerType == PLAYER_BLUEBABY_B)
|
|
hud.RenderSpellQueue(at_make(cornerOffsets[0].x + 58, cornerOffsets[0].y + 49), 1);
|
|
Vector pockets = at_make(g_screenWidth - 28 + cornerOffsets[3].x, g_screenHeight - 18 + cornerOffsets[3].y);
|
|
hud.RenderPocketItems(pockets, layout, pocketAlpha, 1);
|
|
return;
|
|
}
|
|
|
|
Vector cursor;
|
|
if (hud.playerHudIndex >= MAIN_PLAYER_HUD_COUNT && layout == HUD_LAYOUT_JACOB_ESAU)
|
|
{
|
|
hud.RenderActiveItem(1, at_make(hudPos.x + 28, hudPos.y - 16), layout, 1, activeAlpha);
|
|
hud.RenderActiveItem(0, at_make(hudPos.x + 12, hudPos.y - 12), layout, 1, activeAlpha);
|
|
cursor = at_make(hudPos.x + 0, hudPos.y + 20);
|
|
for (int slot = PLAYER_HUD_TRINKET_COUNT - 1; slot >= 0; slot--)
|
|
{
|
|
if (!hud.trinkets[slot].id) continue;
|
|
hud.RenderTrinket(slot, cursor, SMALL, true);
|
|
cursor.x -= TRINKET_STEP;
|
|
}
|
|
cursor.x += 0;
|
|
PocketItem& pocket = player->pocketItems[0];
|
|
if (pocket.type != POCKET_ACTIVE && pocket.id == 0) return;
|
|
}
|
|
else if (layout == HUD_LAYOUT_JACOB_ESAU_COMPACT)
|
|
{
|
|
constexpr float ESAU_DROP = 32;
|
|
Vector base = hud.playerHudIndex < MAIN_PLAYER_HUD_COUNT ? hudPos : at_make(hudPos.x + 0, hudPos.y + ESAU_DROP);
|
|
hud.RenderActiveItem(1, at_make(base.x - 34, base.y - 8), layout, SMALL, activeAlpha);
|
|
hud.RenderActiveItem(0, at_make(base.x - 25, base.y - 8), layout, SMALL, activeAlpha);
|
|
cursor = at_make(base.x - 12, base.y + 20);
|
|
if (online_hud_mode() == ONLINE_HUD_COMPACT && !isMainCorner) cursor = at_make(cursor.x + 0, cursor.y - 8);
|
|
for (int slot = PLAYER_HUD_TRINKET_COUNT - 1; slot >= 0; slot--)
|
|
{
|
|
if (!hud.trinkets[slot].id) continue;
|
|
hud.RenderTrinket(slot, cursor, SMALL, true);
|
|
cursor.x += TRINKET_STEP;
|
|
}
|
|
cursor.x -= 2;
|
|
}
|
|
else
|
|
{
|
|
constexpr float TRINKET_DROP = 22;
|
|
constexpr float NET_COMPACT_RISE = 9;
|
|
constexpr float POCKET_GAP = 3;
|
|
hud.RenderActiveItem(1, at_make(hudPos.x - 45, hudPos.y - 16), layout, 1, activeAlpha);
|
|
hud.RenderActiveItem(0, at_make(hudPos.x - 44, hudPos.y - 12), layout, 1, activeAlpha);
|
|
float left = hudPos.x + 0;
|
|
cursor = at_make(left, hudPos.y + TRINKET_DROP);
|
|
if (isNetCompact) cursor.y -= NET_COMPACT_RISE;
|
|
bool isAnyTrinket = false;
|
|
for (int slot = PLAYER_HUD_TRINKET_COUNT - 1; slot >= 0; slot--)
|
|
{
|
|
if (!hud.trinkets[slot].id) continue;
|
|
hud.RenderTrinket(slot, cursor, SMALL, true);
|
|
cursor.x += TRINKET_STEP;
|
|
isAnyTrinket = true;
|
|
}
|
|
if (player->playerType == PLAYER_ISAAC_B)
|
|
hud.render_inventory(at_make(left + cornerOffsets[0].x, hudPos.y + 33 + cornerOffsets[0].y), 1);
|
|
else if (player->playerType == PLAYER_BLUEBABY_B)
|
|
hud.RenderSpellQueue(at_make(left + cornerOffsets[0].x, hudPos.y + 39 + cornerOffsets[0].y), 1);
|
|
cursor.x -= POCKET_GAP;
|
|
if (isAnyTrinket) cursor.x -= POCKET_GAP;
|
|
}
|
|
cursor.y += POCKET_RISE;
|
|
hud.RenderPocketItems(cursor, layout, pocketAlpha, SMALL);
|
|
}
|
|
|
|
// 009a79b0 Draws an online player's name, avatar and connection by its corner.
|
|
void HUD::render_player_net_status(int, Vector)
|
|
{
|
|
reconstruction_missing("HUD::render_player_net_status 009a79b0");
|
|
}
|
|
|
|
// 009a7c90 Draws the boss bar, centered at the top of the screen (or the bottom, by option or when forced), outside
|
|
// Mega Satan's and Mother's fights and Home's dungeon: Great Gideon's stone counter, or the frame and the fill
|
|
// tinted by the damage and heal flashes. Outside boss, Boss Rush and challenge rooms (but in Home) the bar is the
|
|
// mini one, and Dogma's static bar flickers in its own shader. Not drawing it ends a forced bottom placement.
|
|
void HUD::render_boss_health_bar(Vector barPos)
|
|
{
|
|
constexpr float BAR_HEIGHT = 32;
|
|
constexpr float BAR_MARGIN = 8;
|
|
constexpr float BAR_WIDTH = 148;
|
|
constexpr float STONE_WIDTH = 64;
|
|
constexpr float FILL_LEFT = 20;
|
|
constexpr float FILL_WIDTH = 110;
|
|
constexpr float STONE_TEXT_RIGHT = 48;
|
|
constexpr float STONE_TEXT_Y = 7;
|
|
constexpr int STATIC_STEPS = 256;
|
|
|
|
Room& room = *g_game->room;
|
|
const RoomConfig_Room* roomData = room.descriptor->data;
|
|
bool isHomeDungeon = roomData && roomData->type == ROOM_DUNGEON && roomData->stageId == STB_HOME;
|
|
if (bossHPBarFill < 0 || room.bossId == BOSS_MEGA_SATAN || room.bossId == BOSS_MOTHER || isHomeDungeon)
|
|
{
|
|
isBossBarBottom = false;
|
|
return;
|
|
}
|
|
|
|
bool isBottom = isBossBarBottom || g_manager->optionsConfig.isBossHpOnBottom;
|
|
barPos.y = isBottom ? g_screenHeight - BAR_HEIGHT - BAR_MARGIN + bossBarOffset : BAR_MARGIN - bossBarOffset;
|
|
if (room.bossId == BOSS_GREAT_GIDEON)
|
|
{
|
|
barPos.x = (g_screenWidth - STONE_WIDTH) * 0.5f;
|
|
Vector stoneSize = at_make(STONE_WIDTH, BAR_HEIGHT);
|
|
bossHealthBarStoneImage->Render(KAGE::Graphics::color_quad_rect(barPos, stoneSize, WHITE), WHITE);
|
|
|
|
Font& font6 = g_manager->font6_PFTempestaSevenCondensed;
|
|
char text[TEXT_BUFFER_SIZE];
|
|
std::snprintf(text, sizeof(text), "%d/%d", bossCounter, bossCounterTotal);
|
|
float width = (float)(unsigned int)font6.GetStringWidth(text);
|
|
text_draw(font6, text, at_make(barPos.x + STONE_TEXT_RIGHT - width, barPos.y + STONE_TEXT_Y));
|
|
return;
|
|
}
|
|
|
|
barPos.x = (g_screenWidth - BAR_WIDTH) * 0.5f;
|
|
Vector barSize = at_make(BAR_WIDTH, BAR_HEIGHT);
|
|
Vector fillSize = at_make(bossHPBarFill * FILL_WIDTH, BAR_HEIGHT);
|
|
SourceQuad frameSource = KAGE::Graphics::source_quad_rect(at_make(0, BAR_HEIGHT), barSize);
|
|
SourceQuad fillSource = KAGE::Graphics::source_quad_rect(at_make(FILL_LEFT, 0), fillSize);
|
|
KAGE::Graphics::ColorQuad frameQuad = KAGE::Graphics::color_quad_rect(barPos, barSize, WHITE);
|
|
KAGE::Graphics::ColorQuad fillQuad =
|
|
KAGE::Graphics::color_quad_rect(at_make(barPos.x + FILL_LEFT, barPos.y + 0), fillSize, WHITE);
|
|
|
|
ColorMod barColor = COLOR_DEFAULT;
|
|
KAGE::Graphics::ImagePtr barImage = bossHealthBarImage;
|
|
int roomType = (int)room.roomType;
|
|
if (roomType != ROOM_BOSS && roomType != ROOM_BOSSRUSH && roomType != ROOM_CHALLENGE &&
|
|
g_game->GetStageID() != STB_HOME)
|
|
barImage = bossHealthBarMiniImage;
|
|
|
|
bool isDogma = room.backdropType == BACKDROP_DOGMA;
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
bool isShaderPushed = graphics.shader_push(isDogma ? COLOR_OFFSET_DOGMA_SHADER : COLOR_OFFSET_SHADER);
|
|
if (isDogma)
|
|
{
|
|
barColor._colorize[3] = (float)(g_game->frameCount % STATIC_STEPS) * (1.0f / STATIC_STEPS);
|
|
barImage = bossHealthBarStaticImage;
|
|
}
|
|
apply_sprite_shader_params(barColor, SPRITE_SHADER_COLOR_APPLY, *barImage);
|
|
barImage->Render(frameSource, frameQuad, WHITE);
|
|
|
|
// The fill's tint: Dogma's in pale tones, the rest in reds, flashing white-red when hurt and orange when healed.
|
|
struct BarTint
|
|
{
|
|
float red;
|
|
float green;
|
|
float blue;
|
|
};
|
|
auto tint_pick = [isDogma](BarTint dogma, BarTint normal) { return isDogma ? dogma : normal; };
|
|
BarTint tint;
|
|
if (bossHPBarHealFlash >= 1)
|
|
tint = bossHPBarHealFlash % 2 == 1 ? tint_pick({1, 0.8f, 0.6f}, {0.87f, 0.4f, 0})
|
|
: tint_pick({1, 0.95f, 0.8f}, {0.6f, 0.25f, 0});
|
|
else if (bossHPBarDamageFlash > FLASH_OFF && bossHPBarDamageFlash % 2 != 1)
|
|
tint = tint_pick({1, 0.6f, 0.6f}, {0.48f, 0, 0});
|
|
else tint = tint_pick({1, 1, 1}, {0.8f, 0, 0});
|
|
barColor._tint[0] = tint.red;
|
|
barColor._tint[1] = tint.green;
|
|
barColor._tint[2] = tint.blue;
|
|
barColor._tint[3] = 1;
|
|
apply_sprite_shader_params(barColor, SPRITE_SHADER_COLOR_APPLY, *barImage);
|
|
barImage->Render(fillSource, fillQuad, kcolor_rgba(tint.red, tint.green, tint.blue, 1));
|
|
if (isShaderPushed) graphics.shader_pop();
|
|
}
|
|
|
|
// 008f8ee0 Draws a modded character's co-op portrait.
|
|
void HUD::render_modded_coop_portrait(int, Vector, Vector, const ColorMod&)
|
|
{
|
|
reconstruction_missing("HUD::render_modded_coop_portrait 008f8ee0");
|
|
}
|
|
|
|
// 009a8230 Places the HUD by the HUD offset option: the four screen corners, each player corner (negative from the
|
|
// right or bottom), the boss bar's and minimap's offsets.
|
|
void HUD::update_hud_offset()
|
|
{
|
|
float scale = 1 - g_manager->optionsConfig.hudOffset;
|
|
hudScale = scale;
|
|
cornerOffsets[0] = at_make(scale * -20, scale * -12);
|
|
cornerOffsets[1] = at_make(scale * 24, scale * -12);
|
|
cornerOffsets[2] = at_make(hudScale * -22, scale * 16);
|
|
cornerOffsets[3] = at_make(hudScale * 16, hudScale * 6);
|
|
bossBarOffset = hudScale * 12;
|
|
statsOffset = hudScale * 16;
|
|
minimapOffset = hudScale * -14;
|
|
playerHudPositions[0] = at_make(scale * -20 + 68, scale * -12 + 30);
|
|
playerHudPositions[1] = at_make(scale * 24 - 151, cornerOffsets[0].y + 30);
|
|
playerHudPositions[2] = at_make(hudScale * -22 + 80, hudScale * 6 - 33);
|
|
playerHudPositions[3] = at_make(hudScale * 16 - 151, hudScale * 6 - 33);
|
|
playerHudPositions[4] = at_make(hudScale * 16 - 64, hudScale * 6 - 33);
|
|
for (int i = 5; i < PLAYER_HUD_COUNT; i++) playerHudPositions[i] = {};
|
|
}
|
|
|
|
// 009a6140 Where a player corner draws in a layout: its place (an Esau corner of a Jacob & Esau HUD by its Jacob's,
|
|
// or the bottom right one), raised in the lower compact corners, wrapped from the right and bottom edges, spread for
|
|
// online and versus play, and raised over Tainted Isaac's, ???'s and Cain's extra rows.
|
|
// The original reads a missing player of a twin corner. Here such a corner counts as no co-op ghost.
|
|
Vector HUD::get_player_hud_position(int hudIndex, PlayerHudLayout layout)
|
|
{
|
|
constexpr float ONLINE_SPREAD = 24;
|
|
constexpr float VERSUS_SPREAD = 12;
|
|
constexpr float INVENTORY_RISE = 22;
|
|
constexpr float CRAFTING_RISE = 18;
|
|
|
|
PlayerHUD& hud = playerHUD[hudIndex];
|
|
Entity_Player* player = hud.player;
|
|
bool isGhost = player && player->isCoopGhost;
|
|
Vector at = playerHudPositions[hudIndex];
|
|
bool isPlaced = false;
|
|
if (hud.playerHudIndex >= MAIN_PLAYER_HUD_COUNT && !isGhost)
|
|
{
|
|
if (layout == HUD_LAYOUT_JACOB_ESAU)
|
|
{
|
|
at = at_make(cornerOffsets[3].x - 64, cornerOffsets[3].y - 33);
|
|
isPlaced = true;
|
|
}
|
|
else at = playerHudPositions[hudIndex - MAIN_PLAYER_HUD_COUNT];
|
|
}
|
|
bool isLowerCorner = hudIndex == 2 || hudIndex == 3 || hudIndex == 6 || hudIndex == 7;
|
|
if (!isPlaced && layout == HUD_LAYOUT_JACOB_ESAU_COMPACT && !isGhost && isLowerCorner)
|
|
at.y = at.y - (hudScale * 6 + 16);
|
|
|
|
if (at.x < 0) at.x += g_screenWidth;
|
|
if (at.y < 0) at.y += g_screenHeight;
|
|
bool isVersus = g_game->deathmatchManager.is_active();
|
|
if ((hudIndex & 1) && g_manager->netplayManager.is_online() && !isVersus &&
|
|
g_manager->optionsConfig.onlineHud == ONLINE_HUD_COMPACT)
|
|
at.x += ONLINE_SPREAD;
|
|
if (isVersus) at.x += hudIndex & 1 ? -VERSUS_SPREAD : VERSUS_SPREAD;
|
|
|
|
if (!player || hudIndex < 2 || isGhost) return at;
|
|
if (player->playerType == PLAYER_ISAAC_B || player->playerType == PLAYER_BLUEBABY_B) at.y -= INVENTORY_RISE;
|
|
else if (player->playerType == PLAYER_CAIN_B) at.y -= CRAFTING_RISE;
|
|
return at;
|
|
}
|
|
|
|
// 009a64f0 The corner showing a player, Esau's being Jacob's, or -1 (logged) for none or no player.
|
|
int HUD::GetPlayerHudIndex(Entity_Player* player)
|
|
{
|
|
if (!player)
|
|
{
|
|
log_printf(LOG_ERROR, "((()))->HUD::GetPlayerHudIndex() recieved NULL player entity! \n");
|
|
return -1;
|
|
}
|
|
|
|
Entity_Player* shown = is_main_twin(*player) ? player : player->twin_get();
|
|
for (int i = 0; i < MAIN_PLAYER_HUD_COUNT; i++)
|
|
if (playerHUD[i].player == shown) return i;
|
|
|
|
log_printf(LOG_WARN,
|
|
"((()))->HUD::GetPlayerHudIndex() could not for a Player HUD for the giveiten player entity \n");
|
|
return -1;
|
|
}
|
|
|
|
// 009a6570 A corner's layout: offline the first corner is full size until three players show, Jacob and Esau share
|
|
// theirs until four do, and the other corners are compact. Online every main corner is full size.
|
|
PlayerHudLayout HUD::GetPlayerHUDLayout(int playerHudIndex, Entity_Player* player)
|
|
{
|
|
bool isOnline = g_manager->netplayManager.is_online();
|
|
bool isTwins = is_jacob_or_esau(player);
|
|
if (!isOnline && playerHudIndex != 0 && playerHudIndex != MAIN_PLAYER_HUD_COUNT)
|
|
{
|
|
if (!isTwins) return HUD_LAYOUT_COMPACT;
|
|
return count_player_huds() > 2 ? HUD_LAYOUT_JACOB_ESAU_COMPACT : HUD_LAYOUT_JACOB_ESAU;
|
|
}
|
|
|
|
if (!isTwins)
|
|
{
|
|
if (isOnline) return HUD_LAYOUT_NORMAL;
|
|
return count_player_huds() > 2 ? HUD_LAYOUT_COMPACT : HUD_LAYOUT_NORMAL;
|
|
}
|
|
if (isOnline) return HUD_LAYOUT_JACOB_ESAU;
|
|
return count_player_huds() > 3 ? HUD_LAYOUT_JACOB_ESAU_COMPACT : HUD_LAYOUT_JACOB_ESAU;
|
|
}
|
|
|
|
// 009a8430 How many corners show a player.
|
|
int HUD::count_player_huds()
|
|
{
|
|
return (int)std::count_if(playerHUD.begin(), playerHUD.end(), [](PlayerHUD& hud) { return hud.player != nullptr; });
|
|
}
|
|
|
|
// 009a8620 Empties every corner and the join carousel, then gives each leading player the corner of its controller's
|
|
// seat and its twin the seat's twin corner (Tainted Lazarus's other form and Tainted Jacob's ghost get none).
|
|
void HUD::AssignPlayerHUDs()
|
|
{
|
|
for (PlayerHUD& hud : playerHUD)
|
|
{
|
|
if (!hud.player) continue;
|
|
hud.reset();
|
|
hud.isDirty = true;
|
|
hud.isCraftingItemDirty = true;
|
|
}
|
|
|
|
PlayerManager& players = g_game->playerManager;
|
|
auto is_assigned = [](Entity_Player& player)
|
|
{ return is_main_twin(player) && !player.parent && player.isExists; };
|
|
if (!players.playerList.empty())
|
|
{
|
|
for (CoopJoinSlot& slot : players.coopSlots)
|
|
{
|
|
slot.controllerIndex = -1;
|
|
slot.state = -1;
|
|
slot.menuPosition = 0;
|
|
slot.playerType = 0;
|
|
}
|
|
for (Entity_Player* player : players.playerList)
|
|
if (is_assigned(*player)) players.GetPlayerSlotFromController(player->controllerIndex);
|
|
}
|
|
|
|
for (size_t i = 0; i < players.playerList.size(); i++)
|
|
{
|
|
Entity_Player* player = players.playerList[i];
|
|
if (!is_assigned(*player)) continue;
|
|
|
|
int seat = players.GetPlayerSlotFromController(player->controllerIndex);
|
|
if (seat < 0)
|
|
{
|
|
log_printf(LOG_ERROR,
|
|
"((()))->HUD::AssignPlayerHUDs() could not determine player HUD slot for player entity %d "
|
|
"(ControlerIndex = %d) \n",
|
|
(int)i, player->controllerIndex);
|
|
continue;
|
|
}
|
|
|
|
log_printf(LOG_INFO, "Assinging player entity %d (ControlerIndex = %d) to HUD slot %d \n", (int)i,
|
|
player->controllerIndex, seat);
|
|
playerHUD[seat].assign(player);
|
|
|
|
Entity_Player* twin = player->twin_get();
|
|
if (!twin || !twin->isExists || twin->playerType == PLAYER_THESOUL_B) continue;
|
|
bool isLazarusB = twin->playerType == PLAYER_LAZARUS_B || twin->playerType == PLAYER_LAZARUS2_B;
|
|
if (isLazarusB && !is_main_twin(*twin)) continue;
|
|
|
|
log_printf(LOG_INFO, "Assinging player entity %d's twin (ControlerIndex = %d) to HUD slot %d \n", (int)i,
|
|
twin->controllerIndex, seat);
|
|
playerHUD[seat + MAIN_PLAYER_HUD_COUNT].assign(twin);
|
|
}
|
|
}
|