diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-14 17:58:12 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-14 17:58:12 +0100 |
commit | 0e27aac4f124efcd495469522706df8cc1ca5986 (patch) | |
tree | 728028364c231e0aba5110e6e2a0cef3995812aa | |
parent | 36a95838d17ffaee4020a2aba832af6636591df4 (diff) |
Bring back the Polish translation.
-rw-r--r-- | src/common.hpp | 5 | ||||
-rw-r--r-- | src/main.cpp | 24 | ||||
-rw-r--r-- | src/render.cpp | 4 | ||||
-rw-r--r-- | src/text.cpp | 59 |
4 files changed, 88 insertions, 4 deletions
diff --git a/src/common.hpp b/src/common.hpp index 8478e91..38f8993 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -14,6 +14,8 @@ extern bool debug_draw_cmodels; extern bool debug_draw_paths; extern bool debug_draw_tile_coords; +void utf8_to_wchar(wchar_t *out, size_t size, std::string in); + namespace procgen { class prng_t { uint32_t state = 0; @@ -316,7 +318,8 @@ extern render::state_t *debug_render; namespace text { typedef enum { - LANG_ENGLISH + LANG_ENGLISH, + LANG_POLISH } language_t; extern language_t language; diff --git a/src/main.cpp b/src/main.cpp index e503cad..f5e7a19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,30 @@ uint64_t nano_clock(void) return ts.tv_sec * 1000000000LLU + ts.tv_nsec; } +void utf8_to_wchar(wchar_t *out, size_t size, std::string in) +{ + wchar_t *d = out, *end = out + size; + + for (size_t i = 0; i < in.size(); i++) { + if (d + 1 >= end) + break; + + if ((in[i] & 128) == 0) + *(d++) = in[i]; + else { + if (i + 1 >= in.size()) { + printf("invalid UTF-8 sequence\n"); + abort(); + } + + *(d++) = ((in[i] & 31) << 6) | (in[i + 1] & 63); + i++; + } + } + + *(d++) = 0; +} + int main() { uint64_t t0 = nano_clock(); diff --git a/src/render.cpp b/src/render.cpp index 2f1890e..c4718bf 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -185,7 +185,9 @@ void state_t::render(oriented_sprite_t *sprite, rectf_t bounds, float angle) void state_t::render_text(v2f_t x, float height, std::string str, text_align_t align, sf::Color color) { - sf::Text text(str, font, 40); + wchar_t buffer[4096]; + utf8_to_wchar(buffer, sizeof(buffer) / sizeof(wchar_t), str); + sf::Text text(buffer, font, 40); sf::FloatRect rect; float scale; v2f_t offset; diff --git a/src/text.cpp b/src/text.cpp index ad8f007..1a36180 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -2,7 +2,7 @@ namespace text { -language_t language = LANG_ENGLISH; +language_t language = LANG_POLISH; static const char *human_names[] = { "Kowalski", "Jackson", "Carter", "O'Neill", "Hammond", "Mitchell" @@ -51,14 +51,69 @@ static std::string get_english(index_t index) case UNIT_DAMAGE: return "deals damage to"; + + default: + abort(); } } +static std::string get_polish(index_t index) +{ + switch (index) { + case SAY_BLOCKED: + return "Coś jest na mojej drodze."; + + case SAY_NO_PATH: + return "Nie mogę się tam dostać."; + + case SAY_READY: + return "Gotowy na rozkaz."; + + case SAY_MOVING: + return "Jestem w drodze."; + + case UNIT_ALIEN: + return "Obcy"; + + case UNIT_HUMAN: + return human_names[rand() % count(human_names)]; + + case UNIT_DEATH: + return "nie żyje"; + + case UNIT_ATTACK: + return "atakuje"; + + case UNIT_MISS: + return "chybienie"; + + case UNIT_CRITICAL_MISS: + return "chybienie krytyczne"; + + case UNIT_HIT: + return "trafienie"; + + case UNIT_CRITICAL_HIT: + return "trafienie krytyczne"; + + case UNIT_DAMAGE: + return "zadaje obrażenia"; + + default: + abort(); + } +} std::string get(index_t index) { switch (language) { - default: + case LANG_ENGLISH: return get_english(index); + + case LANG_POLISH: + return get_polish(index); + + default: + abort(); } } |