diff --git a/Scenes/Tiles/GroundTile.tscn b/Scenes/Tiles/GroundTile.tscn index ce20bf9..62eac69 100644 --- a/Scenes/Tiles/GroundTile.tscn +++ b/Scenes/Tiles/GroundTile.tscn @@ -9,6 +9,7 @@ size = Vector2(54, 54) [node name="GroundTile" type="StaticBody2D"] collision_layer = 0 script = ExtResource("1_mqsaf") +TileId = "ground" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.1, 0.1) diff --git a/Scenes/Tiles/MinerTile.tscn b/Scenes/Tiles/MinerTile.tscn index c40d1b1..95a18cb 100644 --- a/Scenes/Tiles/MinerTile.tscn +++ b/Scenes/Tiles/MinerTile.tscn @@ -8,6 +8,7 @@ size = Vector2(54, 54) [node name="MinerTile" type="StaticBody2D"] script = ExtResource("1_mecoy") +TileId = "miner" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.1, 0.1) diff --git a/Scenes/Tiles/StoneIronTile.tscn b/Scenes/Tiles/StoneIronTile.tscn index 817308b..7d8edc9 100644 --- a/Scenes/Tiles/StoneIronTile.tscn +++ b/Scenes/Tiles/StoneIronTile.tscn @@ -9,6 +9,7 @@ size = Vector2(54, 54) [node name="StoneIronTile" type="StaticBody2D"] collision_layer = 0 script = ExtResource("1_ewklp") +TileId = "stone_iron" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.1, 0.1) diff --git a/Scenes/Tiles/StoneTile.tscn b/Scenes/Tiles/StoneTile.tscn index ec84287..0286dfd 100644 --- a/Scenes/Tiles/StoneTile.tscn +++ b/Scenes/Tiles/StoneTile.tscn @@ -9,6 +9,7 @@ size = Vector2(54, 54) [node name="StoneTile" type="StaticBody2D"] collision_layer = 0 script = ExtResource("1_rndy8") +TileId = "stone" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.1, 0.1) diff --git a/Scenes/Tiles/WallTile.tscn b/Scenes/Tiles/WallTile.tscn index d9a4ae7..13c864a 100644 --- a/Scenes/Tiles/WallTile.tscn +++ b/Scenes/Tiles/WallTile.tscn @@ -8,6 +8,7 @@ size = Vector2(54, 54) [node name="WallTile" type="StaticBody2D"] script = ExtResource("1_ph7y3") +TileId = "wall" [node name="Sprite2D" type="Sprite2D" parent="."] scale = Vector2(0.05, 0.05) diff --git a/Scripts/Tiles/BaseTile.cs b/Scripts/Tiles/BaseTile.cs index 6a54ca3..50fc438 100644 --- a/Scripts/Tiles/BaseTile.cs +++ b/Scripts/Tiles/BaseTile.cs @@ -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("ProgressOverlay"); if (_progressOverlay != null) _progressOverlay.Visible = false; + + // Setup audio player + _completionSound = new AudioStreamPlayer(); + AddChild(_completionSound); + var sound = GD.Load("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 + } } \ No newline at end of file diff --git a/Sounds/Events/ConstructionComplete.wav b/Sounds/Events/ConstructionComplete.wav new file mode 100644 index 0000000..7104cb6 Binary files /dev/null and b/Sounds/Events/ConstructionComplete.wav differ diff --git a/Sounds/Events/ConstructionComplete.wav.import b/Sounds/Events/ConstructionComplete.wav.import new file mode 100644 index 0000000..b249f09 --- /dev/null +++ b/Sounds/Events/ConstructionComplete.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://xmgj505csg5x" +path="res://.godot/imported/ConstructionComplete.wav-094dbaa5fa3f80e5fe8fc1583055a77d.sample" + +[deps] + +source_file="res://Sounds/Events/ConstructionComplete.wav" +dest_files=["res://.godot/imported/ConstructionComplete.wav-094dbaa5fa3f80e5fe8fc1583055a77d.sample"] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=2