mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-14 16:04:50 +00:00
✨ IFF Updates
This commit is contained in:
parent
d6d2bf7866
commit
71ff1e1622
14 changed files with 261 additions and 99 deletions
|
|
@ -58,7 +58,6 @@ offset_right = 288.0
|
|||
offset_bottom = 40.0
|
||||
size_flags_horizontal = 0
|
||||
mouse_filter = 2
|
||||
theme = SubResource("Theme_irfqb")
|
||||
theme_override_styles/fill = ExtResource("1_gh51l")
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
|
|
|
|||
|
|
@ -12,30 +12,80 @@
|
|||
#
|
||||
# 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 Node2D
|
||||
extends Control
|
||||
|
||||
@export var attach_point : Node3D
|
||||
@export var player : Player
|
||||
@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
|
||||
|
||||
@onready var _player_name_label : Label = $Offset/VBoxContainer/PlayerNameLabel
|
||||
@onready var _health_bar : ProgressBar = $Offset/VBoxContainer/HealthBar
|
||||
@onready var _v_box_container : VBoxContainer = $Offset/VBoxContainer
|
||||
@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")
|
||||
|
||||
func _ready() -> void:
|
||||
_player_name_label.text = player.name
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
var camera : Camera3D = get_viewport().get_camera_3d()
|
||||
if camera.is_position_behind(attach_point.global_position):
|
||||
_v_box_container.hide()
|
||||
# retrieve camera for current viewport
|
||||
var camera : Camera3D = get_viewport().get_camera_3d()
|
||||
|
||||
# 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() # hide the IFF and exit function
|
||||
return
|
||||
else:
|
||||
_v_box_container.show()
|
||||
_iff_container.show() # display the IFF
|
||||
|
||||
_player_name_label.text = player.nickname
|
||||
position = camera.unproject_position(attach_point.global_position)
|
||||
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, attach_point.global_position)
|
||||
# exclude the camera owner nodes from intersecting with the trace check
|
||||
query.exclude = [camera.owner]
|
||||
# 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
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
# 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
|
||||
|
||||
# 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()
|
||||
|
||||
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 _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_health_changed(new_health : float) -> void:
|
||||
_update_health_bar(new_health)
|
||||
|
|
|
|||
|
|
@ -1,26 +1,52 @@
|
|||
[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"]
|
||||
[ext_resource type="StyleBox" uid="uid://cgv081wfih7la" path="res://interfaces/hud/iff_healthbar_fill_style.tres" id="2_frxvy"]
|
||||
|
||||
[node name="IFF" type="Node2D"]
|
||||
[node name="IFF" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
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
|
||||
[node name="IFFContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 63.0
|
||||
offset_bottom = 42.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="PlayerNameLabel" type="Label" parent="Offset/VBoxContainer"]
|
||||
[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="Offset/VBoxContainer"]
|
||||
[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/fill = ExtResource("2_x7k8o")
|
||||
theme_override_styles/fill = ExtResource("2_frxvy")
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="Chevron" type="Label" parent="IFFContainer"]
|
||||
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
|
||||
|
|
|
|||
9
interfaces/hud/iff_healthbar_fill_style.tres
Normal file
9
interfaces/hud/iff_healthbar_fill_style.tres
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[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
|
||||
Loading…
Add table
Add a link
Reference in a new issue