Players have separate HUDs

This commit is contained in:
Rob Kelly 2024-11-19 11:51:05 -07:00
parent af31c3c431
commit 5878a2efd5
7 changed files with 84 additions and 46 deletions

View File

@ -6,5 +6,5 @@
resource_name = "Sailboat"
cull_mode = 2
albedo_texture = ExtResource("1_k68kk")
roughness = 0.5
roughness = 0.43
texture_filter = 2

View File

@ -79,9 +79,7 @@ var phase: Phase = Phase.FINISHED:
_on_phase_change(value)
phase = value
var hud: ShotHUD:
get:
return world.ui.shot_hud if world and world.ui else null
var hud: ShotHUD
var club: Club.Type:
set(value):
@ -155,13 +153,11 @@ var _tracking_camera: OrbitalCamera
static var scene := preload("res://src/player/shot_setup/shot_setup.tscn")
func _init_deferred() -> void:
# Set up HUD
club = initial_club
func _ready() -> void:
_init_deferred.call_deferred()
# Create & set up HUD
hud = ShotHUD.create(player)
world.ui.add_player_hud(hud)
club = initial_club
func _set_camera_distance(value: float) -> void:
@ -356,7 +352,6 @@ func _on_phase_change(new_phase: Phase) -> void:
print_debug("Player ", player.name, ": change to ", Phase.keys()[new_phase])
match new_phase:
Phase.AIM:
hud.set_state_for_player(player)
hud.show_hud()
if not arrow.visible:
arrow_animation.play("show")

View File

@ -6,7 +6,7 @@ const LIFE_BAR_DAMAGE_RUMBLE_SCALE := 0.2
## Time it takes to dampen the life bar rumble on taking damage, in seconds
const LIFE_BAR_DAMAGE_RUMBLE_TIME := 0.2
var _life_signal: Signal
var player: WorldPlayer
@onready var power_bar: TextureProgressBar = %PowerBar
@onready var curve_bar: ProgressBar = %CurveBar
@ -28,23 +28,16 @@ var _life_signal: Signal
@onready var _state: AnimationNodeStateMachinePlayback = hud_state_machine["parameters/playback"]
static var scene: PackedScene = preload("res://src/ui/shot_hud/shot_hud.tscn")
## Set any HUD state specific to the player.
func set_state_for_player(player: WorldPlayer) -> void:
print_debug("Setting HUD for player ", player.name)
func _ready() -> void:
club_selector.set_state_for_player(player)
_player_name.text = player.name
# TODO animate on life loss?
life_bar.value = player.life
life_bar.tint_progress = player.color
# TODO this is soooooo wack...
# TODO we should just revert to having distinct ShotHUDs for each player
if _life_signal and _life_signal.is_connected(set_life_value):
_life_signal.disconnect(set_life_value)
_life_signal = player.on_life_changed
_life_signal.connect(set_life_value)
player.on_life_changed.connect(set_life_value)
# TODO special equipment
# TODO abilities
@ -108,3 +101,10 @@ func set_life_value(new_value: float) -> void:
# TODO: something for this?
pass
life_bar.value = new_value
static func create(player: WorldPlayer) -> ShotHUD:
var instance: ShotHUD = scene.instantiate()
instance.player = player
return instance

View File

