From 5719c3f920bf3001a69d0e6265dc7bee3196f0a0 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 23 Aug 2025 04:20:42 +0200 Subject: [PATCH] Add Active Buffs management and UI integration --- Scenes/Main/Main.tscn | 56 +++--------------------- Scenes/Main/buff_button.tscn | 10 +++++ Scripts/ActiveBuffUi.cs | 31 +++++++++++++ Scripts/ActiveBuffUi.cs.uid | 1 + Scripts/ActiveBuffsManager.cs | 46 +++++++++++++++++++ Scripts/ActiveBuffsManager.cs.uid | 1 + Scripts/Core/Effects/ApplyBuffEffect.cs | 3 ++ Scripts/Core/Effects/Buff.cs | 4 ++ Scripts/Core/GameLogic.cs | 2 + Scripts/Singletons/GameBus.cs | 12 +++++ Sprites/grey.png | Bin 0 -> 272 bytes Sprites/grey.png.import | 34 ++++++++++++++ Sprites/grey_inlay.png | Bin 0 -> 221 bytes Sprites/grey_inlay.png.import | 34 ++++++++++++++ Sprites/grey_pressed.png | Bin 0 -> 254 bytes Sprites/grey_pressed.png.import | 34 ++++++++++++++ 16 files changed, 217 insertions(+), 51 deletions(-) create mode 100644 Scenes/Main/buff_button.tscn create mode 100644 Scripts/ActiveBuffUi.cs create mode 100644 Scripts/ActiveBuffUi.cs.uid create mode 100644 Scripts/ActiveBuffsManager.cs create mode 100644 Scripts/ActiveBuffsManager.cs.uid create mode 100644 Sprites/grey.png create mode 100644 Sprites/grey.png.import create mode 100644 Sprites/grey_inlay.png create mode 100644 Sprites/grey_inlay.png.import create mode 100644 Sprites/grey_pressed.png create mode 100644 Sprites/grey_pressed.png.import diff --git a/Scenes/Main/Main.tscn b/Scenes/Main/Main.tscn index ed20915..dfe8192 100644 --- a/Scenes/Main/Main.tscn +++ b/Scenes/Main/Main.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=21 format=3 uid="uid://bfil8sd154327"] +[gd_scene load_steps=23 format=3 uid="uid://bfil8sd154327"] [ext_resource type="Script" uid="uid://t71ewkpa5uqs" path="res://Scenes/Main/Main.cs" id="1_p8rbg"] [ext_resource type="Script" uid="uid://b77vh831r1e3c" path="res://Scenes/Main/MiraclePanel.cs" id="2_hcu3t"] [ext_resource type="PackedScene" uid="uid://rj1fsdlhju5y" path="res://Scenes/Main/miracle_button.tscn" id="3_qdkat"] [ext_resource type="Texture2D" uid="uid://dg6ac3jb1366r" path="res://Sprites/globe.svg" id="4_i3fi7"] +[ext_resource type="Script" uid="uid://ddshg236tlltt" path="res://Scripts/ActiveBuffsManager.cs" id="4_xggvw"] +[ext_resource type="PackedScene" uid="uid://b417dl07c13uc" path="res://Scenes/Main/buff_button.tscn" id="5_xd21n"] [ext_resource type="PackedScene" uid="uid://be5d0d3aweg0l" path="res://Scenes/Huts/HutMarker.tscn" id="6_cv8e0"] [ext_resource type="Script" uid="uid://dj2wyrq07gfp2" path="res://Scripts/PopulationVisualizer.cs" id="8_cv8e0"] [ext_resource type="PackedScene" uid="uid://8w7tvsgkev1y" path="res://Scenes/tree.tscn" id="8_hcu3t"] @@ -112,56 +114,8 @@ vertical_scroll_mode = 0 layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 - -[node name="Button" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button2" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button3" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button4" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button5" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button6" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button7" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button8" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button9" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" - -[node name="Button10" type="Button" parent="UiLayer/Control/Main/ScrollContainer2/HBoxContainer"] -layout_mode = 2 -disabled = true -text = "Effect" +script = ExtResource("4_xggvw") +_activeBuffScene = ExtResource("5_xd21n") [node name="Camera2D" type="Camera2D" parent="."] diff --git a/Scenes/Main/buff_button.tscn b/Scenes/Main/buff_button.tscn new file mode 100644 index 0000000..c6fcd10 --- /dev/null +++ b/Scenes/Main/buff_button.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://b417dl07c13uc"] + +[ext_resource type="Script" uid="uid://chnf0t5xdosys" path="res://Scripts/ActiveBuffUi.cs" id="1_7ujuu"] + +[node name="BuffButton" type="Button"] +focus_mode = 0 +disabled = true +button_mask = 0 +text = "Effect" +script = ExtResource("1_7ujuu") diff --git a/Scripts/ActiveBuffUi.cs b/Scripts/ActiveBuffUi.cs new file mode 100644 index 0000000..a364150 --- /dev/null +++ b/Scripts/ActiveBuffUi.cs @@ -0,0 +1,31 @@ +using Godot; +using ParasiticGod.Scripts.Core.Effects; + +namespace ParasiticGod.Scripts; + +[GlobalClass] +public partial class ActiveBuffUi : Button +{ + private Buff _buff; + + public void SetBuff(Buff buff) + { + _buff = buff; + Disabled = true; + UpdateDisplay(); + } + + public override void _Process(double delta) + { + if (_buff != null) + { + UpdateDisplay(); + } + } + + private void UpdateDisplay() + { + Text = _buff.Name; + TooltipText = $"x{_buff.Multiplier:F1} to {_buff.Name.Split(' ')[0]}\n{_buff.Duration:F0}s remaining"; + } +} \ No newline at end of file diff --git a/Scripts/ActiveBuffUi.cs.uid b/Scripts/ActiveBuffUi.cs.uid new file mode 100644 index 0000000..d76c4ca --- /dev/null +++ b/Scripts/ActiveBuffUi.cs.uid @@ -0,0 +1 @@ +uid://chnf0t5xdosys diff --git a/Scripts/ActiveBuffsManager.cs b/Scripts/ActiveBuffsManager.cs new file mode 100644 index 0000000..bce1eb8 --- /dev/null +++ b/Scripts/ActiveBuffsManager.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using Godot; +using ParasiticGod.Scripts.Core; +using ParasiticGod.Scripts.Core.Effects; +using ParasiticGod.Scripts.Singletons; + +namespace ParasiticGod.Scripts; + +[GlobalClass] +public partial class ActiveBuffsManager : Node +{ + [Export] private PackedScene _activeBuffScene; + + private readonly Dictionary _activeBuffUis = new(); + + public override void _Ready() + { + GameBus.Instance.BuffAdded += OnBuffAdded; + GameBus.Instance.BuffRemoved += OnBuffRemoved; + } + + public override void _ExitTree() + { + if (GameBus.Instance == null) return; + GameBus.Instance.BuffAdded -= OnBuffAdded; + GameBus.Instance.BuffRemoved -= OnBuffRemoved; + } + + private void OnBuffAdded(Buff buff) + { + var buffInstance = _activeBuffScene.Instantiate(); + AddChild(buffInstance); + buffInstance.SetBuff(buff); + _activeBuffUis.Add(buff.Id, buffInstance); + } + + private void OnBuffRemoved(Buff buff) + { + if (_activeBuffUis.TryGetValue(buff.Id, out var buffUi)) + { + buffUi.QueueFree(); + _activeBuffUis.Remove(buff.Id); + } + } +} \ No newline at end of file diff --git a/Scripts/ActiveBuffsManager.cs.uid b/Scripts/ActiveBuffsManager.cs.uid new file mode 100644 index 0000000..a790aab --- /dev/null +++ b/Scripts/ActiveBuffsManager.cs.uid @@ -0,0 +1 @@ +uid://ddshg236tlltt diff --git a/Scripts/Core/Effects/ApplyBuffEffect.cs b/Scripts/Core/Effects/ApplyBuffEffect.cs index 0b78c63..1763530 100644 --- a/Scripts/Core/Effects/ApplyBuffEffect.cs +++ b/Scripts/Core/Effects/ApplyBuffEffect.cs @@ -1,4 +1,5 @@ using Godot; +using ParasiticGod.Scripts.Singletons; namespace ParasiticGod.Scripts.Core.Effects; @@ -13,11 +14,13 @@ public partial class ApplyBuffEffect : Effect { var newBuff = new Buff { + Name = $"{TargetStat} x{Multiplier}", Multiplier = Multiplier, Duration = Duration }; gameState.ActiveBuffs.Add(newBuff); + GameBus.Instance.NotifyBuffAdded(newBuff); } public override string ToString() diff --git a/Scripts/Core/Effects/Buff.cs b/Scripts/Core/Effects/Buff.cs index 5960920..2722225 100644 --- a/Scripts/Core/Effects/Buff.cs +++ b/Scripts/Core/Effects/Buff.cs @@ -1,7 +1,11 @@ +using System; + namespace ParasiticGod.Scripts.Core.Effects; public class Buff { + public Guid Id { get; } = Guid.NewGuid(); // Unique identifier + public string Name { get; set; } // For display purposes public float Multiplier { get; set; } = 1.0f; public double Duration { get; set; } } \ No newline at end of file diff --git a/Scripts/Core/GameLogic.cs b/Scripts/Core/GameLogic.cs index 5333aff..c468676 100644 --- a/Scripts/Core/GameLogic.cs +++ b/Scripts/Core/GameLogic.cs @@ -1,4 +1,5 @@ using System; +using ParasiticGod.Scripts.Singletons; namespace ParasiticGod.Scripts.Core; @@ -23,6 +24,7 @@ public class GameLogic buff.Duration -= delta; if (buff.Duration <= 0) { + GameBus.Instance.NotifyBuffRemoved(buff); state.ActiveBuffs.RemoveAt(i); } } diff --git a/Scripts/Singletons/GameBus.cs b/Scripts/Singletons/GameBus.cs index 10bc7ac..0737dc9 100644 --- a/Scripts/Singletons/GameBus.cs +++ b/Scripts/Singletons/GameBus.cs @@ -18,6 +18,8 @@ public partial class GameBus : Node public event Action MiraclePerformed; public event Action> MiraclesUnlocked; public event Action MiracleCompleted; + public event Action BuffAdded; + public event Action BuffRemoved; public event Action PopulationVisualsUpdated; public override void _EnterTree() @@ -80,6 +82,16 @@ public partial class GameBus : Node PopulationVisualsUpdated?.Invoke(); } + public void NotifyBuffAdded(Buff buff) + { + BuffAdded?.Invoke(buff); + } + + public void NotifyBuffRemoved(Buff buff) + { + BuffRemoved?.Invoke(buff); + } + public void SubscribeToStat(Stat stat, Action listener) => _gameState.Subscribe(stat, listener); public void UnsubscribeFromStat(Stat stat, Action listener) => _gameState.Unsubscribe(stat, listener); diff --git a/Sprites/grey.png b/Sprites/grey.png new file mode 100644 index 0000000000000000000000000000000000000000..07eea7b660b913e3708b3651be410e99a8f13311 GIT binary patch literal 272 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUtd7dtgAr-gY-iqgPa1c2Daqp@- z4n>S7dH0+UoKtAHRsYaCwU3v>&vx72u9+3Px~KTHq2K0k9`Q-*XZacN2r}f_$GDxc z)fAL|{^r-e8nXx4AMG2YnlxD&Ob>`unOAB7ZD3${!yMAkZ>e=aX&Dnk1veu|$lCBX zh+?qe-_dMSWmdlDMStGSu;xW;_GWE9K5aMSl*3kGQzpkV?08!6eqsMbkQa1ITq8zopr0H={r8vpGIbNTyemyKVsYWg~t zym^a1zWsZO8q2{afdaPQq+Aqg~|A%H#Q!1*~m7DtR29%!=w1r`XcW(G+x z{Aague7Co{d|%FL#~W$=FW#C7Pgyp@Jn~H19H6XjiEBhjaDG}zd16s2LsF$)Qciw; vN=l_(a#3YLNxoiYZen_>9?*kECa!tO`6;PIE7bP0l+XkKY;<7~ literal 0 HcmV?d00001 diff --git a/Sprites/grey_pressed.png.import b/Sprites/grey_pressed.png.import new file mode 100644 index 0000000..c4c90a0 --- /dev/null +++ b/Sprites/grey_pressed.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://13n1kf5nlb6i" +path="res://.godot/imported/grey_pressed.png-bfad8d00b793dd314961b15e0757bbdf.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/grey_pressed.png" +dest_files=["res://.godot/imported/grey_pressed.png-bfad8d00b793dd314961b15e0757bbdf.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1