diff --git a/cmake/FetchDependencies.cmake b/cmake/FetchDependencies.cmake index a82e4e88..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" "a3dc08c") +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 595d523e..264e1099 100644 --- a/src/libretro/CMakeLists.txt +++ b/src/libretro/CMakeLists.txt @@ -227,11 +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 066229fa..83b8a58c 100644 --- a/src/libretro/message/error.cpp +++ b/src/libretro/message/error.cpp @@ -42,7 +42,7 @@ 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; }; }