From 10623d003fc0758122cd74d23802d783d5afafdd Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Mon, 30 Dec 2024 15:48:49 +0100 Subject: [PATCH] prep work (everything but fontengine) --- doc/lua_api.md | 19 ++++++++++++++++++- src/client/client.cpp | 11 +++++++++++ src/server.cpp | 3 +++ src/server/mods.cpp | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index f46c9eb28..81eaa3863 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -266,7 +266,7 @@ The main Lua script. Running this script should register everything it wants to register. Subsequent execution depends on Luanti calling the registered callbacks. -### `textures`, `sounds`, `media`, `models`, `locale` +### `textures`, `sounds`, `media`, `models`, `locale`, `fonts` Media files (textures, sounds, whatever) that will be transferred to the client and will be available for use by the mod and translation files for @@ -279,6 +279,7 @@ Accepted formats are: images: .png, .jpg, .tga sounds: .ogg vorbis models: .x, .b3d, .obj, (since version 5.10:) .gltf, .glb + fonts: .ttf (since version 5.?, see notes below) Other formats won't be sent to the client (e.g. you can store .blend files in a folder for convenience, without the risk that such files are transferred) @@ -343,6 +344,22 @@ For example, if your model used an emissive material, you should expect that a future version of Luanti may respect this, and thus cause your model to render differently there. +#### Custom fonts + +You can supply custom fonts in TrueType Font (TTF) format. +In the future, having multiple custom fonts and the ability to switch between them is planned, +but for now this feature is limited to the ability to override Luanti's default fonts via mods. +It is recommended that this only be used by game mods. The names are self-explanatory: + +* `regular.ttf` +* `bold.ttf` +* `italic.ttf` +* `bold_italic.ttf` +* `mono.ttf` +* `mono_bold.ttf` +* `mono_bold_italic.ttf` +* `fallback.ttf` + Naming conventions ------------------ diff --git a/src/client/client.cpp b/src/client/client.cpp index 222c1a2ac..d57d629b9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -9,6 +9,7 @@ #include #include #include "client.h" +#include "client/fontengine.h" #include "network/clientopcodes.h" #include "network/connection.h" #include "network/networkpacket.h" @@ -360,6 +361,9 @@ Client::~Client() for (auto &csp : m_sounds_client_to_server) m_sound->freeId(csp.first); m_sounds_client_to_server.clear(); + + // Go back to our mainmenu fonts + g_fontengine->clearMediaFonts(); } void Client::connect(const Address &address, const std::string &address_name, @@ -833,6 +837,13 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, return true; } + const char *font_ext[] = {".ttf", NULL}; + name = removeStringEnd(filename, font_ext); + if (!name.empty()) { + g_fontengine->setMediaFont(name, data); + return true; + } + errorstream << "Client: Don't know how to load file \"" << filename << "\"" << std::endl; return false; diff --git a/src/server.cpp b/src/server.cpp index 1556de406..132802fa0 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2541,6 +2541,9 @@ bool Server::addMediaFile(const std::string &filename, ".x", ".b3d", ".obj", ".gltf", ".glb", // Translation file formats ".tr", ".po", ".mo", + // Fonts + // TODO throw a warning and ignore file if name is not one of the few recognized ones? + ".ttf", NULL }; if (removeStringEnd(filename, supported_ext).empty()) { diff --git a/src/server/mods.cpp b/src/server/mods.cpp index fb47439c9..bfafe701d 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -87,5 +87,6 @@ void ServerModManager::getModsMediaPaths(std::vector &paths) const fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media"); fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "models"); fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "locale"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "fonts"); } }