seeding-planets/gui/game/scripts/game_gui.gd
2025-09-19 13:30:05 +02:00

96 lines
3.0 KiB
GDScript

extends Control
class_name GameGui
signal pause_asked
func _ready():
Pointer.connect("inspected_entity_changed", _on_inspected_entity_changed)
func _on_player_updated(player:Player):
%EnergyCount.text = str(player.energy) + "/" + str(player.max_energy)
%EnergyInfo.modulate = Color.WHITE if player.energy > 0 else Color.RED
for i in player.inventory.max_items:
var item : Item = player.inventory.get_item(i)
if item:
if %Inventory.get_child_count() <= i:
var texture_rect = TextureRect.new()
texture_rect.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
%Inventory.add_child(texture_rect)
%Inventory.get_child(i).texture = item.icon
%Inventory.get_child(i).visible = true
if i == player.inventory.current_item_ind:
%Inventory.get_child(i).modulate = Color.WHITE
else:
%Inventory.get_child(i).modulate = Color.DARK_GRAY
else:
if %Inventory.get_child_count() > i:
%Inventory.get_child(i).visible = false
update_no_energy_left_info(player.energy)
func _on_planet_updated(planet:Planet):
%DayCount.text = str(planet.get_quota_remaining_days()) + " days left"
if planet.next_quota:
var quota_progression_percent : float = (planet.decontamination_surface - planet.last_quota) / (planet.next_quota - planet.last_quota) * 100
%QuotaProgressText.text = str(roundi(planet.decontamination_surface)) + "/" + str(roundi(planet.next_quota))
get_tree().create_tween().tween_property(
%QuotaProgressBar,
"value",
quota_progression_percent,
0.5,
)
func _on_player_action_tried_without_energy():
$AnimationPlayer.play("no_energy_left")
func _on_pause_pressed():
pause_asked.emit()
func _on_player_upgraded():
$EffectAnimation.play("upgrade")
func _on_planet_pass_day_started(planet):
$PassDayAnimation.speed_scale = 1/(planet.PASS_DAY_ANIMATION_TIME)
$PassDayAnimation.play("pass_day")
await $PassDayAnimation.animation_finished
$PassDayAnimation.speed_scale = 1
func _on_inspected_entity_changed(e : InspectableEntity):
var info : Inspector.Info = null
if e:
info = e.inspector_info()
%Inspector.info = info
func update_no_energy_left_info(energy):
if energy == 0 and not %NoEnergyLeft.visible:
%NoEnergyLeft.visible = true
$NoEnergyLeftAnimation.play("no_energy_left_appear")
elif energy != 0 and %NoEnergyLeft.visible:
%NoEnergyLeft.visible = false
func _on_planet_new_quota_started(planet:Planet):
%Announce.announce(
"New Quota",
"Reach " + str(roundi(planet.next_quota)) + " units before " + str(Planet.DEFAULT_DAY_LIMIT) + " days"
)
func _on_planet_pass_day_ended(planet:Planet):
var remaining_days = planet.get_quota_remaining_days()
if remaining_days == 1:
%Announce.announce(
"Last day for reaching quota",
str(roundi(planet.next_quota - planet.decontamination_surface)) + " units left to decontaminate",
Announce.RED_COLOR
)
if remaining_days == 2:
%Announce.announce(
"2 days left before quota's ending",
str(roundi(planet.next_quota - planet.decontamination_surface)) + " units left to decontaminate",
Announce.YELLOW_COLOR
)