Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

Hollow Knight: inventory and charms

Mason Chen119b0d3a44b2
diff --git a/games/hollowknight/Makefile b/games/hollowknight/Makefile
index ef6c880e..efc2e8de 100644
--- a/games/hollowknight/Makefile
+++ b/games/hollowknight/Makefile
@@ -9,7 +9,7 @@ CC = arm-none-eabi-gcc
NWLINK ?= npx --yes -- [email protected]
STRIP ?= arm-none-eabi-strip --strip-unneeded
BUILD_DIR = output
-GAME = src/res.c src/tex.c src/room.c src/gfx.c src/phys.c src/anim.c src/hero.c src/camera.c src/game.c src/world.c src/obj.c src/enemy.c src/hud.c src/spell.c src/text.c src/npc.c src/title.c src/vm.c src/msg.c src/save.c src/death.c src/menu.c src/lzma/LzmaDec.c
+GAME = src/res.c src/tex.c src/room.c src/gfx.c src/phys.c src/anim.c src/hero.c src/camera.c src/game.c src/world.c src/obj.c src/enemy.c src/hud.c src/spell.c src/text.c src/npc.c src/title.c src/vm.c src/msg.c src/save.c src/death.c src/menu.c src/inv.c src/lzma/LzmaDec.c
SRC = $(GAME) src/plat_eadk.c src/main.c
HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index 59fd916d..51470264 100644
Binary files a/games/hollowknight/src/data.bin and b/games/hollowknight/src/data.bin differ
diff --git a/games/hollowknight/src/data.h b/games/hollowknight/src/data.h
index 236e4bc6..eea6b90d 100644
--- a/games/hollowknight/src/data.h
+++ b/games/hollowknight/src/data.h
@@ -567,7 +567,7 @@
#define SPRITE_CORPSE_NAIL 2234
#define SPRITE_FK_BARREL 2235
#define SPRITE_FK_STAFF 2236
-#define SPRITE_DIGIT0 2481
+#define SPRITE_DIGIT0 2524
#define STYLE_DIALOGUE 0
#define STYLE_PROMPT 1
#define STYLE_TITLE_L 2
@@ -812,6 +812,7 @@
#define TUTE_IMAGE {2248, 1.0000f, 1.0000f}
#define TUTE_STOP {2240, 1.0000f, 1.0000f}
#define NOTICE_ICONS {2249, 2250, 2251}
+#define CHARM_ICON_K 1.5000f
#define CHARM_ICONS {-1, 2252, 2253, 2254, 2255, -1, 2256, 2257, 2258, -1, -1, -1, -1, -1, 2259, -1, -1, -1, 2260, 2261, 2262, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
#define CHARM_NAMES {-1, 122, 123, 124, 125, -1, 126, 127, 128, -1, -1, -1, -1, -1, 129, -1, -1, -1, 130, 131, 132, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
#define TXT_CHARM_TUTE_TITLE 133
@@ -884,6 +885,90 @@
#define TXT_PROFILE_CORRUPTED 146
#define TXT_SCREEN_SAVE_PROFILES 147
#define TXT_ZONES {148, 149, 150, 151, 152}
+#define INV_X -4.0500f
+#define INV_Y 7.5500f
+#define INV_BORDER {{2279, -8.0000f, -2.8100f, 1.0000f, 1.0000f}, {2279, 16.1400f, -2.8100f, -1.0000f, 1.0000f}, {2280, -8.0000f, -12.8700f, 0.9877f, -1.0000f}, {2281, 16.2400f, -12.8700f, -1.0000f, -1.0000f}, {2282, 3.9400f, -0.6200f, 1.0000f, 1.0000f}, {2283, 4.0000f, -14.3600f, 1.0000f, 1.0000f}}
+#define INV_NBORDER 6
+#define INV_FRAME {2284, 4.0479f, -7.1963f, 1.0f, 1.0f}
+#define INV_ARROW_L {2285, -9.8300f, -7.2000f, 1.0000f, 1.0000f}
+#define INV_ARROW_R {2285, 18.0300f, -7.2000f, -1.0000f, 1.0000f}
+#define INV_PANE_ARROW_L {2286, -9.8600f, -0.4300f, -1.0000f, 1.0000f}
+#define INV_PANE_ARROW_R {2286, 18.0400f, -0.4300f, 1.0000f, 1.0000f}
+#define INV_PANE_NAME {3.9500f, -0.0745f, 8.3290f}
+#define INV_PANE_NAME_L {-9.4745f, -0.0646f, 8.3290f}
+#define INV_PANE_NAME_R {17.6945f, -0.0646f, 8.3290f}
+#define TXT_INV_PANES {155, 156, 157, 158}
+#define CH_BB {2287, -7.9200f, -8.3700f, 1.0000f, 1.0000f}
+#define CH_BB_POS {{-7.9200f, -8.3700f}, {-6.4200f, -8.3700f}, {-4.9200f, -8.3400f}, {-3.4200f, -8.3400f}, {-1.9200f, -8.3400f}, {-0.4200f, -8.3400f}, {1.0800f, -8.3400f}, {2.5800f, -8.3400f}, {4.0800f, -8.3400f}, {5.5800f, -8.3400f}, {-7.0100f, -9.7900f}, {-5.5100f, -9.7900f}, {-4.0100f, -9.7900f}, {-2.5100f, -9.7900f}, {-1.0100f, -9.7900f}, {0.4900f, -9.7900f}, {1.9900f, -9.7900f}, {3.4900f, -9.7900f}, {4.9900f, -9.7900f}, {6.4900f, -9.7900f}, {-7.9200f, -11.2600f}, {-6.4200f, -11.2600f}, {-4.9200f, -11.2600f}, {-3.4200f, -11.2600f}, {-1.9200f, -11.2600f}, {-0.4200f, -11.2600f}, {1.0800f, -11.2600f}, {2.5800f, -11.2600f}, {4.0800f, -11.2600f}, {5.5800f, -11.2600f}, {-7.0100f, -12.7200f}, {-5.5100f, -12.7200f}, {-4.0100f, -12.7200f}, {-2.5100f, -12.7200f}, {-1.0100f, -12.7200f}, {0.4900f, -12.7200f}, {1.9900f, -12.7200f}, {3.4900f, -12.7200f}, {4.9900f, -12.7200f}, {6.4900f, -12.7200f}}
+#define CH_BB_BOX {1.5002f, 1.4969f, -0.0257f, 0.0685f}
+#define CH_BB_CHARM {2, 1, 4, 20, 19, 21, 31, 37, 3, 35, 23, 24, 25, 33, 14, 15, 32, 18, 13, 6, 12, 5, 11, 10, 22, 7, 34, 8, 9, 27, 29, 17, 16, 28, 26, 39, 30, 38, 40, 36}
+#define CH_GLOW {2288, 0.0500f, 0.0600f, 1.0000f, 0.9919f}
+#define CH_GLOW_A 0.6970f
+#define CH_ICONS {-1, 2252, 2253, 2254, 2255, -1, 2256, 2257, 2258, -1, -1, -1, -1, -1, 2259, -1, -1, -1, 2260, 2261, 2262, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
+#define CH_NEXT_DOT {2289, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define CH_NEXT_DOT_BOX {1.2143f, 1.2736f, -0.0209f, 0.0123f}
+#define CH_EQ_BOX {1.4950f, 1.4950f, 0.0000f, 0.0000f}
+#define CH_TEXT_EQUIPPED {-8.1273f, -2.0957f, 5.4345f}
+#define CH_NOTCH_FULL {2290, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define CH_NOTCH_EMPTY {2291, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define CH_NOTCH_X -7.8000f
+#define CH_NOTCH_Y -6.1600f
+#define CH_NOTCH_DX 0.8100f
+#define CH_NOTCH_FULL_RGB {255, 216, 0}
+#define CH_NOTCH_OVER_RGB {255, 36, 67}
+#define CH_TEXT_NOTCHES {-8.0272f, -5.0757f, 5.4345f}
+#define CH_DIVIDER {2292, -0.8400f, -6.9300f, 1.0000f, 0.1591f}
+#define CH_COST_TEXT {10.7172f, -3.3457f, 5.4345f}
+#define CH_COST_PIP {2290, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define CH_COST_X 11.2300f
+#define CH_COST_Y -3.6600f
+#define CH_COST_DX 0.7500f
+#define CH_DETAIL_X 12.5100f
+#define CH_DETAIL_Y -5.5900f
+#define CH_NAME {12.4800f, -2.2710f, 8.8867f}
+#define CH_DESC {8.0382f, -7.3673f, 8.8867f}
+#define CH_CONFIRM {15.7465f, -13.0221f, 15.3500f}
+#define CH_CONFIRM_KEY {2293, 16.3208f, -13.2878f, 1.0f, 1.0f}
+#define CH_CONFIRM_KEY_W 0.6412f
+#define CH_CURSOR {2294, 0.0000f, 0.0000f, 1.0000f, 0.9756f}
+#define CH_CURSOR_K {1.0720f, 1.0458f}
+#define CH_CURSOR_CORNERS {{1.0000f, 1.0000f}, {-1.1000f, 1.0000f}, {1.0000f, -1.0089f}, {-1.1000f, -1.0089f}}
+#define TXT_CHARM_TXT_EQUIPPED 159
+#define TXT_CHARM_TXT_OVERCHARMED 160
+#define TXT_CHARM_TXT_COST 161
+#define TXT_CTRL_EQUIP 162
+#define TXT_CTRL_UNEQUIP 163
+#define TXT_CHARM_ALERT_NONE 164
+#define TXT_CHARM_ALERT_NONE_BENCH 165
+#define TXT_CHARM_NOTCHES 166
+#define TXT_CHARM_NAMES_INV {-1, 167, 168, 169, 170, -1, 171, 172, 173, -1, -1, -1, -1, -1, 174, -1, -1, -1, 175, 176, 177, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
+#define TXT_CHARM_DESCS {-1, 178, 179, 180, 181, -1, 182, 183, 184, -1, -1, -1, -1, -1, 185, -1, -1, -1, 186, 187, 188, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
+#define TXT_KEY_OK 189
+#define INV_FIXED {{2295, -7.1600f, -3.8300f, 1.0000f, 1.0000f}, {2296, -3.2500f, -4.2100f, 1.0000f, 1.0000f}, {2297, -7.2900f, -9.4400f, 1.0000f, 1.0000f}, {2298, -4.7200f, -6.2100f, 1.0000f, 1.0000f}, {2299, -3.2700f, -7.4600f, 1.0000f, 1.0000f}, {2300, -5.7200f, -13.3200f, 1.0000f, 1.0000f}}
+#define INV_FIXED_BG {{-1, 0, 0, 0, 0}, {-1, 0, 0, 0, 0}, {-1, 0, 0, 0, 0}, {2301, -4.6374f, -6.2413f, 1.0000f, 1.0000f}, {2302, -3.2774f, -7.4713f, 1.0000f, 1.0000f}, {-1, 0, 0, 0, 0}}
+#define INV_FIXED_BOX {{1.9363f, 2.9287f, -0.0651f, 0.0923f}, {1.4420f, 1.4140f, -0.0546f, 0.0682f}, {1.6244f, 5.3245f, 0.0126f, 0.1884f}, {1.7500f, 1.7500f, 0.0000f, 0.0000f}, {1.8505f, 1.8756f, -0.0503f, 0.0629f}, {7.8215f, 1.4409f, 1.7816f, -0.0205f}}
+#define INV_HEART_PIECES {{2303, -7.1460f, -3.5360f, 1.0000f, 1.0000f}, {2304, -7.1460f, -3.5360f, 1.0000f, 1.0000f}, {2305, -7.1460f, -3.5360f, 1.0000f, 1.0000f}, {2306, -7.1460f, -3.5360f, 1.0000f, 1.0000f}}
+#define INV_VESSEL_PIECES {{2307, -3.5860f, -4.3220f, 1.0000f, 1.0000f}, {2308, -3.2892f, -4.3556f, 1.0000f, 1.0000f}, {2309, -3.2500f, -4.1540f, 1.0000f, 1.0000f}}
+#define INV_GEO_TEXT {-4.8612f, -12.9979f, 1.6942f}
+#define INV_EQ_X 1.1000f
+#define INV_EQ_Y -3.8000f
+#define INV_EQ_DX 2.0800f
+#define INV_EQ_DY -2.1800f
+#define INV_EQ {{2310, 1.1000f, -3.8000f, 1.0000f, 1.0000f}, {2311, 1.1000f, -3.8000f, 1.0000f, 1.0000f}, {2312, 1.1300f, -3.8000f, 1.0000f, 1.0000f}, {2313, 1.1300f, -3.8000f, 1.0000f, 1.0000f}, {2314, 1.1300f, -3.8000f, 1.0000f, 1.0000f}, {2315, 1.1300f, -3.8000f, 1.0000f, 1.0000f}}
+#define INV_EQ_BOX {{1.4420f, 1.4140f, 0.0000f, 0.0000f}, {1.4420f, 1.4140f, 0.0000f, 0.0000f}, {1.4420f, 1.4140f, 0.0000f, 0.0000f}, {1.4420f, 1.4140f, 0.0000f, 0.0000f}, {1.4420f, 1.4140f, 0.0000f, 0.0000f}, {1.4420f, 1.4140f, 0.0000f, 0.0000f}}
+#define INV_TRINKETS {{2316, 1.1000f, -10.7400f, 1.0000f, 1.0000f}, {2317, 3.1800f, -10.7400f, 1.0000f, 1.0000f}, {2318, 5.2600f, -10.7400f, 1.0000f, 1.0000f}, {2319, 7.4000f, -10.7800f, 1.0000f, 1.0000f}}
+#define INV_TRINKET_BOX {{1.3970f, 1.7141f, 0.0000f, -0.1535f}, {1.3970f, 1.7141f, 0.0000f, -0.1535f}, {1.3970f, 1.7141f, 0.0000f, -0.1535f}, {1.2162f, 1.5101f, -0.0416f, -0.0832f}}
+#define INV_TRINKET_TEXT {0.3740f, -0.2538f, 1.3871f}
+#define INV_TRINKET_BB {2320, 4.2400f, -10.8700f, 1.0000f, 1.0000f}
+#define INV_DIVIDERS {{2321, -0.1800f, -7.5100f, 1.0000f, 0.2443f, -90.0000f}, {2321, 8.7300f, -7.5100f, 1.0000f, 0.2443f, -90.0000f}}
+#define INV_NAME {12.9500f, -1.9345f, 8.3290f}
+#define INV_DESC {9.2144f, -3.1678f, 7.6475f}
+#define TXT_INV_HEART {{190, 191}, {192, 193}, {194, 195}, {192, 196}, {192, 197}, {198, 199}}
+#define TXT_INV_VESSEL {{190, 191}, {200, 201}, {202, 203}, {200, 204}, {205, 206}}
+#define TXT_INV_FIXED {{207, 208}, {209, 210}, {211, 212}, {213, 214}}
+#define TXT_INV_EQ {{215, 216}, {217, 218}, {219, 220}, {221, 222}, {223, 224}, {225, 226}}
+#define TXT_INV_QUILL {227, 228, 229, 230}
+#define TXT_INV_TRINKETS {{231, 232}, {233, 234}, {235, 236}, {237, 238}}
#define ROOM_ZONES {2, 4, 5, 4, 4, 5, 5, 5, 5, 5, 5, 5, 22, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
#define MSG_FIREBALL 0
#define MSG_DASH 1
diff --git a/games/hollowknight/src/death.c b/games/hollowknight/src/death.c
index c27f60a4..076694d3 100644
--- a/games/hollowknight/src/death.c
+++ b/games/hollowknight/src/death.c
@@ -1,5 +1,6 @@
/* The Knight's death: his Hero Death object (the Hero Death Anim FSM: his body bursting, soul and geo lost, a shade
* left where he fell), GameManager.PlayerDead (the save, the fade), then the respawn at his bench. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
diff --git a/games/hollowknight/src/enemy.c b/games/hollowknight/src/enemy.c
index 501c4fc8..430b9b46 100644
--- a/games/hollowknight/src/enemy.c
+++ b/games/hollowknight/src/enemy.c
@@ -1,5 +1,6 @@
/* Enemies (tools/ents.py: OK_ENEMY): HealthManager, Recoil, SpriteFlash, DamageHero and EnemyDeathEffects, each kind's
* FSM, the corpses they leave and the geo they drop. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
#ifdef HOST
diff --git a/games/hollowknight/src/game.c b/games/hollowknight/src/game.c
index 0d031c11..335a2812 100644
--- a/games/hollowknight/src/game.c
+++ b/games/hollowknight/src/game.c
@@ -27,6 +27,7 @@ void game_new(void) {
strcpy(g_pd.respawn_marker, "Death Respawn Marker");
dialogue_reset();
prompts_reset();
+ inv_reset();
death_reset();
white_blanker_reset();
}
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index 9f141378..d73a04f6 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -31,6 +31,7 @@ enum {
PDF_EQUIPPED_CHARM_26, PDF_EQUIPPED_CHARM_27, PDF_EQUIPPED_CHARM_28, PDF_EQUIPPED_CHARM_29, PDF_EQUIPPED_CHARM_30,
PDF_EQUIPPED_CHARM_31, PDF_EQUIPPED_CHARM_32, PDF_EQUIPPED_CHARM_33, PDF_EQUIPPED_CHARM_34, PDF_EQUIPPED_CHARM_35,
PDF_EQUIPPED_CHARM_36, PDF_EQUIPPED_CHARM_37, PDF_EQUIPPED_CHARM_38, PDF_EQUIPPED_CHARM_39, PDF_EQUIPPED_CHARM_40,
+ PDF_OVERCHARMED, PDF_CAN_OVERCHARM, PDF_HAS_LANTERN, PDF_HEART_PIECE_COLLECTED, PDF_VESSEL_FRAGMENT_COLLECTED,
PDF_COUNT
};
typedef struct {
@@ -58,7 +59,11 @@ typedef struct {
uint8_t charms_owned; /* (charmsOwned) */
uint8_t trinkets[4]; /* (trinket1 .. 4: Wanderer's Journals, Hallownest Seals, King's Idols, Arcane Eggs) */
uint8_t rancid_eggs, ore;
- uint8_t reserved[51];
+ uint8_t charm_slots_filled; /* (charmSlotsFilled: the notches the equipped charms take) */
+ uint8_t heart_pieces, vessel_fragments, simple_keys;
+ uint8_t equipped[12]; /* (equippedCharms: in the order they were equipped; 0 ends it) */
+ uint8_t current_inv_pane; /* (currentInvPane) */
+ uint8_t reserved[34];
/* (saved apart, by the objects' names: their states) */
uint8_t persist[MAX_PERSIST / 8];
/* (not saved) */
@@ -275,6 +280,8 @@ void hero_late_update(void); /* (HeroBox.LateUpdate: a buffered hit) *
void hero_soul_gain(void); /* a nail's hit on an enemy */
void hero_add_health(int amount);
void hero_relinquish_control(void); /* RelinquishControl, RegainControl */
+void hero_relinquish_control_not_velocity(void);
+void hero_charm_update(void); /* CharmUpdate */
void hero_regain_control(void);
void hero_stop_anim_control(void); /* StopAnimationControl, StartAnimationControl */
void hero_start_anim_control(void);
@@ -331,6 +338,7 @@ void notice_show(int text); /* a relic's notice: its icon, its name */
void charm_notice(int id); /* a charm's (in the tutorial, as it is made: its charm) */
void charm_tute(void);
void charm_tute_close(void);
+void notices_close(void); /* (DESTROY JOURNAL MSG: the inventory opens)*/
bool bench_respawn(const char *name); /* RESPAWN: the Knight asleep on the bench so named */
/* the Spell Control FSM (spell.c): focus, spells */
@@ -367,6 +375,14 @@ void menu_start(void);
bool menu_tick(uint32_t keys); /* -> the game kept from ticking (a menu is up) */
void menu_draw(void);
bool menu_in_game(void);
+/* the inventory (inv.c): opened with its key; the world goes on behind it */
+void inv_reset(void);
+uint32_t inv_tick(uint32_t keys); /* -> the keys the game has (none while it is open) */
+void inv_damage(void); /* (HERO DAMAGED: it closes) */
+bool inv_open(void);
+float text_box(int text, int style, float x, float y, float w, int align, float a);
+int charm_cost(int id); /* (charmCost_N) */
+bool charm_equipped(int id);
bool menu_quit(void);
/* ---------------------------------------------------------------- text (text.c) */
diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.c
index 1ceeeaf4..a85c2d17 100644
--- a/games/hollowknight/src/gfx.c
+++ b/games/hollowknight/src/gfx.c
@@ -1219,6 +1219,7 @@ bool gfx_actor(const Inst *in, uint32_t group) {
return true;
}
+static bool overlay_on; /* (the overlay's instances: the room kept back to leave them room, g_gfx_reserve) */
static bool add_item(const Inst *in, float blur_z) {
Item cur;
cur.in = *in;
@@ -1233,7 +1234,7 @@ static bool add_item(const Inst *in, float blur_z) {
draw_bg_item(&cur);
return false;
}
- if (nitems >= MAX_ITEMS) {
+ if (nitems >= MAX_ITEMS - (overlay_on ? 0 : g_gfx_reserve)) {
g_gfx_dropped++; /* (never in the game's rooms: checked by tests) */
return false;
}
@@ -1243,6 +1244,25 @@ static bool add_item(const Inst *in, float blur_z) {
}
bool g_gfx_no_room;
+void (*g_gfx_overlay)(void);
+int g_gfx_reserve;
+
+/* the overlay's (as the HUD's, straight into the frame's instances: as many as there is room for) */
+bool gfx_overlay(const Inst *src) {
+ Inst in = *src;
+ in.ax = (int16_t)(in.ax + (int)lrintf(g_cam_x * 64)), in.ay = (int16_t)(in.ay + (int)lrintf(g_cam_y * 64));
+ in.z = (int16_t)lrintf(HUD_Z * 128);
+ return add_item(&in, 1e9f);
+}
+
+void gfx_overlay_fill(float x0, float y0, float x1, float y1, uint8_t tint) {
+ Inst in;
+ memset(&in, 0, sizeof in);
+ in.ax = (int16_t)lrintf(x0 * 64), in.ay = (int16_t)lrintf(y1 * 64);
+ in.tex = TEX_NONE, in.flags = F_SOLID, in.tint = tint;
+ in.a = to_f16(x1 - x0), in.b = to_f16(y0 - y1);
+ gfx_overlay(&in);
+}
void gfx_frame(void) {
bool roomless = g_room.h == NULL || g_gfx_no_room; /* (the title screen: the HUD's alone) */
@@ -1278,6 +1298,7 @@ void gfx_frame(void) {
if (add_item(&in, 1e9f)) items[nitems - 1].clip = hud_clip_of[i];
}
nhud = 0;
+ if (g_gfx_overlay) overlay_on = true, g_gfx_overlay(), overlay_on = false;
g_gfx_items = (uint32_t)nitems;
if (!strip_ready) {
memset(arb, 0, sizeof arb), memset(ag, 0, sizeof ag), memset(trans, 255, sizeof trans);
diff --git a/games/hollowknight/src/hero.c b/games/hollowknight/src/hero.c
index 4cd5aa06..18882421 100644
--- a/games/hollowknight/src/hero.c
+++ b/games/hollowknight/src/hero.c
@@ -1258,6 +1258,7 @@ void hero_take_damage(int side, int damage, int hazard) {
if (can_take_damage()) {
spell_cancel(); /* (HERO DAMAGED) */
vm_broadcast(VMEV_HERO_DAMAGED);
+ inv_damage();
if (h->damage_mode == DAMAGE_HAZARD_ONLY && hazard == HAZ_NORMAL) return;
cancel_attack();
if (h->cs.recoiling_left || h->cs.recoiling_right) cancel_recoil_horizontal();
@@ -1431,6 +1432,21 @@ void hero_relinquish_control(void) {
h->touching_wall_l = h->touching_wall_r = false;
}
+/* RelinquishControlNotVelocity: as RelinquishControl, its velocity kept */
+void hero_relinquish_control_not_velocity(void) {
+ Hero *h = &g_hero;
+ if (h->control_relinquished || h->cs.dead) return;
+ reset_input();
+ h->accepting_input = false;
+ h->control_relinquished = true;
+ reset_look();
+ reset_attacks();
+ h->touching_wall_l = h->touching_wall_r = false;
+}
+
+/* CharmUpdate: the Knight as his charms make him (charm effects: hero.c's own as they are read) */
+void hero_charm_update(void) {}
+
void hero_regain_control(void) {
Hero *h = &g_hero;
h->accepting_input = true;
diff --git a/games/hollowknight/src/hk.h b/games/hollowknight/src/hk.h
index ba59ecc3..2ea49090 100644
--- a/games/hollowknight/src/hk.h
+++ b/games/hollowknight/src/hk.h
@@ -215,6 +215,12 @@ uint8_t gfx_dyn_tint(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*
uint8_t gfx_dyn_flash(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t fr, uint8_t fg, uint8_t fb, uint8_t amount);
extern uint8_t g_screen_fade; /* 0 .. 255: the screen faded to black */
extern bool g_gfx_no_room; /* (the room not drawn: the menus') */
+/* an overlay over the HUD (the inventory): drawn by g_gfx_overlay as the frame is made, its instances (HUD units)
+ * straight into the frame's; g_gfx_reserve of them kept from the room's */
+extern void (*g_gfx_overlay)(void);
+extern int g_gfx_reserve;
+bool gfx_overlay(const Inst *in);
+void gfx_overlay_fill(float x0, float y0, float x1, float y1, uint8_t tint);
/* a line of text (n glyphs of a style), its pen starting at (x, y) on the baseline (view pixels), of a color (0xAARRGGBB);
* layer 0: the HUD's (in front of all), 1: the room's (in front of it, behind the HUD and the fade) */
bool gfx_text(int style, float x, float y, const uint8_t *s, int n, uint32_t argb, int layer);
diff --git a/games/hollowknight/src/inv.c b/games/hollowknight/src/inv.c
new file mode 100644
index 00000000..716cb829
--- /dev/null
+++ b/games/hollowknight/src/inv.c
@@ -0,0 +1,758 @@
+/* The inventory (Inventory Control): opened with the inventory key when the Knight can be stopped, or at a bench;
+ * the world goes on behind it (the game's frozen, blurred screen: here the world dimmed) and a hit closes it. Its
+ * panes: Inventory (UI Inventory: what the Knight has), Charms (UI Charms: the charms, equipped at a bench), side by
+ * side; the cursor goes from one to the next through the arrows at their sides. Places in HUD units: the border's
+ * from the inventory's place, a pane's from its own (tools/inv.py). */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
+#include <math.h>
+#include "game.h"
+
+#define DT 0.02f
+#define HUD_PX (FOCAL / (-1.342f - CAM_Z))
+#define FADE 0.2f /* (FadeGroup: up and down) */
+#define SLIDE 0.35f /* (Tween Panes: the panes 31 apart) */
+#define PANE_W 31.0f
+#define CURSOR_TIME 0.15f /* (Cursor Movement) */
+#define TWEEN_TIME 0.25f /* (a charm to its notch and back: iTweenMoveTo, easeOutSine) */
+#define DIM 0.75f /* (the screen behind it, darkened) */
+#define REPEAT_FIRST 0.4f /* (ui_list_getinput: a held direction again after this, then each REPEAT) */
+#define REPEAT 0.1f
+#define RESERVE 140 /* (the frame's instances kept for it) */
+
+typedef struct {
+ int16_t sprite;
+ float x, y, kx, ky;
+} Piece;
+typedef struct {
+ int16_t sprite;
+ float x, y, kx, ky, deg;
+} TurnedPiece;
+typedef struct {
+ float x, top, w; /* (a text: x its left, center or right as it is aligned) */
+} TextAt;
+typedef struct {
+ float w, h, ox, oy; /* (a collider: its size and offset, as the world has them) */
+} Box;
+typedef struct {
+ int16_t name, desc;
+} NameDesc;
+
+static const Piece border[INV_NBORDER] = INV_BORDER, frame = INV_FRAME, arrow_l = INV_ARROW_L, arrow_r = INV_ARROW_R,
+ pane_arrow_l = INV_PANE_ARROW_L, pane_arrow_r = INV_PANE_ARROW_R;
+static const TextAt pane_name = INV_PANE_NAME, pane_name_l = INV_PANE_NAME_L, pane_name_r = INV_PANE_NAME_R;
+static const int16_t pane_names[4] = TXT_INV_PANES;
+
+/* the Charms pane */
+static const Piece ch_bb = CH_BB, ch_glow = CH_GLOW, ch_next_dot = CH_NEXT_DOT, ch_notch_full = CH_NOTCH_FULL,
+ ch_notch_empty = CH_NOTCH_EMPTY, ch_divider = CH_DIVIDER, ch_cost_pip = CH_COST_PIP,
+ ch_key = CH_CONFIRM_KEY, ch_cursor = CH_CURSOR;
+static const float ch_bb_pos[40][2] = CH_BB_POS;
+static const uint8_t ch_bb_charm[40] = CH_BB_CHARM;
+static const Box ch_bb_box = CH_BB_BOX, ch_eq_box = CH_EQ_BOX, ch_next_box = CH_NEXT_DOT_BOX;
+static const int16_t ch_icons[41] = CH_ICONS, ch_names[41] = TXT_CHARM_NAMES_INV, ch_descs[41] = TXT_CHARM_DESCS;
+static const TextAt ch_text_equipped = CH_TEXT_EQUIPPED, ch_text_notches = CH_TEXT_NOTCHES, ch_cost_text = CH_COST_TEXT,
+ ch_name = CH_NAME, ch_desc = CH_DESC, ch_confirm = CH_CONFIRM;
+static const float ch_cursor_k[2] = CH_CURSOR_K, ch_corners[4][2] = CH_CURSOR_CORNERS;
+static const uint8_t notch_full_rgb[3] = CH_NOTCH_FULL_RGB, notch_over_rgb[3] = CH_NOTCH_OVER_RGB;
+/* (BuildEquippedCharms: the equipped row) */
+#define EQ_X (-7.28f)
+#define EQ_Y (-3.86f)
+#define EQ_SCALE 1.15f
+#define DETAIL_SCALE 1.5f
+
+/* the Inventory pane: its fixed items (Mask Shards, Soul Vessel, the nail, Vengeful Spirit, Focus, Geo), the
+ * equipment after them (Build Equipment List: four to a row), the relics below */
+enum { IT_HEART, IT_VESSEL, IT_NAIL, IT_FIREBALL, IT_FOCUS, IT_GEO, NFIXED };
+static const Piece inv_fixed[NFIXED] = INV_FIXED, inv_fixed_bg[NFIXED] = INV_FIXED_BG, inv_heart[4] = INV_HEART_PIECES,
+ inv_vessel[3] = INV_VESSEL_PIECES, inv_eq[] = INV_EQ, inv_trinkets[4] = INV_TRINKETS,
+ inv_trinket_bb = INV_TRINKET_BB;
+static const TurnedPiece inv_dividers[2] = INV_DIVIDERS;
+static const Box inv_fixed_box[NFIXED] = INV_FIXED_BOX, inv_eq_box[] = INV_EQ_BOX, inv_trinket_box[4] = INV_TRINKET_BOX;
+static const TextAt inv_name = INV_NAME, inv_desc = INV_DESC, inv_geo_text = INV_GEO_TEXT, inv_trinket_text = INV_TRINKET_TEXT;
+static const NameDesc txt_heart[6] = TXT_INV_HEART, txt_vessel[5] = TXT_INV_VESSEL, txt_fixed[4] = TXT_INV_FIXED,
+ txt_eq[] = TXT_INV_EQ, txt_trinkets[4] = TXT_INV_TRINKETS;
+static const int16_t txt_quill[4] = TXT_INV_QUILL;
+#define NEQ ((int)(sizeof inv_eq / sizeof inv_eq[0]))
+enum { EQ_DASH, EQ_LANTERN, EQ_MAP, EQ_CITY_KEY, EQ_SIMPLE_KEY, EQ_RANCID_EGG };
+
+/* (charmCost_N, as PlayerData starts) */
+static const uint8_t costs[41] = {[1] = 1, [2] = 1, [3] = 1, [4] = 2, [6] = 2, [7] = 3, [8] = 2, [14] = 1, [18] = 2,
+ [19] = 3, [20] = 2};
+int charm_cost(int id) { return id > 0 && id <= 40 ? costs[id] : 0; }
+bool charm_equipped(int id) { return id > 0 && id <= 40 && pd_flag(PDF_EQUIPPED_CHARM_1 + id - 1); }
+static bool charm_got(int id) { return id > 0 && id <= 40 && pd_flag(PDF_GOT_CHARM_1 + id - 1) && ch_icons[id] >= 0; }
+
+enum { IV_CLOSED, IV_OPEN, IV_CLOSING };
+enum { P_INV, P_CHARMS, P_JOURNAL, P_MAP, NPANES };
+/* the Charms pane's places for the cursor: the collection, the equipped row, the arrows; its charm's moves */
+enum { CA_COLLECTION, CA_EQUIPPED, CA_ARROW_L, CA_ARROW_R };
+enum { TW_NONE, TW_UP, TW_DOWN, TW_FAIL, TW_FAIL_BACK };
+#define MAX_INV_ITEMS (NFIXED + 6 + 4)
+
+static struct {
+ uint8_t st, pane, prev_pane;
+ float t; /* (closing: its time) */
+ float border_a, pane_a;
+ float slide_t; /* (panes moving: time so far; -1 none) */
+ int8_t slide_dir;
+ /* input */
+ uint32_t prev_keys, held, blocked; /* (blocked: keys held as it closed, the game's again once let go) */
+ float held_t;
+ /* the cursor: where it is (x, y, half width, half height), where from, where to; its time */
+ float cur[4], cfrom[4], cto[4], ct;
+ bool cursor_set;
+ /* Charms */
+ uint8_t area, coll, eq; /* (the collection: a backboard 1..40; the equipped row: 1.. its items) */
+ uint8_t tween, tw_charm, oc_attempts;
+ float tw_t, tw_from[2], tw_to[2];
+ /* Inventory: its items shown (their kinds), the one selected (-1, -2: the arrows) */
+ uint8_t items[MAX_INV_ITEMS];
+ float item_xy[MAX_INV_ITEMS][2];
+ int nitems;
+ int8_t sel;
+} iv;
+
+bool inv_open(void) { return iv.st != IV_CLOSED; }
+
+static bool has_pane(int p) {
+ return p == P_INV || (p == P_CHARMS && pd_flag(PDF_HAS_CHARM));
+}
+
+/* ---------------------------------------------------------------- the Knight's charms */
+static int equipped_count(void) {
+ int n = 0;
+ while (n < (int)sizeof g_pd.equipped && g_pd.equipped[n]) n++;
+ return n;
+}
+
+static void equip(int id) {
+ int n = equipped_count();
+ if (n < (int)sizeof g_pd.equipped) g_pd.equipped[n] = (uint8_t)id;
+ pd_set_flag(PDF_EQUIPPED_CHARM_1 + id - 1, true);
+}
+
+static void unequip(int id) {
+ int n = equipped_count(), j = 0;
+ for (int i = 0; i < n; i++)
+ if (g_pd.equipped[i] != id) g_pd.equipped[j++] = g_pd.equipped[i];
+ while (j < n) g_pd.equipped[j++] = 0;
+ pd_set_flag(PDF_EQUIPPED_CHARM_1 + id - 1, false);
+}
+
+/* ---------------------------------------------------------------- places */
+static float pane_x(int p) {
+ /* (the current pane at 0; while they move, the one coming from a side, the one going to the other) */
+ if (iv.slide_t < 0) return 0;
+ float q = iv.slide_t / SLIDE;
+ float e = sinf((q > 1 ? 1 : q) * 1.5707964f); /* (easeOutSine) */
+ if (p == iv.pane) return iv.slide_dir * PANE_W * (1 - e);
+ return -iv.slide_dir * PANE_W * e;
+}
+
+/* the equipped row's n-th place (1..), and the next dot's (n = count + 1) */
+static float eq_dx(void) {
+ int n = equipped_count();
+ return n < 9 ? 1.76f : n == 9 ? 1.7f : n == 10 ? 1.5f : 1.4f;
+}
+static void eq_pos(int n, float *x, float *y) { *x = EQ_X + (n - 1) * eq_dx(), *y = EQ_Y; }
+
+static int bb_of_charm(int id) {
+ for (int i = 0; i < 40; i++)
+ if (ch_bb_charm[i] == id) return i + 1;
+ return 1;
+}
+
+/* the cursor to a place: its center, its box */
+static void cursor_to(float x, float y, const Box *b, float kx, float ky) {
+ float to[4] = {x + b->ox * kx, y + b->oy * ky, b->w * kx / 2, b->h * ky / 2};
+ if (!iv.cursor_set) {
+ memcpy(iv.cur, to, sizeof to), memcpy(iv.cfrom, to, sizeof to), memcpy(iv.cto, to, sizeof to);
+ iv.cursor_set = true, iv.ct = CURSOR_TIME;
+ return;
+ }
+ memcpy(iv.cfrom, iv.cur, sizeof iv.cur), memcpy(iv.cto, to, sizeof to);
+ iv.ct = 0;
+}
+
+static const Box arrow_box = {1.2f, 1.6f, 0, 0};
+
+static void charms_cursor(void) {
+ float x, y;
+ if (iv.area == CA_COLLECTION) {
+ cursor_to(ch_bb_pos[iv.coll - 1][0], ch_bb_pos[iv.coll - 1][1], &ch_bb_box, 1, 1);
+ } else if (iv.area == CA_EQUIPPED) {
+ eq_pos(iv.eq, &x, &y);
+ cursor_to(x, y, iv.eq > equipped_count() ? &ch_next_box : &ch_eq_box, 1, 1);
+ } else {
+ const Piece *a = iv.area == CA_ARROW_L ? &arrow_l : &arrow_r;
+ cursor_to(a->x, a->y, &arrow_box, 1, 1);
+ }
+}
+
+/* the Inventory pane's items as the Knight has them now */
+enum { K_HEART_I, K_VESSEL_I, K_NAIL_I, K_FIREBALL_I, K_FOCUS_I, K_GEO_I, K_EQ0 = 16, K_TRINKET0 = 32 };
+static void build_items(void) {
+ int n = 0;
+ for (int k = 0; k < NFIXED; k++) {
+ if (k == IT_FIREBALL && !g_pd.fireball_level) continue;
+ iv.items[n] = (uint8_t)k, iv.item_xy[n][0] = inv_fixed[k].x, iv.item_xy[n][1] = inv_fixed[k].y, n++;
+ }
+ int slot = 0;
+ for (int k = 0; k < NEQ; k++) {
+ bool has = k == EQ_DASH ? g_pd.has_dash : k == EQ_LANTERN ? pd_flag(PDF_HAS_LANTERN)
+ : k == EQ_MAP ? (pd_flag(PDF_HAS_MAP) || pd_flag(PDF_HAS_QUILL)) : k == EQ_CITY_KEY ? pd_flag(PDF_HAS_CITY_KEY)
+ : k == EQ_SIMPLE_KEY ? g_pd.simple_keys > 0 : g_pd.rancid_eggs > 0;
+ if (!has) continue;
+ iv.items[n] = (uint8_t)(K_EQ0 + k);
+ iv.item_xy[n][0] = INV_EQ_X + (slot % 4) * INV_EQ_DX, iv.item_xy[n][1] = INV_EQ_Y + (slot / 4) * INV_EQ_DY;
+ n++, slot++;
+ }
+ for (int k = 0; k < 4; k++)
+ if (g_pd.trinkets[k]) {
+ iv.items[n] = (uint8_t)(K_TRINKET0 + k), iv.item_xy[n][0] = inv_trinkets[k].x, iv.item_xy[n][1] = inv_trinkets[k].y;
+ n++;
+ }
+ iv.nitems = n;
+}
+
+static const Box *item_box(int kind) {
+ return kind < NFIXED ? &inv_fixed_box[kind] : kind < K_TRINKET0 ? &inv_eq_box[kind - K_EQ0] : &inv_trinket_box[kind - K_TRINKET0];
+}
+
+static void inv_cursor(void) {
+ if (iv.sel == -1) cursor_to(arrow_l.x, arrow_l.y, &arrow_box, 1, 1);
+ else if (iv.sel == -2) cursor_to(arrow_r.x, arrow_r.y, &arrow_box, 1, 1);
+ else cursor_to(iv.item_xy[iv.sel][0], iv.item_xy[iv.sel][1], item_box(iv.items[iv.sel]), 1, 1);
+}
+
+static bool other_panes(void) {
+ int n = 0;
+ for (int p = 0; p < NPANES; p++) n += has_pane(p);
+ return n > 1;
+}
+
+/* ---------------------------------------------------------------- panes */
+static void pane_enter(int p) {
+ iv.pane = (uint8_t)p;
+ iv.cursor_set = false;
+ if (p == P_CHARMS) {
+ /* (Activate: at the first charm's backboard) */
+ iv.area = CA_COLLECTION, iv.coll = (uint8_t)bb_of_charm(1), iv.eq = 1, iv.oc_attempts = 0, iv.tween = TW_NONE;
+ charms_cursor();
+ } else {
+ build_items();
+ iv.sel = 0;
+ inv_cursor();
+ }
+}
+
+/* (MOVE PANE: the next pane the Knight has that way, round) */
+static void move_pane(int dir) {
+ int p = iv.pane;
+ for (int k = 0; k < NPANES; k++) {
+ p = (p + dir + NPANES) % NPANES;
+ if (has_pane(p)) break;
+ }
+ if (p == iv.pane) return;
+ iv.prev_pane = iv.pane;
+ iv.slide_t = 0, iv.slide_dir = (int8_t)dir;
+ pane_enter(p); /* (ACTIVATE: its cursor at its first place) */
+}
+
+static int neighbor_pane(int dir) {
+ int p = iv.pane;
+ for (int k = 0; k < NPANES; k++) {
+ p = (p + dir + NPANES) % NPANES;
+ if (has_pane(p)) return p == iv.pane ? -1 : p;
+ }
+ return -1;
+}
+
+/* ---------------------------------------------------------------- opening, closing */
+static bool can_open(void) {
+ const Hero *h = &g_hero;
+ if (pd_flag(PDF_AT_BENCH)) return true;
+ return !g_game.paused && !h->control_relinquished && !h->cs.recoiling && !h->cs.transitioning && !h->cs.hazard_death &&
+ !h->cs.hazard_respawning && g_game.time_scale >= 1 && !g_pd.disable_pause && !h->cs.dashing && h->accepting_input &&
+ !game_changing_room() && !msg_shown();
+}
+
+static void open(void) {
+ memset(&iv, 0, sizeof iv);
+ iv.st = IV_OPEN, iv.slide_t = -1, iv.ct = CURSOR_TIME;
+ iv.prev_keys = g_hero.keys;
+ g_pd.disable_pause = true;
+ if (!pd_flag(PDF_AT_BENCH)) hero_relinquish_control_not_velocity();
+ hud_slide(true);
+ notices_close();
+ int p = g_pd.current_inv_pane;
+ pane_enter(has_pane(p) ? p : P_INV);
+}
+
+static void close_now(void) {
+ iv.st = IV_CLOSED;
+ iv.blocked = iv.prev_keys;
+ g_pd.current_inv_pane = iv.pane;
+ g_pd.disable_pause = false;
+ hud_slide(false);
+ if (!pd_flag(PDF_AT_BENCH)) hero_regain_control();
+}
+
+void inv_damage(void) {
+ if (iv.st == IV_OPEN) iv.st = IV_CLOSING, iv.t = FADE - 0.05f; /* (Damage Close: down fast) */
+}
+
+void inv_reset(void) {
+ memset(&iv, 0, sizeof iv);
+ g_gfx_overlay = NULL, g_gfx_reserve = 0;
+}
+
+/* ---------------------------------------------------------------- the Charms pane's input */
+static void charm_select_text(int *name, int *desc, int *cost, int *detail);
+
+static void charms_confirm(void) {
+ if (iv.tween != TW_NONE) return;
+ int id = 0;
+ if (iv.area == CA_COLLECTION) {
+ id = ch_bb_charm[iv.coll - 1];
+ if (!charm_got(id)) return;
+ } else if (iv.area == CA_EQUIPPED) {
+ if (iv.eq > equipped_count()) return; /* (on the next dot) */
+ id = g_pd.equipped[iv.eq - 1];
+ } else {
+ move_pane(iv.area == CA_ARROW_L ? -1 : 1);
+ return;
+ }
+ if (!pd_flag(PDF_AT_BENCH)) return; /* (charms are changed at a bench) */
+ iv.tw_charm = (uint8_t)id, iv.tw_t = 0;
+ float x, y;
+ if (charm_equipped(id)) {
+ /* Tween Down: from its place in the row to its backboard */
+ int n = 1;
+ while (n <= equipped_count() && g_pd.equipped[n - 1] != id) n++;
+ eq_pos(n, &x, &y);
+ iv.tw_from[0] = x, iv.tw_from[1] = y;
+ int bb = bb_of_charm(id);
+ iv.tw_to[0] = ch_bb_pos[bb - 1][0], iv.tw_to[1] = ch_bb_pos[bb - 1][1];
+ iv.tween = TW_DOWN;
+ unequip(id); /* (its place in the row: gone as it moves) */
+ return;
+ }
+ /* Slot Open?: a notch left to try it in */
+ if (g_pd.charm_slots_filled >= g_pd.charm_slots) return;
+ int bb = bb_of_charm(id);
+ iv.tw_from[0] = ch_bb_pos[bb - 1][0], iv.tw_from[1] = ch_bb_pos[bb - 1][1];
+ eq_pos(equipped_count() + 1, &x, &y);
+ iv.tw_to[0] = x, iv.tw_to[1] = y;
+ iv.tween = TW_UP;
+}
+
+/* the charm's move over: equipped (or overcharmed, or not: back), unequipped */
+static void tween_done(void) {
+ int id = iv.tw_charm;
+ if (iv.tween == TW_UP) {
+ /* Check Points */
+ g_pd.charm_slots_filled = (uint8_t)(g_pd.charm_slots_filled + costs[id]);
+ if (g_pd.charm_slots_filled > g_pd.charm_slots) {
+ /* Overcharm Check: the sixth try breaks through (canOvercharm after) */
+ if (!pd_flag(PDF_CAN_OVERCHARM) && ++iv.oc_attempts < 5) {
+ iv.tween = TW_FAIL, iv.tw_t = 0; /* (Fail: 0.5 s shaking, then back) */
+ return;
+ }
+ pd_set_flag(PDF_CAN_OVERCHARM, true);
+ pd_set_flag(PDF_OVERCHARMED, true);
+ }
+ equip(id);
+ iv.tween = TW_NONE;
+ } else if (iv.tween == TW_FAIL) {
+ /* Fail Back */
+ g_pd.charm_slots_filled = (uint8_t)(g_pd.charm_slots_filled - costs[id]);
+ float t0 = iv.tw_from[0], t1 = iv.tw_from[1];
+ iv.tw_from[0] = iv.tw_to[0], iv.tw_from[1] = iv.tw_to[1], iv.tw_to[0] = t0, iv.tw_to[1] = t1;
+ iv.tween = TW_FAIL_BACK, iv.tw_t = 0;
+ return;
+ } else if (iv.tween == TW_DOWN) {
+ /* Return Points, End Overcharm? */
+ g_pd.charm_slots_filled = (uint8_t)(g_pd.charm_slots_filled - costs[id]);
+ if (g_pd.charm_slots_filled <= g_pd.charm_slots) pd_set_flag(PDF_OVERCHARMED, false);
+ iv.tween = TW_NONE;
+ } else {
+ iv.tween = TW_NONE;
+ }
+ /* (CharmUpdate: the Knight with them; the cursor where it was) */
+ hero_charm_update();
+ if (iv.area == CA_EQUIPPED && iv.eq > equipped_count() + (g_pd.charm_slots_filled < g_pd.charm_slots))
+ iv.eq = (uint8_t)(equipped_count() + (g_pd.charm_slots_filled < g_pd.charm_slots));
+ if (iv.area == CA_EQUIPPED && iv.eq < 1) iv.area = CA_COLLECTION;
+ charms_cursor();
+}
+
+static void charms_move(uint32_t p) {
+ if (iv.tween != TW_NONE) return;
+ int eq_items = equipped_count() + (g_pd.charm_slots_filled < g_pd.charm_slots);
+ if (iv.area == CA_COLLECTION) {
+ if (p & K_DOWN) {
+ if (iv.coll <= 30) iv.coll += 10;
+ } else if (p & K_UP) {
+ if (iv.coll < 11) {
+ if (eq_items) iv.area = CA_EQUIPPED, iv.eq = 1; /* (To Equipment) */
+ } else
+ iv.coll -= 10;
+ } else if (p & K_LEFT) {
+ if ((iv.coll - 1) % 10 == 0) {
+ if (other_panes()) iv.area = CA_ARROW_L;
+ } else
+ iv.coll--;
+ } else if (p & K_RIGHT) {
+ if (iv.coll % 10 == 0) {
+ if (other_panes()) iv.area = CA_ARROW_R;
+ } else
+ iv.coll++;
+ }
+ } else if (iv.area == CA_EQUIPPED) {
+ if (p & K_DOWN) iv.area = CA_COLLECTION, iv.coll = 1; /* (To Bot) */
+ else if (p & K_LEFT) {
+ if (iv.eq <= 1) {
+ if (other_panes()) iv.area = CA_ARROW_L;
+ } else
+ iv.eq--;
+ } else if ((p & K_RIGHT) && iv.eq < eq_items)
+ iv.eq++;
+ } else if (iv.area == CA_ARROW_L) {
+ if (p & K_RIGHT) iv.area = CA_COLLECTION;
+ else if (p & K_LEFT) {
+ move_pane(-1);
+ return;
+ }
+ } else {
+ if (p & K_LEFT) iv.area = CA_COLLECTION;
+ else if (p & K_RIGHT) {
+ move_pane(1);
+ return;
+ }
+ }
+ charms_cursor();
+}
+
+/* ---------------------------------------------------------------- the Inventory pane's input */
+static void inv_move(uint32_t p) {
+ if (iv.sel < 0) {
+ /* (the arrows: on, or back in) */
+ bool left = iv.sel == -1;
+ if ((left && (p & K_LEFT)) || (!left && (p & K_RIGHT))) {
+ move_pane(left ? -1 : 1);
+ return;
+ }
+ if ((left && (p & K_RIGHT)) || (!left && (p & K_LEFT))) {
+ /* (back to the nearest item) */
+ float ax = left ? arrow_l.x : arrow_r.x;
+ int best = 0;
+ for (int i = 1; i < iv.nitems; i++)
+ if (fabsf(iv.item_xy[i][0] - ax) < fabsf(iv.item_xy[best][0] - ax)) best = i;
+ iv.sel = (int8_t)best;
+ inv_cursor();
+ }
+ return;
+ }
+ /* the nearest item that way (by how far it is, along more than across) */
+ float dx = (p & K_RIGHT) ? 1 : (p & K_LEFT) ? -1 : 0, dy = (p & K_UP) ? 1 : (p & K_DOWN) ? -1 : 0;
+ if (!dx && !dy) return;
+ float x0 = iv.item_xy[iv.sel][0], y0 = iv.item_xy[iv.sel][1];
+ int best = -1;
+ float bd = 1e9f;
+ for (int i = 0; i < iv.nitems; i++) {
+ if (i == iv.sel) continue;
+ float ex = iv.item_xy[i][0] - x0, ey = iv.item_xy[i][1] - y0;
+ float along = ex * dx + ey * dy, across = fabsf(ex * dy - ey * dx);
+ if (along < 0.3f || across > along * 2.5f) continue;
+ float dist = along + across * 2;
+ if (dist < bd) bd = dist, best = i;
+ }
+ if (best >= 0) iv.sel = (int8_t)best;
+ else if (dx && other_panes()) iv.sel = (int8_t)(dx < 0 ? -1 : -2);
+ else return;
+ inv_cursor();
+}
+
+/* ---------------------------------------------------------------- each tick */
+uint32_t inv_tick(uint32_t keys) {
+ uint32_t pressed = keys & ~iv.prev_keys;
+ iv.prev_keys = keys;
+ if (iv.st == IV_CLOSED) {
+ g_gfx_overlay = NULL, g_gfx_reserve = 0;
+ iv.blocked &= keys;
+ if ((pressed & K_INV) && can_open()) {
+ open();
+ iv.prev_keys = keys;
+ return 0;
+ }
+ return keys & ~iv.blocked;
+ }
+ extern void inv_draw(void);
+ g_gfx_overlay = inv_draw, g_gfx_reserve = RESERVE;
+ if (iv.st == IV_CLOSING) {
+ iv.t += DT;
+ iv.border_a = iv.pane_a = 1 - iv.t / FADE;
+ if (iv.t >= FADE) {
+ close_now();
+ iv.border_a = iv.pane_a = 0;
+ }
+ return 0;
+ }
+ /* fades up; the panes' move; the cursor's; a charm's */
+ if (iv.border_a < 1) iv.border_a = fminf(1, iv.border_a + DT / FADE);
+ if (iv.pane_a < 1) iv.pane_a = fminf(1, iv.pane_a + DT / FADE);
+ if (iv.slide_t >= 0 && (iv.slide_t += DT) >= SLIDE) iv.slide_t = -1;
+ if (iv.ct < CURSOR_TIME) {
+ iv.ct += DT;
+ float q = iv.ct >= CURSOR_TIME ? 1 : iv.ct / CURSOR_TIME;
+ for (int k = 0; k < 4; k++) iv.cur[k] = iv.cfrom[k] + (iv.cto[k] - iv.cfrom[k]) * q;
+ }
+ if (iv.tween != TW_NONE) {
+ iv.tw_t += DT;
+ if (iv.tw_t >= (iv.tween == TW_FAIL ? 0.5f : TWEEN_TIME)) tween_done();
+ }
+ /* closing: the inventory key, or back */
+ if ((pressed & (K_INV | K_BACK)) && iv.tween == TW_NONE) {
+ iv.st = IV_CLOSING, iv.t = 0;
+ return 0;
+ }
+ if (iv.slide_t >= 0) return 0;
+ /* (directions: held, again after a moment, then often) */
+ uint32_t dirs = keys & (K_LEFT | K_RIGHT | K_UP | K_DOWN);
+ uint32_t move = pressed & dirs;
+ if (dirs && dirs == iv.held) {
+ iv.held_t += DT;
+ if (iv.held_t >= REPEAT_FIRST) move = dirs, iv.held_t -= REPEAT;
+ } else
+ iv.held = dirs, iv.held_t = 0;
+ if (iv.pane == P_CHARMS) {
+ if (move) charms_move(move);
+ if (pressed & K_OK) charms_confirm();
+ } else {
+ if (move) inv_move(move);
+ if ((pressed & K_OK) && iv.sel < 0) move_pane(iv.sel == -1 ? -1 : 1);
+ }
+ return 0;
+}
+
+/* ---------------------------------------------------------------- drawing */
+static void piece(const Piece *p, float ox, float oy, float k, uint8_t tint) {
+ if (p->sprite < 0) return;
+ Inst in;
+ sprite_inst(p->sprite, ox + p->x, oy + p->y, 0, p->kx * k, p->ky * k, tint, &in);
+ gfx_overlay(&in);
+}
+
+static void sprite_at(int sprite, float x, float y, float k, uint8_t tint) {
+ if (sprite < 0) return;
+ Inst in;
+ sprite_inst(sprite, x, y, 0, k, k, tint, &in);
+ gfx_overlay(&in);
+}
+
+/* a text's lines (each top aligned at its place: 0 left, 1 center, 2 right) */
+static void text_at(int text, int style, const TextAt *t, float ox, float oy, int align, float a) {
+ text_box(text, style, ox + t->x, oy + t->top, 1e3f, align, a);
+}
+
+static void digits(char *out, int v) {
+ char b[12];
+ int n = 0;
+ if (v < 0) v = 0;
+ do b[n++] = (char)('0' + v % 10), v /= 10;
+ while (v && n < 11);
+ for (int i = 0; i < n; i++) out[i] = b[n - 1 - i];
+ out[n] = 0;
+}
+
+static void number_at(int v, int style, float x, float top, int align, float a) {
+ /* (kept until the frame is drawn: the text runs point at them) */
+ static char pool[8][12];
+ static int next;
+ char *s = pool[next++ & 7];
+ digits(s, v);
+ const uint8_t *st = font_style(style);
+ int n = (int)strlen(s);
+ float w = text_width(style, (const uint8_t *)s, n);
+ float px = VIEW_W / 2 + x * HUD_PX - (align == 1 ? w / 2 : align == 2 ? w : 0);
+ gfx_text(style, px, VIEW_H / 2 - top * HUD_PX + font_asc(st), (const uint8_t *)s, n, (uint32_t)(a * 255 + 0.5f) << 24 | 0xFFFFFF, 0);
+}
+
+static void cursor_draw(float ox, float oy, uint8_t tint) {
+ /* (its corners, about its box: TL, TR, BL, BR) */
+ static const int8_t sx[4] = {-1, 1, -1, 1}, sy[4] = {1, 1, -1, -1};
+ for (int k = 0; k < 4; k++) {
+ Inst in;
+ sprite_inst(ch_cursor.sprite, ox + iv.cur[0] + sx[k] * iv.cur[2] * ch_cursor_k[0],
+ oy + iv.cur[1] + sy[k] * iv.cur[3] * ch_cursor_k[1], 0, ch_cursor.kx * ch_corners[k][0],
+ ch_cursor.ky * ch_corners[k][1], tint, &in);
+ gfx_overlay(&in);
+ }
+}
+
+static void charm_select_text(int *name, int *desc, int *cost, int *detail) {
+ *name = *desc = -1, *cost = 0, *detail = 0;
+ int id = 0;
+ if (iv.area == CA_COLLECTION) id = ch_bb_charm[iv.coll - 1];
+ else if (iv.area == CA_EQUIPPED) {
+ if (iv.eq <= equipped_count()) id = g_pd.equipped[iv.eq - 1];
+ else *desc = equipped_count() ? -1 : pd_flag(PDF_AT_BENCH) ? TXT_CHARM_ALERT_NONE_BENCH : TXT_CHARM_ALERT_NONE;
+ }
+ if (!charm_got(id)) return;
+ *name = ch_names[id], *desc = ch_descs[id], *cost = costs[id], *detail = id;
+}
+
+static void charms_draw(float ox, float oy, float a, uint8_t white) {
+ uint8_t glow = gfx_dyn_tint(24, 255, 255, 255, (uint8_t)(a * CH_GLOW_A * 255 + 0.5f));
+ uint8_t full = gfx_dyn_tint(25, notch_full_rgb[0], notch_full_rgb[1], notch_full_rgb[2], (uint8_t)(a * 255 + 0.5f));
+ uint8_t over = gfx_dyn_tint(26, notch_over_rgb[0], notch_over_rgb[1], notch_over_rgb[2], (uint8_t)(a * 255 + 0.5f));
+ /* the collection: the backboards, the charms the Knight has (glowing; not those equipped, nor the one moving) */
+ for (int i = 0; i < 40; i++) {
+ float x = ox + ch_bb_pos[i][0], y = oy + ch_bb_pos[i][1];
+ sprite_at(ch_bb.sprite, x, y, ch_bb.kx, white);
+ int id = ch_bb_charm[i];
+ if (!charm_got(id) || charm_equipped(id) || (iv.tween != TW_NONE && iv.tw_charm == id)) continue;
+ piece(&ch_glow, x, y, 1, glow);
+ sprite_at(ch_icons[id], x, y, 1 / CHARM_ICON_K, white);
+ }
+ /* the equipped row, the next dot */
+ int n = equipped_count();
+ for (int i = 1; i <= n; i++) {
+ float x, y;
+ eq_pos(i, &x, &y);
+ if (!(iv.tween == TW_FAIL_BACK && g_pd.equipped[i - 1] == iv.tw_charm))
+ sprite_at(ch_icons[g_pd.equipped[i - 1]], ox + x, oy + y, EQ_SCALE / CHARM_ICON_K, white);
+ }
+ if (g_pd.charm_slots_filled < g_pd.charm_slots && !(iv.tween == TW_UP || iv.tween == TW_FAIL)) {
+ float x, y;
+ eq_pos(n + 1, &x, &y);
+ piece(&ch_next_dot, ox + x, oy + y, 1, white);
+ }
+ /* the notches: full as the charms take them; over them (overcharmed, or trying), red */
+ int slots = g_pd.charm_slots, filled = g_pd.charm_slots_filled;
+ for (int i = 0; i < slots || i < filled; i++) {
+ float x = ox + CH_NOTCH_X + i * CH_NOTCH_DX, y = oy + CH_NOTCH_Y;
+ bool over_on = filled > slots && (pd_flag(PDF_OVERCHARMED) || iv.tween == TW_FAIL);
+ if (i < filled) piece(&ch_notch_full, x, y, 1, over_on ? over : full);
+ else piece(&ch_notch_empty, x, y, 1, white);
+ }
+ text_at(pd_flag(PDF_OVERCHARMED) ? TXT_CHARM_TXT_OVERCHARMED : TXT_CHARM_TXT_EQUIPPED, STYLE_TUTE, &ch_text_equipped,
+ ox, oy, 0, a);
+ text_at(TXT_CHARM_NOTCHES, STYLE_MSG, &ch_text_notches, ox, oy, 0, a);
+ piece(&ch_divider, ox, oy, 1, white);
+ /* the charm moving to its notch or back (shaking as it fails) */
+ if (iv.tween != TW_NONE) {
+ float q = iv.tween == TW_FAIL ? 1 : iv.tw_t / TWEEN_TIME;
+ float e = sinf((q > 1 ? 1 : q) * 1.5707964f);
+ float x = iv.tw_from[0] + (iv.tw_to[0] - iv.tw_from[0]) * e, y = iv.tw_from[1] + (iv.tw_to[1] - iv.tw_from[1]) * e;
+ if (iv.tween == TW_FAIL) x += rand_range(-0.1f, 0.1f), y += rand_range(-0.1f, 0.1f); /* (ObjectJitterRealtime) */
+ sprite_at(ch_icons[iv.tw_charm], ox + x, oy + y, EQ_SCALE / CHARM_ICON_K, white);
+ }
+ /* what is selected: its name, cost, picture, description; Equip or Unequip (at a bench) */
+ int name, desc, cost, detail;
+ charm_select_text(&name, &desc, &cost, &detail);
+ text_at(name, STYLE_DIALOGUE, &ch_name, ox, oy, 1, a);
+ if (detail) {
+ text_at(TXT_CHARM_TXT_COST, STYLE_MSG, &ch_cost_text, ox, oy, 2, a);
+ for (int i = 0; i < cost; i++) piece(&ch_cost_pip, ox + CH_COST_X + i * CH_COST_DX, oy + CH_COST_Y, 1, white);
+ sprite_at(ch_icons[detail], ox + CH_DETAIL_X, oy + CH_DETAIL_Y, DETAIL_SCALE / CHARM_ICON_K, white);
+ }
+ text_box(desc, STYLE_MSG, ox + ch_desc.x, oy + ch_desc.top, ch_desc.w, 0, a);
+ if (detail && pd_flag(PDF_AT_BENCH)) {
+ text_at(charm_equipped(detail) ? TXT_CTRL_UNEQUIP : TXT_CTRL_EQUIP, STYLE_MSG, &ch_confirm, ox, oy, 2, a);
+ /* (the key: the calculator's, by name; its box widened to the right to fit the name) */
+ const uint8_t *st = font_style(STYLE_MSG);
+ float w = text_width(STYLE_MSG, text_get(TXT_KEY_OK), 2), bw = w / HUD_PX + 0.3f;
+ float kx = bw > CH_CONFIRM_KEY_W ? bw / CH_CONFIRM_KEY_W : 1, cx = ox + ch_key.x + (kx - 1) * CH_CONFIRM_KEY_W / 2;
+ Inst in;
+ sprite_inst(ch_key.sprite, cx, oy + ch_key.y, 0, kx, 1, white, &in);
+ gfx_overlay(&in);
+ gfx_text(STYLE_MSG, VIEW_W / 2 + cx * HUD_PX - w / 2,
+ VIEW_H / 2 - (oy + ch_key.y) * HUD_PX + (font_asc(st) - font_desc(st)) / 2, text_get(TXT_KEY_OK), 2,
+ (uint32_t)(a * 255 + 0.5f) << 24 | 0xFFFFFF, 0);
+ }
+ if (iv.cursor_set) cursor_draw(ox, oy, white);
+}
+
+static void items_draw(float ox, float oy, float a, uint8_t white) {
+ for (int i = 0; i < 2; i++) {
+ const TurnedPiece *d = &inv_dividers[i];
+ Inst in;
+ sprite_inst_rot(d->sprite, ox + d->x, oy + d->y, 0, d->kx, d->ky, d->deg, white, &in);
+ gfx_overlay(&in);
+ }
+ bool any_trinket = false;
+ for (int i = 0; i < iv.nitems; i++) any_trinket |= iv.items[i] >= K_TRINKET0;
+ if (any_trinket) piece(&inv_trinket_bb, ox, oy, 1, white);
+ for (int i = 0; i < iv.nitems; i++) {
+ int k = iv.items[i];
+ float x = ox + iv.item_xy[i][0], y = oy + iv.item_xy[i][1];
+ if (k < NFIXED) {
+ piece(&inv_fixed_bg[k], ox, oy, 1, white);
+ piece(&inv_fixed[k], ox, oy, 1, white);
+ if (k == IT_HEART && g_pd.heart_pieces > 0 && g_pd.heart_pieces <= 4) piece(&inv_heart[g_pd.heart_pieces - 1], ox, oy, 1, white);
+ if (k == IT_VESSEL && g_pd.vessel_fragments > 0) piece(&inv_vessel[g_pd.vessel_fragments >= 3 ? 2 : g_pd.vessel_fragments - 1], ox, oy, 1, white);
+ if (k == IT_GEO) number_at(g_pd.geo, STYLE_MSG, ox + inv_geo_text.x, oy + inv_geo_text.top, 0, a);
+ } else if (k < K_TRINKET0) {
+ const Piece *p = &inv_eq[k - K_EQ0];
+ sprite_at(p->sprite, x, y, p->kx, white);
+ int amount = k == K_EQ0 + EQ_SIMPLE_KEY ? g_pd.simple_keys : k == K_EQ0 + EQ_RANCID_EGG ? g_pd.rancid_eggs : 0;
+ if (amount > 1) number_at(amount, STYLE_MSG, x + inv_trinket_text.x, y + inv_trinket_text.top, 1, a);
+ } else {
+ const Piece *p = &inv_trinkets[k - K_TRINKET0];
+ sprite_at(p->sprite, x, y, p->kx, white);
+ number_at(g_pd.trinkets[k - K_TRINKET0], STYLE_MSG, x + inv_trinket_text.x, y + inv_trinket_text.top, 1, a);
+ }
+ }
+ /* the selected item's name and description */
+ if (iv.sel >= 0 && iv.sel < iv.nitems) {
+ int k = iv.items[iv.sel];
+ NameDesc nd = {-1, -1};
+ if (k == IT_HEART) {
+ int h = g_pd.max_health >= 9 ? 5 : !pd_flag(PDF_HEART_PIECE_COLLECTED) ? 0 : 1 + (g_pd.heart_pieces > 3 ? 3 : g_pd.heart_pieces);
+ nd = txt_heart[h];
+ } else if (k == IT_VESSEL) {
+ int v = g_pd.mp_reserve_max >= 99 ? 4 : !pd_flag(PDF_VESSEL_FRAGMENT_COLLECTED) ? 0 : 1 + (g_pd.vessel_fragments > 2 ? 2 : g_pd.vessel_fragments);
+ nd = txt_vessel[v];
+ } else if (k == IT_NAIL) nd = txt_fixed[0];
+ else if (k == IT_FIREBALL) nd = txt_fixed[1];
+ else if (k == IT_FOCUS) nd = txt_fixed[2];
+ else if (k == IT_GEO) nd = txt_fixed[3];
+ else if (k < K_TRINKET0) {
+ nd = txt_eq[k - K_EQ0];
+ if (k == K_EQ0 + EQ_MAP && pd_flag(PDF_HAS_QUILL))
+ nd = pd_flag(PDF_HAS_MAP) ? (NameDesc){txt_quill[2], txt_quill[3]} : (NameDesc){txt_quill[0], txt_quill[1]};
+ } else
+ nd = txt_trinkets[k - K_TRINKET0];
+ text_at(nd.name, STYLE_DIALOGUE, &inv_name, ox, oy, 1, a);
+ text_box(nd.desc, STYLE_MSG, ox + inv_desc.x, oy + inv_desc.top, inv_desc.w, 0, a);
+ }
+ if (iv.cursor_set) cursor_draw(ox, oy, white);
+}
+
+static void pane_draw(int p, float a, uint8_t white) {
+ float ox = INV_X + pane_x(p), oy = INV_Y;
+ if (p == P_CHARMS) charms_draw(ox, oy, a, white);
+ else items_draw(ox, oy, a, white);
+}
+
+void inv_draw(void) {
+ if (iv.st == IV_CLOSED && iv.border_a <= 0) return;
+ float ba = iv.border_a < 0 ? 0 : iv.border_a, pa = iv.pane_a < 0 ? 0 : iv.pane_a;
+ /* the world behind, darkened; the dark frame about it; the border; the arrows; the panes' names */
+ gfx_overlay_fill(-20, -12, 20, 12, gfx_dyn_tint(29, 0, 0, 0, (uint8_t)(ba * DIM * 255 + 0.5f)));
+ uint8_t bw = gfx_dyn_tint(30, 255, 255, 255, (uint8_t)(ba * 255 + 0.5f));
+ piece(&frame, INV_X, INV_Y, 1, bw);
+ for (int i = 0; i < INV_NBORDER; i++) piece(&border[i], INV_X, INV_Y, 1, bw);
+ int l = neighbor_pane(-1), r = neighbor_pane(1);
+ if (l >= 0) piece(&arrow_l, INV_X, INV_Y, 1, bw), piece(&pane_arrow_l, INV_X, INV_Y, 1, bw);
+ if (r >= 0) piece(&arrow_r, INV_X, INV_Y, 1, bw), piece(&pane_arrow_r, INV_X, INV_Y, 1, bw);
+ text_at(pane_names[iv.pane], STYLE_TUTE, &pane_name, INV_X, INV_Y, 1, ba);
+ if (l >= 0) text_at(pane_names[l], STYLE_TUTE, &pane_name_l, INV_X, INV_Y, 0, ba);
+ if (r >= 0) text_at(pane_names[r], STYLE_TUTE, &pane_name_r, INV_X, INV_Y, 2, ba);
+ /* the panes (the one going too, as they move) */
+ uint8_t pw = gfx_dyn_tint(31, 255, 255, 255, (uint8_t)(pa * 255 + 0.5f));
+ if (iv.slide_t >= 0) pane_draw(iv.prev_pane, pa, pw);
+ pane_draw(iv.pane, pa, pw);
+}
diff --git a/games/hollowknight/src/main.c b/games/hollowknight/src/main.c
index 3edf1538..540f93e6 100644
--- a/games/hollowknight/src/main.c
+++ b/games/hollowknight/src/main.c
@@ -58,7 +58,7 @@ int main(void) {
acc += now - last, last = now;
int ticks = 0;
while (acc >= TICK_MS && ticks < MAX_TICKS) {
- if (!menu_tick(keys)) game_tick(keys);
+ if (!menu_tick(keys)) game_tick(inv_tick(keys));
acc -= TICK_MS, ticks++, perf_updates++;
}
if (ticks == MAX_TICKS) acc = 0; /* (too slow to catch up: the game slows down instead) */
diff --git a/games/hollowknight/src/menu.c b/games/hollowknight/src/menu.c
index d049fcce..c21e5d4a 100644
--- a/games/hollowknight/src/menu.c
+++ b/games/hollowknight/src/menu.c
@@ -1,5 +1,6 @@
/* The title screen, the save profiles and the pause menu (UIManager: Menu_Title's MainMenuScreen, SaveProfileScreen and
* PauseMenuScreen, their pieces where tools/menu.py found them): what is selected, what the keys do. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include "game.h"
#define DT 0.02f
diff --git a/games/hollowknight/src/msg.c b/games/hollowknight/src/msg.c
index 867be7d8..ffa15acb 100644
--- a/games/hollowknight/src/msg.c
+++ b/games/hollowknight/src/msg.c
@@ -1,6 +1,7 @@
/* The message as the Knight takes an item (UI Msg Get Item: its Msg Control FSM): a dark backdrop, the item's icon and
* name fade up, then how to use it (Tap or Press, the key, two lines), then the stop marker; a key sends it away.
* Places in HUD units from the screen's center (its prefab, made at the origin, drawn by the HUD's camera). */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
@@ -127,6 +128,14 @@ static float line(int text, int style, float x, float y, int align, bool top, fl
return wmax;
}
+static void sprite_k(int sprite, float x, float y, float k, float a, int slot) {
+ uint8_t al = (uint8_t)(a * 255 + 0.5f);
+ if (!al) return;
+ Inst in;
+ sprite_inst(sprite, x, y, 0, k, k, gfx_dyn_tint(slot, 255, 255, 255, al), &in);
+ gfx_hud(&in, 0);
+}
+
static void sprite(int sprite, float x, float y, float a, int slot) {
uint8_t al = (uint8_t)(a * 255 + 0.5f);
if (!al) return;
@@ -159,6 +168,7 @@ static struct {
} nt = {NT_OFF, -1, -1, -1, 0, -1};
static void notices_off(void) { nt.kind = NT_OFF; }
+void notices_close(void) { notices_off(); }
void notice_icon(int k) { nt.next_icon = k >= 0 && k < (int)(sizeof notice_icons / sizeof notice_icons[0]) ? notice_icons[k] : -1; }
@@ -218,7 +228,8 @@ static void notices_draw(void) {
const float x = -11.91f, y = -6.22f;
float a = fader(0, 0.3f, 0.2f);
piece(&notice_bb, x + 2.82f, y - 0.12f, a * 0.797f, 22);
- if (nt.icon >= 0) sprite(nt.icon, x - 0.46f, y - 0.05f, a, 23);
+ /* (a charm's icon: made larger, for the inventory) */
+ if (nt.icon >= 0) sprite_k(nt.icon, x - 0.46f, y - 0.05f, nt.kind == NT_CHARM ? 1 / CHARM_ICON_K : 1, a, 23);
/* (its Text: left-aligned in its box, 6.12 wide about (3.64, -0.03)) */
line(nt.text, STYLE_NOTICE, x + 3.64f - 3.06f, y - 0.03f, 2, false, a);
return;
@@ -228,7 +239,7 @@ static void notices_draw(void) {
piece(&tute_bb, x, y - 0.53f, a0, 22);
piece(&tute_fleur, x, y + 2.06f, a0, 24);
/* (its Charm Get Msg: no backboard) */
- if (nt.icon >= 0) sprite(nt.icon, x - 2.9f, y + 0.83f, a0, 23);
+ if (nt.icon >= 0) sprite_k(nt.icon, x - 2.9f, y + 0.83f, 1 / CHARM_ICON_K, a0, 23);
line(nt.text, STYLE_NOTICE, x + 1.2f - 3.06f, y + 0.85f, 2, false, a0);
/* (Title, Subtitle, Text: their tops at their rects' tops, 4.02 high) */
line(TXT_CHARM_TUTE_TITLE, STYLE_TUTE_TITLE, x, y + 1.55f + 2.01f, 0, true, a0);
diff --git a/games/hollowknight/src/npc.c b/games/hollowknight/src/npc.c
index fe20aaf1..96d2ee23 100644
--- a/games/hollowknight/src/npc.c
+++ b/games/hollowknight/src/npc.c
@@ -1,4 +1,5 @@
/* What the Knight interacts with by pressing up: benches (Bench Control, its Detect Range's Detect Hero). */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
diff --git a/games/hollowknight/src/obj.c b/games/hollowknight/src/obj.c
index db430b22..c1a3cd1a 100644
--- a/games/hollowknight/src/obj.c
+++ b/games/hollowknight/src/obj.c
@@ -1,5 +1,6 @@
/* The room's objects that the Knight acts on (tools/ents.py: ENT_OBJ and the records after each): what the nail hits,
* breakables and the debris they fling. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
#ifdef HOST
diff --git a/games/hollowknight/src/save.c b/games/hollowknight/src/save.c
index d3be5550..8d07c59b 100644
--- a/games/hollowknight/src/save.c
+++ b/games/hollowknight/src/save.c
@@ -1,6 +1,7 @@
/* GameManager.SaveGame and LoadGame: PlayerData in a file of the calculator's, one a slot. The file: a header with a
* checksum, PlayerData's saved part, then the objects' states by name (tools/ents.py: PHASH), so that a save keeps
* meaning the same objects whatever the data's version. A file that does not check out is never loaded. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include "game.h"
#define SAVE_MAGIC 0x56534B48u /* "HKSV" */
diff --git a/games/hollowknight/src/text.c b/games/hollowknight/src/text.c
index ec434b48..ee0b4f1a 100644
--- a/games/hollowknight/src/text.c
+++ b/games/hollowknight/src/text.c
@@ -49,6 +49,30 @@ static int line_end(const uint8_t *st, const uint8_t *s, int i, float width, int
}
}
+/* a text in a box (HUD units: its top at y, w wide), word wrapped: each line from x (align 0), centered on it (1) or
+ * ending at it (2) -> how far down it goes (HUD units) */
+float text_box(int text, int style, float x, float y, float w, int align, float a) {
+ if (text < 0) return 0;
+ const uint8_t *s = text_get(text), *st = font_style(style);
+ float px = HUD_PX, wp = w * px;
+ float py = VIEW_H / 2 - y * px + font_asc(st);
+ uint32_t col = (uint32_t)(a * 255 + 0.5f) << 24 | 0xFFFFFF;
+ int lines = 0;
+ for (int i = 0; s[i];) {
+ int next, e = line_end(st, s, i, wp, &next);
+ if (e > i && s[i] != TEXT_PAGE) {
+ float lw = text_width(style, s + i, e - i);
+ float lx = VIEW_W / 2 + x * px - (align == 1 ? lw / 2 : align == 2 ? lw : 0);
+ if (a > 0) gfx_text(style, lx, py, s + i, e - i, col, 0);
+ }
+ lines++;
+ py += font_line(st);
+ if (next <= i) break;
+ i = next;
+ }
+ return lines * font_line(st) / px;
+}
+
/* ---------------------------------------------------------------- the dialogue box */
#define BOX_X 0.0f
#define BOX_Y 4.51f /* (DialogueBox's place: the box scales about it) */
diff --git a/games/hollowknight/src/title.c b/games/hollowknight/src/title.c
index 9b84e695..85e2ef88 100644
--- a/games/hollowknight/src/title.c
+++ b/games/hollowknight/src/title.c
@@ -1,6 +1,7 @@
/* The titles (Area Title: its Area Title Control FSM) and what shows them: a room's AreaTitleController, bosses and
* characters (TITLE_*). On a first visit to an area its large title: the fleurs drawn in above and below, the lines faded
* up; else the small one at the bottom left (or right). Places in HUD units from the screen's center. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
diff --git a/games/hollowknight/src/vm.c b/games/hollowknight/src/vm.c
index 7e5e1945..6e0f4534 100644
--- a/games/hollowknight/src/vm.c
+++ b/games/hollowknight/src/vm.c
@@ -2,6 +2,7 @@
* them): states entered on events, their actions run on entering and each step, FINISHED once all are done. Events an
* FSM sends itself switch its state once the action that sent them is over; those from others at once. The objects
* they use (VM objects) are drawn here; the Knight, the dialogue box, the area title are the game's own. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include <math.h>
#include "game.h"
#ifdef HOST
@@ -1015,6 +1016,7 @@ static bool act(Fsm *f, const uint8_t *a, int mode) {
}
case 11: save_set_respawn("Death Respawn Marker", true); break;
case 15: save_game(); break;
+ case 13: hero_relinquish_control_not_velocity(); break;
case 16: hero_gravity(a0 != 0); break;
case 19: set_var(f, store, hero_can_talk()); break; /* (CanInspect: as CanTalk) */
}
diff --git a/games/hollowknight/src/world.c b/games/hollowknight/src/world.c
index 5882d0e7..22edc568 100644
--- a/games/hollowknight/src/world.c
+++ b/games/hollowknight/src/world.c
@@ -1,4 +1,5 @@
/* The room's game objects: their state, run each tick; the render groups they fade. */
+#pragma GCC optimize("Os") /* (its code small: not where a frame's time goes) */
#include "game.h"
#define DT 0.02f
diff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.c
index a851131f..6e805733 100644
--- a/games/hollowknight/tests/play.c
+++ b/games/hollowknight/tests/play.c
@@ -59,6 +59,9 @@ int main(int argc, char **argv) {
if (getenv("HKGEO")) g_pd.geo = atoi(getenv("HKGEO"));
if (getenv("HKFIRE")) g_pd.fireball_level = atoi(getenv("HKFIRE"));
if (getenv("HKHORNETGP")) g_pd.hornet_greenpath = (uint8_t)atoi(getenv("HKHORNETGP"));
+ if (getenv("HKDASH")) g_pd.has_dash = true;
+ if (getenv("HKTRINKETS")) /* (relics: "1,2,0,0") */
+ sscanf(getenv("HKTRINKETS"), "%hhu,%hhu,%hhu,%hhu", &g_pd.trinkets[0], &g_pd.trinkets[1], &g_pd.trinkets[2], &g_pd.trinkets[3]);
for (const char *f = getenv("HKFLAGS"); f && *f;) { /* (PlayerData bools on, by number: "7,8") */
pd_set_flag(atoi(f), true);
while (*f && *f != ',') f++;
@@ -87,7 +90,8 @@ int main(int argc, char **argv) {
keys |= *p == 'L' ? K_LEFT : *p == 'R' ? K_RIGHT : *p == 'U' ? K_UP : *p == 'D' ? K_DOWN : *p == 'J' ? K_JUMP
: *p == 'A' ? K_ATTACK : *p == 'S' ? K_DASH : *p == 'F' ? K_FOCUS | K_SPELL
/* (the calculator's OK, Back, Backspace: also jump, attack) */
- : *p == 'O' ? K_OK | K_JUMP : *p == 'B' ? K_BACK | K_ATTACK : *p == 'P' ? K_PAUSE : 0;
+ : *p == 'O' ? K_OK | K_JUMP : *p == 'B' ? K_BACK | K_ATTACK : *p == 'P' ? K_PAUSE
+ : *p == 'I' ? K_INV : *p == 'M' ? K_MAP : 0;
int n = *p == '*' ? atoi(++p) : 1;
while (*p && *p != ',') p++;
if (*p == ',') p++;
@@ -98,6 +102,7 @@ int main(int argc, char **argv) {
dialogue_start(atoi(strchr(getenv("HKTALK"), ':') + 1));
}
if (getenv("HKKILL") && atoi(getenv("HKKILL")) == tick) hero_take_damage(SIDE_LEFT, 99, HAZ_NORMAL);
+ if (getenv("HKHURT") && atoi(getenv("HKHURT")) == tick) hero_take_damage(SIDE_LEFT, 1, HAZ_NORMAL);
/* (HKREENTER=tick: the room entered again then, as it was left) */
if (getenv("HKREENTER") && atoi(getenv("HKREENTER")) == tick) game_enter(id, px, py, true);
if (getenv("HKGOD")) g_pd.health = g_pd.max_health;
@@ -108,7 +113,7 @@ int main(int argc, char **argv) {
}
if (getenv("HKPROMPT") && atoi(getenv("HKPROMPT")) == tick)
prompt_show(-1, TXT_PROMPT_LISTEN, g_hero.body.x, g_hero.body.y + 1.5f);
- if (!menu || !menu_tick(keys)) game_tick(keys);
+ if (!menu || !menu_tick(keys)) game_tick(inv_tick(keys));
if (trace && menu) printf(" menu in game %d\n", menu_in_game());
if (trace)
printf("%4d keys %02x pos %.3f,%.3f v %.3f,%.3f state %d ground %d jump %d fall %d clip %d frame %d cam %.2f,%.2f\n", tick,
diff --git a/games/hollowknight/tools/actors.py b/games/hollowknight/tools/actors.py
index 20fbacdc..bc9c569a 100644
--- a/games/hollowknight/tools/actors.py
+++ b/games/hollowknight/tools/actors.py
@@ -1,6 +1,7 @@
"""The game's characters and effects (2D Toolkit): their sprite frames at the size they are seen, and their animation
clips. Each sprite frame becomes a texture like the scenery's; pack.py writes the frames' placements (SPR) and the
clips (CLIP)."""
+import os
import numpy as np
from PIL import Image
import unity, tk2d, scene, art, text
@@ -214,6 +215,7 @@ DRAWN_SCALE = {"Arrow Up": 1.3, "Arrow Down": 1.3, "Stop Up": 1.3, "Stop Down":
K0 = scene.FOCAL / (0.004 - scene.CAMZ) # screen pixels a unit, where actors are (z near 0)
HUD_K = (scene.VIEW_H / 2) / 8.7107 # the HUD's (its orthographic camera)
# (actor, clip): drawn bigger or smaller than their sprites
+ACTOR_RES = float(os.environ.get("HK_ACTOR_RES", "1"))
ACTOR_SCALE = {"hud": HUD_K / K0, "liquid": 1.4 * HUD_K / K0, "dialogue": text.TEXT_K * HUD_K / K0}
HUD_MASK = 0.7135
@@ -271,6 +273,8 @@ def build():
col = tk2d.collection(cpath, cpid)
img, lx, ty, upp, (wu, hu) = tk2d.sprite_image(cpath, col, f["spriteId"])
k = K0 * DRAWN_SCALE.get(name, 1.0) * ACTOR_SCALE.get(actor, 1.0)
+ if actor not in ("knight", "hud", "dialogue", "liquid"):
+ k *= ACTOR_RES # (the others' frames: a little less fine, to fit)
if actor == "hud" and (name.startswith("Health") or name.startswith("Blue")):
k *= HUD_MASK
w = max(1, round(img.width * upp * k))
diff --git a/games/hollowknight/tools/art.py b/games/hollowknight/tools/art.py
index c0e96e0a..3e58a805 100644
--- a/games/hollowknight/tools/art.py
+++ b/games/hollowknight/tools/art.py
@@ -15,6 +15,7 @@ BLUR_SIGMA = 1.2 # background blur, calculator pixels (LightBlurredBackgr
BLUR_SCALE = float(os.environ.get("HK_BLUR_SCALE", "0.25")) # texels a screen pixel behind the blur plane
FG_SCALE = float(os.environ.get("HK_FG_SCALE", "0.6")) # ... in front of the gameplay plane (z < FG_Z)
FG_Z = -2.5
+FIT_K = float(os.environ.get("HK_FIT_K", "1")) # (all the rooms' scenery a little less fine, to fit)
BLUR_PRE = False # (the game blurs the background as a whole: the calculator does too)
LZMA_FILTERS = [{"id": lzma.FILTER_LZMA1, "lc": 0, "lp": 0, "pb": 0, "dict_size": 1 << 12, "preset": 9 | lzma.PRESET_EXTREME}]
@@ -193,7 +194,7 @@ def build_variants(rooms, vis_of, owned=lambda r: ()):
it.alpha_only = it.color[:3] == (0, 0, 0) or black_sprite(it.sprite)
it.want = min(1.0, sc) * (BLUR_SCALE if it.blur else FG_SCALE if it.z < FG_Z else 1.0)
if not it.blur:
- it.want *= FIT.get(r, 1.0)
+ it.want *= FIT.get(r, 1.0) * FIT_K
it.cells = None if it.dynamic else cells.get(it.id)
keep.append(it)
per_room[r] = (keep, st)
diff --git a/games/hollowknight/tools/inv.py b/games/hollowknight/tools/inv.py
new file mode 100644
index 00000000..869c7aa3
--- /dev/null
+++ b/games/hollowknight/tools/inv.py
@@ -0,0 +1,232 @@
+"""The inventory (_GameCameras/HudCamera/Inventory): its border, the Inventory pane and the Charms pane. Where their
+pieces are (HUD units: the border's from the inventory's place, a pane's from the pane's own), the sprites they show,
+their texts (src/inv.c)."""
+import math
+import unity, tk2d, text
+
+ROOT = "_GameCameras/HudCamera/Inventory/"
+# the items the Inventory pane lists after the fixed ones (Build Equipment List: its order), by what has them:
+# (object, its name and description, the PlayerData that has it: a bool, or an int above 0)
+EQUIPMENT = [("Dash Cloak", "DASH", "hasDash"), ("Lantern", "LANTERN", "hasLantern"),
+ ("Map and Quill", "MAP", "hasMap"), ("City Key", "CITYKEY", "hasCityKey"), ("Simple Key", "SIMPLEKEY", "simpleKeys"),
+ ("Rancid Egg", "RANCIDEGG", "rancidEggs")]
+# (the map and the quill: Map's sprite, then its own, as they are had)
+QUILL = "QUILL"
+TRINKETS = 4
+
+
+def _doc():
+ return unity.prefab("resources.assets", 5473)
+
+
+def build(sprites, texts, res, charms, charm_icon):
+ """-> {define: value} for data.h. res: the HUD's resolution; charms: the charms this part of the game has;
+ charm_icon(id) -> the charm's icon sprite (drawn at CHARM_ICON_K)"""
+ d = _doc()
+ by = {o["path"]: o for o in d["objects"]}
+ U = lambda v: "%.4ff" % v
+ out = {}
+ sh = text.sheets()
+ inv = by[ROOT[:-1]]
+
+ def comp(o, cls):
+ return next((c["v"] for c in o["c"] if (c.get("class") or c["type"]) == cls and c.get("v") is not None), None)
+
+ def rel(o, base):
+ return o["pos"][0] - base["pos"][0], o["pos"][1] - base["pos"][1]
+
+ def turned(path, base):
+ """an object's sprite turned: "{sprite, x, y, kx, ky, degrees}" """
+ o = by[ROOT + path]
+ x, y = rel(o, base)
+ m = o["m3"]
+ sx, sy = math.hypot(m[0], m[3]), math.hypot(m[1], m[4])
+ deg = math.degrees(math.atan2(m[3], m[0]))
+ sr = comp(o, "SpriteRenderer")
+ sy = thick(sr, sy)
+ k = max(sx, sy)
+ return "{%d, %s, %s, %s, %s, %s}" % (sprites.id(d, sr["m_Sprite"], k, res), U(x), U(y), U(sx / k), U(sy / k), U(deg))
+
+ def thick(sr, sy):
+ """(a line thinner than a pixel here: one pixel, so that it shows)"""
+ s = unity.sprite(d["level"], tuple(d["externals"]), *sr["m_Sprite"])
+ px = s.h / s.ppu * sy * 100 / 8.7107
+ return sy * 1.2 / px if px < 1.2 else sy
+
+ def piece(path, base, scale=None, k=1.0):
+ """an object's sprite (SpriteRenderer or 2D Toolkit) at its place from base's, its scale (or a given one) ->
+ "{sprite, x, y, kx, ky}" (its sprite registered at the larger of its scales; drawn at kx, ky of that)"""
+ o = by[ROOT + path]
+ x, y = rel(o, base)
+ sx, sy = (o["m3"][0] * k, o["m3"][4] * k) if scale is None else scale
+ sr = comp(o, "SpriteRenderer")
+ if sr and sr.get("m_Sprite"):
+ sy = math.copysign(thick(sr, abs(sy)), sy)
+ m = max(abs(sx), abs(sy))
+ if sr and sr.get("m_Sprite"):
+ spr = sprites.id(d, sr["m_Sprite"], m, res)
+ else:
+ tk = comp(o, "tk2dSprite")
+ cp, cpid = tk2d.ref_file("resources.assets", {"m_FileID": tk["collection"][0], "m_PathID": tk["collection"][1]})
+ col = tk2d.collection(cp, cpid)
+ spr = sprites.tk2d(cp, cpid, unity.S(col["spriteDefinitions"][tk["_spriteId"]]["name"]), m, res)
+ return "{%d, %s, %s, %s, %s}" % (spr, U(x), U(y), U(sx / m), U(sy / m))
+
+ def at(path, base):
+ x, y = rel(by[ROOT + path], base)
+ return U(x), U(y)
+
+ def box(path, k=1.0):
+ """an object's collider: its size as the world has it (with its scales), its offset"""
+ o = by[ROOT + path]
+ bc = comp(o, "BoxCollider2D")
+ sx, sy = abs(o["m3"][0]), abs(o["m3"][4])
+ return "{%s, %s, %s, %s}" % (U(bc["m_Size"]["x"] * sx * k), U(bc["m_Size"]["y"] * sy * k),
+ U(bc["m_Offset"]["x"] * sx * k), U(bc["m_Offset"]["y"] * sy * k))
+
+ def tx(path, base):
+ """a text's place (TextMeshPro in its TextContainer, top aligned): "{x, top, width}", x its rect's left, center or
+ right as it is aligned (0 left, 1 center, 2 right)"""
+ o = by[ROOT + path]
+ x, y = rel(o, base)
+ tc, tm = comp(o, "TextContainer"), comp(o, "TextMeshPro")
+ k = o["m3"][0]
+ w, h = tc["m_rect"]["width"] * k, tc["m_rect"]["height"] * k
+ al = tm["m_textAlignment"] % 4
+ x0 = x - tc["m_pivot"]["x"] * w
+ top = y + (1 - tc["m_pivot"]["y"]) * h
+ return "{%s, %s, %s}" % (U(x0 + (0, w / 2, w, 0)[al]), U(top), U(w))
+
+ def txt(sheet, key, style):
+ return texts.add(text.clean(sh[sheet][key]), style)
+
+ # the inventory's place on the HUD; the border, from it
+ out["INV_X"], out["INV_Y"] = U(inv["pos"][0] - by["_GameCameras/HudCamera"]["pos"][0]), \
+ U(inv["pos"][1] - by["_GameCameras/HudCamera"]["pos"][1])
+ border = ["Border/Inv_Border_Corner TL", "Border/Inv_Border_Corner TR", "Border/Inv_Border_Corner (1)",
+ "Border/Inv_Border_Corner (2)", "Border/Inv_Border_Top", "Border/Inv_Border_Bottom"]
+ out["INV_BORDER"] = "{%s}" % ", ".join(piece(p, inv) for p in border)
+ out["INV_NBORDER"] = len(border)
+ # (the dark frame about it: smooth, kept small)
+ o = by[ROOT + "Border/Menu_Border_Black"]
+ x, y = rel(o, inv)
+ sr = comp(o, "SpriteRenderer")
+ out["INV_FRAME"] = "{%d, %s, %s, 1.0f, 1.0f}" % (sprites.id(d, sr["m_Sprite"], o["m3"][0], res * 0.25), U(x), U(y))
+ out["INV_ARROW_L"] = piece("Border/Arrow Left/Arrow Left", inv)
+ out["INV_ARROW_R"] = piece("Border/Arrow Right/Arrow Right", inv)
+ out["INV_PANE_ARROW_L"] = piece("Border/Pane Arrow L/Arrow", inv)
+ out["INV_PANE_ARROW_R"] = piece("Border/Pane Arrow R/Arrow", inv)
+ for n, p in (("NAME", "Pane Name"), ("NAME_L", "Pane Name L"), ("NAME_R", "Pane Name R")):
+ out["INV_PANE_" + n] = tx("Border/" + p, inv)
+ out["TXT_INV_PANES"] = "{%s}" % ", ".join("%d" % txt("UI", k, "TUTE") for k in ("PANE_INVENTORY", "PANE_CHARMS",
+ "PANE_JOURNAL", "PANE_MAP"))
+
+ # ---------------------------------------------------------------- the Charms pane
+ cp_ = by[ROOT + "Charms"]
+ out["CH_BB"] = piece("Charms/Backboards/BB 1", cp_)
+ out["CH_BB_POS"] = "{%s}" % ", ".join("{%s, %s}" % at("Charms/Backboards/BB %d" % i, cp_) for i in range(1, 41))
+ out["CH_BB_BOX"] = box("Charms/Backboards/BB 1")
+ # (each backboard's charm: InvCharmBackboard)
+ out["CH_BB_CHARM"] = "{%s}" % ", ".join(str(comp(by[ROOT + "Charms/Backboards/BB %d" % i], "InvCharmBackboard")["charmNum"])
+ for i in range(1, 41))
+ out["CH_GLOW"] = piece("Charms/Collected Charms/1/Glow", by[ROOT + "Charms/Collected Charms/1"])
+ gl = comp(by[ROOT + "Charms/Collected Charms/1/Glow"], "SpriteRenderer")["m_Color"]
+ out["CH_GLOW_A"] = U(gl["a"])
+ out["CH_ICONS"] = "{%s}" % ", ".join(str(charm_icon(i)) if i in charms else "-1" for i in range(41))
+ eq = by[ROOT + "Charms/Equipped Charms"]
+ nd = by[ROOT + "Charms/Equipped Charms/Next Dot"]
+ out["CH_NEXT_DOT"] = piece("Charms/Equipped Charms/Next Dot/Sprite", nd)
+ out["CH_NEXT_DOT_BOX"] = box("Charms/Equipped Charms/Next Dot")
+ # (an equipped charm's collider: its prefab's, at the scale it is made)
+ pc = unity.prefab("resources.assets", comp(eq, "BuildEquippedCharms")["gameObjectList"][0][1])
+ bc = comp(pc["objects"][0], "BoxCollider2D")
+ k = 1.15
+ out["CH_EQ_BOX"] = "{%s, %s, %s, %s}" % (U(bc["m_Size"]["x"] * k), U(bc["m_Size"]["y"] * k), U(bc["m_Offset"]["x"] * k),
+ U(bc["m_Offset"]["y"] * k))
+ out["CH_TEXT_EQUIPPED"] = tx("Charms/Equipped Charms/Text Equipped", cp_)
+ out["CH_NOTCH_FULL"] = piece("Charms/Equipped Charms/Notches/Charm Cost 1/Sprite Full",
+ by[ROOT + "Charms/Equipped Charms/Notches/Charm Cost 1"])
+ out["CH_NOTCH_EMPTY"] = piece("Charms/Equipped Charms/Notches/Charm Cost 1/Sprite Empty",
+ by[ROOT + "Charms/Equipped Charms/Notches/Charm Cost 1"])
+ out["CH_NOTCH_X"], out["CH_NOTCH_Y"] = at("Charms/Equipped Charms/Notches/Charm Cost 1", cp_)
+ x1 = rel(by[ROOT + "Charms/Equipped Charms/Notches/Charm Cost 2"], cp_)[0]
+ out["CH_NOTCH_DX"] = U(x1 - rel(by[ROOT + "Charms/Equipped Charms/Notches/Charm Cost 1"], cp_)[0])
+ be = comp(eq, "BuildEquippedCharms")
+ for n, c in (("FULL", be["notchFullColor"]), ("OVER", be["notchOverColor"])):
+ out["CH_NOTCH_%s_RGB" % n] = "{%d, %d, %d}" % tuple(round(c[q] * 255) for q in "rgb")
+ out["CH_TEXT_NOTCHES"] = tx("Charms/Equipped Charms/Notches/Text Notches", cp_)
+ out["CH_DIVIDER"] = piece("Charms/Equipped Charms/Inv_0017_divider", cp_)
+ out["CH_COST_TEXT"] = tx("Charms/Details/Cost/Text Cost", cp_)
+ out["CH_COST_PIP"] = piece("Charms/Details/Cost/Cost 1", by[ROOT + "Charms/Details/Cost/Cost 1"])
+ out["CH_COST_X"], out["CH_COST_Y"] = at("Charms/Details/Cost/Cost 1", cp_)
+ out["CH_COST_DX"] = U(rel(by[ROOT + "Charms/Details/Cost/Cost 2"], cp_)[0] - rel(by[ROOT + "Charms/Details/Cost/Cost 1"], cp_)[0])
+ out["CH_DETAIL_X"], out["CH_DETAIL_Y"] = at("Charms/Details/Detail Sprite", cp_)
+ out["CH_NAME"] = tx("Charms/Text Name", cp_)
+ out["CH_DESC"] = tx("Charms/Text Desc", cp_)
+ out["CH_CONFIRM"] = tx("Charms/Confirm Action/Text", cp_)
+ # (its button: the keyboard's key box, as ActionButtonIcon shows it with a keyboard)
+ o = by[ROOT + "Charms/Confirm Action/ActionButtonIcon"]
+ x, y = rel(o, cp_)
+ key = comp(by[ROOT + "Inv/Item Control/IconDashSlash"], "SpriteRenderer")["m_Sprite"]
+ out["CH_CONFIRM_KEY"] = "{%d, %s, %s, 1.0f, 1.0f}" % (sprites.id(d, key, o["m3"][0], res), U(x), U(y))
+ ks = unity.sprite(d["level"], tuple(d["externals"]), *key)
+ out["CH_CONFIRM_KEY_W"] = U(ks.w / ks.ppu * o["m3"][0])
+ out["CH_CURSOR"] = piece("Charms/Cursor/TL/Sprite", by[ROOT + "Charms/Cursor/TL"])
+ cur = by[ROOT + "Charms/Cursor"]
+ out["CH_CURSOR_K"] = "{%s, %s}" % (U(cur["m3"][0]), U(cur["m3"][4]))
+ # (the corners' own scales: TL, TR, BL, BR)
+ out["CH_CURSOR_CORNERS"] = "{%s}" % ", ".join(
+ "{%s, %s}" % (U(by[ROOT + "Charms/Cursor/" + c]["lscale"][0] / 1.4), U(by[ROOT + "Charms/Cursor/" + c]["lscale"][1] / 1.4))
+ for c in ("TL", "TR", "BL", "BR"))
+ for key, style in (("CHARM_TXT_EQUIPPED", "TUTE"), ("CHARM_TXT_OVERCHARMED", "TUTE"), ("CHARM_TXT_COST", "MSG"),
+ ("CTRL_EQUIP", "MSG"), ("CTRL_UNEQUIP", "MSG"), ("CHARM_ALERT_NONE", "MSG"),
+ ("CHARM_ALERT_NONE_BENCH", "MSG")):
+ out["TXT_" + key] = txt("UI", key, style)
+ out["TXT_CHARM_NOTCHES"] = texts.add(text.clean(sh["UI"].get("CHARM_TXT_NOTCHES", "Notches")), "MSG")
+ out["TXT_CHARM_NAMES_INV"] = "{%s}" % ", ".join(
+ str(txt("UI", "CHARM_NAME_%d" % i, "DIALOGUE")) if i in charms else "-1" for i in range(41))
+ out["TXT_CHARM_DESCS"] = "{%s}" % ", ".join(
+ str(txt("UI", "CHARM_DESC_%d" % i, "MSG")) if i in charms else "-1" for i in range(41))
+ out["TXT_KEY_OK"] = texts.add("OK", "MSG")
+
+ # ---------------------------------------------------------------- the Inventory pane
+ ip = by[ROOT + "Inv"]
+ items = by[ROOT + "Inv/Inv_Items"]
+ fixed = [("Heart Pieces", None), ("Soul Orb", None), ("Nail", None), ("Spell Fireball", "Fireball Bg"),
+ ("Spell Focus", "Focus Ring"), ("Geo", None)]
+ out["INV_FIXED"] = "{%s}" % ", ".join(piece("Inv/Inv_Items/" + n, ip) for n, _ in fixed)
+ out["INV_FIXED_BG"] = "{%s}" % ", ".join(piece("Inv/Inv_Items/%s/%s" % (n, b), ip) if b else "{-1, 0, 0, 0, 0}"
+ for n, b in fixed)
+ out["INV_FIXED_BOX"] = "{%s}" % ", ".join(box("Inv/Inv_Items/" + n) for n, _ in fixed)
+ out["INV_HEART_PIECES"] = "{%s}" % ", ".join(piece("Inv/Inv_Items/Heart Pieces/Pieces %d" % i, ip) for i in range(1, 5))
+ out["INV_VESSEL_PIECES"] = "{%s}" % ", ".join(piece("Inv/Inv_Items/Soul Orb/" + p, ip) for p in ("Piece 1", "Piece 2", "Piece All"))
+ out["INV_GEO_TEXT"] = tx("Inv/Inv_Items/Geo/Geo Amount", ip)
+ eqp = by[ROOT + "Inv/Equipment"]
+ # (Build Equipment List's places: equip_position's first, its steps, four to a row)
+ out["INV_EQ_X"], out["INV_EQ_Y"], out["INV_EQ_DX"], out["INV_EQ_DY"] = U(1.1), U(-3.8), U(2.08), U(-2.18)
+ out["INV_EQ"] = "{%s}" % ", ".join(piece("Inv/Equipment/" + n, eqp) for n, _, _ in EQUIPMENT)
+ out["INV_EQ_BOX"] = "{%s}" % ", ".join(box("Inv/Equipment/" + n) for n, _, _ in EQUIPMENT)
+ out["INV_TRINKETS"] = "{%s}" % ", ".join(piece("Inv/Equipment/Trinket%d" % i, ip) for i in range(1, TRINKETS + 1))
+ out["INV_TRINKET_BOX"] = "{%s}" % ", ".join(box("Inv/Equipment/Trinket%d" % i) for i in range(1, TRINKETS + 1))
+ out["INV_TRINKET_TEXT"] = tx("Inv/Equipment/Trinket1/T1 Amount", by[ROOT + "Inv/Equipment/Trinket1"])
+ out["INV_TRINKET_BB"] = piece("Inv/trinket_backboard", ip)
+ out["INV_DIVIDERS"] = "{%s, %s}" % (turned("Inv/Divider L", ip), turned("Inv/Divider R", ip))
+ out["INV_NAME"] = tx("Inv/Text Name", ip)
+ out["INV_DESC"] = tx("Inv/Text Desc", ip)
+ ui = lambda k: txt("UI", k, "DIALOGUE")
+ uid = lambda k: txt("UI", k, "MSG")
+ # (the fixed items' names and descriptions, by their state: Mask Shards none yet, 0..3, all; Vessel Fragments none
+ # yet, 0..2, all; the nail; Vengeful Spirit; Focus; Geo)
+ out["TXT_INV_HEART"] = "{%s}" % ", ".join("{%d, %d}" % (ui("INV_NAME_HEARTPIECE_" + h), uid("INV_DESC_HEARTPIECE_" + h))
+ for h in ("NONE", "0", "1", "2", "3", "ALL"))
+ out["TXT_INV_VESSEL"] = "{%s}" % ", ".join("{%d, %d}" % (ui("INV_NAME_SOULORBS_" + v), uid("INV_DESC_SOULORBS_" + v))
+ for v in ("NONE", "0", "1", "2", "ALL"))
+ out["TXT_INV_FIXED"] = "{%s}" % ", ".join("{%d, %d}" % (ui("INV_NAME_" + k), uid("INV_DESC_" + k))
+ for k in ("NAIL1", "SPELL_FIREBALL1", "SPELL_FOCUS", "GEO"))
+ out["TXT_INV_EQ"] = "{%s}" % ", ".join("{%d, %d}" % (ui("INV_NAME_" + k), uid("INV_DESC_" + k)) for _, k, _ in EQUIPMENT)
+ out["TXT_INV_QUILL"] = "{%d, %d, %d, %d}" % (ui("INV_NAME_QUILL"), uid("INV_DESC_QUILL"), ui("INV_NAME_MAPQUILL"),
+ uid("INV_DESC_MAPQUILL"))
+ out["TXT_INV_TRINKETS"] = "{%s}" % ", ".join("{%d, %d}" % (ui("INV_NAME_TRINKET%d" % i), uid("INV_DESC_TRINKET%d" % i))
+ for i in range(1, TRINKETS + 1))
+ texts.add("0123456789", "MSG")
+ return out
diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.py
index dbeb9f0a..abffe620 100644
--- a/games/hollowknight/tools/pack.py
+++ b/games/hollowknight/tools/pack.py
@@ -510,16 +510,20 @@ def main():
if vm.NOTICE_ICONS else "{-1}"
pmenu = unity.scene("Menu_Title")
icl = next(c["v"] for o in pmenu["objects"] for c in o["c"] if c.get("class") == "CharmIconList")["spriteList"]
- fleurs["CHARM_ICONS"] = "{%s}" % ", ".join(str(SPRITES.id(pmenu, icl[i], 1.0, hud_res)) if i in vm.CHARMS else "-1"
- for i in range(41))
+ # (the charms' icons as big as the inventory shows them: its details', CHARM_ICON_K; smaller elsewhere)
+ icon_k = 1.5
+ charm_icon = lambda i: SPRITES.id(pmenu, icl[i], icon_k, hud_res)
+ fleurs["CHARM_ICON_K"] = "%.4ff" % icon_k
+ fleurs["CHARM_ICONS"] = "{%s}" % ", ".join(str(charm_icon(i)) if i in vm.CHARMS else "-1" for i in range(41))
fleurs["CHARM_NAMES"] = "{%s}" % ", ".join(
str(TEXTS.add(text.clean(text.sheets()["UI"]["CHARM_NAME_%d" % i]), "NOTICE")) if i in vm.CHARMS else "-1"
for i in range(41))
for key, style in (("CHARM_TUTE_TITLE", "TUTE_TITLE"), ("CHARM_TUTE_SUB", "TUTE"), ("CHARM_REMINDER", "TUTE")):
fleurs["TXT_" + key] = TEXTS.add(text.clean(text.sheets()["Prompts"][key]), style)
# the title screen, the save profiles, the pause menu; each room's map zone (the save slots' area)
- import menu
+ import menu, inv
fleurs.update(menu.build(SPRITES, TEXTS))
+ fleurs.update(inv.build(SPRITES, TEXTS, hud_res, vm.CHARMS, charm_icon))
fleurs["ROOM_ZONES"] = "{%s}" % ", ".join(str(scene.settings(unity.scene(r)).get("map_zone") or 0) for r in ROOMS)
for i, item in enumerate(text.MSGS):
fleurs["MSG_" + item] = i
@@ -604,8 +608,8 @@ def main():
t = texs[len(variants) - len(sprites) + j]
nb = sum(len(b) for b in coded[t.first_block:t.first_block + (t.ntiles + art.BLOCK_TILES - 1) // art.BLOCK_TILES]) if t.fmt not in (art.FMT_SOFTA, art.FMT_SOFT) else len(t.soft or b"")
nb += (len(t.pal.tobytes()) if t.pal is not None else 0)
- tot[str(sp.get("key", ("?",)))[:30].split(",")[0]] += nb
- for k, v in tot.most_common(40):
+ tot[sp["job"].name if os.environ.get("ACTSTATS") == "clip" else sp["job"].name.split("/")[0]] += nb
+ for k, v in tot.most_common(80):
print("ACT", v, k)
secs["TEX"].b += struct.pack("<I", len(variants)) + texrec
# actors: each sprite frame's texture and where its top-left corner is (local units), units a texel; the clips