summaryrefslogtreecommitdiff
path: root/Network/Lobby.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2023-12-25 00:21:50 +0100
committerDaniel Weipert <git@mail.dweipert.de>2023-12-25 00:21:50 +0100
commit0bfda86c29d106df5fa3dd16d925c193b3f726c7 (patch)
tree7d248694a63c346f5e82510b50405e34f8d5afe5 /Network/Lobby.gd
parent09794cc76678247592ceb4e8b37e1ab129356466 (diff)
UI + HUD alignmentv2.0.0
Diffstat (limited to 'Network/Lobby.gd')
-rw-r--r--Network/Lobby.gd67
1 files changed, 39 insertions, 28 deletions
diff --git a/Network/Lobby.gd b/Network/Lobby.gd
index 67a1f34..80b663b 100644
--- a/Network/Lobby.gd
+++ b/Network/Lobby.gd
@@ -1,6 +1,12 @@
extends Control
+var ConnectNodeContainer: Node
+var ConnectNode: Node
+var PlayersNodeContainer: Node
+var PlayersNode: Node
+
+
func _ready():
Network.connect("connection_succeeded", Callable(self, "_on_connection_succeeded"))
Network.connect("connection_failed", Callable(self, "_on_connection_failed"))
@@ -9,13 +15,18 @@ func _ready():
Network.connect("game_ended", Callable(self, "_on_game_ended"))
$HTTPRequest.connect("request_completed", Callable(self, '_set_remote_ip'))
+ ConnectNodeContainer = $CenterContainer
+ ConnectNode = $CenterContainer/Connect
+ PlayersNodeContainer = $CenterContainer2
+ PlayersNode = $CenterContainer2/Players
+
if OS.has_environment("USERNAME"):
- $Connect/Name.text = OS.get_environment("USERNAME")
+ ConnectNode.get_node("Name").text = OS.get_environment("USERNAME")
elif OS.has_environment("USER"):
- $Connect/Name.text = OS.get_environment("USER")
+ ConnectNode.get_node("Name").text = OS.get_environment("USER")
else:
var desktop_path = OS.get_system_dir(0).replace("\\", "/").split("/")
- $Connect/Name.text = desktop_path[desktop_path.size() - 2]
+ ConnectNode.get_node("Name").text = desktop_path[desktop_path.size() - 2]
# show lobby if we're already connected somewhere
if Network.peer != null:
@@ -25,20 +36,20 @@ func _ready():
func disable_connect_buttons(is_disabled = true):
- $Connect/Host.disabled = is_disabled
- $Connect/Join.disabled = is_disabled
+ ConnectNode.get_node("Host").disabled = is_disabled
+ ConnectNode.get_node("Join").disabled = is_disabled
func refresh_lobby():
var players = Network.players.values()
var player = Network.player
- $Players/List.clear()
- $Players/List.add_item(player.name + " (You)")
+ PlayersNode.get_node("List").clear()
+ PlayersNode.get_node("List").add_item(player.name + " (You)")
for p in players:
- $Players/List.add_item(p.name)
+ PlayersNode.get_node("List").add_item(p.name)
- $Players/Start.disabled = not multiplayer.is_server()
+ PlayersNode.get_node("Start").disabled = not multiplayer.is_server()
func set_ip():
@@ -48,29 +59,29 @@ func set_ip():
func set_local_ip():
for ip in IP.get_local_addresses():
if ip.begins_with("192.168"):
- $Players/LocalIP.text = ip
+ PlayersNode.get_node("LocalIP").text = ip
break
func set_remote_ip():
- $Players/RemoteIP.text = ""
+ PlayersNode.get_node("RemoteIP").text = ""
$HTTPRequest.request("https://ipv4.icanhazip.com/")
func _set_remote_ip(_result, response_code, _headers, body):
if response_code == 200:
- $Players/RemoteIP.text = body.get_string_from_utf8()
+ PlayersNode.get_node("RemoteIP").text = body.get_string_from_utf8()
else:
- $Players/RemoteIP.text = "Remote IP request failed!"
+ PlayersNode.get_node("RemoteIP").text = "Remote IP request failed!"
self._on_game_error("Remote IP request failed!")
func _on_connection_succeeded():
- $Connect.hide()
- $Players.show()
+ ConnectNodeContainer.hide()
+ PlayersNodeContainer.show()
func _on_connection_failed():
self.disable_connect_buttons()
- $Connect/Error.set_text("Connection failed!")
+ ConnectNode.get_node("Error").set_text("Connection failed!")
func _on_game_error(error):
@@ -81,34 +92,34 @@ func _on_game_error(error):
func _on_game_ended():
self.show()
- $Connect.show()
- $Players.hide()
+ ConnectNodeContainer.show()
+ PlayersNodeContainer.hide()
self.disable_connect_buttons()
func _on_Host_pressed():
- $Connect.hide()
- $Players.show()
- $Connect/Error.text = ""
+ ConnectNodeContainer.hide()
+ PlayersNodeContainer.show()
+ ConnectNode.get_node("Error").text = ""
self.set_ip()
- var player_name = $Connect/Name.text
+ var player_name = ConnectNode.get_node("Name").text
Network.host_game(player_name)
self.refresh_lobby()
func _on_Join_pressed():
- var ip = $Connect/IP.text
+ var ip = ConnectNode.get_node("IP").text
if not ip.is_valid_ip_address():
- $Connect/Error.text = "Invalid IP address!"
+ ConnectNode.get_node("Error").text = "Invalid IP address!"
return
- $Connect/Error.text = ""
+ ConnectNode.get_node("Error").text = ""
self.disable_connect_buttons(false)
self.set_ip()
- var player_name = $Connect/Name.text
+ var player_name = ConnectNode.get_node("Name").text
Network.join_game(ip, player_name)
@@ -117,6 +128,6 @@ func _on_Start_pressed():
func _on_Back_pressed():
- $Connect.show()
- $Players.hide()
+ ConnectNodeContainer.show()
+ PlayersNodeContainer.hide()
Network.leave_game()