Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translatable error screens #208

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/FetchDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion src/libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
10 changes: 9 additions & 1 deletion src/libretro/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ bool MelonDsDs::CoreState::InitErrorScreen(const config_exception& e) noexcept {
}

retro::task::reset();
_messageScreen = std::make_unique<error::ErrorScreen>(e);
_messageScreen = std::make_unique<error::ErrorScreen>(e, language);
Config.SetConfiguredRenderer(RenderMode::Software);
_screenLayout.Update();
retro::error("Error screen initialized");
Expand Down Expand Up @@ -475,6 +475,14 @@ void MelonDsDs::CoreState::DestroyRenderState() {
bool MelonDsDs::CoreState::LoadGame(unsigned type, std::span<const retro_game_info> 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.
Expand Down
1 change: 1 addition & 0 deletions src/libretro/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 32 additions & 6 deletions src/libretro/message/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -185,3 +185,29 @@ span<const uint32_t, NDS_SCREEN_AREA<size_t>> MelonDsDs::error::ErrorScreen::Top
span<const uint32_t, NDS_SCREEN_AREA<size_t>> MelonDsDs::error::ErrorScreen::BottomScreen() const noexcept {
return span<const uint32_t, NDS_SCREEN_AREA<size_t>>{(const uint32_t*)bottomScreen->data, NDS_SCREEN_AREA<size_t>};
}

#include <stdio.h>
/**
* 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?
}
6 changes: 5 additions & 1 deletion src/libretro/message/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#ifndef MELONDS_DS_ERROR_HPP
#define MELONDS_DS_ERROR_HPP

#include <libretro.h> // enum retro_language

#include "exceptions.hpp"
#include "screenlayout.hpp"

Expand All @@ -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;
Expand All @@ -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;
};
}

Expand Down
Loading