From bf9c9d5e754d1b662817fff8dda7f82b10981fa1 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Sun, 7 Jan 2024 20:23:24 -0500 Subject: [PATCH] Remove FONT_TINY and introduce legacy compatibility for it --- autogen/lua_constants/built-in.lua | 15 ++++++++++++++- autogen/lua_definitions/constants.lua | 20 +++++++++++++++----- autogen/lua_definitions/functions.lua | 2 +- docs/lua/constants.md | 5 ++--- docs/lua/functions-3.md | 4 ++-- src/pc/djui/djui_font.c | 15 --------------- src/pc/djui/djui_hud_utils.c | 14 ++++++++++++-- src/pc/djui/djui_hud_utils.h | 3 +-- src/pc/lua/smlua_constants_autogen.c | 15 ++++++++++++--- src/pc/lua/smlua_functions_autogen.c | 2 +- 10 files changed, 60 insertions(+), 35 deletions(-) diff --git a/autogen/lua_constants/built-in.lua b/autogen/lua_constants/built-in.lua index 398fb58d..90f10630 100644 --- a/autogen/lua_constants/built-in.lua +++ b/autogen/lua_constants/built-in.lua @@ -1,5 +1,9 @@ math.randomseed(get_time()) +-------------- +-- CObjects -- +-------------- + _CObjectPool = {} _CObject = { @@ -88,6 +92,10 @@ _ReadOnlyTable = { end } +-------------------- +-- math functions -- +-------------------- + --- @param dest Vec3f --- @param src Vec3f --- @return Vec3f @@ -382,4 +390,9 @@ COURSE_MAX = 25 --- @type integer COURSE_COUNT = 25 --- @type integer -COURSE_MIN = 1 \ No newline at end of file +COURSE_MIN = 1 + +----------------- +-- legacy font -- +----------------- +FONT_TINY = -1 \ No newline at end of file diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index bab0d432..5f606259 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -2,6 +2,10 @@ math.randomseed(get_time()) +-------------- +-- CObjects -- +-------------- + _CObjectPool = {} _CObject = { @@ -90,6 +94,10 @@ _ReadOnlyTable = { end } +-------------------- +-- math functions -- +-------------------- + --- @param dest Vec3f --- @param src Vec3f --- @return Vec3f @@ -386,6 +394,11 @@ COURSE_COUNT = 25 --- @type integer COURSE_MIN = 1 +----------------- +-- legacy font -- +----------------- +FONT_TINY = -1 + --- @type integer INSTANT_WARP_INDEX_START = 0x00 @@ -3462,13 +3475,10 @@ FONT_MENU = 1 FONT_HUD = 2 --- @type DjuiFontType -FONT_TINY = 3 +FONT_ALIASED = 3 --- @type DjuiFontType -FONT_ALIASED = 4 - ---- @type DjuiFontType -FONT_COUNT = 5 +FONT_COUNT = 4 --- @class HudUtilsFilter diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 0c8650c0..c0900eb9 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -3764,7 +3764,7 @@ function djui_hud_set_filter(filterType) -- ... end ---- @param fontType DjuiFontType +--- @param fontType integer --- @return nil function djui_hud_set_font(fontType) -- ... diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 09b377ff..0b66f08a 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -1169,9 +1169,8 @@ | FONT_NORMAL | 0 | | FONT_MENU | 1 | | FONT_HUD | 2 | -| FONT_TINY | 3 | -| FONT_ALIASED | 4 | -| FONT_COUNT | 5 | +| FONT_ALIASED | 3 | +| FONT_COUNT | 4 | ### [enum HudUtilsFilter](#HudUtilsFilter) | Identifier | Value | diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md index 7b26dbb5..db64d0ae 100644 --- a/docs/lua/functions-3.md +++ b/docs/lua/functions-3.md @@ -2502,13 +2502,13 @@ ### Parameters | Field | Type | | ----- | ---- | -| fontType | [enum DjuiFontType](constants.md#enum-DjuiFontType) | +| fontType | `integer` | ### Returns - None ### C Prototype -`void djui_hud_set_font(enum DjuiFontType fontType);` +`void djui_hud_set_font(s8 fontType);` [:arrow_up_small:](#) diff --git a/src/pc/djui/djui_font.c b/src/pc/djui/djui_font.c index 18000524..c67e954a 100644 --- a/src/pc/djui/djui_font.c +++ b/src/pc/djui/djui_font.c @@ -133,20 +133,6 @@ static const struct DjuiFont sDjuiFontHud = { .char_width = djui_font_hud_char_width, }; - /////////////////////////////// - // font 4 (legacy tiny font) // -/////////////////////////////// - -static const struct DjuiFont sDjuiFontTiny = { - .charWidth = 0.5f, - .charHeight = 1.0f, - .lineHeight = 0.8125f, - .defaultFontScale = 16.0f, - .textBeginDisplayList = NULL, - .render_char = djui_font_normal_render_char, - .char_width = djui_font_normal_char_width, -}; - //////////////////////////////// // font 5 (DJ's aliased font) // //////////////////////////////// @@ -187,6 +173,5 @@ const struct DjuiFont* gDjuiFonts[] = { &sDjuiFontNormal, &sDjuiFontTitle, &sDjuiFontHud, - &sDjuiFontTiny, &sDjuiFontAliased }; \ No newline at end of file diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index 05aea41e..5085088d 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -30,6 +30,7 @@ static enum DjuiFontType sFont = FONT_NORMAL; static struct HudUtilsRotation sRotation = { 0, 0, 0 }; static struct DjuiColor sColor = { 255, 255, 255, 255 }; static struct DjuiColor sRefColor = { 255, 255, 255, 255 }; +static bool sLegacy = false; f32 gDjuiHudUtilsZ = 0; u8 gDjuiHudLockMouse = false; @@ -168,8 +169,10 @@ u8 djui_hud_get_font(void) { return sFont; } -void djui_hud_set_font(enum DjuiFontType fontType) { +void djui_hud_set_font(s8 fontType) { if (fontType >= FONT_COUNT) { return; } + sLegacy = fontType == -1; + if (sLegacy) { fontType = 0; } sFont = fontType; } @@ -270,7 +273,7 @@ f32 djui_hud_measure_text(const char* message) { f32 width = 0; const char* c = message; while(*c != '\0') { - width += font->char_width((char*)c); + width += font->char_width((char*)c) * (sLegacy ? 0.5f : 1.0f); c = djui_unicode_next_char((char*)c); } return width * font->defaultFontScale; @@ -280,6 +283,8 @@ void djui_hud_print_text(const char* message, f32 x, f32 y, f32 scale) { if (message == NULL) { return; } gDjuiHudUtilsZ += 0.01f; + if (sLegacy) { scale *= 0.5f; } + const struct DjuiFont* font = gDjuiFonts[sFont]; f32 fontScale = font->defaultFontScale * scale; @@ -328,6 +333,11 @@ void djui_hud_print_text_interpolated(const char* message, f32 prevX, f32 prevY, f32 savedZ = gDjuiHudUtilsZ; gDjuiHudUtilsZ += 0.01f; + if (sLegacy) { + prevScale *= 0.5f; + scale *= 0.5f; + } + const struct DjuiFont* font = gDjuiFonts[sFont]; f32 fontScale = font->defaultFontScale * scale; diff --git a/src/pc/djui/djui_hud_utils.h b/src/pc/djui/djui_hud_utils.h index 60403e00..9db32aa1 100644 --- a/src/pc/djui/djui_hud_utils.h +++ b/src/pc/djui/djui_hud_utils.h @@ -17,7 +17,6 @@ enum DjuiFontType { FONT_NORMAL, FONT_MENU, FONT_HUD, - FONT_TINY, FONT_ALIASED, FONT_COUNT, }; @@ -54,7 +53,7 @@ void djui_hud_set_resolution(enum HudUtilsResolution resolutionType); u8 djui_hud_get_filter(void); void djui_hud_set_filter(enum HudUtilsFilter filterType); u8 djui_hud_get_font(void); -void djui_hud_set_font(enum DjuiFontType fontType); +void djui_hud_set_font(s8 fontType); struct DjuiColor* djui_hud_get_color(void); void djui_hud_set_color(u8 r, u8 g, u8 b, u8 a); void djui_hud_reset_color(void); diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 698e9be3..9f80144e 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -1,5 +1,8 @@ char gSmluaConstants[] = "" "math.randomseed(get_time())\n" +"--------------\n" +"-- CObjects --\n" +"--------------\n" "_CObjectPool = {}\n" "_CObject = {\n" " __index = function (t,k)\n" @@ -76,6 +79,9 @@ char gSmluaConstants[] = "" " __newindex = function (t,k,v)\n" " end\n" "}\n" +"--------------------\n" +"-- math functions --\n" +"--------------------\n" "--- @param dest Vec3f\n" "--- @param src Vec3f\n" "--- @return Vec3f\n" @@ -346,6 +352,10 @@ char gSmluaConstants[] = "" "COURSE_COUNT = 25\n" "--- @type integer\n" "COURSE_MIN = 1\n" +"-----------------\n" +"-- legacy font --\n" +"-----------------\n" +"FONT_TINY = -1\n" "INSTANT_WARP_INDEX_START = 0x00\n" "INSTANT_WARP_INDEX_STOP = 0x04\n" "MAX_AREAS = 16\n" @@ -1371,9 +1381,8 @@ char gSmluaConstants[] = "" "FONT_NORMAL = 0\n" "FONT_MENU = 1\n" "FONT_HUD = 2\n" -"FONT_TINY = 3\n" -"FONT_ALIASED = 4\n" -"FONT_COUNT = 5\n" +"FONT_ALIASED = 3\n" +"FONT_COUNT = 4\n" "ENVFX_MODE_NONE = 0\n" "ENVFX_SNOW_NORMAL = 1\n" "ENVFX_SNOW_WATER = 2\n" diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index a71ebaea..906ef4ca 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -12471,7 +12471,7 @@ int smlua_func_djui_hud_set_font(lua_State* L) { return 0; } - int fontType = smlua_to_integer(L, 1); + s8 fontType = smlua_to_integer(L, 1); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_hud_set_font"); return 0; } djui_hud_set_font(fontType);