aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/MapText.gd
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-04-24 20:24:56 +0200
committer hop311 <hop3114@gmail.com>2024-04-24 20:25:35 +0200
commit0fb9d5c8fb4771ef8001efdd8de1dc2dab4bb5dc (patch)
treee0ec540f15f1a543121cf2f3ea4f0d46cd2c8f6a /game/src/Game/GameSession/MapText.gd
parent7a1167259bc2a33aab8e91c6108d9054c77408bc (diff)
Add province names and improve zooming
Diffstat (limited to 'game/src/Game/GameSession/MapText.gd')
-rw-r--r--game/src/Game/GameSession/MapText.gd50
1 files changed, 50 insertions, 0 deletions
diff --git a/game/src/Game/GameSession/MapText.gd b/game/src/Game/GameSession/MapText.gd
new file mode 100644
index 0000000..22eba10
--- /dev/null
+++ b/game/src/Game/GameSession/MapText.gd
@@ -0,0 +1,50 @@
+class_name MapText
+extends Node3D
+
+@export var _map_view : MapView
+
+var _province_name_font : Font
+
+const _province_name_scale : float = 1.0 / 48.0
+
+func _ready() -> void:
+ _province_name_font = AssetManager.get_font(&"mapfont_56")
+
+func _clear_children() -> void:
+ var child_count : int = get_child_count()
+ while child_count > 0:
+ child_count -= 1
+ remove_child(get_child(child_count))
+
+func generate_map_names() -> void:
+ _clear_children()
+
+ for dict : Dictionary in GameSingleton.get_province_names():
+ _add_province_name(dict)
+
+func _add_province_name(dict : Dictionary) -> void:
+ const identifier_key : StringName = &"identifier"
+ const position_key : StringName = &"position"
+ const rotation_key : StringName = &"rotation"
+ const scale_key : StringName = &"scale"
+
+ var label : Label3D = Label3D.new()
+
+ label.set_draw_flag(Label3D.FLAG_DOUBLE_SIDED, false)
+ label.set_modulate(Color.BLACK)
+ label.set_outline_size(0)
+ label.set_font(_province_name_font)
+ label.set_vertical_alignment(VERTICAL_ALIGNMENT_BOTTOM)
+
+ var identifier : String = dict[identifier_key]
+ label.set_name(identifier)
+ label.set_text(GUINode.format_province_name(identifier))
+
+ label.set_position(_map_view._map_to_world_coords(dict[position_key]) + Vector3(0, 0.001, 0))
+
+ label.rotate_x(-PI / 2)
+ label.rotate_y(dict.get(rotation_key, 0.0))
+
+ label.scale *= dict.get(scale_key, 1.0) * _province_name_scale
+
+ add_child(label)