mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-12 06:55:18 +00:00
✨ Basic implementation of IFF indicators showing player names and health bars
This commit is contained in:
parent
424c01bc02
commit
7e52ededc0
7 changed files with 114 additions and 43 deletions
4
interfaces/hud/healthbar_fill_style.tres
Normal file
4
interfaces/hud/healthbar_fill_style.tres
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[gd_resource type="StyleBoxFlat" format=3 uid="uid://cl7dmo2bg4153"]
|
||||
|
||||
[resource]
|
||||
bg_color = Color(1, 0.356863, 0.145098, 1)
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://bcv81ku26xo"]
|
||||
|
||||
[ext_resource type="StyleBox" uid="uid://cl7dmo2bg4153" path="res://interfaces/hud/healthbar_fill_style.tres" id="1_gh51l"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_2vxif"]
|
||||
script/source = "extends CanvasLayer
|
||||
class_name HUD
|
||||
|
|
@ -8,27 +10,24 @@ class_name HUD
|
|||
@onready var _energy_bar = $EnergyBar
|
||||
|
||||
func _ready():
|
||||
_update_health_label(100)
|
||||
_update_energy_label(100)
|
||||
_update_health_bar(100)
|
||||
_update_energy_bar(100)
|
||||
|
||||
func _update_energy_label(energy) -> void:
|
||||
func _update_energy_bar(energy) -> void:
|
||||
_energy_bar.value = energy
|
||||
|
||||
func _on_energy_changed(new_energy) -> void:
|
||||
_update_energy_label(new_energy)
|
||||
_update_energy_bar(new_energy)
|
||||
|
||||
func _update_health_label(health) -> void:
|
||||
func _update_health_bar(health) -> void:
|
||||
_health_bar.value = health
|
||||
|
||||
func _on_health_changed(new_health) -> void:
|
||||
_update_health_label(new_health)
|
||||
_update_health_bar(new_health)
|
||||
"
|
||||
|
||||
[sub_resource type="Theme" id="Theme_irfqb"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8ju42"]
|
||||
bg_color = Color(1, 0.356863, 0.145098, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_f23s3"]
|
||||
bg_color = Color(0, 0.454902, 0.992157, 1)
|
||||
|
||||
|
|
@ -60,7 +59,7 @@ offset_bottom = 40.0
|
|||
size_flags_horizontal = 0
|
||||
mouse_filter = 2
|
||||
theme = SubResource("Theme_irfqb")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_8ju42")
|
||||
theme_override_styles/fill = ExtResource("1_gh51l")
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
|
||||
|
|
|
|||
26
interfaces/hud/iff.gd
Normal file
26
interfaces/hud/iff.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var _player = $"../.."
|
||||
@onready var _player_name_label = $Offset/VBoxContainer/PlayerNameLabel
|
||||
@onready var _iff_attachment = $"../../IFFAttachment"
|
||||
@onready var _health_bar = $Offset/VBoxContainer/HealthBar
|
||||
@onready var _v_box_container = $Offset/VBoxContainer
|
||||
|
||||
func _process(_delta):
|
||||
var camera : Camera3D = get_viewport().get_camera_3d()
|
||||
if camera.is_position_behind(_iff_attachment.global_position):
|
||||
_v_box_container.hide()
|
||||
else:
|
||||
_v_box_container.show()
|
||||
|
||||
_player_name_label.text = _player.name
|
||||
position = camera.unproject_position(_iff_attachment.global_position)
|
||||
var viewport_size : Vector2 = get_viewport_rect().size
|
||||
position.x = clampf(position.x, 0, viewport_size.x - _v_box_container.size.x)
|
||||
position.y = clampf(position.y, _v_box_container.size.y, viewport_size.y)
|
||||
|
||||
func _update_health_bar(health) -> void:
|
||||
_health_bar.value = health
|
||||
|
||||
func _on_health_changed(new_health) -> void:
|
||||
_update_health_bar(new_health)
|
||||
26
interfaces/hud/iff.tscn
Normal file
26
interfaces/hud/iff.tscn
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dsysi2rd3bu76"]
|
||||
|
||||
[ext_resource type="Script" path="res://interfaces/hud/iff.gd" id="1_75yi1"]
|
||||
[ext_resource type="StyleBox" uid="uid://cl7dmo2bg4153" path="res://interfaces/hud/healthbar_fill_style.tres" id="2_x7k8o"]
|
||||
|
||||
[node name="IFF" type="Node2D"]
|
||||
script = ExtResource("1_75yi1")
|
||||
|
||||
[node name="Offset" type="Node2D" parent="."]
|
||||
position = Vector2(0, -32)
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Offset"]
|
||||
offset_right = 100.0
|
||||
offset_bottom = 40.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="PlayerNameLabel" type="Label" parent="Offset/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="Offset/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
theme_override_styles/fill = ExtResource("2_x7k8o")
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
Loading…
Add table
Add a link
Reference in a new issue