rework l'ui et équilibrage général
This commit is contained in:
@@ -1,32 +1,38 @@
|
||||
extends Control
|
||||
extends CanvasLayer
|
||||
class_name GameGui
|
||||
|
||||
const SCORE_ICON : Texture = preload("res://common/icons/growth.svg")
|
||||
|
||||
@export var quota_reward : QuotaReward
|
||||
|
||||
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.current_planet_data.new_quota_started.connect(_on_planet_new_quota_started)
|
||||
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)
|
||||
player_update(GameInfo.game_data.player_data)
|
||||
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)
|
||||
|
||||
if not GameInfo.game_data.current_planet_data.is_quota_announced:
|
||||
await quota_reward.reward_chosen
|
||||
announce_quota(GameInfo.game_data.current_planet_data)
|
||||
GameInfo.game_data.current_planet_data.is_quota_announced = true
|
||||
%EnergyInfo.update_minimum_size()
|
||||
|
||||
|
||||
func _on_player_updated(player_data : PlayerData):
|
||||
player_update(player_data)
|
||||
|
||||
func player_update(player_data : PlayerData):
|
||||
%EnergyCount.text = "%d/%d" % [player_data.energy, player_data.max_energy]
|
||||
%EnergyInfo.modulate = Color.WHITE if player_data.energy > 0 else Color.RED
|
||||
func player_update(player_data : PlayerData, with_animation = true):
|
||||
var energy_count_text = "[b]%d[/b] / %d" % [player_data.energy, player_data.max_energy]
|
||||
|
||||
update_no_energy_left_info(player_data.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)
|
||||
@@ -37,26 +43,67 @@ func inventory_update(inventory : Inventory):
|
||||
func _on_planet_updated(planet_data : PlanetData):
|
||||
planet_update(planet_data)
|
||||
|
||||
func planet_update(planet_data : PlanetData):
|
||||
func planet_update(planet_data : PlanetData, with_animation = true):
|
||||
if planet_data:
|
||||
%DayCount.text = tr("%d_DAY_LEFT") % (planet_data.quota_days)
|
||||
|
||||
var quota_progression_percent : float = (float(planet_data.garden_score) / float(planet_data.get_quota_score())) * 100
|
||||
%QuotaProgressText.text = "%d/%d" % [planet_data.garden_score, planet_data.get_quota_score()]
|
||||
get_tree().create_tween().tween_property(
|
||||
%QuotaProgressBar,
|
||||
"value",
|
||||
quota_progression_percent,
|
||||
0.5,
|
||||
|
||||
if with_animation:
|
||||
get_tree().create_tween().tween_property(
|
||||
%QuotaProgressBar,
|
||||
"value",
|
||||
quota_progression_percent,
|
||||
0.5,
|
||||
)
|
||||
else: %QuotaProgressBar.value = quota_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).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_pause_pressed():
|
||||
Pause.pause = true
|
||||
|
||||
|
||||
func _on_player_upgraded():
|
||||
$EffectAnimation.play("upgrade")
|
||||
|
||||
@@ -66,14 +113,6 @@ func _on_planet_pass_day_started(planet):
|
||||
await $PassDayAnimation.animation_finished
|
||||
$PassDayAnimation.speed_scale = 1
|
||||
|
||||
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_data : PlanetData):
|
||||
planet_update(planet_data)
|
||||
await quota_reward.reward_chosen
|
||||
@@ -91,6 +130,6 @@ func _on_planet_pass_day_ended(planet:Planet):
|
||||
if planet.data.quota_days == 1:
|
||||
%Announce.announce(
|
||||
tr("LAST_DAY_FOR_REACHING_QUOTA"),
|
||||
str(roundi(planet.data.get_quota_score() - planet.garden.get_score())) + " garden score left",
|
||||
tr("%d_GARDEN_SCORE_LEFT") % [planet.data.get_quota_score() - planet.garden.get_score()],
|
||||
Announce.RED_COLOR
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user