From 9b0a4c378b7cf5a213577d37f9a7568befd839a7 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 15 Feb 2024 15:38:02 -0500 Subject: [PATCH 1/6] pntr: Enable UTF-8 support --- cmake/FetchDependencies.cmake | 2 +- src/libretro/CMakeLists.txt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index a82e4e88..c16acd8e 100644 --- a/cmake/FetchDependencies.cmake +++ b/cmake/FetchDependencies.cmake @@ -42,7 +42,7 @@ fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common. fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca") fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9") fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877") -fetch_dependency(pntr "https://github.com/robloach/pntr" "a3dc08c") +fetch_dependency(pntr "https://github.com/robloach/pntr" "f9bbbd0") fetch_dependency(fmt "https://github.com/fmtlib/fmt" "10.2.1") fetch_dependency(yamc "https://github.com/yohhoy/yamc" "4e015a7") fetch_dependency(span-lite "https://github.com/martinmoene/span-lite" "bc08bf8") diff --git a/src/libretro/CMakeLists.txt b/src/libretro/CMakeLists.txt index 7dff6ac8..7125080d 100644 --- a/src/libretro/CMakeLists.txt +++ b/src/libretro/CMakeLists.txt @@ -224,12 +224,11 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in" "${CMAKE_CURRENT_BIN target_compile_definitions(melondsds_libretro PUBLIC GLM_ENABLE_EXPERIMENTAL - PNTR_ENABLE_DEFAULT_FONT - PNTR_ENABLE_FILTER_SMOOTH PNTR_ENABLE_TTF PNTR_ENABLE_VARGS PNTR_PIXELFORMAT_ARGB PNTR_ENABLE_MATH + PNTR_ENABLE_UTF8 STB_IMAGE_STATIC # To avoid using any dynamically-linked STB implementations ) From 5ba87281f15a8d3f45eaf2167319c6035f0bc6bd Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 19 Apr 2024 00:24:35 -0400 Subject: [PATCH 2/6] Update pntr --- cmake/FetchDependencies.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index c16acd8e..d1b8a7c4 100644 --- a/cmake/FetchDependencies.cmake +++ b/cmake/FetchDependencies.cmake @@ -42,7 +42,7 @@ fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common. fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca") fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9") fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877") -fetch_dependency(pntr "https://github.com/robloach/pntr" "f9bbbd0") +fetch_dependency(pntr "https://github.com/robloach/pntr" "2632c0a") fetch_dependency(fmt "https://github.com/fmtlib/fmt" "10.2.1") fetch_dependency(yamc "https://github.com/yohhoy/yamc" "4e015a7") fetch_dependency(span-lite "https://github.com/martinmoene/span-lite" "bc08bf8") From dfab3034378003c85123d0af72b450c194bf2fbe Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Fri, 19 Apr 2024 00:33:13 -0400 Subject: [PATCH 3/6] Updte --- src/libretro/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libretro/CMakeLists.txt b/src/libretro/CMakeLists.txt index 0110729c..40a5a133 100644 --- a/src/libretro/CMakeLists.txt +++ b/src/libretro/CMakeLists.txt @@ -226,6 +226,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in" "${CMAKE_CURRENT_BIN target_compile_definitions(melondsds_libretro PUBLIC GLM_ENABLE_EXPERIMENTAL + PNTR_ENABLE_DEFAULT_FONT + PNTR_ENABLE_FILTER_SMOOTH PNTR_ENABLE_TTF PNTR_ENABLE_VARGS PNTR_PIXELFORMAT_ARGB From 6059d7a0ec73be31e0a8a6982d825e8b1efcd31a Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 20 Apr 2024 04:33:47 -0400 Subject: [PATCH 4/6] Add sample UTF-8 characters --- cmake/FetchDependencies.cmake | 2 +- src/libretro/message/error.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index d1b8a7c4..0e355d03 100644 --- a/cmake/FetchDependencies.cmake +++ b/cmake/FetchDependencies.cmake @@ -42,7 +42,7 @@ fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common. fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca") fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9") fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877") -fetch_dependency(pntr "https://github.com/robloach/pntr" "2632c0a") +fetch_dependency(pntr "https://github.com/robloach/pntr" "55082e7") fetch_dependency(fmt "https://github.com/fmtlib/fmt" "10.2.1") fetch_dependency(yamc "https://github.com/yohhoy/yamc" "4e015a7") fetch_dependency(span-lite "https://github.com/martinmoene/span-lite" "bc08bf8") diff --git a/src/libretro/message/error.cpp b/src/libretro/message/error.cpp index 066229fa..16b871b9 100644 --- a/src/libretro/message/error.cpp +++ b/src/libretro/message/error.cpp @@ -36,7 +36,7 @@ constexpr pntr_color TEXT_COLOR_BOTTOM = {.rgba = {.b = 0x98, .g = 0xE5, .r = 0x static constexpr const char* const ERROR_TITLE = "Oh no! melonDS DS couldn't start..."; static constexpr const char* const SOLUTION_TITLE = "Here's what you can do:"; -static constexpr const char* const THANK_YOU = "Thank you for using melonDS DS!"; +static constexpr const char* const THANK_YOU = "Thank you for using melonDS DS! Θ.Θ"; using std::span; using MelonDsDs::NDS_SCREEN_AREA; From 67e1be2b29a5ed97f4ea782204381fcd79b49303 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Mon, 22 Apr 2024 00:28:01 -0400 Subject: [PATCH 5/6] pntr: Update with UTF-8 support --- cmake/FetchDependencies.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index 0e355d03..e33ccc3f 100644 --- a/cmake/FetchDependencies.cmake +++ b/cmake/FetchDependencies.cmake @@ -42,7 +42,7 @@ fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common. fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca") fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9") fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877") -fetch_dependency(pntr "https://github.com/robloach/pntr" "55082e7") +fetch_dependency(pntr "https://github.com/robloach/pntr" "23099c7") fetch_dependency(fmt "https://github.com/fmtlib/fmt" "10.2.1") fetch_dependency(yamc "https://github.com/yohhoy/yamc" "4e015a7") fetch_dependency(span-lite "https://github.com/martinmoene/span-lite" "bc08bf8") From a8cee7d9e5f90820ec3b38ac111aefe51c1a10ed Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 22 May 2024 15:52:04 -0400 Subject: [PATCH 6/6] Add translatable error messages with UTF-8 --- cmake/FetchDependencies.cmake | 2 +- src/libretro/CMakeLists.txt | 3 ++- src/libretro/core/core.cpp | 10 ++++++++- src/libretro/core/core.hpp | 1 + src/libretro/message/error.cpp | 40 ++++++++++++++++++++++++++++------ src/libretro/message/error.hpp | 6 ++++- 6 files changed, 51 insertions(+), 11 deletions(-) diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index e33ccc3f..1697f83b 100644 --- a/cmake/FetchDependencies.cmake +++ b/cmake/FetchDependencies.cmake @@ -42,7 +42,7 @@ fetch_dependency("libretro-common" "https://github.com/libretro/libretro-common. fetch_dependency("embed-binaries" "https://github.com/andoalon/embed-binaries.git" "21f28ca") fetch_dependency(glm "https://github.com/g-truc/glm" "33b0eb9") fetch_dependency(libslirp "https://github.com/JesseTG/libslirp-mirror.git" "44e7877") -fetch_dependency(pntr "https://github.com/robloach/pntr" "23099c7") +fetch_dependency(pntr "https://github.com/robloach/pntr" "3421a6d") fetch_dependency(fmt "https://github.com/fmtlib/fmt" "10.2.1") fetch_dependency(yamc "https://github.com/yohhoy/yamc" "4e015a7") fetch_dependency(span-lite "https://github.com/martinmoene/span-lite" "bc08bf8") diff --git a/src/libretro/CMakeLists.txt b/src/libretro/CMakeLists.txt index 40a5a133..264e1099 100644 --- a/src/libretro/CMakeLists.txt +++ b/src/libretro/CMakeLists.txt @@ -227,12 +227,13 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in" "${CMAKE_CURRENT_BIN target_compile_definitions(melondsds_libretro PUBLIC GLM_ENABLE_EXPERIMENTAL PNTR_ENABLE_DEFAULT_FONT - PNTR_ENABLE_FILTER_SMOOTH PNTR_ENABLE_TTF PNTR_ENABLE_VARGS PNTR_PIXELFORMAT_ARGB PNTR_ENABLE_MATH PNTR_ENABLE_UTF8 + PNTR_NO_STDIO + PNTR_NO_SAVE_IMAGE STB_IMAGE_STATIC # To avoid using any dynamically-linked STB implementations ) diff --git a/src/libretro/core/core.cpp b/src/libretro/core/core.cpp index 568e4beb..b7dc4684 100644 --- a/src/libretro/core/core.cpp +++ b/src/libretro/core/core.cpp @@ -313,7 +313,7 @@ bool MelonDsDs::CoreState::InitErrorScreen(const config_exception& e) noexcept { } retro::task::reset(); - _messageScreen = std::make_unique(e); + _messageScreen = std::make_unique(e, language); Config.SetConfiguredRenderer(RenderMode::Software); _screenLayout.Update(); retro::error("Error screen initialized"); @@ -475,6 +475,14 @@ void MelonDsDs::CoreState::DestroyRenderState() { bool MelonDsDs::CoreState::LoadGame(unsigned type, std::span game) noexcept try { ZoneScopedN(TracyFunction); + printf("Initialize languageCoreState::LoadGame "); + + // Initialize the language. + unsigned lang = 0; + if (retro::environment(RETRO_ENVIRONMENT_GET_LANGUAGE, (void*)&lang)) { + language = (enum retro_language)lang; + } + InitContent(type, game); // ...then load the game. diff --git a/src/libretro/core/core.hpp b/src/libretro/core/core.hpp index eee08efc..b80bf12a 100644 --- a/src/libretro/core/core.hpp +++ b/src/libretro/core/core.hpp @@ -155,6 +155,7 @@ namespace MelonDsDs { bool _deferredInitializationPending = false; uint32_t _flushTaskId = 0; NetworkMode _activeNetworkMode = NetworkMode::None; + enum retro_language language = RETRO_LANGUAGE_ENGLISH; }; } #endif //MELONDSDS_CORE_HPP diff --git a/src/libretro/message/error.cpp b/src/libretro/message/error.cpp index 16b871b9..83b8a58c 100644 --- a/src/libretro/message/error.cpp +++ b/src/libretro/message/error.cpp @@ -36,13 +36,13 @@ constexpr pntr_color TEXT_COLOR_BOTTOM = {.rgba = {.b = 0x98, .g = 0xE5, .r = 0x static constexpr const char* const ERROR_TITLE = "Oh no! melonDS DS couldn't start..."; static constexpr const char* const SOLUTION_TITLE = "Here's what you can do:"; -static constexpr const char* const THANK_YOU = "Thank you for using melonDS DS! Θ.Θ"; +static constexpr const char* const THANK_YOU = "Thank you for using melonDS DS!"; using std::span; using MelonDsDs::NDS_SCREEN_AREA; // I intentionally fix the error message to the DS screen size to simplify the layout. -MelonDsDs::error::ErrorScreen::ErrorScreen(const config_exception& e) noexcept : exception(e) { +MelonDsDs::error::ErrorScreen::ErrorScreen(const config_exception& e, enum retro_language language) noexcept : exception(e) { ZoneScopedN(TracyFunction); pntr_font* titleFont = pntr_load_font_ttf_from_memory( @@ -105,7 +105,7 @@ void MelonDsDs::error::ErrorScreen::DrawTopScreen(pntr_font* titleFont, pntr_fon pntr_draw_text( topScreen, titleFont, - ERROR_TITLE, + translate(ERROR_TITLE), (NDS_SCREEN_WIDTH - titleTextSize.x) / 2, MARGIN, TEXT_COLOR_TOP @@ -115,7 +115,7 @@ void MelonDsDs::error::ErrorScreen::DrawTopScreen(pntr_font* titleFont, pntr_fon pntr_draw_text_wrapped( topScreen, bodyFont, - exception.what(), + translate(exception.what()), MARGIN, titleTextSize.y + MARGIN * 2, NDS_SCREEN_WIDTH - MARGIN * 2, @@ -150,7 +150,7 @@ void MelonDsDs::error::ErrorScreen::DrawBottomScreen(pntr_font* titleFont, pntr_ pntr_draw_text( bottomScreen, titleFont, - SOLUTION_TITLE, + translate(SOLUTION_TITLE), (NDS_SCREEN_WIDTH - titleTextSize.x) / 2, MARGIN, TEXT_COLOR_BOTTOM @@ -160,7 +160,7 @@ void MelonDsDs::error::ErrorScreen::DrawBottomScreen(pntr_font* titleFont, pntr_ pntr_draw_text_wrapped( bottomScreen, bodyFont, - exception.user_message(), + translate(exception.user_message()), MARGIN, titleTextSize.y + MARGIN * 2, NDS_SCREEN_WIDTH - MARGIN * 2, @@ -171,7 +171,7 @@ void MelonDsDs::error::ErrorScreen::DrawBottomScreen(pntr_font* titleFont, pntr_ pntr_draw_text( bottomScreen, bodyFont, - THANK_YOU, + translate(THANK_YOU), NDS_SCREEN_WIDTH - thankYouTextSize.x - MARGIN, NDS_SCREEN_HEIGHT - thankYouTextSize.y - MARGIN, TEXT_COLOR_BOTTOM @@ -185,3 +185,29 @@ span> MelonDsDs::error::ErrorScreen::Top span> MelonDsDs::error::ErrorScreen::BottomScreen() const noexcept { return span>{(const uint32_t*)bottomScreen->data, NDS_SCREEN_AREA}; } + +#include +/** + * Translates the given message into the active current `language`. + * + * @param message The message to translate. + * + * @return A translated message if a translation is available, otherwise the original message. + */ +const char* MelonDsDs::error::ErrorScreen::translate(const char* message) const noexcept { + printf("Lagnuage: %d\n", (int)language); + switch (language) { + case RETRO_LANGUAGE_SPANISH: + if (message == ERROR_TITLE) return "¡Oh no! melonDS DS no pudo iniciar..."; + if (message == SOLUTION_TITLE) return "Esto es lo que puedes hacer:"; + if (message == THANK_YOU) return "¡Gracias por usar melonDS DS!"; + case RETRO_LANGUAGE_FRENCH: + if (message == ERROR_TITLE) return "Oh non! melonDS DS n'a pas pu démarrer..."; + if (message == SOLUTION_TITLE) return "Voici ce que vous pouvez faire:"; + if (message == THANK_YOU) return "Merci d'utiliser melonDS DS!"; + default: + return message; + } + + // TODO: Add translations of the possible exceptions? +} diff --git a/src/libretro/message/error.hpp b/src/libretro/message/error.hpp index 0e0f7b5b..4ddfeaa1 100644 --- a/src/libretro/message/error.hpp +++ b/src/libretro/message/error.hpp @@ -17,6 +17,8 @@ #ifndef MELONDS_DS_ERROR_HPP #define MELONDS_DS_ERROR_HPP +#include // enum retro_language + #include "exceptions.hpp" #include "screenlayout.hpp" @@ -31,7 +33,7 @@ namespace MelonDsDs { namespace MelonDsDs::error { class ErrorScreen { public: - explicit ErrorScreen(const config_exception& e) noexcept; + explicit ErrorScreen(const config_exception& e, enum retro_language language) noexcept; ~ErrorScreen(); ErrorScreen(const ErrorScreen&) = delete; ErrorScreen& operator=(const ErrorScreen&) = delete; @@ -43,9 +45,11 @@ namespace MelonDsDs::error { private: void DrawTopScreen(pntr_font* titleFont, pntr_font* bodyFont) const noexcept; void DrawBottomScreen(pntr_font* titleFont, pntr_font* bodyFont) const noexcept; + const char* translate(const char* message) const noexcept; config_exception exception; pntr_image* bottomScreen = nullptr; pntr_image* topScreen = nullptr; + enum retro_language language = RETRO_LANGUAGE_ENGLISH; }; }