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: title screen, save profiles and pause menu

Mason Chenf4e92db70e63
diff --git a/games/hollowknight/Makefile b/games/hollowknight/Makefile
index 61b807c9..ef6c880e 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/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/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 d7b473f8..2710b6f7 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 8a085745..5399cdb5 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 2444
+#define SPRITE_DIGIT0 2460
#define STYLE_DIALOGUE 0
#define STYLE_PROMPT 1
#define STYLE_TITLE_L 2
@@ -575,6 +575,9 @@
#define STYLE_TITLE_SUB 4
#define STYLE_MSG 5
#define STYLE_MSG_NAME 6
+#define STYLE_MENU 7
+#define STYLE_MENU_TITLE 8
+#define STYLE_MENU_SMALL 9
#define TEXT_K 1.333333f
#define FONT_PHASES 4
#define EK_CRAWLER 1
@@ -788,5 +791,73 @@
#define SPRITE_MSG_ICON_DASH 2244
#define SPRITE_GRASS_BALL 2245
#define MSG_TABLE {{107, 108, 109, 110, 111, 112}, {113, 114, 115, 116, 117, 118}}
+#define MENU_LOGO {2246, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_LOGO_Y 3.6585f
+#define MENU_START_Y -1.4181f
+#define MENU_QUIT_Y -2.3582f
+#define MENU_POINTER {2247, 0.0000f, 0.0000f, 1.0023f, 1.0000f}
+#define MENU_POINTER_GAP 0.7525f
+#define MENU_PROFILES_TITLE_Y 6.4481f
+#define MENU_PROFILES_FLEUR {2248, 0.0000f, 0.0000f, 1.0000f, 1.0807f}
+#define MENU_PROFILES_FLEUR_Y 5.4077f
+#define MENU_SLOT_X -2.8186f
+#define MENU_SLOT_Y 3.1252f
+#define MENU_SLOT_DY -2.3269f
+#define MENU_SLOT_ZONES {{2, {2249, 0.0000f, 0.0000f, 1.0000f, 1.0000f}}, {4, {2250, 0.0000f, 0.0000f, 1.0000f, 1.0000f}}, {5, {2251, 0.0000f, 0.0000f, 1.0000f, 1.0000f}}, {6, {2252, 0.0000f, 0.0000f, 1.0000f, 1.0000f}}, {22, {2253, 0.0000f, 0.0000f, 1.0000f, 1.0000f}}}
+#define MENU_SLOT_NZONES 5
+#define MENU_SLOT_BG_DY 0.0102f
+#define MENU_SLOT_FLEUR {2254, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_SLOT_FLEUR_X 0.0000f
+#define MENU_SLOT_FLEUR_Y 0.4512f
+#define MENU_SLOT_SELECTOR {2255, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_SLOT_SELECTOR_X -0.1626f
+#define MENU_SLOT_SELECTOR_Y 0.0813f
+#define MENU_SLOT_CURSOR {2256, 0.0000f, 0.0000f, 1.0000f, 1.0025f}
+#define MENU_SLOT_CURSOR_X -8.2367f
+#define MENU_SLOT_CURSOR_Y 0.0000f
+#define MENU_SLOT_ORB {2257, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_SLOT_ORB_X -4.3089f
+#define MENU_SLOT_ORB_Y 0.1230f
+#define MENU_SLOT_GEO {2258, 0.0000f, 0.0000f, 1.0039f, 1.0000f}
+#define MENU_SLOT_GEO_X -3.6961f
+#define MENU_SLOT_GEO_Y -0.5395f
+#define MENU_SLOT_HEALTH {2259, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_SLOT_HEALTH_X -3.5916f
+#define MENU_SLOT_HEALTH_Y 0.3577f
+#define MENU_SLOT_CURSOR_X2 8.0334f
+#define MENU_SLOT_HEALTH_DX 0.5274f
+#define MENU_SLOT_NUM_X -6.4532f
+#define MENU_SLOT_NEW_X -5.0558f
+#define MENU_SLOT_LOC_X 7.0070f
+#define MENU_SLOT_LOC_Y 0.4573f
+#define MENU_SLOT_TIME_X 7.0045f
+#define MENU_SLOT_TIME_Y -0.6885f
+#define MENU_SLOT_GEOTXT_X -3.1737f
+#define MENU_SLOT_GEOTXT_Y -0.5395f
+#define MENU_SLOT_CLEAR_X 11.7199f
+#define MENU_SLOT_PROMPT_X -2.7845f
+#define MENU_SLOT_YES_X 2.5813f
+#define MENU_SLOT_NO_X 6.2296f
+#define MENU_BACK_Y -5.5406f
+#define MENU_PAUSE_TOP {2260, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_PAUSE_TOP_Y 2.3653f
+#define MENU_PAUSE_BOT {2261, 0.0000f, 0.0000f, 1.0000f, 1.0000f}
+#define MENU_PAUSE_BOT_Y -1.8877f
+#define MENU_PAUSE_CONTINUE_Y 0.6428f
+#define MENU_PAUSE_QUIT_Y -0.4548f
+#define TXT_MAIN_START 119
+#define TXT_MAIN_QUIT 120
+#define TXT_PROFILE_NEW_GAME 121
+#define TXT_PROFILE_CLEAR_BUTTON 122
+#define TXT_PROFILE_CLEAR_PROMPT 123
+#define TXT_NAV_YES 124
+#define TXT_NAV_NO 125
+#define TXT_NAV_BACK 126
+#define TXT_PAUSE_CONTINUE 127
+#define TXT_PAUSE_MAIN 128
+#define TXT_PROFILE_CORRUPTED 129
+#define TXT_SCREEN_SAVE_PROFILES 130
+#define TXT_ZONES {131, 132, 133, 134, 135}
+#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/enemy.c b/games/hollowknight/src/enemy.c
index d20793b6..f7b0e79b 100644
--- a/games/hollowknight/src/enemy.c
+++ b/games/hollowknight/src/enemy.c
@@ -6490,7 +6490,7 @@ void enemies_fixed(void) {
else if (FSM(e) == EF_MOSSKNIGHT) mossknight_fixed(e);
recoil_fixed(e);
if (wants_contacts(e)) {
- float pvx = e->body.vx, pvy = e->body.vy, box[4];
+ float pvx = e->body.vx, pvy = e->body.vy, box[4] = {0};
int had = e->body.ncontacts;
e->body.events = body_events;
if (FSM(e) == EF_MOSQUITO) mosquito_box(e, box);
diff --git a/games/hollowknight/src/game.c b/games/hollowknight/src/game.c
index 6afc7c0a..0d031c11 100644
--- a/games/hollowknight/src/game.c
+++ b/games/hollowknight/src/game.c
@@ -319,6 +319,7 @@ static void step(uint32_t keys) {
void game_tick(uint32_t keys) {
Game *g = &g_game;
+ g_pd.play_time += 0.02f; /* (GameManager: PlayerData's playTime, in real time) */
freeze_tick(0.02f);
scene_tick(0.02f);
/* (game time runs at the time scale: frozen, no steps) */
@@ -329,7 +330,9 @@ void game_tick(uint32_t keys) {
}
}
-void game_draw(void) {
+bool game_changing_room(void) { return g_game.scene_phase != SP_NONE; }
+
+void game_draw_layers(void) {
hud_draw();
msg_draw();
titles_draw();
@@ -340,5 +343,9 @@ void game_draw(void) {
hero_draw();
fireballs_draw();
death_draw();
+}
+
+void game_draw(void) {
+ game_draw_layers();
gfx_frame();
}
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index e9025d4c..a552538d 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -36,7 +36,8 @@ typedef struct {
uint8_t elderbug; /* (Elderbug's state) */
uint8_t hornet_greenpath; /* (hornetGreenpath: her encounters in Greenpath) */
uint8_t quirrel_egg_temple; /* (quirrelEggTemple: his talks at the Black Egg) */
- uint8_t reserved[59];
+ uint8_t map_zone; /* (mapZone: the room's, as it is entered; the save profiles show its area) */
+ uint8_t reserved[58];
/* (saved apart, by the objects' names: their states) */
uint8_t persist[MAX_PERSIST / 8];
/* (not saved) */
@@ -55,6 +56,16 @@ bool save_game(void);
bool save_load(int slot);
bool save_exists(int slot);
void save_select(int slot);
+/* (SaveStats: what the save profiles show of a slot's game) */
+typedef struct {
+ int8_t max_health;
+ uint8_t zone;
+ int16_t mp_reserve_max;
+ int32_t geo;
+ float play_time;
+} SaveStats;
+int save_stats(int slot, SaveStats *st); /* -> 0 no game, 1 a game, -1 a file that does not check out */
+bool save_clear(int slot);
void save_set_respawn(const char *marker, bool facing_right); /* (Bench Control's Rest Burst) */
/* ---------------------------------------------------------------- the room's game objects (tools/ents.py) */
@@ -322,6 +333,14 @@ bool game_enter(int room, float x, float y, bool facing_right);
bool game_respawn(void); /* the Knight at the save's respawn point (a loaded game, after dying) */
void game_tick(uint32_t keys); /* 1/50 s */
void game_draw(void);
+void game_draw_layers(void); /* (what the game draws, before the frame is made) */
+bool game_changing_room(void);
+/* the title screen, the save profiles, the pause menu (menu.c) */
+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);
+bool menu_quit(void);
/* ---------------------------------------------------------------- text (text.c) */
#define TEXT_BR 10 /* (in a text: a line break, a page break) */
diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.c
index adad85c6..1ceeeaf4 100644
--- a/games/hollowknight/src/gfx.c
+++ b/games/hollowknight/src/gfx.c
@@ -95,7 +95,10 @@ static void make_luts(void) {
}
static bool grade_off; /* (the HUD's tints: the room's grading not for them) */
-#define HUD_TINT 240 /* (dynamic tints from slot 16 on are the HUD's) */
+#define HUD_TINT 240 /* (dynamic tints from slot 16 on are the HUD's: 16 the HUD's white, 17 its soul, 18-20 the
+ dialogue's, 21 the area title's, 22-26 the item message's, 27 and 28 the blankers, 29-31
+ the menus'; below, the room's: 0 the Knight's, 1 his light, 2-6 and 10, 11, 15 the
+ enemies', 7 the prompts', 8, 9, 12-14 the scripts' objects') */
static uint32_t grade(float r, float g, float b, float a) {
/* r g b a: 0..1 straight */
@@ -1239,8 +1242,11 @@ static bool add_item(const Inst *in, float blur_z) {
return true;
}
+bool g_gfx_no_room;
+
void gfx_frame(void) {
- if (lut_room != g_room.id) make_luts();
+ bool roomless = g_room.h == NULL || g_gfx_no_room; /* (the title screen: the HUD's alone) */
+ if (!roomless && lut_room != g_room.id) make_luts();
tex_frame();
pal_frame++;
if (!pal_frame) pal_frame = 1;
@@ -1248,16 +1254,15 @@ void gfx_frame(void) {
arena_top = 0;
bg_on = false;
g_gfx_dropped = 0;
- float blur_z = g_room.h->blur_z;
+ float blur_z = roomless ? 1e9f : g_room.h->blur_z;
/* the instances near the camera, back to front, and the actors among them: what is behind the blur plane is drawn
* now (small), the rest kept */
- room_near(g_cam_x, g_cam_y);
- room_first();
Item cur;
uint32_t group;
int na = 0;
+ if (!roomless) room_near(g_cam_x, g_cam_y), room_first();
/* (an actor behind the blur plane but in front of what is kept, by its sorting layer: kept too) */
- while (room_next(&cur.in, &group)) {
+ while (!roomless && room_next(&cur.in, &group)) {
while (na < nactors && (actors[na].group < group || (actors[na].group == group && actors[na].in.z > cur.in.z)))
add_item(&actors[na++].in, nitems ? 1e9f : blur_z);
add_item(&cur.in, blur_z);
diff --git a/games/hollowknight/src/hk.h b/games/hollowknight/src/hk.h
index 91df8e66..ba59ecc3 100644
--- a/games/hollowknight/src/hk.h
+++ b/games/hollowknight/src/hk.h
@@ -33,6 +33,7 @@ void plat_push(int x, int y, int w, int h, const uint16_t *px);
void plat_fill(int x, int y, int w, int h, uint16_t c);
bool plat_save(const char *name, const void *data, uint32_t len);
const uint8_t *plat_load(const char *name, uint32_t *len);
+bool plat_remove(const char *name);
/* ---------------------------------------------------------------- data.bin */
extern const uint8_t *hk_bin;
@@ -213,6 +214,7 @@ uint8_t gfx_dyn_tint(int slot, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*
/* the same, flashing: its colors towards (fr, fg, fb) by amount (SpriteFlash) */
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') */
/* 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/main.c b/games/hollowknight/src/main.c
index 3ad3390d..3edf1538 100644
--- a/games/hollowknight/src/main.c
+++ b/games/hollowknight/src/main.c
@@ -45,33 +45,20 @@ int main(void) {
return plat_end();
}
#else
-/* a new game: the Knight at King's Pass' respawn point */
-static void start(void) {
- game_new();
- room_load(ROOM_TUTORIAL_01);
- int n;
- const Ent *e = room_ents(&n);
- float x = 35.46f, y = 11.37f;
- bool right = true;
- for (int i = 0; i < n; i++)
- if (e[i].type == ENT_RESPAWN) x = e[i].x0, y = e[i].y0, right = e[i].flags & FACING_RIGHT;
- game_enter(ROOM_TUTORIAL_01, x, y, right);
-}
-
int main(void) {
plat_begin();
hk_bin = hk_data;
plat_fill(0, 0, SCREEN_W, SCREEN_H, 0);
- start();
+ menu_start();
uint32_t last = plat_millis(), acc = 0;
for (;;) {
uint32_t keys = plat_keys();
- if (keys & K_HOME) break;
+ if ((keys & K_HOME) || menu_quit()) break;
uint32_t now = plat_millis();
acc += now - last, last = now;
int ticks = 0;
while (acc >= TICK_MS && ticks < MAX_TICKS) {
- game_tick(keys);
+ if (!menu_tick(keys)) game_tick(keys);
acc -= TICK_MS, ticks++, perf_updates++;
}
if (ticks == MAX_TICKS) acc = 0; /* (too slow to catch up: the game slows down instead) */
@@ -79,7 +66,11 @@ int main(void) {
plat_sleep(TICK_MS - acc);
continue;
}
- game_draw();
+ /* (the game, or the title screen and the save profiles alone; the pause menu over the game) */
+ g_gfx_no_room = !menu_in_game();
+ if (menu_in_game()) game_draw_layers();
+ menu_draw();
+ gfx_frame();
perf_frames++;
}
return plat_end();
diff --git a/games/hollowknight/src/menu.c b/games/hollowknight/src/menu.c
new file mode 100644
index 00000000..543319be
--- /dev/null
+++ b/games/hollowknight/src/menu.c
@@ -0,0 +1,268 @@
+/* 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. */
+#include <stdio.h>
+#include "game.h"
+
+#define DT 0.02f
+#define HUD_PX (FOCAL / (-1.342f - CAM_Z)) /* (pixels a HUD unit) */
+#define FADE_TIME 0.2f /* (MENU_FADE_SPEED 5: a screen fades in, out in a fifth of a second) */
+
+typedef struct {
+ int16_t sprite;
+ float ox, oy, sx, sy; /* (its pivot from its rect's center; its scale as drawn) */
+} Piece;
+typedef struct {
+ uint8_t zone;
+ Piece p;
+} ZonePiece;
+
+static const Piece logo = MENU_LOGO, pointer = MENU_POINTER, profiles_fleur = MENU_PROFILES_FLEUR,
+ slot_fleur = MENU_SLOT_FLEUR, slot_selector = MENU_SLOT_SELECTOR, slot_cursor = MENU_SLOT_CURSOR,
+ slot_orb = MENU_SLOT_ORB, slot_geo = MENU_SLOT_GEO, slot_health = MENU_SLOT_HEALTH,
+ pause_top = MENU_PAUSE_TOP, pause_bot = MENU_PAUSE_BOT;
+static const ZonePiece zone_bgs[MENU_SLOT_NZONES] = MENU_SLOT_ZONES;
+static const int16_t zone_texts[MENU_SLOT_NZONES] = TXT_ZONES;
+
+enum { MS_TITLE, MS_PROFILES, MS_GAME, MS_PAUSE };
+/* (the save profiles' rows: the slots, then Back; a slot's Clear Save, its prompt's Yes and No) */
+enum { PS_SLOT, PS_CLEAR, PS_PROMPT_NO, PS_PROMPT_YES };
+
+static struct {
+ uint8_t screen, sel, part;
+ uint32_t prev_keys;
+ float t; /* (time on this screen: its fade in) */
+ int8_t state[SAVE_SLOTS]; /* (save_stats: 0 none, 1 a game, -1 corrupted) */
+ SaveStats stats[SAVE_SLOTS];
+ char num[SAVE_SLOTS][3], geo[SAVE_SLOTS][12], time[SAVE_SLOTS][16];
+ bool quit;
+} mn;
+
+static void read_slots(void) {
+ for (int i = 0; i < SAVE_SLOTS; i++) {
+ mn.state[i] = (int8_t)save_stats(i, &mn.stats[i]);
+ mn.num[i][0] = (char)('1' + i), mn.num[i][1] = '.', mn.num[i][2] = 0;
+ snprintf(mn.geo[i], sizeof mn.geo[i], "%ld", (long)mn.stats[i].geo);
+ /* (SaveStats.GetPlaytimeHHMM: hours if any, then minutes) */
+ float pt = mn.stats[i].play_time;
+ unsigned m = pt > 0 && pt < 3.6e8f ? (unsigned)(pt / 60) : 0, h = m / 60;
+ if (h) snprintf(mn.time[i], sizeof mn.time[i], "%uh %02um", h % 100000u, m % 60);
+ else snprintf(mn.time[i], sizeof mn.time[i], "%um", m);
+ }
+}
+
+static void go(int screen, int sel) {
+ mn.screen = (uint8_t)screen, mn.sel = (uint8_t)sel, mn.part = PS_SLOT, mn.t = 0;
+ if (screen == MS_PROFILES) read_slots();
+}
+
+void menu_start(void) {
+ memset(&mn, 0, sizeof mn);
+ go(MS_TITLE, 0);
+}
+
+bool menu_quit(void) { return mn.quit; }
+bool menu_in_game(void) { return mn.screen == MS_GAME || mn.screen == MS_PAUSE; }
+
+/* a new game in a slot: the Knight at King's Pass' respawn point */
+static void new_game(int slot) {
+ game_new();
+ save_select(slot);
+ room_load(ROOM_TUTORIAL_01);
+ int n;
+ const Ent *e = room_ents(&n);
+ float x = 35.46f, y = 11.37f;
+ bool right = true;
+ for (int i = 0; i < n; i++)
+ if (e[i].type == ENT_RESPAWN) x = e[i].x0, y = e[i].y0, right = e[i].flags & FACING_RIGHT;
+ game_enter(ROOM_TUTORIAL_01, x, y, right);
+}
+
+/* (a slot chosen: its game loaded, at its bench; or a new one) */
+static void pick_slot(int slot) {
+ if (mn.state[slot] == 1) {
+ game_new();
+ if (!save_load(slot) || !game_respawn()) {
+ /* (a file that does not load after all: shown as corrupted) */
+ mn.state[slot] = -1;
+ return;
+ }
+ } else if (mn.state[slot] == 0)
+ new_game(slot);
+ else
+ return; /* (a corrupted save: only cleared) */
+ go(MS_GAME, 0);
+}
+
+/* the keys newly down this frame */
+static uint32_t pressed(uint32_t keys) { return keys & ~mn.prev_keys; }
+
+bool menu_tick(uint32_t keys) {
+ uint32_t p = pressed(keys);
+ mn.prev_keys = keys;
+ mn.t += DT;
+ switch (mn.screen) {
+ case MS_TITLE:
+ /* Start Game, Quit Game */
+ if (p & (K_UP | K_DOWN)) mn.sel ^= 1;
+ if (p & K_OK) {
+ if (mn.sel == 0) go(MS_PROFILES, 0);
+ else mn.quit = true;
+ }
+ return true;
+ case MS_PROFILES:
+ if (mn.part >= PS_PROMPT_NO) {
+ /* Clear Save?: No, Yes */
+ if (p & (K_LEFT | K_RIGHT)) mn.part = mn.part == PS_PROMPT_NO ? PS_PROMPT_YES : PS_PROMPT_NO;
+ if (p & K_BACK) mn.part = PS_CLEAR;
+ else if (p & K_OK) {
+ if (mn.part == PS_PROMPT_YES) save_clear(mn.sel), read_slots(), mn.part = PS_SLOT;
+ else mn.part = PS_CLEAR;
+ }
+ return true;
+ }
+ if (p & K_UP) mn.sel = (uint8_t)(mn.sel ? mn.sel - 1 : SAVE_SLOTS), mn.part = PS_SLOT;
+ if (p & K_DOWN) mn.sel = (uint8_t)(mn.sel < SAVE_SLOTS ? mn.sel + 1 : 0), mn.part = PS_SLOT;
+ /* (a slot with a game, or a corrupted one: its Clear Save, to the right) */
+ if ((p & K_RIGHT) && mn.sel < SAVE_SLOTS && mn.state[mn.sel]) mn.part = PS_CLEAR;
+ if (p & K_LEFT) mn.part = PS_SLOT;
+ if (p & K_BACK) go(MS_TITLE, 0);
+ else if (p & K_OK) {
+ if (mn.sel == SAVE_SLOTS) go(MS_TITLE, 0);
+ else if (mn.part == PS_CLEAR) mn.part = PS_PROMPT_NO;
+ else pick_slot(mn.sel);
+ }
+ return true;
+ case MS_GAME:
+ /* (the pause key: the game paused, unless PlayerData's disablePause or a room changing) */
+ if ((p & K_PAUSE) && !g_pd.disable_pause && !game_changing_room()) {
+ go(MS_PAUSE, 0);
+ return true;
+ }
+ return false;
+ case MS_PAUSE:
+ if (p & (K_UP | K_DOWN)) mn.sel ^= 1;
+ if (p & (K_PAUSE | K_BACK)) go(MS_GAME, 0);
+ else if (p & K_OK) {
+ if (mn.sel == 0) go(MS_GAME, 0);
+ else {
+ /* Quit to Menu: the game saved (the Knight at his bench as it loads), the title */
+ save_game();
+ go(MS_TITLE, 0);
+ }
+ }
+ return true;
+ }
+ return false;
+}
+
+/* ---------------------------------------------------------------- drawing */
+static uint8_t white(int slot, float a) { return gfx_dyn_tint(29 + slot, 255, 255, 255, (uint8_t)(a * 255 + 0.5f)); }
+
+static void piece(const Piece *pc, float cx, float cy, bool flip, uint8_t tint) {
+ Inst in;
+ sprite_inst(pc->sprite, cx + (flip ? -pc->ox : pc->ox), cy + pc->oy, 0, flip ? -pc->sx : pc->sx, pc->sy, tint, &in);
+ gfx_hud(&in, 0);
+}
+
+/* a text: its x its center (align 0), left (1) or right (2), y its middle (HUD units) -> its width (HUD units) */
+static float text_at(int style, const uint8_t *s, int n, float x, float y, int align, float a) {
+ const uint8_t *st = font_style(style);
+ float w = text_width(style, s, n), px = VIEW_W / 2 + x * HUD_PX - (align == 0 ? w / 2 : align == 2 ? w : 0);
+ /* (Trajan's capitals: their middle at y) */
+ gfx_text(style, px, VIEW_H / 2 - y * HUD_PX + font_asc(st) * 0.36f, s, n, (uint32_t)(a * 255 + 0.5f) << 24 | 0xFFFFFF, 0);
+ return w / HUD_PX;
+}
+
+static float text_id(int style, int id, float x, float y, int align, float a) {
+ const uint8_t *s = text_get(id);
+ int n = 0;
+ while (s[n] && s[n] != TEXT_BR) n++;
+ return text_at(style, s, n, x, y, align, a);
+}
+
+/* a button: its text centered on x at y, its pointers either side if selected */
+static void button(int text, float x, float y, bool sel, float a) {
+ float w = text_id(STYLE_MENU, text, x, y, 0, a);
+ if (!sel) return;
+ piece(&pointer, x - w / 2 - MENU_POINTER_GAP, y, false, white(0, a));
+ piece(&pointer, x + w / 2 + MENU_POINTER_GAP, y, true, white(0, a));
+}
+
+static void draw_slot(int i, float a) {
+ float cx = MENU_SLOT_X, cy = MENU_SLOT_Y + i * MENU_SLOT_DY;
+ bool sel = mn.sel == i;
+ uint8_t full = white(0, a);
+ if (sel && mn.part == PS_SLOT) {
+ /* (Selector: the slot lit; its cursors) */
+ piece(&slot_selector, cx + MENU_SLOT_SELECTOR_X, cy + MENU_SLOT_SELECTOR_Y, false, white(1, a * 0.5f));
+ piece(&slot_cursor, cx + MENU_SLOT_CURSOR_X, cy + MENU_SLOT_CURSOR_Y, false, full);
+ piece(&slot_cursor, cx + MENU_SLOT_CURSOR_X2, cy + MENU_SLOT_CURSOR_Y, true, full);
+ }
+ text_at(STYLE_MENU_TITLE, (const uint8_t *)mn.num[i], 2, cx + MENU_SLOT_NUM_X, cy, 0, a);
+ if (mn.part >= PS_PROMPT_NO && sel) {
+ /* Clear Save?: No, Yes */
+ text_id(STYLE_MENU, TXT_PROFILE_CLEAR_PROMPT, cx + MENU_SLOT_PROMPT_X, cy, 0, a);
+ float wy = text_id(STYLE_MENU, TXT_NAV_YES, cx + MENU_SLOT_YES_X, cy, 0, a);
+ float wn = text_id(STYLE_MENU, TXT_NAV_NO, cx + MENU_SLOT_NO_X, cy, 0, a);
+ float x = mn.part == PS_PROMPT_YES ? cx + MENU_SLOT_YES_X : cx + MENU_SLOT_NO_X, w = mn.part == PS_PROMPT_YES ? wy : wn;
+ piece(&pointer, x - w / 2 - MENU_POINTER_GAP, cy, false, full);
+ piece(&pointer, x + w / 2 + MENU_POINTER_GAP, cy, true, full);
+ return;
+ }
+ if (mn.state[i] == 0) {
+ text_id(STYLE_MENU, TXT_PROFILE_NEW_GAME, cx + MENU_SLOT_NEW_X, cy, 1, a);
+ return;
+ }
+ if (mn.state[i] < 0) {
+ text_id(STYLE_MENU, TXT_PROFILE_CORRUPTED, cx + MENU_SLOT_NEW_X, cy, 1, a);
+ } else {
+ const SaveStats *st = &mn.stats[i];
+ /* its area's background (a zone without one: none), its fleur, its masks, soul orb, geo, area, play time */
+ for (int k = 0; k < MENU_SLOT_NZONES; k++)
+ if (zone_bgs[k].zone == st->zone) piece(&zone_bgs[k].p, cx, cy + MENU_SLOT_BG_DY, false, full);
+ piece(&slot_fleur, cx + MENU_SLOT_FLEUR_X, cy + MENU_SLOT_FLEUR_Y, false, full);
+ piece(&slot_orb, cx + MENU_SLOT_ORB_X, cy + MENU_SLOT_ORB_Y, false, full);
+ for (int k = 0; k < st->max_health && k < 11; k++)
+ piece(&slot_health, cx + MENU_SLOT_HEALTH_X + k * MENU_SLOT_HEALTH_DX, cy + MENU_SLOT_HEALTH_Y, false, full);
+ piece(&slot_geo, cx + MENU_SLOT_GEO_X, cy + MENU_SLOT_GEO_Y, false, full);
+ text_at(STYLE_MENU_SMALL, (const uint8_t *)mn.geo[i], (int)strlen(mn.geo[i]), cx + MENU_SLOT_GEOTXT_X,
+ cy + MENU_SLOT_GEOTXT_Y, 1, a);
+ for (int k = 0; k < MENU_SLOT_NZONES; k++)
+ if (zone_bgs[k].zone == st->zone)
+ text_id(STYLE_MENU_SMALL, zone_texts[k], cx + MENU_SLOT_LOC_X, cy + MENU_SLOT_LOC_Y, 2, a);
+ text_at(STYLE_MENU_SMALL, (const uint8_t *)mn.time[i], (int)strlen(mn.time[i]), cx + MENU_SLOT_TIME_X,
+ cy + MENU_SLOT_TIME_Y, 2, a);
+ }
+ /* Clear Save, to the right */
+ float w = text_id(STYLE_MENU, TXT_PROFILE_CLEAR_BUTTON, cx + MENU_SLOT_CLEAR_X, cy, 0, a);
+ if (sel && mn.part == PS_CLEAR) {
+ piece(&pointer, cx + MENU_SLOT_CLEAR_X - w / 2 - MENU_POINTER_GAP, cy, false, full);
+ piece(&pointer, cx + MENU_SLOT_CLEAR_X + w / 2 + MENU_POINTER_GAP, cy, true, full);
+ }
+}
+
+void menu_draw(void) {
+ float a = mn.t / FADE_TIME;
+ if (a > 1) a = 1;
+ switch (mn.screen) {
+ case MS_TITLE:
+ piece(&logo, 0, MENU_LOGO_Y, false, white(0, a));
+ button(TXT_MAIN_START, 0, MENU_START_Y, mn.sel == 0, a);
+ button(TXT_MAIN_QUIT, 0, MENU_QUIT_Y, mn.sel == 1, a);
+ break;
+ case MS_PROFILES:
+ text_id(STYLE_MENU_TITLE, TXT_SCREEN_SAVE_PROFILES, 0, MENU_PROFILES_TITLE_Y, 0, a);
+ piece(&profiles_fleur, 0, MENU_PROFILES_FLEUR_Y, false, white(0, a));
+ for (int i = 0; i < SAVE_SLOTS; i++) draw_slot(i, a);
+ button(TXT_NAV_BACK, 0, MENU_BACK_Y, mn.sel == SAVE_SLOTS, a);
+ break;
+ case MS_PAUSE:
+ /* (the modal dimmer: the game behind at a fifth) */
+ gfx_hud_fill(-15, -9, 15, 9, gfx_dyn_tint(31, 0, 0, 0, (uint8_t)(0.8f * a * 255 + 0.5f)));
+ piece(&pause_top, 0, MENU_PAUSE_TOP_Y, false, white(0, a));
+ piece(&pause_bot, 0, MENU_PAUSE_BOT_Y, false, white(0, a));
+ button(TXT_PAUSE_CONTINUE, 0, MENU_PAUSE_CONTINUE_Y, mn.sel == 0, a);
+ button(TXT_PAUSE_MAIN, 0, MENU_PAUSE_QUIT_Y, mn.sel == 1, a);
+ break;
+ }
+}
diff --git a/games/hollowknight/src/msg.c b/games/hollowknight/src/msg.c
index ac652704..31480959 100644
--- a/games/hollowknight/src/msg.c
+++ b/games/hollowknight/src/msg.c
@@ -137,7 +137,7 @@ void blanker_set(float alpha, bool on) { blank_alpha = alpha, blank_on = on; }
void msg_draw(void) {
if (wb.on && wb.alpha > 0)
- gfx_hud_fill(-15, -9, 15, 9, gfx_dyn_tint(8, 255, 255, 255, (uint8_t)(wb.alpha * 255 + 0.5f)));
+ gfx_hud_fill(-15, -9, 15, 9, gfx_dyn_tint(28, 255, 255, 255, (uint8_t)(wb.alpha * 255 + 0.5f)));
if (blank_on && blank_alpha > 0)
gfx_hud_fill(-15, -9, 15, 9, gfx_dyn_tint(27, 0, 0, 0, (uint8_t)(blank_alpha * 255 + 0.5f)));
if (m.st == MS_OFF) return;
diff --git a/games/hollowknight/src/plat_eadk.c b/games/hollowknight/src/plat_eadk.c
index f283a011..42f10f2c 100644
--- a/games/hollowknight/src/plat_eadk.c
+++ b/games/hollowknight/src/plat_eadk.c
@@ -36,5 +36,6 @@ void plat_fill(int x, int y, int w, int h, uint16_t c) {
}
bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }
const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }
+bool plat_remove(const char *name) { return ef_remove(name); }
void plat_begin(void) { np_app_begin(); }
int plat_end(void) { return np_app_end(); }
diff --git a/games/hollowknight/src/plat_host.c b/games/hollowknight/src/plat_host.c
index 14bcca65..200ffcaa 100644
--- a/games/hollowknight/src/plat_host.c
+++ b/games/hollowknight/src/plat_host.c
@@ -41,6 +41,11 @@ const uint8_t *plat_load(const char *name, uint32_t *len) {
fclose(f);
return loaded;
}
+bool plat_remove(const char *name) {
+ char p[512];
+ snprintf(p, sizeof p, "%s/%s", save_dir, name);
+ return remove(p) == 0;
+}
void plat_begin(void) {}
int plat_end(void) { return 0; }
diff --git a/games/hollowknight/src/save.c b/games/hollowknight/src/save.c
index b0286641..d3be5550 100644
--- a/games/hollowknight/src/save.c
+++ b/games/hollowknight/src/save.c
@@ -77,6 +77,28 @@ static const uint8_t *checked(int slot, uint32_t *count) {
return p + sizeof h;
}
+int save_stats(int slot, SaveStats *st) {
+ char name[8];
+ slot_name(slot, name);
+ uint32_t len, count;
+ if (!plat_load(name, &len)) return 0;
+ const uint8_t *p = checked(slot, &count);
+ if (!p) return -1;
+ /* (its PlayerData's fields, read where they are) */
+ memcpy(&st->max_health, p + offsetof(PlayerData, max_health), sizeof st->max_health);
+ memcpy(&st->mp_reserve_max, p + offsetof(PlayerData, mp_reserve_max), sizeof st->mp_reserve_max);
+ memcpy(&st->geo, p + offsetof(PlayerData, geo), sizeof st->geo);
+ memcpy(&st->play_time, p + offsetof(PlayerData, play_time), sizeof st->play_time);
+ st->zone = p[offsetof(PlayerData, map_zone)];
+ return 1;
+}
+
+bool save_clear(int slot) {
+ char name[8];
+ slot_name(slot, name);
+ return plat_remove(name);
+}
+
bool save_exists(int slot) {
uint32_t count;
return checked(slot, &count) != NULL;
diff --git a/games/hollowknight/src/vm.c b/games/hollowknight/src/vm.c
index e1d61387..b162a964 100644
--- a/games/hollowknight/src/vm.c
+++ b/games/hollowknight/src/vm.c
@@ -1330,8 +1330,9 @@ void vm_tick(void) {
}
}
-/* (a colour for an object this frame: the same colour, the same slot; slots no one else uses) */
-static const uint8_t tint_slots[] = {28, 29, 30, 31, 9, 12, 13, 14};
+/* (a colour for an object this frame: the same colour, the same slot; the room's slots no one else uses, graded with
+ * it: below the HUD's) */
+static const uint8_t tint_slots[] = {8, 9, 12, 13, 14};
static uint32_t tint_used[sizeof tint_slots];
static uint8_t obj_tint(int *n, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
uint32_t c = (uint32_t)r | (uint32_t)g << 8 | (uint32_t)b << 16 | (uint32_t)a << 24;
diff --git a/games/hollowknight/src/world.c b/games/hollowknight/src/world.c
index ba9e8b6e..5882d0e7 100644
--- a/games/hollowknight/src/world.c
+++ b/games/hollowknight/src/world.c
@@ -130,6 +130,9 @@ void world_enter(void) {
obj_enter();
titles_enter();
vm_enter();
+ /* (SceneManager: the room's map zone, PlayerData's) */
+ static const uint8_t zones[NUM_ROOMS] = ROOM_ZONES;
+ if (g_room.id >= 0 && g_room.id < NUM_ROOMS) g_pd.map_zone = zones[g_room.id];
}
/* (Pause's WaitForHeroInPosition: the masks start as the Knight is placed; its Wait only counts when it was placed
diff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.c
index 32e6604c..1a164f06 100644
--- a/games/hollowknight/tests/play.c
+++ b/games/hollowknight/tests/play.c
@@ -64,8 +64,16 @@ int main(int argc, char **argv) {
while (*f && *f != ',') f++;
if (*f) f++;
}
+ /* (HKMENU: from the title screen, as the calculator starts; HKSAVES: the saves' folder) */
+ bool menu = getenv("HKMENU") != NULL;
+ if (getenv("HKSAVES")) {
+ extern void host_save_dir(const char *d);
+ host_save_dir(getenv("HKSAVES"));
+ }
+ if (menu)
+ menu_start();
/* (HKLOAD=slot: that save loaded, the Knight at its respawn point) */
- if (getenv("HKLOAD")) {
+ else if (getenv("HKLOAD")) {
if (!save_load(atoi(getenv("HKLOAD"))) || (getenv("HKGEO") && (g_pd.geo = atoi(getenv("HKGEO")), 0)) || !game_respawn()) {
printf("load failed\n");
return 1;
@@ -77,7 +85,9 @@ int main(int argc, char **argv) {
uint32_t keys = 0;
for (; *p && *p != '*'; p++)
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 : 0;
+ : *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;
int n = *p == '*' ? atoi(++p) : 1;
while (*p && *p != ',') p++;
if (*p == ',') p++;
@@ -96,7 +106,8 @@ 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);
- game_tick(keys);
+ if (!menu || !menu_tick(keys)) game_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,
keys, g_hero.body.x, g_hero.body.y, g_hero.body.vx, g_hero.body.vy, g_hero.state, g_hero.cs.on_ground,
@@ -123,7 +134,16 @@ int main(int argc, char **argv) {
}
if (shot) {
int nf = getenv("NF") ? atoi(getenv("NF")) : 3;
- for (int i = 0; i < nf; i++) game_draw(); /* (the tile cache warm, as while playing) */
+ for (int i = 0; i < nf; i++) { /* (the tile cache warm, as while playing) */
+ if (!menu) {
+ game_draw();
+ continue;
+ }
+ g_gfx_no_room = !menu_in_game();
+ if (menu_in_game()) game_draw_layers();
+ menu_draw();
+ gfx_frame();
+ }
host_shot(shot);
}
if (getenv("HKGROUPS")) {
diff --git a/games/hollowknight/tools/menu.py b/games/hollowknight/tools/menu.py
new file mode 100644
index 00000000..185539a6
--- /dev/null
+++ b/games/hollowknight/tools/menu.py
@@ -0,0 +1,194 @@
+"""The title screen, the save profiles and the pause menu (Menu_Title's UI canvas): where its pieces are, in HUD units
+from the screen's center, and the sprites they show (src/menu.c)."""
+import json, os
+import unity
+
+CANVAS = (1920.0, 1200.0) # (CanvasScaler: 1920 x 1080, Expand: a 16:10 screen's canvas is taller)
+UNITS = 2 * 8.7107 / CANVAS[1] # (HUD units a canvas unit: the canvas's height is the HUD camera's)
+
+
+def rects():
+ """Menu_Title's UI: per object path, its rect's center (canvas units from the canvas's center) and size, its scale
+ (cached in tools/cache)."""
+ p = os.path.join(unity.CACHE, "menu_rects.json")
+ if os.path.exists(p):
+ return json.load(open(p))
+ lv = unity.asset_file("level%d" % unity.scene_index()["Menu_Title"])
+ tr, gos = {}, {}
+ for pid, o in lv.objects.items():
+ if o.type.name in ("Transform", "RectTransform"):
+ tr[pid] = o.read_typetree()
+ tr[pid]["_rect"] = o.type.name == "RectTransform"
+ elif o.type.name == "GameObject":
+ gos[pid] = o.read_typetree()
+ names = {d["m_GameObject"]["m_PathID"]: pid for pid, d in tr.items()}
+ canvas = next(pid for pid, d in tr.items()
+ if unity.S(gos[d["m_GameObject"]["m_PathID"]]["m_Name"]) == "UICanvas")
+ out, memo = {}, {}
+
+ def rect(pid):
+ """its rect in canvas units: center (x, y), size (w, h), accumulated scale"""
+ if pid in memo:
+ return memo[pid]
+ d = tr[pid]
+ if pid == canvas:
+ r = (0.0, 0.0, CANVAS[0], CANVAS[1], 1.0)
+ elif not d["_rect"] or d["m_Father"]["m_PathID"] not in tr:
+ r = (0.0, 0.0, 0.0, 0.0, 1.0)
+ else:
+ px, py, pw, ph, ps = rect(d["m_Father"]["m_PathID"])
+ amin, amax, piv = d["m_AnchorMin"], d["m_AnchorMax"], d["m_Pivot"]
+ w = d["m_SizeDelta"]["x"] + (amax["x"] - amin["x"]) * pw
+ h = d["m_SizeDelta"]["y"] + (amax["y"] - amin["y"]) * ph
+ # (the pivot's place in the parent, from its own rect's center)
+ ax = (amin["x"] + (amax["x"] - amin["x"]) * piv["x"] - 0.5) * pw + d["m_AnchoredPosition"]["x"]
+ ay = (amin["y"] + (amax["y"] - amin["y"]) * piv["y"] - 0.5) * ph + d["m_AnchoredPosition"]["y"]
+ cx, cy = ax + (0.5 - piv["x"]) * w, ay + (0.5 - piv["y"]) * h
+ s = d["m_LocalScale"]["x"]
+ # (in the parent's scale; its own scales its rect about its pivot)
+ r = (px + (ax + (cx - ax) * s) * ps, py + (ay + (cy - ay) * s) * ps, w, h, ps * s)
+ memo[pid] = r
+ return r
+
+ def path(gp):
+ t = tr[names[gp]]
+ f = t["m_Father"]["m_PathID"]
+ up = path(tr[f]["m_GameObject"]["m_PathID"]) + "/" if f in tr else ""
+ return up + unity.S(gos[gp]["m_Name"])
+ for gp in gos:
+ if gp not in names:
+ continue
+ pt = path(gp)
+ if pt.startswith("_UIManager/UICanvas/"):
+ out[pt[len("_UIManager/UICanvas/"):]] = rect(names[gp])
+ json.dump(out, open(p, "w"))
+ return out
+
+
+def place(r):
+ """a rect -> its center (HUD units from the screen's center), its size (HUD units, with its scale)"""
+ x, y, w, h, s = r
+ return x * UNITS, y * UNITS, w * s * UNITS, h * s * UNITS
+
+
+# (the pieces: an object's Image (or a sprite of the scene's) fitted to its rect)
+SLOT = "SaveProfileScreen/Content/SaveSlots/Slot%s"
+ACTIVE = SLOT + "/ActiveSaveSlot%d"
+ZONES = {2: "KINGS_PASS", 4: "TOWN", 5: "CROSSROADS", 6: "GREEN_PATH", 22: "SHAMAN_TEMPLE"} # (GlobalEnums.MapZone)
+MENU_K = 1.6 # (the menus' text, bigger: the game's is hard to read at this screen's size)
+
+
+def build(sprites, texts):
+ """The menus' sprites and texts registered -> {define: value} for data.h (src/menu.c)"""
+ import text, scene, actors
+ d = unity.scene("Menu_Title")
+ by = {o["path"].replace("_UIManager/UICanvas/", ""): o for o in d["objects"]}
+ r = rects()
+ res = actors.HUD_K / actors.K0
+ out = {}
+ U = lambda v: "%.4ff" % v
+
+ def image(path):
+ o = by[path]
+ v = next(c["v"] for c in o["c"] if isinstance(c.get("v"), dict) and "m_Sprite" in c["v"])
+ return v["m_Sprite"], bool(v.get("m_PreserveAspect"))
+
+ def piece(ref, w, h, preserve=True):
+ """a sprite drawn in a w x h rect (HUD units) -> its record: sprite, its pivot from the rect's center, its
+ scale as drawn"""
+ s = unity.sprite(d["level"], list(d["externals"]), ref[0], ref[1])
+ wu, hu = s.w / s.ppu, s.h / s.ppu
+ k = min(w / wu, h / hu) if preserve else min(w / wu, h / hu)
+ sx, sy = (1.0, 1.0) if preserve else (w / wu / k, h / hu / k)
+ W, H = wu * k * sx, hu * k * sy
+ spr = sprites.id(d, ref, k, res)
+ return "{%d, %s, %s, %s, %s}" % (spr, U((s.px - 0.5) * W), U((s.py - 0.5) * H), U(sx), U(sy))
+
+ def at(path):
+ x, y, w, h = place(r[path])
+ return x, y, w, h
+
+ def obj_piece(path, preserve=None, k=1.0, frame_of=None):
+ """(frame_of: the sprite another object shows, its animation's last frame where this one shows its first)"""
+ ref, pa = image(frame_of or path)
+ x, y, w, h = at(path)
+ return piece(ref, abs(w) * k, abs(h) * k, pa if preserve is None else preserve)
+ # the title: the logo (its world sprite as the menu's camera shows it, over the buttons), its buttons
+ lw = 0.52 * 320 / actors.HUD_K
+ logo = unity.sprite(d["level"], list(d["externals"]), 2, 110)
+ out["MENU_LOGO"] = piece([2, 110], lw, lw * logo.h / logo.w)
+ out["MENU_LOGO_Y"] = U(100 / actors.HUD_K - 0.29 * 200 / actors.HUD_K)
+ btn = "MainMenuScreen/MainMenuButtons/%sButton"
+ out["MENU_START_Y"] = U(at(btn % "StartGame")[1])
+ out["MENU_QUIT_Y"] = U(at(btn % "Options")[1]) # (the second of the buttons shown)
+ cx, cy, cw, ch = at(btn % "StartGame" + "/Text/CursorLeft")
+ tx, ty, tw, th = at(btn % "StartGame" + "/Text")
+ # (the pointers as big as the text is made)
+ out["MENU_POINTER"] = obj_piece(btn % "StartGame" + "/Text/CursorLeft", False, MENU_K)
+ # (from the text's edge to the pointer's center: the game's gap, then half the pointer as drawn)
+ out["MENU_POINTER_GAP"] = U((tx - abs(tw) / 2) - (cx + abs(cw) / 2) + abs(cw) * MENU_K / 2)
+ # the save profiles: the title and its fleur, the slots (one's pieces, from its center), Back
+ out["MENU_PROFILES_TITLE_Y"] = U(at("SaveProfileScreen/Title")[1])
+ out["MENU_PROFILES_FLEUR"] = obj_piece("SaveProfileScreen/TopFleur")
+ out["MENU_PROFILES_FLEUR_Y"] = U(at("SaveProfileScreen/TopFleur")[1])
+ s1x, s1y, _, _ = at(SLOT % "One")
+ out["MENU_SLOT_X"], out["MENU_SLOT_Y"] = U(s1x), U(s1y)
+ out["MENU_SLOT_DY"] = U(at(SLOT % "Two")[1] - s1y)
+ rel = lambda path: (at(path)[0] - s1x, at(path)[1] - s1y)
+ bgx, bgy, bgw, bgh = at(SLOT % "One" + "/Background")
+ zones = []
+ for z in sorted(ZONES):
+ ref = next(a["backgroundImage"] for a in next(c["v"] for c in by["SaveProfileScreen/Content/SaveSlots"]["c"]
+ if c.get("class") == "SaveSlotBackgrounds")["areaBackgrounds"]
+ if a["areaName"] == z)
+ zones.append("{%d, %s}" % (z, piece(ref, abs(bgw), abs(bgh))))
+ out["MENU_SLOT_ZONES"] = "{%s}" % ", ".join(zones)
+ out["MENU_SLOT_NZONES"] = len(zones)
+ out["MENU_SLOT_BG_DY"] = U(bgy - s1y)
+ for name, path in (("FLEUR", "/Fleur"), ("SELECTOR", "/Selector"), ("CURSOR", "/CursorLeft"),
+ ("ORB", "/ActiveSaveSlot1/HUDLayout/SoulOrb"), ("GEO", "/ActiveSaveSlot1/HUDLayout/GeoIcon"),
+ ("HEALTH", "/ActiveSaveSlot1/HUDLayout/HealthSlots/HealthUnit1")):
+ p = SLOT % "One" + path
+ out["MENU_SLOT_" + name] = obj_piece(p, False if name == "CURSOR" else None, MENU_K if name == "CURSOR" else 1.0)
+ x, y = rel(p)
+ out["MENU_SLOT_%s_X" % name], out["MENU_SLOT_%s_Y" % name] = U(x), U(y)
+ out["MENU_SLOT_CURSOR_X2"] = U(rel(SLOT % "One" + "/CursorRight")[0])
+ out["MENU_SLOT_HEALTH_DX"] = U(rel(SLOT % "One" + "/ActiveSaveSlot1/HUDLayout/HealthSlots/HealthUnit2")[0] -
+ rel(SLOT % "One" + "/ActiveSaveSlot1/HUDLayout/HealthSlots/HealthUnit1")[0])
+
+ def edge(path, align):
+ """a text's anchor (x: its left, center or right, as aligned; y: its middle) from the slot's center"""
+ x, y, w, h = at(path)
+ x -= s1x
+ return U(x - abs(w) / 2 if align == 3 else x + abs(w) / 2 if align == 5 else x), U(y - s1y)
+ out["MENU_SLOT_NUM_X"], _ = edge(SLOT % "One" + "/SlotNumberText", 4)
+ out["MENU_SLOT_NEW_X"], _ = edge(SLOT % "One" + "/NewGameText", 3)
+ out["MENU_SLOT_LOC_X"], out["MENU_SLOT_LOC_Y"] = edge(ACTIVE % ("One", 1) + "/LocationText", 5)
+ out["MENU_SLOT_TIME_X"], out["MENU_SLOT_TIME_Y"] = edge(ACTIVE % ("One", 1) + "/PlayTimeText", 5)
+ out["MENU_SLOT_GEOTXT_X"], out["MENU_SLOT_GEOTXT_Y"] = edge(ACTIVE % ("One", 1) + "/HUDLayout/GeoText", 3)
+ out["MENU_SLOT_CLEAR_X"] = U(at("SaveProfileScreen/Content/ClearSaveButtons/ClearSaveButtonOne")[0] - s1x)
+ pr = "SaveProfileScreen/Content/ClearSavePrompts/ClearSavePromptOne"
+ out["MENU_SLOT_PROMPT_X"] = U(at(pr + "/ClearSaveText")[0] - s1x)
+ out["MENU_SLOT_YES_X"] = U(at(pr + "/YesButton")[0] - s1x)
+ out["MENU_SLOT_NO_X"] = U(at(pr + "/NoButton")[0] - s1x)
+ out["MENU_BACK_Y"] = U(at("SaveProfileScreen/Controls/BackButton")[1])
+ # the pause menu: its fleurs, Continue and Quit to Menu (between them, Options' place shared)
+ out["MENU_PAUSE_TOP"] = obj_piece("PauseMenuScreen/TopFleur", frame_of="NewPauseMenuScreen/TopFleur")
+ out["MENU_PAUSE_TOP_Y"] = U(at("PauseMenuScreen/TopFleur")[1])
+ out["MENU_PAUSE_BOT"] = obj_piece("PauseMenuScreen/BottomFleur", frame_of="NewPauseMenuScreen/BottomFleur")
+ out["MENU_PAUSE_BOT_Y"] = U(at("PauseMenuScreen/BottomFleur")[1])
+ yc, yo, yq = (at("PauseMenuScreen/Controls/%sButton" % b)[1] for b in ("Continue", "Options", "Quit"))
+ out["MENU_PAUSE_CONTINUE_Y"], out["MENU_PAUSE_QUIT_Y"] = U((yc + yo) / 2), U((yo + yq) / 2)
+ # the texts
+ sh = text.sheets()
+ mm = lambda k, st="MENU": texts.add(text.clean(sh["MainMenu"][k]), st)
+ for k in ("MAIN_START", "MAIN_QUIT", "PROFILE_NEW_GAME", "PROFILE_CLEAR_BUTTON", "PROFILE_CLEAR_PROMPT", "NAV_YES",
+ "NAV_NO", "NAV_BACK", "PAUSE_CONTINUE", "PAUSE_MAIN", "PROFILE_CORRUPTED"):
+ out["TXT_" + k] = mm(k)
+ out["TXT_SCREEN_SAVE_PROFILES"] = mm("SCREEN_SAVE_PROFILES", "MENU_TITLE")
+ out["TXT_ZONES"] = "{%s}" % ", ".join("%d" % texts.add(text.clean(sh["Map Zones"][ZONES[z]]), "MENU_SMALL")
+ for z in sorted(ZONES))
+ # (the characters the numbers need: slots, geo, play time)
+ texts.add("1234.", "MENU_TITLE")
+ texts.add("0123456789hm", "MENU_SMALL")
+ return out
diff --git a/games/hollowknight/tools/pack.py b/games/hollowknight/tools/pack.py
index af82ee69..6f5c78c7 100644
--- a/games/hollowknight/tools/pack.py
+++ b/games/hollowknight/tools/pack.py
@@ -490,6 +490,10 @@ def main():
pgb = unity.prefab("sharedassets149.assets", 34)
fleurs["SPRITE_GRASS_BALL"] = SPRITES.id(pgb, next(c["v"] for c in pgb["objects"][0]["c"] if c["type"] == "SpriteRenderer")["m_Sprite"], 1)
fleurs["MSG_TABLE"] = "{%s}" % ", ".join(msgs)
+ # the title screen, the save profiles, the pause menu; each room's map zone (the save slots' area)
+ import menu
+ fleurs.update(menu.build(SPRITES, TEXTS))
+ 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
for r in ROOMS:
diff --git a/games/hollowknight/tools/text.py b/games/hollowknight/tools/text.py
index ee05702c..6a89c90a 100644
--- a/games/hollowknight/tools/text.py
+++ b/games/hollowknight/tools/text.py
@@ -92,6 +92,11 @@ STYLES = {
# the message as an item is taken (UI Msg Get Item: its lines, a third bigger; its item's name)
"MSG": _style("Perpetua", 3.73 * 1.4407, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
"MSG_NAME": _style("TrajanPro-Bold", 9.32 * 1.4407, HUD_PX, *TRAJAN, k=1, phases=1),
+ # the menus (Menu_Title's UI canvas, 1920 x 1200 for 320 x 200 pixels; their text bigger: menu.MENU_K): the
+ # buttons (Trajan bold, 54 at 0.549 and 45 at 0.7), the screens' titles and slot numbers, the slots' details
+ "MENU": _style("TrajanPro-Bold", 31 / 6 * 1.6 * 10, 1, *TRAJAN, k=1),
+ "MENU_TITLE": _style("TrajanPro-Bold", 53 / 6 * 1.35 * 10, 1, *TRAJAN, k=1, phases=1),
+ "MENU_SMALL": _style("TrajanPro-Regular", 27 / 6 * 1.6 * 10, 1, *TRAJAN, k=1),
}
# the items the message shows: (its name in the UI sheet, the Prompts sheet's prefix, tap or press, its two lines, the