You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
class_name WeaponInfo |
|
extends Node2D |
|
|
|
# TODO: Render rounds as sprites? |
|
|
|
const VISIBLE_DURATION := 0.8 |
|
|
|
@onready var rounds := $Rounds as Label |
|
@onready var reloading := $Reloading as ProgressBar |
|
|
|
var _visible_delay : float |
|
var _previous_weapon : Weapon |
|
var _previous_rounds : int |
|
|
|
func _process(delta: float) -> void: |
|
var player := Game.LOCAL_PLAYER |
|
var weapon := player.inventory.equipped as Weapon if player else null |
|
if not weapon: visible = false; _previous_weapon = null; return |
|
|
|
visible = true |
|
_visible_delay -= delta |
|
if _visible_delay <= 0: |
|
modulate = Color(modulate, modulate.a - delta) |
|
if modulate.a <= 0: visible = false |
|
|
|
if weapon != _previous_weapon or weapon.rounds != _previous_rounds or weapon.is_reloading: |
|
_visible_delay = VISIBLE_DURATION |
|
modulate = Color.WHITE |
|
|
|
rounds.visible = weapon.capacity > 1 |
|
rounds.text = "%d/%d" % [ weapon.rounds, weapon.capacity ] |
|
reloading.value = weapon.reload_progress |
|
reloading.visible = weapon.is_reloading |
|
|
|
_previous_weapon = weapon |
|
_previous_rounds = weapon.rounds
|
|
|