Files
isaac-port/src/hud.h
T

210 lines
6.9 KiB
C++

#pragma once
#include "anm2.h"
#include "font.h"
#include "fx_layers.h"
#include "item_info_hud.h"
#include "kage_graphics.h"
#include "player_hud.h"
#include "rich_text.h"
#include "stat_hud.h"
#include <array>
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
struct RNG;
constexpr int MESSAGE_STACK_COUNT = 6;
constexpr int HISTORY_PLAYER_COUNT = 2;
constexpr float BOSS_BAR_HIDDEN = -1;
constexpr int FLASH_OFF = -1;
constexpr int ONLINE_HUD_OFFLINE = 3;
// How much of the HUD a refresh request redraws. A full request is never downgraded by a lighter one.
enum HudRefresh : int
{
HUD_REFRESH_NONE,
HUD_REFRESH_PLAYER,
HUD_REFRESH_FULL
};
// Whether mark_all_slots_dirty has the recent items HUD rebuild its icons.
enum HistoryRebuild
{
HISTORY_KEEP_ICONS,
HISTORY_REBUILD_ICONS
};
// Whether mark_all_slots_dirty empties the recent items HUD first.
enum HistoryClear
{
HISTORY_KEEP_ITEMS,
HISTORY_CLEAR_ITEMS
};
// Construction (008405b0) and destruction (00840670) are the defaults.
// A banner the HUD shows (stage names, item names, pill names): a streak animation with a title and subtitle drawn into
// a text surface the streak's null 0 places. A text starting with character 1 is rich text drawn with icons.
struct HUD_Message
{
ANM2 streakSprite;
Font font;
Font fontKR;
KColor streakColor = kcolor_rgba(0, 0, 0, 1);
KColor textColor = kcolor_rgba(1, 1, 1, 1);
KAGE::Graphics::ImagePtr textImage;
std::u16string text;
std::u16string subtext;
Vector position{};
float scale = 1;
bool isAutoHide = true;
bool isCurseDisplay = false;
bool isShowing = false;
void load_graphics();
void free_text_buffers();
void set_text_line(std::u16string_view line, int lineIndex);
void Show(const char* title, const char* subtitle, bool isAutoHideOn, bool isCurse);
void text_out();
void Update();
void UpdateTextImage();
void Render(Vector at, float atScale);
static void render_text_image(Font& textFont, std::u16string_view line, Vector at, KColor textColor);
};
// An item of the recent items list, with its icon.
struct HistoryHUDItem
{
KAGE::Graphics::ImagePtr image;
int id = 0;
};
// The recent items of one player and whether they need recomputing.
struct HistoryHUDPlayer
{
std::vector<HistoryHUDItem> items;
Entity_Player* player = nullptr;
bool isDirty = false;
};
// The recent items HUD (REPENTOGON's HistoryHUD) under the minimap, for up to two players.
struct HistoryHUD
{
std::array<HistoryHUDPlayer, HISTORY_PLAYER_COUNT> players{};
bool isComputed = false;
void clear();
void Render(Vector at, bool isMini);
void Recompute(int playerIndex, bool isImmediate);
void RecomputeAll(bool isImmediate);
};
// The online HUD style option in effect, ONLINE_HUD_OFFLINE offline.
int online_hud_mode();
// Construction and destruction (006f2060, 006f23d0) are the defaults.
// The heads-up display of a run (g_game->hud): the player corners, the pickup counters and run icons, the stats,
// recent items and item info panels, the banners, the fortune paper, the co-op join carousel and the boss bar.
class HUD
{
public:
std::array<PlayerHUD, PLAYER_HUD_COUNT> playerHUD{};
std::array<HUD_Message, MESSAGE_STACK_COUNT> messageStack{};
std::array<HUD_Message, MAIN_PLAYER_HUD_COUNT> messagePlayerHUD{};
std::array<Vector, MAIN_PLAYER_HUD_COUNT> cornerOffsets{};
std::array<Vector, PLAYER_HUD_COUNT> playerHudPositions{};
HUD_Message messageMain;
Font font;
Font fontKR;
ANM2 cardsPillsSprite;
ANM2 chargeBarSmallSprite;
ANM2 chargeBarSprite;
ANM2 coopMenuSprite;
ANM2 craftingTableSprite;
ANM2 fortuneSprite;
ANM2 heartsSprite;
ANM2 inventorySprite;
ANM2 pickupHUDSprite;
ANM2 poopSpellsSprite;
ANM2 statsSprite;
StatHUD statHUD;
HistoryHUD historyHUD;
ItemInfoHUD itemInfoHUD;
KAGE::Graphics::ImagePtr bossHealthBarImage;
KAGE::Graphics::ImagePtr bossHealthBarMiniImage;
KAGE::Graphics::ImagePtr bossHealthBarRushImage;
KAGE::Graphics::ImagePtr bossHealthBarStaticImage;
KAGE::Graphics::ImagePtr bossHealthBarStoneImage;
KAGE::Graphics::ImagePtr coopMenuImage;
KAGE::Graphics::ImagePtr fortuneTextImage;
KAGE::Graphics::ImagePtr spiderModHealthBarImage;
float bossBarOffset = 0;
float bossHPBarFill = BOSS_BAR_HIDDEN;
float hudScale = 0;
float minimapOffset = 0;
float statsOffset = 0;
int bossHPBarDamageFlash = FLASH_OFF;
int bossHPBarHealFlash = FLASH_OFF;
int hudRefreshCountdown = 2;
HudRefresh hudRefreshType = HUD_REFRESH_FULL;
int16_t bossCounter = 0;
int16_t bossCounterTotal = 0;
bool isBossBarBottom = false;
bool isGraphicsLoaded = false;
bool isRefreshTick = false;
bool isVisible = true;
void graphics_reload();
void reset();
void LoadGraphics();
void unload_graphics();
void Update();
void PostUpdate();
void refresh_request(HudRefresh type);
void FlashChargeBar(Entity_Player* player, int activeSlot);
void InvalidateActiveItem(Entity_Player* player, int activeSlot);
void InvalidateCraftingItem(Entity_Player* player);
void mark_all_slots_dirty(HistoryRebuild rebuild, HistoryClear clearing);
void SetVisible(bool isShown);
bool IsVisible();
void ShowItemText(Entity_Player* player, ItemConfig_Item* item);
void ShowStackedItemTextCustom(const char* title, const char* subtitle);
static int lua_show_item_text(void* luaState);
void show_pill_name(Entity_Player* player, const char* title, const char* subtitle);
void ShowFortuneText(const std::vector<std::string>& lines);
void show_fortune_line(const char* text);
void show_fortune_text_impl(const char* text);
void render_fortune_text(const std::vector<std::string>& lines);
void Render();
void render_counters(Vector& cursor, Vector shake);
void render_run_icons(Vector& cursor, Vector shake, float& statsX);
void render_coop_carousel();
void render_streak_texts();
void render_player_hud(int playerHudIndex, PlayerHudLayout layout);
void render_player_net_status(int playerHudIndex, Vector at);
void render_boss_health_bar(Vector barPos);
static void render_modded_coop_portrait(int playerType, Vector at, Vector portraitScale, const ColorMod& color);
void update_hud_offset();
Vector get_player_hud_position(int hudIndex, PlayerHudLayout layout);
int GetPlayerHudIndex(Entity_Player* player);
PlayerHudLayout GetPlayerHUDLayout(int playerHudIndex, Entity_Player* player);
int count_player_huds();
void AssignPlayerHUDs();
};
// The stringtable categories a fortune is drawn from.
constexpr std::string_view FORTUNE_GENERAL = "Fortune_General";
constexpr std::string_view FORTUNE_SEEDS = "Fortune_Seeds";
constexpr std::string_view FORTUNE_RULES = "Fortune_Rules";
void fortune_text_show(RNG& rng, std::string_view category);
void fortune_show(std::string_view category);