@ -390,6 +390,18 @@ tracks/0/keys = {
"update": 0,
"values": [0.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SouthWest:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector2(0, 982)]
}
[sub_resource type="Animation" id="Animation_dt1yq"]
resource_name = "hide"
@ -407,6 +419,18 @@ tracks/0/keys = {
"update": 0,
"values": [0.0, 0.0872665, -1.5708]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SouthWest:position")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.1, 0.4),
"transitions": PackedFloat32Array(1.618, 1.618, 1),
"update": 0,
"values": [Vector2(0, 982), Vector2(0, 960), Vector2(0, 1100)]
}
[sub_resource type="Animation" id="Animation_0maif"]
resource_name = "show"
@ -424,6 +448,18 @@ tracks/0/keys = {
"update": 0,
"values": [-1.5708, 0.0872665, 0.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("SouthWest:position")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.34, 0.4),
"transitions": PackedFloat32Array(1.618, 1.618, 1),
"update": 0,
"values": [Vector2(0, 1100), Vector2(0, 960), Vector2(0, 982)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_c3i4w"]
_data = {
@ -438,21 +474,21 @@ animation = &"hide"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_v05eu"]
animation = &"show"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_28a4x"]
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_bj7v0"]
switch_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_xpwgd"]
switch_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_3o88y"]
advance_mode = 2
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_osrbp"]
states/hidden/node = SubResource("AnimationNodeAnimation_8uxnp")
states/hidden/position = Vector2(592, 100)
states/hidden/position = Vector2(378, 100)
states/visible/node = SubResource("AnimationNodeAnimation_v05eu")
states/visible/position = Vector2(364, 100)
transitions = ["Start", "visible", SubResource("AnimationNodeStateMachineTransition_28a4x"), "visible", "hidden", SubResource("AnimationNodeStateMachineTransition_bj7v0"), "hidden", "visible", SubResource("AnimationNodeStateMachineTransition_xpwgd")]
states/visible/position = Vector2(597, 100)
transitions = ["visible", "hidden", SubResource("AnimationNodeStateMachineTransition_bj7v0"), "hidden", "visible", SubResource("AnimationNodeStateMachineTransition_xpwgd"), "Start", "hidden", SubResource("AnimationNodeStateMachineTransition_3o88y")]
graph_offset = Vector2(-309, -132)
[node name="ShotHUD" type="Control"]
@ -650,24 +686,13 @@ grow_horizontal = 1
grow_vertical = 1
pivot_offset = Vector2(-400, 0)
[node name="HUDAnimation" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_c3i4w")
}
[node name="HUDStateMachine" type="AnimationTree" parent="."]
unique_name_in_owner = true
root_node = NodePath("%HUDStateMachine/..")
tree_root = SubResource("AnimationNodeStateMachine_osrbp")
anim_player = NodePath("../HUDAnimation")
[node name="SouthWest" type="MarginContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_top = 1.0
anchor_right = 0.333
anchor_bottom = 1.0
offset_top = -40.0
offset_top = -98.0
offset_right = 40.0
grow_vertical = 0
theme_override_constants/margin_left = 16
@ -709,3 +734,14 @@ script = ExtResource("3_6groq")
[node name="LifeBar" parent="SouthWest/VBoxContainer/MarginContainer/LifeBarRumbler" instance=ExtResource("9_w1fiw")]
unique_name_in_owner = true
layout_mode = 1
[node name="HUDAnimation" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_c3i4w")
}
[node name="HUDStateMachine" type="AnimationTree" parent="."]
unique_name_in_owner = true
root_node = NodePath("%HUDStateMachine/..")
tree_root = SubResource("AnimationNodeStateMachine_osrbp")
anim_player = NodePath("../HUDAnimation")

View File

@ -1,4 +1,8 @@
class_name WorldUI extends Control
## Container & accessor for the world UI.
@onready var shot_hud: ShotHUD = %ShotHUD
@onready var hud_container: Control = %HUDContainer
func add_player_hud(hud: ShotHUD) -> void:
hud_container.add_child(hud)

View File

@ -3,7 +3,6 @@ class_name RoundRobinManager extends PlayManager
func on_initialization() -> void:
print("IN ON_INITIALIZATION")
# Set first player as active
players[0].shot_setup.phase = ShotSetup.Phase.AIM

View File

@ -1,8 +1,7 @@
[gd_scene load_steps=9 format=3 uid="uid://cwnwcd8kushl3"]
[gd_scene load_steps=8 format=3 uid="uid://cwnwcd8kushl3"]
[ext_resource type="Script" path="res://src/world/world.gd" id="1_ybjyx"]
[ext_resource type="PackedScene" uid="uid://bm2o3mex10v11" path="res://levels/debug_level/debug_level.tscn" id="2_0xu5a"]
[ext_resource type="PackedScene" uid="uid://c4ifdiohng830" path="res://src/ui/shot_hud/shot_hud.tscn" id="2_5b7qb"]
[ext_resource type="Script" path="res://src/player/world_player.gd" id="2_e743i"]
[ext_resource type="Script" path="res://src/ui/world_ui.gd" id="2_imewa"]
[ext_resource type="Resource" uid="uid://crock3revdn73" path="res://src/player/debug_player.tres" id="3_pyw81"]
@ -31,6 +30,11 @@ grow_vertical = 2
mouse_filter = 1
script = ExtResource("2_imewa")
[node name="ShotHUD" parent="UI" instance=ExtResource("2_5b7qb")]
[node name="HUDContainer" type="Control" parent="UI"]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2