From 92ebb2868de81b2cc900467cbcddba593e3c65ff Mon Sep 17 00:00:00 2001 From: Rendo Date: Sat, 19 Jul 2025 19:29:45 +0500 Subject: [PATCH] counter +1 --- addons/pvzadventure/AdventureLevelResource.cs | 2 +- scenes/gui/sun_counter.tscn | 11 ++++---- scenes/prototype_survival.tscn | 1 - scenes/templates/level_template.tscn | 1 - scripts/LevelGUIElements.cs | 4 +-- scripts/Sun.cs | 14 +++++----- scripts/gui/SunCounter.cs | 26 ++++++++++++++++--- scripts/gui/SunCounterImage.cs | 11 -------- scripts/gui/SunCounterImage.cs.uid | 1 - scripts/level/PlantField.cs | 4 +-- scripts/level/RuntimeLevelData.cs | 14 ++++++---- 11 files changed, 50 insertions(+), 39 deletions(-) delete mode 100644 scripts/gui/SunCounterImage.cs delete mode 100644 scripts/gui/SunCounterImage.cs.uid diff --git a/addons/pvzadventure/AdventureLevelResource.cs b/addons/pvzadventure/AdventureLevelResource.cs index 37b1f50..32e3821 100644 --- a/addons/pvzadventure/AdventureLevelResource.cs +++ b/addons/pvzadventure/AdventureLevelResource.cs @@ -5,7 +5,7 @@ using Godot.Collections; [Tool] public partial class AdventureLevelResource : Resource { - [Export] public float startSun = 50; + [Export] public int startSun = 50; //[Export] public Array conditions; [Export(PropertyHint.Range, "0,1,0.01")] public float wavePercentage; [Export] public float standardWaveDelay; diff --git a/scenes/gui/sun_counter.tscn b/scenes/gui/sun_counter.tscn index 3a856a7..8e3573d 100644 --- a/scenes/gui/sun_counter.tscn +++ b/scenes/gui/sun_counter.tscn @@ -1,16 +1,15 @@ -[gd_scene load_steps=7 format=3 uid="uid://ky35veswaytr"] +[gd_scene load_steps=6 format=3 uid="uid://ky35veswaytr"] [ext_resource type="Texture2D" uid="uid://bhp3vuvwf7lak" path="res://assets/sprites/gui/suncounter.tres" id="1_e5x4k"] [ext_resource type="Theme" uid="uid://b8l285cjcgeyi" path="res://resources/themes/GameStyle.tres" id="1_vhhcn"] [ext_resource type="Texture2D" uid="uid://c47rflkf2wap0" path="res://assets/sprites/sun.tres" id="2_gugre"] [ext_resource type="Script" uid="uid://dwxohya1exdkh" path="res://scripts/gui/SunCounter.cs" id="3_qhmb8"] -[ext_resource type="Script" uid="uid://0ekxnoq6cyt4" path="res://scripts/gui/SunCounterImage.cs" id="4_c68ge"] [sub_resource type="LabelSettings" id="LabelSettings_lxkq5"] font_size = 10 font_color = Color(0, 0, 0, 1) -[node name="SunCounter" type="TextureRect"] +[node name="SunCounter" type="TextureRect" node_paths=PackedStringArray("text", "sunImage")] anchors_preset = -1 anchor_right = 0.082 anchor_bottom = 0.067 @@ -19,6 +18,9 @@ offset_bottom = 0.199999 size_flags_vertical = 0 theme = ExtResource("1_vhhcn") texture = ExtResource("1_e5x4k") +script = ExtResource("3_qhmb8") +text = NodePath("Label") +sunImage = NodePath("Sun") [node name="Sun" type="TextureRect" parent="."] show_behind_parent = true @@ -34,7 +36,6 @@ offset_right = 22.5 offset_bottom = 22.487 pivot_offset = Vector2(23, 22) texture = ExtResource("2_gugre") -script = ExtResource("4_c68ge") [node name="Label" type="Label" parent="."] process_mode = 3 @@ -48,8 +49,8 @@ offset_left = 0.0219994 offset_top = 0.00599957 offset_right = -0.0219994 offset_bottom = -0.00500107 +text = "0" label_settings = SubResource("LabelSettings_lxkq5") horizontal_alignment = 1 vertical_alignment = 1 text_overrun_behavior = 3 -script = ExtResource("3_qhmb8") diff --git a/scenes/prototype_survival.tscn b/scenes/prototype_survival.tscn index da65065..e4d6f35 100644 --- a/scenes/prototype_survival.tscn +++ b/scenes/prototype_survival.tscn @@ -194,7 +194,6 @@ size = Vector2(282, 399) [node name="Data" type="Node" parent="."] script = ExtResource("1_tnxdx") -SunCount = 50.0 [node name="Camera2D" type="Camera2D" parent="."] position = Vector2(481, 200) diff --git a/scenes/templates/level_template.tscn b/scenes/templates/level_template.tscn index 5efe940..e015c28 100644 --- a/scenes/templates/level_template.tscn +++ b/scenes/templates/level_template.tscn @@ -434,7 +434,6 @@ libraries = { [node name="Data" type="Node" parent="." node_paths=PackedStringArray("levelRunner", "player")] script = ExtResource("1_31ltw") -SunCount = 50.0 levelRunner = NodePath("../LevelRunner") player = NodePath("../MainAnimationPlayer") diff --git a/scripts/LevelGUIElements.cs b/scripts/LevelGUIElements.cs index 8d74ea1..f191d2f 100644 --- a/scripts/LevelGUIElements.cs +++ b/scripts/LevelGUIElements.cs @@ -1,5 +1,5 @@ using Godot; -using System; +using Newlon.Components.GUI; namespace Newlon.Components; @@ -10,7 +10,7 @@ public partial class LevelGUIElements : Control [Export] public HBoxContainer SeedpacketsHotbar; [Export] - public TextureRect SunCounter; + public SunCounter SunCounter; public override void _Ready() { Instance = this; diff --git a/scripts/Sun.cs b/scripts/Sun.cs index 44940ad..4a2ffb2 100644 --- a/scripts/Sun.cs +++ b/scripts/Sun.cs @@ -1,4 +1,5 @@ using Godot; +using Newlon.Components.GUI; using Newlon.Components.Level; @@ -6,8 +7,6 @@ namespace Newlon; public partial class Sun : Area2D { - public static Control Counter; - [Export] public int amount = 25; [Export] private Timer _deathTimer; [Export] private AnimationPlayer _rotation; @@ -39,21 +38,22 @@ public partial class Sun : Area2D } public override void _MouseEnter() { - if (Settings.SunClick) return; + if (Settings.SunClick || scoring) return; ScoreSun(); } private void ScoreSun() { _fade.Stop(); scoring = true; - + + RuntimeLevelData.Instance.AddSun(amount); + GetNode("SunPlayer").Play(); var tween = CreateTween(); - tween.TweenInterval(0.1); - tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (Counter.GlobalPosition + Counter.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out); + tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (SunCounter.Instance.sunImage.GlobalPosition + SunCounter.Instance.sunImage.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out); tween.TweenCallback(Callable.From(() => { - RuntimeLevelData.Instance.AddSun(amount); + SunCounter.Update(); QueueFree(); })); } diff --git a/scripts/gui/SunCounter.cs b/scripts/gui/SunCounter.cs index fa7c11f..74778fd 100644 --- a/scripts/gui/SunCounter.cs +++ b/scripts/gui/SunCounter.cs @@ -1,12 +1,32 @@ +using System.Globalization; using Godot; using Newlon.Components.Level; namespace Newlon.Components.GUI; -public partial class SunCounter : Label +public partial class SunCounter : Control { - public override void _Process(double delta) + public static SunCounter Instance { get; private set; } + private Tween tween; + [Export] private Label text; + [Export] public TextureRect sunImage { get; private set;} + public override void _EnterTree() { - Text = RuntimeLevelData.Instance.SunCount.ToString(); + Instance = this; + } + + public static void Update() + { + if (Instance.tween != null) Instance.tween.Kill(); + Instance.tween = Instance.CreateTween(); + Instance.tween.TweenMethod(Callable.From(Instance.SetText), int.Parse(Instance.text.Text), RuntimeLevelData.Instance.SunCount, 1.0); + } + public static void UpdateInstantly() + { + Instance.text.Text = RuntimeLevelData.Instance.SunCount.ToString(); + } + private void SetText(int value) + { + text.Text = value.ToString(); } } diff --git a/scripts/gui/SunCounterImage.cs b/scripts/gui/SunCounterImage.cs deleted file mode 100644 index ecb6288..0000000 --- a/scripts/gui/SunCounterImage.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Godot; -using Newlon; -using System; - -public partial class SunCounterImage : Control -{ - public override void _Ready() - { - Sun.Counter = this; - } -} diff --git a/scripts/gui/SunCounterImage.cs.uid b/scripts/gui/SunCounterImage.cs.uid deleted file mode 100644 index c05e487..0000000 --- a/scripts/gui/SunCounterImage.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://0ekxnoq6cyt4 diff --git a/scripts/level/PlantField.cs b/scripts/level/PlantField.cs index d8a1059..0c7772f 100644 --- a/scripts/level/PlantField.cs +++ b/scripts/level/PlantField.cs @@ -59,7 +59,7 @@ public partial class PlantField : Node2D bool canPlace = _resource != null && inBoundary && PoolContainer.Instance.EntityField[_resource.Layer].ContainsKey(expected_pos) == false - && RuntimeLevelData.Instance.CheckSpendSun(_resource.Cost); + && RuntimeLevelData.Instance.CheckSpendSun((int)_resource.Cost); // Setting visuals if (_previousCanPlace != canPlace) @@ -97,7 +97,7 @@ public partial class PlantField : Node2D PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant); - RuntimeLevelData.Instance.SpendSun(_resource.Cost); + RuntimeLevelData.Instance.SpendSun((int)_resource.Cost); PoolContainer.Instance.SpawnParticles(particles, plant.GlobalPosition + Vector2.Down * FieldParams.TileHeight/2.0f); diff --git a/scripts/level/RuntimeLevelData.cs b/scripts/level/RuntimeLevelData.cs index e2d248f..378d9a9 100644 --- a/scripts/level/RuntimeLevelData.cs +++ b/scripts/level/RuntimeLevelData.cs @@ -1,5 +1,6 @@ using System; using Godot; +using Newlon.Components.GUI; namespace Newlon.Components.Level; @@ -14,8 +15,7 @@ public partial class RuntimeLevelData : Node Loose } - [Export] - public float SunCount { get; private set; } = 0; + public int SunCount { get; private set; } = 0; [Export] private LevelRunner levelRunner; [Export] @@ -37,20 +37,24 @@ public partial class RuntimeLevelData : Node public override void _Ready() { Engine.TimeScale = 1.0; + SunCount = LevelResource.startSun; + SunCounter.UpdateInstantly(); SetLevelState(LevelStates.ChooseYourSeeds); } #region Sun - public void AddSun(float amount) + public void AddSun(int amount) { SunCount += amount; + SunCounter.Update(); } - public void SpendSun(float amount) + public void SpendSun(int amount) { SunCount -= amount; + SunCounter.Update(); } - public bool CheckSpendSun(float amount) + public bool CheckSpendSun(int amount) { if (SunCount - amount < 0) return false;