From 4650fe9d49d95f0d43c4924f64709850fa8160c2 Mon Sep 17 00:00:00 2001 From: no_name_user_7718 Date: Thu, 23 May 2024 18:10:49 +0300 Subject: [PATCH] feat: Added Game Manager --- data/scenes/Game/GameChat/game_chat.tscn | 143 ++++++++++++ .../Scripts/Sinhronizers/ChatSinhronizer.gd | 27 +++ .../scenes/Game/StartPanel/connected_panel.gd | 39 ++++ .../Game/StartPanel/connected_panel.tscn | 193 ++++++++++++++++ data/scenes/Game/game.gd | 55 ++++- data/scenes/Game/game.tscn | 15 +- data/scenes/HELPERS/PopUps/game_panel.tscn | 1 - data/scenes/Player/Player.gd | 21 ++ data/scenes/lobbies/ChatSinhronizer.gd | 4 +- data/scenes/lobbies/GameLabel.gd | 29 ++- data/scenes/lobbies/GameLabel.tscn | 2 +- data/scenes/lobbies/GamesSinhronizer.gd | 60 ++++- data/scenes/lobbies/Lob174C.tmp | 216 ++++++++++++++++++ data/scenes/lobbies/Lobbies.tscn | 56 ++++- data/scenes/main_menu/main_menu.gd | 11 +- data/scripts/objects/GateWay.gd | 25 +- data/styles/locale/localization.csv | 11 +- project.godot | 1 + 18 files changed, 872 insertions(+), 37 deletions(-) create mode 100644 data/scenes/Game/GameChat/game_chat.tscn create mode 100644 data/scenes/Game/Scripts/Sinhronizers/ChatSinhronizer.gd create mode 100644 data/scenes/Game/StartPanel/connected_panel.gd create mode 100644 data/scenes/Game/StartPanel/connected_panel.tscn create mode 100644 data/scenes/lobbies/Lob174C.tmp diff --git a/data/scenes/Game/GameChat/game_chat.tscn b/data/scenes/Game/GameChat/game_chat.tscn new file mode 100644 index 0000000..3a10de6 --- /dev/null +++ b/data/scenes/Game/GameChat/game_chat.tscn @@ -0,0 +1,143 @@ +[gd_scene load_steps=4 format=3 uid="uid://jfqkb4y8h1rq"] + +[ext_resource type="FontFile" uid="uid://dhvfket83gjln" path="res://data/styles/fonts/Roboto-Regular.ttf" id="1_dcpst"] + +[sub_resource type="GDScript" id="GDScript_bvg37"] +script/source = "extends ColorRect + + +@export var GameChat : RichTextLabel +@export var InputText : LineEdit + +## On client send message to chat +signal sending_message(message:String) + + +func _ready(): + GameChat.clear() + GameChat.scroll_following = true + + +func add_message(_name, _message): + GameChat.append_text(\"# \") + GameChat.push_color(Color.DARK_ORANGE) + GameChat.append_text(_name) + GameChat.pop() + GameChat.append_text(\" : \") + GameChat.append_text(_message) + GameChat.newline() + if GATEWAY.debug: + print(\"Get new game chat message\") + + +func send_message(_message): + sending_message.emit(_message) + if GATEWAY.debug: + print(\"Send new game chat message\") + + +func _on_game_chat_send_btn_button_up(): + if !InputText.text.is_empty(): + self.send_message(InputText.text) + InputText.text = \"\" +" + +[sub_resource type="GDScript" id="GDScript_opgwe"] +script/source = "extends LineEdit + + +@export var GameChatController : ColorRect + + +func _process(_delta): + if self.has_focus() and Input.is_key_pressed(KEY_ENTER): + if !self.text.is_empty(): + GameChatController.send_message(self.text) + self.text = \"\" +" + +[node name="GameChatBackground" type="ColorRect" node_paths=PackedStringArray("GameChat", "InputText")] +size_flags_horizontal = 3 +color = Color(0.215902, 0.215902, 0.215902, 1) +script = SubResource("GDScript_bvg37") +GameChat = NodePath("GameChatMarginContainer/GameChatContainer/GameChatPanel/GameChat") +InputText = NodePath("GameChatMarginContainer/GameChatContainer/GameChatBtnContainer/GameChatInput") + +[node name="GameChatMarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="GameChatContainer" type="VBoxContainer" parent="GameChatMarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 10 + +[node name="ControlContainer" type="HBoxContainer" parent="GameChatMarginContainer/GameChatContainer"] +layout_mode = 2 + +[node name="GameChatTitle" type="Label" parent="GameChatMarginContainer/GameChatContainer/ControlContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +text = "$GameChat" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="MinMaxButton" type="Button" parent="GameChatMarginContainer/GameChatContainer/ControlContainer"] +visible = false +layout_direction = 2 +layout_mode = 2 +size_flags_horizontal = 10 +size_flags_vertical = 0 +auto_translate = false +localize_numeral_system = false +mouse_default_cursor_shape = 2 +theme_override_font_sizes/font_size = 16 +shortcut_feedback = false +shortcut_in_tooltip = false +text = "$Minimize" +flat = true + +[node name="GameChatPanel" type="Panel" parent="GameChatMarginContainer/GameChatContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="GameChat" type="RichTextLabel" parent="GameChatMarginContainer/GameChatContainer/GameChatPanel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +theme_override_fonts/normal_font = ExtResource("1_dcpst") +theme_override_font_sizes/normal_font_size = 15 +bbcode_enabled = true +text = "# PlayerName : Text text text. Text text text. Text text text. Text text text. Text text text. Text text text." +scroll_following = true +shortcut_keys_enabled = false +deselect_on_focus_loss_enabled = false +drag_and_drop_selection_enabled = false +metadata/_edit_use_anchors_ = true + +[node name="GameChatBtnContainer" type="HBoxContainer" parent="GameChatMarginContainer/GameChatContainer"] +layout_mode = 2 +theme_override_constants/separation = 10 + +[node name="GameChatInput" type="LineEdit" parent="GameChatMarginContainer/GameChatContainer/GameChatBtnContainer" node_paths=PackedStringArray("GameChatController")] +layout_mode = 2 +size_flags_horizontal = 3 +script = SubResource("GDScript_opgwe") +GameChatController = NodePath("../../../..") + +[node name="GameChatSendBtn" type="Button" parent="GameChatMarginContainer/GameChatContainer/GameChatBtnContainer"] +layout_mode = 2 +text = "$Send" + +[connection signal="button_up" from="GameChatMarginContainer/GameChatContainer/GameChatBtnContainer/GameChatSendBtn" to="." method="_on_game_chat_send_btn_button_up"] diff --git a/data/scenes/Game/Scripts/Sinhronizers/ChatSinhronizer.gd b/data/scenes/Game/Scripts/Sinhronizers/ChatSinhronizer.gd new file mode 100644 index 0000000..43da257 --- /dev/null +++ b/data/scenes/Game/Scripts/Sinhronizers/ChatSinhronizer.gd @@ -0,0 +1,27 @@ +extends Node + +var players : Array + +## On get new message +signal get_new_message(name:String, message:String) + + +func _on_game_game_info_changed(_gameGata): + players = _gameGata.players + + +func _on_connected_panel_send_message(_message): + self.rpc_id(1, "rpc_send_message", GATEWAY.clientId, _message, players, GATEWAY.playerToken) + + +#--------------------------------------------------------------------------------------------------- +# RPC Client +@rpc("authority", "call_local", "unreliable", 10) +func rpc_add_message(_name, _message): + get_new_message.emit(_name, _message) + + +#--------------------------------------------------------------------------------------------------- +# RPC Server +@rpc("any_peer", "call_local", "unreliable", 10) +func rpc_send_message(_client_id, _message, _players, _token): pass diff --git a/data/scenes/Game/StartPanel/connected_panel.gd b/data/scenes/Game/StartPanel/connected_panel.gd new file mode 100644 index 0000000..15415d6 --- /dev/null +++ b/data/scenes/Game/StartPanel/connected_panel.gd @@ -0,0 +1,39 @@ +extends Panel + + +@export var Chat : ColorRect +@export var GameName : Label +@export var LeaderName : Label +@export var Players : Label +@export var PlayersInfo : Label +var gameId : int + +signal send_message(_message:String) +signal disconnect_self + + +func add_message(_name, _message): + Chat.add_message(_name, _message) + + +func _on_game_chat_background_sending_message(message): + send_message.emit(message) + + +func _on_chat_sinhronizer_get_new_message(_name, message): + add_message(_name, message) + + +func _on_game_game_info_changed(gameInfo): + gameId = gameInfo.gameId + PlayersInfo.text = "" + GameName.text = gameInfo.gameName + LeaderName.text = gameInfo.ownerName + Players.text = "%s/%s" % [len(gameInfo.players), gameInfo.maxPlayers] + if len(gameInfo.players_info) > 0: + for player in gameInfo.players_info: + PlayersInfo.text += "%s\n" % [gameInfo.players_info[player]["name"]] + + +func _on_back_button_need_disconecct(): + disconnect_self.emit() diff --git a/data/scenes/Game/StartPanel/connected_panel.tscn b/data/scenes/Game/StartPanel/connected_panel.tscn new file mode 100644 index 0000000..6a5ed4a --- /dev/null +++ b/data/scenes/Game/StartPanel/connected_panel.tscn @@ -0,0 +1,193 @@ +[gd_scene load_steps=5 format=3 uid="uid://8qdk7tbki7tb"] + +[ext_resource type="Script" path="res://data/scenes/Game/StartPanel/connected_panel.gd" id="1_plf8o"] +[ext_resource type="PackedScene" uid="uid://jfqkb4y8h1rq" path="res://data/scenes/Game/GameChat/game_chat.tscn" id="1_u3fum"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yapw7"] +content_margin_left = 10.0 +content_margin_top = 10.0 +content_margin_right = 10.0 +content_margin_bottom = 10.0 +bg_color = Color(0.180005, 0.180005, 0.180005, 1) +border_width_left = 5 +border_width_top = 5 +border_width_right = 5 +border_width_bottom = 5 +border_color = Color(0.707602, 0.575264, 0, 1) +border_blend = true +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 +expand_margin_left = 5.0 +expand_margin_top = 5.0 +expand_margin_right = 5.0 +expand_margin_bottom = 5.0 + +[sub_resource type="GDScript" id="GDScript_vgbeq"] +script/source = "extends Button + + +signal need_disconecct + + +func _on_button_up(): + need_disconecct.emit() +" + +[node name="ConnectedPanel" type="Panel" node_paths=PackedStringArray("Chat", "GameName", "LeaderName", "Players", "PlayersInfo")] +custom_minimum_size = Vector2(512, 256) +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_yapw7") +script = ExtResource("1_plf8o") +Chat = NodePath("MarginContainer/MainContainer/MainItemsContainer/GameChatBackground") +GameName = NodePath("MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer/GameName") +LeaderName = NodePath("MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_2/LeaderName") +Players = NodePath("MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_3/Players") +PlayersInfo = NodePath("MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_4/ScrollContainer/PlayersInfo") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="MainContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="Title" type="Label" parent="MarginContainer/MainContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +theme_override_font_sizes/font_size = 18 +text = "$ConnectToGame" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="MainItemsContainer" type="HBoxContainer" parent="MarginContainer/MainContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 25 +alignment = 1 + +[node name="MainRowsContainer" type="VBoxContainer" parent="MarginContainer/MainContainer/MainItemsContainer"] +layout_mode = 2 +size_flags_horizontal = 0 +theme_override_constants/separation = 5 + +[node name="RowContainer" type="HBoxContainer" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer"] +layout_mode = 2 +theme_override_constants/separation = 15 + +[node name="Label" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +text = "$GameName" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="GameName" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "The game name" + +[node name="RowContainer_2" type="HBoxContainer" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer"] +layout_mode = 2 +theme_override_constants/separation = 15 + +[node name="Label" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_2"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +text = "$GameLeader" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="LeaderName" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_2"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "The game leader name" + +[node name="RowContainer_3" type="HBoxContainer" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer"] +layout_mode = 2 +theme_override_constants/separation = 15 + +[node name="Label" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_3"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +text = "$Players" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Players" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_3"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "0/5" + +[node name="RowContainer_4" type="HBoxContainer" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 15 + +[node name="Label" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_4"] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +text = "$InGameLobbie" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_4"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="PlayersInfo" type="Label" parent="MarginContainer/MainContainer/MainItemsContainer/MainRowsContainer/RowContainer_4/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +text = "User-1 +User-2 +User-3 +" +horizontal_alignment = 2 + +[node name="GameChatBackground" parent="MarginContainer/MainContainer/MainItemsContainer" instance=ExtResource("1_u3fum")] +clip_contents = true +custom_minimum_size = Vector2(200, 200) +layout_mode = 2 +auto_translate = false +localize_numeral_system = false + +[node name="ButtonsContainer" type="HBoxContainer" parent="MarginContainer/MainContainer"] +layout_mode = 2 +size_flags_vertical = 8 +theme_override_constants/separation = 10 + +[node name="StartButton" type="Button" parent="MarginContainer/MainContainer/ButtonsContainer"] +visible = false +layout_mode = 2 +disabled = true +text = "$StartGame" + +[node name="ReadyButton" type="Button" parent="MarginContainer/MainContainer/ButtonsContainer"] +visible = false +layout_mode = 2 +text = "$ReadyGame" + +[node name="BackButton" type="Button" parent="MarginContainer/MainContainer/ButtonsContainer"] +layout_mode = 2 +size_flags_horizontal = 10 +text = "$Back" +script = SubResource("GDScript_vgbeq") + +[connection signal="sending_message" from="MarginContainer/MainContainer/MainItemsContainer/GameChatBackground" to="." method="_on_game_chat_background_sending_message"] +[connection signal="button_up" from="MarginContainer/MainContainer/ButtonsContainer/BackButton" to="MarginContainer/MainContainer/ButtonsContainer/BackButton" method="_on_button_up"] +[connection signal="need_disconecct" from="MarginContainer/MainContainer/ButtonsContainer/BackButton" to="." method="_on_back_button_need_disconecct"] diff --git a/data/scenes/Game/game.gd b/data/scenes/Game/game.gd index 3b33bed..caea059 100644 --- a/data/scenes/Game/game.gd +++ b/data/scenes/Game/game.gd @@ -10,14 +10,16 @@ var players : Array var players_info : Dictionary var maxPlayers : int var gamePassword : String +var instanceName: String var isStarted : bool #--------------------------------------------------------------------------------------------------# # Signals -signal game_info_changed +signal game_info_changed(gameInfo:Dictionary) signal game_created +signal game_empty #--------------------------------------------------------------------------------------------------# @@ -31,7 +33,8 @@ func get_game_info(): players_info = self.players_info, maxPlayers = self.maxPlayers, gamePassword = self.gamePassword, - isStarted = self.isStarted + isStarted = self.isStarted, + instanceName = self.instanceName } @@ -42,22 +45,25 @@ func set_game_info(_gameSettings:Dictionary, isLocal:bool = true): self.maxPlayers = _gameSettings.maxPlayers self.gamePassword = _gameSettings.gamePassword self.name = str(_gameSettings.gameId) + self.instanceName = _gameSettings.instanceName + self.players = _gameSettings.players + self.players_info = _gameSettings.players_info self.isStarted = false _emmit_game_info_changed() if isLocal: - self.rpc_id(1, "rpc_game_info_changed", get_game_info()) + self.rpc_id(1, "rpc_game_info_changed", get_game_info(), GATEWAY.playerToken) func connect_player(_clientId:int): - self.rpc_id(1, "rpc_set_player", _clientId) + self.rpc_id(1, "rpc_set_player", _clientId, GATEWAY.playerToken) func disconnect_player(_clientId:int): - self.rpc_id(1, "rpc_unset_player", _clientId) + self.rpc_id(1, "rpc_unset_player", _clientId, GATEWAY.playerToken) func added_player(_player:Dictionary): - players.push_back(_player.id) + players.push_back(int(_player.id)) players_info[_player.id] = { 'login' = _player.login, 'name' = _player.name @@ -69,6 +75,17 @@ func delete_player(_clientId:int): players.erase(_clientId) players_info.erase(_clientId) _emmit_game_info_changed() + if _clientId == GATEWAY.clientId: + GATEWAY.is_reconnected = true + var Lobbies = get_node("/root/Lobbies") + var current_scene = get_tree().get_current_scene() + get_tree().set_current_scene(Lobbies) + current_scene.queue_free() + multiplayer.server_disconnected.emit() + + +func close_game(): + emit_signal("game_empty") #--------------------------------------------------------------------------------------------------# @@ -77,6 +94,17 @@ func _on_game_created(): self.connect_player(GATEWAY.clientId) +func _on_connected_panel_disconnect_self(): + self.disconnect_player(GATEWAY.clientId) + + +func _on_game_empty(): + var Lobbies = get_node("/root/Lobbies") + var current_scene = get_tree().get_current_scene() + get_tree().set_current_scene(Lobbies) + current_scene.queue_free() + + #--------------------------------------------------------------------------------------------------# # Signals emmit func _emmit_game_info_changed(): @@ -100,15 +128,24 @@ func rpc_unset_player_info(_clientId:int): delete_player(_clientId) +@rpc("authority", "call_local", "reliable", 3) +func rpc_close_game(): + close_game() + + #--------------------------------------------------------------------------------------------------- # RPC Server @rpc("any_peer", "call_local", "reliable", 3) -func rpc_game_info_changed(_gameSettings:Dictionary): pass +func rpc_game_info_changed(_gameSettings:Dictionary, _token:String): pass @rpc("any_peer", "call_local", "reliable", 3) -func rpc_set_player(_clientId:int): pass +func rpc_set_player(_clientId:int, _token:String): pass @rpc("any_peer", "call_local", "reliable", 3) -func rpc_unset_player(_clientId:int): pass +func rpc_unset_player(_clientId:int, _token:String): pass + + +@rpc("any_peer", "call_local", "reliable", 3) +func rpc_set_close_game(_gameId:int, _token:String): pass diff --git a/data/scenes/Game/game.tscn b/data/scenes/Game/game.tscn index afe160d..ca209b3 100644 --- a/data/scenes/Game/game.tscn +++ b/data/scenes/Game/game.tscn @@ -1,8 +1,21 @@ -[gd_scene load_steps=2 format=3 uid="uid://u3ht16dhk3iq"] +[gd_scene load_steps=4 format=3 uid="uid://u3ht16dhk3iq"] [ext_resource type="Script" path="res://data/scenes/Game/game.gd" id="1_2bjjo"] +[ext_resource type="PackedScene" uid="uid://8qdk7tbki7tb" path="res://data/scenes/Game/StartPanel/connected_panel.tscn" id="2_depbf"] +[ext_resource type="Script" path="res://data/scenes/Game/Scripts/Sinhronizers/ChatSinhronizer.gd" id="2_ekkht"] [node name="Game" type="Node"] script = ExtResource("1_2bjjo") +[node name="ChatSinhronizer" type="Node" parent="."] +script = ExtResource("2_ekkht") + +[node name="ConnectedPanel" parent="." instance=ExtResource("2_depbf")] + [connection signal="game_created" from="." to="." method="_on_game_created"] +[connection signal="game_empty" from="." to="." method="_on_game_empty"] +[connection signal="game_info_changed" from="." to="ChatSinhronizer" method="_on_game_game_info_changed"] +[connection signal="game_info_changed" from="." to="ConnectedPanel" method="_on_game_game_info_changed"] +[connection signal="get_new_message" from="ChatSinhronizer" to="ConnectedPanel" method="_on_chat_sinhronizer_get_new_message"] +[connection signal="disconnect_self" from="ConnectedPanel" to="." method="_on_connected_panel_disconnect_self"] +[connection signal="send_message" from="ConnectedPanel" to="ChatSinhronizer" method="_on_connected_panel_send_message"] diff --git a/data/scenes/HELPERS/PopUps/game_panel.tscn b/data/scenes/HELPERS/PopUps/game_panel.tscn index 3fec6ce..049ab53 100644 --- a/data/scenes/HELPERS/PopUps/game_panel.tscn +++ b/data/scenes/HELPERS/PopUps/game_panel.tscn @@ -79,7 +79,6 @@ text = "$GameName" [node name="GameName" type="LineEdit" parent="MarginContainer/GameVBoxContainer/Game_SettingsContainer/GameNameBox"] layout_mode = 2 size_flags_horizontal = 3 -alignment = 2 [node name="MaxPlayersBox" type="HBoxContainer" parent="MarginContainer/GameVBoxContainer/Game_SettingsContainer"] layout_mode = 2 diff --git a/data/scenes/Player/Player.gd b/data/scenes/Player/Player.gd index fc0cb30..d2913da 100644 --- a/data/scenes/Player/Player.gd +++ b/data/scenes/Player/Player.gd @@ -4,6 +4,7 @@ extends Node2D var clientId : int var playerName : String var token : String +var login : String #--------------------------------------------------------------------------------------------------# @@ -15,6 +16,16 @@ func _init(): set_physics_process(0) +func autentification_failed(): + GATEWAY.is_reconnected = false + multiplayer.server_disconnected.emit() + + +func autentification_confirm(): + playerName = GATEWAY.playerName + token = GATEWAY.playerToken + login = GATEWAY.playerLogin + #--------------------------------------------------------------------------------------------------# # RPC Client @rpc("authority", "reliable", "call_remote", 1) @@ -22,6 +33,16 @@ func authorizated(_name, _token, _isAuthorized): if _isAuthorized: token = _token playerName = _name + GATEWAY.playerToken = _token + GATEWAY.playerName = _name GATEWAY.emit_signal("authorizated") else: GATEWAY.emit_signal("unauthorizated") + + +@rpc("authority", "reliable", "call_local", 1) +func autentificated(_isAuth:bool): + if !_isAuth: + autentification_failed() + else: + autentification_confirm() diff --git a/data/scenes/lobbies/ChatSinhronizer.gd b/data/scenes/lobbies/ChatSinhronizer.gd index f3d75b0..2386f21 100644 --- a/data/scenes/lobbies/ChatSinhronizer.gd +++ b/data/scenes/lobbies/ChatSinhronizer.gd @@ -10,7 +10,7 @@ func _ready(): func send_message(_message): - self.rpc_id(1, "rpc_send_message", GATEWAY.clientId, _message) + self.rpc_id(1, "rpc_send_message", GATEWAY.clientId, _message, GATEWAY.playerToken) if GATEWAY.debug: print("Send new message") @@ -33,4 +33,4 @@ func rpc_add_message(_name, _message): #--------------------------------------------------------------------------------------------------- # RPC Server @rpc("any_peer", "call_local", "unreliable", 9) -func rpc_send_message(_client_id, _message): pass +func rpc_send_message(_client_id, _message, _token): pass diff --git a/data/scenes/lobbies/GameLabel.gd b/data/scenes/lobbies/GameLabel.gd index 08407fe..1e028bb 100644 --- a/data/scenes/lobbies/GameLabel.gd +++ b/data/scenes/lobbies/GameLabel.gd @@ -2,14 +2,15 @@ extends Label var gameId : int +var instanceName: String var ownerName : String var gameName : String -var players : Array var maxPlayers : int var gamePassword : String - var isStarted : bool +signal left_mouse_button_clicked(instanceName:String) + func set_game_data(_data:Dictionary): self.gameId = _data.gameId @@ -19,11 +20,16 @@ func set_game_data(_data:Dictionary): self.gamePassword = _data.gamePassword self.name = str(_data.gameId) self.isStarted = _data.isStarted + self.instanceName = _data.instanceName self.text = "%s | %s | %s | " % [_data.gameName, _data.ownerName, _data.maxPlayers] if _data.gamePassword != "": self.text += "PASSWORD" else: self.text += "OPEN" + if isStarted: + self.text += " | Close" + else: + self.text += " | Wait" func get_game_data() -> Dictionary: @@ -35,3 +41,22 @@ func get_game_data() -> Dictionary: gamePassword = self.gamePassword, isStarted = self.isStarted } + + +func _input(event: InputEvent): + if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: + if __is_mouse_over_label( + get_global_mouse_position(), + self.get_global_transform().origin, + self.size + ): + self.left_mouse_button_clicked.emit(self.instanceName) + + +func __is_mouse_over_label(mouse_pos:Vector2, label_pos:Vector2, label_size:Vector2) -> bool: + return ( + mouse_pos.x >= label_pos.x and + mouse_pos.x <= label_pos.x + label_size.x and + mouse_pos.y >= label_pos.y and + mouse_pos.y <= label_pos.y + label_size.y + ) diff --git a/data/scenes/lobbies/GameLabel.tscn b/data/scenes/lobbies/GameLabel.tscn index 28363a0..23d782d 100644 --- a/data/scenes/lobbies/GameLabel.tscn +++ b/data/scenes/lobbies/GameLabel.tscn @@ -14,7 +14,7 @@ Label/constants/shadow_outline_size = 1 Label/font_sizes/font_size = 16 [node name="Label" type="Label"] -mouse_filter = 1 +mouse_filter = 0 mouse_default_cursor_shape = 2 theme = SubResource("Theme_4x7tq") text = "Game number 1" diff --git a/data/scenes/lobbies/GamesSinhronizer.gd b/data/scenes/lobbies/GamesSinhronizer.gd index 8c1591b..7eacbd2 100644 --- a/data/scenes/lobbies/GamesSinhronizer.gd +++ b/data/scenes/lobbies/GamesSinhronizer.gd @@ -6,21 +6,23 @@ extends Node @export var PopUpError : PopupPanel @export var LobbieUI : Control @export var GamePanel : Panel +@export var ContinueGame : Button func _ready(): - rpc_id(1, "rpc_get_games_list") + rpc_id(1, "rpc_get_games_list", GATEWAY.playerToken) + multiplayer.connected_to_server.connect(_on_search_button_button_up) func create_game(_gameData:Dictionary): - rpc_id(1, "rpc_create_game", _gameData) + rpc_id(1, "rpc_create_game", _gameData, GATEWAY.playerToken) func _on_search_button_button_up(): if SearchLine.text == "": - rpc_id(1, "rpc_get_games_list") + rpc_id(1, "rpc_get_games_list", GATEWAY.playerToken) else: - rpc_id(1, "rpc_get_game", SearchLine.text) + rpc_id(1, "rpc_get_game", SearchLine.text, GATEWAY.playerToken) func _on_create_game_button_up(): @@ -29,11 +31,13 @@ func _on_create_game_button_up(): func _on_popup_error_user_push_ok(): LobbieUI.visible = true + rpc_id(1, "rpc_get_games_list", GATEWAY.playerToken) GamePanel.emit_signal("back_pushed") func _on_game_panel_back_pushed(): GamePanel.visible = false + rpc_id(1, "rpc_get_games_list", GATEWAY.playerToken) func _on_game_panel_create_pushed(_data): @@ -50,19 +54,51 @@ func _on_game_panel_create_pushed(_data): create_game(gameData) +func _on_game_label_clicked(_instanceName): + rpc_id(1, "rpc_get_game_info", _instanceName, GATEWAY.playerToken) + if GATEWAY.debug: + print("Game label clicked, instance: ", _instanceName) + + +func _on_continue_game_button_up(): + rpc_id(1, "rpc_get_game_info", ContinueGame.instanceName, GATEWAY.playerToken) + if GATEWAY.debug: + print("Connect to self game") + + +#--------------------------------------------------------------------------------------------------- +# Functions +func connect_to_game(_gameData): + var Game = preload("res://data/scenes/Game/game.tscn").instantiate() + get_tree().root.add_child(Game) + Game.set_game_info(_gameData, false) + Game.connect_player(GATEWAY.clientId) + get_tree().set_current_scene(Game) + + #--------------------------------------------------------------------------------------------------- # RPC Client @rpc("authority", "call_local", "unreliable", 2) func rpc_set_games_list(_games:Array): + ContinueGame.visible = false var games_count = GameBox.get_child_count() while games_count > 0: var game = GameBox.get_child(games_count - 1) + if game.has_signal("left_mouse_button_clicked"): + if game.is_connected("left_mouse_button_clicked", _on_game_label_clicked): + game.disconnect("left_mouse_button_clicked", _on_game_label_clicked) get_node(game.get_path()).queue_free() games_count -= 1 if _games.size() > 0: for game in _games: + if game.has("isMy"): + ContinueGame.visible = true + ContinueGame.instanceName = game.instanceName var gameLabel = preload("res://data/scenes/lobbies/GameLabel.tscn").instantiate() + await get_tree().create_timer(0.5).timeout gameLabel.set_game_data(game) + if not gameLabel.is_connected("left_mouse_button_clicked", _on_game_label_clicked): + gameLabel.left_mouse_button_clicked.connect(_on_game_label_clicked) GameBox.add_child(gameLabel) if GATEWAY.debug: print("Get games list") @@ -73,10 +109,11 @@ func rpc_game_created(_game:Dictionary): var game_instance = preload("res://data/scenes/Game/game.tscn").instantiate() game_instance.set_game_info(_game, false) get_tree().root.add_child(game_instance) - get_node("/root/%s" % [_game.gameId]).emit_signal("game_created") + game_instance.emit_signal("game_created") + GamePanel.visible = false + get_tree().set_current_scene(game_instance) if GATEWAY.debug: print("Created new game") - get_node("/root/Lobbies").queue_free() @rpc("authority", "call_local", "unreliable", 2) @@ -87,6 +124,13 @@ func rpc_cant_create_game(_message : String): print("Can`t create game") +@rpc("authority", "call_local", "unreliable", 2) +func rpc_set_game_info(_gameData:Dictionary): + connect_to_game(_gameData) + if GATEWAY.debug: + print("Get game info") + + #--------------------------------------------------------------------------------------------------- # RPC Server @rpc("any_peer", "call_local", "unreliable", 2) @@ -99,3 +143,7 @@ func rpc_get_games_list(): pass @rpc("any_peer", "call_local", "unreliable", 2) func rpc_get_game(_name:String): pass + + +@rpc("any_peer", "call_local", "reliable", 2) +func rpc_get_game_info(_instanceName:String): pass diff --git a/data/scenes/lobbies/Lob174C.tmp b/data/scenes/lobbies/Lob174C.tmp new file mode 100644 index 0000000..2288083 --- /dev/null +++ b/data/scenes/lobbies/Lob174C.tmp @@ -0,0 +1,216 @@ +[gd_scene load_steps=6 format=3 uid="uid://d4nhi3k0agm2q"] + +[ext_resource type="FontFile" uid="uid://dhvfket83gjln" path="res://data/styles/fonts/Roboto-Regular.ttf" id="1_qbt18"] +[ext_resource type="Script" path="res://data/scenes/lobbies/GamesSinhronizer.gd" id="2_a6k32"] +[ext_resource type="Script" path="res://data/scenes/lobbies/ChatSinhronizer.gd" id="2_cc8va"] + +[sub_resource type="GDScript" id="GDScript_2o8xy"] +script/source = "extends LineEdit + + +@export var ChatSinhronizer : Node + + +func _process(_delta): + if self.has_focus() and Input.is_key_pressed(KEY_ENTER): + if !self.text.is_empty(): + ChatSinhronizer.send_message(self.text) + self.text = \"\" +" + +[sub_resource type="GDScript" id="GDScript_4mwjp"] +script/source = "extends Button + + +func _ready(): + multiplayer.server_disconnected.connect(_server_disconnect) + + +func _on_button_up(): + multiplayer.emit_signal(\"server_disconnected\") + + +func _server_disconnect(): + get_tree().change_scene_to_packed(load(\"res://data/scenes/main_menu/main_menu.tscn\")) +" + +[node name="Lobbies" type="Node"] + +[node name="ChatSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GlobalChat")] +script = ExtResource("2_cc8va") +GlobalChat = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/Panel/GlobalChat") + +[node name="GamesSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GameBox", "SearchLine")] +script = ExtResource("2_a6k32") +GameBox = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll/GamesBox") +SearchLine = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search/GameSearch") + +[node name="LobbieUI" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Background" type="ColorRect" parent="LobbieUI"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.125911, 0.125911, 0.125911, 1) + +[node name="MainMarginContainer" type="MarginContainer" parent="LobbieUI"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="MainUIContainer" type="VBoxContainer" parent="LobbieUI/MainMarginContainer"] +layout_mode = 2 + +[node name="MainContainer" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/separation = 10 +alignment = 1 + +[node name="GamesBackground" type="ColorRect" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +color = Color(0.215902, 0.215902, 0.215902, 1) + +[node name="GamesMarginContainer" type="MarginContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="GamesContainer" type="VBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer"] +layout_mode = 2 + +[node name="GamesTitle" type="Label" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +theme_override_fonts/font = ExtResource("1_qbt18") +theme_override_font_sizes/font_size = 16 +text = "$Games" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Search" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer"] +layout_mode = 2 + +[node name="GameSearch" type="LineEdit" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search"] +layout_mode = 2 +size_flags_horizontal = 3 +placeholder_text = "$search_game" + +[node name="SearchButton" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search"] +layout_mode = 2 +text = "$Search" + +[node name="GamesScroll" type="ScrollContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 +vertical_scroll_mode = 2 + +[node name="GamesBox" type="VBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 10 + +[node name="GlobalChatBackground" type="ColorRect" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +color = Color(0.215902, 0.215902, 0.215902, 1) + +[node name="GlobalChatMarginContainer" type="MarginContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="GlobalChatContainer" type="VBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer"] +layout_mode = 2 + +[node name="GlobalChatTitle" type="Label" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer"] +layout_mode = 2 +theme_override_colors/font_color = Color(0.707602, 0.575264, 0, 1) +theme_override_fonts/font = ExtResource("1_qbt18") +theme_override_font_sizes/font_size = 16 +text = "$GlobalChat" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Panel" type="Panel" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer"] +layout_mode = 2 +size_flags_vertical = 3 + +[node name="GlobalChat" type="RichTextLabel" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/Panel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +theme_override_fonts/normal_font = ExtResource("1_qbt18") +theme_override_font_sizes/normal_font_size = 15 +bbcode_enabled = true +text = "# PlayerName : Text text text. Text text text. Text text text. Text text text. Text text text. Text text text." +scroll_following = true +shortcut_keys_enabled = false +deselect_on_focus_loss_enabled = false +drag_and_drop_selection_enabled = false +metadata/_edit_use_anchors_ = true + +[node name="GlobalChatMessage" type="LineEdit" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer" node_paths=PackedStringArray("ChatSinhronizer")] +layout_mode = 2 +size_flags_vertical = 8 +placeholder_text = "$your_message" +caret_blink = true +script = SubResource("GDScript_2o8xy") +ChatSinhronizer = NodePath("../../../../../../../../ChatSinhronizer") + +[node name="ButtonsContainer" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer"] +layout_mode = 2 + +[node name="CreateGame" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"] +layout_mode = 2 +size_flags_horizontal = 2 +text = "$CreateGame" + +[node name="Back" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"] +layout_mode = 2 +size_flags_horizontal = 10 +size_flags_vertical = 8 +theme_override_fonts/font = ExtResource("1_qbt18") +theme_override_font_sizes/font_size = 15 +text = "$Back" +script = SubResource("GDScript_4mwjp") + +[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search/SearchButton" to="GamesSinhronizer" method="_on_search_button_button_up"] +[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" to="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" method="_on_button_up"] diff --git a/data/scenes/lobbies/Lobbies.tscn b/data/scenes/lobbies/Lobbies.tscn index 136ddb4..a30fb2e 100644 --- a/data/scenes/lobbies/Lobbies.tscn +++ b/data/scenes/lobbies/Lobbies.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://d4nhi3k0agm2q"] +[gd_scene load_steps=10 format=3 uid="uid://d4nhi3k0agm2q"] [ext_resource type="FontFile" uid="uid://dhvfket83gjln" path="res://data/styles/fonts/Roboto-Regular.ttf" id="1_qbt18"] [ext_resource type="Script" path="res://data/scenes/lobbies/GamesSinhronizer.gd" id="2_a6k32"] @@ -20,31 +20,43 @@ func _process(_delta): self.text = \"\" " +[sub_resource type="GDScript" id="GDScript_1d6b7"] +script/source = "extends Button + +@export var ChatSinhronizer : Node +@export var InputText : LineEdit + + +func _on_button_up(): + if !InputText.text.is_empty(): + ChatSinhronizer.send_message(InputText.text) + InputText.text = \"\" +" + +[sub_resource type="GDScript" id="GDScript_o4vgu"] +script/source = "extends Button + +var instanceName : String +" + [sub_resource type="GDScript" id="GDScript_4mwjp"] script/source = "extends Button -func _ready(): - multiplayer.server_disconnected.connect(_server_disconnect) - - func _on_button_up(): multiplayer.emit_signal(\"server_disconnected\") - - -func _server_disconnect(): - get_tree().change_scene_to_packed(load(\"res://data/scenes/main_menu/main_menu.tscn\")) " [node name="Lobbies" type="Node"] -[node name="GamesSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GameBox", "SearchLine", "PopUpError", "LobbieUI", "GamePanel")] +[node name="GamesSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GameBox", "SearchLine", "PopUpError", "LobbieUI", "GamePanel", "ContinueGame")] script = ExtResource("2_a6k32") GameBox = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/GamesScroll/GamesBox") SearchLine = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search/GameSearch") PopUpError = NodePath("../PopupError") LobbieUI = NodePath("../LobbieUI") GamePanel = NodePath("../LobbieUI/MainMarginContainer/GamePanel") +ContinueGame = NodePath("../LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/ContinueGame") [node name="ChatSinhronizer" type="Node" parent="." node_paths=PackedStringArray("GlobalChat")] script = ExtResource("2_cc8va") @@ -195,13 +207,24 @@ deselect_on_focus_loss_enabled = false drag_and_drop_selection_enabled = false metadata/_edit_use_anchors_ = true -[node name="GlobalChatMessage" type="LineEdit" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer" node_paths=PackedStringArray("ChatSinhronizer")] +[node name="InputContainer" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer"] layout_mode = 2 + +[node name="GlobalChatMessage" type="LineEdit" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/InputContainer" node_paths=PackedStringArray("ChatSinhronizer")] +layout_mode = 2 +size_flags_horizontal = 3 size_flags_vertical = 8 placeholder_text = "$your_message" caret_blink = true script = SubResource("GDScript_2o8xy") -ChatSinhronizer = NodePath("../../../../../../../../ChatSinhronizer") +ChatSinhronizer = NodePath("../../../../../../../../../ChatSinhronizer") + +[node name="SendButton" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/InputContainer" node_paths=PackedStringArray("ChatSinhronizer", "InputText")] +layout_mode = 2 +text = "$Send" +script = SubResource("GDScript_1d6b7") +ChatSinhronizer = NodePath("../../../../../../../../../ChatSinhronizer") +InputText = NodePath("../GlobalChatMessage") [node name="ButtonsContainer" type="HBoxContainer" parent="LobbieUI/MainMarginContainer/MainUIContainer"] layout_mode = 2 @@ -211,6 +234,13 @@ layout_mode = 2 size_flags_horizontal = 2 text = "$CreateGame" +[node name="ContinueGame" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"] +visible = false +layout_mode = 2 +size_flags_horizontal = 4 +text = "$ContinueGame" +script = SubResource("GDScript_o4vgu") + [node name="Back" type="Button" parent="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer"] layout_mode = 2 size_flags_horizontal = 10 @@ -226,7 +256,9 @@ layout_mode = 2 [connection signal="user_push_ok" from="PopupError" to="GamesSinhronizer" method="_on_popup_error_user_push_ok"] [connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GamesBackground/GamesMarginContainer/GamesContainer/Search/SearchButton" to="GamesSinhronizer" method="_on_search_button_button_up"] +[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/InputContainer/SendButton" to="LobbieUI/MainMarginContainer/MainUIContainer/MainContainer/GlobalChatBackground/GlobalChatMarginContainer/GlobalChatContainer/InputContainer/SendButton" method="_on_button_up"] [connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/CreateGame" to="GamesSinhronizer" method="_on_create_game_button_up"] +[connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/ContinueGame" to="GamesSinhronizer" method="_on_continue_game_button_up"] [connection signal="button_up" from="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" to="LobbieUI/MainMarginContainer/MainUIContainer/ButtonsContainer/Back" method="_on_button_up"] [connection signal="back_pushed" from="LobbieUI/MainMarginContainer/GamePanel" to="GamesSinhronizer" method="_on_game_panel_back_pushed"] [connection signal="create_pushed" from="LobbieUI/MainMarginContainer/GamePanel" to="GamesSinhronizer" method="_on_game_panel_create_pushed"] diff --git a/data/scenes/main_menu/main_menu.gd b/data/scenes/main_menu/main_menu.gd index cd4eac0..c68eeba 100644 --- a/data/scenes/main_menu/main_menu.gd +++ b/data/scenes/main_menu/main_menu.gd @@ -49,6 +49,9 @@ func _on_login_btn_button_down(): func _on_connected_ok(): + var player = GATEWAY._get_player(GATEWAY.clientId) + if player: + player.login = LoginInput.text InfoText.text = "Connected to %s on port %s" % [GATEWAY.settings.Ip, GATEWAY.settings.Port] await get_tree().create_timer(5).timeout GATEWAY.rpc_id(1, 'authorization', LoginInput.text, PasswordInput.text.md5_text()) @@ -77,6 +80,7 @@ func _on_authorization_fail(): func _on_authorization_ok(): + GATEWAY.playerLogin = LoginInput.text start_lobbies() @@ -125,10 +129,15 @@ func _on_registration_ok(): RegistrationPasswordInput_2.editable = true LoginContainer.visible = true RegistrationContainer.visible = false + GATEWAY.playerLogin = RegistrationInput.text start_lobbies() #--------------------------------------------------------------------------------------------------# # Functions func start_lobbies(): - get_tree().change_scene_to_packed(load("res://data/scenes/lobbies/Lobbies.tscn")) + var Lobbies = preload("res://data/scenes/lobbies/Lobbies.tscn").instantiate() + var current_scene = get_tree().get_current_scene() + current_scene.queue_free() + get_tree().root.add_child(Lobbies) + get_tree().set_current_scene(Lobbies) diff --git a/data/scripts/objects/GateWay.gd b/data/scripts/objects/GateWay.gd index c5df176..05d1f5d 100644 --- a/data/scripts/objects/GateWay.gd +++ b/data/scripts/objects/GateWay.gd @@ -10,6 +10,10 @@ var settings : Dictionary = { Port = 3300, } var clientId : int +var playerName : String +var playerToken : String +var playerLogin : String +var is_reconnected : bool = false # Signals signal unauthorizated @@ -86,7 +90,14 @@ func _on_server_disconnected(): player.queue_free() if debug: print('Disconnected from server') - multiplayer.multiplayer_peer = null + multiplayer.multiplayer_peer.close() + if !is_reconnected: + var lobbies = get_node_or_null("Lobbies") + if lobbies: + lobbies.queue_free() + get_tree().change_scene_to_packed(load("res://data/scenes/main_menu/main_menu.tscn")) + else: + connect_to_server() func _on_connected_ok(): @@ -96,6 +107,9 @@ func _on_connected_ok(): player.clientId = clientId player.name = str(clientId) add_child(player) + if is_reconnected: + autentification.rpc_id(1, playerToken, playerLogin) + is_reconnected = false if debug: print('Connect to server') @@ -104,6 +118,9 @@ func _on_connected_fail(): if debug: print('Connection failed') multiplayer.multiplayer_peer = null + if is_reconnected: + is_reconnected = false + get_tree().change_scene_to_packed(load("res://data/scenes/main_menu/main_menu.tscn")) func _on_authorization_fail(): @@ -125,9 +142,15 @@ func _on_registration_fail(_reason : String): @rpc("any_peer", "reliable", "call_local", 1) func authorization(): pass + @rpc("any_peer", "reliable", "call_local", 1) func registration(): pass + +@rpc("any_peer", "reliable", "call_local", 1) +func autentification(_token: String): pass + + #--------------------------------------------------------------------------------------------------# # RPC Client @rpc("any_peer", "reliable", "call_local", 1) diff --git a/data/styles/locale/localization.csv b/data/styles/locale/localization.csv index 3df6f67..cf562d6 100644 --- a/data/styles/locale/localization.csv +++ b/data/styles/locale/localization.csv @@ -30,4 +30,13 @@ $only_one_game_for_one_player,Another game has already been created - Only one g $data_base_error,Data base error,Помилка бази даних,Ошибка базы данных $GameName,Game name,Назва гри,Название игры $MaxPlayers,Max players,Макс.гравців,Макс.игроков -$leave_empty_for_open_game,Leave blank for open play,Залиште поле порожнім для відкритої гри,Оставьте поле пустым для открытой игры \ No newline at end of file +$leave_empty_for_open_game,Leave blank for open play,Залиште поле порожнім для відкритої гри,Оставьте поле пустым для открытой игры +$Send,Send,Надіслати,Отправить +$ContinueGame,Continue game,Продовжити гру,Продолжить игру +$GameLeader,Game leader,Ведучій,Ведущий +$Players,Players count,Гравців,Игроков +$InGameLobbie,Players,Гравці,Игроки +$ConnectToGame,Join the game,Приєднатись до гри,Присоединяйтесь к игре +$GameChat,Game chat,Ігровий чат,Игровой чат +$StartGame,Start game,Почати гру,Начать игру +$ReadyGame,Ready,Готовий,Готов \ No newline at end of file diff --git a/project.godot b/project.godot index 99287b2..868d55c 100644 --- a/project.godot +++ b/project.godot @@ -33,6 +33,7 @@ GATEWAY="*res://data/scripts/objects/GateWay.gd" window/size/viewport_width=800 window/size/viewport_height=600 +window/stretch/mode="canvas_items" window/stretch/aspect="expand" window/ios/allow_high_refresh_rate=false window/ios/hide_home_indicator=false