diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..26e83855 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +add_subdirectory(src) + +FILE( + GLOB_RECURSE + data_dos_file + data/* +) + +add_custom_target(Data_DOS + SOURCES + ${data_dos_file} +) + +FILE( + GLOB_RECURSE + doc_file + doc/* +) + +add_custom_target(Doc + SOURCES + ${doc_file} +) + +add_custom_target(Root_Data + SOURCES + COPYING + ReadMe.amigaos4 + README.md + SDLPoP.ini + mods/mods.txt + replays/replays.txt +) diff --git a/SDLPoP.ini b/SDLPoP.ini index 2542fe28..ba30097f 100644 --- a/SDLPoP.ini +++ b/SDLPoP.ini @@ -15,6 +15,10 @@ [General] +; Language selection (EN, FR, DE) +; Texts not translated default to english +language = EN + ; Show the in-game menu when you pause the game by pressing Escape. ; If this is disabled, you can still bring up the menu using Backspace. enable_pause_menu = true diff --git a/data/TITLE/res42_DE.png b/data/TITLE/res42_DE.png new file mode 100644 index 00000000..b8eba669 Binary files /dev/null and b/data/TITLE/res42_DE.png differ diff --git a/data/TITLE/res42_FR.png b/data/TITLE/res42_FR.png new file mode 100644 index 00000000..eafc885e Binary files /dev/null and b/data/TITLE/res42_FR.png differ diff --git a/data/TITLE/res43_DE.png b/data/TITLE/res43_DE.png new file mode 100644 index 00000000..91f73678 Binary files /dev/null and b/data/TITLE/res43_DE.png differ diff --git a/data/TITLE/res43_FR.png b/data/TITLE/res43_FR.png new file mode 100644 index 00000000..3ea2843f Binary files /dev/null and b/data/TITLE/res43_FR.png differ diff --git a/data/TITLE/res44_DE.png b/data/TITLE/res44_DE.png new file mode 100644 index 00000000..d0929899 Binary files /dev/null and b/data/TITLE/res44_DE.png differ diff --git a/data/TITLE/res44_FR.png b/data/TITLE/res44_FR.png new file mode 100644 index 00000000..c2f2fe42 Binary files /dev/null and b/data/TITLE/res44_FR.png differ diff --git a/data/TITLE/res52_DE.png b/data/TITLE/res52_DE.png new file mode 100644 index 00000000..608ebf63 Binary files /dev/null and b/data/TITLE/res52_DE.png differ diff --git a/data/TITLE/res52_FR.png b/data/TITLE/res52_FR.png new file mode 100644 index 00000000..3bce5975 Binary files /dev/null and b/data/TITLE/res52_FR.png differ diff --git a/data/TITLE/res53_DE.png b/data/TITLE/res53_DE.png new file mode 100644 index 00000000..50ced69c Binary files /dev/null and b/data/TITLE/res53_DE.png differ diff --git a/data/TITLE/res53_FR.png b/data/TITLE/res53_FR.png new file mode 100644 index 00000000..de501a76 Binary files /dev/null and b/data/TITLE/res53_FR.png differ diff --git a/data/font/res1132.png b/data/font/res1132.png new file mode 100644 index 00000000..9e6d62dd Binary files /dev/null and b/data/font/res1132.png differ diff --git a/data/font/res1133.png b/data/font/res1133.png new file mode 100644 index 00000000..c9257991 Binary files /dev/null and b/data/font/res1133.png differ diff --git a/data/font/res1134.png b/data/font/res1134.png new file mode 100644 index 00000000..0cd277c4 Binary files /dev/null and b/data/font/res1134.png differ diff --git a/data/font/res1135.png b/data/font/res1135.png new file mode 100644 index 00000000..b97a06ed Binary files /dev/null and b/data/font/res1135.png differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f79fbb6..a944ba54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,10 @@ if (WIN32) link_directories(${SDL2}/${SDL2_ARCH}/lib) endif() +if (UNIX) + add_definitions(-D_GNU_SOURCE=1) +endif() + set(SOURCE_FILES main.c common.h @@ -59,6 +63,12 @@ set(SOURCE_FILES data.h proto.h types.h + Localization/legacy_ingame_texts.h + Localization/language.h + Localization/non_ascii_code.h + Localization/legacy_ingame_texts.c + Localization/language.c + Localization/non_ascii_code.c seg000.c seg001.c seg002.c diff --git a/src/Localization/language.c b/src/Localization/language.c new file mode 100644 index 00000000..ccbaba1f --- /dev/null +++ b/src/Localization/language.c @@ -0,0 +1,63 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#include +#include + +#include "../proto.h" +#include "language.h" + +enum localization set_language_param(const char *value) { + if (strcmp(value, "EN") == 0) return EN; + else if (strcmp(value, "FR") == 0) return FR; + else if (strcmp(value, "DE") == 0) return DE; + else return EN; +} + +void select_language_img(enum localization loc, + char* image_filename, size_t image_filename_size, + const char* filename_no_ext, int resource_id, const char* extension) { + char lang_append[10]; + + switch (loc) { + case EN: + strncpy(lang_append, "", sizeof(lang_append)); break; + case FR: + strncpy(lang_append, "_FR", sizeof(lang_append)); break; + case DE: + strncpy(lang_append, "_DE", sizeof(lang_append)); break; + default: + strncpy(lang_append, "", sizeof(lang_append)); break; + } + + // First check if there is a file specific to the selected language + snprintf_check(image_filename,image_filename_size,"data/%s/res%d%s.%s",filename_no_ext, resource_id, lang_append, extension); + + // try to open the file to check if it exists + FILE* fp = fopen(locate_file(image_filename), "rb"); + if (fp != NULL) { + fclose(fp); + } + else { + // Specific file does not exist - fallback to regular file + snprintf_check(image_filename,image_filename_size,"data/%s/res%d.%s",filename_no_ext, resource_id, extension); + } + return; +} diff --git a/src/Localization/language.h b/src/Localization/language.h new file mode 100644 index 00000000..a70c82e2 --- /dev/null +++ b/src/Localization/language.h @@ -0,0 +1,36 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#ifndef LANGUAGE_H +#define LANGUAGE_H + +enum localization { + EN = 0, + FR, + DE +}; + +enum localization set_language_param(const char *value); + +void select_language_img(enum localization loc, + char* image_filename, size_t image_filename_size, + const char* filename_no_ext, int resource_id, const char* extension); + +#endif diff --git a/src/Localization/legacy_ingame_texts.c b/src/Localization/legacy_ingame_texts.c new file mode 100644 index 00000000..565a03c6 --- /dev/null +++ b/src/Localization/legacy_ingame_texts.c @@ -0,0 +1,195 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#include + +#include "legacy_ingame_texts.h" + +// Note : bottom text box cannot display more than 28 chars + +void str_one_second_left(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "DERNIERE SECONDE", string_size); break; + case DE: + strncpy(string, "1 SEKUNDE UEBRIG", string_size); break; + case EN: + default: + strncpy(string, "1 SECOND LEFT", string_size); break; + } +} + +void str_seconds_left(enum localization loc, char* string, size_t string_size, word rem_sec) { + switch (loc) { + case FR: + snprintf(string, string_size, "ENCORE %d SECONDES", rem_sec); break; + case DE: + snprintf(string, string_size, "%d SEKUNDEN UEBRIG", rem_sec); break; + case EN: + default: + snprintf(string, string_size, "%d SECONDS LEFT", rem_sec); break; + } +} + +void str_minutes_left(enum localization loc, char* string, size_t string_size, word rem_min) { + switch (loc) { + case FR: + snprintf(string, string_size, "ENCORE %d MINUTES", rem_min); break; + case DE: + snprintf(string, string_size, "%d MINUTEN UEBRIG", rem_min); break; + case EN: + default: + snprintf(string, string_size, "%d MINUTES LEFT", rem_min); break; + } +} + +void str_time_expired(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "TEMPS ECOULE!", string_size); break; + case DE: + strncpy(string, "DIE ZEIT IST ABGELAUFEN!", string_size); break; + case EN: + default: + strncpy(string, "TIME HAS EXPIRED!", string_size); break; + } +} + +void str_level(enum localization loc, char* string, size_t string_size, byte disp_level) { + switch (loc) { + case FR: + snprintf(string, string_size, "NIVEAU %d", disp_level); break; + case DE: + snprintf(string, string_size, "LEVEL %d", disp_level); break; + case EN: + default: + snprintf(string, string_size, "LEVEL %d", disp_level); break; + } +} + +void str_pressbutton(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "PRESSEZ LE BOUTON", string_size); break; + case DE: + strncpy(string, "KNOPFDRUCK ZUM WEITERSPIELEN", string_size); break; + case EN: + default: + strncpy(string, "Press Button to Continue", string_size); break; + } +} + +void str_pause(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "PAUSE", string_size); break; + case DE: + strncpy(string, "PAUSE", string_size); break; + case EN: + default: + strncpy(string, "GAME PAUSED", string_size); break; + } +} + +void str_save(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "PARTIE SAUVEE", string_size); break; + case DE: + strncpy(string, "SPIEL WURDE GESPEICHERT", string_size); break; + case EN: + default: + strncpy(string, "GAME SAVED", string_size); break; + } +} + +void str_unable_save(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "SAUVEGARDE IMPOSSIBLE", string_size); break; + case DE: + strncpy(string, "SPIEL NICHT GESPEICHERT", string_size); break; + case EN: + default: + strncpy(string, "UNABLE TO SAVE GAME", string_size); break; + } +} + +void str_copy_protection_bottom(enum localization loc, char* string, size_t string_size, + word copy_word, word copy_line, word copy_page) { + switch (loc) { + case FR: + snprintf(string, string_size, "PAGE %d LIGNE %d MOT %d", copy_page, copy_line, copy_word); break; + case DE: + snprintf(string, string_size, "SEITE %d ZEILE %d WORT %d", copy_page, copy_line, copy_word); break; + case EN: + default: + snprintf(string, string_size, "WORD %d LINE %d PAGE %d", copy_word, copy_line, copy_page); + } +} + +void str_copy_protection_dialog(enum localization loc, char* string, size_t string_size, + word copy_word, word copy_line, word copy_page) { + switch (loc) { + case FR: + snprintf(string, string_size, + "Buvez la potion correspondant à la première " + "lettre du Mot %d Ligne %d de la Page %d du Manuel.", + copy_word, copy_line, copy_page); + break; + case DE: + snprintf(string, string_size, + "Trinken Sie die magische Flasche mit dem Anfangsbuchstaben von\n" + "Wort %d in Zeile %d auf Seite %d.", + copy_word, copy_line, copy_page); + break; + case EN: + default: + snprintf(string, string_size, + "Drink potion matching the first letter of Word %d on Line %d\n" + "of Page %d of the manual.", + copy_word, copy_line, copy_page); + } +} + +void str_dialog(enum localization loc, char* string, size_t string_size, const char* text) { + switch (loc) { + case FR: + snprintf(string, string_size, "%s\n\nPressez une touche pour continuer.", text); + break; + case DE: + snprintf(string, string_size, "%s\n\nDrücken Sie eine Taste.", text); break; + case EN: + default: + snprintf(string, string_size, "%s\n\nPress any key to continue.", text); + } +} + +void str_loading(enum localization loc, char* string, size_t string_size) { + switch (loc) { + case FR: + strncpy(string, "Chargement. . .", string_size); break; + case DE: + strncpy(string, "Bitte Warten. . .", string_size); break; + case EN: + default: + strncpy(string, "Loading. . . .", string_size); break; + } +} diff --git a/src/Localization/legacy_ingame_texts.h b/src/Localization/legacy_ingame_texts.h new file mode 100644 index 00000000..e6b1b4cc --- /dev/null +++ b/src/Localization/legacy_ingame_texts.h @@ -0,0 +1,51 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#ifndef INGAME_TEXTS_H +#define INGAME_TEXTS_H + +// This file contains text from the orginal DOS game + +#include "../types.h" +#include "language.h" + +void str_one_second_left(enum localization loc, char* string, size_t string_size); +void str_seconds_left(enum localization loc, char* string, size_t string_size, word rem_sec); +void str_minutes_left(enum localization loc, char* string, size_t string_size, word rem_min); + +void str_time_expired(enum localization loc, char* string, size_t string_size); + +void str_level(enum localization loc, char* string, size_t string_size, byte disp_level); + +void str_pressbutton(enum localization loc, char* string, size_t string_size); +void str_pause(enum localization loc, char* string, size_t string_size); +void str_save(enum localization loc, char* string, size_t string_size); +void str_unable_save(enum localization loc, char* string, size_t string_size); + +void str_copy_protection_bottom(enum localization loc, char* string, size_t string_size, + word copy_word, word copy_line, word copy_page); +void str_copy_protection_dialog(enum localization loc, char* string, size_t string_size, + word copy_word, word copy_line, word copy_page); + +void str_dialog(enum localization loc, char* string, size_t string_size, const char* text); + +void str_loading(enum localization loc, char* string, size_t string_size); + +#endif diff --git a/src/Localization/non_ascii_code.c b/src/Localization/non_ascii_code.c new file mode 100644 index 00000000..71817648 --- /dev/null +++ b/src/Localization/non_ascii_code.c @@ -0,0 +1,44 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#include +#include + +#include "non_ascii_code.h" + +bool is_letter(const char* letter, const char* text, int* nb_bytes) { + *nb_bytes = (int) strlen(letter); + return strncmp(letter, text, *nb_bytes) == 0; +} + +byte get_non_ascii_code(const char* text, int* nb_bytes) { + if ((byte) *text <= 127) { + *nb_bytes = 1; + return (byte) *text; + } + + if (is_letter("à", text, nb_bytes)) return 132; + if (is_letter("é", text, nb_bytes)) return 133; + if (is_letter("è", text, nb_bytes)) return 134; + if (is_letter("ü", text, nb_bytes)) return 135; + + *nb_bytes = 1; + return 32; // Default to space +} diff --git a/src/Localization/non_ascii_code.h b/src/Localization/non_ascii_code.h new file mode 100644 index 00000000..9e28b35e --- /dev/null +++ b/src/Localization/non_ascii_code.h @@ -0,0 +1,28 @@ +/* +SDLPoP, a port/conversion of the DOS game Prince of Persia. +Copyright (C) 2013-2023 Dávid Nagy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +The authors of this program may be contacted at https://forum.princed.org +*/ + +#ifndef NON_ASCII_CODE_H +#define NON_ASCII_CODE_H + +#include "../types.h" + +byte get_non_ascii_code(const char* text, int* nb_bytes); + +#endif diff --git a/src/data.h b/src/data.h index 6d398e25..d57cb894 100644 --- a/src/data.h +++ b/src/data.h @@ -21,6 +21,8 @@ The authors of this program may be contacted at https://forum.princed.org #ifndef DATA_H #define DATA_H +#include "Localization/language.h" + #ifdef BODY // If included from data.c: definitions (without extern and with initialization). #define INIT(...) __VA_ARGS__ @@ -214,7 +216,7 @@ extern word is_blind_mode; // data:0F86 extern const rect_type rect_top INIT(= {0, 0, 192, 320}); // data:0F96 -extern const rect_type rect_bottom_text INIT(= {193, 70, 202, 250}); +extern const rect_type rect_bottom_text INIT(= {193, 69, 202, 257}); // Original values : {193, 70, 202, 250} // data:4CB2 extern word leveldoor_right; @@ -710,6 +712,7 @@ extern byte is_validate_mode; extern dword curr_tick INIT(= 0); #endif // USE_REPLAY +extern enum localization pop_language INIT(= 0); extern byte start_fullscreen INIT(= 0); extern word pop_window_width INIT(= 640); extern word pop_window_height INIT(= 400); diff --git a/src/options.c b/src/options.c index 0e7d1db9..f55ba840 100644 --- a/src/options.c +++ b/src/options.c @@ -19,6 +19,7 @@ The authors of this program may be contacted at https://forum.princed.org */ #include "common.h" +#include "Localization/language.h" #include #ifdef __amigaos4__ #define strtoimax(a,b,c) strtoll(a,b,c) @@ -175,6 +176,13 @@ static int global_ini_callback(const char *section, const char *name, const char if (ini_process_boolean(name, value, option_name, target)) return 1; if (check_ini_section("General")) { + + // Language selection + if (strcasecmp(name, "language") == 0) { + pop_language = set_language_param(value); + return 1; + } + #ifdef USE_MENU process_boolean("enable_pause_menu", &enable_pause_menu); #endif diff --git a/src/proto.h b/src/proto.h index 13933ee9..70d57722 100644 --- a/src/proto.h +++ b/src/proto.h @@ -18,6 +18,11 @@ along with this program. If not, see . The authors of this program may be contacted at https://forum.princed.org */ +#ifndef PROTO_H +#define PROTO_H + +#include "common.h" + // SEG000.C void pop_main(void); void init_game_main(void); @@ -727,3 +732,5 @@ void stop_midi(void); void init_midi(void); void midi_callback(void *userdata, Uint8 *stream, int len); void play_midi_sound(sound_buffer_type* buffer); + +#endif diff --git a/src/seg000.c b/src/seg000.c index 69e9bff0..204ed4b5 100644 --- a/src/seg000.c +++ b/src/seg000.c @@ -19,6 +19,8 @@ The authors of this program may be contacted at https://forum.princed.org */ #include "common.h" +#include "Localization/legacy_ingame_texts.h" + #include #define _USE_MATH_DEFINES #include @@ -965,7 +967,9 @@ void draw_game_frame() { erase_bottom_text(0); } else { if (blink_frame == 3) { - display_text_bottom("Press Button to Continue"); + char sprintf_temp[40]; + str_pressbutton(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); play_sound_from_buffer(sound_pointers[sound_38_blink]); // press button blink } } @@ -1702,7 +1706,9 @@ int do_paused() { check_sound_playing()) { stop_sounds(); } - display_text_bottom("GAME PAUSED"); + char sprintf_temp[40]; + str_pause(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); #ifdef USE_MENU if (enable_pause_menu || is_menu_shown) { draw_menu(); @@ -2076,10 +2082,13 @@ void save_game() { } } + char sprintf_temp[40]; if (success) { - display_text_bottom("GAME SAVED"); + str_save(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); } else { - display_text_bottom("UNABLE TO SAVE GAME"); + str_unable_save(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); //play_sound_from_buffer(&sound_cant_save); } text_time_remaining = 24; @@ -2246,15 +2255,12 @@ void show_copyprot(int where) { text_time_total = 1188; text_time_remaining = 1188; is_show_time = 0; - snprintf(sprintf_temp, sizeof(sprintf_temp), - "WORD %d LINE %d PAGE %d", - copyprot_word[copyprot_idx], copyprot_line[copyprot_idx], copyprot_page[copyprot_idx]); + str_copy_protection_bottom(pop_language, sprintf_temp, sizeof(sprintf_temp), + copyprot_word[copyprot_idx], copyprot_line[copyprot_idx], copyprot_page[copyprot_idx]); display_text_bottom(sprintf_temp); } else { - snprintf(sprintf_temp, sizeof(sprintf_temp), - "Drink potion matching the first letter of Word %d on Line %d\n" - "of Page %d of the manual.", - copyprot_word[copyprot_idx], copyprot_line[copyprot_idx], copyprot_page[copyprot_idx]); + str_copy_protection_dialog(pop_language, sprintf_temp, sizeof(sprintf_temp), + copyprot_word[copyprot_idx], copyprot_line[copyprot_idx], copyprot_page[copyprot_idx]); show_dialog(sprintf_temp); } #endif @@ -2262,7 +2268,9 @@ void show_copyprot(int where) { // seg000:2489 void show_loading() { - show_text(&screen_rect, halign_center, valign_middle, "Loading. . . ."); + char sprintf_temp[140]; + str_loading(pop_language, sprintf_temp, sizeof(sprintf_temp)); + show_text(&screen_rect, halign_center, valign_middle, sprintf_temp); update_screen(); } @@ -2382,9 +2390,11 @@ const char* get_writable_file_path(char* custom_path_buffer, size_t max_len, con snprintf_check(save_path, max_len, "%s", custom_save_path); else if (home_path != NULL && home_path[0] != '\0') snprintf_check(save_path, max_len, "%s/.%s", home_path, POP_DIR_NAME); + else // save_path might not be initialized + save_path[0] = '\0'; #endif - if (save_path != NULL && save_path[0] != '\0') { + if (save_path[0] != '\0') { #if defined WIN32 || _WIN32 || WIN64 || _WIN64 mkdir (save_path); #else diff --git a/src/seg001.c b/src/seg001.c index 6aba682f..f555bd2a 100644 --- a/src/seg001.c +++ b/src/seg001.c @@ -730,7 +730,7 @@ void draw_star(int which_star,int mark_dirty) { // seg001:0E94 void show_hof() { // Hall of Fame - char time_text[12]; + char time_text[13]; for (short index = 0; index < hof_count; ++index) { #ifdef ALLOW_INFINITE_TIME diff --git a/src/seg006.c b/src/seg006.c index af6ca1e8..4bb2d3cf 100644 --- a/src/seg006.c +++ b/src/seg006.c @@ -20,6 +20,8 @@ The authors of this program may be contacted at https://forum.princed.org #include "common.h" +#include "Localization/legacy_ingame_texts.h" + #define SEQTBL_BASE 0x196E #define SEQTBL_0 (seqtbl - SEQTBL_BASE) extern const byte seqtbl[]; // the sequence table is defined in seqtbl.c @@ -1362,7 +1364,9 @@ void play_kid() { current_level != 15 // no message if died on potions level ) { text_time_remaining = text_time_total = 288; - display_text_bottom("Press Button to Continue"); + char sprintf_temp[40]; + str_pressbutton(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); } else { text_time_remaining = text_time_total = 36; } diff --git a/src/seg008.c b/src/seg008.c index d8212cdd..5eca2cc4 100644 --- a/src/seg008.c +++ b/src/seg008.c @@ -19,6 +19,7 @@ The authors of this program may be contacted at https://forum.princed.org */ #include "common.h" +#include "Localization/legacy_ingame_texts.h" // data:27E0 add_table_type ptr_add_table = add_backtable; @@ -1786,13 +1787,13 @@ void show_time() { if (rem_min == 1) { rem_sec = (rem_tick + 1) / 12; if (rem_sec == 1) { - strncpy(sprintf_temp, "1 SECOND LEFT", sizeof(sprintf_temp)); + str_one_second_left(pop_language, sprintf_temp, sizeof(sprintf_temp)); text_time_remaining = text_time_total = 12; } else { - snprintf(sprintf_temp, sizeof(sprintf_temp), "%d SECONDS LEFT", rem_sec); + str_seconds_left(pop_language, sprintf_temp, sizeof(sprintf_temp), rem_sec); } } else { - snprintf(sprintf_temp, sizeof(sprintf_temp), "%d MINUTES LEFT", rem_min); + str_minutes_left(pop_language, sprintf_temp, sizeof(sprintf_temp), rem_min); } display_text_bottom(sprintf_temp); } else { @@ -1815,8 +1816,8 @@ void show_time() { else if (rem_min == 0) // may also be negative, don't report "expired" in that case! #endif - - display_text_bottom("TIME HAS EXPIRED!"); + str_time_expired(pop_language, sprintf_temp, sizeof(sprintf_temp)); + display_text_bottom(sprintf_temp); } is_show_time = 0; } @@ -1834,7 +1835,7 @@ void show_level() { disp_level = /*12*/ custom->level_13_level_number; } text_time_remaining = text_time_total = 24; - snprintf(sprintf_temp, sizeof(sprintf_temp), "LEVEL %d", disp_level); + str_level(pop_language, sprintf_temp, sizeof(sprintf_temp), disp_level); display_text_bottom(sprintf_temp); is_show_time = 1; } diff --git a/src/seg009.c b/src/seg009.c index 52f62450..d1687d48 100644 --- a/src/seg009.c +++ b/src/seg009.c @@ -22,6 +22,9 @@ The authors of this program may be contacted at https://forum.princed.org #include #include +#include "Localization/legacy_ingame_texts.h" +#include "Localization/non_ascii_code.h" + #ifdef _WIN32 #include #include @@ -1262,11 +1265,14 @@ int find_linebreak(const char* text,int length,int break_width,int x_align) { short curr_line_width = 0; // in pixels const char* text_pos = text; while (curr_char_pos < length) { - curr_line_width += get_char_width(*text_pos); + int nb_bytes = 1; + byte curr_char_code = get_non_ascii_code(&(*text_pos), &nb_bytes); + + curr_line_width += get_char_width(curr_char_code); if (curr_line_width <= break_width) { - ++curr_char_pos; + curr_char_pos+=nb_bytes; char curr_char = *text_pos; - text_pos++; + text_pos+=nb_bytes; if (curr_char == '\n') { return curr_char_pos; } @@ -1323,8 +1329,10 @@ int draw_text_line(const char* text,int length) { int width = 0; const char* text_pos = text; while (--length >= 0) { - width += draw_text_character(*text_pos); - text_pos++; + int nb_bytes = 1; + byte curr_char_code = get_non_ascii_code(&(*text_pos), &nb_bytes); + width += draw_text_character(curr_char_code); + text_pos += nb_bytes; } //show_cursor(); return width; @@ -1587,7 +1595,7 @@ void dialog_method_2_frame(dialog_type* dialog) { // seg009:0C44 void show_dialog(const char* text) { char string[256]; - snprintf(string, sizeof(string), "%s\n\nPress any key to continue.", text); + str_dialog(pop_language, string, sizeof(string), text); showmessage(string, 1, &key_test_quit); } @@ -2915,7 +2923,11 @@ void load_from_opendats_metadata(int resource_id, const char* extension, FILE** if (len >= 5 && filename_no_ext[len-4] == '.') { filename_no_ext[len-4] = '\0'; // terminate, so ".DAT" is deleted from the filename } - snprintf_check(image_filename,sizeof(image_filename),"data/%s/res%d.%s",filename_no_ext, resource_id, extension); + + select_language_img(pop_language, + image_filename, sizeof(image_filename), + filename_no_ext, resource_id, extension); + if (!use_custom_levelset) { //printf("loading (binary) %s",image_filename); fp = fopen(locate_file(image_filename), "rb"); diff --git a/src/types.h b/src/types.h index dbfb2540..c3f3c4d0 100644 --- a/src/types.h +++ b/src/types.h @@ -21,6 +21,8 @@ The authors of this program may be contacted at https://forum.princed.org #ifndef TYPES_H #define TYPES_H +#include "config.h" + #define STB_VORBIS_HEADER_ONLY #include "stb_vorbis.c"