From ff92434409ef34b10ae4169f6723b1dab310b2c3 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Fri, 14 Feb 2025 18:06:40 +0300 Subject: [PATCH] chat things --- src/ingame/ingame.gd | 19 ++++++++++++++++--- src/ingame/ingame.tscn | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ingame/ingame.gd b/src/ingame/ingame.gd index dd8d7ca..b35a706 100644 --- a/src/ingame/ingame.gd +++ b/src/ingame/ingame.gd @@ -138,8 +138,8 @@ func _submit_chat_message(text: String) -> void: @rpc("authority", "call_local", "reliable", 1) func _add_chat_message(username: String, text: String) -> void: - _chat_history.add_child(_make_chat_message(username, text)) - _chat_history_inactive.add_child(_make_chat_message(username, text)) + _chat_history.add_child(_make_chat_message(username, text, false)) + _chat_history_inactive.add_child(_make_chat_message(username, text, true)) func _on_chat_history_scroll_changed(history: ScrollContainer) -> void: @@ -147,11 +147,24 @@ func _on_chat_history_scroll_changed(history: ScrollContainer) -> void: history.scroll_vertical = int(history.get_v_scroll_bar().max_value) -func _make_chat_message(username: String, text: String) -> RichTextLabel: +func _fade_inactive_chat_message(p_label: RichTextLabel) -> void: + var start := Time.get_ticks_msec() + while true: + var now := Time.get_ticks_msec() + if now - start >= 10000: break + p_label.add_theme_color_override("default_color", Color(0, 0, 0, 1.0 - (now - start) / 10000.0 )) + await get_tree().process_frame + p_label.queue_free() + + +func _make_chat_message(username: String, text: String, inactive: bool) -> RichTextLabel: var label := RichTextLabel.new() label.bbcode_enabled = true label.fit_content = true label.append_text("[color=red]%s[/color] %s" % [username.replace("[", "[lb]"), text.replace("[", "[lb]")]) + if inactive: + label.add_theme_color_override("default_color", Color.BLACK) + _fade_inactive_chat_message(label) return label diff --git a/src/ingame/ingame.tscn b/src/ingame/ingame.tscn index 896b782..b14c1cc 100644 --- a/src/ingame/ingame.tscn +++ b/src/ingame/ingame.tscn @@ -155,7 +155,7 @@ vertical_scroll_mode = 3 [node name="ChatHistory" type="VBoxContainer" parent="UI/ChatPanelInactive/ChatHistoryScroll"] layout_mode = 2 size_flags_horizontal = 3 -size_flags_vertical = 3 +size_flags_vertical = 10 [node name="ComboTimer" type="Timer" parent="UI"] wait_time = 3.0