From c71083879339cfe84c53137d8046cbd2bae00320 Mon Sep 17 00:00:00 2001 From: desktop Date: Fri, 11 Dec 2020 23:57:11 +0100 Subject: [PATCH] Implemented character preview when selecting character --- .../HerMajestyTheQueen/HerMajestyTheQueen.gd | 2 +- GUI/CharacterOption.gd | 10 ++++++---- GUI/CharacterOption.tscn | 14 +++++++++----- GUI/CharacterSelect.gd | 17 ++++++++++++++++- GUI/CharacterSelect.tscn | 15 ++++----------- Player.gd | 5 ++++- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.gd b/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.gd index 3ed70c0..0108308 100644 --- a/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.gd +++ b/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.gd @@ -2,5 +2,5 @@ extends "res://Player.gd" func _ready(): if name == String(get_tree().get_network_unique_id()): - print("SELF") + return #$Throne/Cube.cast_shadow = 3 diff --git a/GUI/CharacterOption.gd b/GUI/CharacterOption.gd index 0ccd86c..9dfd66b 100644 --- a/GUI/CharacterOption.gd +++ b/GUI/CharacterOption.gd @@ -1,9 +1,11 @@ extends Control - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. +func set_character(packed_character): + var character = packed_character.instance() + character.show_healthbar = false + + $Viewport.add_child(character) func _process(delta): $Viewport.size = rect_size + diff --git a/GUI/CharacterOption.tscn b/GUI/CharacterOption.tscn index 71a697d..e456009 100644 --- a/GUI/CharacterOption.tscn +++ b/GUI/CharacterOption.tscn @@ -1,6 +1,5 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.tscn" type="PackedScene" id=1] [ext_resource path="res://GUI/CharacterOption.gd" type="Script" id=2] [sub_resource type="ViewportTexture" id=1] @@ -9,6 +8,9 @@ viewport_path = NodePath("Viewport") [node name="CharacterOption" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 +margin_right = -824.0 +margin_bottom = -300.0 +rect_min_size = Vector2( 200, 300 ) script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false @@ -25,12 +27,14 @@ __meta__ = { [node name="Viewport" type="Viewport" parent="."] size = Vector2( 500, 500 ) +own_world = true transparent_bg = true -msaa = 2 render_target_v_flip = true [node name="Camera" type="Camera" parent="Viewport"] -transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 1.38191, -6.32464 ) +transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 1.38191, -8.49631 ) fov = 39.6532 -[node name="HerMajestyTheQueen" parent="Viewport" instance=ExtResource( 1 )] +[node name="DirectionalLight" type="DirectionalLight" parent="Viewport"] +transform = Transform( 1, 0, 0, 0, -0.361787, 0.932261, 0, -0.932261, -0.361787, 0, 3.34228, -3.37409 ) +light_energy = 2.9 diff --git a/GUI/CharacterSelect.gd b/GUI/CharacterSelect.gd index 8b133bd..9682ccb 100644 --- a/GUI/CharacterSelect.gd +++ b/GUI/CharacterSelect.gd @@ -5,8 +5,23 @@ onready var game = get_parent().get_parent() func _ready(): var dir = Directory.new() dir.open("res://Assets/Characters/") + dir.list_dir_begin() - #$CenterContainer/VBoxContainer/CharacterList.add_child(null) + var file = dir.get_next() + while file != "": + if not file.begins_with("."): + # Add character + add_character(file) + + file = dir.get_next() + +func add_character(character_name): + var path = "res://Assets/Characters/" + character_name + "/" + character_name + ".tscn" + var packed_character = load(path) + + var character_option = preload("res://GUI/CharacterOption.tscn").instance() + $CenterContainer/VBoxContainer/CharacterList.add_child(character_option) + character_option.set_character(packed_character) func spawn(): get_parent().get_parent().spawn(get_tree().get_network_unique_id()) diff --git a/GUI/CharacterSelect.tscn b/GUI/CharacterSelect.tscn index 336359c..6762653 100644 --- a/GUI/CharacterSelect.tscn +++ b/GUI/CharacterSelect.tscn @@ -22,28 +22,21 @@ __meta__ = { [node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"] margin_left = -177.0 -margin_top = -50.0 +margin_top = -26.0 margin_right = 176.0 -margin_bottom = 50.0 +margin_bottom = 26.0 [node name="CharacterList" type="HBoxContainer" parent="CenterContainer/VBoxContainer"] margin_right = 353.0 -margin_bottom = 48.0 alignment = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="Button" type="Button" parent="CenterContainer/VBoxContainer/CharacterList"] -margin_left = 30.0 -margin_right = 322.0 -margin_bottom = 48.0 -text = "Her Majesty the Queen" - [node name="Options" type="HBoxContainer" parent="CenterContainer/VBoxContainer"] -margin_top = 52.0 +margin_top = 4.0 margin_right = 353.0 -margin_bottom = 100.0 +margin_bottom = 52.0 alignment = 1 [node name="SelectButton" type="Button" parent="CenterContainer/VBoxContainer/Options"] diff --git a/Player.gd b/Player.gd index 242ff3b..8ccd499 100644 --- a/Player.gd +++ b/Player.gd @@ -11,6 +11,7 @@ const WALK_DECEL = 0.1 const MOUSE_SENSITIVITY = 1.0 / 1000 +export var show_healthbar = true export var max_health = 150 onready var health = max_health setget set_health @@ -310,7 +311,7 @@ func set_local_player(): # Called when the node enters the scene tree for the first time. func _ready(): - set_health(150) + set_health(max_health) # disabled the ragdoll collider #for i in $Player/Gibs.get_children(): # i.get_child(1).disabled = true @@ -318,6 +319,8 @@ func _ready(): #$"Player/Gibs/PlayerGibs _cell /shape0".set_disabled(true) rset_config("translation", MultiplayerAPI.RPC_MODE_SYNC) + if !show_healthbar: + $Billboard.hide() # only show the debug label on local machine if name != String(get_tree().get_network_unique_id()):