💫 Better build effects
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using AceFieldNewHorizon.Scripts.System;
|
||||
using Godot;
|
||||
using Vector2 = Godot.Vector2;
|
||||
@@ -7,9 +7,14 @@ namespace AceFieldNewHorizon.Scripts.Tiles;
|
||||
|
||||
public partial class BaseTile : Node2D
|
||||
{
|
||||
[Export] public string TileId { get; set; }
|
||||
|
||||
public BuildingData TileData { get; set; }
|
||||
|
||||
private CollisionShape2D _collisionShape;
|
||||
private Sprite2D _sprite;
|
||||
private ColorRect _progressOverlay;
|
||||
private AudioStreamPlayer _completionSound;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -18,6 +23,15 @@ public partial class BaseTile : Node2D
|
||||
_progressOverlay = GetNodeOrNull<ColorRect>("ProgressOverlay");
|
||||
if (_progressOverlay != null)
|
||||
_progressOverlay.Visible = false;
|
||||
|
||||
// Setup audio player
|
||||
_completionSound = new AudioStreamPlayer();
|
||||
AddChild(_completionSound);
|
||||
var sound = GD.Load<AudioStream>("res://Sounds/Events/ConstructionComplete.wav");
|
||||
if (sound != null)
|
||||
{
|
||||
_completionSound.Stream = sound;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGhostMode(bool canPlace)
|
||||
@@ -47,6 +61,7 @@ public partial class BaseTile : Node2D
|
||||
var texSize = new Vector2(GridUtils.TileSize, GridUtils.TileSize);
|
||||
|
||||
_progressOverlay.Visible = true;
|
||||
_progressOverlay.Modulate = Colors.White;
|
||||
_progressOverlay.Color = new Color(0, 0, 1, 0.4f); // semi-transparent blue
|
||||
|
||||
async void RunProgress()
|
||||
@@ -67,9 +82,33 @@ public partial class BaseTile : Node2D
|
||||
);
|
||||
}
|
||||
|
||||
_progressOverlay.Visible = false;
|
||||
// Fade out the overlay instead of making it instantly disappear
|
||||
await FadeOutOverlay(0.5f);
|
||||
}
|
||||
|
||||
RunProgress();
|
||||
}
|
||||
|
||||
private async Task FadeOutOverlay(float duration)
|
||||
{
|
||||
var elapsed = 0f;
|
||||
var startAlpha = _progressOverlay.Modulate.A;
|
||||
|
||||
// Play completion sound
|
||||
if (_completionSound?.Stream != null)
|
||||
{
|
||||
_completionSound.Play();
|
||||
}
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
elapsed += (float)GetProcessDeltaTime();
|
||||
var alpha = Mathf.Lerp(startAlpha, 0f, elapsed / duration);
|
||||
_progressOverlay.Modulate = new Color(1, 1, 1, alpha);
|
||||
}
|
||||
|
||||
_progressOverlay.Visible = false;
|
||||
_progressOverlay.Modulate = Colors.White; // Reset alpha for next use
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user