progress bar / waypoint / iffs improvements

This commit is contained in:
anyreso 2024-05-11 15:25:22 -04:00
parent 2dfea5b250
commit 1588224d45
13 changed files with 307 additions and 218 deletions

View file

@ -0,0 +1,50 @@
[gd_scene load_steps=7 format=3 uid="uid://bbeecp3jusppn"]
[ext_resource type="Script" path="res://interfaces/hud/iffs/iff.gd" id="1_g6kgb"]
[ext_resource type="Shader" uid="uid://n2dcb4l0qun2" path="res://interfaces/progress_bar/resources/visual_shader.res" id="2_8cjkh"]
[ext_resource type="Script" path="res://interfaces/progress_bar/progress_bar_3d.gd" id="3_vss6w"]
[ext_resource type="Texture2D" uid="uid://cpb6vpa0c74rl" path="res://interfaces/waypoint/assets/waypoint.svg" id="4_lrbtk"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wrx5m"]
render_priority = 0
shader = ExtResource("2_8cjkh")
[sub_resource type="QuadMesh" id="QuadMesh_b6wb8"]
material = SubResource("ShaderMaterial_wrx5m")
size = Vector2(0.35, 0.025)
center_offset = Vector3(0, 0.09, 0)
[node name="IFF" type="Node3D"]
script = ExtResource("1_g6kgb")
border = 0.4
billboard = 1
depth_test = true
[node name="Username" type="Label3D" parent="."]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
offset = Vector2(0, 64)
billboard = 1
fixed_size = true
text = "Username"
font_size = 24
[node name="HealthBar" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000610828, 0.0127701, -0.000638008)
instance_shader_parameters/background = Color(0, 0, 0, 0.5)
instance_shader_parameters/billboard = 1
instance_shader_parameters/border = 0.0
instance_shader_parameters/fill = Color(1, 1, 1, 1)
instance_shader_parameters/progress = 1.0
instance_shader_parameters/size = Vector2(0.35, 0.025)
mesh = SubResource("QuadMesh_b6wb8")
script = ExtResource("3_vss6w")
border = 0.0
billboard = 1
fill = Color(1, 1, 1, 1)
[node name="Chevron" type="Sprite3D" parent="."]
transform = Transform3D(0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04, 0, 0, 0)
offset = Vector2(0, 64)
billboard = 1
fixed_size = true
texture = ExtResource("4_lrbtk")

View file

@ -1,9 +0,0 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://cgv081wfih7la"]
[resource]
bg_color = Color(1, 0, 0, 0.25)
corner_radius_top_left = 3
corner_radius_top_right = 3
corner_radius_bottom_right = 3
corner_radius_bottom_left = 3
anti_aliasing = false

View file

@ -12,92 +12,107 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Control
@tool
class_name IFF extends Node3D
@export var player : Player
@export var match_participant_component : MatchParticipantComponent
@export var attach_point : Marker3D
@export var healthbar_low_health_color : Color = Color(1 ,0 ,0, 0.78)
@export var healthbar_mid_health_color : Color = Color(1, 1, 0, 0.78)
@export var healthbar_high_health_color : Color = Color(0, 1, 0, 0.78)
@export var iff_in_range_radius_ratio : float = 0.05
signal health_changed(new_value : float)
signal fill_changed(color : Color)
signal background_changed(color : Color)
signal billboard_changed(new_billboard : int)
signal username_changed(new_username : String)
signal border_changed(new_border : float)
signal depth_test_changed(new_depth_test : bool)
@onready var _iff_container : Control = $IFFContainer
@onready var _iff_in_range_container : Control = $IFFContainer/IFFInRangeContainer
@onready var _player_name_label : Control = $IFFContainer/IFFInRangeContainer/PlayerNameLabel
@onready var _health_bar : ProgressBar = $IFFContainer/IFFInRangeContainer/HealthBar
@onready var is_within_los : bool = false
@onready var healthbar_fill_stylebox : StyleBoxFlat = _health_bar.get_theme_stylebox("fill")
# If `true`, the waypoint fades as the camera get closer.
#@export var fade : bool = true
func set_nickname(new_nickname : String) -> void:
_player_name_label.text = new_nickname
## The current value for the pgroess bar.
@export_range(0., 1.) var value : float = 1.:
set(new_value):
value = new_value
health_changed.emit(value)
func _process(_delta : float) -> void:
# retrieve camera for current viewport
var camera : Camera3D = get_viewport().get_camera_3d()
## The border for the progress bar.
@export_range(0., 1.) var border : float = .2:
set(new_border):
border = new_border
border_changed.emit(border)
# if the player is NOT infront of the camera or camera does NOT have LOS to player
if camera.is_position_behind(attach_point.global_position) or !is_within_los:
_iff_container.hide()
else:
_iff_container.show()
## The username to display on top of this indicator.
@export var username : String = "Username":
set(value):
username = value
username_changed.emit(username)
# Show the correct IFF based on whether the player we're looking at belongs is a friend or a foe
# in other words if their team_ids are the same as the "pawn" player
if player.pawn_player != null:
if player.pawn_player.match_participant_component.team_id == player.match_participant_component.team_id:
%FoeChevron.hide()
%FriendChevron.show()
else:
%FoeChevron.show()
%FriendChevron.hide()
## The foreground color to use for this indicator.
@export var fill : Color = Color.WHITE:
set(value):
fill = value
fill_changed.emit(fill)
func _physics_process(_delta : float) -> void:
# https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html
var camera : Camera3D = get_viewport().get_camera_3d()
is_within_los = false # always initialise trace_success as false
var space_state : PhysicsDirectSpaceState3D = camera.get_world_3d().direct_space_state
# do a trace check from camera to towards the player
var query : PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.create(camera.global_position, player.global_position)
# only collide with Layer 1 (objects) and Layer 32 (terrain/structures)
query.collision_mask = 0b10000000_00000000_00000000_00000001
# exclude the camera owner nodes from intersecting with the trace check
if player.pawn_player:
query.exclude = [player.pawn_player]
# do trace check and store result
var result : Dictionary = space_state.intersect_ray(query)
# if a result was returned and the hit result is the player
if result and result["collider"] == player:
# the player is in camera LOS
is_within_los = true
## The background color to use for this indicator.
@export var background : Color = Color(0, 0, 0, 0.5):
set(color):
background = color
background_changed.emit(color)
var new_iff_position : Vector2 = camera.unproject_position(attach_point.global_position) # get the screen location of the players head
var viewport_size : Vector2 = get_viewport_rect().size
## The billboard mode to use. See [member BaseMaterial3D.BillboardMode] for possible values.
@export_enum("Disabled", "Enabled", "Y-Billboard") var billboard : int = 2:
set(new_billboard):
billboard = new_billboard
billboard_changed.emit(billboard)
# check if the unprojected point lies inside the viewport
if !Rect2(Vector2(0, 0), viewport_size).has_point(new_iff_position):
_iff_container.hide() # hide the IFF and exit function
return
@export var depth_test : bool = false:
set(new_depth_test):
depth_test = new_depth_test
depth_test_changed.emit(new_depth_test)
# if player is NOT in range to have its healthbar and name drawn
if (new_iff_position - viewport_size / 2).length() > iff_in_range_radius_ratio * viewport_size.length():
_iff_in_range_container.hide() # hide the in range IFF
else:
_iff_in_range_container.show()
@onready var label : Label3D = $Username
@onready var chevron : Sprite3D = $Chevron
@onready var hbar : ProgressBar3D = $HealthBar
new_iff_position.y -= _iff_container.size.y # move the IFF up so the bottom of it is at the players head
new_iff_position.x -= _iff_container.size.x / 2 # move the IFF left so it's centered horizontally above players head
position = new_iff_position # set the position of the IFF
func _on_billboard_changed(new_billboard : int) -> void:
label.billboard = new_billboard as BaseMaterial3D.BillboardMode
hbar.billboard = new_billboard
chevron.billboard = new_billboard as BaseMaterial3D.BillboardMode
func _update_health_bar(health : float) -> void:
_health_bar.value = health
# modify health_box stylebox depending health value
if health < 75 and health > 40:
healthbar_fill_stylebox.bg_color = healthbar_mid_health_color
elif health <= 40:
healthbar_fill_stylebox.bg_color = healthbar_low_health_color
else:
healthbar_fill_stylebox.bg_color = healthbar_high_health_color
func _on_border_changed(new_border : float) -> void:
hbar.border = new_border
func _on_health_changed(new_health : float) -> void:
_update_health_bar(new_health)
func _on_username_changed(new_username : String) -> void:
# The label's text can only be set once the node is ready.
if is_inside_tree():
label.text = new_username
func _on_background_changed(color : Color) -> void:
label.outline_modulate = color
hbar.background = color
func _on_fill_changed(color : Color) -> void:
label.modulate = color
hbar.fill = color
chevron.modulate = color
func _on_health_changed(new_value : float) -> void:
hbar.value = new_value
func _on_depth_test_changed(new_depth_test : bool) -> void:
label.no_depth_test = !new_depth_test
#hbar.no_depth_test = !new_depth_test
chevron.no_depth_test = !new_depth_test
func _enter_tree() -> void:
if not username_changed.is_connected(_on_username_changed):
username_changed.connect(_on_username_changed)
if not health_changed.is_connected(_on_health_changed):
health_changed.connect(_on_health_changed)
if not fill_changed.is_connected(_on_fill_changed):
fill_changed.connect(_on_fill_changed)
if not background_changed.is_connected(_on_background_changed):
background_changed.connect(_on_background_changed)
if not border_changed.is_connected(_on_border_changed):
border_changed.connect(_on_border_changed)
if not billboard_changed.is_connected(_on_billboard_changed):
billboard_changed.connect(_on_billboard_changed)
if not depth_test_changed.is_connected(_on_depth_test_changed):
depth_test_changed.connect(_on_depth_test_changed)

View file

@ -1,71 +0,0 @@
[gd_scene load_steps=4 format=3 uid="uid://dsysi2rd3bu76"]
[ext_resource type="Script" path="res://interfaces/hud/iffs/iff.gd" id="1_g1wra"]
[ext_resource type="StyleBox" uid="uid://cgv081wfih7la" path="res://interfaces/hud/iffs/health_foreground.tres" id="2_e3xla"]
[ext_resource type="StyleBox" uid="uid://dcn1ll2ra4lwn" path="res://interfaces/hud/vitals/background.tres" id="2_jtos4"]
[node name="IFF" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_g1wra")
[node name="IFFContainer" type="MarginContainer" parent="."]
layout_mode = 0
offset_right = 63.0
offset_bottom = 42.0
mouse_filter = 2
[node name="IFFInRangeContainer" type="Control" parent="IFFContainer"]
layout_mode = 2
mouse_filter = 2
[node name="PlayerNameLabel" type="Label" parent="IFFContainer/IFFInRangeContainer"]
layout_mode = 2
offset_right = 63.0
offset_bottom = 17.0
theme_override_colors/font_color = Color(1, 1, 1, 1)
theme_override_font_sizes/font_size = 12
text = "Player"
horizontal_alignment = 1
metadata/_edit_use_anchors_ = true
[node name="HealthBar" type="ProgressBar" parent="IFFContainer/IFFInRangeContainer"]
layout_mode = 2
offset_top = 20.0
offset_right = 63.0
offset_bottom = 24.0
mouse_filter = 2
theme_override_styles/background = ExtResource("2_jtos4")
theme_override_styles/fill = ExtResource("2_e3xla")
value = 60.0
show_percentage = false
[node name="FoeChevron" type="Label" parent="IFFContainer"]
unique_name_in_owner = true
visible = false
layout_direction = 2
layout_mode = 2
size_flags_vertical = 1
theme_override_colors/font_color = Color(1, 0, 0, 0.2)
theme_override_colors/font_outline_color = Color(0, 0, 0, 0.2)
theme_override_constants/outline_size = 3
theme_override_constants/line_spacing = -20
theme_override_font_sizes/font_size = 14
text = "▼"
horizontal_alignment = 1
vertical_alignment = 2
[node name="FriendChevron" type="Label" parent="IFFContainer"]
unique_name_in_owner = true
visible = false
layout_direction = 2
layout_mode = 2
size_flags_vertical = 1
theme_override_colors/font_color = Color(0, 1, 0, 0.2)
theme_override_colors/font_outline_color = Color(0, 0, 0, 0.2)
theme_override_constants/outline_size = 3
theme_override_constants/line_spacing = -20
theme_override_font_sizes/font_size = 14
text = "▼"
horizontal_alignment = 1
vertical_alignment = 2