open-fpsz/interfaces/hud/iff.gd

42 lines
1.6 KiB
GDScript

# This file is part of open-fpsz.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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
@export var attach_point : Node3D
@export var player : Player
@onready var _player_name_label = $Offset/VBoxContainer/PlayerNameLabel
@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(attach_point.global_position):
_v_box_container.hide()
else:
_v_box_container.show()
_player_name_label.text = player.nickname
position = camera.unproject_position(attach_point.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)