From 46897ebdbe69145d6e9290c474c8ac426372226e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 27 Sep 2025 22:07:11 +0200 Subject: Chat system messages --- client/game.gd | 16 +++++++++++++--- client/gui/components/message/chat_message.gd | 14 ++++++++------ client/gui/menus/game.gd | 12 ++++++++---- 3 files changed, 29 insertions(+), 13 deletions(-) (limited to 'client') diff --git a/client/game.gd b/client/game.gd index 020c43db..34040034 100644 --- a/client/game.gd +++ b/client/game.gd @@ -24,13 +24,12 @@ signal text_message(message: TextMessage) signal update_tutorial_running(running: bool) class TextMessage: - var username: String + var username #: String var color: Color var text: String var timeout_initial: float var timeout_remaining - enum SpectatingMode { CENTER, FREE, @@ -82,6 +81,11 @@ func _ready(): get_parent().replace_menu("res://gui/menus/error.tscn", [reason, menu.data]) ) mp.connect_to_url(menu.data) + text_message.connect(func(m): + text_message_history.push_back(m) + while text_message_history.size() > 64: + text_message_history.pop_front() + ) func handle_packet(p): match p.type: @@ -261,7 +265,6 @@ func handle_packet(p): player.text_message(data) text_message.emit(data) - text_message_history.append(data) elif "tile" in p.message: push_error("TODO: tile message") else: @@ -369,6 +372,13 @@ func handle_packet(p): _: push_error("Unrecognized packet type: %s" % p.type) +func system_message(s: String): + var message = TextMessage.new() + message.text = s + message.color = Color.GOLD + message.timeout_remaining = 5. + text_message.emit(message) + func set_join_state(state: JoinState): join_state = state join_state_updated.emit(state) diff --git a/client/gui/components/message/chat_message.gd b/client/gui/components/message/chat_message.gd index ce3dd0ca..27403701 100644 --- a/client/gui/components/message/chat_message.gd +++ b/client/gui/components/message/chat_message.gd @@ -20,13 +20,15 @@ class_name ChatMessage @onready var sender_label: Label = $Sender @onready var message_label: Label = $MarginContainer/Message -func set_message(username: String, message: String, username_color: Color, fade_away: bool = false, fade_time: float = 5.): - sender_label.text = "<%s>" % username +func set_message(username, message: String, username_color: Color, fade_away: bool = false, fade_time: float = 5.): + if username == null: + sender_label.hide() + message_label.add_theme_color_override("font_color", username_color) + else: + sender_label.text = "<%s>" % username + sender_label.add_theme_color_override("font_color", username_color.lightened(.5)) message_label.text = message - sender_label.add_theme_color_override("font_color", username_color.lightened(.5)) - - if fade_away: - fade_away_timer.start(fade_time) + if fade_away: fade_away_timer.start(fade_time) func _on_fade_away_timeout() -> void: queue_free() diff --git a/client/gui/menus/game.gd b/client/gui/menus/game.gd index 0466d287..e0ab5de7 100644 --- a/client/gui/menus/game.gd +++ b/client/gui/menus/game.gd @@ -25,13 +25,12 @@ func _ready(): get_tree().get_root().go_back_requested.connect(open_ingame_menu) super() transition.set_loading_text(tr("c.menu.game.connecting")) - Settings.hook_changed_init("gameplay.first_person", "mouse_lock", func (_a): update_mouse_capture()) func _input(_event): if Input.is_action_just_pressed("ui_menu"): open_ingame_menu() - + if Input.is_action_just_pressed("chat"): Sound.play_click() chat_preview.visible = false @@ -39,13 +38,17 @@ func _input(_event): chat_preview.visible = true if Input.is_action_just_pressed("screenshot"): - get_viewport().get_texture().get_image().save_png(get_shot_path("screenshot-%s.png")) + var path = get_shot_path("screenshot-%s.png") + get_viewport().get_texture().get_image().save_png(path) + game.system_message(tr("c.system_message.screenshot_saved").format({"path": path})) if Input.is_action_just_pressed("sceneshot"): + var path = get_shot_path("sceneshot-%s.glb") var doc := GLTFDocument.new() var state := GLTFState.new() doc.append_from_scene(game, state) - doc.write_to_filesystem(state, get_shot_path("sceneshot-%s.glb")) + doc.write_to_filesystem(state, path) + game.system_message(tr("c.system_message.sceneshot_saved").format({"path": path})) if Input.is_action_just_pressed("toggle_first_person"): Settings.write("gameplay.first_person", not Settings.read("gameplay.first_person")) @@ -61,6 +64,7 @@ func _menu_cover(state): game.follow_camera.disable_input_menu = state game.follow_camera.update_disable_input() update_mouse_capture() + func _menu_exit(): super() Input.mouse_mode = Input.MOUSE_MODE_VISIBLE -- cgit v1.2.3-70-g09d2