diff --git a/chat_panel.gd b/chat_panel.gd index 25797d9..3009a29 100644 --- a/chat_panel.gd +++ b/chat_panel.gd @@ -6,6 +6,10 @@ extends VBoxContainer @export_range(0.1, 1.0, 0.05) var auto_scroll_duration: float = 0.2 @export var message_container: VBoxContainer @export var scroll_container: ScrollContainer +@export var message_input: LineEdit +@export var send_message_button: Button + +signal message_sent(message: String) func put_chat_message(sender: String, message: String) -> void: var scene: ChatMessage = _chat_message_scene.instantiate() @@ -22,5 +26,22 @@ func put_chat_message(sender: String, message: String) -> void: func _scroll_to_bottom() -> void: create_tween().set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_OUT).tween_property(scroll_container, "scroll_vertical", scroll_container.get_v_scroll_bar().max_value - scroll_container.get_v_scroll_bar().size.y, auto_scroll_duration) +func _send_chat_message() -> void: + if message_input.text.is_empty(): + return + + message_sent.emit(message_input.text.strip_edges()) + message_input.text = "" + func _on_web_client_user_message_received(sender: String, message: String) -> void: put_chat_message(sender, message) + +func _on_message_input_text_changed(new_text: String) -> void: + send_message_button.disabled = new_text.is_empty() + +func _on_message_input_gui_input(event: InputEvent) -> void: + if event.is_action_pressed("send_chat_message"): + _send_chat_message() + +func _on_send_message_button_pressed() -> void: + _send_chat_message() diff --git a/components/client_interface.gd b/components/client_interface.gd index ee7d6e8..dadfeaa 100644 --- a/components/client_interface.gd +++ b/components/client_interface.gd @@ -35,12 +35,6 @@ func _on_disconnect_lobby_button_pressed() -> void: leave_lobby_button.disabled = true client.leave_lobby() -func _on_send_message_button_pressed() -> void: - var msg: String = chat_message_input.text.strip_edges() - if not msg.is_empty(): - client.send_chat_message(msg) - chat_message_input.text = "" - func _on_web_client_tcp_connected_to_server() -> void: _write_line("You are connected to the server") diff --git a/components/web_client_tcp.gd b/components/web_client_tcp.gd index 77b333c..1f3c536 100644 --- a/components/web_client_tcp.gd +++ b/components/web_client_tcp.gd @@ -248,7 +248,8 @@ func leave_lobby() -> void: connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS) func send_chat_message(message: String) -> void: - _send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message)) + #_send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message)) + pass func start_game() -> void: _send_message(JSON.stringify({ @@ -305,3 +306,6 @@ func submit_play_winner(winning_client_id: String) -> void: func _send_message(message: String) -> void: _socket.send_text(message) + +func _on_chat_panel_message_sent(message: String) -> void: + _send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message)) diff --git a/game.tscn b/game.tscn index cac53db..117eb5c 100644 --- a/game.tscn +++ b/game.tscn @@ -106,7 +106,7 @@ text = "Disconnect" [node name="ConnectedPlayersLabel" type="Label" parent="Interface/ClientInterface/MarginContainer/VBoxContainer"] layout_mode = 2 -[node name="ChatPanel" type="VBoxContainer" parent="Interface" node_paths=PackedStringArray("message_container", "scroll_container")] +[node name="ChatPanel" type="VBoxContainer" parent="Interface" node_paths=PackedStringArray("message_container", "scroll_container", "message_input", "send_message_button")] layout_mode = 1 anchors_preset = -1 anchor_top = 0.478704 @@ -117,6 +117,8 @@ script = ExtResource("4_iotsf") auto_scroll_duration = 0.4 message_container = NodePath("ScrollContainer/MessageContainer") scroll_container = NodePath("ScrollContainer") +message_input = NodePath("InputContainer/MessageInput") +send_message_button = NodePath("InputContainer/SendMessageButton") metadata/_edit_use_anchors_ = true [node name="ScrollContainer" type="ScrollContainer" parent="Interface/ChatPanel"] @@ -502,7 +504,10 @@ playing_card_scene = ExtResource("6_eow3j") [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/InputContainer/SendMessageButton" to="Interface/ClientInterface" method="_on_send_message_button_pressed"] +[connection signal="message_sent" from="Interface/ChatPanel" to="WebClient" method="_on_chat_panel_message_sent"] +[connection signal="gui_input" from="Interface/ChatPanel/InputContainer/MessageInput" to="Interface/ChatPanel" method="_on_message_input_gui_input"] +[connection signal="text_changed" from="Interface/ChatPanel/InputContainer/MessageInput" to="Interface/ChatPanel" method="_on_message_input_text_changed"] +[connection signal="pressed" from="Interface/ChatPanel/InputContainer/SendMessageButton" to="Interface/ChatPanel" 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"] diff --git a/project.godot b/project.godot index 5050ef3..65c0e36 100644 --- a/project.godot +++ b/project.godot @@ -32,6 +32,12 @@ left_mouse_button={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(217, 46),"global_position":Vector2(233, 130),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } +send_chat_message={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194310,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [layer_names]