From 1b9d5bc78125b3ee82590bb755418ba7a61fc8c6 Mon Sep 17 00:00:00 2001 From: desktop Date: Fri, 26 Feb 2021 22:17:00 +0100 Subject: [PATCH] Added rudimentary character select --- GUI/CharacterOption.gd | 9 ++++++++- GUI/CharacterSelect.gd | 7 +++++++ Game.gd | 35 +++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/GUI/CharacterOption.gd b/GUI/CharacterOption.gd index 9dfd66b..5f8dc06 100644 --- a/GUI/CharacterOption.gd +++ b/GUI/CharacterOption.gd @@ -1,11 +1,18 @@ extends Control +signal character_selected() + +onready var character_select = get_parent().get_parent().get_parent().get_parent() + func set_character(packed_character): var character = packed_character.instance() character.show_healthbar = false $Viewport.add_child(character) + $CharacterDisplay.connect("pressed", self, "select_character") + +func select_character(): + emit_signal("character_selected") func _process(delta): $Viewport.size = rect_size - diff --git a/GUI/CharacterSelect.gd b/GUI/CharacterSelect.gd index 51c0627..c95839a 100644 --- a/GUI/CharacterSelect.gd +++ b/GUI/CharacterSelect.gd @@ -1,6 +1,7 @@ extends Control onready var game = get_parent().get_parent() +var selected_character = null func _ready(): var dir = Directory.new() @@ -21,7 +22,13 @@ func add_character(character_name): var character_option = preload("res://GUI/CharacterOption.tscn").instance() $CenterContainer/VBoxContainer/CharacterList.add_child(character_option) + character_option.set_character(packed_character) + character_option.connect("character_selected", self, "character_selected", [character_name, packed_character]) + +func character_selected(character_name, packed_character): + print(character_name) + game.local_player = packed_character.instance() func spawn(): game.spawn(get_tree().get_network_unique_id()) diff --git a/Game.gd b/Game.gd index a6fc68e..02fa8d1 100644 --- a/Game.gd +++ b/Game.gd @@ -22,8 +22,27 @@ var local_player = null setget set_local_player onready var menu_stack = [$MenuContainer/MainMenu] func set_local_player(player): + if local_player != null: + $Players.remove_child(local_player) + local_player = player + + var id = peer.get_unique_id() + player.name = str(id) + player.set_network_master(id) + $Players.add_child(local_player) player.set_local_player() + + var nickname = $MenuContainer/MainMenu/Name.text + set_nickname(nickname) + player.set_nickname(nickname) + on_player_added(player) + + var player_data = get_player_data() + + rpc("set_player_data", player_data) + + player.hide() # Called when the node enters the scene tree for the first time. func _ready(): @@ -255,26 +274,10 @@ remote func check_players(player_data): func join_game(): var player = player_scene.instance() - var id = peer.get_unique_id() - player.name = str(id) - player.set_network_master(id) - - $Players.add_child(player) set_local_player(player) - var nickname = $MenuContainer/MainMenu/Name.text - set_nickname(nickname) - player.set_nickname(nickname) - on_player_added(player) - - var player_data = get_player_data() - - rpc("set_player_data", player_data) - - player.hide() open_menu("CharacterSelectScreen") - sync func spawn(player_id): var spawning_player = $Players.get_node(str(player_id))