generated from krampus/template-godot4
48 lines
1.1 KiB
GDScript
48 lines
1.1 KiB
GDScript
class_name PlayerHUD extends Control
|
|
|
|
const TRANSITION_TIME := 0.06
|
|
|
|
const COLOR_VISIBLE := Color("#ffffffee")
|
|
const COLOR_DISABLED := Color("#cccccc44")
|
|
const COLOR_INVISIBLE := Color("#ffffff00")
|
|
|
|
@onready var interact_hud: Control = %InteractHUD
|
|
|
|
@onready var alert_player: AnimationPlayer = %AlertPlayer
|
|
|
|
|
|
func _ready() -> void:
|
|
Game.manager.alert_raised.connect(_on_raise_alert)
|
|
|
|
|
|
func _transition_color(element: CanvasItem, color: Color) -> void:
|
|
create_tween().tween_property(element, "modulate", color, TRANSITION_TIME).set_trans(
|
|
Tween.TRANS_CUBIC
|
|
)
|
|
|
|
|
|
func _to_visible(element: Control) -> void:
|
|
_transition_color(element, COLOR_VISIBLE)
|
|
|
|
|
|
func _to_disabled(element: Control) -> void:
|
|
_transition_color(element, COLOR_DISABLED)
|
|
|
|
|
|
func _to_invisible(element: Control) -> void:
|
|
_transition_color(element, COLOR_INVISIBLE)
|
|
|
|
|
|
func select_interactive(prop: Interactive) -> void:
|
|
if prop:
|
|
if prop.enabled:
|
|
_to_visible(interact_hud)
|
|
else:
|
|
_to_disabled(interact_hud)
|
|
else:
|
|
_to_invisible(interact_hud)
|
|
|
|
|
|
func _on_raise_alert(_new_value: int) -> void:
|
|
alert_player.play("grunk_alert")
|