fix: enforce Chinese font for all UI controls

This commit is contained in:
2026-08-01 23:00:38 +08:00
parent 32bcaef4fa
commit 38df2541ae
4 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
extends Node
# Enforce a Chinese-capable font for every UI control, including controls
# constructed dynamically after their scene has loaded.
const UI_FONT: FontFile = preload("res://assets/fonts/msyh.ttc")
func _enter_tree() -> void:
get_tree().node_added.connect(_on_node_added)
_apply_font_recursively(get_tree().root)
func _exit_tree() -> void:
var node_added_callback := Callable(self, "_on_node_added")
if get_tree().node_added.is_connected(node_added_callback):
get_tree().node_added.disconnect(node_added_callback)
func _on_node_added(node: Node) -> void:
_apply_font_recursively(node)
func _apply_font_recursively(node: Node) -> void:
if node is Control:
var control := node as Control
control.add_theme_font_override(&"font", UI_FONT)
if control is RichTextLabel:
control.add_theme_font_override(&"normal_font", UI_FONT)
for child in node.get_children():
_apply_font_recursively(child)

View File

@@ -0,0 +1 @@
uid://cvb5smbfhqnfc

View File

@@ -8,7 +8,7 @@ dedicated_server=false
custom_features="" custom_features=""
export_filter="scenes" export_filter="scenes"
export_files=PackedStringArray("res://scenes/ui/WebBootstrap.tscn") export_files=PackedStringArray("res://scenes/ui/WebBootstrap.tscn")
include_filter="Config/*.gd,Config/*.json,_Core/*.gd,_Core/managers/*.gd,_Core/systems/*.gd,_Core/utils/*.gd,assets/audio/ui/*.wav" include_filter="Config/*.gd,Config/*.json,_Core/*.gd,_Core/managers/*.gd,_Core/systems/*.gd,_Core/utils/*.gd,assets/audio/ui/*.wav,assets/fonts/*.ttc"
exclude_filter="" exclude_filter=""
export_path="build/web/index.html" export_path="build/web/index.html"
patches=PackedStringArray() patches=PackedStringArray()

View File

@@ -21,6 +21,7 @@ config/icon="res://icon.svg"
[autoload] [autoload]
UIFontManager="*res://_Core/managers/UIFontManager.gd"
SceneManager="*res://_Core/managers/SceneManager.gd" SceneManager="*res://_Core/managers/SceneManager.gd"
EventSystem="*res://_Core/systems/EventSystem.gd" EventSystem="*res://_Core/systems/EventSystem.gd"
ApiClient="*res://_Core/managers/ApiClient.gd" ApiClient="*res://_Core/managers/ApiClient.gd"