Skip to content

Commit 6197923

Browse files
committed
Add separate font for Chinese language
Current English font "Friz" doesn't support Chinese which caused \ Chinese to not work in html5. System font fallback doesn't work in \ html5
1 parent 89ad818 commit 6197923

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ override.cfg
410410
# Fonts
411411
*.woff2
412412
*.otf
413+
*.ttf
413414

414415
# Audio
415416
*.mp3

Diff for: assets/fonts/NotoSansSC-Medium.ttf.import

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="font_data_dynamic"
4+
type="FontFile"
5+
uid="uid://b230565e8xtmg"
6+
path="res://.godot/imported/NotoSansSC-Medium.ttf-b9fc0864eb5f89a2c92385a10052b365.fontdata"
7+
8+
[deps]
9+
10+
source_file="res://assets/fonts/NotoSansSC-Medium.ttf"
11+
dest_files=["res://.godot/imported/NotoSansSC-Medium.ttf-b9fc0864eb5f89a2c92385a10052b365.fontdata"]
12+
13+
[params]
14+
15+
Rendering=null
16+
antialiasing=1
17+
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
19+
multichannel_signed_distance_field=false
20+
msdf_pixel_range=8
21+
msdf_size=48
22+
allow_system_fallback=true
23+
force_autohinter=false
24+
hinting=1
25+
subpixel_positioning=1
26+
oversampling=0.0
27+
Fallbacks=null
28+
fallbacks=[]
29+
Compress=null
30+
compress=true
31+
preload=[]
32+
language_support={}
33+
script_support={}
34+
opentype_features={}

Diff for: src/singletons/preloads.gd

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const ability_button_scene: PackedScene = preload("res://src/ui/buttons/ability_
3535
const inventory_slot_button_scene: PackedScene = preload("res://src/ui/buttons/inventory_slot_button.tscn")
3636
const mission_card: PackedScene = preload("res://src/ui/title_screen/missions_menu/mission_card.tscn")
3737
const mission_track_indicator_scene: PackedScene = preload("res://src/ui/hud/mission_track_indicator.tscn")
38+
const noto_sans_chinese_font: Font = preload("res://assets/fonts/NotoSansSC-Medium.ttf")
39+
const friz_font: Font = preload("res://assets/fonts/Friz Quadrata Std Medium.otf")
40+
41+
3842
const element_icons: Dictionary = {
3943
Element.enm.ICE: preload("res://resources/icons/elements/ice.tres"),
4044
Element.enm.NATURE: preload("res://resources/icons/elements/nature.tres"),

Diff for: src/singletons/settings.gd

+24
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,29 @@ func _ready():
117117

118118
_load_window_settings()
119119

120+
load_language_setting()
121+
122+
123+
# NOTE: need to switch fonts when switching languages
124+
# because the English "Friz" font doesn't support Chinese
125+
# characters. If we don't switch, then on desktop the game
126+
# will fallback to system font and Chinese will render ok.
127+
# On html5, system fonts are not available and Chinese
128+
# characters won't draw at all - that's why this step is
129+
# necessary.
130+
func load_language_setting():
120131
var selected_language: String = get_setting(Settings.LANGUAGE)
121132
TranslationServer.set_locale(selected_language)
133+
134+
var chinese_locale: String = Language.get_locale_from_enum(Language.enm.CHINESE)
135+
var font_for_selected_language: Font
136+
if selected_language == chinese_locale:
137+
font_for_selected_language = Preloads.noto_sans_chinese_font
138+
else:
139+
font_for_selected_language = Preloads.friz_font
140+
141+
var theme: Theme = preload("res://resources/theme/wc3_theme.tres")
142+
theme.default_font = font_for_selected_language
122143

123144

124145
#########################
@@ -145,6 +166,9 @@ func get_bool_setting(setting: String) -> bool:
145166

146167
func set_setting(setting: String, value: Variant):
147168
_cache[setting] = value
169+
170+
if setting == Settings.LANGUAGE:
171+
load_language_setting()
148172

149173

150174
# Save all changes to file

Diff for: src/ui/game_menu/settings_menu.gd

-1
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,4 @@ func _on_display_mode_combo_item_selected(index: int):
195195

196196
func _on_language_item_selected(index: int) -> void:
197197
var selected_locale: String = Language.get_locale_from_option(index)
198-
TranslationServer.set_locale(selected_locale)
199198
Settings.set_setting(Settings.LANGUAGE, selected_locale)

0 commit comments

Comments
 (0)