1943 lines
87 KiB
C++
1943 lines
87 KiB
C++
#include "entity/player/hud.h"
|
|
#include "entity/player/active_items.h"
|
|
#include "entity/config.h"
|
|
#include "entity/pickup/pickup.h"
|
|
#include "entity/player/player.h"
|
|
#include "game/game.h"
|
|
#include "ui/hud.h"
|
|
#include "entity/pickup/item_config.h"
|
|
#include "entity/pickup/item_pool.h"
|
|
#include "engine/log.h"
|
|
#include "game/manager.h"
|
|
#include "ui/menu/manager.h"
|
|
#include "ui/menu/special_seeds.h"
|
|
#include "engine/render_passes.h"
|
|
#include "engine/seeds.h"
|
|
#include "engine/data.h"
|
|
#include "stb_image.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <map>
|
|
#ifdef ISAAC_REPENTOGON
|
|
#include "repentogon/player.h"
|
|
#include <cstring>
|
|
#endif
|
|
|
|
constexpr const char* HEARTS_PNG = "gfx/ui/ui_hearts.png";
|
|
constexpr const char* HEARTS_SMALL_PNG = "gfx/ui/ui_hearts_small.png";
|
|
constexpr std::string_view CRAFTING_BLIND_GFX = "gfx/Items/Collectibles/questionmark.png";
|
|
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
|
constexpr const char* ANIMATION_CURSE_HEART = "CurseHeart";
|
|
constexpr const char* ANIMATION_GOLD_OVERLAY = "GoldHeartOverlay";
|
|
constexpr const char* ANIMATION_WHITE_OVERLAY = "WhiteHeartOverlay";
|
|
constexpr const char* MANTLE_WOODEN_CROSS = "HolyMantleWoodenCross";
|
|
constexpr const char* MANTLE_BLANKET = "HolyMantleBlanket";
|
|
constexpr const char* MANTLE_HOLY_MANTLE = "HolyMantle";
|
|
constexpr const char* MANTLE_HOLY_CARD = "HolyMantleHolyCard";
|
|
constexpr const char* EXTRA_LIVES_FORMAT = "x%d%s";
|
|
|
|
// Tainted Isaac's inventory: the icons' frame, the step between slots, the icons' shadow, and ui_inventory's layers.
|
|
constexpr float INVENTORY_ICON_SIZE = 32;
|
|
constexpr float INVENTORY_STEP = 12;
|
|
constexpr float INVENTORY_DOT_ALPHA = 0.5f;
|
|
constexpr int INVENTORY_LAYER_DOT = 0;
|
|
constexpr int INVENTORY_LAYER_SELECT = 1;
|
|
constexpr ColorMod INVENTORY_SHADOW = {{0, 0, 0, 0.3f}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
|
|
// Tainted Cain's crafting table: the result box faded while empty, its icon, and the bag's slots in rows of four.
|
|
constexpr const char* CRAFTING_RESULT_ANIMATION = "Result";
|
|
constexpr ColorMod CRAFTING_EMPTY_COLOR = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float CRAFTING_ICON_SIZE = 32;
|
|
constexpr float CRAFTING_STEP = 12;
|
|
constexpr float CRAFTING_SLOTS_X = 64;
|
|
constexpr float CRAFTING_SLOTS_Y = 6;
|
|
constexpr float CRAFTING_SLOT_REACH = 8;
|
|
constexpr const char* CRAFTING_SLOT_ANIMATION = "Idle";
|
|
|
|
// The Cantripped challenge's card table: three cards and one more per Starter Deck (20 at most), the first in the
|
|
// result box at full size, the rest in a row leftward at half size, an empty one as an empty slot.
|
|
constexpr int CARD_TABLE_BASE = 3;
|
|
constexpr int CARD_TABLE_MAX = 20;
|
|
constexpr float CARD_RESULT_FRAME = 1;
|
|
constexpr float CARD_ROW_X = -26;
|
|
constexpr float CARD_ROW_Y = -6;
|
|
constexpr float CARD_EMPTY_SHIFT_X = 8;
|
|
constexpr float CARD_EMPTY_Y = 2;
|
|
constexpr int CRAFTING_COLUMNS = 4;
|
|
|
|
// The flash colors of HeartFlash, which add to a heart's color: red, soul, black, gold and rotten.
|
|
constexpr std::array<std::array<float, 3>, HEART_FLASH_COUNT> HEART_FLASH_OFFSETS = {{{0, 0, 0},
|
|
{128 / 255.0f, 0, 0},
|
|
{50 / 255.0f, 70 / 255.0f, 90 / 255.0f},
|
|
{80 / 255.0f, 26 / 255.0f, 26 / 255.0f},
|
|
{128 / 255.0f, 100 / 255.0f, 20 / 255.0f},
|
|
{60 / 255.0f, 128 / 255.0f, 0}}};
|
|
|
|
constexpr float HEART_SPACING_X = 12;
|
|
constexpr float HEART_SPACING_Y = 10;
|
|
constexpr float HEART_SMALL_SPACING_X = 8;
|
|
constexpr float HEART_SMALL_SPACING_Y = 6;
|
|
constexpr int HEARTS_PER_ROW = 6;
|
|
constexpr int HEART_ALPHA_FULL = 255;
|
|
constexpr int HEART_ALPHA_DIMMED = 80;
|
|
constexpr int FORGOTTEN_HEART_SLOTS = 6;
|
|
constexpr int GOLD_RESET_SLOT = 5;
|
|
constexpr float DEATHMATCH_BAR_SHIFT_X = -4;
|
|
constexpr float DEATHMATCH_BAR_SHIFT_Y = -6;
|
|
|
|
// Esau's row of the compact twin layout: how far it drops, and the line between it and Jacob's.
|
|
constexpr float ESAU_HEARTS_DROP = 34;
|
|
constexpr float ESAU_HEARTS_DROP_COMPACT = 4;
|
|
constexpr float ESAU_LINE_LEFT = 8;
|
|
constexpr float ESAU_LINE_RIGHT = 45;
|
|
constexpr float ESAU_LINE_RISE = 12;
|
|
|
|
// The fading hearts of Tainted Magdalene: their pulse period and how far they fade.
|
|
constexpr float FADE_PULSE_FRAMES = 30;
|
|
constexpr float FADE_TINT_BASE = 0.5f;
|
|
constexpr float FADE_TINT_RANGE = 0.3f;
|
|
constexpr float FADE_OFFSET_RANGE = 0.1f;
|
|
constexpr float FADE_COLORIZE_BASE = 0.6f;
|
|
constexpr int MAGGY_FADE_START = 2;
|
|
|
|
// The Holy Mantle shields beside the hearts: the most shown, the hearts a row may hold, and the second one's nudge.
|
|
constexpr int MANTLE_LIMIT = 5;
|
|
constexpr int MANTLE_HEART_LIMIT_MIN = 12;
|
|
constexpr int MANTLE_FORGOTTEN_SLOT = 5;
|
|
constexpr int WOODEN_CROSS_SHIELDS_MAX = 2;
|
|
constexpr uint8_t MANTLE_STACKS_MASK = 0xf;
|
|
constexpr float MANTLE_SECOND_X = 6;
|
|
constexpr float MANTLE_SECOND_RISE = 4;
|
|
constexpr float MANTLE_SECOND_ALPHA = 0.5f;
|
|
|
|
// The extra lives text: its gap from the hearts, its rise, and the shift beside a shield or in the compact layout.
|
|
constexpr float LIVES_GAP = 10;
|
|
constexpr float LIVES_RISE = 8;
|
|
constexpr float LIVES_ROW_RISE = 6;
|
|
constexpr float LIVES_COMPACT_SHIFT = 5;
|
|
constexpr float HEART_EXTENT_PAD = 2;
|
|
|
|
// How the HUD fades between the twins' items while the drop button is held.
|
|
constexpr float DROP_FADE_STEP = 0.25f;
|
|
|
|
// The full heart Tainted Magdalene's health drain gives over (with Birthright, one more), and her dropping one.
|
|
constexpr int LAST_HEART_FLASH_PERIOD = 45;
|
|
constexpr int LAST_HEART_FLASH_FRAMES = 10;
|
|
constexpr int LAST_HEART_FLASH_STEPS = 9;
|
|
|
|
// A trinket icon's shadow.
|
|
constexpr float TRINKET_SHADOW_ALPHA = 0.3f;
|
|
constexpr ColorMod TRINKET_SHADOW = {{0, 0, 0, TRINKET_SHADOW_ALPHA}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr uint32_t ERROR_TRINKET_POOL = 189;
|
|
|
|
// The active items whose HUD icon is not their item icon, the books Bethany and Judas show over the first slot, and
|
|
// the Necronomicon's powered icon, which needs three of the form counter it reads.
|
|
constexpr int NECRONOMICON_FORM = 15;
|
|
constexpr int NECRONOMICON_FORM_COUNT = 3;
|
|
|
|
// The pockets: the small ones behind the first (stacked in the normal HUD, in a row in the others), the first's card
|
|
// front, its name and Tarot Cloth's glow, the pocket active's icon and the Bag of Crafting's table.
|
|
constexpr float POCKET_BACK_X = 4;
|
|
constexpr float POCKET_BACK_RISE = -6;
|
|
constexpr float POCKET_BACK_STEP = 10;
|
|
constexpr float POCKET_BACK_ROW_STEP = 8;
|
|
constexpr float POCKET_BACK_ROW_X = 2;
|
|
constexpr float POCKET_BACK_ROW_Y = 12;
|
|
constexpr float POCKET_BACK_ACTIVE_X = -12;
|
|
constexpr float POCKET_BACK_ROW_ACTIVE_X = -4;
|
|
constexpr float POCKET_BACK_ACTIVE_Y = -8;
|
|
constexpr int CARD_FRONT_COUNT = 98;
|
|
constexpr float CARD_FRONT_SHIFT = -3;
|
|
constexpr float POCKET_TEXT_X = -16;
|
|
constexpr float POCKET_ROW_TEXT_X = 13;
|
|
constexpr float POCKET_TEXT_Y = -8;
|
|
constexpr float POCKET_SHOWN_TEXT_Y = -10;
|
|
constexpr float POCKET_ACTIVE_TEXT_SHIFT = -4;
|
|
constexpr float POCKET_ROW_ACTIVE_TEXT_SHIFT = 6;
|
|
constexpr float POCKET_ACTIVE_X = 24;
|
|
constexpr float POCKET_ACTIVE_Y = 18;
|
|
constexpr float POCKET_ROW_ACTIVE_X = 9;
|
|
constexpr float POCKET_ROW_ACTIVE_Y = 8;
|
|
constexpr float CRAFTING_TABLE_X = 14;
|
|
constexpr float CRAFTING_TABLE_Y = -3;
|
|
constexpr float CRAFTING_ROW_TABLE_X = 50;
|
|
constexpr float CRAFTING_ROW_TABLE_Y = 27;
|
|
constexpr float POCKET_SECOND_TWIN_SHIFT = 12;
|
|
constexpr float TAROT_GLOW_SPEED = 0.2f;
|
|
constexpr float TAROT_GLOW_RED_PHASE = 0.5f;
|
|
constexpr float TAROT_GLOW_GREEN_PHASE = 0.25f;
|
|
constexpr float TAROT_GLOW_RED = 0.17f;
|
|
constexpr float TAROT_GLOW_GREEN = 0.1f;
|
|
constexpr float TAROT_GLOW_BLUE = 0.25f;
|
|
|
|
// An active item with its own HUD icon.
|
|
struct ActiveIcon
|
|
{
|
|
int item;
|
|
const char* path;
|
|
};
|
|
|
|
constexpr ActiveIcon ACTIVE_ICONS[] = {{290, "gfx/characters/costumes/Costume_Rebirth_90_TheJar.png"},
|
|
{326, "gfx/ui/hud_BreathOfLife.png"},
|
|
{352, "gfx/ui/hud_GlassCannon.png"},
|
|
{422, "gfx/ui/hud_GlowingHourGlass.png"},
|
|
{434, "gfx/characters/costumes/Costume_434_JarOfFlies.png"},
|
|
{474, "gfx/ui/hud_BrokenGlassCannon.png"},
|
|
{479, "gfx/ui/hud_Smelter.png"},
|
|
{483, "gfx/ui/hud_MamaMega.png"},
|
|
{489, "gfx/characters/costumes/Costume_489_DInfinity.png"},
|
|
{523, "gfx/characters/costumes/costume_523_movingbox.png"},
|
|
{685, "gfx/ui/hud_JarOfWisps.png"},
|
|
{711, "gfx/ui/hud_Flip.png"},
|
|
{720, "gfx/ui/hud_EverythingJar.png"}};
|
|
constexpr const char* NECRONOMICON_POWERED_PNG = "gfx/ui/hud_NecronomiconPowered.png";
|
|
constexpr const char* URN_OF_SOULS_PNG = "gfx/ui/hud_UrnOfSouls.png";
|
|
constexpr const char* URN_OF_SOULS_BELIAL_PNG = "gfx/ui/hud_UrnOfSouls_belial.png";
|
|
constexpr const char* BAG_OF_CRAFTING_PNG = "gfx/ui/hud_BagOfCrafting.png";
|
|
constexpr const char* BOOK_OF_VIRTUES_PNG = "gfx/ui/hud_BookOfVirtues.png";
|
|
constexpr const char* BOOK_OF_BELIAL_PNG = "gfx/ui/hud_BookOfBelial.png";
|
|
constexpr const char* BOOK_OF_VIRTUES_BELIAL_PNG = "gfx/ui/hud_BookOfVirtuesWithBelial.png";
|
|
|
|
// An active slot's icon: its frames and size, the second slot's scale, the shadow under it, the shift in a versus match,
|
|
// and the book behind the first slot, which lowers the slot and raises the item's icon over it.
|
|
constexpr float ACTIVE_ICON_SIZE = 32;
|
|
constexpr float SECOND_ACTIVE_SCALE = 0.5f;
|
|
constexpr float ACTIVE_SHADOW_ALPHA = 0.3f;
|
|
constexpr float ACTIVE_SHADOW_SHIFT = 2;
|
|
constexpr float VERSUS_ACTIVE_SHIFT = 12;
|
|
constexpr float BOOK_SLOT_DROP = 3;
|
|
constexpr float BOOK_ICON_RISE = -7;
|
|
constexpr int SUBCHARGES_PER_CHARGE = 450;
|
|
|
|
// The actives whose icon shows a counter, a state or a glow of its own.
|
|
constexpr int JAR_HEARTS_SHOWN = 10;
|
|
constexpr int JAR_FLIES_SHOWN = 20;
|
|
constexpr int JAR_FLIES_PER_ROW = 11;
|
|
constexpr int HOURGLASS_USES = 3;
|
|
constexpr int HOURGLASS_FRAMES = 7;
|
|
constexpr int URN_SOULS_SHOWN = 20;
|
|
constexpr int JAR_WISPS_SHOWN = 12;
|
|
constexpr int EVERYTHING_JAR_SHOWN = 12;
|
|
constexpr float JAR_ICON_OFFSET_X = -5;
|
|
constexpr float JAR_ICON_OFFSET_Y = -10;
|
|
constexpr float URN_ICON_OFFSET_X = -1;
|
|
constexpr float URN_ICON_OFFSET_Y = -8;
|
|
constexpr float HOLD_POOP_X = 16;
|
|
constexpr float HOLD_POOP_Y = 21;
|
|
constexpr int HOLD_POOP_LAYER = 1;
|
|
constexpr const char* HOLD_POOP_ANIMATION = "IdleSmall";
|
|
|
|
// The charge bar beside an active: where it sits beside the first slot, the second, and both in Esau's flipped corner,
|
|
// how far its fill reaches and from where, and the overlay of its segments by the charges it holds.
|
|
constexpr float BAR_X = 34;
|
|
constexpr float BAR_X_SECOND = -2;
|
|
constexpr float BAR_X_FLIPPED = 0;
|
|
constexpr float BAR_X_FLIPPED_SECOND = 38;
|
|
constexpr float BAR_Y = 17;
|
|
constexpr float BAR_HEIGHT = 23;
|
|
constexpr float BAR_TOP = 3;
|
|
constexpr float BAR_SMALL_DROP = 4;
|
|
constexpr float BAR_SMALL_HEIGHT = 12;
|
|
constexpr float BAR_SMALL_TOP = 1;
|
|
constexpr const char* BAR_EMPTY = "BarEmpty";
|
|
constexpr const char* BAR_FULL = "BarFull";
|
|
constexpr const char* BAR_OVERLAY_SINGLE = "BarOverlay1";
|
|
|
|
// A segment overlay of the charge bar, by the charges it shows.
|
|
struct BarOverlay
|
|
{
|
|
int charges;
|
|
const char* animation;
|
|
};
|
|
|
|
constexpr BarOverlay BAR_OVERLAYS[] = {{2, "BarOverlay2"}, {3, "BarOverlay3"}, {4, "BarOverlay4"}, {5, "BarOverlay5"},
|
|
{6, "BarOverlay6"}, {8, "BarOverlay8"}, {12, "BarOverlay12"}};
|
|
|
|
// The charge bar's colors: Bethany's soul charge, Tainted Bethany's blood, the partial charge, the full Necronomicon of
|
|
// a Necromancer, the battery's charge (and its partial charge, at half the alpha) and Berserk's cooldown.
|
|
constexpr ColorMod BAR_SOUL = {{1, 1, 1, 1}, {0.6f, 0.85f, 1.2f, 1}, {0, 0, 0}};
|
|
constexpr ColorMod BAR_BLOOD = {{1, 1, 1, 1}, {1, 0.2f, 0.2f, 1}, {0, 0, 0}};
|
|
constexpr ColorMod BAR_PARTIAL = {{1, 1, 1, 0.5f}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr ColorMod BAR_NECRONOMICON = {{0.6f, 0.6f, 0.6f, 1}, {1.2f, 0.6f, 1.2f, 1}, {0, 0, 0}};
|
|
constexpr ColorMod BAR_BATTERY = {{1, 1, 1, 1}, {0, 0, 0, 0}, {1, 0, 0}};
|
|
constexpr ColorMod BAR_COOLDOWN = {{1, 1, 1, 1}, {1.2f, 1.2f, 1.2f, 1}, {0, 0, 0}};
|
|
constexpr ColorMod ICON_SHADOW = {{0, 0, 0, ACTIVE_SHADOW_ALPHA}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr ColorMod ICON_OUTLINE = {{0, 0, 0, 1}, {0, 0, 0, 0}, {1, 1, 1}};
|
|
|
|
|
|
// A color that only tints by an alpha and adds a red offset.
|
|
static ColorMod heart_color(float alpha, float redOffset)
|
|
{
|
|
return {{1, 1, 1, alpha}, {0, 0, 0, 0}, {redOffset, 0, 0}};
|
|
}
|
|
|
|
// Pulses a fading heart's color with the game's frames.
|
|
static void fade_pulse(ColorMod& color)
|
|
{
|
|
float pulse = sin_float((float)g_game->frameCount * 3.1415927f / FADE_PULSE_FRAMES) * 0.5f + 0.5f;
|
|
float tint = pulse * FADE_TINT_RANGE + FADE_TINT_BASE;
|
|
float offset = pulse * FADE_OFFSET_RANGE;
|
|
|
|
color_multiply(color, {{tint, tint, tint, 1}, {1, 1, 1, FADE_COLORIZE_BASE - offset}, {offset, 0, 0}});
|
|
}
|
|
|
|
// Whether a player is The Forgotten or The Soul, whose hearts past the first row are the other's.
|
|
static bool is_forgotten(const Entity_Player& player)
|
|
{
|
|
return player.playerType == PLAYER_THEFORGOTTEN || player.playerType == PLAYER_THESOUL;
|
|
}
|
|
|
|
// Whether a player is Judas or Dark Judas with Birthright, whose actives show Book of Belial.
|
|
static bool is_judas_birthright(Entity_Player& player)
|
|
{
|
|
bool isJudas = player.playerType == PLAYER_JUDAS || player.playerType == PLAYER_BLACKJUDAS;
|
|
return isJudas && player.HasCollectible(COLLECTIBLE_BIRTHRIGHT);
|
|
}
|
|
|
|
// The Wooden Cross shields a player has left: one per trinket multiplier (at most two) less those broken.
|
|
static int wooden_cross_shields(Entity_Player& player)
|
|
{
|
|
int multiplier = std::min(player.GetTrinketMultiplier(TRINKET_WOODEN_CROSS), WOODEN_CROSS_SHIELDS_MAX);
|
|
return std::max(multiplier - (player.holyMantleStacks & MANTLE_STACKS_MASK), 0);
|
|
}
|
|
|
|
// Whether a corner shows the online co-op's compact HUD: online, before a versus match, for the players past the
|
|
// first of each side.
|
|
static bool is_hud_compact(const PlayerHUD& hud)
|
|
{
|
|
bool isCompactOption =
|
|
g_game->deathmatchManager.state < DEATHMATCH_INTRO && g_manager->optionsConfig.onlineHud == ONLINE_HUD_COMPACT;
|
|
return g_manager->netplayManager.is_online() && isCompactOption && hud.playerHudIndex != 0 &&
|
|
hud.playerHudIndex != MAIN_PLAYER_HUD_COUNT;
|
|
}
|
|
|
|
// Shows a player in a corner that does not show it yet, emptied first and redrawn.
|
|
void PlayerHUD::assign(Entity_Player* shown)
|
|
{
|
|
if (shown == player) return;
|
|
|
|
reset();
|
|
player = shown;
|
|
isDirty = true;
|
|
isCraftingItemDirty = true;
|
|
}
|
|
|
|
// 00841cf0 Empties the corner: hearts, flashes, trinkets, actives, the crafting bag, and the player it showed.
|
|
void PlayerHUD::reset()
|
|
{
|
|
hearts.fill({});
|
|
lastHeartFlash = 0;
|
|
redHeartFlashCountdown = 0;
|
|
soulHeartFlashCountdown = 0;
|
|
goldHeartFlashCountdown = 0;
|
|
for (PlayerHUDTrinket& trinket : trinkets) trinket = {};
|
|
for (PlayerHUDActiveItem& item : activeItems) item = {};
|
|
inventoryIcons.clear();
|
|
isDirty = false;
|
|
isCraftingItemDirty = false;
|
|
craftingResultImage.reset();
|
|
craftingBagImage.reset();
|
|
player = nullptr;
|
|
}
|
|
|
|
// Forgets the box the corner covered, as HUD::Render does before each frame.
|
|
void PlayerHUD::bounds_reset()
|
|
{
|
|
boundsMin = vector_make(PLAYER_HUD_BOUNDS_FAR, PLAYER_HUD_BOUNDS_FAR);
|
|
boundsMax = vector_make(-PLAYER_HUD_BOUNDS_FAR, -PLAYER_HUD_BOUNDS_FAR);
|
|
}
|
|
|
|
// 00842230 Follows the player: its hearts (The Forgotten's first row, The Soul's second), the last heart's flash
|
|
// while one heart is left without a Holy Mantle shield, the actives, trinkets and pockets with their icons, Tainted
|
|
// Isaac's inventory and the crafting bag's result when asked, the twins' drop fade, and the heart flashes. A change
|
|
// asks the HUD to redraw the players' part.
|
|
// The crafting bag's result is not a field of Entity_Player yet. It is none while the bag is empty, as here.
|
|
void PlayerHUD::Update()
|
|
{
|
|
Entity_Player& shown = *player;
|
|
bool isChanged = false;
|
|
|
|
for (PlayerHUDHeart& heart : hearts) heart.isEternalHeartVisible = false;
|
|
std::span<PlayerHUDHeart> slots = hearts;
|
|
if (shown.subPlayer && is_forgotten(shown) && !shown.parent)
|
|
{
|
|
UpdateHearts(slots.first(FORGOTTEN_HEART_SLOTS), shown);
|
|
UpdateHearts(slots.subspan(FORGOTTEN_HEART_SLOTS, FORGOTTEN_HEART_SLOTS), *shown.subPlayer);
|
|
}
|
|
else UpdateHearts(slots, shown);
|
|
|
|
lastHeartFlash = 0;
|
|
if (shown.boneHearts + shown.soulHearts + shown.eternalHearts + shown.redHearts == 1)
|
|
{
|
|
TemporaryEffects& effects = shown.temporaryEffects;
|
|
TemporaryEffect* mantle = effects.isDisabled ? nullptr : effects.GetCollectibleEffect(COLLECTIBLE_HOLY_MANTLE);
|
|
int frame = g_game->frameCount % LAST_HEART_FLASH_PERIOD;
|
|
if ((!mantle || mantle->count == 0) && frame < LAST_HEART_FLASH_FRAMES)
|
|
lastHeartFlash = (int16_t)((LAST_HEART_FLASH_STEPS - frame) * HEART_ALPHA_FULL / LAST_HEART_FLASH_STEPS);
|
|
}
|
|
|
|
actives_update(isChanged);
|
|
trinkets_update(isChanged);
|
|
pockets_update();
|
|
if (isDirty) inventory_update();
|
|
|
|
if (isCraftingItemDirty)
|
|
{
|
|
craftingResultImage.reset();
|
|
if (ItemConfig_Item* crafted = g_manager->itemConfig.GetCollectible(shown.bagOfCraftingOutput))
|
|
craftingResultImage = Manager::LoadImage((g_game->GetCurses() & CURSE_OF_BLIND) ? CRAFTING_BLIND_GFX
|
|
: crafted->gfxFilename);
|
|
isCraftingItemDirty = false;
|
|
}
|
|
|
|
bool isDropHeld = input_is_action_pressed(ACTION_DROP, shown.controllerIndex, &shown);
|
|
dropHoldFade = std::clamp(dropHoldFade + (isDropHeld ? DROP_FADE_STEP : -DROP_FADE_STEP), 0.0f, 1.0f);
|
|
for (int8_t* countdown : {&redHeartFlashCountdown, &soulHeartFlashCountdown, &goldHeartFlashCountdown})
|
|
if (*countdown > 0) (*countdown)--;
|
|
if (isChanged) hud->refresh_request(HUD_REFRESH_PLAYER);
|
|
}
|
|
|
|
// The active slots of Update: each counts its charge bar flash down, loads its item's HUD icon when the item
|
|
// changed, and the book icon the first slot shows (Book of Virtues, Judas's Book of Belial, or both) when it changed.
|
|
void PlayerHUD::actives_update(bool& isChanged)
|
|
{
|
|
Entity_Player& shown = *player;
|
|
|
|
for (int slot = 0; slot < PLAYER_HUD_ACTIVE_COUNT; slot++)
|
|
{
|
|
PlayerHUDActiveItem& active = activeItems[slot];
|
|
int item = shown.activeItems[slot].item;
|
|
if (active.chargeBarFlash >= 0)
|
|
{
|
|
isChanged = true;
|
|
active.chargeBarFlash--;
|
|
}
|
|
|
|
int book = 0;
|
|
if (slot == 0)
|
|
{
|
|
if (shown.HasCollectible(COLLECTIBLE_BOOK_OF_VIRTUES) && item != COLLECTIBLE_BOOK_OF_VIRTUES)
|
|
book = COLLECTIBLE_BOOK_OF_VIRTUES;
|
|
if (is_judas_birthright(shown) && item != COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)
|
|
book = book == COLLECTIBLE_BOOK_OF_VIRTUES ? COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE : COLLECTIBLE_BOOK_OF_BELIAL;
|
|
}
|
|
|
|
if (item != active.id)
|
|
{
|
|
active.id = item;
|
|
|
|
ItemConfig_Item* config = g_manager->itemConfig.GetCollectible(item);
|
|
active.itemImage.reset();
|
|
if (config)
|
|
{
|
|
std::string_view path = config->gfxFilename;
|
|
bool isNecronomiconPowered = !shown.hasCurseMistEffect && !shown.isCoopGhost &&
|
|
shown.playerForms[NECRONOMICON_FORM] >= NECRONOMICON_FORM_COUNT &&
|
|
shown.activeItems[slot].varData == 1;
|
|
for (const ActiveIcon& icon : ACTIVE_ICONS)
|
|
if (icon.item == item) path = icon.path;
|
|
if (item == COLLECTIBLE_NECRONOMICON && isNecronomiconPowered) path = NECRONOMICON_POWERED_PNG;
|
|
if (item == COLLECTIBLE_URN_OF_SOULS)
|
|
path = is_judas_birthright(shown) ? URN_OF_SOULS_BELIAL_PNG : URN_OF_SOULS_PNG;
|
|
if (item == COLLECTIBLE_BAG_OF_CRAFTING && slot != ACTIVE_SLOT_POCKET) path = BAG_OF_CRAFTING_PNG;
|
|
active.itemImage = Manager::LoadImage(path);
|
|
}
|
|
isChanged = true;
|
|
}
|
|
|
|
if (book == active.bookItemId) continue;
|
|
active.bookItemId = book;
|
|
if (book == COLLECTIBLE_BOOK_OF_VIRTUES) active.bookImage = Manager::LoadImage(BOOK_OF_VIRTUES_PNG);
|
|
else if (book == COLLECTIBLE_BOOK_OF_BELIAL) active.bookImage = Manager::LoadImage(BOOK_OF_BELIAL_PNG);
|
|
else if (book == COLLECTIBLE_BOOK_OF_BELIAL_PASSIVE)
|
|
active.bookImage = Manager::LoadImage(BOOK_OF_VIRTUES_BELIAL_PNG);
|
|
else active.bookImage.reset();
|
|
isChanged = true;
|
|
}
|
|
}
|
|
|
|
// The icon of a trinket slot, the Modeling Clay copy's when there is one, and the middle of its drawn pixels. The
|
|
// original scans the 32 pixel square oddly: for each column x of row y it tests the red byte of the pixel (x + 1) * y
|
|
// counted along the square, and it stores the middle of the rows in x and of the columns in y. Both are kept.
|
|
static void trinket_icon_load(PlayerHUDTrinket& trinket)
|
|
{
|
|
constexpr int TRINKET_ICON_PIXELS = 32;
|
|
constexpr int RGBA = 4;
|
|
ItemConfig& items = g_manager->itemConfig;
|
|
ItemConfig_Item* item = trinket.clayItem ? items.GetCollectible(trinket.clayItem) : items.GetTrinket(trinket.id);
|
|
if (!item) return;
|
|
trinket.image = Manager::LoadImage(item->gfxFilename);
|
|
if (!trinket.image) return;
|
|
|
|
int width = 0;
|
|
int height = 0;
|
|
uint8_t* pixels = KAGE::Graphics::texels_load(trinket.image->path, width, height);
|
|
std::array<uint8_t, TRINKET_ICON_PIXELS * TRINKET_ICON_PIXELS * RGBA> square{};
|
|
for (int row = 0; pixels && row < std::min(height, TRINKET_ICON_PIXELS); row++)
|
|
std::copy_n(pixels + (size_t)row * width * RGBA, std::min(width, TRINKET_ICON_PIXELS) * RGBA, square.begin() + row * TRINKET_ICON_PIXELS * RGBA);
|
|
stbi_image_free(pixels);
|
|
|
|
uint32_t minX = TRINKET_ICON_PIXELS;
|
|
uint32_t maxX = 0;
|
|
uint32_t minY = TRINKET_ICON_PIXELS;
|
|
uint32_t maxY = 0;
|
|
for (uint32_t y = 0; y < TRINKET_ICON_PIXELS; y++)
|
|
for (uint32_t x = 0; x < TRINKET_ICON_PIXELS; x++)
|
|
{
|
|
if (square[(x + 1) * y * RGBA] == 0) continue;
|
|
minX = std::min(minX, x);
|
|
maxX = std::max(maxX, x);
|
|
minY = std::min(minY, y);
|
|
maxY = std::max(maxY, y);
|
|
}
|
|
uint32_t middleY = (maxY - minY) / 2 + minY;
|
|
uint32_t middleX = (maxX - minX) / 2 + minX;
|
|
trinket.offset = vector_make((float)middleY, (float)middleX);
|
|
}
|
|
|
|
// The trinket the error trinket passes for in the current room, picked by the room's spawn seed, or the error trinket
|
|
// itself while that seed is 0.
|
|
int error_trinket_disguise_get()
|
|
{
|
|
uint32_t seed = g_game->GetRoomByIdx(g_game->currentRoomIdx)->spawnSeed;
|
|
if (seed == 0) return TRINKET_ERROR;
|
|
|
|
seed ^= seed >> 2;
|
|
seed ^= seed << 7;
|
|
return (int)((seed >> 25 ^ seed) % ERROR_TRINKET_POOL + 1);
|
|
}
|
|
|
|
// The trinket slots of Update: each follows its trinket (the error trinket shows one picked by the room's spawn seed)
|
|
// and, once it shows Modeling Clay, the item the clay copies, reloading the icon and the offset of its drawn pixels
|
|
// when either changed.
|
|
void PlayerHUD::trinkets_update(bool& isChanged)
|
|
{
|
|
Entity_Player& shown = *player;
|
|
|
|
for (int slot = 0; slot < PLAYER_HUD_TRINKET_COUNT; slot++)
|
|
{
|
|
PlayerHUDTrinket& trinket = trinkets[slot];
|
|
int id = (int)(shown.trinkets[slot] & TRINKET_ID_MASK);
|
|
int clayItem = trinket.id == TRINKET_MODELING_CLAY ? shown.modelingClayEffect : 0;
|
|
if (id == TRINKET_ERROR) id = error_trinket_disguise_get();
|
|
if (id == trinket.id && clayItem == trinket.clayItem) continue;
|
|
|
|
trinket.id = id;
|
|
trinket.clayItem = clayItem;
|
|
trinket_icon_load(trinket);
|
|
isChanged = true;
|
|
g_game->hud.mark_all_slots_dirty(HISTORY_KEEP_ICONS, HISTORY_KEEP_ITEMS);
|
|
}
|
|
}
|
|
|
|
// The pocket slots of Update: each loads the pickup sprite of its card or pill when what it holds changed, and none
|
|
// for a pocket active or an empty slot.
|
|
void PlayerHUD::pockets_update()
|
|
{
|
|
Entity_Player& shown = *player;
|
|
|
|
for (int slot = 0; slot < PLAYER_HUD_POCKET_COUNT; slot++)
|
|
{
|
|
PlayerHUDPocketItem& pocket = pocketItems[slot];
|
|
PocketItem& held = shown.pocketItems[slot];
|
|
int subtype = 0;
|
|
if (held.type == POCKET_CARD)
|
|
{
|
|
ItemConfig_Card* card = g_manager->itemConfig.GetCard(held.id);
|
|
if (card) subtype = card->pickupSubtype;
|
|
}
|
|
else if (held.type == POCKET_PILL) subtype = held.id;
|
|
if (held.type == pocket.kind && subtype == pocket.id) continue;
|
|
|
|
EntityConfig_Entity* config = nullptr;
|
|
if (subtype != 0 && held.type != POCKET_ACTIVE)
|
|
{
|
|
int variant = held.type == POCKET_CARD ? PICKUP_TAROTCARD : PICKUP_PILL;
|
|
config = g_manager->entityConfig.GetEntity(ENTITY_PICKUP, variant, subtype);
|
|
}
|
|
if (config) pocket.sprite.Load(config->anm2Path, GRAPHICS_LOAD);
|
|
else pocket.sprite.Reset();
|
|
pocket.kind = held.type;
|
|
pocket.id = subtype;
|
|
}
|
|
}
|
|
|
|
// The inventory icons of Update when the corner is redrawn: Tainted Isaac's passives (an empty slot shows none, an
|
|
// active or unknown item is left out), or the Cantripped challenge's item cards, else none. An icon loaded before is
|
|
// reused, once per id. A glitched item keeps no image, and an item whose image fails to load is left out.
|
|
// The original reads the id of a card's missing item. Here that card is left out.
|
|
void PlayerHUD::inventory_update()
|
|
{
|
|
bool isInventory = player->playerType == PLAYER_ISAAC_B;
|
|
bool isCantripped = !isInventory && g_game->challenge == CHALLENGE_CANTRIPPED && !player->itemCards.empty();
|
|
std::map<int, KAGE::Graphics::ImagePtr> loaded;
|
|
|
|
for (PlayerHUDIcon& icon : inventoryIcons) loaded.emplace(icon.id, icon.image);
|
|
inventoryIcons.clear();
|
|
auto icon_add = [&](int id)
|
|
{
|
|
ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(id);
|
|
if (!item || (isInventory && item->type == ITEM_ACTIVE)) return;
|
|
if (auto cached = loaded.find(id); cached != loaded.end())
|
|
{
|
|
inventoryIcons.push_back({cached->second, id});
|
|
loaded.erase(cached);
|
|
}
|
|
else if (id < 0) inventoryIcons.push_back({nullptr, id});
|
|
else if (KAGE::Graphics::ImagePtr image = Manager::LoadImage(item->gfxFilename)) inventoryIcons.push_back({image, id});
|
|
};
|
|
|
|
if (isInventory)
|
|
{
|
|
for (int entry : player->inventory)
|
|
{
|
|
if (entry < 0) inventoryIcons.emplace_back();
|
|
else icon_add(player->history.historyItems[entry].id);
|
|
}
|
|
}
|
|
else if (isCantripped)
|
|
{
|
|
for (uint32_t card : player->itemCards)
|
|
{
|
|
if (card == 0) inventoryIcons.emplace_back();
|
|
else icon_add((int)card);
|
|
}
|
|
}
|
|
isDirty = false;
|
|
}
|
|
|
|
// 00841e20 Fills heart slots from a player's health: the red hearts (rotten or coin ones, empty past what it has),
|
|
// then the soul and black hearts with the bone hearts among them, the eternal heart over the last filled red or bone
|
|
// heart, the broken hearts, and no heart past those. The last filled hearts are golden, as many as it has. Tainted
|
|
// Magdalene's red hearts past her first two (three with Birthright) and her soul hearts fade.
|
|
void PlayerHUD::UpdateHearts(std::span<PlayerHUDHeart> slots, Entity_Player& shown)
|
|
{
|
|
HealthType healthType = shown.GetHealthType();
|
|
if (healthType == HEALTH_NO_HEALTH) return;
|
|
|
|
bool isCoin = healthType == HEALTH_COIN;
|
|
bool isMaggy = shown.playerType == PLAYER_MAGDALENE_B && (int)shown.maggyHealthDrainCooldown >= 1;
|
|
int maggyFadeStart = MAGGY_FADE_START + (shown.HasCollectible(COLLECTIBLE_BIRTHRIGHT) ? 1 : 0);
|
|
int count = (int)slots.size();
|
|
int rotten = shown.rottenHearts;
|
|
int red = shown.redHearts - rotten * 2;
|
|
int filled = 0;
|
|
int slot = 0;
|
|
auto flash_if = [](int8_t countdown, HeartFlash flash) { return countdown > 0 ? flash : HEART_FLASH_NONE; };
|
|
|
|
for (; slot < (shown.maxHearts + 1) / 2 && slot < count; slot++)
|
|
{
|
|
PlayerHUDHeart& heart = slots[slot];
|
|
heart.isVisible = true;
|
|
heart.isFadeHeart = isMaggy && slot >= maggyFadeStart;
|
|
if (red < 1 && rotten < 1)
|
|
{
|
|
heart.isGoldenHeartVisible = false;
|
|
heart.isFadeHeart = false;
|
|
heart.spriteAnim = isCoin ? "CoinEmpty" : "EmptyHeart";
|
|
heart.flashType = HEART_FLASH_NONE;
|
|
continue;
|
|
}
|
|
|
|
filled++;
|
|
heart.isGoldenHeartVisible = true;
|
|
if (red < 1)
|
|
{
|
|
heart.spriteAnim = "RottenHeartFull";
|
|
heart.flashType = flash_if(redHeartFlashCountdown, HEART_FLASH_ROTTEN);
|
|
rotten--;
|
|
continue;
|
|
}
|
|
if (isCoin) heart.spriteAnim = red < 2 ? "CoinHeartHalf" : "CoinHeartFull";
|
|
else heart.spriteAnim = red < 2 ? "RedHeartHalf" : "RedHeartFull";
|
|
heart.flashType = flash_if(redHeartFlashCountdown, isCoin ? HEART_FLASH_GOLD : HEART_FLASH_RED);
|
|
red = std::max(red - 2, 0);
|
|
}
|
|
|
|
int eternalSlot = std::max(slot - 1, 0);
|
|
int soul = shown.soulHearts;
|
|
int soulIndex = 0;
|
|
uint32_t boneBit = 1;
|
|
for (int i = 0; i < (shown.soulHearts + 1) / 2 + shown.boneHearts && slot < count; i++, slot++)
|
|
{
|
|
PlayerHUDHeart& heart = slots[slot];
|
|
filled++;
|
|
heart.isFadeHeart = isMaggy;
|
|
heart.isVisible = true;
|
|
heart.isGoldenHeartVisible = true;
|
|
bool isBone = shown.boneHearts >= 1 && (uint32_t)shown.boneHeartsMask & boneBit;
|
|
boneBit = boneBit << 1 | boneBit >> 31;
|
|
if (isBone)
|
|
{
|
|
if (red >= 1)
|
|
{
|
|
heart.spriteAnim = red < 2 ? "BoneHeartHalf" : "BoneHeartFull";
|
|
heart.flashType = flash_if(redHeartFlashCountdown, HEART_FLASH_RED);
|
|
eternalSlot = slot;
|
|
}
|
|
else if (rotten >= 1)
|
|
{
|
|
rotten--;
|
|
heart.spriteAnim = "RottenBoneHeartFull";
|
|
heart.flashType = flash_if(redHeartFlashCountdown, HEART_FLASH_ROTTEN);
|
|
}
|
|
else
|
|
{
|
|
heart.spriteAnim = "BoneHeartEmpty";
|
|
heart.flashType = HEART_FLASH_NONE;
|
|
}
|
|
red = std::max(red - 2, 0);
|
|
continue;
|
|
}
|
|
|
|
bool isBlack = shown.soulHearts >= soulIndex * 2 + 1 && shown.blackHearts & 1 << (soulIndex & 31);
|
|
if (isBlack) heart.spriteAnim = soul < 2 ? "BlackHeartHalf" : "BlackHeartFull";
|
|
else heart.spriteAnim = soul < 2 ? "BlueHeartHalf" : "BlueHeartFull";
|
|
heart.flashType = flash_if(soulHeartFlashCountdown, isBlack ? HEART_FLASH_BLACK : HEART_FLASH_SOUL);
|
|
soul = std::max(soul - 2, 0);
|
|
soulIndex++;
|
|
}
|
|
|
|
if (shown.eternalHearts > 0)
|
|
{
|
|
slots[eternalSlot].spriteOverlayAnim = ANIMATION_WHITE_OVERLAY;
|
|
slots[eternalSlot].isEternalHeartVisible = true;
|
|
slots[eternalSlot].flashType = HEART_FLASH_NONE;
|
|
}
|
|
|
|
bool isFull = false;
|
|
for (int broken = 0; broken < shown.brokenHearts; broken++, slot++)
|
|
{
|
|
isFull = slot >= count;
|
|
if (isFull) break;
|
|
slots[slot].isVisible = true;
|
|
slots[slot].isGoldenHeartVisible = false;
|
|
slots[slot].spriteAnim = isCoin ? "BrokenCoinHeart" : "BrokenHeart";
|
|
slots[slot].flashType = HEART_FLASH_NONE;
|
|
}
|
|
if (!isFull)
|
|
for (; slot < count; slot++) slots[slot].isVisible = false;
|
|
|
|
filled -= shown.goldenHearts;
|
|
for (PlayerHUDHeart& heart : slots)
|
|
{
|
|
if (filled < 1) return;
|
|
if (!heart.isVisible || !heart.isGoldenHeartVisible) continue;
|
|
heart.isGoldenHeartVisible = false;
|
|
filled--;
|
|
}
|
|
}
|
|
|
|
// 00843df0 Draws the hearts in rows of six from at (leftward for Esau's corner of the twin layout), last first, each
|
|
// tinted by its flash (or the last heart's flash), dimmed past The Forgotten's first row or under an instant death
|
|
// curse, Tainted Magdalene's pulsing, with the eternal heart over its heart and the golden overlays after. The Holy
|
|
// Mantle shields follow the hearts, then the extra lives count. The curse of the unknown shows one cursed heart, and a
|
|
// versus match a health bar. outExtent is how far the hearts reach.
|
|
void PlayerHUD::RenderHearts(Vector& outExtent, ANM2& sprite, PlayerHudLayout layout, float heartScale, Vector at)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
HudHeartsDraw heartsDraw = {outExtent, sprite, at, layout, heartScale};
|
|
bool isFollowed = player && !player->isCoopGhost;
|
|
if (isFollowed && hud_hearts_pre_render(*this, heartsDraw)) return;
|
|
ScopeExit heartsPost = {[&] { if (isFollowed) hud_hearts_post_render(*this, heartsDraw); }};
|
|
#endif
|
|
Game& game = *g_game;
|
|
if (game.currentRoomIdx == ROOM_DEATHMATCH_IDX)
|
|
{
|
|
outExtent = render_deathmatch_health_bar(vector_make(at.x + DEATHMATCH_BAR_SHIFT_X, at.y + DEATHMATCH_BAR_SHIFT_Y));
|
|
return;
|
|
}
|
|
|
|
bool isCompact = is_hud_compact(*this);
|
|
bool isFlipped = playerHudIndex >= MAIN_PLAYER_HUD_COUNT && layout == HUD_LAYOUT_JACOB_ESAU;
|
|
float spacingX = isCompact ? HEART_SMALL_SPACING_X : HEART_SPACING_X;
|
|
float spacingY = isCompact ? HEART_SMALL_SPACING_Y : HEART_SPACING_Y;
|
|
if (sprite.ReplaceSpritesheet(0, isCompact ? HEARTS_SMALL_PNG : HEARTS_PNG)) sprite.LoadGraphics();
|
|
|
|
if (!player || player->isCoopGhost)
|
|
{
|
|
outExtent = vector_make(spacingX * heartScale, spacingY * heartScale);
|
|
return;
|
|
}
|
|
|
|
if (layout == HUD_LAYOUT_JACOB_ESAU_COMPACT)
|
|
{
|
|
if (playerHudIndex >= MAIN_PLAYER_HUD_COUNT)
|
|
{
|
|
at.y += ESAU_HEARTS_DROP;
|
|
if (isCompact) at.y -= ESAU_HEARTS_DROP_COMPACT;
|
|
Vector from = vector_make(at.x - ESAU_LINE_LEFT, at.y - ESAU_LINE_RISE);
|
|
Vector to = vector_make(at.x + ESAU_LINE_RIGHT, at.y - ESAU_LINE_RISE);
|
|
KColor white = kcolor_rgba(1, 1, 1, 1);
|
|
render_color_quad(from, to, white, white, 1);
|
|
}
|
|
isCompact = true;
|
|
}
|
|
|
|
Entity_Player& shown = *player;
|
|
sprite.scale = vector_make(heartScale, heartScale);
|
|
if (game.GetCurses() & CURSE_OF_THE_UNKNOWN)
|
|
{
|
|
sprite.SetFrame(ANIMATION_CURSE_HEART, 0);
|
|
sprite.Render({at});
|
|
sprite.scale = vector_make(1, 1);
|
|
outExtent = vector_make(spacingX * heartScale, spacingY * heartScale);
|
|
return;
|
|
}
|
|
|
|
float stepX = isFlipped ? -spacingX : spacingX;
|
|
auto slot_position = [&](int slot) {
|
|
int row = slot / HEARTS_PER_ROW;
|
|
return vector_make((float)(slot % HEARTS_PER_ROW) * stepX * heartScale + at.x,
|
|
(float)row * spacingY * heartScale + at.y);
|
|
};
|
|
int maxColumn = -1;
|
|
int maxRow = 0;
|
|
int fullSlots = 0;
|
|
bool isInstantDeath = shown.HasInstantDeathCurse();
|
|
if (isFlipped) sprite.isFlipX = true;
|
|
|
|
if (shown.GetHealthType() != HEALTH_NO_HEALTH)
|
|
{
|
|
for (int slot = PLAYER_HUD_HEART_COUNT - 1; slot >= 0; slot--)
|
|
{
|
|
PlayerHUDHeart& heart = hearts[slot];
|
|
bool isDimmed = (slot >= FORGOTTEN_HEART_SLOTS && is_forgotten(shown)) || isInstantDeath;
|
|
int alpha = isDimmed ? HEART_ALPHA_DIMMED : HEART_ALPHA_FULL;
|
|
if (!heart.isVisible) continue;
|
|
|
|
maxColumn = std::max(slot % HEARTS_PER_ROW, maxColumn);
|
|
maxRow = std::max(slot / HEARTS_PER_ROW, maxRow);
|
|
Vector position = slot_position(slot);
|
|
float unitAlpha = (float)alpha * BYTE_TO_UNIT;
|
|
float flashOffset = slot == 0 ? (float)lastHeartFlash * BYTE_TO_UNIT : 0;
|
|
sprite.SetFrame(heart.spriteAnim, 0);
|
|
|
|
HeartFlash flash = heart.flashType;
|
|
if (goldHeartFlashCountdown != 0 && heart.isGoldenHeartVisible) flash = HEART_FLASH_GOLD;
|
|
if (flash != HEART_FLASH_NONE)
|
|
{
|
|
const std::array<float, 3>& offset = HEART_FLASH_OFFSETS[flash];
|
|
sprite.color = {{1, 1, 1, unitAlpha}, {0, 0, 0, 0}, {offset[0], offset[1], offset[2]}};
|
|
}
|
|
else sprite.color = heart_color(unitAlpha, flashOffset);
|
|
if (heart.isFadeHeart) fade_pulse(sprite.color);
|
|
sprite.Render({position});
|
|
|
|
if (heart.isEternalHeartVisible)
|
|
{
|
|
sprite.SetFrame(heart.spriteOverlayAnim, 0);
|
|
sprite.color = heart_color(unitAlpha, flashOffset);
|
|
if (heart.isFadeHeart) fade_pulse(sprite.color);
|
|
sprite.Render({position});
|
|
}
|
|
if (fullSlots == 0 && alpha == HEART_ALPHA_FULL) fullSlots = slot + 1;
|
|
}
|
|
|
|
sprite.SetFrame(ANIMATION_GOLD_OVERLAY, 0);
|
|
sprite.color = heart_color((float)(is_forgotten(shown) ? HEART_ALPHA_DIMMED : HEART_ALPHA_FULL) * BYTE_TO_UNIT, 0);
|
|
for (int slot = PLAYER_HUD_HEART_COUNT - 1; slot >= 0; slot--)
|
|
{
|
|
if (slot == GOLD_RESET_SLOT) sprite.color = COLOR_DEFAULT;
|
|
if (hearts[slot].isVisible && hearts[slot].isGoldenHeartVisible) sprite.Render({slot_position(slot)});
|
|
}
|
|
}
|
|
|
|
bool isMantleShifted = false;
|
|
TemporaryEffects& effects = shown.temporaryEffects;
|
|
TemporaryEffect* mantle = effects.isDisabled ? nullptr : effects.GetCollectibleEffect(COLLECTIBLE_HOLY_MANTLE);
|
|
if (mantle && mantle->count > 0)
|
|
{
|
|
std::array<const char*, MANTLE_LIMIT> shields{};
|
|
int shieldCount = 0;
|
|
int woodenCross = wooden_cross_shields(shown);
|
|
if (woodenCross != 0) shields[shieldCount++] = MANTLE_WOODEN_CROSS;
|
|
if (woodenCross > 1) shields[shieldCount++] = MANTLE_WOODEN_CROSS;
|
|
if (effects.HasCollectibleEffect(COLLECTIBLE_BLANKET)) shields[shieldCount++] = MANTLE_BLANKET;
|
|
if (shown.HasCollectible(COLLECTIBLE_HOLY_MANTLE) && shown.holyMantleState == 0)
|
|
shields[shieldCount++] = MANTLE_HOLY_MANTLE;
|
|
if (effects.HasNullEffect(NULLITEM_HOLY_CARD)) shields[shieldCount++] = MANTLE_HOLY_CARD;
|
|
for (; shieldCount < mantle->count && shieldCount < MANTLE_LIMIT; shieldCount++)
|
|
shields[shieldCount] = MANTLE_HOLY_MANTLE;
|
|
|
|
int limit = is_forgotten(shown) ? MANTLE_FORGOTTEN_SLOT
|
|
: std::max(shown.GetHeartLimit(false) / 2, MANTLE_HEART_LIMIT_MIN) - 1;
|
|
float shift = 0;
|
|
int slot = fullSlots;
|
|
if (limit < fullSlots)
|
|
{
|
|
shift = stepX;
|
|
isMantleShifted = true;
|
|
slot = limit;
|
|
}
|
|
maxColumn = std::max(maxColumn, slot % HEARTS_PER_ROW);
|
|
int row = slot / HEARTS_PER_ROW;
|
|
Vector position = vector_make(((float)(slot % HEARTS_PER_ROW) * stepX + shift) * heartScale + at.x,
|
|
(float)row * spacingY * heartScale + at.y);
|
|
|
|
if (mantle->count > 1 && shields[1])
|
|
{
|
|
sprite.color._tint[3] = MANTLE_SECOND_ALPHA;
|
|
sprite.SetFrame(shields[1], 0);
|
|
float nudge = isFlipped ? -MANTLE_SECOND_X : MANTLE_SECOND_X;
|
|
sprite.Render({vector_make(nudge * heartScale + position.x, position.y + heartScale * -MANTLE_SECOND_RISE)});
|
|
sprite.color = COLOR_DEFAULT;
|
|
}
|
|
if (shields[0])
|
|
{
|
|
sprite.SetFrame(shields[0], 0);
|
|
sprite.Render({position});
|
|
}
|
|
}
|
|
if (isFlipped) sprite.isFlipX = false;
|
|
|
|
int lives = shown.GetExtraLives();
|
|
if (lives >= 1)
|
|
{
|
|
Vector shake = game.screenShakeOffset;
|
|
float rowsY = (float)maxRow * spacingY * heartScale + at.y;
|
|
float right = at.x + (float)maxColumn * stepX * heartScale + shake.x;
|
|
char text[32];
|
|
std::snprintf(text, sizeof(text), EXTRA_LIVES_FORMAT, lives,
|
|
shown.HasCollectible(COLLECTIBLE_GUPPYS_COLLAR) ? "?" : "");
|
|
|
|
Font& font = g_manager->font6_PFTempestaSevenCondensed;
|
|
float y = (-LIVES_RISE - (float)maxRow * LIVES_ROW_RISE) + rowsY + shake.y;
|
|
float direction = isFlipped ? -1 : 1;
|
|
float x = isFlipped ? (-LIVES_GAP - (float)font.GetStringWidth(text)) + right : right + LIVES_GAP;
|
|
if (isMantleShifted && !isCompact) x += direction * spacingX;
|
|
else if (isCompact) x -= direction * LIVES_COMPACT_SHIFT;
|
|
FontSettings settings;
|
|
font.DrawString(text, vector_make(x, y), vector_make(heartScale, heartScale), kcolor_rgba(1, 1, 1, 1), settings);
|
|
}
|
|
|
|
sprite.scale = vector_make(1, 1);
|
|
outExtent = vector_make(((float)maxColumn * spacingX + spacingX) * heartScale,
|
|
((float)maxRow * spacingY + spacingY + HEART_EXTENT_PAD) * heartScale);
|
|
}
|
|
|
|
// What an active's icon shows: its frame in the icon sheet, how far the item rises over the book behind it, and
|
|
// whether it glows with a white outline.
|
|
struct IconLayout
|
|
{
|
|
Vector frame{};
|
|
Vector bookOffset = vector_make(0, BOOK_ICON_RISE);
|
|
bool isOutlined = false;
|
|
};
|
|
|
|
// One pass of an active's icon: where and in what color, from which frame, and whether the item draws over the book.
|
|
struct IconPass
|
|
{
|
|
ColorMod color = COLOR_DEFAULT;
|
|
Vector frame{};
|
|
Vector position{};
|
|
bool isItemShown = true;
|
|
};
|
|
|
|
// The fills of an active's charge bar, as parts of the bar: the charge, the partial charge, the soul or blood charge
|
|
// Bethany and Tainted Bethany would spend, the battery's charge and partial charge, and Berserk's cooldown.
|
|
struct ChargeFills
|
|
{
|
|
float battery = 0;
|
|
float batteryPartial = 0;
|
|
float blood = 0;
|
|
float charge = 0;
|
|
float cooldown = 0;
|
|
float partial = 0;
|
|
float soul = 0;
|
|
};
|
|
|
|
// What an active slot holds of charges, with Red Redemption's key counting its uses left as its charge.
|
|
struct SlotCharge
|
|
{
|
|
int battery = 0;
|
|
int blood = 0;
|
|
int charge = 0;
|
|
int max = 0;
|
|
int soul = 0;
|
|
int subCharge = 0;
|
|
float partial = 0;
|
|
ActiveDischarge discharge = DISCHARGE_CHARGES;
|
|
};
|
|
|
|
// An active slot's charges as its bar shows them. The original crashes on an item missing from the config: here it
|
|
// discharges by charges.
|
|
static SlotCharge slot_charge_get(Entity_Player& shown, int slot, ItemConfig_Item* config)
|
|
{
|
|
ActiveItemDesc& active = shown.activeItems[slot];
|
|
SlotCharge charge;
|
|
charge.charge = active.charge;
|
|
charge.battery = active.batteryCharge;
|
|
charge.max = shown.GetActiveMaxCharge(slot);
|
|
charge.subCharge = active.subCharge;
|
|
charge.soul = shown.playerType == PLAYER_BETHANY ? shown.effectiveSoulCharge : 0;
|
|
charge.blood = shown.playerType == PLAYER_BETHANY_B ? shown.effectiveBloodCharge : 0;
|
|
charge.partial = (float)active.partialCharge;
|
|
charge.discharge = config ? config->discharge_get() : DISCHARGE_CHARGES;
|
|
|
|
if (g_game->challenge == CHALLENGE_RED_REDEMPTION && active.item == COLLECTIBLE_RED_KEY)
|
|
{
|
|
charge.max = active.varData;
|
|
charge.charge = std::max(charge.max - shown.temporaryEffects.GetNullEffectNum(NULLITEM_JACOBS_CURSE), 0);
|
|
charge.battery = 0;
|
|
charge.subCharge = 0;
|
|
charge.discharge = DISCHARGE_HELD;
|
|
}
|
|
return charge;
|
|
}
|
|
|
|
// The frame and offsets of an active's icon: the counters of the jars, the urn, the hourglass, D Infinity and the bag
|
|
// of crafting, the states of the moving box and Flip. A full bag of crafting glows, whatever the charge.
|
|
static void active_icon_frame_set(IconLayout& icon, Entity_Player& shown, int slot, const SlotCharge& charge)
|
|
{
|
|
ActiveItemDesc& active = shown.activeItems[slot];
|
|
auto frameAt = [&](int column, int row = 0) {
|
|
icon.frame = vector_make(column * ACTIVE_ICON_SIZE, row * ACTIVE_ICON_SIZE);
|
|
};
|
|
|
|
switch (active.item)
|
|
{
|
|
case COLLECTIBLE_THE_JAR:
|
|
frameAt(std::min((int)std::ceil((float)shown.jarHearts * 0.5f), JAR_HEARTS_SHOWN));
|
|
icon.bookOffset = vector_make(JAR_ICON_OFFSET_X, JAR_ICON_OFFSET_Y);
|
|
break;
|
|
case COLLECTIBLE_JAR_OF_FLIES:
|
|
{
|
|
int flies = std::min(shown.jarFlies, JAR_FLIES_SHOWN);
|
|
frameAt(flies % JAR_FLIES_PER_ROW, flies / JAR_FLIES_PER_ROW);
|
|
icon.bookOffset = vector_make(JAR_ICON_OFFSET_X, JAR_ICON_OFFSET_Y);
|
|
break;
|
|
}
|
|
case COLLECTIBLE_GLOWING_HOUR_GLASS:
|
|
frameAt(std::clamp(HOURGLASS_USES - active.varData, 0, HOURGLASS_FRAMES));
|
|
break;
|
|
case COLLECTIBLE_D_INFINITY:
|
|
frameAt((int16_t)(active.varData >> 16));
|
|
break;
|
|
case COLLECTIBLE_MOVING_BOX:
|
|
if (!shown.movingBoxContents.empty())
|
|
frameAt(1);
|
|
break;
|
|
case COLLECTIBLE_URN_OF_SOULS:
|
|
{
|
|
Weapon* weapon = shown.weapons[0] ? shown.weapons[0].get() : shown.weapons[1].get();
|
|
frameAt(std::min((int)shown.urnSouls, URN_SOULS_SHOWN),
|
|
weapon && weapon->weaponType == WEAPON_URN_OF_SOULS);
|
|
icon.bookOffset = vector_make(URN_ICON_OFFSET_X, URN_ICON_OFFSET_Y);
|
|
break;
|
|
}
|
|
case COLLECTIBLE_JAR_OF_WISPS:
|
|
frameAt(std::min(active.varData, JAR_WISPS_SHOWN));
|
|
icon.bookOffset = vector_make(URN_ICON_OFFSET_X, URN_ICON_OFFSET_Y);
|
|
break;
|
|
case COLLECTIBLE_BAG_OF_CRAFTING:
|
|
{
|
|
if (slot == ACTIVE_SLOT_POCKET)
|
|
break;
|
|
int count = (int)std::ranges::count_if(shown.bagOfCraftingContent, [](char pickup) { return pickup != 0; });
|
|
icon.isOutlined = count == BAG_OF_CRAFTING_SIZE;
|
|
frameAt(count);
|
|
break;
|
|
}
|
|
case COLLECTIBLE_FLIP:
|
|
frameAt(shown.playerType == PLAYER_LAZARUS2_B);
|
|
break;
|
|
case COLLECTIBLE_EVERYTHING_JAR:
|
|
frameAt(std::min(charge.soul + charge.blood + charge.battery + charge.charge, EVERYTHING_JAR_SHOWN) + 1);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Draws a glitched item's icon in a quad from a frame of its cell, through the procedural items' surface.
|
|
static void glitched_icon_draw(int id, const SourceQuad& source, const KAGE::Graphics::ColorQuad& quad,
|
|
const ColorMod& color)
|
|
{
|
|
ProceduralItemManager& glitched = g_game->proceduralItemManager;
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *glitched.renderTarget);
|
|
glitched.render_item(id, source, quad, kcolor_rgba(color._tint[0], color._tint[1], color._tint[2], color._tint[3]));
|
|
}
|
|
|
|
// (008452f0) Draws an active's item icon in a quad from a frame: a glitched item through the procedural items.
|
|
static void active_item_draw(const PlayerHUDActiveItem& active, const SourceQuad& source,
|
|
const KAGE::Graphics::ColorQuad& quad, const ColorMod& color)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
bool isOutline = std::memcmp(&color, &ICON_OUTLINE, sizeof(ColorMod)) == 0;
|
|
if (activeItemRender.isItemHidden || (activeItemRender.isOutlineHidden && isOutline)) return;
|
|
#endif
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
if (active.id < 0) return glitched_icon_draw(active.id, source, quad, color);
|
|
if (!active.itemImage) return;
|
|
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *active.itemImage);
|
|
active.itemImage->Render(source, quad, kcolor_rgba(color._tint[0], color._tint[1], color._tint[2], color._tint[3]));
|
|
}
|
|
|
|
// One pass of an active's icon: the book behind the first slot, then the item over it, raised by the icon's offset.
|
|
static void icon_pass_draw(const PlayerHUDActiveItem& active, const IconLayout& icon, float iconSize,
|
|
const IconPass& pass)
|
|
{
|
|
Vector size = vector_make(ACTIVE_ICON_SIZE, ACTIVE_ICON_SIZE);
|
|
KColor tint = kcolor_rgba(pass.color._tint[0], pass.color._tint[1], pass.color._tint[2], pass.color._tint[3]);
|
|
KAGE::Graphics::ColorQuad quad =
|
|
KAGE::Graphics::color_quad_rect(pass.position, vector_make(iconSize, iconSize), kcolor_rgba(1, 1, 1, 1));
|
|
|
|
if (active.bookImage)
|
|
{
|
|
apply_sprite_shader_params(pass.color, SPRITE_SHADER_COLOR_APPLY, *active.bookImage);
|
|
active.bookImage->Render(KAGE::Graphics::source_quad_rect({}, size), quad, tint);
|
|
for (Vector* corner : {&quad._topLeft, &quad._topRight, &quad._bottomLeft, &quad._bottomRight})
|
|
*corner = vector_add(*corner, icon.bookOffset);
|
|
}
|
|
if (pass.isItemShown)
|
|
active_item_draw(active, KAGE::Graphics::source_quad_rect(pass.frame, size), quad, pass.color);
|
|
}
|
|
|
|
// The frame an active's outline glows from: the lit frames of the Jar of Wisps, the hourglass and Glass Cannon, the
|
|
// Everything Jar's first. Breath of Life outlines only its book.
|
|
static void outline_frame_set(IconPass& outline, int item)
|
|
{
|
|
if (item == COLLECTIBLE_JAR_OF_WISPS || item == COLLECTIBLE_GLOWING_HOUR_GLASS)
|
|
outline.frame.y += ACTIVE_ICON_SIZE;
|
|
else if (item == COLLECTIBLE_EVERYTHING_JAR)
|
|
outline.frame.x = 0;
|
|
else if (item == COLLECTIBLE_GLASS_CANNON || item == COLLECTIBLE_BROKEN_GLASS_CANNON)
|
|
outline.frame.x += ACTIVE_ICON_SIZE;
|
|
else if (item == COLLECTIBLE_BREATH_OF_LIFE)
|
|
outline.isItemShown = false;
|
|
}
|
|
|
|
// The fills of an active's charge bar. A bar item shows Bethany's charges as all or nothing, a held item not at all.
|
|
static ChargeFills charge_fills_get(PlayerHUD& hud, const SlotCharge& slot, ItemConfig_Item* config)
|
|
{
|
|
ChargeFills fills;
|
|
float max = (float)slot.max;
|
|
|
|
fills.charge =
|
|
slot.subCharge != 0 ? (float)slot.subCharge / (max * SUBCHARGES_PER_CHARGE) : (float)slot.charge / max;
|
|
fills.battery = std::min(1.0f, (float)slot.battery / max);
|
|
if (slot.discharge == DISCHARGE_CHARGES)
|
|
{
|
|
fills.soul = std::min(1.0f, (float)(slot.soul + slot.charge) / max);
|
|
fills.blood = std::min(1.0f, (float)(slot.blood + slot.charge) / max);
|
|
}
|
|
else if (slot.discharge == DISCHARGE_BAR)
|
|
{
|
|
fills.soul = slot.soul > 0 ? 1 : 0;
|
|
fills.blood = slot.blood > 0 ? 1 : 0;
|
|
}
|
|
|
|
fills.partial = std::min(1.0f, ((float)slot.charge + slot.partial) / max);
|
|
if (fills.partial <= fills.charge)
|
|
fills.batteryPartial = std::min(1.0f, ((float)slot.battery + slot.partial) / max);
|
|
if (!config || config->id != COLLECTIBLE_BERSERK)
|
|
return fills;
|
|
|
|
TemporaryEffect* berserk = hud.player->temporaryEffects.GetCollectibleEffect(COLLECTIBLE_BERSERK);
|
|
if (berserk)
|
|
fills.cooldown = (float)berserk->cooldown / (float)config->maxCooldown;
|
|
return fills;
|
|
}
|
|
|
|
// The charge bar as one active draws it: the sprite, where, at what alpha, and how tall its fill is.
|
|
struct ChargeBar
|
|
{
|
|
ANM2* sprite = nullptr;
|
|
SpriteDraw draw;
|
|
float alpha = 1;
|
|
float height = BAR_HEIGHT;
|
|
};
|
|
|
|
// The bar's current frame drawn up to a part of it from the bottom, in the sprite's color.
|
|
static void bar_fill_render(const ChargeBar& bar, float fill)
|
|
{
|
|
SpriteDraw clamped = bar.draw;
|
|
clamped.topLeftClamp.y += (1 - fill) * bar.height;
|
|
bar.sprite->Render(clamped);
|
|
}
|
|
|
|
// The bar's current frame drawn up to a part of it in a color at the bar's alpha, then back in the default color.
|
|
static void bar_fill_draw(const ChargeBar& bar, float fill, ColorMod color)
|
|
{
|
|
color._tint[3] *= bar.alpha;
|
|
bar.sprite->color = color;
|
|
bar_fill_render(bar, fill);
|
|
bar.sprite->color = COLOR_DEFAULT;
|
|
}
|
|
|
|
// 008453c0 Draws an active slot (the second at half size): the item's icon over its shadow, with the book behind the
|
|
// first slot, outlined in white while it can be used, then its charge bar. The bar fills with Bethany's charges, the
|
|
// charge, the battery's and Berserk's cooldown, under the overlay of its segments. A flashing bar shows only its
|
|
// overlay on even frames. Hold shows the poop it holds.
|
|
void PlayerHUD::RenderActiveItem(int activeSlot, Vector at, PlayerHudLayout layout, float itemScale, float alpha)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
max_charge_cache_begin();
|
|
ScopeExit cacheEnd = {max_charge_cache_end};
|
|
#endif
|
|
if (!player || player->isCoopGhost)
|
|
return;
|
|
#ifdef ISAAC_REPENTOGON
|
|
HudActiveDraw activeDraw = {at, activeSlot, layout, alpha, itemScale};
|
|
if (hud_active_item_pre_render(*this, activeDraw)) return;
|
|
ScopeExit activePost = {[&] { hud_active_item_post_render(*this, activeDraw); }};
|
|
#endif
|
|
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Entity_Player& shown = *player;
|
|
int item = activeSlot >= 0 && activeSlot < PLAYER_HUD_ACTIVE_COUNT ? shown.activeItems[activeSlot].item : 0;
|
|
if (item == 0)
|
|
{
|
|
graphics.shader_default_set();
|
|
return;
|
|
}
|
|
|
|
bool isCompact = is_hud_compact(*this);
|
|
ANM2& bar = isCompact ? hud->chargeBarSmallSprite : hud->chargeBarSprite;
|
|
ItemConfig_Item* config = g_manager->itemConfig.GetCollectible(item);
|
|
SlotCharge charge = slot_charge_get(shown, activeSlot, config);
|
|
PlayerHUDActiveItem& active = activeItems[activeSlot];
|
|
float scale = (activeSlot == 1 ? SECOND_ACTIVE_SCALE : 1) * itemScale;
|
|
if (g_game->deathmatchManager.state >= DEATHMATCH_INTRO)
|
|
at.x -= VERSUS_ACTIVE_SHIFT;
|
|
|
|
if (active.itemImage || active.bookImage || active.id < 0)
|
|
{
|
|
Vector shake = g_game->screenShakeOffset;
|
|
IconLayout icon;
|
|
graphics.shader_default_set();
|
|
icon.isOutlined = charge.max >= 1 &&
|
|
shown.GetTotalActiveCharge(activeSlot) >= shown.GetActiveMinUsableCharge(activeSlot) &&
|
|
alpha >= 1;
|
|
active_icon_frame_set(icon, shown, activeSlot, charge);
|
|
#ifdef ISAAC_REPENTOGON
|
|
if (activeItemRender.isCropped) icon.frame = vector_make(activeItemRender.cropX, activeItemRender.cropY);
|
|
#endif
|
|
if (item == COLLECTIBLE_HOLD && shown.activeItems[activeSlot].varData != 0)
|
|
{
|
|
ANM2& poops = hud->poopSpellsSprite;
|
|
poops.scale = vector_make(scale, scale);
|
|
poops.SetFrame(HOLD_POOP_ANIMATION, shown.activeItems[activeSlot].varData);
|
|
poops.RenderLayer(HOLD_POOP_LAYER, {vector_make(scale * HOLD_POOP_X + at.x, scale * HOLD_POOP_Y + at.y)});
|
|
poops.scale = vector_make(1, 1);
|
|
}
|
|
if (active.bookImage)
|
|
at.y += BOOK_SLOT_DROP;
|
|
|
|
float iconSize = scale * ACTIVE_ICON_SIZE;
|
|
Vector origin = vector_add(at, shake);
|
|
ColorMod shadow = ICON_SHADOW;
|
|
shadow._tint[3] *= alpha;
|
|
icon_pass_draw(active, icon, iconSize,
|
|
{shadow, icon.frame,
|
|
vector_make(origin.x + scale * ACTIVE_SHADOW_SHIFT, origin.y + scale * ACTIVE_SHADOW_SHIFT)});
|
|
|
|
if (icon.isOutlined)
|
|
{
|
|
IconPass outline = {ICON_OUTLINE, icon.frame};
|
|
outline.color._tint[3] = alpha;
|
|
outline_frame_set(outline, item);
|
|
for (Vector step : {vector_make(-1, 0), vector_make(0, -1), vector_make(0, 1), vector_make(1, 0)})
|
|
{
|
|
outline.position = vector_make(origin.x - step.x * scale, origin.y - step.y * scale);
|
|
icon_pass_draw(active, icon, iconSize, outline);
|
|
}
|
|
}
|
|
|
|
bool isFull = charge.max >= 1 && charge.charge == charge.max;
|
|
if (item == COLLECTIBLE_BREATH_OF_LIFE || item == COLLECTIBLE_SMELTER)
|
|
icon.frame.x = isFull ? ACTIVE_ICON_SIZE : 0;
|
|
else if (item == COLLECTIBLE_MAMA_MEGA)
|
|
icon.frame.x = shown.hasGoldenBomb ? ACTIVE_ICON_SIZE : 0;
|
|
IconPass main = {COLOR_DEFAULT, icon.frame, origin};
|
|
main.color._tint[3] = alpha;
|
|
icon_pass_draw(active, icon, iconSize, main);
|
|
}
|
|
|
|
bool isBarHidden = charge.max < 1;
|
|
#ifdef ISAAC_REPENTOGON
|
|
isBarHidden = isBarHidden || activeItemRender.isChargeBarHidden;
|
|
#endif
|
|
if (isBarHidden)
|
|
{
|
|
graphics.shader_default_set();
|
|
return;
|
|
}
|
|
|
|
ChargeFills fills = charge_fills_get(*this, charge, config);
|
|
bool isFlipped = playerHudIndex >= MAIN_PLAYER_HUD_COUNT && layout == HUD_LAYOUT_JACOB_ESAU;
|
|
float barX =
|
|
activeSlot == 1 ? (isFlipped ? BAR_X_FLIPPED_SECOND : BAR_X_SECOND) : (isFlipped ? BAR_X_FLIPPED : BAR_X);
|
|
ChargeBar chargeBar = {&bar, {vector_make(barX * scale + at.x, scale * BAR_Y + at.y)}, alpha};
|
|
if (isCompact)
|
|
{
|
|
chargeBar.draw.position.y += BAR_SMALL_DROP;
|
|
chargeBar.height = BAR_SMALL_HEIGHT;
|
|
}
|
|
chargeBar.draw.topLeftClamp.y = isCompact ? BAR_SMALL_TOP : BAR_TOP;
|
|
const char* overlay = BAR_OVERLAY_SINGLE;
|
|
for (const BarOverlay& segments : BAR_OVERLAYS)
|
|
if (segments.charges == charge.max)
|
|
overlay = segments.animation;
|
|
|
|
bar.scale = vector_make(scale, scale);
|
|
bar.SetFrame(BAR_EMPTY, 0);
|
|
bar.color._tint[3] = alpha;
|
|
bar.Render({chargeBar.draw.position});
|
|
|
|
int flash = active.chargeBarFlash;
|
|
if (flash < 0 || flash % 2 == 1)
|
|
{
|
|
bar.SetFrame(BAR_FULL, 0);
|
|
if (fills.charge < fills.soul)
|
|
bar_fill_draw(chargeBar, fills.soul, BAR_SOUL);
|
|
if (fills.charge < fills.blood)
|
|
bar_fill_draw(chargeBar, fills.blood, BAR_BLOOD);
|
|
if (fills.charge < fills.partial)
|
|
bar_fill_draw(chargeBar, fills.partial, BAR_PARTIAL);
|
|
|
|
bool isNecronomiconFull = item == COLLECTIBLE_NECRONOMICON && shown.HasPlayerForm(NECRONOMICON_FORM) &&
|
|
shown.activeItems[activeSlot].varData == 1;
|
|
if (isNecronomiconFull)
|
|
bar_fill_draw(chargeBar, fills.charge, BAR_NECRONOMICON);
|
|
else
|
|
bar_fill_render(chargeBar, fills.charge);
|
|
if (fills.battery < fills.batteryPartial)
|
|
{
|
|
ColorMod color = BAR_BATTERY;
|
|
color._tint[3] = BAR_PARTIAL._tint[3];
|
|
bar_fill_draw(chargeBar, fills.batteryPartial, color);
|
|
}
|
|
if (fills.battery > 0)
|
|
bar_fill_draw(chargeBar, fills.battery, BAR_BATTERY);
|
|
if (fills.cooldown > 0)
|
|
bar_fill_draw(chargeBar, fills.cooldown, BAR_COOLDOWN);
|
|
}
|
|
|
|
bar.SetFrame(overlay, 0);
|
|
bar.color._tint[3] = alpha;
|
|
bar.Render({chargeBar.draw.position});
|
|
graphics.shader_default_set();
|
|
}
|
|
|
|
// (0084bab0) Draws a trinket's icon at a position and size in a color, from its 32 pixel frame at crop.
|
|
void PlayerHUD::trinket_draw(const PlayerHUDTrinket& trinket, Vector at, const ColorMod& color, float trinketScale,
|
|
Vector crop)
|
|
{
|
|
SourceQuad source = KAGE::Graphics::source_quad_rect(crop, vector_make(TRINKET_SIZE, TRINKET_SIZE));
|
|
Vector size = vector_make(trinketScale * TRINKET_SIZE, trinketScale * TRINKET_SIZE);
|
|
KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(at, size, kcolor_rgba(1, 1, 1, 1));
|
|
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *trinket.image);
|
|
trinket.image->Render(source, quad, kcolor_rgba(color._tint[0], color._tint[1], color._tint[2], color._tint[3]));
|
|
}
|
|
|
|
// 00846ff0 Draws a trinket slot's icon over its shadow, shaken with the screen and, when small, centered on its drawn
|
|
// pixels: the error trinket reddened, a golden trinket shimmering in the gold shader, a Modeling Clay copy in clay.
|
|
// Monkey Paw shows the frame of the fingers it has left. The original leaves the shaders it picks current. Here they
|
|
// are popped after.
|
|
void PlayerHUD::RenderTrinket(int trinketSlot, Vector at, float trinketScale, bool isSmall)
|
|
{
|
|
const PlayerHUDTrinket& trinket = trinkets[trinketSlot];
|
|
if (trinket.id == 0 || !trinket.image) return;
|
|
float frameX = trinket.id == TRINKET_MONKEY_PAW ? (float)(MONKEY_PAW_FRAMES - player->monkeyPawCounter) * TRINKET_SIZE
|
|
: 0;
|
|
Vector crop = vector_make(frameX, 0);
|
|
#ifdef ISAAC_REPENTOGON
|
|
if (!hud_trinket_pre_render(*this, trinketSlot, at, trinketScale, crop)) return;
|
|
#endif
|
|
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Vector shake = g_game->screenShakeOffset;
|
|
Vector position = vector_make(at.x + shake.x, shake.y + at.y);
|
|
if (isSmall)
|
|
position = vector_make(position.x - trinketScale * trinket.offset.x, position.y - trinketScale * trinket.offset.y);
|
|
|
|
int pushed = graphics.shader_push(COLOR_OFFSET_SHADER) ? 1 : 0;
|
|
trinket_draw(trinket, vector_make(trinketScale + trinketScale + position.x, trinketScale + trinketScale + position.y),
|
|
TRINKET_SHADOW, trinketScale, crop);
|
|
|
|
ColorMod color = COLOR_DEFAULT;
|
|
uint32_t held = player->trinkets[trinketSlot];
|
|
if ((held & TRINKET_ID_MASK) == TRINKET_ERROR)
|
|
for (int i = 0; i < 3; i++) color._tint[i] = ERROR_TRINKET_TINT[i];
|
|
if (held & TRINKET_GOLDEN_FLAG)
|
|
{
|
|
if (graphics.shader_push(COLOR_OFFSET_GOLD_SHADER)) pushed++;
|
|
color._colorize[3] = (float)(g_game->frameCount % GOLD_SHIMMER_STEPS) * (1.0f / GOLD_SHIMMER_STEPS);
|
|
}
|
|
else if (trinket.clayItem != 0)
|
|
for (int i = 0; i < 4; i++) color._colorize[i] = CLAY_COLORIZE[i];
|
|
trinket_draw(trinket, position, color, trinketScale, crop);
|
|
for (; pushed > 0; pushed--) graphics.shader_pop();
|
|
}
|
|
|
|
// The pockets behind the first, small: their cards and pills, or the pocket active at half size. The normal HUD stacks
|
|
// them up from the corner, the others line them along the bottom.
|
|
static void pockets_back_render(PlayerHUD& hud, Vector at, PlayerHudLayout layout, float alpha, float size)
|
|
{
|
|
Entity_Player* player = hud.player;
|
|
bool isNormal = layout == HUD_LAYOUT_NORMAL;
|
|
for (int i = isNormal ? POCKET_SLOT_COUNT - 1 : 1; isNormal ? i > 0 : i < POCKET_SLOT_COUNT; i += isNormal ? -1 : 1)
|
|
{
|
|
PocketItem& held = player->pocketItems[i];
|
|
if (held.id == 0) continue;
|
|
|
|
Vector spot = isNormal ? vector_make(at.x + POCKET_BACK_X, at.y + (POCKET_BACK_RISE - (float)i * POCKET_BACK_STEP * size))
|
|
: vector_make(at.x + ((float)i * POCKET_BACK_ROW_STEP * size - POCKET_BACK_ROW_X),
|
|
at.y + size * POCKET_BACK_ROW_Y);
|
|
if (held.type == POCKET_ACTIVE)
|
|
{
|
|
Vector itemAt = vector_make(spot.x + size * (isNormal ? POCKET_BACK_ACTIVE_X : POCKET_BACK_ROW_ACTIVE_X),
|
|
spot.y + size * POCKET_BACK_ACTIVE_Y);
|
|
hud.RenderActiveItem(held.id - 1, itemAt, isNormal ? HUD_LAYOUT_NORMAL : layout, size * 0.5f, alpha);
|
|
continue;
|
|
}
|
|
ANM2& sprite = hud.pocketItems[i].sprite;
|
|
if (!sprite.isLoaded) continue;
|
|
sprite.SetFrame("HUDSmall", 0);
|
|
sprite.Render({spot, {}, {}});
|
|
}
|
|
}
|
|
|
|
// Sets the first pocket's card front on the card sheet. True when it shows: a vanilla card whose frame draws a layer,
|
|
// or any modded card.
|
|
static bool card_front_set(HUD& hud, int id)
|
|
{
|
|
ANM2& cards = hud.cardsPillsSprite;
|
|
if (id >= CARD_FRONT_COUNT) return true;
|
|
|
|
cards.SetFrame(ANIMATION_CARD_FRONTS, id);
|
|
for (int layer = 0; layer < (int)cards.layerStates.size(); layer++)
|
|
{
|
|
const AnimationFrame* frame = cards.animState.GetLayerFrame(layer);
|
|
if (frame && frame->isVisible) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// The first pocket's name: a card's or pill's, a pocket active's (its description while the map is held), or the
|
|
// question marks the mystery seeds show. Unidentified pills show question marks too.
|
|
static std::string pocket_name_get(Entity_Player& player, const PocketItem& held)
|
|
{
|
|
StringTable& table = g_manager->stringTable;
|
|
Seeds& seeds = g_game->seedEffects;
|
|
auto is_map_held = [&] { return input_is_action_pressed(ACTION_MAP, player.controllerIndex, nullptr); };
|
|
bool isMystery = (seeds.HasSeedEffect(SEED_PILLS_NEVER_IDENTIFY) && held.type == POCKET_PILL) ||
|
|
(seeds.HasSeedEffect(SEED_MYSTERY_TAROT_CARDS) && held.type == POCKET_CARD);
|
|
std::string name;
|
|
|
|
if (held.type == POCKET_CARD)
|
|
{
|
|
ItemConfig_Card* card = g_manager->itemConfig.GetCard(held.id);
|
|
if (card) name = is_map_held() ? card->description_get() : card->GetName();
|
|
}
|
|
else if (held.type == POCKET_PILL)
|
|
{
|
|
uint32_t color = (uint32_t)(held.id & PILL_COLOR_MASK);
|
|
if (!g_game->itemPool.IsPillIdentified(color)) isMystery = true;
|
|
else if (ItemConfig_Pill* pill = g_manager->itemConfig.GetPillEffect(g_game->itemPool.GetPillEffect(color, &player)))
|
|
name = pill->GetName();
|
|
}
|
|
else if (ItemConfig_Item* item = g_manager->itemConfig.GetCollectible(player.activeItems[held.id - 1].item))
|
|
name = is_map_held() ? item->description_get() : item->GetLocalizedName();
|
|
if (!isMystery) return name;
|
|
|
|
bool isMissing = false;
|
|
std::string_view marks = table.get_string("PocketItems", table.language, "QUESTION_MARKS_NAME", &isMissing);
|
|
return isMissing ? "#QUESTION_MARKS_NAME" : std::string(marks);
|
|
}
|
|
|
|
// 008471c0 Draws the pockets at their size and alpha: those behind the first small, then the first with its name. A
|
|
// card shows its front (or the pickup's HUD frame), a pill its HUD frame and a pocket active its icon, the Bag of
|
|
// Crafting's table in place of a name. The Dyslexia seed scrambles the name, and Esau's second HUD sets it left of the
|
|
// pocket. The pocket sprites and the HUD's card sprite go back to full size after. Netplay's remote check of the map
|
|
// button is offline, and a TMTRAINER pocket active stops the game.
|
|
void PlayerHUD::RenderPocketItems(Vector at, PlayerHudLayout layout, float alpha, float pocketScale)
|
|
{
|
|
Entity_Player& shown = *player;
|
|
ANM2& cards = hud->cardsPillsSprite;
|
|
float size = std::abs(pocketScale);
|
|
cards.scale = vector_make(size, size);
|
|
cards.color._tint[3] = alpha;
|
|
for (PlayerHUDPocketItem& pocket : pocketItems)
|
|
{
|
|
pocket.sprite.scale = vector_make(size, size);
|
|
pocket.sprite.color._tint[3] = alpha;
|
|
}
|
|
Entity_Player* twin = shown.twin_get();
|
|
bool isSecondTwin = twin && twin->playerIndex != -1 && shown.playerIndex > twin->playerIndex && twin != &shown;
|
|
pockets_back_render(*this, at, layout, alpha, size);
|
|
|
|
PocketItem& held = shown.pocketItems[0];
|
|
bool isActive = held.type == POCKET_ACTIVE;
|
|
ItemConfig_Card* card = held.type == POCKET_CARD ? g_manager->itemConfig.GetCard(held.id) : nullptr;
|
|
bool isShown = held.id != 0 && (!isActive || (held.id - 1U < ACTIVE_SLOT_COUNT &&
|
|
g_manager->itemConfig.GetCollectible(shown.activeItems[held.id - 1].item)));
|
|
if (isShown)
|
|
{
|
|
bool isFrontShown = held.type == POCKET_CARD && !g_game->seedEffects.HasSeedEffect(SEED_MYSTERY_TAROT_CARDS) &&
|
|
card_front_set(*hud, held.id);
|
|
bool isGlowing = card && (card->cardType == CARD_TAROT || card->cardType == CARD_TAROT_REVERSE) &&
|
|
shown.HasCollectible(COLLECTIBLE_TAROT_CLOTH);
|
|
std::string name = pocket_name_get(shown, held);
|
|
bool isNormal = layout == HUD_LAYOUT_NORMAL;
|
|
float cardX = isFrontShown && isNormal ? CARD_FRONT_SHIFT : 0;
|
|
float textX = isNormal ? POCKET_TEXT_X : POCKET_ROW_TEXT_X;
|
|
float textY = POCKET_TEXT_Y;
|
|
Vector spot = vector_make(at.x + cardX, at.y);
|
|
|
|
if (isActive)
|
|
{
|
|
int slot = held.id - 1;
|
|
textX += isNormal ? POCKET_ACTIVE_TEXT_SHIFT : POCKET_ROW_ACTIVE_TEXT_SHIFT;
|
|
Vector itemAt = isNormal ? vector_make(spot.x - POCKET_ACTIVE_X, spot.y - POCKET_ACTIVE_Y)
|
|
: vector_make(spot.x - POCKET_ROW_ACTIVE_X, spot.y - POCKET_ROW_ACTIVE_Y);
|
|
RenderActiveItem(slot, itemAt, isNormal ? HUD_LAYOUT_NORMAL : layout, size, alpha);
|
|
if (isNormal) textY = POCKET_SHOWN_TEXT_Y;
|
|
if (shown.activeItems[slot].item == COLLECTIBLE_BAG_OF_CRAFTING)
|
|
{
|
|
name.clear();
|
|
Vector tableAt = isNormal ? vector_make((textX - CRAFTING_TABLE_X) * size + at.x, size * CRAFTING_TABLE_Y + at.y)
|
|
: vector_make((textX + CRAFTING_ROW_TABLE_X) * size + at.x,
|
|
size * CRAFTING_ROW_TABLE_Y + at.y);
|
|
RenderCraftingTable(tableAt, size);
|
|
}
|
|
}
|
|
else if (!isFrontShown)
|
|
{
|
|
textY = POCKET_SHOWN_TEXT_Y;
|
|
ANM2& sprite = pocketItems[0].sprite;
|
|
if (sprite.isLoaded)
|
|
{
|
|
sprite.SetFrame(ANIMATION_HUD, 0);
|
|
sprite.Render({spot, {}, {}});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (isGlowing)
|
|
{
|
|
float phase = (float)g_game->frameCount * TAROT_GLOW_SPEED;
|
|
cards.color = COLOR_DEFAULT;
|
|
cards.color._tint[3] = alpha;
|
|
cards.color._offset[0] = sin_float(phase + TAROT_GLOW_RED_PHASE) * TAROT_GLOW_RED + TAROT_GLOW_RED;
|
|
cards.color._offset[1] = sin_float(phase + TAROT_GLOW_GREEN_PHASE) * TAROT_GLOW_GREEN + TAROT_GLOW_GREEN;
|
|
cards.color._offset[2] = sin_float(phase) * TAROT_GLOW_BLUE + TAROT_GLOW_BLUE;
|
|
}
|
|
bool isModdedFront = held.id >= CARD_FRONT_COUNT && card && !card->hudAnim.empty();
|
|
if (!isModdedFront) cards.Render({spot, {}, {}});
|
|
else if (card->moddedCardFront)
|
|
{
|
|
card->moddedCardFront->Play(card->hudAnim);
|
|
card->moddedCardFront->Render({spot, {}, {}});
|
|
}
|
|
cards.color = COLOR_DEFAULT;
|
|
textY = POCKET_SHOWN_TEXT_Y;
|
|
}
|
|
|
|
if (!name.empty())
|
|
{
|
|
if (g_game->seedEffects.HasSeedEffect(SEED_DYSLEXIA)) name = string_scramble_seeded(name);
|
|
Font& font = g_manager->font9_PFTempestaSevenCondensedAgain;
|
|
float x = at.x + textX * size;
|
|
if (isNormal) x -= (float)font.GetStringWidth(name) * size;
|
|
else if (layout == HUD_LAYOUT_JACOB_ESAU && isSecondTwin)
|
|
x -= (float)font.GetStringWidth(name) * size + POCKET_SECOND_TWIN_SHIFT;
|
|
Vector shake = g_game->screenShakeOffset;
|
|
FontSettings settings;
|
|
font.DrawString(name, vector_make(x + shake.x, at.y + textY * size + shake.y), vector_make(size, size),
|
|
kcolor_rgba(1, 1, 1, alpha), settings);
|
|
}
|
|
}
|
|
|
|
cards.scale = vector_make(1, 1);
|
|
for (PlayerHUDPocketItem& pocket : pocketItems)
|
|
{
|
|
pocket.sprite.scale = vector_make(1, 1);
|
|
pocket.sprite.color._tint[3] = 1;
|
|
}
|
|
}
|
|
|
|
// (00848c20) Draws an inventory or crafting icon in a quad: a glitched item through the procedural items.
|
|
static void inventory_icon_draw(const PlayerHUDIcon& icon, const KAGE::Graphics::ColorQuad& quad, const ColorMod& color)
|
|
{
|
|
SourceQuad source = KAGE::Graphics::source_quad_rect({}, vector_make(INVENTORY_ICON_SIZE, INVENTORY_ICON_SIZE));
|
|
if (icon.id < 0) return glitched_icon_draw(icon.id, source, quad, color);
|
|
if (!icon.image) return;
|
|
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *icon.image);
|
|
icon.image->Render(source, quad, kcolor_rgba(color._tint[0], color._tint[1], color._tint[2], color._tint[3]));
|
|
}
|
|
|
|
// 00848d20 Draws Tainted Isaac's inventory in two rows: each held item's icon at half size over its shadow, shaken
|
|
// with the screen and widening the corner's bounds, or a faint dot for an empty slot. The first slot is marked as the
|
|
// one the next item replaces.
|
|
void PlayerHUD::render_inventory(Vector at, float inventoryScale)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
HudElementScope elementScope(*this, HUD_ELEMENT_INVENTORY, at, inventoryScale);
|
|
if (!elementScope.isDrawn) return;
|
|
#endif
|
|
ANM2& sprite = hud->inventorySprite;
|
|
int slots = player->GetMaxInventorySize();
|
|
int columns = slots / 2;
|
|
float half = inventoryScale * INVENTORY_ICON_SIZE * 0.5f;
|
|
float inset = inventoryScale * INVENTORY_ICON_SIZE * 0.25f;
|
|
Vector shake = g_game->screenShakeOffset;
|
|
|
|
sprite.scale = vector_make(inventoryScale, inventoryScale);
|
|
for (int slot = 0; slot < slots; slot++)
|
|
{
|
|
int row = slot / columns;
|
|
Vector cell = vector_make((float)(slot % columns) * INVENTORY_STEP * inventoryScale + at.x,
|
|
(float)row * INVENTORY_STEP * inventoryScale + at.y);
|
|
bool isShown = slot < (int)inventoryIcons.size() && (inventoryIcons[slot].image || inventoryIcons[slot].id < 0);
|
|
if (isShown)
|
|
{
|
|
const PlayerHUDIcon& icon = inventoryIcons[slot];
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
Vector size = vector_make(half, half);
|
|
Vector spot = vector_make(cell.x + shake.x, cell.y + shake.y);
|
|
inventory_icon_draw(icon, KAGE::Graphics::color_quad_rect(vector_make(spot.x + inventoryScale, spot.y + inventoryScale),
|
|
size, kcolor_rgba(1, 1, 1, 1)),
|
|
INVENTORY_SHADOW);
|
|
KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(spot, size, kcolor_rgba(1, 1, 1, 1));
|
|
inventory_icon_draw(icon, quad, COLOR_DEFAULT);
|
|
for (Vector corner : {quad._topLeft, quad._bottomRight})
|
|
{
|
|
boundsMin = vector_make(std::min(boundsMin.x, corner.x), std::min(boundsMin.y, corner.y));
|
|
boundsMax = vector_make(std::max(boundsMax.x, corner.x), std::max(boundsMax.y, corner.y));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sprite.GetLayer(INVENTORY_LAYER_DOT)->color._tint[3] = INVENTORY_DOT_ALPHA;
|
|
sprite.RenderLayer(INVENTORY_LAYER_DOT, {vector_make(inset + cell.x, inset + cell.y)});
|
|
}
|
|
if (slot == 0) sprite.RenderLayer(INVENTORY_LAYER_SELECT, {vector_make(inset + cell.x, cell.y + inset)});
|
|
}
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
}
|
|
|
|
// Shows a frame of the crafting table sprite's animation, stopped there.
|
|
static void crafting_frame_set(ANM2& sprite, std::string_view animation, float frame)
|
|
{
|
|
if (!sprite.SetAnimation(animation) || !sprite.animState.animData) return;
|
|
sprite.animState.SetFrameFloat(frame);
|
|
sprite.animState.isPlaying = false;
|
|
}
|
|
|
|
// Draws an item card's icon over its shadow (shifted by a scale) and widens the corner's bounds to the icon.
|
|
void PlayerHUD::card_icon_render(const PlayerHUDIcon& icon, Vector at, float size, float shadowShift)
|
|
{
|
|
Vector square = vector_make(size, size);
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
inventory_icon_draw(icon, KAGE::Graphics::color_quad_rect(vector_make(at.x + shadowShift, at.y + shadowShift), square,
|
|
kcolor_rgba(1, 1, 1, 1)),
|
|
INVENTORY_SHADOW);
|
|
KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(at, square, kcolor_rgba(1, 1, 1, 1));
|
|
inventory_icon_draw(icon, quad, COLOR_DEFAULT);
|
|
for (Vector corner : {quad._topLeft, quad._bottomRight})
|
|
{
|
|
boundsMin = vector_make(std::min(boundsMin.x, corner.x), std::min(boundsMin.y, corner.y));
|
|
boundsMax = vector_make(std::max(boundsMax.x, corner.x), std::max(boundsMax.y, corner.y));
|
|
}
|
|
}
|
|
|
|
// The Cantripped part of RenderCraftingTable (00849510): the cards held, last first. The first fills the result box
|
|
// (faint while empty) with its icon over a shadow the original draws in the same spot. The others line up leftward at
|
|
// half size over shadows, an empty one as an empty slot.
|
|
void PlayerHUD::render_card_table(Vector at, float tableScale)
|
|
{
|
|
ANM2& sprite = hud->craftingTableSprite;
|
|
Vector shake = g_game->screenShakeOffset;
|
|
int cards = std::min(player->GetCollectibleNum(COLLECTIBLE_STARTER_DECK, ITEM_CHECK_MODIFIED) + CARD_TABLE_BASE, CARD_TABLE_MAX);
|
|
auto is_held = [&](int slot) {
|
|
return slot < (int)inventoryIcons.size() && (inventoryIcons[slot].image || inventoryIcons[slot].id < 0);
|
|
};
|
|
|
|
for (int slot = cards - 1; slot > 0; slot--)
|
|
{
|
|
float x = (CARD_ROW_X - (float)(slot - 1) * CRAFTING_STEP) * tableScale;
|
|
if (is_held(slot))
|
|
{
|
|
Vector spot = vector_make(x + shake.x + at.x, at.y + shake.y + tableScale * CARD_ROW_Y);
|
|
card_icon_render(inventoryIcons[slot], spot, tableScale * CRAFTING_ICON_SIZE * 0.5f, tableScale);
|
|
continue;
|
|
}
|
|
crafting_frame_set(sprite, CRAFTING_SLOT_ANIMATION, 0);
|
|
sprite.Render({vector_make(x + CARD_EMPTY_SHIFT_X * tableScale + at.x, tableScale * CARD_EMPTY_Y + at.y)});
|
|
}
|
|
if (cards <= 0) return;
|
|
|
|
bool isResultHeld = is_held(0);
|
|
crafting_frame_set(sprite, CRAFTING_RESULT_ANIMATION, CARD_RESULT_FRAME);
|
|
if (!isResultHeld) sprite.color = CRAFTING_EMPTY_COLOR;
|
|
sprite.Render({at});
|
|
sprite.color = COLOR_DEFAULT;
|
|
if (isResultHeld)
|
|
{
|
|
float half = CRAFTING_ICON_SIZE * 0.5f;
|
|
card_icon_render(inventoryIcons[0], vector_make(at.x + shake.x - half, at.y + shake.y - half),
|
|
tableScale * CRAFTING_ICON_SIZE, 0);
|
|
}
|
|
}
|
|
|
|
// 00849510 Draws Tainted Cain's crafting bag: the result box, faint while the bag makes nothing, else with the item's
|
|
// icon over its shadow, then the bag's eight pickups in two rows, each widening the corner's bounds. In the Cantripped
|
|
// challenge it draws the card table instead.
|
|
void PlayerHUD::RenderCraftingTable(Vector at, float tableScale)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
HudElementScope elementScope(*this, HUD_ELEMENT_CRAFTING_TABLE, at, tableScale);
|
|
if (!elementScope.isDrawn) return;
|
|
#endif
|
|
ANM2& sprite = hud->craftingTableSprite;
|
|
sprite.scale = vector_make(tableScale, tableScale);
|
|
if (g_game->challenge == CHALLENGE_CANTRIPPED)
|
|
{
|
|
render_card_table(at, tableScale);
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
return;
|
|
}
|
|
|
|
crafting_frame_set(sprite, CRAFTING_RESULT_ANIMATION, 0);
|
|
if (!craftingResultImage) sprite.color = CRAFTING_EMPTY_COLOR;
|
|
sprite.Render({at});
|
|
sprite.color = COLOR_DEFAULT;
|
|
if (craftingResultImage)
|
|
{
|
|
Vector shake = g_game->screenShakeOffset;
|
|
float half = tableScale * CRAFTING_ICON_SIZE * 0.5f;
|
|
float size = tableScale * CRAFTING_ICON_SIZE;
|
|
KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(
|
|
vector_make(at.x + shake.x - half, at.y + shake.y - half), vector_make(size, size), kcolor_rgba(1, 1, 1, 1));
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
for (const ColorMod& color : {INVENTORY_SHADOW, COLOR_DEFAULT})
|
|
inventory_icon_draw({craftingResultImage, 0}, quad, color);
|
|
}
|
|
|
|
float reach = tableScale * CRAFTING_SLOT_REACH;
|
|
for (int slot = 0; slot < BAG_OF_CRAFTING_SIZE; slot++)
|
|
{
|
|
int row = slot / CRAFTING_COLUMNS;
|
|
Vector spot = vector_make(((float)(slot % CRAFTING_COLUMNS) * CRAFTING_STEP - CRAFTING_SLOTS_X) * tableScale + at.x,
|
|
((float)row * CRAFTING_STEP - CRAFTING_SLOTS_Y) * tableScale + at.y);
|
|
crafting_frame_set(sprite, CRAFTING_SLOT_ANIMATION, (float)player->bagOfCraftingContent[slot]);
|
|
sprite.Render({spot});
|
|
boundsMin = vector_make(std::min(boundsMin.x, spot.x - reach), std::min(boundsMin.y, spot.y - reach));
|
|
boundsMax = vector_make(std::max(boundsMax.x, spot.x + reach), std::max(boundsMax.y, spot.y + reach));
|
|
}
|
|
KAGE::Graphics::manager.shader_default_set();
|
|
}
|
|
|
|
// The hearts of a versus health bar's segments in the order it shows them, also the order of their columns in its
|
|
// image (two texels each: a cap and a fill).
|
|
enum VersusBarKind : int
|
|
{
|
|
VERSUS_BAR_RED,
|
|
VERSUS_BAR_EMPTY,
|
|
VERSUS_BAR_SOUL,
|
|
VERSUS_BAR_GOLDEN,
|
|
VERSUS_BAR_ROTTEN,
|
|
VERSUS_BAR_BONE,
|
|
VERSUS_BAR_BLACK,
|
|
VERSUS_BAR_KIND_COUNT
|
|
};
|
|
|
|
// A rectangle of texels in the health bar's image.
|
|
struct VersusBarTexels
|
|
{
|
|
float x = 0;
|
|
float y = 0;
|
|
float width = 0;
|
|
float height = 0;
|
|
};
|
|
|
|
// A versus health bar: 80 hearts on its first row and the rest on a second one 13 lower, 1.2 wide each, drawn in
|
|
// segments of at most 16 between caps 2 wide, with a tick 1 wide between kinds, all 8 high. A frame 14 high goes
|
|
// around each row, starting 2 above and left of it, and the player's portrait sits left of the first row.
|
|
constexpr const char* VERSUS_BAR_PNG = "gfx/ui/ui_isaachealthbar.png";
|
|
constexpr int VERSUS_BAR_ROW_HEARTS = 80;
|
|
constexpr int VERSUS_BAR_SEGMENT_HEARTS = 16;
|
|
constexpr float VERSUS_BAR_HEART_WIDTH = 1.2f;
|
|
constexpr float VERSUS_BAR_CAP_WIDTH = 2;
|
|
constexpr float VERSUS_BAR_TICK_WIDTH = 1;
|
|
constexpr float VERSUS_BAR_HEIGHT = 8;
|
|
constexpr float VERSUS_BAR_ROW_SPACING = 13;
|
|
constexpr float VERSUS_BAR_FRAME_INSET = 2;
|
|
constexpr float VERSUS_BAR_PORTRAIT_BACK_X = -14;
|
|
constexpr float VERSUS_BAR_PORTRAIT_X = -16;
|
|
constexpr float VERSUS_BAR_PORTRAIT_Y = -2;
|
|
constexpr float VERSUS_BAR_SIZE_X = 46;
|
|
constexpr float VERSUS_BAR_SIZE_Y = 17;
|
|
constexpr VersusBarTexels VERSUS_BAR_TICK = {12, 6, 1, 2};
|
|
constexpr VersusBarTexels VERSUS_BAR_FRAME_LEFT = {22, 16, 3, 14};
|
|
constexpr VersusBarTexels VERSUS_BAR_FRAME_MIDDLE = {25, 16, 1, 14};
|
|
constexpr VersusBarTexels VERSUS_BAR_FRAME_RIGHT = {26, 16, 5, 14};
|
|
constexpr VersusBarTexels VERSUS_BAR_PORTRAIT_BACK = {15, 0, 16, 14};
|
|
constexpr VersusBarTexels VERSUS_BAR_PORTRAIT = {0, 14, 20, 18};
|
|
|
|
// The source quad of a rectangle of the health bar's image.
|
|
static SourceQuad versus_bar_source(const VersusBarTexels& texels)
|
|
{
|
|
return KAGE::Graphics::source_quad_rect(vector_make(texels.x, texels.y), vector_make(texels.width, texels.height));
|
|
}
|
|
|
|
// The hearts a player has of a kind of the health bar: its empty heart containers stand for the empty kind.
|
|
static int versus_bar_hearts_get(const Entity_Player& shown, int kind)
|
|
{
|
|
switch (kind)
|
|
{
|
|
case VERSUS_BAR_RED: return shown.redHearts;
|
|
case VERSUS_BAR_EMPTY: return shown.maxHearts - shown.redHearts;
|
|
case VERSUS_BAR_SOUL: return shown.soulHearts;
|
|
case VERSUS_BAR_GOLDEN: return shown.goldenHearts;
|
|
case VERSUS_BAR_ROTTEN: return shown.rottenHearts;
|
|
case VERSUS_BAR_BONE: return shown.boneHearts;
|
|
default: return shown.blackHearts;
|
|
}
|
|
}
|
|
|
|
// (0084a920, 0084abc0) Draws up to 16 hearts of a kind at the cursor as a cap, a stretched fill and a cap, taking them
|
|
// from both the kind's and the row's counts. Whether either count ran out.
|
|
static bool versus_bar_segment_render(KAGE::Graphics::ImageBase& image, int kind, Vector& cursor, int& hearts,
|
|
int& remaining)
|
|
{
|
|
float column = (float)(kind * 2);
|
|
SourceQuad cap = versus_bar_source({column, 0, 1, VERSUS_BAR_HEIGHT});
|
|
SourceQuad fill = versus_bar_source({column + 1, 0, 1, VERSUS_BAR_HEIGHT});
|
|
int taken = std::min({remaining, hearts, VERSUS_BAR_SEGMENT_HEARTS});
|
|
|
|
hearts -= taken;
|
|
remaining -= taken;
|
|
float width = (float)taken * VERSUS_BAR_HEART_WIDTH;
|
|
Vector capSize = vector_make(VERSUS_BAR_CAP_WIDTH, VERSUS_BAR_HEIGHT);
|
|
if (width > 0)
|
|
{
|
|
image.Render(cap, KAGE::Graphics::color_quad_rect(cursor, capSize, WHITE), WHITE);
|
|
cursor.x += VERSUS_BAR_CAP_WIDTH;
|
|
width -= VERSUS_BAR_CAP_WIDTH;
|
|
}
|
|
if (width > VERSUS_BAR_CAP_WIDTH)
|
|
{
|
|
Vector fillSize = vector_make(width - VERSUS_BAR_CAP_WIDTH, VERSUS_BAR_HEIGHT);
|
|
KAGE::Graphics::ColorQuad quad = KAGE::Graphics::color_quad_rect(cursor, fillSize, WHITE);
|
|
image.Render(fill, quad, WHITE);
|
|
cursor.x += quad._topRight.x - quad._topLeft.x;
|
|
width = VERSUS_BAR_CAP_WIDTH;
|
|
}
|
|
if (width > 0)
|
|
{
|
|
image.Render(cap, KAGE::Graphics::color_quad_rect(cursor, capSize, WHITE), WHITE);
|
|
cursor.x += VERSUS_BAR_CAP_WIDTH;
|
|
}
|
|
return std::min(hearts, remaining) == 0;
|
|
}
|
|
|
|
// 0084ad40 Draws a versus health bar and returns its size (none for a ghost): the hearts kind by kind from red to
|
|
// black, a tick before each kind but the first of a row, the empty containers first finishing the red hearts' last
|
|
// segment. Past 80 hearts a second row starts. Then the frames, the portrait's backing and the portrait in the
|
|
// player's color.
|
|
Vector PlayerHUD::render_deathmatch_health_bar(Vector at)
|
|
{
|
|
Entity_Player& shown = *player;
|
|
if (shown.isCoopGhost) return vector_make(0, 0);
|
|
if (!deathmatchHealthBarImage) deathmatchHealthBarImage = Manager::LoadImage(VERSUS_BAR_PNG);
|
|
if (!deathmatchHealthBarImage) return vector_make(0, 0);
|
|
|
|
KAGE::Graphics::ImageBase& image = *deathmatchHealthBarImage;
|
|
std::vector<Vector> rowEnds;
|
|
std::vector<Vector> rowStarts = {vector_make(at.x - VERSUS_BAR_FRAME_INSET, at.y - VERSUS_BAR_FRAME_INSET)};
|
|
std::vector<Vector> ticks;
|
|
Vector cursor = at;
|
|
int total = shown.rottenHearts + shown.boneHearts + shown.goldenHearts + shown.blackHearts + shown.soulHearts +
|
|
shown.maxHearts;
|
|
int rowHearts = (unsigned)total > VERSUS_BAR_ROW_HEARTS ? VERSUS_BAR_ROW_HEARTS : total;
|
|
int overflowHearts = total - rowHearts;
|
|
int* remaining = &rowHearts;
|
|
int hearts = shown.redHearts;
|
|
int kind = VERSUS_BAR_RED;
|
|
bool isTickSkipped = hearts > 0;
|
|
|
|
while (kind < VERSUS_BAR_KIND_COUNT)
|
|
{
|
|
cursor = vector_make(std::floor(cursor.x), std::floor(cursor.y));
|
|
if (std::min(*remaining, hearts) > 0)
|
|
{
|
|
if (!isTickSkipped)
|
|
{
|
|
ticks.push_back(cursor);
|
|
cursor.x += VERSUS_BAR_TICK_WIDTH;
|
|
}
|
|
isTickSkipped = false;
|
|
}
|
|
|
|
int startHearts = hearts;
|
|
if (!versus_bar_segment_render(image, kind, cursor, hearts, *remaining)) continue;
|
|
if (*remaining == 0)
|
|
{
|
|
if (overflowHearts <= 0) break;
|
|
remaining = &overflowHearts;
|
|
rowEnds.push_back(vector_make(cursor.x - 1, cursor.y - VERSUS_BAR_FRAME_INSET));
|
|
cursor = vector_make(at.x, at.y + VERSUS_BAR_ROW_SPACING);
|
|
isTickSkipped = true;
|
|
rowStarts.push_back(vector_make(cursor.x - VERSUS_BAR_FRAME_INSET, cursor.y - VERSUS_BAR_FRAME_INSET));
|
|
}
|
|
if (hearts != 0 || ++kind == VERSUS_BAR_KIND_COUNT) continue;
|
|
|
|
hearts = versus_bar_hearts_get(shown, kind);
|
|
if (kind != VERSUS_BAR_EMPTY) continue;
|
|
int finish = std::min(VERSUS_BAR_SEGMENT_HEARTS - startHearts, hearts);
|
|
if (finish == 0) continue;
|
|
hearts -= finish;
|
|
versus_bar_segment_render(image, kind, cursor, finish, *remaining);
|
|
}
|
|
if (rowStarts.size() > rowEnds.size())
|
|
rowEnds.push_back(vector_make(cursor.x - 1, cursor.y - VERSUS_BAR_FRAME_INSET));
|
|
|
|
SourceQuad tick = versus_bar_source(VERSUS_BAR_TICK);
|
|
Vector tickSize = vector_make(VERSUS_BAR_TICK_WIDTH, VERSUS_BAR_HEIGHT);
|
|
for (Vector& spot : ticks) image.Render(tick, KAGE::Graphics::color_quad_rect(spot, tickSize, WHITE), WHITE);
|
|
|
|
SourceQuad left = versus_bar_source(VERSUS_BAR_FRAME_LEFT);
|
|
SourceQuad middle = versus_bar_source(VERSUS_BAR_FRAME_MIDDLE);
|
|
SourceQuad right = versus_bar_source(VERSUS_BAR_FRAME_RIGHT);
|
|
for (size_t row = 0; row < rowStarts.size(); row++)
|
|
{
|
|
Vector start = rowStarts[row];
|
|
Vector end = rowEnds[row];
|
|
image.Render(left, start, WHITE);
|
|
image.Render(right, end, WHITE);
|
|
Vector from = vector_make(start.x + VERSUS_BAR_FRAME_LEFT.width, start.y);
|
|
Vector to = vector_make(end.x, end.y + VERSUS_BAR_FRAME_MIDDLE.height);
|
|
DestinationQuad quad = {from, vector_make(to.x, from.y), vector_make(from.x, to.y), to};
|
|
image.Render(middle, KAGE::Graphics::ColorQuad(quad, WHITE), WHITE);
|
|
}
|
|
|
|
std::array<int, COOP_SLOT_COUNT>& colors = g_game->playerManager.colorControllers;
|
|
auto color = std::ranges::find(colors, shown.controllerIndex);
|
|
int colorIndex = color == colors.end() ? PLAYER_COLOR_NONE : (int)(color - colors.begin());
|
|
image.Render(versus_bar_source(VERSUS_BAR_PORTRAIT_BACK), vector_make(at.x + VERSUS_BAR_PORTRAIT_BACK_X, at.y),
|
|
WHITE);
|
|
image.Render(versus_bar_source(VERSUS_BAR_PORTRAIT),
|
|
vector_make(at.x + VERSUS_BAR_PORTRAIT_X, at.y + VERSUS_BAR_PORTRAIT_Y),
|
|
PlayerManager::GetPlayerColorValue(colorIndex));
|
|
return vector_make(VERSUS_BAR_SIZE_X, VERSUS_BAR_SIZE_Y);
|
|
}
|
|
|
|
// 009a8500 A new corner of a HUD, not one of its eight, showing a player.
|
|
std::shared_ptr<PlayerHUD> PlayerHUD::make_ref(HUD* owner, Entity_Player* shown)
|
|
{
|
|
auto corner = std::make_shared<PlayerHUD>();
|
|
|
|
corner->hud = owner;
|
|
corner->playerHudIndex = -1;
|
|
corner->assign(shown);
|
|
return corner;
|
|
}
|