Refactored and documented UI code
This commit is contained in:
parent
5b880fa1ac
commit
cabc547b51
4 changed files with 7 additions and 16 deletions
|
|
@ -15,4 +15,4 @@ func _on_player_player_died() -> void:
|
||||||
func _on_button_retry_pressed() -> void:
|
func _on_button_retry_pressed() -> void:
|
||||||
Engine.time_scale = 1.
|
Engine.time_scale = 1.
|
||||||
Grid.reset()
|
Grid.reset()
|
||||||
get_tree().reload_current_scene()
|
get_tree().call_deferred("reload_current_scene")
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,8 @@ extends HBoxContainer
|
||||||
|
|
||||||
@export var packedHeart : PackedScene;
|
@export var packedHeart : PackedScene;
|
||||||
var current_max_hp = 0
|
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):
|
func set_health(health : int):
|
||||||
var i = 0
|
var i = 0
|
||||||
for heart : Heart in get_children():
|
for heart : Heart in get_children():
|
||||||
|
|
@ -17,8 +12,8 @@ func set_health(health : int):
|
||||||
heart.restore()
|
heart.restore()
|
||||||
else:
|
else:
|
||||||
heart.fade()
|
heart.fade()
|
||||||
current_health = health
|
|
||||||
|
|
||||||
|
# Adjust the number of children to max HP
|
||||||
func set_maxhealth(new_max_hp : int):
|
func set_maxhealth(new_max_hp : int):
|
||||||
if new_max_hp > current_max_hp:
|
if new_max_hp > current_max_hp:
|
||||||
for i in range(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()):
|
for i in range(children.size()):
|
||||||
if new_max_hp < i+1:
|
if new_max_hp < i+1:
|
||||||
children[i].queue_free()
|
children[i].queue_free()
|
||||||
current_health = min(current_health, current_max_hp)
|
|
||||||
else: pass
|
|
||||||
|
|
||||||
current_max_hp = new_max_hp
|
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:
|
func _on_player_health_changed(new_health: int) -> void:
|
||||||
set_health(new_health)
|
set_health(new_health)
|
||||||
|
|
||||||
|
|
||||||
func _on_player_max_hp_changed(new_max_hp: int) -> void:
|
func _on_player_max_hp_changed(new_max_hp: int) -> void:
|
||||||
set_maxhealth(new_max_hp)
|
set_maxhealth(new_max_hp)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ extends MarginContainer
|
||||||
@export var player : Player;
|
@export var player : Player;
|
||||||
@onready var timer : Timer = player.get_node("ActiveItemCooldown")
|
@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:
|
func _on_player_active_item_changed(newitem: ActiveItem) -> void:
|
||||||
timer.stop()
|
timer.stop()
|
||||||
if(newitem != null):
|
if(newitem != null):
|
||||||
|
|
@ -10,10 +11,9 @@ func _on_player_active_item_changed(newitem: ActiveItem) -> void:
|
||||||
else:
|
else:
|
||||||
%ItemTexture.texture = null
|
%ItemTexture.texture = null
|
||||||
|
|
||||||
|
# Display the cooldown progress
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
# visible = timer.time_left != 0;
|
|
||||||
if not visible: return;
|
if not visible: return;
|
||||||
|
|
||||||
var percentage = timer.time_left / timer.wait_time;
|
var percentage = timer.time_left / timer.wait_time;
|
||||||
$CooldownOverlay.material.set_shader_parameter("percentage", percentage);
|
$CooldownOverlay.material.set_shader_parameter("percentage", percentage);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ extends Control
|
||||||
|
|
||||||
@onready var item_list : ItemList = $ItemList
|
@onready var item_list : ItemList = $ItemList
|
||||||
|
|
||||||
|
# Add items from each pool to journal. TODO: Deal with multiplicities.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
await get_tree().create_timer(0.3).timeout
|
await get_tree().create_timer(0.3).timeout
|
||||||
for item_scene in ItemSpawn.item_pool.common:
|
for item_scene in ItemSpawn.item_pool.common:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue