moved chat to new ChatPanel and added smooth bottom scrolling when new message is received

This commit is contained in:
2025-07-20 13:36:30 +02:00
parent 4fe629d012
commit 3cf036db42
8 changed files with 274 additions and 79 deletions
+191 -71
View File
@@ -6,15 +6,12 @@
[ext_resource type="Script" uid="uid://utt8atbh7b2a" path="res://game_client.gd" id="3_feb5d"]
[ext_resource type="Script" uid="uid://bipfa366flrfa" path="res://environment_manager.gd" id="4_7jktm"]
[ext_resource type="PackedScene" uid="uid://jlovgr2iojrg" path="res://elements/player_hand.tscn" id="4_fc0e3"]
[ext_resource type="Script" uid="uid://bfhknl0awlj22" path="res://chat_panel.gd" id="4_iotsf"]
[ext_resource type="Script" uid="uid://bokp83oigikj2" path="res://number_input.gd" id="4_vef74"]
[ext_resource type="PackedScene" uid="uid://b55xpcxk7g5ph" path="res://cards/playing_card.tscn" id="6_eow3j"]
[ext_resource type="PackedScene" uid="uid://dj1wye7o27vil" path="res://assets/table.glb" id="7_eow3j"]
[ext_resource type="Script" uid="uid://c5bk4gjeyh7vy" path="res://card_stack.gd" id="8_j5wjh"]
[sub_resource type="SystemFont" id="SystemFont_80nbo"]
font_names = PackedStringArray("IBM Plex Mono")
font_weight = 500
[sub_resource type="Environment" id="Environment_fc0e3"]
ambient_light_source = 2
ambient_light_color = Color(1, 1, 1, 1)
@@ -22,7 +19,7 @@ ambient_light_energy = 0.15
[node name="Game" type="Node"]
[node name="WebClientTCP" type="Node" parent="."]
[node name="WebClient" type="Node" parent="."]
script = ExtResource("1_feb5d")
[node name="Interface" type="Control" parent="."]
@@ -35,24 +32,23 @@ grow_vertical = 2
theme = ExtResource("2_hve3p")
metadata/_edit_use_anchors_ = true
[node name="ClientInterface" type="ColorRect" parent="Interface" node_paths=PackedStringArray("client", "connect_button", "create_lobby_button", "join_lobby_button", "leave_lobby_button", "chat_message_input", "send_chat_message_button", "connected_players_label", "name_input", "lobby_code_input", "output")]
[node name="ClientInterface" type="ColorRect" parent="Interface" node_paths=PackedStringArray("client", "connect_button", "create_lobby_button", "join_lobby_button", "leave_lobby_button", "chat_message_input", "send_chat_message_button", "connected_players_label", "name_input", "lobby_code_input")]
custom_minimum_size = Vector2(316, 0)
layout_mode = 2
offset_right = 316.0
offset_bottom = 1080.0
offset_bottom = 429.0
color = Color(0.26, 0.2236, 0.230273, 1)
script = ExtResource("2_e2o6t")
client = NodePath("../../WebClientTCP")
client = NodePath("../../WebClient")
connect_button = NodePath("MarginContainer/VBoxContainer/ServerInputs/ConnectButton")
create_lobby_button = NodePath("MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton")
join_lobby_button = NodePath("MarginContainer/VBoxContainer/ServerInputs/JoinLobbyButton")
leave_lobby_button = NodePath("MarginContainer/VBoxContainer/ServerInputs/LeaveLobbyButton")
chat_message_input = NodePath("../ChatPanel/ChatContainer/MessageInput")
send_chat_message_button = NodePath("../ChatPanel/ChatContainer/SendMessageButton")
chat_message_input = NodePath("../ChatPanel/InputContainer/MessageInput")
send_chat_message_button = NodePath("../ChatPanel/InputContainer/SendMessageButton")
connected_players_label = NodePath("MarginContainer/VBoxContainer/ConnectedPlayersLabel")
name_input = NodePath("MarginContainer/VBoxContainer/ServerInputs/NameInput")
lobby_code_input = NodePath("MarginContainer/VBoxContainer/ServerInputs/LobbyCodeInput")
output = NodePath("MarginContainer/VBoxContainer/ScrollContainer/Output")
[node name="MarginContainer" type="MarginContainer" parent="Interface/ClientInterface"]
layout_mode = 1
@@ -75,7 +71,7 @@ layout_mode = 2
[node name="URLInput" type="LineEdit" parent="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs"]
layout_mode = 2
text = "wss://denizk0461.dev/magsrv/"
text = "127.0.0.1:9974"
placeholder_text = "URL"
[node name="ConnectButton" type="Button" parent="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs"]
@@ -110,45 +106,167 @@ text = "Disconnect"
[node name="ConnectedPlayersLabel" type="Label" parent="Interface/ClientInterface/MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="ScrollContainer" type="ScrollContainer" parent="Interface/ClientInterface/MarginContainer/VBoxContainer"]
[node name="ChatPanel" type="VBoxContainer" parent="Interface" node_paths=PackedStringArray("message_container", "scroll_container")]
layout_mode = 1
anchors_preset = -1
anchor_top = 0.478704
anchor_right = 0.234375
anchor_bottom = 1.0
grow_vertical = 0
script = ExtResource("4_iotsf")
auto_scroll_duration = 0.4
message_container = NodePath("ScrollContainer/MessageContainer")
scroll_container = NodePath("ScrollContainer")
metadata/_edit_use_anchors_ = true
[node name="ScrollContainer" type="ScrollContainer" parent="Interface/ChatPanel"]
layout_mode = 2
size_flags_vertical = 3
horizontal_scroll_mode = 0
vertical_scroll_mode = 4
[node name="Output" type="Label" parent="Interface/ClientInterface/MarginContainer/VBoxContainer/ScrollContainer"]
custom_minimum_size = Vector2(64, 1)
[node name="MessageContainer" type="VBoxContainer" parent="Interface/ChatPanel/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
theme_override_fonts/font = SubResource("SystemFont_80nbo")
autowrap_mode = 2
metadata/_edit_lock_ = true
alignment = 2
[node name="ChatPanel" type="Control" parent="Interface"]
layout_mode = 1
anchor_top = 0.478704
anchor_right = 0.234375
anchor_bottom = 1.0
grow_vertical = 0
metadata/_edit_use_anchors_ = true
[node name="Label" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="ChatContainer" type="HBoxContainer" parent="Interface/ChatPanel"]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -31.0
grow_horizontal = 2
grow_vertical = 0
[node name="Label2" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="MessageInput" type="LineEdit" parent="Interface/ChatPanel/ChatContainer"]
[node name="Label3" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label4" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label5" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label6" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label7" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label8" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label9" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label10" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label11" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label12" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label13" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label14" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label15" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label16" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label17" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label18" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label19" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label20" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label21" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label22" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label23" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label24" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label25" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label26" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label27" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label28" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label29" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label30" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label31" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="Label32" type="Label" parent="Interface/ChatPanel/ScrollContainer/MessageContainer"]
layout_mode = 2
text = "asdf"
[node name="InputContainer" type="HBoxContainer" parent="Interface/ChatPanel"]
layout_mode = 2
[node name="MessageInput" type="LineEdit" parent="Interface/ChatPanel/InputContainer"]
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "Type chat message here"
[node name="SendMessageButton" type="Button" parent="Interface/ChatPanel/ChatContainer"]
[node name="SendMessageButton" type="Button" parent="Interface/ChatPanel/InputContainer"]
layout_mode = 2
text = "Send"
@@ -156,6 +274,7 @@ text = "Send"
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 485.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("2_hve3p")
@@ -165,7 +284,7 @@ layout_mode = 2
size_flags_horizontal = 3
mouse_filter = 2
script = ExtResource("3_feb5d")
web_client = NodePath("../../WebClientTCP")
web_client = NodePath("../../WebClient")
start_game_button = NodePath("StartGameButton")
play_card_button = NodePath("PlayCardButton")
bet_container = NodePath("BetContainer")
@@ -297,7 +416,7 @@ text = "NOT ALLOWED!"
[node name="EnvironmentManager" type="Node3D" parent="." node_paths=PackedStringArray("web_client", "card_stack", "own_player_hand", "hand_markers_3", "hand_markers_4", "hand_markers_5", "hand_markers_6")]
script = ExtResource("4_7jktm")
web_client = NodePath("../WebClientTCP")
web_client = NodePath("../WebClient")
card_stack = NodePath("CardStack")
own_player_hand = NodePath("PlayerHand0")
hand_markers_3 = [NodePath("HandMarker1"), NodePath("HandMarker2")]
@@ -345,44 +464,45 @@ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -0.999999, -4.37114e-08,
script = ExtResource("8_j5wjh")
playing_card_scene = ExtResource("6_eow3j")
[connection signal="cards_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_cards_received"]
[connection signal="client_joined_lobby" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_client_joined_lobby"]
[connection signal="client_joined_lobby" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_joined_lobby"]
[connection signal="client_left_lobby" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_left_lobby" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_order_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_client_order_received"]
[connection signal="connected_to_lobby" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_lobby"]
[connection signal="connected_to_server" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_server"]
[connection signal="connection_error_occurred" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_error_occurred"]
[connection signal="connection_status_changed" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
[connection signal="disconnected_from_server" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
[connection signal="new_round_started" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
[connection signal="notify_play_card_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_web_client_tcp_received_bet_request"]
[connection signal="received_chat_message" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
[connection signal="received_connection_message" from="WebClientTCP" to="Interface/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
[connection signal="received_end_game_request" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_end_game_request"]
[connection signal="received_expected_bet" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_expected_bet"]
[connection signal="received_first_card" from="WebClientTCP" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_received_first_card"]
[connection signal="received_play_winner_request" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_play_winner_request"]
[connection signal="received_played_card" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_played_card"]
[connection signal="received_win" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_win"]
[connection signal="received_winning_client" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_winning_client"]
[connection signal="request_next_play" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_play"]
[connection signal="request_next_round" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_round"]
[connection signal="reset_first_card" from="WebClientTCP" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_reset_first_card"]
[connection signal="trump_received" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_trump_received"]
[connection signal="trump_received" from="WebClientTCP" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_trump_received"]
[connection signal="cards_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_cards_received"]
[connection signal="client_joined_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_client_joined_lobby"]
[connection signal="client_joined_lobby" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_joined_lobby"]
[connection signal="client_left_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_left_lobby" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_client_left_lobby"]
[connection signal="client_order_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_client_order_received"]
[connection signal="connected_to_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_lobby"]
[connection signal="connected_to_server" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connected_to_server"]
[connection signal="connection_error_occurred" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_error_occurred"]
[connection signal="connection_status_changed" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
[connection signal="disconnected_from_lobby" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
[connection signal="disconnected_from_server" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
[connection signal="new_round_started" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
[connection signal="notify_play_card_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
[connection signal="received_bet_request" from="WebClient" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_web_client_tcp_received_bet_request"]
[connection signal="received_chat_message" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
[connection signal="received_client_id" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
[connection signal="received_connection_message" from="WebClient" to="Interface/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
[connection signal="received_end_game_request" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_end_game_request"]
[connection signal="received_expected_bet" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_expected_bet"]
[connection signal="received_first_card" from="WebClient" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_received_first_card"]
[connection signal="received_play_winner_request" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_play_winner_request"]
[connection signal="received_played_card" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_played_card"]
[connection signal="received_win" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_win"]
[connection signal="received_winning_client" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_received_winning_client"]
[connection signal="request_next_play" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_play"]
[connection signal="request_next_round" from="WebClient" to="HBoxContainer/GameUI" method="_on_web_client_tcp_request_next_round"]
[connection signal="reset_first_card" from="WebClient" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_reset_first_card"]
[connection signal="trump_received" from="WebClient" to="EnvironmentManager" method="_on_web_client_tcp_trump_received"]
[connection signal="trump_received" from="WebClient" to="EnvironmentManager/PlayerHand0" method="_on_web_client_tcp_trump_received"]
[connection signal="user_message_received" from="WebClient" to="Interface/ChatPanel" method="_on_web_client_user_message_received"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/ConnectButton" to="Interface/ClientInterface" method="_on_connect_button_pressed"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="Interface/ClientInterface" method="_on_create_lobby_button_pressed"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/CreateLobbyButton" to="HBoxContainer/GameUI" method="_on_create_lobby_button_pressed"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/JoinLobbyButton" to="Interface/ClientInterface" method="_on_join_lobby_button_pressed"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/JoinLobbyButton" to="HBoxContainer/GameUI" method="_on_join_lobby_button_pressed"]
[connection signal="pressed" from="Interface/ClientInterface/MarginContainer/VBoxContainer/ServerInputs/LeaveLobbyButton" to="Interface/ClientInterface" method="_on_disconnect_lobby_button_pressed"]
[connection signal="pressed" from="Interface/ChatPanel/ChatContainer/SendMessageButton" to="Interface/ClientInterface" method="_on_send_message_button_pressed"]
[connection signal="pressed" from="Interface/ChatPanel/InputContainer/SendMessageButton" to="Interface/ClientInterface" method="_on_send_message_button_pressed"]
[connection signal="pressed" from="HBoxContainer/GameUI/StartGameButton" to="HBoxContainer/GameUI" method="_on_start_game_button_pressed"]
[connection signal="pressed" from="HBoxContainer/GameUI/PlayCardButton" to="EnvironmentManager/PlayerHand0" method="_on_play_card_button_pressed"]
[connection signal="text_changed" from="HBoxContainer/GameUI/BetContainer/BetInput" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_text_changed"]