extends CanvasLayer class_name GameGui const SCORE_ICON : Texture = preload("res://common/icons/growth.svg") func _ready(): GameInfo.game_data.current_planet_data.updated.connect(_on_planet_updated) GameInfo.game_data.current_planet_data.plant_gaining_score.connect(_on_plant_gaining_score) GameInfo.game_data.player_data.updated.connect(_on_player_updated) GameInfo.game_data.player_data.inventory.updated.connect(_on_inventory_updated) planet_update(GameInfo.game_data.current_planet_data, false) player_update(GameInfo.game_data.player_data, false) inventory_update(GameInfo.game_data.player_data.inventory) %EnergyInfo.update_minimum_size() func _on_player_updated(player_data : PlayerData): player_update(player_data) func player_update(player_data : PlayerData, with_animation = true): var energy_count_text = "[b]%d[/b] / %d" % [player_data.energy, player_data.max_energy] if energy_count_text != %EnergyCount.text and with_animation: %EnergyAnimationPlayer.bounce() %EnergyCount.text = energy_count_text %EnergyInfo.modulate = Color.WHITE if player_data.energy > 0 else Color.RED func _on_inventory_updated(inventory : Inventory): inventory_update(inventory) func inventory_update(inventory : Inventory): %Inventory.update(inventory) func _on_planet_updated(planet_data : PlanetData): planet_update(planet_data) func planet_update(planet_data : PlanetData, with_animation = true): if planet_data: %ChargeCount.text = tr("%d_CHARGE_LEFT") % (planet_data.charges) var objective_progression_percent : float = (float(planet_data.garden_score) / float(planet_data.objective)) * 100 %ObjectiveProgressText.text = "%d/%d" % [planet_data.garden_score, planet_data.objective] if with_animation: get_tree().create_tween().tween_property( %QuotaProgressBar, "value", objective_progression_percent, 0.5, ) else: %QuotaProgressBar.value = objective_progression_percent func _on_plant_gaining_score(plant: Plant, amount : int): for i in range(amount): var camera = get_viewport().get_camera_2d() var screen_size = get_viewport().get_visible_rect().size spawn_score_particle( plant.global_position - camera.global_position + screen_size / 2, %QuotaProgressBar.global_position + %QuotaProgressBar.size / 2, 0.8 ) await get_tree().create_timer(0.3 / max(1,i)).timeout func spawn_score_particle( from_position, to_position, duration ): var sprite_particle = Sprite2D.new() sprite_particle.texture = SCORE_ICON %ScoreParticles.add_child(sprite_particle) sprite_particle.position = from_position var tween = get_tree().create_tween() tween.set_trans(Tween.TransitionType.TRANS_SPRING) tween.tween_property( sprite_particle, "position", to_position, duration ) await tween.finished sprite_particle.queue_free() func _on_player_action_tried_without_energy(): $AnimationPlayer.play("no_energy_left") 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_planet_pass_day_ended(planet:Planet): if planet.data.charges == 1: %Announce.announce( tr("LAST_RECHARGE"), tr("%d_GARDEN_SCORE_LEFT") % [planet.data.objective - planet.garden.get_score()], Announce.RED_COLOR )