From 39e28c20357d5d7b3fbeae6c854c97e876c5eb3b Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 24 Apr 2020 14:32:04 +0200 Subject: [PATCH] Now the player ui and the nameplates are dynamically allocated aswell. --- game/player/Body.gd | 10 +++++++++- game/player/GUI.gd | 2 +- game/player/Mob.tscn | 6 +----- game/player/NamePlate.gd | 2 +- game/player/NetworkedPlayer.tscn | 6 +----- game/player/Player.tscn | 8 +------- game/ui/loot_window/LootWindow.gd | 3 +++ game/ui/player_ui/player_ui.tscn | 1 - 8 files changed, 17 insertions(+), 21 deletions(-) diff --git a/game/player/Body.gd b/game/player/Body.gd index 8c923d56..e122aeb7 100644 --- a/game/player/Body.gd +++ b/game/player/Body.gd @@ -580,9 +580,13 @@ func on_c_controlled_changed(val): var cam_scene : PackedScene = ResourceLoader.load("res://data/camera/CameraPivot.tscn") camera_pivot = cam_scene.instance() as Spatial add_child(camera_pivot) - camera = camera_pivot.get_node("Camera") as Camera + var uiscn : PackedScene = ResourceLoader.load("res://ui/player_ui/player_ui.tscn") + var ui = uiscn.instance() + add_child(ui) + + set_process_input(true) set_process_unhandled_input(true) else: @@ -593,6 +597,10 @@ func on_c_controlled_changed(val): set_process_input(false) set_process_unhandled_input(false) + var nameplatescn : PackedScene = ResourceLoader.load("res://ui/nameplates/NamePlate.tscn") + var nameplate = nameplatescn.instance() + add_child(nameplate) + func on_sdied(entity): diff --git a/game/player/GUI.gd b/game/player/GUI.gd index 475f46f8..2d2f370f 100644 --- a/game/player/GUI.gd +++ b/game/player/GUI.gd @@ -20,7 +20,7 @@ extends Control # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -export (NodePath) var player_path : NodePath +export (String) var player_path : String = "../../.." export (Array, NodePath) var child_controls : Array func _ready() -> void: diff --git a/game/player/Mob.tscn b/game/player/Mob.tscn index 747947de..68760e67 100644 --- a/game/player/Mob.tscn +++ b/game/player/Mob.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://player/Mob.gd" type="Script" id=2] -[ext_resource path="res://ui/nameplates/NamePlate.tscn" type="PackedScene" id=3] [node name="Mob" type="Entity" groups=[ "mobs", @@ -9,6 +8,3 @@ body_path = NodePath("Body") character_skeleton_path = NodePath("Body/Rotation_Helper/Model/character") script = ExtResource( 2 ) - -[node name="NamePlate" parent="." instance=ExtResource( 3 )] -max_distance = 50.0 diff --git a/game/player/NamePlate.gd b/game/player/NamePlate.gd index 6eb6b3d3..628d4ae2 100644 --- a/game/player/NamePlate.gd +++ b/game/player/NamePlate.gd @@ -51,7 +51,7 @@ func _ready(): health_bar = get_node(health_bar_path) as TextureProgress health_bar_label = get_node(health_bar_label_path) as Label - entity = get_node("..") as Entity + entity = get_node("../..") as Entity health = entity.get_health() health.connect("c_changed", self, "c_health_changed") diff --git a/game/player/NetworkedPlayer.tscn b/game/player/NetworkedPlayer.tscn index 23588990..80c1d52a 100644 --- a/game/player/NetworkedPlayer.tscn +++ b/game/player/NetworkedPlayer.tscn @@ -1,12 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://player/NetworkedPlayer.gd" type="Script" id=1] -[ext_resource path="res://ui/nameplates/NamePlate.tscn" type="PackedScene" id=3] [node name="NetworkedPlayer" type="Entity"] body_path = NodePath("Body") character_skeleton_path = NodePath("Body/Rotation_Helper/Model/character") script = ExtResource( 1 ) - -[node name="NamePlate" parent="." instance=ExtResource( 3 )] -max_distance = 50.0 diff --git a/game/player/Player.tscn b/game/player/Player.tscn index ae6053e4..2c988017 100644 --- a/game/player/Player.tscn +++ b/game/player/Player.tscn @@ -1,14 +1,8 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://player/Player.gd" type="Script" id=2] -[ext_resource path="res://ui/player_ui/player_ui.tscn" type="PackedScene" id=3] [node name="Player" type="Entity" groups=[ "players", ]] -body_path = NodePath("HumanFemale") -character_skeleton_path = NodePath("HumanFemale/Rotation_Helper/Model/character") script = ExtResource( 2 ) - -[node name="GUILayer" parent="." instance=ExtResource( 3 )] -[connection signal="onc_open_loot_winow_request" from="." to="GUILayer" method="_on_Player_onc_open_loot_winow_request"] diff --git a/game/ui/loot_window/LootWindow.gd b/game/ui/loot_window/LootWindow.gd index e73d98d5..425bf8ff 100644 --- a/game/ui/loot_window/LootWindow.gd +++ b/game/ui/loot_window/LootWindow.gd @@ -57,6 +57,7 @@ func refresh(): func set_player(p_player : Entity) -> void: player = p_player player.connect("ctarget_bag_changed", self, "ctarget_bag_changed") + player.connect("onc_open_loot_winow_request", self, "onc_open_loot_winow_request") func on_visibility_changed(): if visible: @@ -81,3 +82,5 @@ func ctarget_bag_changed(entity: Entity, bag: Bag) -> void: target_bag.connect("item_removed", self, "on_item_removed") +func onc_open_loot_winow_request() -> void: + show() diff --git a/game/ui/player_ui/player_ui.tscn b/game/ui/player_ui/player_ui.tscn index fbb7f5ff..7063a0b4 100644 --- a/game/ui/player_ui/player_ui.tscn +++ b/game/ui/player_ui/player_ui.tscn @@ -42,7 +42,6 @@ __meta__ = { "_edit_group_": true, "_edit_lock_": true } -player_path = NodePath("../..") child_controls = [ NodePath("Unitframes"), NodePath("Actionbars"), NodePath("Windows/SpellBookWindow"), NodePath("Buttons"), NodePath("Castbar"), NodePath("AuraFrame"), NodePath("Windows/Inventory"), NodePath("Windows/LootWindow"), NodePath("Windows/TalentWindow"), NodePath("Windows/CraftingWindow") ] [node name="TouchTargetControls" type="MarginContainer" parent="GUI"]