From 98c37d0b28db4b73b9c8423a821bce5ce7b9ba49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20PHELIPOT?= Date: Sun, 26 Jan 2020 20:29:46 +0100 Subject: [PATCH] [i18n] Configurable fonts - Add font configuration in internationalization files - Scale font size using a configurable ratio - Add a script to identify translation item statuses using Git metadata - Execute the i18n script in a new gitlab-ci step (delayed) - Clone haxrcorp_4089_cyrillic_altgr font (haxrcorp_4089_cyrillic_altgr_extended) to add some additional latin characters (mainly for French) --- .gitlab-ci.yml | 12 + CHANGELOG.md | 2 + Cargo.lock | 122 +++++++++ .../haxrcorp_4089_cyrillic_altgr_extended.ttf | 3 + assets/voxygen/i18n/en.ron | 22 ++ assets/voxygen/i18n/fr_FR.ron | 26 +- voxygen/Cargo.toml | 1 + voxygen/src/hud/bag.rs | 13 +- voxygen/src/hud/buttons.rs | 10 +- voxygen/src/hud/character_window.rs | 28 +- voxygen/src/hud/chat.rs | 22 +- voxygen/src/hud/esc_menu.rs | 28 +- voxygen/src/hud/map.rs | 17 +- voxygen/src/hud/minimap.rs | 28 +- voxygen/src/hud/mod.rs | 146 +++++----- voxygen/src/hud/quest.rs | 12 +- voxygen/src/hud/settings_window.rs | 232 ++++++++-------- voxygen/src/hud/skillbar.rs | 160 +++++------ voxygen/src/hud/social.rs | 37 +-- voxygen/src/hud/spell.rs | 11 +- voxygen/src/i18n.rs | 25 +- voxygen/src/lib.rs | 3 + voxygen/src/menu/char_selection/ui.rs | 181 +++++++------ voxygen/src/menu/main/ui.rs | 134 +++++----- voxygen/src/session.rs | 1 + voxygen/src/ui/font_ids.rs | 30 --- voxygen/src/ui/fonts.rs | 40 +++ voxygen/src/ui/mod.rs | 4 +- voxygen/tests/check_i18n_files.rs | 250 ++++++++++++++++++ 29 files changed, 1044 insertions(+), 556 deletions(-) create mode 100644 assets/voxygen/font/haxrcorp_4089_cyrillic_altgr_extended.ttf delete mode 100644 voxygen/src/ui/font_ids.rs create mode 100644 voxygen/src/ui/fonts.rs create mode 100644 voxygen/tests/check_i18n_files.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 327db2b377..813eabf4c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -122,6 +122,18 @@ benchmarks: - unset DISABLE_GIT_LFS_CHECK - cargo bench +localization-status: + variables: + GIT_DEPTH: 0 + stage: post + when: delayed + start_in: 5 seconds + allow_failure: true + tags: + - veloren-docker + script: + - cargo test -q test_all_localizations -- --nocapture --ignored + linux: stage: post when: delayed diff --git a/CHANGELOG.md b/CHANGELOG.md index 9148aa2723..0559a4dd4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added rotating orientation marker to main-map - Added daily Mac builds - Allow spawning individual pet species, not just generic body kinds. +- Configurable fonts +- Tanslation status tracking ### Changed diff --git a/Cargo.lock b/Cargo.lock index fb7cbde8db..399d5b6a2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,11 @@ name = "autocfg" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "backtrace" version = "0.3.40" @@ -324,6 +329,10 @@ dependencies = [ name = "cc" version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "jobserver 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "cexpr" @@ -1138,6 +1147,20 @@ dependencies = [ "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "git2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gl_generator" version = "0.11.0" @@ -1394,6 +1417,16 @@ dependencies = [ "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "image" version = "0.22.3" @@ -1470,6 +1503,14 @@ name = "itoa" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "jobserver" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "jpeg-decoder" version = "0.1.16" @@ -1518,6 +1559,19 @@ name = "libc" version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libgit2-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libssh2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libloading" version = "0.5.2" @@ -1527,6 +1581,30 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libssh2-sys" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libz-sys" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "line_drawing" version = "0.7.0" @@ -1931,6 +2009,23 @@ dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "openssl-sys" +version = "0.9.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "orbclient" version = "0.3.27" @@ -3112,6 +3207,16 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "uvth" version = "3.1.1" @@ -3122,6 +3227,11 @@ dependencies = [ "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "vcpkg" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "vek" version = "0.9.11" @@ -3249,6 +3359,7 @@ dependencies = [ "gfx 0.18.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_device_gl 0.16.2 (registry+https://github.com/rust-lang/crates.io-index)", "gfx_window_glutin 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "glutin 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)", "guillotiere 0.4.2 (git+https://github.com/Imberflur/guillotiere)", @@ -3582,6 +3693,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum atom 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3c86699c3f02778ec07158376991c8f783dd1f2f95c579ffaf0738dc984b2fe2" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" @@ -3690,6 +3802,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum gif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" "checksum gio 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2db9fad8f1b0d4c7338a210a6cbdf081dcc1a3c223718c698c4f313f6c288acb" "checksum gio-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a57872499171d279f8577ce83837da4cae62b08dd32892236ed67ab7ea61030" +"checksum git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c1af51ea8a906616af45a4ce78eacf25860f7a13ae7bf8a814693f0f4037a26" "checksum gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39a23d5e872a275135d66895d954269cf5e8661d234eb1c2480f4ce0d586acbd" "checksum gl_generator 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ca98bbde17256e02d17336a6bdb5a50f7d0ccacee502e191d3e3d0ec2f96f84a" "checksum gleam 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "cae10d7c99d0e77b4766e850a60898a17c1abaf01075531f1066f03dc7dc5fc5" @@ -3715,6 +3828,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum image 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4be8aaefbe7545dc42ae925afb55a0098f226a3fe5ef721872806f44f57826" "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" "checksum inflate 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" @@ -3724,6 +3838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum jobserver 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" "checksum jpeg-decoder 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c1aae18ffeeae409c6622c3b6a7ee49792a7e5a062eea1b135fbb74e301792ba" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum khronos_api 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" @@ -3731,7 +3846,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum lewton 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8d542c1a317036c45c2aa1cf10cc9d403ca91eb2d333ef1a4917e5cb10628bd0" "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" +"checksum libgit2-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4870c781f6063efb83150cd22c1ddf6ecf58531419e7570cdcced46970f64a16" "checksum libloading 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +"checksum libssh2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "36aa6e813339d3a063292b77091dfbbb6152ff9006a459895fa5bebed7d34f10" +"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum line_drawing 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5cc7ad3d82c845bdb5dde34ffdcc7a5fb4d2996e1e1ee0f19c33bc80e15196b9" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" @@ -3775,6 +3893,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" "checksum objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" "checksum ogg 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d79f1db9148be9d0e174bb3ac890f6030fcb1ed947267c5a91ee4c91b5a91e15" +"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +"checksum openssl-sys 0.9.54 (registry+https://github.com/rust-lang/crates.io-index)" = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986" "checksum orbclient 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b18f57ab94fbd058e30aa57f712ec423c0bb7403f8493a6c58eef0c36d9402" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" @@ -3912,7 +4032,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" "checksum uvth 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e59a167890d173eb0fcd7a1b99b84dc05c521ae8d76599130b8e19bef287abbf" +"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" "checksum vek 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)" = "1eb3ca8ea588deba055424cc1a79a830428b2f6c270b8d8f91946f660fa4d8ee" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/assets/voxygen/font/haxrcorp_4089_cyrillic_altgr_extended.ttf b/assets/voxygen/font/haxrcorp_4089_cyrillic_altgr_extended.ttf new file mode 100644 index 0000000000..28a2f56603 --- /dev/null +++ b/assets/voxygen/font/haxrcorp_4089_cyrillic_altgr_extended.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9fe6b6694620909217869f4f3fdce28d9ce9e5f0720c5a601903c95669dc428 +size 22120 diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index fcf50d5956..e09f419d0a 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -17,6 +17,28 @@ VoxygenLocalization( language_identifier: "en", ), convert_utf8_to_ascii: false, + fonts: { + "opensans": Font ( + asset_key: "voxygen.font.OpenSans-Regular", + scale_ratio: 1.0, + ), + "metamorph": Font ( + asset_key: "voxygen.font.Metamorphous-Regular", + scale_ratio: 1.0, + ), + "alkhemi": Font ( + asset_key: "voxygen.font.Alkhemikal", + scale_ratio: 1.0, + ), + "wizard": Font ( + asset_key: "voxygen.font.wizard", + scale_ratio: 1.0, + ), + "cyri": Font ( + asset_key: "voxygen.font.haxrcorp_4089_cyrillic_altgr", + scale_ratio: 1.0, + ), + }, string_map: { /// Start Common section // Texts used in multiple locations with the same formatting diff --git a/assets/voxygen/i18n/fr_FR.ron b/assets/voxygen/i18n/fr_FR.ron index d1cbbb75c6..6d5c4d581c 100644 --- a/assets/voxygen/i18n/fr_FR.ron +++ b/assets/voxygen/i18n/fr_FR.ron @@ -4,7 +4,29 @@ VoxygenLocalization( language_name: "Français", language_identifier: "fr_FR", ), - convert_utf8_to_ascii: true, + convert_utf8_to_ascii: false, + fonts: { + "opensans": Font ( + asset_key: "voxygen.font.OpenSans-Regular", + scale_ratio: 1.0, + ), + "metamorph": Font ( + asset_key: "voxygen.font.Metamorphous-Regular", + scale_ratio: 1.0, + ), + "alkhemi": Font ( + asset_key: "voxygen.font.Alkhemikal", + scale_ratio: 1.0, + ), + "wizard": Font ( + asset_key: "voxygen.font.wizard", + scale_ratio: 1.0, + ), + "cyri": Font ( + asset_key: "voxygen.font.haxrcorp_4089_cyrillic_altgr_extended", + scale_ratio: 0.9, + ), + }, string_map: { // Common texts used in multiple locations "common.username": "pseudo", @@ -16,7 +38,7 @@ VoxygenLocalization( "common.languages": "Langues", "common.interface": "Interface", "common.gameplay": "Gameplay", - "common.controls": "Controles", + "common.controls": "Contrôles", "common.video": "Video", "common.sound": "Audio", "common.resume": "Reprendre", diff --git a/voxygen/Cargo.toml b/voxygen/Cargo.toml index 74b11a18c0..7c3e6debb0 100644 --- a/voxygen/Cargo.toml +++ b/voxygen/Cargo.toml @@ -72,6 +72,7 @@ winres = "0.1" [dev-dependencies] criterion = "0.3" +git2 = "0.10" world = { package = "veloren-world", path = "../world" } [[bench]] diff --git a/voxygen/src/hud/bag.rs b/voxygen/src/hud/bag.rs index 3869b778f1..22d763ed42 100644 --- a/voxygen/src/hud/bag.rs +++ b/voxygen/src/hud/bag.rs @@ -1,9 +1,9 @@ use super::{ img_ids::{Imgs, ImgsRot}, item_imgs::{ItemImgs, ItemKey}, - Event as HudEvent, Fonts, TEXT_COLOR, + Event as HudEvent, TEXT_COLOR, }; -use crate::ui::{ImageFrame, Tooltip, TooltipManager, Tooltipable}; +use crate::ui::{fonts::ConrodVoxygenFonts, ImageFrame, Tooltip, TooltipManager, Tooltipable}; use client::Client; use conrod_core::{ color, image, @@ -35,7 +35,7 @@ pub struct Bag<'a> { client: &'a Client, imgs: &'a Imgs, item_imgs: &'a ItemImgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, #[conrod(common_builder)] common: widget::CommonBuilder, rot_imgs: &'a ImgsRot, @@ -48,7 +48,7 @@ impl<'a> Bag<'a> { client: &'a Client, imgs: &'a Imgs, item_imgs: &'a ItemImgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, rot_imgs: &'a ImgsRot, tooltip_manager: &'a mut TooltipManager, pulse: f32, @@ -118,10 +118,11 @@ impl<'a> Widget for Bag<'a> { 5.0, ) }) - .title_font_size(15) + .title_font_size(self.fonts.cyri.scale(15)) .parent(ui.window) - .desc_font_size(12) + .desc_font_size(self.fonts.cyri.scale(12)) .title_text_color(TEXT_COLOR) + .font_id(self.fonts.cyri.conrod_id) .desc_text_color(TEXT_COLOR); // Bag parts diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index d37a186dcf..b6931106cf 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -3,8 +3,8 @@ use conrod_core::{ widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, }; -use super::{img_ids::Imgs, Fonts, Windows, TEXT_COLOR}; -use crate::ui::ToggleButton; +use super::{img_ids::Imgs, Windows, TEXT_COLOR}; +use crate::ui::{fonts::ConrodVoxygenFonts, ToggleButton}; widget_ids! { struct Ids { @@ -31,7 +31,7 @@ pub struct Buttons<'a> { show_bag: bool, imgs: &'a Imgs, - _fonts: &'a Fonts, + _fonts: &'a ConrodVoxygenFonts, #[conrod(common_builder)] common: widget::CommonBuilder, } @@ -42,14 +42,14 @@ impl<'a> Buttons<'a> { show_map: bool, show_bag: bool, imgs: &'a Imgs, - _fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, ) -> Self { Self { open_windows, show_map, show_bag, imgs, - _fonts, + _fonts: fonts, common: widget::CommonBuilder::default(), } } diff --git a/voxygen/src/hud/character_window.rs b/voxygen/src/hud/character_window.rs index ecf972250d..48b460a16f 100644 --- a/voxygen/src/hud/character_window.rs +++ b/voxygen/src/hud/character_window.rs @@ -1,5 +1,5 @@ -use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR, XP_COLOR}; -use crate::i18n::VoxygenLocalization; +use super::{img_ids::Imgs, Show, TEXT_COLOR, XP_COLOR}; +use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts}; use common::comp::Stats; use conrod_core::{ color, @@ -71,7 +71,7 @@ widget_ids! { pub struct CharacterWindow<'a> { _show: &'a Show, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, stats: &'a Stats, localized_strings: &'a std::sync::Arc, @@ -84,7 +84,7 @@ impl<'a> CharacterWindow<'a> { _show: &'a Show, stats: &'a Stats, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { @@ -155,8 +155,8 @@ impl<'a> Widget for CharacterWindow<'a> { .get("character_window.character_name"), ) .mid_top_with_margin_on(state.charwindow_frame, 6.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .color(TEXT_COLOR) .set(state.charwindow_title, ui); @@ -352,8 +352,8 @@ impl<'a> Widget for CharacterWindow<'a> { // Level Text::new(&level) .mid_top_with_margin_on(state.charwindow_rectangle, 10.0) - .font_id(self.fonts.cyri) - .font_size(30) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(30)) .color(TEXT_COLOR) .set(state.charwindow_tab1_level, ui); @@ -376,8 +376,8 @@ impl<'a> Widget for CharacterWindow<'a> { // Exp-Text Text::new(&exp_treshold) .mid_top_with_margin_on(state.charwindow_tab1_expbar, 10.0) - .font_id(self.fonts.cyri) - .font_size(15) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(15)) .color(TEXT_COLOR) .set(state.charwindow_tab1_exp, ui); @@ -395,8 +395,8 @@ impl<'a> Widget for CharacterWindow<'a> { .get("character_window.character_stats"), ) .top_left_with_margins_on(state.charwindow_rectangle, 140.0, 5.0) - .font_id(self.fonts.cyri) - .font_size(16) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(16)) .color(TEXT_COLOR) .set(state.charwindow_tab1_statnames, ui); @@ -406,8 +406,8 @@ impl<'a> Widget for CharacterWindow<'a> { self.stats.endurance, self.stats.fitness, self.stats.willpower )) .top_right_with_margins_on(state.charwindow_rectangle, 140.0, 5.0) - .font_id(self.fonts.cyri) - .font_size(16) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(16)) .color(TEXT_COLOR) .set(state.charwindow_tab1_stats, ui); diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 1b7b1859c8..2a3197fdaa 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -1,8 +1,8 @@ use super::{ - img_ids::Imgs, Fonts, BROADCAST_COLOR, FACTION_COLOR, GAME_UPDATE_COLOR, GROUP_COLOR, - KILL_COLOR, META_COLOR, PRIVATE_COLOR, SAY_COLOR, TELL_COLOR, TEXT_COLOR, + img_ids::Imgs, BROADCAST_COLOR, FACTION_COLOR, GAME_UPDATE_COLOR, GROUP_COLOR, KILL_COLOR, + META_COLOR, PRIVATE_COLOR, SAY_COLOR, TELL_COLOR, TEXT_COLOR, }; -use crate::GlobalState; +use crate::{ui::fonts::ConrodVoxygenFonts, GlobalState}; use client::Event as ClientEvent; use common::{msg::validate_chat_msg, ChatType}; use conrod_core::{ @@ -34,7 +34,7 @@ pub struct Chat<'a> { global_state: &'a GlobalState, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, #[conrod(common_builder)] common: widget::CommonBuilder, @@ -48,7 +48,7 @@ impl<'a> Chat<'a> { new_messages: &'a mut VecDeque, global_state: &'a GlobalState, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, ) -> Self { Self { new_messages, @@ -187,8 +187,8 @@ impl<'a> Widget for Chat<'a> { .restrict_to_height(false) .color(TEXT_COLOR) .line_spacing(2.0) - .font_size(15) - .font_id(self.fonts.opensans); + .font_size(self.fonts.opensans.scale(15)) + .font_id(self.fonts.opensans.conrod_id); if let Some(pos) = self.force_cursor { text_edit = text_edit.cursor_pos(pos); @@ -251,8 +251,8 @@ impl<'a> Widget for Chat<'a> { ChatType::Kill => KILL_COLOR, }; let text = Text::new(&message) - .font_size(15) - .font_id(self.fonts.opensans) + .font_size(self.fonts.opensans.scale(15)) + .font_id(self.fonts.opensans.conrod_id) .w(470.0) .color(color) .line_spacing(2.0); @@ -270,8 +270,8 @@ impl<'a> Widget for Chat<'a> { // Needs to be larger than the space above. Some( Text::new("") - .font_size(6) - .font_id(self.fonts.opensans) + .font_size(self.fonts.opensans.scale(6)) + .font_id(self.fonts.opensans.conrod_id) .w(470.0), ) }; diff --git a/voxygen/src/hud/esc_menu.rs b/voxygen/src/hud/esc_menu.rs index 8743805b06..cf0be312ca 100644 --- a/voxygen/src/hud/esc_menu.rs +++ b/voxygen/src/hud/esc_menu.rs @@ -1,5 +1,5 @@ -use super::{img_ids::Imgs, settings_window::SettingsTab, Fonts, TEXT_COLOR}; -use crate::i18n::VoxygenLocalization; +use super::{img_ids::Imgs, settings_window::SettingsTab, TEXT_COLOR}; +use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts}; use conrod_core::{ widget::{self, Button, Image}, widget_ids, Labelable, Positionable, Sizeable, Widget, WidgetCommon, @@ -21,7 +21,7 @@ widget_ids! { #[derive(WidgetCommon)] pub struct EscMenu<'a> { imgs: &'a Imgs, - _fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, #[conrod(common_builder)] @@ -31,12 +31,12 @@ pub struct EscMenu<'a> { impl<'a> EscMenu<'a> { pub fn new( imgs: &'a Imgs, - _fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { imgs, - _fonts, + fonts, localized_strings, common: widget::CommonBuilder::default(), } @@ -90,7 +90,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("common.resume")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_1, ui) .was_clicked() { @@ -106,7 +107,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("common.settings")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_2, ui) .was_clicked() { @@ -121,7 +123,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("common.controls")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_3, ui) .was_clicked() { @@ -136,7 +139,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("common.characters")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_4, ui) .was_clicked() { @@ -151,7 +155,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("esc_menu.logout")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_5, ui) .was_clicked() { @@ -166,7 +171,8 @@ impl<'a> Widget for EscMenu<'a> { .label(&self.localized_strings.get("esc_menu.quit_game")) .label_y(conrod_core::position::Relative::Scalar(3.0)) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.menu_button_6, ui) .was_clicked() { diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 0ce7691198..0b237c72ec 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -1,8 +1,8 @@ use super::{ img_ids::{Imgs, ImgsRot}, - Fonts, Show, TEXT_COLOR, + Show, TEXT_COLOR, }; -use crate::ui::img_ids; +use crate::ui::{fonts::ConrodVoxygenFonts, img_ids}; use client::{self, Client}; use common::{comp, terrain::TerrainChunkSize, vol::RectVolSize}; use conrod_core::{ @@ -12,6 +12,7 @@ use conrod_core::{ }; use specs::WorldExt; use vek::*; + widget_ids! { struct Ids { map_frame, @@ -36,7 +37,7 @@ pub struct Map<'a> { world_map: &'a (img_ids::Rotations, Vec2), imgs: &'a Imgs, rot_imgs: &'a ImgsRot, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, #[conrod(common_builder)] common: widget::CommonBuilder, _pulse: f32, @@ -49,7 +50,7 @@ impl<'a> Map<'a> { imgs: &'a Imgs, rot_imgs: &'a ImgsRot, world_map: &'a (img_ids::Rotations, Vec2), - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, pulse: f32, velocity: f32, ) -> Self { @@ -149,15 +150,15 @@ impl<'a> Widget for Map<'a> { match self.client.current_chunk() { Some(chunk) => Text::new(chunk.meta().name()) .mid_top_with_margin_on(state.ids.map_bg, 55.0) - .font_size(60) + .font_size(self.fonts.alkhemi.scale(60)) .color(TEXT_COLOR) - .font_id(self.fonts.alkhemi) + .font_id(self.fonts.alkhemi.conrod_id) .parent(state.ids.map_frame_r) .set(state.ids.location_name, ui), None => Text::new(" ") .mid_top_with_margin_on(state.ids.map_bg, 3.0) - .font_size(40) - .font_id(self.fonts.alkhemi) + .font_size(self.fonts.alkhemi.scale(40)) + .font_id(self.fonts.alkhemi.conrod_id) .color(TEXT_COLOR) .set(state.ids.location_name, ui), } diff --git a/voxygen/src/hud/minimap.rs b/voxygen/src/hud/minimap.rs index 259325f178..d44668ed5f 100644 --- a/voxygen/src/hud/minimap.rs +++ b/voxygen/src/hud/minimap.rs @@ -1,8 +1,8 @@ use super::{ img_ids::{Imgs, ImgsRot}, - Fonts, Show, HP_COLOR, TEXT_COLOR, + Show, HP_COLOR, TEXT_COLOR, }; -use crate::ui::img_ids; +use crate::ui::{fonts::ConrodVoxygenFonts, img_ids}; use client::{self, Client}; use common::{comp, terrain::TerrainChunkSize, vol::RectVolSize}; use conrod_core::{ @@ -38,7 +38,7 @@ pub struct MiniMap<'a> { imgs: &'a Imgs, rot_imgs: &'a ImgsRot, world_map: &'a (img_ids::Rotations, Vec2), - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, #[conrod(common_builder)] common: widget::CommonBuilder, } @@ -50,7 +50,7 @@ impl<'a> MiniMap<'a> { imgs: &'a Imgs, rot_imgs: &'a ImgsRot, world_map: &'a (img_ids::Rotations, Vec2), - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, ) -> Self { Self { show, @@ -276,20 +276,20 @@ impl<'a> Widget for MiniMap<'a> { // Region Name Text::new(state.last_region_name.as_ref().unwrap_or(&"".to_owned())) .mid_top_with_margin_on(ui.window, 200.0) - .font_size(70) - .font_id(self.fonts.alkhemi) + .font_size(self.fonts.alkhemi.scale(70)) + .font_id(self.fonts.alkhemi.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, fade)) .set(state.ids.zone_display_bg, ui); Text::new(state.last_region_name.as_ref().unwrap_or(&"".to_owned())) .top_left_with_margins_on(state.ids.zone_display_bg, -2.5, -2.5) - .font_size(70) - .font_id(self.fonts.alkhemi) + .font_size(self.fonts.alkhemi.scale(70)) + .font_id(self.fonts.alkhemi.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade)) .set(state.ids.zone_display, ui); }, None => Text::new(" ") .middle_of(ui.window) - .font_size(14) + .font_size(self.fonts.alkhemi.scale(14)) .color(HP_COLOR) .set(state.ids.zone_display, ui), } @@ -303,13 +303,17 @@ impl<'a> Widget for MiniMap<'a> { state.ids.mmap_frame, if self.show.mini_map { 6.0 } else { 0.0 }, ) - .font_size(if self.show.mini_map { 20 } else { 18 }) - .font_id(self.fonts.cyri) + .font_size( + self.fonts + .cyri + .scale(if self.show.mini_map { 30 } else { 18 }), + ) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.mmap_location, ui), None => Text::new(" ") .mid_top_with_margin_on(state.ids.mmap_frame, 0.0) - .font_size(18) + .font_size(self.fonts.cyri.scale(18)) .color(TEXT_COLOR) .set(state.ids.mmap_location, ui), } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index c6908a992b..ae2bc278de 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -39,7 +39,7 @@ use crate::{ i18n::{i18n_asset_key, LanguageMetadata, VoxygenLocalization}, render::{AaMode, CloudMode, Consts, FluidMode, Globals, Renderer}, scene::camera::Camera, - ui::{Graphic, Ingameable, ScaleMode, Ui}, + ui::{fonts::ConrodVoxygenFonts, Graphic, Ingameable, ScaleMode, Ui}, window::{Event as WinEvent, GameInput}, GlobalState, }; @@ -178,16 +178,6 @@ widget_ids! { } } -font_ids! { - pub struct Fonts { - opensans: "voxygen.font.OpenSans-Regular", - metamorph: "voxygen.font.Metamorphous-Regular", - alkhemi: "voxygen.font.Alkhemikal", - wizard: "voxygen.font.wizard", - cyri:"voxygen.font.haxrcorp_4089_cyrillic_altgr", - } -} - pub struct DebugInfo { pub tps: f64, pub ping_ms: f64, @@ -433,7 +423,7 @@ pub struct Hud { world_map: (/* Id */ Rotations, Vec2), imgs: Imgs, item_imgs: ItemImgs, - fonts: Fonts, + fonts: ConrodVoxygenFonts, rot_imgs: ImgsRot, new_messages: VecDeque, show: Show, @@ -446,6 +436,7 @@ pub struct Hud { force_chat_cursor: Option, pulse: f32, velocity: f32, + voxygen_i18n: std::sync::Arc, } impl Hud { @@ -468,8 +459,13 @@ impl Hud { let rot_imgs = ImgsRot::load(&mut ui).expect("Failed to load rot images!"); // Load item images. let item_imgs = ItemImgs::new(&mut ui); + // Load language + let voxygen_i18n = load_expect::(&i18n_asset_key( + &global_state.settings.language.selected_language, + )); // Load fonts. - let fonts = Fonts::load(&mut ui).expect("Failed to load fonts!"); + let fonts = ConrodVoxygenFonts::load(&voxygen_i18n.fonts, &mut ui) + .expect("Impossible to load fonts!"); Self { ui, @@ -508,9 +504,16 @@ impl Hud { force_chat_cursor: None, pulse: 0.0, velocity: 0.0, + voxygen_i18n, } } + pub fn update_language(&mut self, voxygen_i18n: std::sync::Arc) { + self.voxygen_i18n = voxygen_i18n; + self.fonts = ConrodVoxygenFonts::load(&self.voxygen_i18n.fonts, &mut self.ui) + .expect("Impossible to load fonts!"); + } + fn update_layout( &mut self, client: &Client, @@ -533,10 +536,6 @@ impl Hud { common::util::GIT_VERSION.to_string() ); - let localized_strings = load_expect::(&i18n_asset_key( - &global_state.settings.language.selected_language, - )); - if self.show.ingame { let ecs = client.state().ecs(); let pos = ecs.read_storage::(); @@ -1167,13 +1166,13 @@ impl Hud { // Name Text::new(&name) - .font_size(30) + .font_size(self.fonts.cyri.scale(30)) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .x_y(-1.0, MANA_BAR_Y + 48.0) .position_ingame(ingame_pos) .set(name_bg_id, ui_widgets); Text::new(&name) - .font_size(30) + .font_size(self.fonts.cyri.scale(30)) .color(Color::Rgba(0.61, 0.61, 0.89, 1.0)) .x_y(0.0, MANA_BAR_Y + 50.0) .position_ingame(ingame_pos) @@ -1225,7 +1224,7 @@ impl Hud { } // Introduction Text - let intro_text = &localized_strings.get("hud.welcome"); + let intro_text = &self.voxygen_i18n.get("hud.welcome"); if self.show.intro && !self.show.esc_menu && !self.intro_2 { match global_state.settings.gameplay.intro_show { Intro::Show => { @@ -1235,15 +1234,16 @@ impl Hud { .set(self.ids.intro_bg, ui_widgets); Text::new(intro_text) .top_left_with_margins_on(self.ids.intro_bg, 10.0, 10.0) - .font_size(20) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(20)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.intro_text, ui_widgets); if Button::image(self.imgs.button) .w_h(100.0, 50.0) .mid_bottom_with_margin_on(self.ids.intro_bg, 10.0) - .label(&localized_strings.get("common.close")) - .label_font_size(20) + .label(&self.voxygen_i18n.get("common.close")) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) @@ -1279,10 +1279,10 @@ impl Hud { { self.never_show = !self.never_show }; - Text::new(&localized_strings.get("hud.do_not_show_on_startup")) + Text::new(&self.voxygen_i18n.get("hud.do_not_show_on_startup")) .right_from(self.ids.intro_check, 10.0) - .font_size(10) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(10)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.intro_check_text, ui_widgets); // X-button @@ -1318,15 +1318,15 @@ impl Hud { .set(self.ids.intro_bg, ui_widgets); Text::new(intro_text) .top_left_with_margins_on(self.ids.intro_bg, 10.0, 10.0) - .font_size(20) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(20)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.intro_text, ui_widgets); if Button::image(self.imgs.button) .w_h(100.0, 50.0) .mid_bottom_with_margin_on(self.ids.intro_bg, 10.0) - .label(&localized_strings.get("common.close")) - .label_font_size(20) + .label(&self.voxygen_i18n.get("common.close")) + .label_font_size(self.fonts.cyri.scale(20)) .label_color(TEXT_COLOR) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) @@ -1363,23 +1363,23 @@ impl Hud { // Alpha Version Text::new(&version) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.version, ui_widgets); // Ticks per second Text::new(&format!("FPS: {:.0}", debug_info.tps)) .color(TEXT_COLOR) .down_from(self.ids.version, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.fps_counter, ui_widgets); // Ping Text::new(&format!("Ping: {:.0}ms", debug_info.ping_ms)) .color(TEXT_COLOR) .down_from(self.ids.fps_counter, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.ping, ui_widgets); // Player's position let coordinates_text = match debug_info.coordinates { @@ -1392,8 +1392,8 @@ impl Hud { Text::new(&coordinates_text) .color(TEXT_COLOR) .down_from(self.ids.ping, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.coordinates, ui_widgets); // Player's velocity let velocity_text = match debug_info.velocity { @@ -1409,8 +1409,8 @@ impl Hud { Text::new(&velocity_text) .color(TEXT_COLOR) .down_from(self.ids.coordinates, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.velocity, ui_widgets); // Loaded distance Text::new(&format!( @@ -1420,8 +1420,8 @@ impl Hud { )) .color(TEXT_COLOR) .down_from(self.ids.velocity, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.loaded_distance, ui_widgets); // Time let time_in_seconds = client.state().get_time_of_day(); @@ -1436,8 +1436,8 @@ impl Hud { )) .color(TEXT_COLOR) .down_from(self.ids.loaded_distance, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.time, ui_widgets); // Number of entities @@ -1445,8 +1445,8 @@ impl Hud { Text::new(&format!("Entity count: {}", entity_count)) .color(TEXT_COLOR) .down_from(self.ids.time, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.entity_count, ui_widgets); // Number of chunks @@ -1456,8 +1456,8 @@ impl Hud { )) .color(TEXT_COLOR) .down_from(self.ids.entity_count, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.num_chunks, ui_widgets); // Number of figures @@ -1467,13 +1467,14 @@ impl Hud { )) .color(TEXT_COLOR) .down_from(self.ids.num_chunks, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.num_figures, ui_widgets); // Help Window Text::new( - &localized_strings + &self + .voxygen_i18n .get("hud.press_key_to_toggle_keybindings_fmt") .replace( "{key}", @@ -1482,12 +1483,13 @@ impl Hud { ) .color(TEXT_COLOR) .down_from(self.ids.num_figures, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.help_info, ui_widgets); // Info about Debug Shortcut Text::new( - &localized_strings + &self + .voxygen_i18n .get("hud.press_key_to_toggle_debug_info_fmt") .replace( "{key}", @@ -1496,13 +1498,14 @@ impl Hud { ) .color(TEXT_COLOR) .down_from(self.ids.help_info, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.debug_info, ui_widgets); } else { // Help Window Text::new( - &localized_strings + &self + .voxygen_i18n .get("hud.press_key_to_show_keybindings_fmt") .replace( "{key}", @@ -1511,12 +1514,13 @@ impl Hud { ) .color(TEXT_COLOR) .top_left_with_margins_on(ui_widgets.window, 5.0, 5.0) - .font_id(self.fonts.cyri) - .font_size(16) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(16)) .set(self.ids.help_info, ui_widgets); // Info about Debug Shortcut Text::new( - &localized_strings + &self + .voxygen_i18n .get("hud.press_key_to_show_debug_info_fmt") .replace( "{key}", @@ -1525,8 +1529,8 @@ impl Hud { ) .color(TEXT_COLOR) .down_from(self.ids.help_info, 5.0) - .font_id(self.fonts.cyri) - .font_size(12) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(12)) .set(self.ids.debug_info, ui_widgets); } @@ -1541,8 +1545,8 @@ impl Hud { .w_h(120.0, 50.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("hud.show_tips")) - .label_font_size(20) + .label(&self.voxygen_i18n.get("hud.show_tips")) + .label_font_size(self.fonts.cyri.scale(20)) .label_color(TEXT_COLOR) .mid_bottom_with_margin_on(self.ids.help, 20.0) .set(self.ids.button_help3, ui_widgets) @@ -1686,7 +1690,7 @@ impl Hud { &self.show, &self.imgs, &self.fonts, - &localized_strings, + &self.voxygen_i18n, ) .set(self.ids.settings_window, ui_widgets) { @@ -1787,7 +1791,7 @@ impl Hud { client, &self.imgs, &self.fonts, - &localized_strings, + &self.voxygen_i18n, ) .set(self.ids.social_window, ui_widgets) { @@ -1810,7 +1814,7 @@ impl Hud { &player_stats, &self.imgs, &self.fonts, - &localized_strings, + &self.voxygen_i18n, ) .set(self.ids.character_window, ui_widgets) { @@ -1829,7 +1833,7 @@ impl Hud { client, &self.imgs, &self.fonts, - &localized_strings, + &self.voxygen_i18n, ) .set(self.ids.spell, ui_widgets) { @@ -1848,7 +1852,7 @@ impl Hud { client, &self.imgs, &self.fonts, - &localized_strings, + &self.voxygen_i18n, ) .set(self.ids.quest, ui_widgets) { @@ -1882,7 +1886,7 @@ impl Hud { } if self.show.esc_menu { - match EscMenu::new(&self.imgs, &self.fonts, &localized_strings) + match EscMenu::new(&self.imgs, &self.fonts, &self.voxygen_i18n) .set(self.ids.esc_menu, ui_widgets) { Some(esc_menu::Event::OpenSettings(tab)) => { diff --git a/voxygen/src/hud/quest.rs b/voxygen/src/hud/quest.rs index 094c52629b..795abfd475 100644 --- a/voxygen/src/hud/quest.rs +++ b/voxygen/src/hud/quest.rs @@ -1,5 +1,5 @@ -use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR}; -use crate::i18n::VoxygenLocalization; +use super::{img_ids::Imgs, Show, TEXT_COLOR}; +use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts}; use client::{self, Client}; use conrod_core::{ color, @@ -23,7 +23,7 @@ pub struct Quest<'a> { _client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, #[conrod(common_builder)] common: widget::CommonBuilder, @@ -34,7 +34,7 @@ impl<'a> Quest<'a> { show: &'a Show, _client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { @@ -98,8 +98,8 @@ impl<'a> Widget for Quest<'a> { // TODO: Use an actual character name. Text::new(&self.localized_strings.get("hud.quests")) .mid_top_with_margin_on(state.quest_frame, 6.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .color(TEXT_COLOR) .set(state.quest_title, ui); diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 66f6f56675..58b71226de 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -1,11 +1,11 @@ use super::{ - img_ids::Imgs, BarNumbers, CrosshairType, Fonts, Intro, ShortcutNumbers, Show, XpBar, MENU_BG, + img_ids::Imgs, BarNumbers, CrosshairType, Intro, ShortcutNumbers, Show, XpBar, MENU_BG, TEXT_COLOR, }; use crate::{ i18n::{list_localizations, LanguageMetadata, VoxygenLocalization}, render::{AaMode, CloudMode, FluidMode}, - ui::{ImageSlider, ScaleMode, ToggleButton}, + ui::{fonts::ConrodVoxygenFonts, ImageSlider, ScaleMode, ToggleButton}, GlobalState, }; use conrod_core::{ @@ -155,7 +155,7 @@ pub struct SettingsWindow<'a> { global_state: &'a GlobalState, show: &'a Show, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, #[conrod(common_builder)] common: widget::CommonBuilder, @@ -166,7 +166,7 @@ impl<'a> SettingsWindow<'a> { global_state: &'a GlobalState, show: &'a Show, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { @@ -288,7 +288,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Title Text::new(&self.localized_strings.get("common.settings")) .mid_top_with_margin_on(state.ids.settings_bg, 5.0) - .font_size(14) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.settings_title, ui); @@ -311,7 +312,8 @@ impl<'a> Widget for SettingsWindow<'a> { }) .top_left_with_margins_on(state.ids.settings_l, 8.0 * 4.0, 2.0 * 4.0) .label(&self.localized_strings.get("common.interface")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(state.ids.interface, ui) .was_clicked() @@ -328,8 +330,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("hud.settings.general")) .top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.general_txt, ui); @@ -351,8 +353,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("hud.settings.help_window")) .right_from(state.ids.button_help, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.button_help) .color(TEXT_COLOR) .set(state.ids.show_help_label, ui); @@ -375,8 +377,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("hud.settings.debug_info")) .right_from(state.ids.debug_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.debug_button) .color(TEXT_COLOR) .set(state.ids.debug_button_label, ui); @@ -402,8 +404,8 @@ impl<'a> Widget for SettingsWindow<'a> { }; Text::new(&self.localized_strings.get("hud.settings.tips_on_startup")) .right_from(state.ids.tips_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.button_help) .color(TEXT_COLOR) .set(state.ids.tips_button_label, ui); @@ -411,8 +413,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Ui Scale Text::new(&self.localized_strings.get("hud.settings.ui_scale")) .down_from(state.ids.tips_button, 20.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.ui_scale_label, ui); @@ -445,8 +447,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(self.localized_strings.get("hud.settings.relative_scaling")) .right_from(state.ids.relative_to_win_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.relative_to_win_button) .color(TEXT_COLOR) .set(state.ids.relative_to_win_text, ui); @@ -480,8 +482,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(self.localized_strings.get("hud.settings.custom_scaling")) .right_from(state.ids.absolute_scale_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.absolute_scale_button) .color(TEXT_COLOR) .set(state.ids.absolute_scale_text, ui); @@ -507,8 +509,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Custom Scaling Text Text::new(&format!("{:.2}", scale)) .right_from(state.ids.ui_scale_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.ui_scale_value, ui); } else { @@ -657,14 +659,14 @@ impl<'a> Widget for SettingsWindow<'a> { // Crosshair Transparency Text and Slider Text::new(&self.localized_strings.get("hud.settings.crosshair")) .down_from(state.ids.absolute_scale_button, 20.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.ch_title, ui); Text::new(&self.localized_strings.get("hud.settings.transparency")) .right_from(state.ids.ch_3_bg, 20.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.ch_transp_text, ui); @@ -687,17 +689,17 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&format!("{:.2}", crosshair_transp,)) .right_from(state.ids.ch_transp_slider, 8.0) - .font_size(14) + .font_size(self.fonts.cyri.scale(14)) .graphics_for(state.ids.ch_transp_slider) - .font_id(self.fonts.cyri) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.ch_transp_value, ui); // Hotbar text Text::new(&self.localized_strings.get("hud.settings.hotbar")) .down_from(state.ids.ch_1_bg, 20.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.hotbar_title, ui); // Show xp bar @@ -729,8 +731,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.toggle_bar_experience"), ) .right_from(state.ids.show_xpbar_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.show_xpbar_button) .color(TEXT_COLOR) .set(state.ids.show_xpbar_text, ui); @@ -763,8 +765,8 @@ impl<'a> Widget for SettingsWindow<'a> { } Text::new(&self.localized_strings.get("hud.settings.toggle_shortcuts")) .right_from(state.ids.show_shortcuts_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.show_shortcuts_button) .color(TEXT_COLOR) .set(state.ids.show_shortcuts_text, ui); @@ -792,8 +794,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.scrolling_combat_text"), ) .top_left_with_margins_on(state.ids.settings_content_r, 5.0, 5.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.sct_title, ui); // Generally toggle the SCT @@ -817,8 +819,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.scrolling_combat_text"), ) .right_from(state.ids.sct_show_radio, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.sct_show_radio) .color(TEXT_COLOR) .set(state.ids.sct_show_text, ui); @@ -841,8 +843,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.single_damage_number"), ) .right_from(state.ids.sct_single_dmg_radio, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.sct_single_dmg_radio) .color(TEXT_COLOR) .set(state.ids.sct_single_dmg_text, ui); @@ -865,8 +867,8 @@ impl<'a> Widget for SettingsWindow<'a> { } Text::new(&self.localized_strings.get("hud.settings.cumulated_damage")) .right_from(state.ids.sct_show_batch_radio, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.sct_batched_dmg_radio) .color(TEXT_COLOR) .set(state.ids.sct_show_batch_text, ui); @@ -884,8 +886,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("hud.settings.incoming_damage")) .right_from(state.ids.sct_inc_dmg_radio, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.sct_inc_dmg_radio) .color(TEXT_COLOR) .set(state.ids.sct_inc_dmg_text, ui); @@ -912,8 +914,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.cumulated_incoming_damage"), ) .right_from(state.ids.sct_batch_inc_radio, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.sct_batch_inc_radio) .color(TEXT_COLOR) .set(state.ids.sct_batch_inc_text, ui); @@ -930,8 +932,8 @@ impl<'a> Widget for SettingsWindow<'a> { }, 20.0, ) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.bar_numbers_title, ui); @@ -960,8 +962,8 @@ impl<'a> Widget for SettingsWindow<'a> { } Text::new(&self.localized_strings.get("hud.settings.none")) .right_from(state.ids.show_bar_numbers_none_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.show_bar_numbers_none_button) .color(TEXT_COLOR) .set(state.ids.show_bar_numbers_none_text, ui); @@ -991,8 +993,8 @@ impl<'a> Widget for SettingsWindow<'a> { } Text::new(&self.localized_strings.get("hud.settings.values")) .right_from(state.ids.show_bar_numbers_values_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.show_bar_numbers_values_button) .color(TEXT_COLOR) .set(state.ids.show_bar_numbers_values_text, ui); @@ -1022,8 +1024,8 @@ impl<'a> Widget for SettingsWindow<'a> { } Text::new(&self.localized_strings.get("hud.settings.percentages")) .right_from(state.ids.show_bar_numbers_percentage_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.show_bar_numbers_percentage_button) .color(TEXT_COLOR) .set(state.ids.show_bar_numbers_percentage_text, ui); @@ -1031,8 +1033,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Chat Transp Text::new(&self.localized_strings.get("hud.settings.chat")) .down_from(state.ids.show_bar_numbers_percentage_button, 20.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.chat_transp_title, ui); Text::new( @@ -1041,8 +1043,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.background_transparency"), ) .right_from(state.ids.chat_transp_slider, 20.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.chat_transp_text, ui); @@ -1065,8 +1067,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("common.languages")) .down_from(state.ids.chat_transp_slider, 20.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.language_text, ui); @@ -1085,7 +1087,7 @@ impl<'a> Widget for SettingsWindow<'a> { .w_h(200.0, 22.0) .color(MENU_BG) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.languages_list, ui) { events.push(Event::ChangeLanguage(language_list[clicked].to_owned())); @@ -1111,7 +1113,8 @@ impl<'a> Widget for SettingsWindow<'a> { }) .right_from(state.ids.interface, 0.0) .label(&self.localized_strings.get("common.gameplay")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(state.ids.gameplay, ui) .was_clicked() @@ -1127,8 +1130,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Mouse Pan Sensitivity Text::new(&self.localized_strings.get("hud.settings.pan_sensitivity")) .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.mouse_pan_label, ui); @@ -1151,16 +1154,16 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&format!("{}", display_pan)) .right_from(state.ids.mouse_pan_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.mouse_pan_value, ui); // Mouse Zoom Sensitivity Text::new(&self.localized_strings.get("hud.settings.zoom_sensitivity")) .down_from(state.ids.mouse_pan_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.mouse_zoom_label, ui); @@ -1183,8 +1186,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&format!("{}", display_zoom)) .right_from(state.ids.mouse_zoom_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.mouse_zoom_value, ui); @@ -1212,8 +1215,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.invert_scroll_zoom"), ) .right_from(state.ids.mouse_zoom_invert_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.mouse_zoom_invert_button) .color(TEXT_COLOR) .set(state.ids.mouse_zoom_invert_label, ui); @@ -1242,8 +1245,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.invert_mouse_y_axis"), ) .right_from(state.ids.mouse_y_invert_button, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .graphics_for(state.ids.mouse_y_invert_button) .color(TEXT_COLOR) .set(state.ids.mouse_y_invert_label, ui); @@ -1268,7 +1271,8 @@ impl<'a> Widget for SettingsWindow<'a> { }) .right_from(state.ids.gameplay, 0.0) .label(&self.localized_strings.get("common.controls")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(state.ids.controls, ui) .was_clicked() @@ -1282,8 +1286,8 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&self.localized_strings.get("hud.settings.control_names")) .color(TEXT_COLOR) .top_left_with_margins_on(state.ids.settings_content, 5.0, 5.0) - .font_id(self.fonts.cyri) - .font_size(18) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(18)) .set(state.ids.controls_text, ui); // TODO: Replace with buttons that show actual keybinds and allow the user to // change them. @@ -1412,8 +1416,8 @@ impl<'a> Widget for SettingsWindow<'a> { )) .color(TEXT_COLOR) .right_from(state.ids.controls_text, 0.0) - .font_id(self.fonts.cyri) - .font_size(18) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(18)) .set(state.ids.controls_controls, ui); } @@ -1437,7 +1441,8 @@ impl<'a> Widget for SettingsWindow<'a> { .right_from(state.ids.controls, 0.0) .label(&self.localized_strings.get("common.video")) .parent(state.ids.settings_r) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(state.ids.video, ui) .was_clicked() @@ -1450,8 +1455,8 @@ impl<'a> Widget for SettingsWindow<'a> { // View Distance Text::new(&self.localized_strings.get("hud.settings.view_distance")) .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.vd_text, ui); @@ -1477,16 +1482,16 @@ impl<'a> Widget for SettingsWindow<'a> { self.global_state.settings.graphics.view_distance )) .right_from(state.ids.vd_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.vd_value, ui); // Max FPS Text::new(&self.localized_strings.get("hud.settings.maximum_fps")) .down_from(state.ids.vd_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.max_fps_text, ui); @@ -1512,16 +1517,16 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&format!("{}", self.global_state.settings.graphics.max_fps)) .right_from(state.ids.max_fps_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.max_fps_value, ui); // FOV Text::new(&self.localized_strings.get("hud.settings.fov")) .down_from(state.ids.max_fps_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.fov_text, ui); @@ -1544,16 +1549,16 @@ impl<'a> Widget for SettingsWindow<'a> { Text::new(&format!("{}", self.global_state.settings.graphics.fov)) .right_from(state.ids.fov_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.fov_value, ui); // AaMode Text::new(&self.localized_strings.get("hud.settings.antialiasing_mode")) .down_from(state.ids.fov_slider, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.aa_mode_text, ui); @@ -1583,7 +1588,7 @@ impl<'a> Widget for SettingsWindow<'a> { .w_h(400.0, 22.0) .color(MENU_BG) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .down_from(state.ids.aa_mode_text, 8.0) .set(state.ids.aa_mode_list, ui) { @@ -1597,8 +1602,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.cloud_rendering_mode"), ) .down_from(state.ids.aa_mode_list, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.cloud_mode_text, ui); @@ -1619,7 +1624,7 @@ impl<'a> Widget for SettingsWindow<'a> { .w_h(400.0, 22.0) .color(MENU_BG) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .down_from(state.ids.cloud_mode_text, 8.0) .set(state.ids.cloud_mode_list, ui) { @@ -1633,8 +1638,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.fluid_rendering_mode"), ) .down_from(state.ids.cloud_mode_list, 8.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.fluid_mode_text, ui); @@ -1657,7 +1662,7 @@ impl<'a> Widget for SettingsWindow<'a> { .w_h(400.0, 22.0) .color(MENU_BG) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .down_from(state.ids.fluid_mode_text, 8.0) .set(state.ids.fluid_mode_list, ui) { @@ -1666,8 +1671,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Fullscreen Text::new(&self.localized_strings.get("hud.settings.fullscreen")) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .down_from(state.ids.fluid_mode_list, 8.0) .color(TEXT_COLOR) .set(state.ids.fullscreen_label, ui); @@ -1694,9 +1699,9 @@ impl<'a> Widget for SettingsWindow<'a> { .press_image(self.imgs.settings_button_press) .down_from(state.ids.fullscreen_label, 12.0) .label(&self.localized_strings.get("hud.settings.save_window_size")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .set(state.ids.save_window_size_button, ui) .was_clicked() { @@ -1730,7 +1735,8 @@ impl<'a> Widget for SettingsWindow<'a> { .right_from(state.ids.video, 0.0) .parent(state.ids.settings_r) .label(&self.localized_strings.get("common.sound")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(state.ids.sound, ui) .was_clicked() @@ -1743,8 +1749,8 @@ impl<'a> Widget for SettingsWindow<'a> { // Music Volume ----------------------------------------------------- Text::new(&self.localized_strings.get("hud.settings.music_volume")) .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.audio_volume_text, ui); @@ -1772,8 +1778,8 @@ impl<'a> Widget for SettingsWindow<'a> { .get("hud.settings.sound_effect_volume"), ) .down_from(state.ids.audio_volume_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.sfx_volume_text, ui); @@ -1799,8 +1805,8 @@ impl<'a> Widget for SettingsWindow<'a> { let device_list = &self.global_state.audio.device_list; Text::new(&self.localized_strings.get("hud.settings.audio_device")) .down_from(state.ids.sfx_volume_slider, 10.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.audio_device_text, ui); @@ -1811,7 +1817,7 @@ impl<'a> Widget for SettingsWindow<'a> { .w_h(400.0, 22.0) .color(MENU_BG) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.opensans) + .label_font_id(self.fonts.opensans.conrod_id) .down_from(state.ids.audio_device_text, 10.0) .set(state.ids.audio_device_list, ui) { diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 114f1137f8..91781e43eb 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -1,9 +1,10 @@ use super::{ - img_ids::Imgs, BarNumbers, Fonts, ShortcutNumbers, XpBar, CRITICAL_HP_COLOR, HP_COLOR, - LOW_HP_COLOR, MANA_COLOR, TEXT_COLOR, XP_COLOR, + img_ids::Imgs, BarNumbers, ShortcutNumbers, XpBar, CRITICAL_HP_COLOR, HP_COLOR, LOW_HP_COLOR, + MANA_COLOR, TEXT_COLOR, XP_COLOR, }; use crate::{ i18n::{i18n_asset_key, VoxygenLocalization}, + ui::fonts::ConrodVoxygenFonts, GlobalState, }; use common::{ @@ -108,7 +109,7 @@ pub enum ResourceType { pub struct Skillbar<'a> { global_state: &'a GlobalState, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, stats: &'a Stats, energy: &'a Energy, character_state: &'a CharacterState, @@ -123,7 +124,7 @@ impl<'a> Skillbar<'a> { pub fn new( global_state: &'a GlobalState, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, stats: &'a Stats, energy: &'a Energy, character_state: &'a CharacterState, @@ -264,14 +265,14 @@ impl<'a> Widget for Skillbar<'a> { .replace("{level_nb}", &self.stats.level.level().to_string()); Text::new(&level_up_text) .middle_of(state.ids.level_align) - .font_size(30) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(30)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, fade_level)) .set(state.ids.level_message_bg, ui); Text::new(&level_up_text) .bottom_left_with_margins_on(state.ids.level_message_bg, 2.0, 2.0) - .font_size(30) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(30)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_level)) .set(state.ids.level_message, ui); Image::new(self.imgs.level_up) @@ -290,8 +291,8 @@ impl<'a> Widget for Skillbar<'a> { if self.stats.is_dead { Text::new(&localized_strings.get("hud.you_died")) .middle_of(ui.window) - .font_size(50) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(50)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.death_message_1_bg, ui); Text::new(&localized_strings.get("hud.press_key_to_respawn").replace( @@ -299,14 +300,14 @@ impl<'a> Widget for Skillbar<'a> { &format!("{:?}", self.global_state.settings.controls.respawn), )) .mid_bottom_with_margin_on(state.ids.death_message_1_bg, -120.0) - .font_size(30) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(30)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.death_message_2_bg, ui); Text::new(&localized_strings.get("hud.you_died")) .bottom_left_with_margins_on(state.ids.death_message_1_bg, 2.0, 2.0) - .font_size(50) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(50)) + .font_id(self.fonts.cyri.conrod_id) .color(CRITICAL_HP_COLOR) .set(state.ids.death_message_1, ui); Text::new(&localized_strings.get("hud.press_key_to_respawn").replace( @@ -314,7 +315,8 @@ impl<'a> Widget for Skillbar<'a> { &format!("{:?}", self.global_state.settings.controls.respawn), )) .bottom_left_with_margins_on(state.ids.death_message_2_bg, 2.0, 2.0) - .font_size(30) + .font_size(self.fonts.cyri.scale(30)) + .font_id(self.fonts.cyri.conrod_id) .color(CRITICAL_HP_COLOR) .set(state.ids.death_message_2, ui); } @@ -347,8 +349,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 4.0 * scale, ) - .font_size(10) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(10)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -357,8 +359,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 4.0 * scale, ) - .font_size(10) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(10)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.next_level_text, ui); } else if self.stats.level.level() < 100 { @@ -369,8 +371,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 3.0 * scale, ) - .font_size(9) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(9)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -379,8 +381,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 3.0 * scale, ) - .font_size(9) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(9)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.next_level_text, ui); } else { @@ -391,8 +393,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 2.5 * scale, ) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -401,8 +403,8 @@ impl<'a> Widget for Skillbar<'a> { 3.5 * scale, 2.5 * scale, ) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, 1.0)) .set(state.ids.next_level_text, ui); } @@ -472,8 +474,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 4.0 * scale * 1.5, ) - .font_size(17) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(17)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -482,8 +484,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 4.0 * scale * 1.5, ) - .font_size(15) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(15)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.next_level_text, ui); } else if self.stats.level.level() < 100 { @@ -494,8 +496,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 3.0 * scale * 1.5, ) - .font_size(15) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(15)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -504,8 +506,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 3.0 * scale * 1.5, ) - .font_size(15) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(15)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.next_level_text, ui); } else { @@ -516,8 +518,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 2.75 * scale * 1.5, ) - .font_size(12) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(12)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.level_text, ui); Text::new(&next_level) @@ -526,8 +528,8 @@ impl<'a> Widget for Skillbar<'a> { 3.0 * scale * 1.5, 2.75 * scale * 1.5, ) - .font_size(12) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(12)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(1.0, 1.0, 1.0, fade_xp)) .set(state.ids.next_level_text, ui); } @@ -849,74 +851,74 @@ impl<'a> Widget for Skillbar<'a> { if let ShortcutNumbers::On = shortcuts { Text::new("1") .top_right_with_margins_on(state.ids.slot1_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot1_text, ui); Text::new("2") .top_right_with_margins_on(state.ids.slot2_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot2_text, ui); Text::new("3") .top_right_with_margins_on(state.ids.slot3_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot3_text, ui); Text::new("4") .top_right_with_margins_on(state.ids.slot4_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot4_text, ui); Text::new("5") .top_right_with_margins_on(state.ids.slot5_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot5_text, ui); Text::new("M1") .top_left_with_margins_on(state.ids.m1_slot, 5.0, 5.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.m1_text, ui); Text::new("M2") .top_right_with_margins_on(state.ids.m2_slot, 5.0, 5.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.m2_text, ui); Text::new("6") .top_left_with_margins_on(state.ids.slot6_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot6_text, ui); Text::new("7") .top_left_with_margins_on(state.ids.slot7_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot7_text, ui); Text::new("8") .top_left_with_margins_on(state.ids.slot8_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot8_text, ui); Text::new("9") .top_left_with_margins_on(state.ids.slot9_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slot9_text, ui); Text::new("Q") .top_left_with_margins_on(state.ids.slotq_bg, 1.0, 1.0) - .font_size(8) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(8)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.slotq_text, ui); }; @@ -961,14 +963,14 @@ impl<'a> Widget for Skillbar<'a> { ); Text::new(&hp_text) .mid_top_with_margin_on(state.ids.healthbar_bg, 6.0 * scale) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.health_text_bg, ui); Text::new(&hp_text) .bottom_left_with_margins_on(state.ids.health_text_bg, 2.0, 2.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.health_text, ui); let energy_text = format!( @@ -979,14 +981,14 @@ impl<'a> Widget for Skillbar<'a> { ); Text::new(&energy_text) .mid_top_with_margin_on(state.ids.energybar_bg, 6.0 * scale) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.energy_text_bg, ui); Text::new(&energy_text) .bottom_left_with_margins_on(state.ids.energy_text_bg, 2.0, 2.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.energy_text, ui); } @@ -995,27 +997,27 @@ impl<'a> Widget for Skillbar<'a> { let hp_text = format!("{}%", hp_percentage as u32); Text::new(&hp_text) .mid_top_with_margin_on(state.ids.healthbar_bg, 6.0 * scale) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.health_text_bg, ui); Text::new(&hp_text) .bottom_left_with_margins_on(state.ids.health_text_bg, 2.0, 2.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.health_text, ui); let energy_text = format!("{}%", energy_percentage as u32); Text::new(&energy_text) .mid_top_with_margin_on(state.ids.energybar_bg, 6.0 * scale) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(Color::Rgba(0.0, 0.0, 0.0, 1.0)) .set(state.ids.energy_text_bg, ui); Text::new(&energy_text) .bottom_left_with_margins_on(state.ids.energy_text_bg, 2.0, 2.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(state.ids.energy_text, ui); } diff --git a/voxygen/src/hud/social.rs b/voxygen/src/hud/social.rs index 641172b128..fb57e8523e 100644 --- a/voxygen/src/hud/social.rs +++ b/voxygen/src/hud/social.rs @@ -1,6 +1,6 @@ -use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR, TEXT_COLOR_3}; +use super::{img_ids::Imgs, Show, TEXT_COLOR, TEXT_COLOR_3}; -use crate::i18n::VoxygenLocalization; +use crate::{i18n::VoxygenLocalization, ui::fonts::ConrodVoxygenFonts}; use client::{self, Client}; use conrod_core::{ color, @@ -39,7 +39,7 @@ pub struct Social<'a> { show: &'a Show, client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, #[conrod(common_builder)] @@ -51,7 +51,7 @@ impl<'a> Social<'a> { show: &'a Show, client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { @@ -115,8 +115,8 @@ impl<'a> Widget for Social<'a> { // Title Text::new(&self.localized_strings.get("hud.social")) .mid_top_with_margin_on(ids.social_frame, 6.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .color(TEXT_COLOR) .set(ids.social_title, ui); @@ -160,7 +160,8 @@ impl<'a> Widget for Social<'a> { }) .top_left_with_margins_on(ids.align, 4.0, 0.0) .label(&self.localized_strings.get("hud.social.online")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .parent(ids.frame) .label_color(TEXT_COLOR) .set(ids.online_tab, ui) @@ -191,15 +192,15 @@ impl<'a> Widget for Social<'a> { .replace("{nb_player}", &format!("{:?}", count)), ) .top_left_with_margins_on(ids.content_align, -2.0, 7.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(ids.online_title, ui); for (i, (_, player_alias)) in self.client.player_list.iter().enumerate() { Text::new(player_alias) .down(3.0) - .font_size(15) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(15)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(ids.player_names[i], ui); } @@ -225,7 +226,8 @@ impl<'a> Widget for Social<'a> { }) .right_from(ids.online_tab, 0.0) .label(&self.localized_strings.get("hud.social.friends")) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .parent(ids.frame) .label_color(TEXT_COLOR_3) .set(ids.friends_tab, ui) @@ -239,8 +241,8 @@ impl<'a> Widget for Social<'a> { if let SocialTab::Friends = self.show.social_tab { Text::new(&self.localized_strings.get("hud.social.not_yet_available")) .middle_of(ids.content_align) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR_3) .set(ids.friends_test, ui); } @@ -256,7 +258,8 @@ impl<'a> Widget for Social<'a> { .right_from(ids.friends_tab, 0.0) .label(&self.localized_strings.get("hud.social.faction")) .parent(ids.frame) - .label_font_size(14) + .label_font_size(self.fonts.cyri.scale(14)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR_3) .set(ids.faction_tab, ui) .was_clicked() @@ -269,8 +272,8 @@ impl<'a> Widget for Social<'a> { if let SocialTab::Faction = self.show.social_tab { Text::new(&self.localized_strings.get("hud.social.not_yet_available")) .middle_of(ids.content_align) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(18)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR_3) .set(ids.faction_test, ui); } diff --git a/voxygen/src/hud/spell.rs b/voxygen/src/hud/spell.rs index 24aa2d55ff..ca49c4b30c 100644 --- a/voxygen/src/hud/spell.rs +++ b/voxygen/src/hud/spell.rs @@ -1,4 +1,5 @@ -use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR}; +use super::{img_ids::Imgs, Show, TEXT_COLOR}; +use crate::ui::fonts::ConrodVoxygenFonts; use conrod_core::{ color, widget::{self, Button, Image, Rectangle, Text}, @@ -25,7 +26,7 @@ pub struct Spell<'a> { _client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, #[conrod(common_builder)] @@ -37,7 +38,7 @@ impl<'a> Spell<'a> { show: &'a Show, _client: &'a Client, imgs: &'a Imgs, - fonts: &'a Fonts, + fonts: &'a ConrodVoxygenFonts, localized_strings: &'a std::sync::Arc, ) -> Self { Self { @@ -101,8 +102,8 @@ impl<'a> Widget for Spell<'a> { // TODO: Use an actual character name. Text::new(&self.localized_strings.get("hud.spell")) .mid_top_with_margin_on(state.spell_frame, 6.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .color(TEXT_COLOR) .set(state.spell_title, ui); diff --git a/voxygen/src/i18n.rs b/voxygen/src/i18n.rs index 9d1e637067..3b8064a849 100644 --- a/voxygen/src/i18n.rs +++ b/voxygen/src/i18n.rs @@ -30,10 +30,26 @@ pub struct LanguageMetadata { pub language_identifier: String, } +/// Store font metadata +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct Font { + /// Key to retrieve the font in the asset system + pub asset_key: String, + + /// Scale ratio to resize the UI text dynamicly + pub scale_ratio: f32, +} + +impl Font { + /// Scale input size to final UI size + pub fn scale(&self, value: u32) -> u32 { (value as f32 * self.scale_ratio).round() as u32 } +} + +/// Store font metadata +pub type VoxygenFonts = HashMap; + /// Store internationalization data -/// -/// TODO: store the font locations here (Font asset path for instance) -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct VoxygenLocalization { /// A map storing the localized texts /// @@ -44,6 +60,9 @@ pub struct VoxygenLocalization { /// into a ASCII version by using the `deunicode` crate. pub convert_utf8_to_ascii: bool, + /// Font configuration is stored here + pub fonts: VoxygenFonts, + pub metadata: LanguageMetadata, } diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index f3fad20a8b..301aab5d19 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -1,3 +1,6 @@ /// Used by benchmarks pub mod mesh; pub mod render; + +// Used by tests +pub mod i18n; diff --git a/voxygen/src/menu/char_selection/ui.rs b/voxygen/src/menu/char_selection/ui.rs index 22ec50d31b..41e0db473a 100644 --- a/voxygen/src/menu/char_selection/ui.rs +++ b/voxygen/src/menu/char_selection/ui.rs @@ -3,6 +3,7 @@ use crate::{ meta::CharacterData, render::{Consts, Globals, Renderer}, ui::{ + fonts::ConrodVoxygenFonts, img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelSs9Graphic}, ImageFrame, ImageSlider, Tooltip, Tooltipable, Ui, }, @@ -21,6 +22,7 @@ use conrod_core::{ widget::{text_box::Event as TextBoxEvent, Button, Image, Rectangle, Scrollbar, Text, TextBox}, widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, UiCell, Widget, }; + const STARTER_HAMMER: &str = "common.items.weapons.starter_hammer"; const STARTER_BOW: &str = "common.items.weapons.starter_bow"; const STARTER_AXE: &str = "common.items.weapons.starter_axe"; @@ -227,16 +229,6 @@ rotation_image_ids! { } } -font_ids! { - pub struct Fonts { - opensans: "voxygen.font.OpenSans-Regular", - metamorph: "voxygen.font.Metamorphous-Regular", - alkhemi: "voxygen.font.Alkhemikal", - cyri:"voxygen.font.haxrcorp_4089_cyrillic_altgr", - wizard: "voxygen.font.wizard", - } -} - pub enum Event { Logout, Play, @@ -265,10 +257,10 @@ pub struct CharSelectionUi { ids: Ids, imgs: Imgs, rot_imgs: ImgsRot, - fonts: Fonts, + fonts: ConrodVoxygenFonts, //character_creation: bool, info_content: InfoContent, - selected_language: String, + voxygen_i18n: std::sync::Arc, //deletion_confirmation: bool, /* pub character_name: String, @@ -290,8 +282,13 @@ impl CharSelectionUi { // Load images let imgs = Imgs::load(&mut ui).expect("Failed to load images!"); let rot_imgs = ImgsRot::load(&mut ui).expect("Failed to load images!"); - // Load fonts - let fonts = Fonts::load(&mut ui).expect("Failed to load fonts!"); + // Load language + let voxygen_i18n = load_expect::(&i18n_asset_key( + &global_state.settings.language.selected_language, + )); + // Load fonts. + let fonts = ConrodVoxygenFonts::load(&voxygen_i18n.fonts, &mut ui) + .expect("Impossible to load fonts!"); // TODO: Randomize initial values. Self { @@ -301,7 +298,7 @@ impl CharSelectionUi { rot_imgs, fonts, info_content: InfoContent::None, - selected_language: global_state.settings.language.selected_language.clone(), + voxygen_i18n, //deletion_confirmation: false, /* character_creation: false, @@ -334,8 +331,6 @@ impl CharSelectionUi { env!("CARGO_PKG_VERSION"), common::util::GIT_VERSION.to_string() ); - let localized_strings = - load_expect::(&i18n_asset_key(&self.selected_language)); // Tooltip let tooltip_human = Tooltip::new({ @@ -350,9 +345,9 @@ impl CharSelectionUi { 5.0, ) }) - .title_font_size(15) - .desc_font_size(10) - .font_id(self.fonts.cyri) + .title_font_size(self.fonts.cyri.scale(15)) + .desc_font_size(self.fonts.cyri.scale(10)) + .font_id(self.fonts.cyri.conrod_id) .title_text_color(TEXT_COLOR) .desc_text_color(TEXT_COLOR_2); @@ -372,10 +367,10 @@ impl CharSelectionUi { match self.info_content { InfoContent::None => unreachable!(), InfoContent::Deletion(character_index) => { - Text::new(&localized_strings.get("char_selection.delete_permanently")) + Text::new(&self.voxygen_i18n.get("char_selection.delete_permanently")) .mid_top_with_margin_on(self.ids.info_frame, 40.0) - .font_size(24) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(24)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.delete_text, ui_widgets); if Button::image(self.imgs.button) @@ -384,9 +379,9 @@ impl CharSelectionUi { .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) - .label(&localized_strings.get("common.no")) - .label_font_id(self.fonts.cyri) - .label_font_size(18) + .label(&self.voxygen_i18n.get("common.no")) + .label_font_id(self.fonts.cyri.conrod_id) + .label_font_size(self.fonts.cyri.scale(18)) .label_color(TEXT_COLOR) .set(self.ids.info_no, ui_widgets) .was_clicked() @@ -399,9 +394,9 @@ impl CharSelectionUi { .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) - .label(&localized_strings.get("common.yes")) - .label_font_id(self.fonts.cyri) - .label_font_size(18) + .label(&self.voxygen_i18n.get("common.yes")) + .label_font_id(self.fonts.cyri.conrod_id) + .label_font_size(self.fonts.cyri.scale(18)) .label_color(TEXT_COLOR) .set(self.ids.info_ok, ui_widgets) .was_clicked() @@ -456,8 +451,8 @@ impl CharSelectionUi { // Server Name Text::new(&client.server_info.name) .mid_top_with_margin_on(self.ids.server_frame_bg, 5.0) - .font_size(26) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(26)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.server_name_text, ui_widgets); //Change Server @@ -467,10 +462,10 @@ impl CharSelectionUi { .parent(self.ids.charlist_bg) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("char_selection.change_server")) + .label(&self.voxygen_i18n.get("char_selection.change_server")) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) - .label_font_size(18) + .label_font_id(self.fonts.cyri.conrod_id) + .label_font_size(self.fonts.cyri.scale(18)) .label_y(conrod_core::position::Relative::Scalar(3.0)) .set(self.ids.change_server, ui_widgets) .was_clicked() @@ -480,13 +475,13 @@ impl CharSelectionUi { // Enter World Button let character_count = global_state.meta.characters.len(); - let enter_world_str = &localized_strings.get("char_selection.enter_world"); + let enter_world_str = &self.voxygen_i18n.get("char_selection.enter_world"); let enter_button = Button::image(self.imgs.button) .mid_bottom_with_margin_on(ui_widgets.window, 10.0) .w_h(250.0, 60.0) .label(enter_world_str) - .label_font_size(26) - .label_font_id(self.fonts.cyri) + .label_font_size(self.fonts.cyri.scale(26)) + .label_font_id(self.fonts.cyri.conrod_id) .label_y(conrod_core::position::Relative::Scalar(3.0)); if match &self.mode { @@ -514,10 +509,10 @@ impl CharSelectionUi { .w_h(150.0, 40.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("char_selection.logout")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("char_selection.logout")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(conrod_core::position::Relative::Scalar(3.0)) .set(self.ids.logout_button, ui_widgets) .was_clicked() @@ -528,8 +523,8 @@ impl CharSelectionUi { // Alpha Version Text::new(&version) .top_right_with_margins_on(ui_widgets.window, 5.0, 5.0) - .font_size(14) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.version, ui_widgets); @@ -572,7 +567,7 @@ impl CharSelectionUi { .image_color(Color::Rgba(1.0, 1.0, 1.0, 0.8)) .hover_image(self.imgs.selection_hover) .press_image(self.imgs.selection_press) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .label_y(conrod_core::position::Relative::Scalar(20.0)) .set(self.ids.character_boxes[i], ui_widgets) .was_clicked() @@ -586,7 +581,7 @@ impl CharSelectionUi { .press_image(self.imgs.delete_button_press) .with_tooltip( tooltip_manager, - &localized_strings.get("char_selection.delete_permanently"), + &self.voxygen_i18n.get("char_selection.delete_permanently"), "", &tooltip_human, ) @@ -597,26 +592,27 @@ impl CharSelectionUi { } Text::new(&character.name) .top_left_with_margins_on(self.ids.character_boxes[i], 6.0, 9.0) - .font_size(19) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(19)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.character_names[i], ui_widgets); Text::new( - &localized_strings + &self + .voxygen_i18n .get("char_selection.level_fmt") .replace("{level_nb}", "1"), ) //TODO Insert real level here as soon as they get saved .down_from(self.ids.character_names[i], 4.0) - .font_size(17) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(17)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.character_levels[i], ui_widgets); - Text::new(&localized_strings.get("char_selection.uncanny_valley")) + Text::new(&self.voxygen_i18n.get("char_selection.uncanny_valley")) .down_from(self.ids.character_levels[i], 4.0) - .font_size(17) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(17)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.character_locations[i], ui_widgets); } @@ -637,9 +633,9 @@ impl CharSelectionUi { .w_h(386.0, 80.0) .hover_image(self.imgs.selection_hover) .press_image(self.imgs.selection_press) - .label(&localized_strings.get("char_selection.create_new_charater")) + .label(&self.voxygen_i18n.get("char_selection.create_new_charater")) .label_color(Color::Rgba(0.38, 1.0, 0.07, 1.0)) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .image_color(Color::Rgba(0.38, 1.0, 0.07, 1.0)) .set(self.ids.character_box_2, ui_widgets) .was_clicked() @@ -661,10 +657,10 @@ impl CharSelectionUi { .w_h(150.0, 40.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("common.back")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.back")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(conrod_core::position::Relative::Scalar(3.0)) .set(self.ids.back_button, ui_widgets) .was_clicked() @@ -677,10 +673,10 @@ impl CharSelectionUi { .w_h(150.0, 40.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("common.create")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.create")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(conrod_core::position::Relative::Scalar(3.0)) .set(self.ids.create_button, ui_widgets) .was_clicked() @@ -705,11 +701,11 @@ impl CharSelectionUi { for event in TextBox::new(name) .w_h(300.0, 60.0) .mid_top_with_margin_on(self.ids.name_input, 2.0) - .font_size(26) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(26)) + .font_id(self.fonts.cyri.conrod_id) .center_justify() .text_color(TEXT_COLOR) - .font_id(self.fonts.cyri) + .font_id(self.fonts.cyri.conrod_id) .color(TRANSPARENT) .border_color(TRANSPARENT) .set(self.ids.name_field, ui_widgets) @@ -745,10 +741,10 @@ impl CharSelectionUi { .set(self.ids.selection_scrollbar, ui_widgets); // Male/Female/Race Icons - Text::new(&localized_strings.get("char_selection.character_creation")) + Text::new(&self.voxygen_i18n.get("char_selection.character_creation")) .mid_top_with_margin_on(self.ids.creation_alignment, 10.0) - .font_size(24) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(24)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.bodyrace_text, ui_widgets); // Alignment @@ -833,7 +829,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.human"), + &self.voxygen_i18n.get("common.races.human"), "", &tooltip_human, ) @@ -866,7 +862,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.orc"), + &self.voxygen_i18n.get("common.races.orc"), "", &tooltip_human, ) @@ -891,7 +887,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.dwarf"), + &self.voxygen_i18n.get("common.races.dwarf"), "", &tooltip_human, ) @@ -916,7 +912,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.elf"), + &self.voxygen_i18n.get("common.races.elf"), "", &tooltip_human, ) @@ -942,7 +938,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.undead"), + &self.voxygen_i18n.get("common.races.undead"), "", &tooltip_human, ) @@ -967,7 +963,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.races.danari"), + &self.voxygen_i18n.get("common.races.danari"), "", &tooltip_human, ) @@ -993,7 +989,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.weapons.hammer"), + &self.voxygen_i18n.get("common.weapons.hammer"), "", &tooltip_human, ) @@ -1022,7 +1018,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.weapons.bow"), + &self.voxygen_i18n.get("common.weapons.bow"), "", &tooltip_human, ) @@ -1050,7 +1046,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.weapons.staff"), + &self.voxygen_i18n.get("common.weapons.staff"), "", &tooltip_human, ) @@ -1078,7 +1074,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.weapons.sword"), + &self.voxygen_i18n.get("common.weapons.sword"), "", &tooltip_human, ) @@ -1126,7 +1122,7 @@ impl CharSelectionUi { .press_image(self.imgs.icon_border_press) .with_tooltip( tooltip_manager, - &localized_strings.get("common.weapons.axe"), + &self.voxygen_i18n.get("common.weapons.axe"), "", &tooltip_human, ) @@ -1136,8 +1132,9 @@ impl CharSelectionUi { *tool = Some(STARTER_AXE); } // Sliders - let (metamorph, slider_indicator, slider_range) = ( - self.fonts.cyri, + let (cyri, cyri_size, slider_indicator, slider_range) = ( + self.fonts.cyri.conrod_id, + self.fonts.cyri.scale(18), self.imgs.slider_indicator, self.imgs.slider_range, ); @@ -1151,8 +1148,8 @@ impl CharSelectionUi { Text::new(text) .down_from(prev_id, 22.0) .align_middle_x_of(prev_id) - .font_size(18) - .font_id(metamorph) + .font_size(cyri_size) + .font_id(cyri) .color(TEXT_COLOR) .set(text_id, ui_widgets); ImageSlider::discrete(selected_val, 0, max, slider_indicator, slider_range) @@ -1167,7 +1164,7 @@ impl CharSelectionUi { // Hair Style if let Some(new_val) = char_slider( self.ids.creation_buttons_alignment_2, - localized_strings.get("char_selection.hair_style"), + self.voxygen_i18n.get("char_selection.hair_style"), self.ids.hairstyle_text, body.race.num_hair_styles(body.body_type) as usize - 1, body.hair_style as usize, @@ -1179,7 +1176,7 @@ impl CharSelectionUi { // Hair Color if let Some(new_val) = char_slider( self.ids.hairstyle_slider, - localized_strings.get("char_selection.hair_color"), + self.voxygen_i18n.get("char_selection.hair_color"), self.ids.haircolor_text, body.race.num_hair_colors() as usize - 1, body.hair_color as usize, @@ -1191,7 +1188,7 @@ impl CharSelectionUi { // Skin if let Some(new_val) = char_slider( self.ids.haircolor_slider, - localized_strings.get("char_selection.skin"), + self.voxygen_i18n.get("char_selection.skin"), self.ids.skin_text, body.race.num_skin_colors() as usize - 1, body.skin as usize, @@ -1204,7 +1201,7 @@ impl CharSelectionUi { let current_eyebrows = body.eyebrows; if let Some(new_val) = char_slider( self.ids.skin_slider, - localized_strings.get("char_selection.eyebrows"), + self.voxygen_i18n.get("char_selection.eyebrows"), self.ids.eyebrows_text, humanoid::ALL_EYEBROWS.len() - 1, humanoid::ALL_EYEBROWS @@ -1219,7 +1216,7 @@ impl CharSelectionUi { // EyeColor if let Some(new_val) = char_slider( self.ids.eyebrows_slider, - localized_strings.get("char_selection.eye_color"), + self.voxygen_i18n.get("char_selection.eye_color"), self.ids.eyecolor_text, body.race.num_eye_colors() as usize - 1, body.eye_color as usize, @@ -1232,7 +1229,7 @@ impl CharSelectionUi { let _current_accessory = body.accessory; if let Some(new_val) = char_slider( self.ids.eyecolor_slider, - localized_strings.get("char_selection.accessories"), + self.voxygen_i18n.get("char_selection.accessories"), self.ids.accessories_text, body.race.num_accessories(body.body_type) as usize - 1, body.accessory as usize, @@ -1245,7 +1242,7 @@ impl CharSelectionUi { if body.race.num_beards(body.body_type) > 1 { if let Some(new_val) = char_slider( self.ids.accessories_slider, - localized_strings.get("char_selection.beard"), + self.voxygen_i18n.get("char_selection.beard"), self.ids.beard_text, body.race.num_beards(body.body_type) as usize - 1, body.beard as usize, @@ -1255,10 +1252,10 @@ impl CharSelectionUi { body.beard = new_val as u8; } } else { - Text::new(&localized_strings.get("char_selection.beard")) + Text::new(&self.voxygen_i18n.get("char_selection.beard")) .mid_bottom_with_margin_on(self.ids.accessories_slider, -40.0) - .font_size(18) - .font_id(self.fonts.cyri) + .font_size(self.fonts.metamorph.scale(18)) + .font_id(self.fonts.metamorph.conrod_id) .color(TEXT_COLOR_2) .set(self.ids.beard_text, ui_widgets); ImageSlider::discrete(5, 0, 10, self.imgs.nothing, self.imgs.slider_range) @@ -1275,7 +1272,7 @@ impl CharSelectionUi { let current_chest = body.chest; if let Some(new_val) = char_slider( self.ids.beard_slider, - localized_strings.get("char_selection.chest_color"), + self.voxygen_i18n.get("char_selection.chest_color"), self.ids.chest_text, humanoid::ALL_CHESTS.len() - 1, humanoid::ALL_CHESTS diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index 3273c9bb96..e6f45122f5 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -3,6 +3,7 @@ use crate::{ render::Renderer, ui::{ self, + fonts::ConrodVoxygenFonts, img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic}, Graphic, ImageFrame, Tooltip, Ui, }, @@ -103,16 +104,6 @@ rotation_image_ids! { } } -font_ids! { - pub struct Fonts { - opensans: "voxygen.font.OpenSans-Regular", - metamorph: "voxygen.font.Metamorphous-Regular", - alkhemi: "voxygen.font.Alkhemikal", - cyri:"voxygen.font.haxrcorp_4089_cyrillic_altgr", - wizard: "voxygen.font.wizard", - } -} - pub enum Event { LoginAttempt { username: String, @@ -143,7 +134,6 @@ pub struct MainMenuUi { ids: Ids, imgs: Imgs, rot_imgs: ImgsRot, - fonts: Fonts, username: String, password: String, server_address: String, @@ -154,6 +144,8 @@ pub struct MainMenuUi { show_disclaimer: bool, time: f32, bg_img_id: conrod_core::image::Id, + voxygen_i18n: std::sync::Arc, + fonts: ConrodVoxygenFonts, } impl MainMenuUi { @@ -184,15 +176,19 @@ impl MainMenuUi { let bg_img_id = ui.add_graphic(Graphic::Image(load_expect( bg_imgs.choose(&mut rng).unwrap(), ))); - // Load fonts - let fonts = Fonts::load(&mut ui).expect("Failed to load fonts"); + // Load language + let voxygen_i18n = load_expect::(&i18n_asset_key( + &global_state.settings.language.selected_language, + )); + // Load fonts. + let fonts = ConrodVoxygenFonts::load(&voxygen_i18n.fonts, &mut ui) + .expect("Impossible to load fonts!"); Self { ui, ids, imgs, rot_imgs, - fonts, username: networking.username.clone(), password: "".to_owned(), server_address: networking.servers[networking.default_server].clone(), @@ -203,6 +199,8 @@ impl MainMenuUi { time: 0.0, show_disclaimer: global_state.settings.show_disclaimer, bg_img_id, + voxygen_i18n, + fonts, } } @@ -220,10 +218,7 @@ impl MainMenuUi { const TEXT_COLOR_2: Color = Color::Rgba(1.0, 1.0, 1.0, 0.2); //const INACTIVE: Color = Color::Rgba(0.47, 0.47, 0.47, 0.47); - let localized_strings = load_expect::(&i18n_asset_key( - &global_state.settings.language.selected_language, - )); - let intro_text = &localized_strings.get("main.login_process"); + let intro_text = &self.voxygen_i18n.get("main.login_process"); // Tooltip let _tooltip = Tooltip::new({ @@ -238,8 +233,9 @@ impl MainMenuUi { 5.0, ) }) - .title_font_size(15) - .desc_font_size(10) + .title_font_size(self.fonts.cyri.scale(15)) + .desc_font_size(self.fonts.cyri.scale(10)) + .font_id(self.fonts.cyri.conrod_id) .title_text_color(TEXT_COLOR) .desc_text_color(TEXT_COLOR_2); @@ -256,14 +252,14 @@ impl MainMenuUi { Text::new(&version) .color(TEXT_COLOR) .top_right_with_margins_on(ui_widgets.window, 5.0, 5.0) - .font_id(self.fonts.cyri) - .font_size(14) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(14)) .set(self.ids.version, ui_widgets); // Popup (Error/Info) if let Some(popup_data) = &self.popup { let text = Text::new(&popup_data.msg) .rgba(1.0, 1.0, 1.0, if self.connect { fade_msg } else { 1.0 }) - .font_id(self.fonts.cyri); + .font_id(self.fonts.cyri.conrod_id); Rectangle::fill_with([65.0 * 6.0, 140.0], color::TRANSPARENT) .rgba(0.1, 0.1, 0.1, if self.connect { 0.0 } else { 1.0 }) .parent(ui_widgets.window) @@ -281,14 +277,14 @@ impl MainMenuUi { .set(self.ids.error_frame, ui_widgets); if self.connect { text.mid_top_with_margin_on(self.ids.error_frame, 10.0) - .font_id(self.fonts.alkhemi) + .font_id(self.fonts.alkhemi.conrod_id) .bottom_left_with_margins_on(ui_widgets.window, 60.0, 60.0) - .font_size(70) + .font_size(self.fonts.cyri.scale(70)) .set(self.ids.login_error, ui_widgets); } else { text.mid_top_with_margin_on(self.ids.error_frame, 10.0) - .font_id(self.fonts.cyri) - .font_size(25) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(25)) .set(self.ids.login_error, ui_widgets); }; if Button::image(self.imgs.button) @@ -305,8 +301,8 @@ impl MainMenuUi { .press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) .label(&popup_data.button_text) - .label_font_id(self.fonts.cyri) - .label_font_size(15) + .label_font_id(self.fonts.cyri.conrod_id) + .label_font_size(self.fonts.cyri.scale(15)) .label_color(TEXT_COLOR) .set(self.ids.button_ok, ui_widgets) .was_clicked() @@ -347,16 +343,16 @@ impl MainMenuUi { .scroll_kids_vertically() .set(self.ids.disc_window, ui_widgets); - Text::new(&localized_strings.get("common.disclaimer")) + Text::new(&self.voxygen_i18n.get("common.disclaimer")) .top_left_with_margins_on(self.ids.disc_window, 30.0, 40.0) - .font_size(35) - .font_id(self.fonts.alkhemi) + .font_size(self.fonts.cyri.scale(35)) + .font_id(self.fonts.alkhemi.conrod_id) .color(TEXT_COLOR) .set(self.ids.disc_text_1, ui_widgets); - Text::new(&localized_strings.get("main.notice")) + Text::new(&self.voxygen_i18n.get("main.notice")) .top_left_with_margins_on(self.ids.disc_window, 110.0, 40.0) - .font_size(26) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(26)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.disc_text_2, ui_widgets); if Button::image(self.imgs.button) @@ -366,9 +362,9 @@ impl MainMenuUi { .press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) .label("Accept") - .label_font_size(22) + .label_font_size(self.fonts.cyri.scale(22)) .label_color(TEXT_COLOR) - .label_font_id(self.fonts.cyri) + .label_font_id(self.fonts.cyri.conrod_id) .set(self.ids.disc_button, ui_widgets) .was_clicked() { @@ -384,8 +380,8 @@ impl MainMenuUi { self.connect = true; self.connecting = Some(std::time::Instant::now()); self.popup = Some(PopupData { - msg: [localized_strings.get("main.connecting"), "..."].concat(), - button_text: localized_strings.get("common.cancel").to_owned(), + msg: [self.voxygen_i18n.get("main.connecting"), "..."].concat(), + button_text: self.voxygen_i18n.get("common.cancel").to_owned(), popup_type: PopupType::ConnectionInfo, }); @@ -408,8 +404,8 @@ impl MainMenuUi { .set(self.ids.info_bottom, ui_widgets); Text::new(intro_text) .top_left_with_margins_on(self.ids.info_frame, 15.0, 15.0) - .font_size(20) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(20)) + .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) .set(self.ids.info_text, ui_widgets); @@ -422,8 +418,8 @@ impl MainMenuUi { self.connect = true; self.connecting = Some(std::time::Instant::now()); self.popup = Some(PopupData { - msg: [localized_strings.get("main.creating_world"), "..."].concat(), - button_text: localized_strings.get("common.cancel").to_owned(), + msg: [self.voxygen_i18n.get("main.creating_world"), "..."].concat(), + button_text: self.voxygen_i18n.get("common.cancel").to_owned(), popup_type: PopupType::ConnectionInfo, }); }; @@ -440,8 +436,8 @@ impl MainMenuUi { for event in TextBox::new(&self.username) .w_h(290.0, 30.0) .mid_bottom_with_margin_on(self.ids.username_bg, 44.0 / 2.0) - .font_size(22) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(22)) + .font_id(self.fonts.cyri.conrod_id) .text_color(TEXT_COLOR) // transparent background .color(TRANSPARENT) @@ -471,8 +467,8 @@ impl MainMenuUi { for event in TextBox::new(&self.password) .w_h(290.0, 30.0) .mid_bottom_with_margin_on(self.ids.password_bg, 44.0 / 2.0) - .font_size(22) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(22)) + .font_id(self.fonts.cyri.conrod_id) .text_color(TEXT_COLOR) // transparent background .color(TRANSPARENT) @@ -524,8 +520,8 @@ impl MainMenuUi { //.press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) .label(&text) - .label_font_size(20) - .label_font_id(self.fonts.cyri) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR), ui_widgets, ) @@ -542,9 +538,9 @@ impl MainMenuUi { .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) .label_y(Relative::Scalar(2.0)) - .label(&localized_strings.get("common.close")) - .label_font_size(20) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.close")) + .label_font_size(self.fonts.cyri.scale(20)) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) .set(self.ids.servers_close, ui_widgets) .was_clicked() @@ -563,8 +559,8 @@ impl MainMenuUi { for event in TextBox::new(&self.server_address) .w_h(290.0, 30.0) .mid_bottom_with_margin_on(self.ids.address_bg, 44.0 / 2.0) - .font_size(22) - .font_id(self.fonts.cyri) + .font_size(self.fonts.cyri.scale(22)) + .font_id(self.fonts.cyri.conrod_id) .text_color(TEXT_COLOR) // transparent background .color(TRANSPARENT) @@ -587,10 +583,10 @@ impl MainMenuUi { .w_h(258.0, 55.0) .down_from(self.ids.address_bg, 20.0) .align_middle_x_of(self.ids.address_bg) - .label(&localized_strings.get("common.multiplayer")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.multiplayer")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(22) + .label_font_size(self.fonts.cyri.scale(22)) .label_y(Relative::Scalar(5.0)) /*.with_tooltip( tooltip_manager, @@ -614,10 +610,10 @@ impl MainMenuUi { .w_h(258.0, 55.0) .down_from(self.ids.login_button, 20.0) .align_middle_x_of(self.ids.address_bg) - .label(&localized_strings.get("common.singleplayer")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.singleplayer")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(22) + .label_font_size(self.fonts.cyri.scale(22)) .label_y(Relative::Scalar(5.0)) .label_x(Relative::Scalar(2.0)) .set(self.ids.singleplayer_button, ui_widgets) @@ -632,10 +628,10 @@ impl MainMenuUi { .bottom_left_with_margins_on(ui_widgets.window, 60.0, 30.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("common.quit")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.quit")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(Relative::Scalar(3.0)) .set(self.ids.quit_button, ui_widgets) .was_clicked() @@ -649,10 +645,10 @@ impl MainMenuUi { .up_from(self.ids.quit_button, 8.0) //.hover_image(self.imgs.button_hover) //.press_image(self.imgs.button_press) - .label(&localized_strings.get("common.settings")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.settings")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR_2) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(Relative::Scalar(3.0)) .set(self.ids.settings_button, ui_widgets) .was_clicked() @@ -666,10 +662,10 @@ impl MainMenuUi { .up_from(self.ids.settings_button, 8.0) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .label(&localized_strings.get("common.servers")) - .label_font_id(self.fonts.cyri) + .label(&self.voxygen_i18n.get("common.servers")) + .label_font_id(self.fonts.cyri.conrod_id) .label_color(TEXT_COLOR) - .label_font_size(20) + .label_font_size(self.fonts.cyri.scale(20)) .label_y(Relative::Scalar(3.0)) .set(self.ids.servers_button, ui_widgets) .was_clicked() diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 437784d197..8dfc6595c8 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -590,6 +590,7 @@ impl PlayState for SessionState { ) .unwrap(); localized_strings.log_missing_entries(); + self.hud.update_language(localized_strings.clone()); }, HudEvent::ToggleFullscreen => { global_state diff --git a/voxygen/src/ui/font_ids.rs b/voxygen/src/ui/font_ids.rs deleted file mode 100644 index d6c8a92643..0000000000 --- a/voxygen/src/ui/font_ids.rs +++ /dev/null @@ -1,30 +0,0 @@ -/// This macro will automatically load all specified assets, get the -/// corresponding FontIds and create a struct with all of them. -/// -/// Example usage: -/// ``` -/// font_ids! { -/// pub struct Fonts { -/// font1: "filename1", -/// font2: "filename2", -/// } -/// } -/// ``` -#[macro_export] -macro_rules! font_ids { - ($($v:vis struct $Ids:ident { $( $name:ident: $specifier:expr $(,)? )* })*) => { - $( - $v struct $Ids { - $( $v $name: conrod_core::text::font::Id, )* - } - - impl $Ids { - pub fn load(ui: &mut crate::ui::Ui) -> Result { - Ok(Self { - $( $name: ui.new_font(common::assets::load($specifier)?), )* - }) - } - } - )* - }; -} diff --git a/voxygen/src/ui/fonts.rs b/voxygen/src/ui/fonts.rs new file mode 100644 index 0000000000..c42b9abf3a --- /dev/null +++ b/voxygen/src/ui/fonts.rs @@ -0,0 +1,40 @@ +use crate::i18n::{Font, VoxygenFonts}; + +pub struct ConrodVoxygenFont { + metadata: Font, + pub conrod_id: conrod_core::text::font::Id, +} + +impl ConrodVoxygenFont { + pub fn new(font: &Font, ui: &mut crate::ui::Ui) -> ConrodVoxygenFont { + return Self { + metadata: font.clone(), + conrod_id: ui.new_font(common::assets::load_expect(&font.asset_key)), + }; + } + + /// Scale input size to final UI size + pub fn scale(&self, value: u32) -> u32 { self.metadata.scale(value) } +} + +macro_rules! conrod_fonts { + ($([ $( $name:ident$(,)? )* ])*) => { + $( + pub struct ConrodVoxygenFonts { + $(pub $name: ConrodVoxygenFont,)* + } + + impl ConrodVoxygenFonts { + pub fn load(voxygen_fonts: &VoxygenFonts, ui: &mut crate::ui::Ui) -> Result { + Ok(Self { + $( $name: ConrodVoxygenFont::new(voxygen_fonts.get(stringify!($name)).unwrap(), ui),)* + }) + } + } + )* + }; +} + +conrod_fonts! { + [opensans, metamorph, alkhemi, cyri, wizard] +} diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index a384c77078..1016c2a134 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -6,7 +6,7 @@ mod widgets; #[macro_use] pub mod img_ids; #[macro_use] -mod font_ids; +pub mod fonts; pub use event::Event; pub use graphic::{Graphic, SampleStrat, Transform}; @@ -96,7 +96,7 @@ impl assets::Asset for Font { } pub struct Ui { - ui: conrod_core::Ui, + pub ui: conrod_core::Ui, image_map: Map<(graphic::Id, Rotation)>, cache: Cache, // Draw commands for the next render diff --git a/voxygen/tests/check_i18n_files.rs b/voxygen/tests/check_i18n_files.rs new file mode 100644 index 0000000000..2efe365826 --- /dev/null +++ b/voxygen/tests/check_i18n_files.rs @@ -0,0 +1,250 @@ +use git2::Repository; +use ron::de::from_bytes; +use std::{ + collections::{HashMap, HashSet}, + fs, + path::{Path, PathBuf}, +}; +use veloren_voxygen::i18n::VoxygenLocalization; + +/// List localization files as a PathBuf vector +fn i18n_files(i18n_dir: &Path) -> Vec { + fs::read_dir(i18n_dir) + .unwrap() + .map(|res| res.map(|e| e.path()).unwrap()) + .filter(|e| match e.extension() { + Some(ext) => ext == "ron", + None => false, + }) + .collect() +} + +#[derive(Debug, PartialEq)] +enum LocalizationState { + UpToDate, + NotFound, + Outdated, + Unknown, + Unused, +} + +#[derive(Debug)] +struct LocalizationEntryState { + pub key_line: Option, + pub chuck_line_range: Option<(usize, usize)>, + pub commit_id: Option, + pub state: LocalizationState, +} + +impl LocalizationEntryState { + pub fn new() -> LocalizationEntryState { + LocalizationEntryState { + key_line: None, + chuck_line_range: None, + commit_id: None, + state: LocalizationState::Unknown, + } + } +} + +/// Returns the Git blob associated with the given reference and path +fn read_file_from_path<'a>( + repo: &'a git2::Repository, + reference: &git2::Reference, + path: &std::path::Path, +) -> git2::Blob<'a> { + let tree = reference + .peel_to_tree() + .expect("Impossible to peel HEAD to a tree object"); + tree.get_path(path) + .expect(&format!( + "Impossible to find the file {:?} in reference {:?}", + path, + reference.name() + )) + .to_object(&repo) + .unwrap() + .peel_to_blob() + .expect("Impossible to fetch the Git object") +} + +fn generate_key_version<'a>( + repo: &'a git2::Repository, + localization: &VoxygenLocalization, + path: &std::path::Path, + file_blob: &git2::Blob, +) -> HashMap { + let mut keys: HashMap = localization + .string_map + .keys() + .map(|k| (k.to_owned(), LocalizationEntryState::new())) + .collect(); + let mut to_process: HashSet<&String> = localization.string_map.keys().map(|k| k).collect(); + let mut line_nb = 0; + + // Find key start lines + for line in std::str::from_utf8(file_blob.content()) + .expect("UTF-8 file") + .split('\n') + { + line_nb += 1; + + let mut found_key = None; + + for key in to_process.iter() { + if line.contains(key.as_str()) { + found_key = Some(key.to_owned()); + break; + } + } + + if let Some(key) = found_key { + keys.get_mut(key).unwrap().key_line = Some(line_nb); + to_process.remove(&key); + }; + } + + // Find commit for each keys + repo.blame_file(path, None) + .expect("Impossible to generate the Git blame") + .iter() + .for_each(|e: git2::BlameHunk| { + for state in keys.values_mut() { + let line = state.key_line.unwrap(); + + if line >= e.final_start_line() && line < e.final_start_line() + e.lines_in_hunk() { + state.chuck_line_range = Some(( + e.final_start_line(), + e.final_start_line() + e.lines_in_hunk(), + )); + state.commit_id = match state.commit_id { + Some(existing_commit) => { + match repo.graph_descendant_of(e.final_commit_id(), existing_commit) { + Ok(true) => Some(e.final_commit_id()), + Ok(false) => Some(existing_commit), + Err(err) => panic!(err), + } + }, + None => Some(e.final_commit_id()), + }; + } + } + }); + + keys +} + +#[test] +#[ignore] +fn test_all_localizations<'a>() { + // Generate paths + let i18n_asset_path = Path::new("assets/voxygen/i18n/"); + let en_i18n_path = i18n_asset_path.join("en.ron"); + let root_dir = std::env::current_dir() + .map(|p| p.parent().expect("").to_owned()) + .unwrap(); + let i18n_path = root_dir.join(i18n_asset_path); + + if !root_dir.join(&en_i18n_path).is_file() { + panic!("Reference language file not found {:?}", &en_i18n_path) + } + + // Initialize Git objects + let repo = Repository::discover(&root_dir).expect(&format!( + "Failed to open the Git repository at {:?}", + &root_dir + )); + let head_ref = repo.head().expect("Impossible to get the HEAD reference"); + + // Read HEAD for the reference language file + let i18n_en_blob = read_file_from_path(&repo, &head_ref, &en_i18n_path); + let loc: VoxygenLocalization = + from_bytes(i18n_en_blob.content()).expect("Expect to parse the RON file"); + let i18n_references: HashMap = + generate_key_version(&repo, &loc, &en_i18n_path, &i18n_en_blob); + + // Compare to other reference files + let i18n_files = i18n_files(&i18n_path); + for file in i18n_files { + let relfile = file.strip_prefix(&root_dir).unwrap(); + let mut uptodate_entries = 0; + if relfile == en_i18n_path { + continue; + } + println!("{:?}", relfile); + + // Find the localization entry state + let current_blob = read_file_from_path(&repo, &head_ref, &relfile); + let current_loc: VoxygenLocalization = + from_bytes(current_blob.content()).expect("Expect to parse the RON file"); + let mut current_i18n = generate_key_version(&repo, ¤t_loc, &relfile, ¤t_blob); + for (ref_key, ref_state) in i18n_references.iter() { + match current_i18n.get_mut(ref_key) { + Some(state) => { + let commit_id = state.commit_id.unwrap(); + let ref_commit_id = ref_state.commit_id.unwrap(); + if commit_id != ref_commit_id + && !repo + .graph_descendant_of(commit_id, ref_commit_id) + .unwrap_or(false) + { + state.state = LocalizationState::Outdated; + } else { + state.state = LocalizationState::UpToDate; + } + }, + None => { + current_i18n.insert(ref_key.to_owned(), LocalizationEntryState { + key_line: None, + chuck_line_range: None, + commit_id: None, + state: LocalizationState::NotFound, + }); + }, + } + } + + let ref_keys: HashSet<&String> = i18n_references.keys().collect(); + for (_, state) in current_i18n + .iter_mut() + .filter(|&(k, _)| !ref_keys.contains(k)) + { + state.state = LocalizationState::Unused; + } + + // Display + println!( + "{:10} {:60}{:40} {:40}", + "State", + "Key name", + relfile.to_str().unwrap(), + en_i18n_path.to_str().unwrap() + ); + + let mut sorted_keys: Vec<&String> = current_i18n.keys().collect(); + sorted_keys.sort(); + for key in sorted_keys { + let state = current_i18n.get(key).unwrap(); + if state.state != LocalizationState::UpToDate { + println!( + "[{:9}] {:60}{:40} {:40}", + format!("{:?}", state.state), + key, + state + .commit_id + .map(|s| format!("{}", s)) + .unwrap_or("None".to_string()), + i18n_references + .get(key) + .map(|s| s.commit_id) + .flatten() + .map(|s| format!("{}", s)) + .unwrap_or("None".to_string()), + ); + } else { + uptodate_entries += 1; + } + } + println!("{} entries are up-to-date\n", uptodate_entries); + } +}