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: bigger text to read, in the game's own typefaces (the titles as they were): dialogue, prompts, menus, descriptions; a shop shows what an item does beside its window, descriptions take the biggest size their box holds, names and keys keep clear of what is around them; a test checks every screen's text stays in it, in its box and off other text

Mason363d0c02bb11656
diff --git a/games/hollowknight/README.md b/games/hollowknight/README.md
index 41bb12a3..bb32dd9b 100644
--- a/games/hollowknight/README.md
+++ b/games/hollowknight/README.md
@@ -74,6 +74,7 @@ In menus, OK or EXE confirms and Back goes back. In the inventory, left and righ
* **One app at a time:** Hollow Knight takes all the room the calculator has for apps. Installing it from the NumWorks website swaps out NumPlay and the other apps, and installing NumPlay again swaps it back out. Your saves in each one are kept.
* **Only the start of the game:** it ends with Hornet in Greenpath. The ways on to places further in stay shut, like Jiji's door, the lift down to the mines and the Dream Nail's paths, and so do the Forgotten Crossroads' side rooms off the way to Greenpath, like Brooding Mawlek's and the Glowing Womb.
* **No music or sound:** the calculator has no speaker.
+* **Text made to read:** what there is to read is bigger than in the game, in its own typefaces, and a shop shows what an item does beside its window.
* **A few things are simpler:** dust, sparks and other particles are left out, and characters and scenery are drawn a little less finely so the whole game fits.
* **Busy rooms stay smooth:** when the calculator falls behind, the room is drawn at half the height, each line shown twice. The HUD, text and menus stay sharp.
diff --git a/games/hollowknight/docs/iselda.png b/games/hollowknight/docs/iselda.png
index f7d9859b..86638692 100644
Binary files a/games/hollowknight/docs/iselda.png and b/games/hollowknight/docs/iselda.png differ
diff --git a/games/hollowknight/docs/map.png b/games/hollowknight/docs/map.png
index b18cd79f..817cd38e 100644
Binary files a/games/hollowknight/docs/map.png and b/games/hollowknight/docs/map.png differ
diff --git a/games/hollowknight/src/data.bin b/games/hollowknight/src/data.bin
index c665237c..f8a4e9fa 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 4c7a0df8..2f9b972a 100644
--- a/games/hollowknight/src/data.h
+++ b/games/hollowknight/src/data.h
@@ -690,6 +690,7 @@
#define STYLE_MENU_SMALL 12
#define STYLE_YN 13
#define STYLE_MSG_S 14
+#define STYLE_MSG_XS 15
#define TEXT_K 1.333333f
#define FONT_PHASES 4
#define EK_CRAWLER 1
diff --git a/games/hollowknight/src/game.h b/games/hollowknight/src/game.h
index 0729afdb..572e8a8f 100644
--- a/games/hollowknight/src/game.h
+++ b/games/hollowknight/src/game.h
@@ -482,6 +482,7 @@ bool map_pane_holds(void); /* (Do Not Close: zoomed into) */
float map_pane_nav(void); /* (the pane's arrows' and the side panes' names' alpha: away as it is zoomed into) */
void map_pane_close(void);
float text_box(int text, int style, float x, float y, float w, int align, float a);
+int text_fit(int text, float w, float room); /* (a description's style: the first of MSG, MSG_S, MSG_XS that fits) */
int charm_cost(int id); /* (charmCost_N) */
bool charm_equipped(int id);
bool menu_quit(void);
diff --git a/games/hollowknight/src/gfx.c b/games/hollowknight/src/gfx.c
index d2d9e66d..5e1d0195 100644
--- a/games/hollowknight/src/gfx.c
+++ b/games/hollowknight/src/gfx.c
@@ -1606,8 +1606,60 @@ typedef struct {
static TextRun runs[MAX_RUNS];
static int nruns;
+#ifdef HOST
+/* (tests: the text of each frame drawn, checked: in the screen, no line over another, none left out) */
+bool g_text_audit;
+char g_text_audit_log[2048];
+static uint32_t runs_dropped;
+static void text_box_px(const TextRun *r, int *x0, int *y0, int *x1, int *y1) {
+ float pen = r->x;
+ *x0 = *y0 = 1 << 30, *x1 = *y1 = -(1 << 30);
+ for (int i = 0; i < r->n; i++) {
+ const Glyph *g = font_glyph(r->style, r->s[i], 0);
+ if (!g) continue;
+ int gx = (int)floorf(pen) + g->left, gy = r->y - g->top;
+ pen += g->adv * (1.0f / 64);
+ if (!g->w) continue;
+ if (gx < *x0) *x0 = gx;
+ if (gx + g->w > *x1) *x1 = gx + g->w;
+ if (gy < *y0) *y0 = gy;
+ if (gy + g->h > *y1) *y1 = gy + g->h;
+ }
+}
+static void text_audit(void) {
+ char *o = g_text_audit_log;
+ size_t left = sizeof g_text_audit_log;
+ o[0] = 0;
+#define LOG(...) do { int k_ = snprintf(o, left, __VA_ARGS__); if (k_ > 0 && (size_t)k_ < left) o += k_, left -= (size_t)k_; } while (0)
+ if (runs_dropped) LOG("%u lines left out; ", runs_dropped);
+ runs_dropped = 0;
+ for (int i = 0; i < nruns; i++) {
+ const TextRun *a = &runs[i];
+ if ((a->rgb >> 24) < 128) continue;
+ int ax0, ay0, ax1, ay1;
+ text_box_px(a, &ax0, &ay0, &ax1, &ay1);
+ if (ax1 < ax0 || ax1 <= 0 || ay1 <= 0 || ax0 >= VIEW_W || ay0 >= VIEW_H) continue; /* (not shown at all) */
+ if (ax0 < 0 || ay0 < 0 || ax1 > VIEW_W || ay1 > VIEW_H)
+ LOG("\"%.*s\" off the screen (%d,%d-%d,%d); ", a->n, (const char *)a->s, ax0, ay0, ax1, ay1);
+ for (int j = i + 1; j < nruns; j++) {
+ const TextRun *b = &runs[j];
+ if ((b->rgb >> 24) < 128) continue;
+ int bx0, by0, bx1, by1;
+ text_box_px(b, &bx0, &by0, &bx1, &by1);
+ int ox = (ax1 < bx1 ? ax1 : bx1) - (ax0 > bx0 ? ax0 : bx0), oy = (ay1 < by1 ? ay1 : by1) - (ay0 > by0 ? ay0 : by0);
+ if (ox > 1 && oy > 1)
+ LOG("\"%.*s\" over \"%.*s\"; ", a->n, (const char *)a->s, b->n, (const char *)b->s);
+ }
+ }
+#undef LOG
+}
+#endif
+
bool gfx_text(int style, float x, float y, const uint8_t *s, int n, uint32_t argb, int layer) {
uint32_t a = argb >> 24;
+#ifdef HOST
+ if (nruns >= MAX_RUNS && n > 0 && a) runs_dropped++;
+#endif
if (nruns >= MAX_RUNS || n <= 0 || !a) return false;
const uint8_t *st = font_style(style);
TextRun *r = &runs[nruns++];
@@ -1836,6 +1888,9 @@ void gfx_frame(void) {
finish_strip(sy0, STRIP_H);
}
vsf = 1;
+#ifdef HOST
+ if (g_text_audit) text_audit();
+#endif
nruns = 0;
#ifdef HOST
{
diff --git a/games/hollowknight/src/inv.c b/games/hollowknight/src/inv.c
index 3ba80b71..edd40fc1 100644
--- a/games/hollowknight/src/inv.c
+++ b/games/hollowknight/src/inv.c
@@ -54,6 +54,16 @@ static const uint8_t notch_full_rgb[3] = CH_NOTCH_FULL_RGB, notch_over_rgb[3] =
#define EQ_Y (-3.86f)
#define EQ_SCALE 1.15f
#define DETAIL_SCALE 1.5f
+/* (a description's bottom, from the panes' top: over the border; over the Equip key at a bench; under the cost) */
+#define DESC_BOTTOM (-13.7f)
+#define DESC_BOTTOM_BENCH (-12.35f)
+#define CH_DESC_GAP 0.3f
+/* (how much lower what comes under a name (its top at top, the next's at next) must be for the name's bigger text) */
+static float name_below(float top, float next) {
+ const uint8_t *st = font_style(STYLE_DIALOGUE);
+ float d = (font_asc(st) + font_desc(st)) / HUD_PX - (top - next);
+ return d > 0 ? d : 0;
+}
/* 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 */
@@ -618,13 +628,13 @@ void ui_number_at(int v, int style, float x, float top, int align, float a) {
/* an action's key (ActionButtonIcon: the calculator's key, by name, in a box as wide as it) at (x, y) -> its half width */
float ui_key(int name, float x, float y, uint8_t white, float a) {
- const uint8_t *st = font_style(STYLE_MSG), *s = text_get(name);
+ const uint8_t *st = font_style(STYLE_MSG_S), *s = text_get(name);
int n = (int)strlen((const char *)s);
- float w = text_width(STYLE_MSG, s, n), bw = w / HUD_PX + 0.3f;
+ float w = text_width(STYLE_MSG_S, s, n), bw = w / HUD_PX + 0.3f;
Inst in;
sprite_inst(SPRITE_MSG_KEY, x, y, 0, bw / 0.95f, 0.75f, white, &in);
gfx_overlay(&in);
- gfx_text(STYLE_MSG, VIEW_W / 2 + x * HUD_PX - w / 2, VIEW_H / 2 - y * HUD_PX + (font_asc(st) - font_desc(st)) / 2, s, n,
+ gfx_text(STYLE_MSG_S, VIEW_W / 2 + x * HUD_PX - w / 2, VIEW_H / 2 - y * HUD_PX + (font_asc(st) - font_desc(st)) / 2, s, n,
(uint32_t)(a * 255 + 0.5f) << 24 | 0xFFFFFF, 0);
return bw / 2;
}
@@ -703,22 +713,36 @@ static void charms_draw(float ox, float oy, float a, uint8_t white) {
int name, desc, cost, detail;
charm_select_text(&name, &desc, &cost, &detail);
ui_text_at(name, STYLE_DIALOGUE, &ch_name, ox, oy, 1, a);
+ /* (its picture under its cost where its description still fits under that, in the message's size or the smaller;
+ * else the description up in the picture's place) */
+ float down = name_below(ch_name.top, ch_cost_text.top); /* (all under the name lower by as much as it is bigger) */
+ float bottom = detail && pd_flag(PDF_AT_BENCH) ? DESC_BOTTOM_BENCH : DESC_BOTTOM, top = ch_desc.top - down;
+ int style = text_box(desc, STYLE_MSG, 0, 0, ch_desc.w, 0, 0) <= top - bottom ? STYLE_MSG : STYLE_MSG_S;
+ bool picture = !detail || text_box(desc, style, 0, 0, ch_desc.w, 0, 0) <= top - bottom;
+ if (!picture) {
+ const uint8_t *st = font_style(STYLE_MSG);
+ top = ch_cost_text.top - down - (font_asc(st) + font_desc(st)) / HUD_PX - CH_DESC_GAP;
+ style = text_fit(desc, ch_desc.w, top - bottom);
+ }
+ if (!detail) style = text_fit(desc, ch_desc.w, top - bottom);
if (detail) {
- ui_text_at(TXT_CHARM_TXT_COST, STYLE_MSG, &ch_cost_text, ox, oy, 2, a);
- for (int i = 0; i < cost; i++) ui_piece(&ch_cost_pip, ox + CH_COST_X + i * CH_COST_DX, oy + CH_COST_Y, 1, white);
- ui_sprite_at(ch_icons[detail], ox + CH_DETAIL_X, oy + CH_DETAIL_Y, DETAIL_SCALE / CHARM_ICON_K, white);
+ ui_text_at(TXT_CHARM_TXT_COST, STYLE_MSG, &ch_cost_text, ox, oy - down, 2, a);
+ for (int i = 0; i < cost; i++) ui_piece(&ch_cost_pip, ox + CH_COST_X + i * CH_COST_DX, oy - down + CH_COST_Y, 1, white);
+ if (picture)
+ ui_sprite_at(ch_icons[detail], ox + CH_DETAIL_X, oy - down + 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);
+ text_box(desc, style, ox + ch_desc.x, oy + top, ch_desc.w, 0, a);
if (detail && pd_flag(PDF_AT_BENCH)) {
- ui_text_at(charm_equipped(detail) ? TXT_CTRL_UNEQUIP : TXT_CTRL_EQUIP, STYLE_MSG, &ch_confirm, ox, oy, 2, a);
+ /* (as the keys' actions elsewhere, the smaller message's size) */
+ ui_text_at(charm_equipped(detail) ? TXT_CTRL_UNEQUIP : TXT_CTRL_EQUIP, STYLE_MSG_S, &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;
+ const uint8_t *st = font_style(STYLE_MSG_S);
+ float w = text_width(STYLE_MSG_S, 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,
+ gfx_text(STYLE_MSG_S, 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);
}
@@ -778,7 +802,8 @@ static void items_draw(float ox, float oy, float a, uint8_t white) {
} else
nd = txt_trinkets[k - K_TRINKET0];
ui_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);
+ float top = inv_desc.top - name_below(inv_name.top, inv_desc.top);
+ text_box(nd.desc, text_fit(nd.desc, inv_desc.w, top - DESC_BOTTOM), ox + inv_desc.x, oy + top, inv_desc.w, 0, a);
}
if (iv.cursor_set) cursor_draw(ox, oy, white);
}
diff --git a/games/hollowknight/src/map.c b/games/hollowknight/src/map.c
index 50ca48d3..289bea54 100644
--- a/games/hollowknight/src/map.c
+++ b/games/hollowknight/src/map.c
@@ -338,6 +338,30 @@ static void hud_text(int text, int style, float x, float top, int align, uint32_
}
}
+/* a next area's name (centered at x, its top): its edge by the arrow where the game has it, the text being bigger
+ * than the one its place was made for (tools/gamemap.py: the message's size then, MSG_LAYOUT_EM pixels an em) */
+#define MSG_LAYOUT_EM 8.23f
+#define NEXT_MARGIN 0.25f /* (a name kept this far in from the screen's side, ...) */
+#define NEXT_UNDER 0.45f /* (... its top this far under its arrow) */
+static void next_name_at(const MapNext *n, float ox, float oy, float k, float *x, float *top) {
+ const uint8_t *st = font_style(STYLE_MSG), *s = text_get(n->text);
+ float r = MSG_LAYOUT_EM / font_em(st);
+ float w = text_width(STYLE_MSG, s, (int)strlen((const char *)s)) / HUD_PX, h = (font_asc(st) + font_desc(st)) / HUD_PX;
+ float w0 = w * r, h0 = h * r, t0 = oy + n->top * k;
+ float cx0 = ox + n->tx * k + (n->align == 0 ? w0 / 2 : n->align == 2 ? -w0 / 2 : 0), cy0 = t0 - h0 / 2;
+ float dx = cx0 - (ox + n->x * k), dy = cy0 - (oy + n->y * k);
+ *x = cx0, *top = cy0 + h / 2;
+ if (fabsf(dx) > fabsf(dy)) *x = dx > 0 ? cx0 - w0 / 2 + w / 2 : cx0 + w0 / 2 - w / 2; /* (beside it: that side kept) */
+ else if (dy > 0) *top = t0 - h0 + h; /* (over it: its bottom kept) */
+ else *top = t0; /* (under it: its top kept) */
+ /* (past the screen's side: inside it, under the arrow) */
+ float edge = VIEW_W / 2 / HUD_PX - NEXT_MARGIN;
+ if (*x + w / 2 > edge || *x - w / 2 < -edge) {
+ *x = *x + w / 2 > edge ? edge - w / 2 : -edge + w / 2;
+ *top = oy + n->y * k - NEXT_UNDER;
+ }
+}
+
/* a room of the map shown: rough with its area's map; else once mapped */
static bool room_shown(int i) {
const MapRoom *r = &rooms[i];
@@ -376,7 +400,9 @@ static void draw_area(int a, float ox, float oy, float k, bool quick) {
const MapNext *n = &nexts[i];
if (rooms[n->room].area != a || !room_shown(n->room) || (n->visited >= 0 && !pd_flag(n->visited))) continue;
hud_sprite(n->sprite, ox + n->x * k, oy + n->y * k, sk, n->ang, map_tint(0xFFFFFF, 255));
- hud_text(n->text, STYLE_MSG, ox + n->tx * k, oy + n->top * k, n->align, 0xFFFFFF, 1);
+ float x, top;
+ next_name_at(n, ox, oy, k, &x, &top);
+ hud_text(n->text, STYLE_MSG, x, top, 1, 0xFFFFFF, 1);
}
}
@@ -509,6 +535,7 @@ static void map_msg_draw(void) {
* (Map Key: the pins had, the key and the pins shown or not); the markers' menu (MapMarkerMenu: placed and taken back,
* six of each kind). Places: the pane's from the inventory's, Game_Map's from the HUD's middle.) */
typedef struct { UiPiece piece; int16_t text; UiText name; float zx, zy, cx, cy, ext[4]; } WidePiece;
+#define MAP_NAME_GAP 0.4f /* (the least room between two areas' names) */
typedef struct { UiPiece back; float key[2]; UiText text; int16_t texts[3]; } MapAction;
typedef struct { UiPiece icon; int16_t text; UiText at; } KeyRow;
static const WidePiece wide[NAREAS] = MAP_WIDE;
@@ -812,7 +839,7 @@ static void action_draw(const MapAction *m, int which, int key, float ox, float
UiText t = m->text;
if (right && t.x > m->key[0] - hw - 0.15f) t.x = m->key[0] - hw - 0.15f;
if (!right && t.x < m->key[0] + hw + 0.15f) t.x = m->key[0] + hw + 0.15f;
- ui_text_at(m->texts[which], STYLE_MSG, &t, ox, oy, right ? 2 : 0, a);
+ ui_text_at(m->texts[which], STYLE_MSG_S, &t, ox, oy, right ? 2 : 0, a); /* (as the keys' actions elsewhere) */
}
/* the pane at (ox, oy) (its alpha a; its white); current: the pane shown (else going: Pane Reset, nothing chosen) */
@@ -823,12 +850,24 @@ void map_pane_draw(float ox, float oy, float a, uint8_t white, bool current) {
float wa = current ? mp.wide_a : 1;
if (wa > 0) {
uint8_t wa8 = (uint8_t)(wa * 255 + 0.5f);
+ /* (the names, in the smallest of the bigger text: those of areas side by side moved apart where they would meet) */
+ float nx[NAREAS], hw[NAREAS];
+ for (int i = 0; i < NAREAS; i++) {
+ const uint8_t *s = text_get(wide[i].text);
+ nx[i] = wide[i].name.x, hw[i] = text_width(STYLE_MSG_XS, s, (int)strlen((const char *)s)) / HUD_PX / 2 + MAP_NAME_GAP / 2;
+ }
+ for (int i = 0; i < NAREAS; i++)
+ for (int j = 0; j < NAREAS; j++) {
+ if (i == j || !have_area(i) || !have_area(j) || fabsf(wide[i].name.top - wide[j].name.top) > 1 || nx[i] > nx[j]) continue;
+ float over = nx[i] + hw[i] - (nx[j] - hw[j]);
+ if (over > 0) nx[i] -= over / 2, nx[j] += over / 2;
+ }
for (int i = 0; i < NAREAS; i++) {
if (!have_area(i) || wide[i].piece.sprite < 0) continue;
bool on = current && st == MP_WIDE && mp.sel == i;
uint8_t g = on ? 255 : MAP_WIDE_GREY, gn = on ? 255 : MAP_WIDE_NAME_GREY;
ui_piece(&wide[i].piece, ox, oy, 1, map_tint((uint32_t)g * 0x10101u, wa8));
- hud_text(wide[i].text, STYLE_MSG_S, ox + wide[i].name.x, oy + wide[i].name.top, 1, (uint32_t)gn * 0x10101u, wa);
+ hud_text(wide[i].text, STYLE_MSG_XS, ox + nx[i], oy + wide[i].name.top, 1, (uint32_t)gn * 0x10101u, wa);
}
/* (its compass: where the Knight's area is) */
int z = area_of_zone();
diff --git a/games/hollowknight/src/shop.c b/games/hollowknight/src/shop.c
index 6c7a89c0..55348c96 100644
--- a/games/hollowknight/src/shop.c
+++ b/games/hollowknight/src/shop.c
@@ -42,6 +42,9 @@ static const uint8_t first[SHOP_N + 1] = SHOP_FIRST, active_rgb[3] = SHOP_ACTIVE
static const char *const rooms[SHOP_N] = SHOP_ROOMS;
static const int16_t nostock[SHOP_N] = SHOP_NOSTOCK, titles[SHOP_N] = SHOP_TITLES;
#define MAX_ROWS 16
+#define SHOP_KEY_GAP 0.25f /* (between a key and its action) */
+#define SHOP_KEY_OUT 0.3f /* (the keys a little further out than the game's: their actions' text is bigger) */
+#define SHOP_PEG_BELOW 0.09f /* (a peg's center under the bottom of Notch Cost's text) */
enum {
SH_CLOSED, SH_TALK_UP, SH_TALK, SH_TALK_DOWN, /* (nothing left: Box Up, its conversation, Box Down) */
@@ -379,8 +382,24 @@ static void anim_piece(const AnimPiece *p, const Anim *an, uint8_t tint) {
gfx_overlay(&in);
}
-/* an action's key (ActionButtonIcon: the calculator's, by name) */
-static void key_at(const float *at, int name, float a, uint8_t white) { ui_key(name, at[0], at[1], white, a); }
+/* an action's key (ActionButtonIcon: the calculator's, by name) -> its half width */
+static float key_at(const float *at, int name, float a, uint8_t white) { return ui_key(name, at[0], at[1], white, a); }
+
+/* the selected item's description: on the window's left, over a dark panel (in the window, at a size that reads, it
+ * would not fit the calculator's screen); the message's size, smaller where that runs out of the panel (text_fit) */
+#define DESC_X0 (-13.35f) /* (its text's left, right, top; the panel's bottom: HUD units) */
+#define DESC_X1 (-1.35f)
+#define DESC_TOP 5.05f
+#define DESC_BOTTOM (-8.4f)
+#define DESC_PAD 0.4f
+static void desc_draw(const Item *it, float bob, float a) {
+ float w = DESC_X1 - DESC_X0;
+ int style = text_fit(it->desc, w, DESC_TOP - DESC_BOTTOM);
+ float h = text_box(it->desc, style, 0, 0, w, 0, 0);
+ gfx_overlay_fill(DESC_X0 - DESC_PAD, DESC_TOP - h - DESC_PAD + bob, DESC_X1 + DESC_PAD, DESC_TOP + DESC_PAD + bob,
+ gfx_dyn_tint(27, 0, 0, 0, (uint8_t)(a * SHOP_BACKBOARD_A * 255 + 0.5f)));
+ text_box(it->desc, style, DESC_X0, DESC_TOP + bob, w, 0, a);
+}
static void shop_draw(void) {
float bob = sh.bob_t > 0 ? (sh.bob_t > 0.2f ? (0.4f - sh.bob_t) / 0.2f : sinf(sh.bob_t / 0.2f * 1.5707964f)) * 0.5f : 0;
@@ -426,17 +445,18 @@ static void shop_draw(void) {
if (sh.cur > 0) ui_piece(&arrow_u, 0, bu + bob, 1, root);
if (sh.cur + 1 < sh.n) ui_piece(&arrow_d, 0, -bd + bob, 1, root);
ui_piece(&selector, 0, (sh.jitter > 0 ? rand_range(-0.11f, 0.11f) : 0) + bob, 1, root);
- ui_text_at(it->name, STYLE_TUTE, &t_name, 0, bob, 1, sh.root_a);
+ /* (its name over its column, on two lines where it is too long for one; what comes under it, lower by as much) */
+ float down = text_box(it->name, STYLE_TUTE, t_name.x, t_name.top + bob, t_name.w, 1, sh.root_a) -
+ font_line(font_style(STYLE_TUTE)) / HUD_PX;
int notch = it->type == ST_CHARM ? charm_cost(it->charm) : 0;
if (notch > 0) {
- /* (Notch Cost: its pegs, centred as Centre Pegs has them) */
- ui_text_at(TXT_SHOP_CHARM_TXT_NOTCHCOST, STYLE_MSG, &t_notch, 0, bob, 1, sh.root_a);
- for (int i = 0; i < notch && i < 6; i++) ui_piece(&peg, pegs_x[notch - 1] + i * SHOP_PEG_DX, bob, 1, root);
+ /* (Notch Cost: its pegs, centred as Centre Pegs has them, as far under its text as the game has them) */
+ const uint8_t *st = font_style(STYLE_MSG);
+ float pegs = peg.y - (t_notch.top - (font_asc(st) + font_desc(st)) / HUD_PX - SHOP_PEG_BELOW);
+ ui_text_at(TXT_SHOP_CHARM_TXT_NOTCHCOST, STYLE_MSG, &t_notch, 0, bob - down, 1, sh.root_a);
+ for (int i = 0; i < notch && i < 6; i++) ui_piece(&peg, pegs_x[notch - 1] + i * SHOP_PEG_DX, bob - down - pegs, 1, root);
}
- /* (its size: the message's, smaller where that runs out of the window) */
- float top = t_desc.top + (notch > 0 ? 0 : SHOP_DESC_DY);
- int style = top - text_box(it->desc, STYLE_MSG, 0, 0, t_desc.w, 0, 0) < SHOP_DESC_BOTTOM ? STYLE_MSG_S : STYLE_MSG;
- text_box(it->desc, style, t_desc.x, top + bob, t_desc.w, 0, sh.root_a);
+ desc_draw(it, bob, sh.root_a);
}
/* the confirmation: the item, its cost, the question, Yes and No (the pointers at the one chosen) */
if (sh.conf_a > 0) {
@@ -458,10 +478,13 @@ static void shop_draw(void) {
if (sh.thanks_a > 0) ui_text_at(TXT_SHOP_SHOP_PURCHASE_COMPLETE, STYLE_NOTICE, &t_thanks, 0, 0, 1, sh.thanks_a);
/* the actions: Buy and Exit, by their keys (Confirm and Cancel in the confirmation) */
if (sh.st == SH_LIST || sh.st == SH_CONFIRM) {
+ /* (each by its key, as far from it as the game has them) */
bool c = sh.st == SH_CONFIRM;
- ui_text_at(c ? TXT_SHOP_CTRL_CONFIRM : TXT_SHOP_CTRL_BUY, STYLE_MSG, &t_act_confirm, 0, 0, 2, 1);
- ui_text_at(c ? TXT_SHOP_CTRL_CANCEL : TXT_SHOP_CTRL_EXIT, STYLE_MSG, &t_act_cancel, 0, 0, 0, 1);
- key_at(key_confirm, TXT_KEY_OK, 1, white);
- key_at(key_cancel, TXT_KEY_BACK, 1, white);
+ const float kc[2] = {key_confirm[0] + SHOP_KEY_OUT, key_confirm[1]}, kb[2] = {key_cancel[0] - SHOP_KEY_OUT, key_cancel[1]};
+ float ok = key_at(kc, TXT_KEY_OK, 1, white), back = key_at(kb, TXT_KEY_BACK, 1, white);
+ ui_text_at(c ? TXT_SHOP_CTRL_CONFIRM : TXT_SHOP_CTRL_BUY, STYLE_MSG_S, &t_act_confirm, kc[0] - ok - SHOP_KEY_GAP -
+ t_act_confirm.x, 0, 2, 1);
+ ui_text_at(c ? TXT_SHOP_CTRL_CANCEL : TXT_SHOP_CTRL_EXIT, STYLE_MSG_S, &t_act_cancel, kb[0] + back + SHOP_KEY_GAP -
+ t_act_cancel.x, 0, 0, 1);
}
}
diff --git a/games/hollowknight/src/stag.c b/games/hollowknight/src/stag.c
index f3bbb894..47b300a0 100644
--- a/games/hollowknight/src/stag.c
+++ b/games/hollowknight/src/stag.c
@@ -12,6 +12,8 @@
#define HUD_PX (FOCAL / (-1.342f - CAM_Z))
#define NSTATIONS 3
#define RESERVE 80 /* (the frame's instances kept for it) */
+#define STAG_TITLE_OVER 0.16f /* (Stations' baseline over its divider, as the game has it) */
+#define STAG_KEYS_GAP 0.15f /* (between the two actions' lines) */
typedef struct {
float x, y, kx, ky;
@@ -156,11 +158,20 @@ static float key_box(const float *k, int name, float a, uint8_t white) {
return k[0] - ui_key(name, at[0] + k[0] * g, at[1] + k[1] * g, white, a);
}
-/* an action's text, ending before its key (the text bigger than the game's: kept clear of it) */
-static void act_text(int text, const UiText *t, float key_left) {
+/* an action's text, ending before its key (the text bigger than the game's: kept clear of it; the keys' actions'
+ * size, as elsewhere) */
+static void act_text(int text, const UiText *t, float key_left, float dy) {
UiText u = *t;
if (u.x > key_left - 0.15f) u.x = key_left - 0.15f;
- put_text(text, STYLE_MSG, &u, 0, 2, 1);
+ put_text(text, STYLE_MSG_S, &u, dy, 2, 1);
+}
+
+/* how much higher than the game's a text must be to keep above what is under it (its top at top, what is under it at
+ * under; as far over it as the game's) */
+static float raise(int style, float top, float under, float over) {
+ const uint8_t *st = font_style(style);
+ float d = font_asc(st) / HUD_PX + over - (top - under);
+ return d > 0 ? d : 0;
}
static void stag_draw(void) {
@@ -182,7 +193,7 @@ static void stag_draw(void) {
}
/* the list: its title and divider, its rows, the pointers at the current one, the Knight's icon by his station */
put_piece(&divider, 0, 0, faded);
- put_text(TXT_STAG_STATIONS, STYLE_MSG, &t_stations, 0, 1, fade);
+ put_text(TXT_STAG_STATIONS, STYLE_MSG, &t_stations, raise(STYLE_MSG, t_stations.top, divider.y, STAG_TITLE_OVER), 1, fade);
for (int i = 0; i < sg.n; i++) put_text(names[sg.rows[i]], STYLE_TUTE, &t_row, -i * STAG_ROW_DY, 1, fade);
/* (the names bigger than the game's: the icon and the pointers kept clear of them) */
float kx = fminf(list_knight.x, row0[0] - width_of(names[sg.rows[sg.init]], STYLE_TUTE) / 2 - 0.6f) - list_knight.x;
@@ -193,8 +204,13 @@ static void stag_draw(void) {
put_piece(&ptr_l, row0[0] - px - ptr_l.x, y, white);
put_piece(&ptr_r, row0[0] + px - ptr_r.x, y, white);
/* the action keys (Buttons: after half a second) */
- act_text(TXT_STAG_CTRL_TRAVEL, &t_act_confirm, key_box(key_confirm, TXT_KEY_OK, 1, white));
- act_text(TXT_STAG_CTRL_CANCEL, &t_act_cancel, key_box(key_cancel, TXT_KEY_BACK, 1, white));
+ /* (Travel over Cancel: higher, for both their bigger text) */
+ const uint8_t *st = font_style(STYLE_MSG_S);
+ float up = (font_asc(st) + font_desc(st)) / HUD_PX + STAG_KEYS_GAP - (key_confirm[1] - key_cancel[1]);
+ up = up > 0 ? up : 0;
+ const float kc[2] = {key_confirm[0], key_confirm[1] + up};
+ act_text(TXT_STAG_CTRL_TRAVEL, &t_act_confirm, key_box(kc, TXT_KEY_OK, 1, white), up);
+ act_text(TXT_STAG_CTRL_CANCEL, &t_act_cancel, key_box(key_cancel, TXT_KEY_BACK, 1, white), 0);
}
for (int i = 0; i < 2; i++)
if (sg.border[i].sprite >= 0) put(sg.border[i].sprite, borders[i].x, borders[i].y, borders[i].kx, borders[i].ky, white);
diff --git a/games/hollowknight/src/text.c b/games/hollowknight/src/text.c
index b4bdae8a..950af5e5 100644
--- a/games/hollowknight/src/text.c
+++ b/games/hollowknight/src/text.c
@@ -1,9 +1,13 @@
/* Text: the game's sheets' entries (TEXT, in the pack's own code page) in its fonts (FONT: glyphs of 4-bit alpha);
* the dialogue box (DialogueManager: Box Open, its Text's DialogueBox and Dialogue Page Control) and the prompt
- * markers over what the Knight can act on (PromptMarker). Text is a third bigger than the game's (tools/text.py),
- * the boxes with it. */
+ * markers over what the Knight can act on (PromptMarker). The boxes are a third bigger than the game's, the text read
+ * in them bigger still, to read on the calculator's screen (tools/text.py: the titles as the game has them). */
#include <math.h>
#include "game.h"
+#ifdef HOST
+#include <stdio.h>
+#include <stdlib.h>
+#endif
#define DT 0.02f
#define HUD_PX (FOCAL / (-1.342f - CAM_Z)) /* (the HUD's pixels a unit) */
@@ -73,6 +77,22 @@ float text_box(int text, int style, float x, float y, float w, int align, float
return lines * font_line(st) / px;
}
+/* a description's style: the message's, else the smaller ones, the first in which it fits in room (HUD units) down
+ * from its top, w wide (the last, where none does) */
+#ifdef HOST
+uint32_t g_text_overrun; /* (tests: a text too long for its box even in the smallest) */
+#endif
+int text_fit(int text, float w, float room) {
+ static const int8_t styles[] = {STYLE_MSG, STYLE_MSG_S, STYLE_MSG_XS};
+ for (unsigned i = 0; i < sizeof styles; i++)
+ if (text_box(text, styles[i], 0, 0, w, 0, 0) <= room + 0.01f) return styles[i];
+#ifdef HOST
+ g_text_overrun++;
+ if (getenv("HKOVERRUN")) printf(" text %d: %.2f high in MSG_XS, room %.2f\n", text, text_box(text, STYLE_MSG_XS, 0, 0, w, 0, 0), room);
+#endif
+ return STYLE_MSG_XS;
+}
+
/* ---------------------------------------------------------------- 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/tests/check.py b/games/hollowknight/tests/check.py
index 38eb27d8..ed394bd5 100644
--- a/games/hollowknight/tests/check.py
+++ b/games/hollowknight/tests/check.py
@@ -5,6 +5,8 @@
the ground, and can slash and move; and spikes there send him back to a good place
- the ground's seams, as the calculator rounds: landed a few float steps low, the Knight walks off both ways; jumping
at a wall, he falls back down
+- the text of the shops, the inventory (its items, charms and map), the menus, the messages and the stag's menu: in the
+ screen, in its box, no line over another
- every arena won: its fight over and the room's battle gates open, also as the Knight comes back and after a save and
a load
- a long walk of made up keys from every room: the Knight never out of the room, without control, wedged, undrawn or
@@ -54,6 +56,9 @@ def main():
results.append(report("gates", rc, out, ("FAIL",)))
rc, out = play("--gates", "seams")
results.append(report("seams", rc, out, ("FAIL",)))
+ with tempfile.TemporaryDirectory() as saves:
+ rc, out = play("--gates", "texts", env={"HKSAVES": saves})
+ results.append(report("texts", rc, out, ("FAIL",)))
with tempfile.TemporaryDirectory() as saves:
rc, out = play("--gates", "arenas", env={"HKSAVES": saves})
results.append(report("arenas", rc, out, ("FAIL",)))
diff --git a/games/hollowknight/tests/play.c b/games/hollowknight/tests/play.c
index 5b022ad0..2be26c93 100644
--- a/games/hollowknight/tests/play.c
+++ b/games/hollowknight/tests/play.c
@@ -348,7 +348,161 @@ static int seams_test(void) {
return fails ? 1 : 0;
}
+/* the text on the screens that show much of it (the shops, the inventory and its charms and map, the menus, the
+ * messages, a conversation), each frame drawn: in the screen, no line over another, none left out (gfx.c's audit) */
+extern bool g_text_audit;
+extern char g_text_audit_log[2048];
+static int text_fails;
+static char text_seen[64][160];
+static int text_nseen;
+static void text_frame(const char *where, bool menu) {
+ if (menu) {
+ g_gfx_no_room = !menu_in_game();
+ if (menu_in_game()) game_draw_layers();
+ menu_draw();
+ gfx_frame();
+ } else
+ game_draw();
+ if (getenv("HKTEXTSHOTS")) { /* (each frame checked, as an image: HKTEXTSHOTS=its folder) */
+ static int nshot;
+ char path[256];
+ snprintf(path, sizeof path, "%s/%03d_%s.ppm", getenv("HKTEXTSHOTS"), nshot++, where);
+ for (char *c = path + strlen(getenv("HKTEXTSHOTS")) + 1; *c; c++)
+ if (*c == ' ') *c = '_';
+ host_shot(path);
+ }
+ extern uint32_t g_text_overrun;
+ if (g_text_overrun) {
+ size_t k = strlen(g_text_audit_log);
+ snprintf(g_text_audit_log + k, sizeof g_text_audit_log - k, "a description too long for its box; ");
+ g_text_overrun = 0;
+ }
+ if (!g_text_audit_log[0]) return;
+ char line[160];
+ snprintf(line, sizeof line, "%s: %s", where, g_text_audit_log);
+ for (int i = 0; i < text_nseen; i++)
+ if (!strcmp(text_seen[i], line)) return;
+ if (text_nseen < 64) strcpy(text_seen[text_nseen++], line);
+ printf("FAIL texts %s\n", line);
+ text_fails++;
+}
+/* (keys as --play has them; each step drawn) */
+static void text_keys(const char *where, const char *keys, bool menu) {
+ for (const char *p = keys; *p;) {
+ uint32_t k = 0;
+ for (; *p && *p != '*'; p++)
+ k |= *p == 'L' ? K_LEFT : *p == 'R' ? K_RIGHT : *p == 'U' ? K_UP : *p == 'D' ? K_DOWN : *p == 'O' ? K_OK | K_JUMP
+ : *p == 'B' ? K_BACK | K_ATTACK : *p == 'P' ? K_PAUSE : *p == 'I' ? K_INV : *p == 'M' ? K_MAP
+ : *p == 'S' ? K_DASH : 0;
+ int n = *p == '*' ? atoi(++p) : 1;
+ while (*p && *p != ',') p++;
+ if (*p == ',') p++;
+ for (int i = 0; i < n; i++) {
+ if (!menu || !menu_tick(k)) game_tick(stag_tick(shop_tick(inv_tick(k))));
+ if (i == n - 1) text_frame(where, menu); /* (as it settles: panes slide, windows open) */
+ }
+ }
+}
+static void text_room(const char *room, float x, float y, const char *flags) {
+ game_new();
+ g_pd.geo = 9999;
+ for (const char *f = flags; *f;) {
+ pd_set_flag(atoi(f), true);
+ while (*f && *f != ',') f++;
+ if (*f) f++;
+ }
+ for (int r = 0; r < NUM_ROOMS; r++)
+ if (!strcmp(room_name(r), room)) game_enter(r, x, y, true);
+}
+static int texts_test(void) {
+ g_text_audit = true;
+ char down[512] = "_*80,U*2,_*100";
+ for (int i = 0; i < 14; i++) strcat(down, ",D*2,_*25");
+ /* the shops: every row, then the confirmation (a new game's stock; then with the maps and pins had, the rest) */
+ static const struct { const char *room; float x; const char *flags; } shops[] = {
+ {"Room_mapper", 17.35f, "123,149"}, {"Room_mapper", 17.35f, "123,149,1,2,130,131,132,133,134,135,136"},
+ {"Room_shop", 15.6f, "23,122"}, {"Room_Charm_Shop", 17.14f, "124"}};
+ for (unsigned k = 0; k < sizeof shops / sizeof shops[0]; k++) {
+ text_room(shops[k].room, shops[k].x, 6.5f, shops[k].flags);
+ text_keys(shops[k].room, down, false);
+ text_keys(shops[k].room, "O*2,_*60,D*2,_*20,B*2,_*40", false);
+ }
+ /* the inventory: its panes, every place on them (with all it can hold); the charms, every one (at a bench too); the
+ * map */
+ for (int bench = 0; bench < 2; bench++) {
+ text_room("Town", 60, 12, bench ? "0,1,2,3,14,119,123,37,38,39,40,42,43,44,45,50,53,54,55,56,57"
+ : "1,2,3,14,119,123,37,38,39,40,42,43,44,45,50,53,54,55,56,57");
+ g_pd.charm_slots = 3, g_pd.has_spell = true, g_pd.fireball_level = 1, g_pd.simple_keys = 1, g_pd.rancid_eggs = 1;
+ g_pd.heart_pieces = 2, g_pd.vessel_fragments = 1;
+ pd_set_flag(PDF_HEART_PIECE_COLLECTED, true), pd_set_flag(PDF_VESSEL_FRAGMENT_COLLECTED, true);
+ for (int i = 0; i < 4; i++) g_pd.trinkets[i] = 1;
+ char keys[1024] = "_*40,I*2,_*60";
+ for (int i = 0; i < 6; i++) { /* (each row, left to right, then down) */
+ for (int j = 0; j < 7; j++) strcat(keys, ",R*2,_*15");
+ strcat(keys, ",D*2,_*15");
+ for (int j = 0; j < 7; j++) strcat(keys, ",L*2,_*15");
+ strcat(keys, ",D*2,_*15");
+ }
+ text_keys(bench ? "inventory at a bench" : "inventory", keys, false);
+ }
+ /* the quick map of each area */
+ static const char *const quick[] = {"Town", "Crossroads_04", "Fungus1_01"};
+ for (unsigned i = 0; i < sizeof quick / sizeof quick[0]; i++) {
+ text_room(quick[i], 20, 12, "1,2,6,12,16,130,131");
+ memset(g_pd.rooms_mapped, 0xFF, sizeof g_pd.rooms_mapped), memset(g_pd.rooms_visited, 0xFF, sizeof g_pd.rooms_visited);
+ text_keys("quick map", "_*60,M*90", false);
+ }
+ /* the inventory's map, its key and pins shown (Shift); the stag's menu, every station open */
+ text_room("Town", 60, 12, "1,2,130,131,132,133,134,135,136,137,138,139,140,141,142");
+ memset(g_pd.rooms_mapped, 0xFF, sizeof g_pd.rooms_mapped), memset(g_pd.rooms_visited, 0xFF, sizeof g_pd.rooms_visited);
+ text_keys("map", "_*40,I*2,_*60,L*2,_*20,L*2,_*20,L*2,_*20,L*2,_*40,S*2,_*30,S*2,_*30,S*2,_*30,O*2,_*80,S*2,_*30,B*2,_*60",
+ false);
+ {
+ static const int16_t opened[] = STAG_OPENED;
+ text_room("Room_Town_Stag_Station", 40, 8, "");
+ for (unsigned i = 0; i < sizeof opened / sizeof opened[0]; i++)
+ if (opened[i] >= 0) pd_set_flag(opened[i], true);
+ g_pd.stag_position1 = 1;
+ stag_menu_open(0, 0);
+ text_keys("stag", "_*60,D*2,_*20,D*2,_*20", false);
+ }
+ /* the menus: the title, the profiles, how to play's two pages, the pause menu */
+ game_new();
+ menu_start();
+ text_keys("menus", "_*40,O*2,_*40,B*2,_*30,D*2,_*10,O*2,_*40,O*2,_*40,O*2,_*30", true);
+ /* the messages as the fireball and the dash are taken; a relic's notice; the charm tutorial */
+ text_room("Crossroads_01", 40, 12, "");
+ msg_show(MSG_FIREBALL);
+ text_keys("message", "_*200", false);
+ text_room("Crossroads_01", 40, 12, "");
+ msg_show(MSG_DASH);
+ text_keys("message", "_*200", false);
+ /* a relic's notice; a charm's, and the charm tutorial */
+ {
+ typedef struct { int16_t name, desc; } ND;
+ static const ND tr[4] = TXT_INV_TRINKETS;
+ text_room("Crossroads_01", 40, 12, "");
+ notice_icon(0);
+ notice_show(tr[0].name);
+ text_keys("notice", "_*30,_*60,_*100", false);
+ text_room("Crossroads_01", 40, 12, "");
+ charm_notice(1);
+ text_keys("charm notice", "_*30,_*60,_*100", false);
+ text_room("Crossroads_01", 40, 12, "");
+ charm_tute();
+ text_keys("charm tutorial", "_*30,_*60,_*100", false);
+ charm_tute_close();
+ }
+ /* a conversation (Elderbug's first) */
+ text_room("Town", 76, 12, "");
+ text_keys("Elderbug", "_*40,U*2,_*120,O*2,_*60,O*2,_*60,O*2,_*60,O*2,_*60,O*2,_*60", false);
+ g_text_audit = false;
+ printf("texts: %d failing\n", text_fails);
+ return text_fails ? 1 : 0;
+}
+
static int gates_test(const char *which) {
+ if (!strcmp(which, "texts")) return texts_test();
if (!strcmp(which, "seams")) return seams_test();
if (!strcmp(which, "markers")) return markers_test();
if (!strcmp(which, "arenas")) return arenas_test();
diff --git a/games/hollowknight/tools/text.py b/games/hollowknight/tools/text.py
index 5d5bec46..a529863c 100644
--- a/games/hollowknight/tools/text.py
+++ b/games/hollowknight/tools/text.py
@@ -73,40 +73,52 @@ HUD_PX = 100 / 8.7107 # (the HUD camera's: pixels a unit)
WORLD_PX = 421.94 / 38.1 # (the room's camera, at z = 0)
-def _style(font, size, px, line_height, line_spacing, point, asc, desc, k=TEXT_K, spacing=0.0, phases=PHASES):
- em = size * 0.1 * px * k
+def _style(font, size, px, line_height, line_spacing, point, asc, desc, k=TEXT_K, spacing=0.0, phases=PHASES, em=None):
+ """(em: in pixels, else the game's size, k times; the body text's at sizes that read on the calculator's screen)"""
+ em = em or size * 0.1 * px * k
return (font, em, (line_height + line_spacing) / point * em, asc / point * em, -desc / point * em, spacing / 100 * em,
phases)
+# the body text's sizes (ems in pixels): what is read, bigger than the game's at this screen's size (its titles as
+# they are); two pen phases, half a pixel apart, enough at these sizes (and styles of the same font and size share
+# their glyphs)
+READ_EM, DESC_EM, SMALL_EM, XSMALL_EM = 14.0, 12.5, 11.0, 9.2
+PERPETUA = (134.0625, 0, 117, 95.9375, -38.1875)
+
+
# (Trajan Pro's metrics: trajan_bold_tmpro's point size, line height, ascender, descender)
TRAJAN = (84, 0, 70, 52.5, -17.5)
STYLES = {
- "DIALOGUE": _style("Perpetua", 7.2, HUD_PX, 134.0625, 24.6, 117, 95.9375, -38.1875),
- "PROMPT": _style("TrajanPro-Bold", 6.67, WORLD_PX, *TRAJAN),
+ "DIALOGUE": _style("Perpetua", 7.2, HUD_PX, 134.0625, 24.6, 117, 95.9375, -38.1875, em=READ_EM, phases=2),
+ "PROMPT": _style("TrajanPro-Bold", 6.67, WORLD_PX, *TRAJAN, em=11.5, phases=2),
# the area titles (Area Title: TextMeshPro, size 36): the large one's main line, the small one's, and the lines
# above and below them (the large title's at their own size; the small one's, a third bigger, the same)
"TITLE_L": _style("TrajanPro-Bold", 36 * 0.4902, HUD_PX, *TRAJAN, k=1, spacing=4.69, phases=1),
"TITLE_S": _style("TrajanPro-Bold", 36 * 0.3493, HUD_PX, *TRAJAN, k=1, spacing=4.69, phases=1),
"TITLE_SUB": _style("TrajanPro-Bold", 36 * 0.1942, HUD_PX, *TRAJAN, k=1, spacing=21.06),
# 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": _style("Perpetua", 3.73 * 1.4407, HUD_PX, *PERPETUA, em=DESC_EM, phases=2),
"MSG_NAME": _style("TrajanPro-Bold", 9.32 * 1.4407, HUD_PX, *TRAJAN, k=1, phases=1),
# the notices as a relic or a charm is taken (Relic Get Msg, Charm Get Msg: Perpetua 8), the charm tutorial's title
# (9) and its lines (6)
- "NOTICE": _style("Perpetua", 8, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
+ "NOTICE": _style("Perpetua", 8, HUD_PX, *PERPETUA, em=READ_EM, phases=2),
"TUTE_TITLE": _style("Perpetua", 9, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875, phases=1),
- "TUTE": _style("Perpetua", 6, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
+ "TUTE": _style("Perpetua", 6, HUD_PX, *PERPETUA, em=DESC_EM, phases=2),
# 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": _style("TrajanPro-Bold", 31 / 6 * 1.6 * 10, 1, *TRAJAN, em=10.5, phases=2),
"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),
+ "MENU_SMALL": _style("TrajanPro-Regular", 27 / 6 * 1.6 * 10, 1, *TRAJAN, em=9.5, phases=2),
# the yes or no box's Yes and No (Text YN's UI List: TextMeshPro 10)
"YN": _style("Perpetua", 10, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
# a shop's long descriptions, smaller (still bigger than the game's) where the message's size runs out of the window
- "MSG_S": _style("Perpetua", 3.73 * 1.4407 * 0.78, HUD_PX, 134.0625, 0, 117, 95.9375, -38.1875),
+ "MSG_S": _style("Perpetua", 3.73 * 1.4407 * 0.78, HUD_PX, *PERPETUA, em=SMALL_EM, phases=2),
+ # the longest descriptions (the inventory's relics, some charms), where neither fits their box
+ "MSG_XS": _style("Perpetua", 3.73 * 1.4407 * 0.78, HUD_PX, *PERPETUA, em=XSMALL_EM, phases=2),
}
+# (the styles a text falls back to where it does not fit: every character of the one it stands in for)
+FALLBACKS = {"MSG_S": "MSG", "MSG_XS": "MSG"}
# the items the message shows: (its name in the UI sheet, the Prompts sheet's prefix, tap or press, its two lines, the
# calculator's key for it)
@@ -168,21 +180,27 @@ class Texts:
alpha (low nibble first)."""
import font
cp = self.code_page()
- blocks = []
+ # (styles of the same font, size, spacing and phases share one set of glyphs: those of all of them; the others'
+ # blocks, their metrics and offsets only, go just before the one with the glyphs, their offsets reaching on)
+ groups = {}
for name, (fname, em, line, asc, desc, spacing, phases) in STYLES.items():
- chars = sorted({c for s, st in self.list if st == name for c in s if c not in "\n\f"} | {" ", "-"})
+ groups.setdefault((fname, em, spacing, phases), []).append(name)
+ blocks = {}
+ for (fname, em, spacing, phases), names in groups.items():
+ names_in = set(names) | {FALLBACKS[n] for n in names if n in FALLBACKS}
+ chars = sorted({c for s, st in self.list if st in names_in for c in s if c not in "\n\f"} | {" ", "-"})
lo = min(cp[c] for c in chars)
ncodes = max(cp[c] for c in chars) - lo + 1
- head = bytearray(struct.pack("<ffffBBH", em, line, asc, desc, lo, ncodes, 0))
- offs = [0] * (ncodes * PHASES)
+ heads = 20 + 2 * ncodes * PHASES # (a block's metrics and offsets)
body = bytearray()
- base = len(head) + 2 * len(offs)
+ at = {} # (code - lo) * PHASES + pen phase -> its glyph, from the glyphs' start
for ph in range(phases):
- for ch, g in zip(chars, font.bitmaps(fname, chars, em, ph / PHASES)):
+ for ch, g in zip(chars, font.bitmaps(fname, chars, em, ph / phases)):
a, left, top, adv = g
h, w = a.shape
- for q in range(ph, PHASES, phases): # (big text: one phase for all)
- offs[(cp[ch] - lo) * PHASES + q] = base + len(body)
+ for q in range(PHASES): # (each pen phase, the nearest drawn below it; big text: one for all)
+ if q * phases // PHASES == ph:
+ at[(cp[ch] - lo) * PHASES + q] = len(body)
body += struct.pack("<BBbbH", w, h, left, top, min(65535, round((adv + spacing) * 64)))
q = (a.astype(np.uint16) * 15 + 127) // 255
for row in q:
@@ -190,15 +208,22 @@ class Texts:
body += bytes(r[i] | r[i + 1] << 4 for i in range(0, len(r), 2))
if len(body) & 1:
body.append(0)
- assert base + len(body) < 65536, name
while len(body) % 4:
body.append(0)
- blocks.append(bytes(head) + struct.pack("<%dH" % len(offs), *offs) + bytes(body))
+ for k, name in enumerate(names):
+ _, _, line, asc, desc, _, _ = STYLES[name]
+ head = struct.pack("<ffffBBH", em, line, asc, desc, lo, ncodes, 0)
+ base = heads * (len(names) - k) # (the glyphs, from this block's start)
+ offs = [0] * (ncodes * PHASES)
+ for i, o in at.items():
+ offs[i] = base + o
+ assert max(offs) < 65536, name
+ blocks[name] = head + struct.pack("<%dH" % len(offs), *offs) + (bytes(body) if k == len(names) - 1 else b"")
out = bytearray(struct.pack("<I", len(blocks)))
pos = 4 + 4 * len(blocks)
- for b in blocks:
- out += struct.pack("<I", pos)
- pos += len(b)
- for b in blocks:
- out += b
+ order = [n for names in groups.values() for n in names]
+ for name in STYLES:
+ out += struct.pack("<I", pos + sum(len(blocks[n]) for n in order[:order.index(name)]))
+ for name in order:
+ out += blocks[name]
return bytes(out)