Refactored and documented UI code

This commit is contained in:
RealMelwei 2025-10-14 16:24:45 +02:00
parent 5b880fa1ac
commit cabc547b51
4 changed files with 7 additions and 16 deletions

View file

@ -15,4 +15,4 @@ func _on_player_player_died() -> void:
func _on_button_retry_pressed() -> void:
Engine.time_scale = 1.
Grid.reset()
get_tree().reload_current_scene()
get_tree().call_deferred("reload_current_scene")

View file

@ -2,13 +2,8 @@ extends HBoxContainer
@export var packedHeart : PackedScene;
var current_max_hp = 0
var current_health = 0
func _ready() -> void:
#for i in range(initial_health):
#add_child(packedHeart.instantiate())
pass
# Set number of hearts to red corresponding to input health
func set_health(health : int):
var i = 0
for heart : Heart in get_children():
@ -17,8 +12,8 @@ func set_health(health : int):
heart.restore()
else:
heart.fade()
current_health = health
# Adjust the number of children to max HP
func set_maxhealth(new_max_hp : int):
if new_max_hp > current_max_hp:
for i in range(new_max_hp - current_max_hp):
@ -28,16 +23,11 @@ func set_maxhealth(new_max_hp : int):
for i in range(children.size()):
if new_max_hp < i+1:
children[i].queue_free()
current_health = min(current_health, current_max_hp)
else: pass
current_max_hp = new_max_hp
set_health(current_max_hp)
# Update display on (max) HP changes for the player
func _on_player_health_changed(new_health: int) -> void:
set_health(new_health)
func _on_player_max_hp_changed(new_max_hp: int) -> void:
set_maxhealth(new_max_hp)

View file

@ -3,6 +3,7 @@ extends MarginContainer
@export var player : Player;
@onready var timer : Timer = player.get_node("ActiveItemCooldown")
# Refresh icon and cooldown on active item change
func _on_player_active_item_changed(newitem: ActiveItem) -> void:
timer.stop()
if(newitem != null):
@ -10,10 +11,9 @@ func _on_player_active_item_changed(newitem: ActiveItem) -> void:
else:
%ItemTexture.texture = null
# Display the cooldown progress
func _process(_delta: float) -> void:
# visible = timer.time_left != 0;
if not visible: return;
var percentage = timer.time_left / timer.wait_time;
$CooldownOverlay.material.set_shader_parameter("percentage", percentage);

View file

@ -2,6 +2,7 @@ extends Control
@onready var item_list : ItemList = $ItemList
# Add items from each pool to journal. TODO: Deal with multiplicities.
func _ready() -> void:
await get_tree().create_timer(0.3).timeout
for item_scene in ItemSpawn.item_pool.common: