Animated the gold count label.

WorldChunkRefactoring
Martin Felis 2023-06-24 16:59:40 +02:00
parent c982ec783c
commit 22ad86319d
2 changed files with 30 additions and 4 deletions

View File

@ -17,7 +17,7 @@ public class Game : Spatial
private TextureRect _worldTextureRect;
private TextureRect _heightTextureRect;
private Button _generateWorldButton;
private Control _gameUI;
private Control _gameUi;
private Label _goldCountLabel;
// scene nodes
@ -62,8 +62,8 @@ public class Game : Spatial
_worldTextureRect = worldGeneratorContainer.GetNode<TextureRect>("WorldTextureRect");
_heightTextureRect = worldGeneratorContainer.GetNode<TextureRect>("HeightTextureRect");
_generateWorldButton = worldGeneratorContainer.GetNode<Button>("WorldGenerateButton");
_gameUI = (Control)FindNode("GameUI");
_goldCountLabel = _gameUI.GetNode<Label>("GoldCount");
_gameUi = (Control)FindNode("GameUI");
_goldCountLabel = _gameUi.GetNode<Label>("GoldCount");
Debug.Assert(_goldCountLabel != null);
// scene nodes
@ -291,6 +291,8 @@ public class Game : Spatial
_player.Navigation.PlanDirectPath(playerStartTransform.origin, playerStartTransform.origin,
playerStartTransform.basis.Quat());
_goldCountLabel.Text = "0";
foreach (Spatial entity in GetNode("Entities").GetChildren())
{
Transform entityTransform = entity.Transform;
@ -338,6 +340,10 @@ public class Game : Spatial
public void OnGoldCountChanged(int goldCount)
{
AnimationPlayer animationPlayer = _gameUi.GetNode<AnimationPlayer>("AnimationPlayer");
_goldCountLabel.Text = goldCount.ToString();
animationPlayer.CurrentAnimation = "FlashLabel";
animationPlayer.Seek(0);
animationPlayer.Play();
}
}

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=2]
[gd_scene load_steps=22 format=2]
[ext_resource path="res://scenes/StreamContainer.cs" type="Script" id=1]
[ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2]
@ -15,6 +15,22 @@
[ext_resource path="res://entities/Axe.tscn" type="PackedScene" id=14]
[ext_resource path="res://systems/InteractionSystem.cs" type="Script" id=15]
[sub_resource type="Animation" id=25]
resource_name = "FlashLabel"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("GoldCount:rect_scale")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.3 ),
"transitions": PoolRealArray( 1, 0.170755, 1 ),
"update": 0,
"values": [ Vector2( 1, 1 ), Vector2( 2, 2 ), Vector2( 1, 1 ) ]
}
[sub_resource type="CubeMesh" id=1]
size = Vector3( 1, 1, 1 )
@ -69,9 +85,13 @@ margin_top = 13.0
margin_right = 84.0
margin_bottom = 27.0
rect_min_size = Vector2( 50, 0 )
rect_pivot_offset = Vector2( 45, 8 )
text = "0"
align = 2
[node name="AnimationPlayer" type="AnimationPlayer" parent="GameUI"]
anims/FlashLabel = SubResource( 25 )
[node name="DebugContainer" type="PanelContainer" parent="."]
visible = false
self_modulate = Color( 1, 1, 1, 0.443137 )