diff --git a/client/Main.gd b/client/Main.gd index 1bca5d4..eb07e79 100644 --- a/client/Main.gd +++ b/client/Main.gd @@ -2,24 +2,41 @@ extends Node @export var ui: UI -func _enter_tree(): - connect_main() - connect_ui() - func _ready(): + connect_events() pause(true) var args := OS.get_cmdline_args() var offline := args.has("--offline") if offline: - Global.account.id = "test" - Global.account.name = "Local" - Global.account.auth_token = "test" - Global.player = %PlayerAdd.spawn_player(Global.account.id, Global.account.name, Vector3.ZERO) - %Login.success.emit() + start_offline() else: - %Login.send_login() + start_online() + +func connect_events(): + %Login.success.connect(on_login) + %Logout.success.connect(on_logout) + + %Login.success.connect(ui.reconnect.hide) + %Logout.success.connect(ui.reconnect.show) + + %Ping.changed.connect(ui.network.set_ping) + %Client.download_changed.connect(ui.network.set_download) + %Client.upload_changed.connect(ui.network.set_upload) + + %Chat.message_received.connect(ui.chat.add_message) + ui.chat.message_submitted.connect(%Chat.send_message) + +func start_offline(): + Global.account.id = "test" + Global.account.name = "Local" + Global.account.auth_token = "test" + Global.player = %PlayerAdd.spawn_player(Global.account.id, Global.account.name, Vector3.ZERO) + %Login.success.emit() + +func start_online(): + %Login.send_login() func _input(event): if event.is_action_pressed("toggle_fullscreen"): @@ -47,19 +64,6 @@ func mute_audio(enabled: bool): var master_sound = AudioServer.get_bus_index("Master") AudioServer.set_bus_mute(master_sound, enabled) -func connect_main(): - %Login.success.connect(on_login) - %Logout.success.connect(on_logout) - -func connect_ui(): - ui.login = %Login.success - ui.logout = %Logout.success - ui.ping_changed = %Ping.changed - ui.download_changed = %Client.download_changed - ui.upload_changed = %Client.upload_changed - ui.message_received = %Chat.message_received - ui.chat_message_submitted.connect(%Chat.send_message) - func toggle_fullscreen(): var mode = DisplayServer.window_get_mode() @@ -74,4 +78,4 @@ func center_window(): var screen_center := DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2 var window := get_window() var window_size = window.get_size_with_decorations() - window.set_position(screen_center - window_size / 2) \ No newline at end of file + window.set_position(screen_center - window_size / 2) diff --git a/client/Main.tscn b/client/Main.tscn index 9f3999f..b877097 100644 --- a/client/Main.tscn +++ b/client/Main.tscn @@ -101,7 +101,7 @@ unique_name_in_owner = true script = ExtResource("10_y3len") packet_type = 20 -[node name="Statistics" type="Timer" parent="Client"] +[node name="BandwidthTimer" type="Timer" parent="Client"] process_thread_group = 1 process_thread_group_order = 0 process_thread_messages = 0 @@ -177,4 +177,4 @@ process_mode = 3 [connection signal="timeout" from="Client/Ping/Timer" to="Client/Ping" method="send_ping"] [connection signal="timeout" from="Client/Login/Timer" to="Client/Login" method="send_login"] -[connection signal="timeout" from="Client/Statistics" to="Client" method="update_statistics"] +[connection signal="timeout" from="Client/BandwidthTimer" to="Client" method="update_statistics"] diff --git a/client/Start.gd b/client/Start.gd index 4019726..f576de2 100644 --- a/client/Start.gd +++ b/client/Start.gd @@ -35,4 +35,4 @@ func fade_out(): progress_bar.hide() var tween = get_tree().create_tween() tween.tween_property(modulate, "color", Color(1.0, 1.0, 1.0, 0), fade_duration) - tween.tween_callback(queue_free) \ No newline at end of file + tween.tween_callback(queue_free) diff --git a/client/ui/UI.gd b/client/ui/UI.gd index 4e41e43..3c2573f 100644 --- a/client/ui/UI.gd +++ b/client/ui/UI.gd @@ -3,20 +3,14 @@ extends Node static var focus: Control -signal chat_message_submitted(message: String) - -@export var login: Signal -@export var logout: Signal -@export var ping_changed: Signal -@export var download_changed: Signal -@export var upload_changed: Signal -@export var message_received: Signal +var chat: Chat +var reconnect: Panel +var network: NetworkUI func _enter_tree(): - if get_node_or_null("/root/Main"): - return - - connect_fake() + chat = %Chat + reconnect = %Reconnect + network = %Network func _process(_delta): var new_focus := get_viewport().gui_get_focus_owner() @@ -26,14 +20,6 @@ func _process(_delta): else: UI.focus = null -func connect_fake(): - for property in get_property_list(): - if property.type != TYPE_SIGNAL: - continue - - add_user_signal(property.name) - set(property.name, Signal(self, property.name)) - static func unfocus(): if UI.focus: UI.focus.release_focus() \ No newline at end of file diff --git a/client/ui/UI.tscn b/client/ui/UI.tscn index 3c115ba..25d0a5b 100644 --- a/client/ui/UI.tscn +++ b/client/ui/UI.tscn @@ -1,18 +1,15 @@ -[gd_scene load_steps=16 format=3 uid="uid://dagn5bf7ou3sd"] +[gd_scene load_steps=13 format=3 uid="uid://dagn5bf7ou3sd"] [ext_resource type="PackedScene" uid="uid://cch67vqpsmtej" path="res://ui/debug/DebugLabel.tscn" id="1_7s8uu"] [ext_resource type="Script" path="res://ui/UI.gd" id="1_l5b6o"] [ext_resource type="Script" path="res://ui/debug/FPSLabel.gd" id="2_i200p"] -[ext_resource type="Script" path="res://ui/debug/PingLabel.gd" id="3_xjdws"] [ext_resource type="Script" path="res://ui/debug/PositionLabel.gd" id="4_beqf6"] [ext_resource type="Script" path="res://ui/debug/VelocityLabel.gd" id="5_8lm6a"] -[ext_resource type="Script" path="res://ui/chat/ChatBox.gd" id="5_43juw"] [ext_resource type="Script" path="res://ui/debug/PerformanceLabel.gd" id="5_ab7ln"] -[ext_resource type="Script" path="res://ui/chat/ChatInput.gd" id="6_cg2h5"] -[ext_resource type="Script" path="res://ui/debug/UploadLabel.gd" id="7_cfnpx"] -[ext_resource type="Script" path="res://ui/debug/DownloadLabel.gd" id="8_ogt38"] -[ext_resource type="Script" path="res://ui/connect/ConnectPanel.gd" id="11_cwl0t"] +[ext_resource type="PackedScene" uid="uid://dvfy6k5h51x7w" path="res://ui/chat/Chat.tscn" id="5_jygpp"] +[ext_resource type="PackedScene" uid="uid://bigr3od0vmicg" path="res://ui/network/Network.tscn" id="6_asn0f"] [ext_resource type="PackedScene" uid="uid://bqpbrju7mc7d5" path="res://ui/settings/Settings.tscn" id="11_rt7sl"] +[ext_resource type="PackedScene" uid="uid://c6jhsk76pk5k4" path="res://ui/reconnect/Reconnect.tscn" id="12_plqhr"] [ext_resource type="Script" path="res://ui/debug/StateLabel.gd" id="12_rr0mv"] [ext_resource type="PackedScene" uid="uid://y6kdpmp5glv0" path="res://ui/inventory/Inventory.tscn" id="13_1fc2b"] @@ -122,26 +119,9 @@ offset_right = 50.5 grow_horizontal = 2 grow_vertical = 0 -[node name="Chat" type="VBoxContainer" parent="Bottom"] -custom_minimum_size = Vector2(320, 180) +[node name="Chat" parent="Bottom" instance=ExtResource("5_jygpp")] +unique_name_in_owner = true layout_mode = 2 -size_flags_vertical = 3 -alignment = 2 - -[node name="ChatBox" type="RichTextLabel" parent="Bottom/Chat"] -layout_mode = 2 -size_flags_vertical = 3 -focus_mode = 2 -bbcode_enabled = true -scroll_active = false -scroll_following = true -context_menu_enabled = true -selection_enabled = true -script = ExtResource("5_43juw") - -[node name="ChatInput" type="LineEdit" parent="Bottom/Chat"] -layout_mode = 2 -script = ExtResource("6_cg2h5") [node name="BottomRight" type="MarginContainer" parent="."] anchors_preset = 3 @@ -154,24 +134,9 @@ offset_top = -54.0 grow_horizontal = 0 grow_vertical = 0 -[node name="VBoxContainer" type="VBoxContainer" parent="BottomRight"] +[node name="Network" parent="BottomRight" instance=ExtResource("6_asn0f")] +unique_name_in_owner = true layout_mode = 2 -alignment = 2 - -[node name="Ping" parent="BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")] -layout_mode = 2 -alignment = 2 -script = ExtResource("3_xjdws") - -[node name="Send" parent="BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")] -layout_mode = 2 -alignment = 2 -script = ExtResource("7_cfnpx") - -[node name="Receive" parent="BottomRight/VBoxContainer" instance=ExtResource("1_7s8uu")] -layout_mode = 2 -alignment = 2 -script = ExtResource("8_ogt38") [node name="TopRight" type="MarginContainer" parent="."] anchors_preset = 1 @@ -199,29 +164,9 @@ layout_mode = 2 alignment = 2 script = ExtResource("5_8lm6a") -[node name="ConnectPanel" type="Panel" parent="."] +[node name="Reconnect" parent="." instance=ExtResource("12_plqhr")] +unique_name_in_owner = true visible = false -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -script = ExtResource("11_cwl0t") - -[node name="ConnectLabel" type="Label" parent="ConnectPanel"] -layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -47.5 -offset_top = -10.0 -offset_right = 47.5 -offset_bottom = 10.0 -grow_horizontal = 2 -grow_vertical = 2 -text = "Connecting..." [node name="Settings" parent="." instance=ExtResource("11_rt7sl")] visible = false diff --git a/client/ui/chat/Chat.gd b/client/ui/chat/Chat.gd new file mode 100644 index 0000000..aac51c0 --- /dev/null +++ b/client/ui/chat/Chat.gd @@ -0,0 +1,7 @@ +class_name Chat +extends VBoxContainer + +signal message_submitted(message: String) + +func add_message(message: String): + %Messages.append_text(message + "\n") \ No newline at end of file diff --git a/client/ui/chat/Chat.tscn b/client/ui/chat/Chat.tscn new file mode 100644 index 0000000..1abaf42 --- /dev/null +++ b/client/ui/chat/Chat.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=3 format=3 uid="uid://dvfy6k5h51x7w"] + +[ext_resource type="Script" path="res://ui/chat/Chat.gd" id="1_sxxey"] +[ext_resource type="Script" path="res://ui/chat/ChatInput.gd" id="2_yjq4f"] + +[node name="Chat" type="VBoxContainer"] +custom_minimum_size = Vector2(320, 180) +size_flags_vertical = 3 +alignment = 2 +script = ExtResource("1_sxxey") + +[node name="Messages" type="RichTextLabel" parent="."] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +focus_mode = 2 +bbcode_enabled = true +scroll_active = false +scroll_following = true +context_menu_enabled = true +selection_enabled = true + +[node name="Input" type="LineEdit" parent="."] +unique_name_in_owner = true +layout_mode = 2 +script = ExtResource("2_yjq4f") diff --git a/client/ui/chat/ChatBox.gd b/client/ui/chat/ChatBox.gd deleted file mode 100644 index d4ad2ef..0000000 --- a/client/ui/chat/ChatBox.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends RichTextLabel - -func _ready(): - owner.message_received.connect(on_message_received) - -func on_message_received(bbcode: String): - append_text(bbcode + "\n") \ No newline at end of file diff --git a/client/ui/chat/ChatInput.gd b/client/ui/chat/ChatInput.gd index 8fd4cc7..09f571c 100644 --- a/client/ui/chat/ChatInput.gd +++ b/client/ui/chat/ChatInput.gd @@ -23,6 +23,6 @@ func on_focus_exited(): tween.tween_property(self, "modulate", Color(1, 1, 1, 0), 0.2) func on_text_submitted(message: String): - (owner as UI).chat_message_submitted.emit(message) text = "" release_focus() + (owner as Chat).message_submitted.emit(message) diff --git a/client/ui/connect/ConnectPanel.gd b/client/ui/connect/ConnectPanel.gd deleted file mode 100644 index 477d5e0..0000000 --- a/client/ui/connect/ConnectPanel.gd +++ /dev/null @@ -1,11 +0,0 @@ -extends Panel - -func _ready(): - owner.login.connect(on_login) - owner.logout.connect(on_logout) - -func on_login(): - hide() - -func on_logout(): - show() diff --git a/client/ui/debug/DownloadLabel.gd b/client/ui/debug/DownloadLabel.gd deleted file mode 100644 index cb56627..0000000 --- a/client/ui/debug/DownloadLabel.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends DebugLabel - -func _ready(): - owner.download_changed.connect(on_download_changed) - -func on_download_changed(download): - text = "%d bytes" % download diff --git a/client/ui/debug/PingLabel.gd b/client/ui/debug/PingLabel.gd deleted file mode 100644 index 3c1badc..0000000 --- a/client/ui/debug/PingLabel.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends DebugLabel - -func _ready(): - owner.ping_changed.connect(on_ping_changed) - -func on_ping_changed(ping): - text = str(snapped(ping * 1000, 1)) + " ms" diff --git a/client/ui/debug/UploadLabel.gd b/client/ui/debug/UploadLabel.gd deleted file mode 100644 index 4bcc36a..0000000 --- a/client/ui/debug/UploadLabel.gd +++ /dev/null @@ -1,7 +0,0 @@ -extends DebugLabel - -func _ready(): - owner.upload_changed.connect(on_upload_changed) - -func on_upload_changed(upload): - text = "%d bytes" % upload diff --git a/client/ui/network/Network.gd b/client/ui/network/Network.gd new file mode 100644 index 0000000..3c5eee3 --- /dev/null +++ b/client/ui/network/Network.gd @@ -0,0 +1,11 @@ +class_name NetworkUI +extends VBoxContainer + +func set_ping(ping: float): + %Ping.text = str(snapped(ping * 1000, 1)) + " ms" + +func set_download(download: int): + %Receive.text = "%d bytes" % download + +func set_upload(upload: int): + %Send.text = "%d bytes" % upload \ No newline at end of file diff --git a/client/ui/network/Network.tscn b/client/ui/network/Network.tscn new file mode 100644 index 0000000..ea7654c --- /dev/null +++ b/client/ui/network/Network.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=3 uid="uid://bigr3od0vmicg"] + +[ext_resource type="PackedScene" uid="uid://cch67vqpsmtej" path="res://ui/debug/DebugLabel.tscn" id="1_d3f0b"] +[ext_resource type="Script" path="res://ui/network/Network.gd" id="1_dnvs4"] + +[node name="Network" type="VBoxContainer"] +alignment = 2 +script = ExtResource("1_dnvs4") + +[node name="Ping" parent="." instance=ExtResource("1_d3f0b")] +unique_name_in_owner = true +layout_mode = 2 +alignment = 2 + +[node name="Send" parent="." instance=ExtResource("1_d3f0b")] +unique_name_in_owner = true +layout_mode = 2 +alignment = 2 + +[node name="Receive" parent="." instance=ExtResource("1_d3f0b")] +unique_name_in_owner = true +layout_mode = 2 +alignment = 2 diff --git a/client/ui/reconnect/Reconnect.tscn b/client/ui/reconnect/Reconnect.tscn new file mode 100644 index 0000000..fa7bc1a --- /dev/null +++ b/client/ui/reconnect/Reconnect.tscn @@ -0,0 +1,23 @@ +[gd_scene format=3 uid="uid://c6jhsk76pk5k4"] + +[node name="Reconnect" type="Panel"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Label" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -47.5 +offset_top = -10.0 +offset_right = 47.5 +offset_bottom = 10.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "Connecting..."