developpement d'écran de chargement et d'écran de sélection de niveau
* modification de certains assets * optimisation de chunks * ajout d'un SceneManager * ajout d'un premier dialogue avec Demeter * changement des jour en charge * mise en place d'un système de run * etc...
This commit is contained in:
@@ -3,133 +3,110 @@ 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)
|
||||
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)
|
||||
|
||||
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()
|
||||
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)
|
||||
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]
|
||||
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
|
||||
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)
|
||||
inventory_update(inventory)
|
||||
|
||||
func inventory_update(inventory : Inventory):
|
||||
%Inventory.update(inventory)
|
||||
%Inventory.update(inventory)
|
||||
|
||||
func _on_planet_updated(planet_data : PlanetData):
|
||||
planet_update(planet_data)
|
||||
planet_update(planet_data)
|
||||
|
||||
func planet_update(planet_data : PlanetData, with_animation = true):
|
||||
if planet_data:
|
||||
%DayCount.text = tr("%d_DAY_LEFT") % (planet_data.quota_days)
|
||||
if planet_data:
|
||||
%ChargeCount.text = tr("%d_CHARGE_LEFT") % (planet_data.charges)
|
||||
|
||||
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()]
|
||||
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",
|
||||
quota_progression_percent,
|
||||
0.5,
|
||||
)
|
||||
else: %QuotaProgressBar.value = quota_progression_percent
|
||||
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
|
||||
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
|
||||
)
|
||||
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
|
||||
await get_tree().create_timer(0.3 / max(1,i)).timeout
|
||||
|
||||
func spawn_score_particle(
|
||||
from_position,
|
||||
to_position,
|
||||
duration
|
||||
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 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
|
||||
)
|
||||
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()
|
||||
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
|
||||
$AnimationPlayer.play("no_energy_left")
|
||||
|
||||
func _on_player_upgraded():
|
||||
$EffectAnimation.play("upgrade")
|
||||
$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_new_quota_started(planet_data : PlanetData):
|
||||
planet_update(planet_data)
|
||||
await quota_reward.reward_chosen
|
||||
announce_quota(planet_data)
|
||||
planet_data.is_quota_announced = true
|
||||
|
||||
|
||||
func announce_quota(planet_data : PlanetData):
|
||||
%Announce.announce(
|
||||
tr("NEW_QUOTA"),
|
||||
tr("REACH_%d_GARDEN_SCORE_BEFORE_%d_DAYS") % [planet_data.get_quota_score(), planet_data.get_quota_duration()]
|
||||
)
|
||||
$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.quota_days == 1:
|
||||
%Announce.announce(
|
||||
tr("LAST_DAY_FOR_REACHING_QUOTA"),
|
||||
tr("%d_GARDEN_SCORE_LEFT") % [planet.data.get_quota_score() - planet.garden.get_score()],
|
||||
Announce.RED_COLOR
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user