From 7ebe54681e777b01504352018ada8b6d1dad960d Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:16:58 -0400 Subject: [PATCH] Add DJUI Font option --- lang/Czech.ini | 3 + lang/Dutch.ini | 3 + lang/English.ini | 3 + lang/French.ini | 3 + lang/German.ini | 3 + lang/Italian.ini | 3 + lang/Polish.ini | 3 + lang/Portuguese.ini | 3 + lang/Russian.ini | 3 + lang/Spanish.ini | 3 + src/pc/configfile.c | 19 +++-- src/pc/configfile.h | 1 + src/pc/djui/djui_font.c | 4 +- src/pc/djui/djui_panel_menu_options.c | 3 +- src/pc/djui/djui_text.c | 3 +- src/pc/djui/djui_unicode.c | 114 +++++++++++++------------- src/pc/djui/djui_unicode.h | 2 +- 17 files changed, 106 insertions(+), 70 deletions(-) diff --git a/lang/Czech.ini b/lang/Czech.ini index 361ee4219..5a6d76fe1 100644 --- a/lang/Czech.ini +++ b/lang/Czech.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Zobrazit FPS" [DJUI_THEMES] DJUI_THEME = "Téma DJUI" DJUI_SCALE = "Stupnice DJUI" +DJUI_FONT = "DJUI Font" AUTO = "Automatický" CENTER = "Střed" +FONT_NORMAL = "Normální" +FONT_ALIASED = "Hladký" LIGHT_THEME = "Světlo" DARK_THEME = "Tmavý" MARIO_THEME = "Mario" diff --git a/lang/Dutch.ini b/lang/Dutch.ini index d5356311a..6eae13e78 100644 --- a/lang/Dutch.ini +++ b/lang/Dutch.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Toon FPS" [DJUI_THEMES] DJUI_THEME = "DJUI Thema" DJUI_SCALE = "DJUI Schaal" +DJUI_FONT = "DJUI-lettertype" AUTO = "Automatisch" CENTER = "Centreren" +FONT_NORMAL = "Normaal" +FONT_ALIASED = "Glad" LIGHT_THEME = "Licht" DARK_THEME = "Donker" MARIO_THEME = "Mario" diff --git a/lang/English.ini b/lang/English.ini index 9c689a71b..cdf6344be 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Show FPS" [DJUI_THEMES] DJUI_THEME = "DJUI Theme" DJUI_SCALE = "DJUI Scale" +DJUI_FONT = "DJUI Font" AUTO = "Auto" CENTER = "Center" +FONT_NORMAL = "Normal" +FONT_ALIASED = "Aliased" LIGHT_THEME = "Light" DARK_THEME = "Dark" MARIO_THEME = "Mario" diff --git a/lang/French.ini b/lang/French.ini index d8b81a99f..4114b8fc9 100644 --- a/lang/French.ini +++ b/lang/French.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Afficher FPS" [DJUI_THEMES] DJUI_THEME = "Thème DJUI" DJUI_SCALE = "Échelle DJUI" +DJUI_FONT = "Police DJUI" AUTO = "Automatique" CENTER = "Centrer" +FONT_NORMAL = "Normal" +FONT_ALIASED = "Lisse" LIGHT_THEME = "Lumière" DARK_THEME = "Sombre" MARIO_THEME = "Mario" diff --git a/lang/German.ini b/lang/German.ini index 6b0f20049..a909dd27e 100644 --- a/lang/German.ini +++ b/lang/German.ini @@ -148,8 +148,11 @@ SHOW_FPS = "FPS anzeigen" [DJUI_THEMES] DJUI_THEME = "DJUI-Thema" DJUI_SCALE = "DJUI-Skala" +DJUI_FONT = "DJUI-Schriftart" AUTO = "Automatisch" CENTER = "Zentrieren" +FONT_NORMAL = "Normal" +FONT_ALIASED = "Glatt" LIGHT_THEME = "Litch" DARK_THEME = "Dunkel" MARIO_THEME = "Mario" diff --git a/lang/Italian.ini b/lang/Italian.ini index bc6aaaf16..57fb669c7 100644 --- a/lang/Italian.ini +++ b/lang/Italian.ini @@ -146,8 +146,11 @@ SHOW_FPS = "Mostra FPS" [DJUI_THEMES] DJUI_THEME = "Tema DJUI" DJUI_SCALE = "Scala DJUI" +DJUI_FONT = "Font DJUI" AUTO = "Automatico" CENTER = "Centrare" +FONT_NORMAL = "Normale" +FONT_ALIASED = "Liscio" LIGHT_THEME = "Luce" DARK_THEME = "Scuro" MARIO_THEME = "Mario" diff --git a/lang/Polish.ini b/lang/Polish.ini index fa3da0305..26b15094b 100644 --- a/lang/Polish.ini +++ b/lang/Polish.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Pokaż FPS" [DJUI_THEMES] DJUI_THEME = "Motyw DJUI" DJUI_SCALE = "Skala DJUI" +DJUI_FONT = "Czcionka DJUI" AUTO = "Automatyczny" CENTER = "Środek" +FONT_NORMAL = "Normalny" +FONT_ALIASED = "Gładki" LIGHT_THEME = "Światło" DARK_THEME = "Ciemny" MARIO_THEME = "Mario" diff --git a/lang/Portuguese.ini b/lang/Portuguese.ini index 74681e0f6..590a6da63 100644 --- a/lang/Portuguese.ini +++ b/lang/Portuguese.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Mostrar taxa de quadros" [DJUI_THEMES] DJUI_THEME = "Tema DJUI" DJUI_SCALE = "Tamanho da DJUI" +DJUI_FONT = "Fonte DJUI" AUTO = "Automático" CENTER = "Centralizar" +FONT_NORMAL = "Normal" +FONT_ALIASED = "Suave" LIGHT_THEME = "Claro" DARK_THEME = "Escuro" MARIO_THEME = "Mario" diff --git a/lang/Russian.ini b/lang/Russian.ini index 61da5c41d..e5f0b6880 100644 --- a/lang/Russian.ini +++ b/lang/Russian.ini @@ -147,8 +147,11 @@ SHOW_FPS = "Показывать FPS" [DJUI_THEMES] DJUI_THEME = "Темы DJUI" DJUI_SCALE = "Шкала DJUI" +DJUI_FONT = "Шрифт DJUI" AUTO = "Автоматический" CENTER = "Центр" +FONT_NORMAL = "Обычный" +FONT_ALIASED = "Гладкий" LIGHT_THEME = "Свет" DARK_THEME = "Темный" MARIO_THEME = "Mario" diff --git a/lang/Spanish.ini b/lang/Spanish.ini index ce9be6611..ee06e06c2 100644 --- a/lang/Spanish.ini +++ b/lang/Spanish.ini @@ -148,8 +148,11 @@ SHOW_FPS = "Mostrar FPS" [DJUI_THEMES] DJUI_THEME = "Tema de DJUI" DJUI_SCALE = "Tamaño de DJUI" +DJUI_FONT = "Fuente DJUI" AUTO = "Automático" CENTER = "Centrar" +FONT_NORMAL = "Normal" +FONT_ALIASED = "Alias" LIGHT_THEME = "Claro" DARK_THEME = "Oscuro" MARIO_THEME = "Mario" diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 688b3cf83..1eabc6433 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -13,11 +13,12 @@ #include "gfx/gfx_window_manager_api.h" #include "controller/controller_api.h" #include "fs/fs.h" -#include "pc/mods/mods.h" -#include "pc/network/ban_list.h" -#include "pc/crash_handler.h" -#include "pc/network/moderator_list.h" +#include "mods/mods.h" +#include "network/ban_list.h" +#include "crash_handler.h" +#include "network/moderator_list.h" #include "debuglog.h" +#include "djui/djui_hud_utils.h" #define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0])) @@ -163,6 +164,7 @@ char configDestId[MAX_CONFIG_STRING] = "0"; bool configFadeoutDistantSounds = false; unsigned int configDjuiTheme = DJUI_THEME_DARK; bool configDjuiThemeCenter = true; +unsigned int configDjuiThemeFont = FONT_NORMAL; unsigned int configDjuiScale = 0; bool configGlobalPlayerModels = true; char configLastVersion[MAX_CONFIG_STRING] = ""; @@ -237,11 +239,11 @@ static const struct ConfigOption options[] = { {.name = "coop_network_system", .type = CONFIG_TYPE_UINT , .uintValue = &configNetworkSystem}, {.name = "coop_player_interaction", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerInteraction}, {.name = "coop_player_knockback_strength", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerKnockbackStrength}, - {.name = "coopdx_nametags", .type = CONFIG_TYPE_BOOL , .boolValue = &configNametags}, - {.name = "coopdx_bouncy_bounds", .type = CONFIG_TYPE_UINT , .uintValue = &configBouncyLevelBounds}, + {.name = "coop_nametags", .type = CONFIG_TYPE_BOOL , .boolValue = &configNametags}, + {.name = "coop_bouncy_bounds", .type = CONFIG_TYPE_UINT , .uintValue = &configBouncyLevelBounds}, {.name = "coop_player_model", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerModel}, {.name = "coop_player_name", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configPlayerName, .maxStringLength = MAX_PLAYER_STRING}, - {.name = "coopdx_menu_staff_roll", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuStaffRoll}, + {.name = "coop_menu_staff_roll", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuStaffRoll}, {.name = "coop_menu_level", .type = CONFIG_TYPE_UINT , .uintValue = &configMenuLevel}, {.name = "coop_menu_sound", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuSound}, {.name = "coop_menu_random", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuRandom}, @@ -261,7 +263,7 @@ static const struct ConfigOption options[] = { {.name = "coop_custom_palette_skin", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[SKIN]}, {.name = "coop_custom_palette_cap", .type = CONFIG_TYPE_COLOR , .colorValue = &configCustomPalette.parts[CAP]}, {.name = "coop_stay_in_level_after_star", .type = CONFIG_TYPE_UINT , .uintValue = &configStayInLevelAfterStar}, - {.name = "coopdx_global_player_models", .type = CONFIG_TYPE_BOOL , .boolValue = &configGlobalPlayerModels}, + {.name = "coop_global_player_models", .type = CONFIG_TYPE_BOOL , .boolValue = &configGlobalPlayerModels}, {.name = "disable_popups", .type = CONFIG_TYPE_BOOL , .boolValue = &configDisablePopups}, {.name = "lua_profiler", .type = CONFIG_TYPE_BOOL , .boolValue = &configLuaProfiler}, #ifdef DEVELOPMENT @@ -283,6 +285,7 @@ static const struct ConfigOption options[] = { {.name = "fade_distant_sounds", .type = CONFIG_TYPE_BOOL , .boolValue = &configFadeoutDistantSounds}, {.name = "djui_theme", .type = CONFIG_TYPE_UINT , .uintValue = &configDjuiTheme}, {.name = "djui_theme_center", .type = CONFIG_TYPE_BOOL , .boolValue = &configDjuiThemeCenter}, + {.name = "djui_theme_font", .type = CONFIG_TYPE_UINT , .uintValue = &configDjuiThemeFont}, {.name = "djui_scale", .type = CONFIG_TYPE_UINT , .uintValue = &configDjuiScale}, {.name = "last_version", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configLastVersion, .maxStringLength = MAX_CONFIG_STRING} }; diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 231306d91..7ade744e9 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -120,6 +120,7 @@ extern char configDestId[]; extern bool configFadeoutDistantSounds; extern unsigned int configDjuiTheme; extern bool configDjuiThemeCenter; +extern unsigned int configDjuiThemeFont; extern unsigned int configDjuiScale; extern bool configGlobalPlayerModels; extern char configLastVersion[]; diff --git a/src/pc/djui/djui_font.c b/src/pc/djui/djui_font.c index ff16ac309..c1628276f 100644 --- a/src/pc/djui/djui_font.c +++ b/src/pc/djui/djui_font.c @@ -22,7 +22,7 @@ static void djui_font_normal_render_char(char* c) { static f32 djui_font_normal_char_width(char* c) { if (*c == ' ') { return 0.30f; } extern const f32 font_normal_widths[]; - return djui_unicode_get_sprite_width(c, font_normal_widths); + return djui_unicode_get_sprite_width(c, font_normal_widths, 32.0f); } static const struct DjuiFont sDjuiFontNormal = { @@ -153,7 +153,7 @@ static void djui_font_aliased_render_char(char* c) { static f32 djui_font_aliased_char_width(char* c) { if (*c == ' ') { return 6 / 32.0f; } extern const f32 font_aliased_widths[]; - return djui_unicode_get_sprite_width(c, font_aliased_widths) / 32.0f; + return djui_unicode_get_sprite_width(c, font_aliased_widths, 1.0f) / 32.0f; } static const struct DjuiFont sDjuiFontAliased = { diff --git a/src/pc/djui/djui_panel_menu_options.c b/src/pc/djui/djui_panel_menu_options.c index 84b5c0f85..7d79e0d79 100644 --- a/src/pc/djui/djui_panel_menu_options.c +++ b/src/pc/djui/djui_panel_menu_options.c @@ -81,7 +81,8 @@ void djui_panel_main_menu_create(struct DjuiBase* caller) { djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_THEME), themeChoices, DJUI_THEME_MAX, &configDjuiTheme, djui_panel_misc_djui_setting_change); char* djuiScaleChoices[5] = {DLANG(DJUI_THEMES, AUTO), "x0.5", "x0.85", "x1.0", "x1.5"}; djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_SCALE), djuiScaleChoices, 5, &configDjuiScale, djui_panel_misc_djui_setting_change); - + char* djuiFontChoices[2] = {DLANG(DJUI_THEMES, FONT_NORMAL), DLANG(DJUI_THEMES, FONT_ALIASED)}; + djui_selectionbox_create(body, DLANG(DJUI_THEMES, DJUI_FONT), djuiFontChoices, 2, &configDjuiThemeFont, djui_panel_misc_djui_setting_change); if (gDjuiInMainMenu) { struct DjuiSelectionbox* selectionbox1 = djui_selectionbox_create(body, DLANG(MENU_OPTIONS, LEVEL), levelChoices, 18, &configMenuLevel, NULL); diff --git a/src/pc/djui/djui_text.c b/src/pc/djui/djui_text.c index 29b34dece..57661ac48 100644 --- a/src/pc/djui/djui_text.c +++ b/src/pc/djui/djui_text.c @@ -1,6 +1,7 @@ #include #include "djui.h" #include "djui_unicode.h" +#include "djui_hud_utils.h" #include "game/segment2.h" static u8 sSavedR = 0; @@ -389,7 +390,7 @@ struct DjuiText* djui_text_create(struct DjuiBase* parent, const char* message) djui_base_init(parent, base, djui_text_render, djui_text_destroy); text->message = NULL; - djui_text_set_font(text, gDjuiFonts[0]); + djui_text_set_font(text, gDjuiFonts[configDjuiThemeFont == 0 ? FONT_NORMAL : FONT_ALIASED]); djui_text_set_font_scale(text, text->font->defaultFontScale); djui_text_set_text(text, message); djui_text_set_alignment(text, DJUI_HALIGN_LEFT, DJUI_VALIGN_TOP); diff --git a/src/pc/djui/djui_unicode.c b/src/pc/djui/djui_unicode.c index 48f3eb579..350b4abc8 100644 --- a/src/pc/djui/djui_unicode.c +++ b/src/pc/djui/djui_unicode.c @@ -82,60 +82,60 @@ struct SmCodeGlyph sSmCodeGlyphs[] = { { "ß", 'S', 0, 0 }, { "¡", '!', 0, 0 }, - { "¿", '?', 0, 0 }, + { "¿", '?', 12, 0 }, - { "Б", 'B', 0, 0 }, - { "Г", 'L', 0, 0 }, - { "Д", 'A', 0, 0 }, - { "Ж", 'X', 0, 0 }, - { "З", '3', 0, 0 }, - { "И", 'N', 0, 0 }, - { "Й", 'N', 0, 0 }, - { "Л", 'U', 0, 0 }, - { "П", 'U', 0, 0 }, - { "У", 'y', 0, 0 }, - { "Ф", 'o', 0, 0 }, - { "Ц", 'U', 0, 0 }, - { "Ч", '4', 0, 0 }, - { "Ш", 'W', 0, 0 }, - { "Щ", 'W', 0, 0 }, - { "Ъ", 'b', 0, 0 }, - { "Ы", 'O', 0, 0 }, - { "Ь", 'b', 0, 0 }, - { "Ѣ", 'b', 0, 0 }, - { "Э", '3', 0, 0 }, - { "Ю", 'O', 0, 0 }, - { "Я", 'R', 0, 0 }, - { "Є", 'E', 0, 0 }, + { "Б", 15, 0, 0 }, + { "Г", 14, 0, 0 }, + { "Д", 17, 0, 0 }, + { "Ж", 17, 0, 0 }, + { "З", 13, 0, 0 }, + { "И", 15, 0, 0 }, + { "Й", 15, 0, 0 }, + { "Л", 13, 0, 0 }, + { "П", 14, 0, 0 }, + { "У", 12, 0, 0 }, + { "Ф", 17, 0, 0 }, + { "Ц", 14, 0, 0 }, + { "Ч", 11, 0, 0 }, + { "Ш", 17, 0, 0 }, + { "Щ", 17, 0, 0 }, + { "Ъ", 13, 0, 0 }, + { "Ы", 17, 0, 0 }, + { "Ь", 12, 0, 0 }, + { "Ѣ", 14, 0, 0 }, + { "Э", 13, 0, 0 }, + { "Ю", 17, 0, 0 }, + { "Я", 13, 0, 0 }, + { "Є", 12, 0, 0 }, - { "а", 'a', 0, 0 }, - { "б", '6', 0, 0 }, - { "в", 'B', 0, 0 }, - { "г", 'r', 0, 0 }, - { "д", 'A', 0, 0 }, - { "ж", 'x', 0, 0 }, - { "з", '3', 0, 0 }, - { "и", 'n', 0, 0 }, - { "й", 'n', 0, 0 }, - { "к", 'k', 0, 0 }, - { "л", 'n', 0, 0 }, - { "м", 'm', 0, 0 }, - { "н", 'h', 0, 0 }, - { "п", 'n', 0, 0 }, - { "т", 't', 0, 0 }, - { "ф", 'o', 0, 0 }, - { "ц", 'u', 0, 0 }, - { "ч", '4', 0, 0 }, - { "ш", 'w', 0, 0 }, - { "щ", 'w', 0, 0 }, - { "ъ", 'b', 0, 0 }, - { "ы", 'O', 0, 0 }, - { "ь", 'b', 0, 0 }, - { "ѣ", 'b', 0, 0 }, - { "э", '3', 0, 0 }, - { "ю", 'O', 0, 0 }, - { "я", 'r', 0, 0 }, - { "є", 'e', 0, 0 }, + { "а", 13, 0, 0 }, + { "б", 11, 0, 0 }, + { "в", 11, 0, 0 }, + { "г", 10, 0, 0 }, + { "д", 12, 0, 0 }, + { "ж", 15, 0, 0 }, + { "з", 13, 0, 0 }, + { "и", 12, 0, 0 }, + { "й", 12, 0, 0 }, + { "к", 9, 0, 0 }, + { "л", 10, 0, 0 }, + { "м", 11, 0, 0 }, + { "н", 11, 0, 0 }, + { "п", 11, 0, 0 }, + { "т", 11, 0, 0 }, + { "ф", 14, 0, 0 }, + { "ц", 11, 0, 0 }, + { "ч", 9, 0, 0 }, + { "ш", 17, 0, 0 }, + { "щ", 17, 0, 0 }, + { "ъ", 14, 0, 0 }, + { "ы", 17, 0, 0 }, + { "ь", 12, 0, 0 }, + { "ѣ", 13, 0, 0 }, + { "э", 12, 0, 0 }, + { "ю", 16, 0, 0 }, + { "я", 12, 0, 0 }, + { "є", 12, 0, 0 }, { "Č", 'C', 0, 0 }, { "č", 'c', 0, 0 }, @@ -154,7 +154,7 @@ struct SmCodeGlyph sSmCodeGlyphs[] = { { "Ň", 'N', 0, 0 }, { "ň", 'n', 0, 0 }, { "Ť", 'T', 0, 0 }, - { "ť", 't', 0, 0 }, + { "ť", 13, 0, 0 }, { "ę", 'e', 0, 0 }, { "ń", 'n', 0, 0 }, @@ -285,10 +285,10 @@ u32 djui_unicode_get_sprite_index(char* text) { return (u8)'?' - SPRITE_INDEX_START_CHAR; } -f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[]) { +f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[], f32 unicodeScale) { if (!text) { return 0; } - // check for ASCI + // check for ASCII if ((u8)*text < 128) { // make sure it's in the valid range if ((u8)*text < SPRITE_INDEX_START_CHAR) { @@ -307,10 +307,10 @@ f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[]) { if (glyph) { if (glyph->width) { // use the custom width - return glyph->width; + return glyph->width / unicodeScale; } if ((u8)glyph->base < (u8)'!') { - return glyph->base; + return glyph->base / unicodeScale; } // use the base width return font_widths[(u8)glyph->base - SPRITE_INDEX_START_CHAR]; diff --git a/src/pc/djui/djui_unicode.h b/src/pc/djui/djui_unicode.h index 7b75885d7..59d138162 100644 --- a/src/pc/djui/djui_unicode.h +++ b/src/pc/djui/djui_unicode.h @@ -5,7 +5,7 @@ void djui_unicode_init(void); u32 djui_unicode_get_sprite_index(char* text); -f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[]); +f32 djui_unicode_get_sprite_width(char* text, const f32 font_widths[], f32 unicodeScale); char* djui_unicode_next_char(char* text); char* djui_unicode_at_index(char* text, s32 index); size_t djui_unicode_len(char* text);