From 1e004b62b827523b76e1c7ae5ad3ef5e89627de9 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Mon, 13 Oct 2025 09:57:49 +0200 Subject: [PATCH 01/10] Implemented first version of EventResources --- Babushka.sln.DotSettings.user | 1 + project.godot | 1 + resources/events/test.tres | 10 +++++ scenes/Babushka_scene_indoor_vesnas_room.tscn | 2 - scenes/Babushka_scene_startMenu.tscn | 29 +++++++++++- scripts/CSharp/Events/EventCaller.cs | 13 ++++++ scripts/CSharp/Events/EventCaller.cs.uid | 1 + scripts/CSharp/Events/EventListener.cs | 28 ++++++++++++ scripts/CSharp/Events/EventListener.cs.uid | 1 + scripts/CSharp/Events/EventResource.cs | 44 +++++++++++++++++++ scripts/CSharp/Events/EventResource.cs.uid | 1 + 11 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 resources/events/test.tres create mode 100644 scripts/CSharp/Events/EventCaller.cs create mode 100644 scripts/CSharp/Events/EventCaller.cs.uid create mode 100644 scripts/CSharp/Events/EventListener.cs create mode 100644 scripts/CSharp/Events/EventListener.cs.uid create mode 100644 scripts/CSharp/Events/EventResource.cs create mode 100644 scripts/CSharp/Events/EventResource.cs.uid diff --git a/Babushka.sln.DotSettings.user b/Babushka.sln.DotSettings.user index 349fb41..2e4589b 100644 --- a/Babushka.sln.DotSettings.user +++ b/Babushka.sln.DotSettings.user @@ -8,6 +8,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/project.godot b/project.godot index baff4e1..c7180b7 100644 --- a/project.godot +++ b/project.godot @@ -144,6 +144,7 @@ directories/tres_directory={ "default_bus_layout": "res://audio/default_bus_layout.tres", "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", +"events/test": "res://resources/events/test.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", "inventory_interactable_outline": "res://art/materials/inventory_interactable_outline.tres", diff --git a/resources/events/test.tres b/resources/events/test.tres new file mode 100644 index 0000000..a01c70d --- /dev/null +++ b/resources/events/test.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://beed6ikqf46vk"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Events/EventResource.cs" id="1_6u8ge"] + +[resource] +resource_name = "kafjhkj" +script = ExtResource("1_6u8ge") +Name = "kafjhkj" +_showLog = true +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scenes/Babushka_scene_indoor_vesnas_room.tscn b/scenes/Babushka_scene_indoor_vesnas_room.tscn index d5097bf..c2b4f8d 100644 --- a/scenes/Babushka_scene_indoor_vesnas_room.tscn +++ b/scenes/Babushka_scene_indoor_vesnas_room.tscn @@ -98,7 +98,6 @@ _followNode = NodePath("../Vesna/CharacterBody2D") [node name="BedInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(-1429, 487) -_useOutline = false _useSprite = false _id = 1 @@ -109,7 +108,6 @@ toStatus = 2 [node name="DoorInteraction" parent="." instance=ExtResource("8_phqdf")] position = Vector2(777, 201) -_useOutline = false _useSprite = false _id = 0 diff --git a/scenes/Babushka_scene_startMenu.tscn b/scenes/Babushka_scene_startMenu.tscn index f4ea948..43f1fc7 100644 --- a/scenes/Babushka_scene_startMenu.tscn +++ b/scenes/Babushka_scene_startMenu.tscn @@ -1,8 +1,11 @@ -[gd_scene load_steps=4 format=3 uid="uid://c6wnoif01ltld"] +[gd_scene load_steps=7 format=3 uid="uid://c6wnoif01ltld"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_fj2fh"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Events/EventCaller.cs" id="3_beyjr"] [ext_resource type="Texture2D" uid="uid://c7atj6ohlmir3" path="res://art/ui/StartScreen/titlescreen.png" id="3_r0y6o"] +[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Events/EventListener.cs" id="4_beyjr"] [ext_resource type="Texture2D" uid="uid://du612t3xytly3" path="res://art/ui/StartScreen/babushkalog_white.png" id="4_dl0t1"] +[ext_resource type="Resource" uid="uid://beed6ikqf46vk" path="res://resources/events/test.tres" id="5_5a78e"] [node name="BabushkaSceneStartMenu" type="Node2D"] script = ExtResource("1_fj2fh") @@ -52,6 +55,24 @@ toggle_mode = true text = "Quit " +[node name="Quit2" type="Button" parent="CanvasLayer/TextureRect"] +custom_minimum_size = Vector2(100, 30) +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 205.0 +offset_top = 215.0 +offset_right = 405.0 +offset_bottom = 255.0 +grow_vertical = 2 +scale = Vector2(2, 2) +toggle_mode = true +text = "Test +" +script = ExtResource("3_beyjr") +eventResource = ExtResource("5_5a78e") + [node name="Text" type="TextureRect" parent="CanvasLayer/TextureRect"] layout_mode = 1 offset_left = 50.0 @@ -62,5 +83,11 @@ scale = Vector2(0.5, 0.5) texture = ExtResource("4_dl0t1") stretch_mode = 3 +[node name="Node" type="Node" parent="."] +script = ExtResource("4_beyjr") +_eventResource = ExtResource("5_5a78e") +_showLog = true + [connection signal="pressed" from="CanvasLayer/TextureRect/Start" to="." method="LoadScene"] [connection signal="pressed" from="CanvasLayer/TextureRect/Quit" to="." method="Quit"] +[connection signal="pressed" from="CanvasLayer/TextureRect/Quit2" to="CanvasLayer/TextureRect/Quit2" method="RaiseEvent"] diff --git a/scripts/CSharp/Events/EventCaller.cs b/scripts/CSharp/Events/EventCaller.cs new file mode 100644 index 0000000..c6171f2 --- /dev/null +++ b/scripts/CSharp/Events/EventCaller.cs @@ -0,0 +1,13 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Events; + +public partial class EventCaller : Node +{ + [Export] EventResource eventResource; + + public void RaiseEvent() + { + eventResource.Raise(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventCaller.cs.uid b/scripts/CSharp/Events/EventCaller.cs.uid new file mode 100644 index 0000000..5c245d3 --- /dev/null +++ b/scripts/CSharp/Events/EventCaller.cs.uid @@ -0,0 +1 @@ +uid://b5dotkx17gvxg diff --git a/scripts/CSharp/Events/EventListener.cs b/scripts/CSharp/Events/EventListener.cs new file mode 100644 index 0000000..54a6307 --- /dev/null +++ b/scripts/CSharp/Events/EventListener.cs @@ -0,0 +1,28 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Events; + +public partial class EventListener : Node +{ + [Export] private EventResource _eventResource; + [Export] private bool _showLog; + + [Signal] public delegate void EventRaisedEventHandler(); + + public override void _EnterTree() + { + _eventResource.RegisterListener(this); + } + + public override void _ExitTree() + { + _eventResource.UnregisterListener(this); + } + + public void RaiseEvent() + { + if(_showLog) + GD.Print("Event Raised on: " + Name); + EmitSignal(SignalName.EventRaised); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventListener.cs.uid b/scripts/CSharp/Events/EventListener.cs.uid new file mode 100644 index 0000000..a140a15 --- /dev/null +++ b/scripts/CSharp/Events/EventListener.cs.uid @@ -0,0 +1 @@ +uid://bc6uaaxsx5k5p diff --git a/scripts/CSharp/Events/EventResource.cs b/scripts/CSharp/Events/EventResource.cs new file mode 100644 index 0000000..fe4771f --- /dev/null +++ b/scripts/CSharp/Events/EventResource.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Events; + +[GlobalClass] [Tool] +public partial class EventResource : Resource +{ + [Export] private string Name + { + get { return ResourceName; } + set { ResourceName = value; } + } + + [Export] private bool _showLog; + [ExportToolButton("Raise")] Callable _raiseAction => Callable.From(Raise); + + private List _eventListeners = new (); + + public void RegisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Registering listener " + listener); + _eventListeners.Add(listener); + } + + public void UnregisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Unregistering listener " + listener); + _eventListeners.Remove(listener); + } + + public void Raise() + { + if(_showLog) + GD.Print("Raising event: " + Name); + + foreach (var eventListener in _eventListeners) + { + eventListener.RaiseEvent(); + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventResource.cs.uid b/scripts/CSharp/Events/EventResource.cs.uid new file mode 100644 index 0000000..207618d --- /dev/null +++ b/scripts/CSharp/Events/EventResource.cs.uid @@ -0,0 +1 @@ +uid://ci3t5mvnopntg From a593be82739ba5adfc3edec1119e2a3c7318df7f Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Sat, 18 Oct 2025 17:15:35 +0200 Subject: [PATCH 02/10] :memo: added documentation and improved event scope --- Babushka.csproj | 1 + project.godot | 2 +- resources/events/{test.tres => test2.tres} | 8 +-- scenes/Babushka_scene_startMenu.tscn | 22 +++---- scripts/CSharp/Events/EventCaller.cs | 13 ---- scripts/CSharp/Events/EventListener.cs | 28 --------- scripts/CSharp/Events/EventResource.cs | 44 ------------- .../CSharp/Low Code/Events/EventListener.cs | 62 +++++++++++++++++++ .../Events/EventListener.cs.uid | 0 scripts/CSharp/Low Code/Events/EventRaiser.cs | 35 +++++++++++ .../Events/EventRaiser.cs.uid} | 0 .../CSharp/Low Code/Events/EventResource.cs | 62 +++++++++++++++++++ .../Events/EventResource.cs.uid | 0 13 files changed, 175 insertions(+), 102 deletions(-) rename resources/events/{test.tres => test2.tres} (54%) delete mode 100644 scripts/CSharp/Events/EventCaller.cs delete mode 100644 scripts/CSharp/Events/EventListener.cs delete mode 100644 scripts/CSharp/Events/EventResource.cs create mode 100644 scripts/CSharp/Low Code/Events/EventListener.cs rename scripts/CSharp/{ => Low Code}/Events/EventListener.cs.uid (100%) create mode 100644 scripts/CSharp/Low Code/Events/EventRaiser.cs rename scripts/CSharp/{Events/EventCaller.cs.uid => Low Code/Events/EventRaiser.cs.uid} (100%) create mode 100644 scripts/CSharp/Low Code/Events/EventResource.cs rename scripts/CSharp/{ => Low Code}/Events/EventResource.cs.uid (100%) diff --git a/Babushka.csproj b/Babushka.csproj index 76acd77..8d3587e 100644 --- a/Babushka.csproj +++ b/Babushka.csproj @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/project.godot b/project.godot index c7180b7..ff69202 100644 --- a/project.godot +++ b/project.godot @@ -144,7 +144,6 @@ directories/tres_directory={ "default_bus_layout": "res://audio/default_bus_layout.tres", "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", -"events/test": "res://resources/events/test.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", "inventory_interactable_outline": "res://art/materials/inventory_interactable_outline.tres", @@ -163,6 +162,7 @@ directories/tres_directory={ "test/test_01": "res://resources/quests/test/test_01.tres", "test/test_02": "res://resources/quests/test/test_02.tres", "test/test_03": "res://resources/quests/test/test_03.tres", +"test2": "res://resources/events/test2.tres", "textbubble_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_TextBubbles/textbubble_style.tres", "tomato": "res://resources/items/tomato.tres", "tomato_seed": "res://resources/items/tomato_seed.tres", diff --git a/resources/events/test.tres b/resources/events/test2.tres similarity index 54% rename from resources/events/test.tres rename to resources/events/test2.tres index a01c70d..14b8ba4 100644 --- a/resources/events/test.tres +++ b/resources/events/test2.tres @@ -1,10 +1,8 @@ -[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://beed6ikqf46vk"] +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"] -[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Events/EventResource.cs" id="1_6u8ge"] +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_jm77s"] [resource] -resource_name = "kafjhkj" -script = ExtResource("1_6u8ge") -Name = "kafjhkj" +script = ExtResource("1_jm77s") _showLog = true metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scenes/Babushka_scene_startMenu.tscn b/scenes/Babushka_scene_startMenu.tscn index 43f1fc7..55101a6 100644 --- a/scenes/Babushka_scene_startMenu.tscn +++ b/scenes/Babushka_scene_startMenu.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=7 format=3 uid="uid://c6wnoif01ltld"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_fj2fh"] -[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Events/EventCaller.cs" id="3_beyjr"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_5a78e"] [ext_resource type="Texture2D" uid="uid://c7atj6ohlmir3" path="res://art/ui/StartScreen/titlescreen.png" id="3_r0y6o"] -[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Events/EventListener.cs" id="4_beyjr"] +[ext_resource type="Resource" uid="uid://bgfxakxxfmoxs" path="res://resources/events/test2.tres" id="4_5a78e"] [ext_resource type="Texture2D" uid="uid://du612t3xytly3" path="res://art/ui/StartScreen/babushkalog_white.png" id="4_dl0t1"] -[ext_resource type="Resource" uid="uid://beed6ikqf46vk" path="res://resources/events/test.tres" id="5_5a78e"] +[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="6_5a78e"] [node name="BabushkaSceneStartMenu" type="Node2D"] script = ExtResource("1_fj2fh") @@ -55,7 +55,7 @@ toggle_mode = true text = "Quit " -[node name="Quit2" type="Button" parent="CanvasLayer/TextureRect"] +[node name="Test" type="Button" parent="CanvasLayer/TextureRect"] custom_minimum_size = Vector2(100, 30) layout_mode = 1 anchors_preset = 4 @@ -70,8 +70,8 @@ scale = Vector2(2, 2) toggle_mode = true text = "Test " -script = ExtResource("3_beyjr") -eventResource = ExtResource("5_5a78e") +script = ExtResource("3_5a78e") +_eventResources = Array[Object]([ExtResource("4_5a78e")]) [node name="Text" type="TextureRect" parent="CanvasLayer/TextureRect"] layout_mode = 1 @@ -83,11 +83,11 @@ scale = Vector2(0.5, 0.5) texture = ExtResource("4_dl0t1") stretch_mode = 3 -[node name="Node" type="Node" parent="."] -script = ExtResource("4_beyjr") -_eventResource = ExtResource("5_5a78e") -_showLog = true +[node name="EventListener" type="Node" parent="."] +script = ExtResource("6_5a78e") +_eventResources = Array[Object]([ExtResource("4_5a78e")]) [connection signal="pressed" from="CanvasLayer/TextureRect/Start" to="." method="LoadScene"] [connection signal="pressed" from="CanvasLayer/TextureRect/Quit" to="." method="Quit"] -[connection signal="pressed" from="CanvasLayer/TextureRect/Quit2" to="CanvasLayer/TextureRect/Quit2" method="RaiseEvent"] +[connection signal="pressed" from="CanvasLayer/TextureRect/Test" to="CanvasLayer/TextureRect/Test" method="RaiseEvents"] +[connection signal="EventRaised" from="EventListener" to="CanvasLayer/TextureRect/Test" method="hide"] diff --git a/scripts/CSharp/Events/EventCaller.cs b/scripts/CSharp/Events/EventCaller.cs deleted file mode 100644 index c6171f2..0000000 --- a/scripts/CSharp/Events/EventCaller.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Godot; - -namespace Babushka.scripts.CSharp.Events; - -public partial class EventCaller : Node -{ - [Export] EventResource eventResource; - - public void RaiseEvent() - { - eventResource.Raise(); - } -} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventListener.cs b/scripts/CSharp/Events/EventListener.cs deleted file mode 100644 index 54a6307..0000000 --- a/scripts/CSharp/Events/EventListener.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Godot; - -namespace Babushka.scripts.CSharp.Events; - -public partial class EventListener : Node -{ - [Export] private EventResource _eventResource; - [Export] private bool _showLog; - - [Signal] public delegate void EventRaisedEventHandler(); - - public override void _EnterTree() - { - _eventResource.RegisterListener(this); - } - - public override void _ExitTree() - { - _eventResource.UnregisterListener(this); - } - - public void RaiseEvent() - { - if(_showLog) - GD.Print("Event Raised on: " + Name); - EmitSignal(SignalName.EventRaised); - } -} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventResource.cs b/scripts/CSharp/Events/EventResource.cs deleted file mode 100644 index fe4771f..0000000 --- a/scripts/CSharp/Events/EventResource.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; -using Godot; - -namespace Babushka.scripts.CSharp.Events; - -[GlobalClass] [Tool] -public partial class EventResource : Resource -{ - [Export] private string Name - { - get { return ResourceName; } - set { ResourceName = value; } - } - - [Export] private bool _showLog; - [ExportToolButton("Raise")] Callable _raiseAction => Callable.From(Raise); - - private List _eventListeners = new (); - - public void RegisterListener(EventListener listener) - { - if(_showLog) - GD.Print("Registering listener " + listener); - _eventListeners.Add(listener); - } - - public void UnregisterListener(EventListener listener) - { - if(_showLog) - GD.Print("Unregistering listener " + listener); - _eventListeners.Remove(listener); - } - - public void Raise() - { - if(_showLog) - GD.Print("Raising event: " + Name); - - foreach (var eventListener in _eventListeners) - { - eventListener.RaiseEvent(); - } - } -} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventListener.cs b/scripts/CSharp/Low Code/Events/EventListener.cs new file mode 100644 index 0000000..2bf3693 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventListener.cs @@ -0,0 +1,62 @@ +using System; +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Listens to an as long as this node is in the tree (i.e., during playtime). +/// +public partial class EventListener : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private Array _eventResources; + + /// + /// Log to console when this event is being raised. + /// + [Export] private bool _showLog; + + /// + /// The signal that is triggered when this listener is called by one of the . + /// + [Signal] public delegate void EventRaisedEventHandler(); + + + /// + /// Subscribes to all s present in the array. + /// + /// + public override void _EnterTree() + { + foreach (var eventRes in _eventResources) + { + eventRes.RegisterListener(this); + } + } + + /// + /// Unsubscribes from all s present in the array. + /// + /// + public override void _ExitTree() + { + foreach (var eventRes in _eventResources) + { + eventRes.UnregisterListener(this); + } + } + + /// + /// Called by a s from the array. + /// Propagates the event by emitting signal. + /// + public void Invoke() + { + if(_showLog) + GD.Print("Event Raised on: " + Name); + EmitSignal(SignalName.EventRaised); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventListener.cs.uid b/scripts/CSharp/Low Code/Events/EventListener.cs.uid similarity index 100% rename from scripts/CSharp/Events/EventListener.cs.uid rename to scripts/CSharp/Low Code/Events/EventListener.cs.uid diff --git a/scripts/CSharp/Low Code/Events/EventRaiser.cs b/scripts/CSharp/Low Code/Events/EventRaiser.cs new file mode 100644 index 0000000..2bebce3 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventRaiser.cs @@ -0,0 +1,35 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Raises one or more s from the scene. +/// +public partial class EventRaiser : Node +{ + /// + /// The s to call + /// + [Export] Array _eventResources; + + /// + /// Raises all s present in . + /// + public void RaiseEvents() + { + foreach (var eventRes in _eventResources) + { + eventRes.Raise(); + } + } + + /// + /// Raises at index. + /// + /// + public void RaiseEvent(int index) + { + _eventResources[index].Raise(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventCaller.cs.uid b/scripts/CSharp/Low Code/Events/EventRaiser.cs.uid similarity index 100% rename from scripts/CSharp/Events/EventCaller.cs.uid rename to scripts/CSharp/Low Code/Events/EventRaiser.cs.uid diff --git a/scripts/CSharp/Low Code/Events/EventResource.cs b/scripts/CSharp/Low Code/Events/EventResource.cs new file mode 100644 index 0000000..1560c00 --- /dev/null +++ b/scripts/CSharp/Low Code/Events/EventResource.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Events; + +/// +/// Represents an event in the project space. +/// Can be called by and subscribed to by . +/// +[GlobalClass] [Tool] +public partial class EventResource : Resource +{ + /// + /// Log into console when this event resource is adding or removing listeners, and when it's raised. + /// + [Export] private bool _showLog; + + /// + /// Raise-Button Call with Editor Export for easier debugging. + /// Beware: This will only work with custom event listeners that register at edit-time. + /// Standard register and deregister during playtime. + /// + [ExportToolButton("Raise")] Callable _raiseAction => Callable.From(Raise); + + private List _eventListeners = new (); + + /// + /// Adds an EventListener to the calling list for this event. + /// + /// + public void RegisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Registering listener " + listener); + _eventListeners.Add(listener); + } + + /// + /// Removes an Eventlistener from the calling list for this event. + /// + /// + public void UnregisterListener(EventListener listener) + { + if(_showLog) + GD.Print("Unregistering listener " + listener); + _eventListeners.Remove(listener); + } + + /// + /// Raises this event on all current listeners. + /// + public void Raise() + { + if(_showLog) + GD.Print("Raising event: " + ResourcePath.GetFile().TrimSuffix(".tres")); + + foreach (var eventListener in _eventListeners) + { + eventListener.Invoke(); + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Events/EventResource.cs.uid b/scripts/CSharp/Low Code/Events/EventResource.cs.uid similarity index 100% rename from scripts/CSharp/Events/EventResource.cs.uid rename to scripts/CSharp/Low Code/Events/EventResource.cs.uid From a74abe684b792f1f7a745700b256cbae11e335bc Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:33:38 +0200 Subject: [PATCH 03/10] Godot upgrade to 4.5 --- Babushka.csproj | 4 ++-- project.godot | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Babushka.csproj b/Babushka.csproj index 8d3587e..e6eea3b 100644 --- a/Babushka.csproj +++ b/Babushka.csproj @@ -1,4 +1,4 @@ - + net8.0 true @@ -6,6 +6,6 @@ - + \ No newline at end of file diff --git a/project.godot b/project.godot index ff69202..4b22b5d 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="Babushka" run/main_scene="uid://bopv10dqm1knc" -config/features=PackedStringArray("4.4", "C#", "Forward Plus") +config/features=PackedStringArray("4.5", "C#", "Forward Plus") run/max_fps=120 boot_splash/fullsize=false boot_splash/image="uid://utam4axkvutc" @@ -121,6 +121,7 @@ directories/tres_directory={ "8_goto_bed": "res://resources/quests/demo/8_goto_bed.tres", "9_talk_to_chuga": "res://resources/quests/demo/9_talk_to_chuga.tres", "Babushka_NPC_Namebox_background": "res://dialog/Babushka_NPC_Namebox_background.tres", +"ColorEvent": "res://resources/events/ColorEvent.tres", "InputFieldsStyle": "res://addons/dialogic/Editor/Events/styles/InputFieldsStyle.tres", "MainTheme": "res://addons/dialogic/Editor/Theme/MainTheme.tres", "NPC_narrative": "res://dialog/NPC_narrative.tres", @@ -132,6 +133,7 @@ directories/tres_directory={ "SectionPanel": "res://addons/dialogic/Editor/Events/styles/SectionPanel.tres", "SimpleButtonHover": "res://addons/dialogic/Editor/Events/styles/SimpleButtonHover.tres", "SimpleButtonNormal": "res://addons/dialogic/Editor/Events/styles/SimpleButtonNormal.tres", +"TestStringEvent": "res://resources/events/TestStringEvent.tres", "TextBackground": "res://addons/dialogic/Editor/Events/styles/TextBackground.tres", "TitleBgStylebox": "res://addons/dialogic/Editor/Common/TitleBgStylebox.tres", "babushka_dialogue_style": "res://addons/babushkahelpers/babushka_dialogue_style.tres", @@ -162,7 +164,6 @@ directories/tres_directory={ "test/test_01": "res://resources/quests/test/test_01.tres", "test/test_02": "res://resources/quests/test/test_02.tres", "test/test_03": "res://resources/quests/test/test_03.tres", -"test2": "res://resources/events/test2.tres", "textbubble_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_TextBubbles/textbubble_style.tres", "tomato": "res://resources/items/tomato.tres", "tomato_seed": "res://resources/items/tomato_seed.tres", From 5bcbee8865160440bd905511e2e9755eaf0451c9 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:38:15 +0200 Subject: [PATCH 04/10] created test scene and removed event test elements from start scene --- resources/events/ColorEvent.tres | 9 ++++ resources/events/TestStringEvent.tres | 9 ++++ scenes/Babushka_scene_startMenu.tscn | 29 +----------- scenes/testing/eventTest.tscn | 63 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 resources/events/ColorEvent.tres create mode 100644 resources/events/TestStringEvent.tres create mode 100644 scenes/testing/eventTest.tscn diff --git a/resources/events/ColorEvent.tres b/resources/events/ColorEvent.tres new file mode 100644 index 0000000..03399f5 --- /dev/null +++ b/resources/events/ColorEvent.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://dc7e13hq47uma"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_ufwo5"] + +[resource] +script = ExtResource("1_ufwo5") +_showLog = true +Payload = Color(0.84002423, 0.44197178, 0.5653889, 1) +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/events/TestStringEvent.tres b/resources/events/TestStringEvent.tres new file mode 100644 index 0000000..aa7a312 --- /dev/null +++ b/resources/events/TestStringEvent.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_dd3u7"] + +[resource] +script = ExtResource("1_dd3u7") +_showLog = true +Payload = "This is a test." +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scenes/Babushka_scene_startMenu.tscn b/scenes/Babushka_scene_startMenu.tscn index 55101a6..f4ea948 100644 --- a/scenes/Babushka_scene_startMenu.tscn +++ b/scenes/Babushka_scene_startMenu.tscn @@ -1,11 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://c6wnoif01ltld"] +[gd_scene load_steps=4 format=3 uid="uid://c6wnoif01ltld"] [ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_fj2fh"] -[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_5a78e"] [ext_resource type="Texture2D" uid="uid://c7atj6ohlmir3" path="res://art/ui/StartScreen/titlescreen.png" id="3_r0y6o"] -[ext_resource type="Resource" uid="uid://bgfxakxxfmoxs" path="res://resources/events/test2.tres" id="4_5a78e"] [ext_resource type="Texture2D" uid="uid://du612t3xytly3" path="res://art/ui/StartScreen/babushkalog_white.png" id="4_dl0t1"] -[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="6_5a78e"] [node name="BabushkaSceneStartMenu" type="Node2D"] script = ExtResource("1_fj2fh") @@ -55,24 +52,6 @@ toggle_mode = true text = "Quit " -[node name="Test" type="Button" parent="CanvasLayer/TextureRect"] -custom_minimum_size = Vector2(100, 30) -layout_mode = 1 -anchors_preset = 4 -anchor_top = 0.5 -anchor_bottom = 0.5 -offset_left = 205.0 -offset_top = 215.0 -offset_right = 405.0 -offset_bottom = 255.0 -grow_vertical = 2 -scale = Vector2(2, 2) -toggle_mode = true -text = "Test -" -script = ExtResource("3_5a78e") -_eventResources = Array[Object]([ExtResource("4_5a78e")]) - [node name="Text" type="TextureRect" parent="CanvasLayer/TextureRect"] layout_mode = 1 offset_left = 50.0 @@ -83,11 +62,5 @@ scale = Vector2(0.5, 0.5) texture = ExtResource("4_dl0t1") stretch_mode = 3 -[node name="EventListener" type="Node" parent="."] -script = ExtResource("6_5a78e") -_eventResources = Array[Object]([ExtResource("4_5a78e")]) - [connection signal="pressed" from="CanvasLayer/TextureRect/Start" to="." method="LoadScene"] [connection signal="pressed" from="CanvasLayer/TextureRect/Quit" to="." method="Quit"] -[connection signal="pressed" from="CanvasLayer/TextureRect/Test" to="CanvasLayer/TextureRect/Test" method="RaiseEvents"] -[connection signal="EventRaised" from="EventListener" to="CanvasLayer/TextureRect/Test" method="hide"] diff --git a/scenes/testing/eventTest.tscn b/scenes/testing/eventTest.tscn new file mode 100644 index 0000000..d7a968c --- /dev/null +++ b/scenes/testing/eventTest.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=6 format=3 uid="uid://6n3p3psmxovj"] + +[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="1_w5ykc"] +[ext_resource type="Resource" uid="uid://dc7e13hq47uma" path="res://resources/events/ColorEvent.tres" id="2_4h3ry"] +[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_bj4kf"] +[ext_resource type="Resource" uid="uid://bgfxakxxfmoxs" path="res://resources/events/TestStringEvent.tres" id="4_5dsed"] +[ext_resource type="Script" uid="uid://co1b320qemg1i" path="res://scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs" id="5_nm8dh"] + +[node name="EventTest" type="Node2D"] + +[node name="Control" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 0 +offset_top = -1.0 +offset_right = 513.0 +offset_bottom = 329.0 + +[node name="ColorRect" type="ColorRect" parent="Control"] +layout_mode = 0 +offset_right = 178.0 +offset_bottom = 145.0 +script = ExtResource("1_w5ykc") +_eventResources = Array[Object]([ExtResource("2_4h3ry")]) +_showLog = true + +[node name="LabelTextEventButton" type="Button" parent="Control"] +layout_mode = 0 +offset_left = 194.0 +offset_top = 148.0 +offset_right = 351.0 +offset_bottom = 179.0 +text = "Show Event Text +" +script = ExtResource("3_bj4kf") +_eventResources = Array[Object]([ExtResource("4_5dsed")]) + +[node name="ChangeColorButton" type="Button" parent="Control"] +layout_mode = 0 +offset_top = 148.0 +offset_right = 112.0 +offset_bottom = 179.0 +text = "Change Color +" +script = ExtResource("5_nm8dh") +_eventResource = ExtResource("2_4h3ry") + +[node name="TestLabel" type="Label" parent="Control"] +layout_mode = 0 +offset_left = 237.0 +offset_top = 54.0 +offset_right = 277.0 +offset_bottom = 77.0 +script = ExtResource("1_w5ykc") +_eventResources = Array[Object]([ExtResource("4_5dsed")]) + +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(239, 110) +zoom = Vector2(3.4, 3.4) + +[connection signal="NewEventPayload" from="Control/ColorRect" to="Control/ColorRect" method="set_color"] +[connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"] +[connection signal="pressed" from="Control/ChangeColorButton" to="Control/ChangeColorButton" method="RandomizeEventResource"] +[connection signal="EventRaisedWithPayload" from="Control/TestLabel" to="Control/TestLabel" method="set_text"] From ef56f79d5c1ec9591b5006254cb79c978bb208ad Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:39:01 +0200 Subject: [PATCH 05/10] :sparkles: Added event payload and Valuechange-handling --- resources/events/test2.tres | 8 ---- .../CSharp/Low Code/Events/EventListener.cs | 37 ++++++++++++++++++- .../CSharp/Low Code/Events/EventResource.cs | 35 +++++++++++++++++- 3 files changed, 69 insertions(+), 11 deletions(-) delete mode 100644 resources/events/test2.tres diff --git a/resources/events/test2.tres b/resources/events/test2.tres deleted file mode 100644 index 14b8ba4..0000000 --- a/resources/events/test2.tres +++ /dev/null @@ -1,8 +0,0 @@ -[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"] - -[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_jm77s"] - -[resource] -script = ExtResource("1_jm77s") -_showLog = true -metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/scripts/CSharp/Low Code/Events/EventListener.cs b/scripts/CSharp/Low Code/Events/EventListener.cs index 2bf3693..caa2801 100644 --- a/scripts/CSharp/Low Code/Events/EventListener.cs +++ b/scripts/CSharp/Low Code/Events/EventListener.cs @@ -1,4 +1,3 @@ -using System; using Godot; using Godot.Collections; @@ -23,6 +22,26 @@ public partial class EventListener : Node /// The signal that is triggered when this listener is called by one of the . /// [Signal] public delegate void EventRaisedEventHandler(); + + /// + /// The signal that is triggered when this listener is called by one of the . + /// + [Signal] public delegate void EventRaisedWithPayloadEventHandler(Variant payload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void PayloadChangedEventHandler(Variant payload, Variant oldPayload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void NewEventPayloadEventHandler(Variant payload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void OldEventPayloadEventHandler(Variant oldPayload); /// @@ -53,10 +72,24 @@ public partial class EventListener : Node /// Called by a s from the array. /// Propagates the event by emitting signal. /// - public void Invoke() + public void EventInvoked(Variant payload) { if(_showLog) GD.Print("Event Raised on: " + Name); EmitSignal(SignalName.EventRaised); + EmitSignal(SignalName.EventRaisedWithPayload, payload); + } + + /// + /// Called by a s from the array. + /// Propagates the event by emitting signal. + /// + public void EventPayloadChanged(Variant payload, Variant oldPayload) + { + if(_showLog) + GD.Print($"Calling Event Payload Changed Signals on: " + Name); + EmitSignal(SignalName.PayloadChanged, payload, oldPayload); + EmitSignal(SignalName.NewEventPayload, payload); + EmitSignal(SignalName.OldEventPayload, oldPayload); } } \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventResource.cs b/scripts/CSharp/Low Code/Events/EventResource.cs index 1560c00..4811348 100644 --- a/scripts/CSharp/Low Code/Events/EventResource.cs +++ b/scripts/CSharp/Low Code/Events/EventResource.cs @@ -14,6 +14,24 @@ public partial class EventResource : Resource /// Log into console when this event resource is adding or removing listeners, and when it's raised. /// [Export] private bool _showLog; + + [Export] + public Variant Payload + { + get { return _payload; } + set + { + if (!_payload.Equals(value)) + { + _lastPayload = _payload; + _payload = value; + ValueChangeHandler(); + } + } + } + + private Variant _payload; + private Variant _lastPayload; /// /// Raise-Button Call with Editor Export for easier debugging. @@ -56,7 +74,22 @@ public partial class EventResource : Resource foreach (var eventListener in _eventListeners) { - eventListener.Invoke(); + eventListener.EventInvoked(_payload); } } + + /// + /// Called when the Payload value changed. + /// + public void ValueChangeHandler() + { + if(_showLog) + GD.Print($"Event payload changed from {_lastPayload} to {_payload} on event resource: " + ResourcePath.GetFile().TrimSuffix(".tres")); + + foreach (var eventListener in _eventListeners) + { + eventListener.EventPayloadChanged(_payload, _lastPayload); + } + } + } \ No newline at end of file From 5cf250b295eed950279a1cfabf428bb0e55cf678 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:39:17 +0200 Subject: [PATCH 06/10] :sparkles: Added randomizer class for certain types of EventResources --- .../Low Code/Randomizer/VariantRandomizer.cs | 54 +++++++++++++++++++ .../Randomizer/VariantRandomizer.cs.uid | 1 + 2 files changed, 55 insertions(+) create mode 100644 scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs create mode 100644 scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs new file mode 100644 index 0000000..959fa1c --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs @@ -0,0 +1,54 @@ +using System; +using Babushka.scripts.CSharp.Low_Code.Events; +using Godot; +using Microsoft.VisualBasic; + +namespace Babushka.scripts.CSharp.Low_Code.Randomizer; + +/// +/// A class to randomize the payload value of select types of s. +/// +public partial class VariantRandomizer : Node +{ + /// + /// The event resource to work on. + /// + [Export] public EventResource _eventResource; + + /// + /// Sets the payload of a randomizable event resource to a random value. + /// + public void RandomizeEventResource() + { + switch (_eventResource.Payload.VariantType) + { + case Variant.Type.Color: + _eventResource.Payload= GetRandomColor(); + break; + case Variant.Type.Int: + _eventResource.Payload= GetRandomInt(); + break; + case Variant.Type.Float: + _eventResource.Payload= GetRandomFloat(); + break; + } + } + + private Color GetRandomColor() + { + Random rand = new Random(); + return new Color(rand.NextSingle(), rand.NextSingle(), rand.NextSingle(), 1.0f); + } + + private int GetRandomInt() + { + Random rand = new Random(); + return rand.Next(); + } + + private float GetRandomFloat() + { + Random rand = new Random(); + return rand.NextSingle(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid new file mode 100644 index 0000000..ece8168 --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid @@ -0,0 +1 @@ +uid://co1b320qemg1i From 080ebaae47331aefa79639096221a02f622f5e59 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:50:48 +0200 Subject: [PATCH 07/10] removed redundant import statement --- scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs index 959fa1c..178af0d 100644 --- a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs @@ -1,7 +1,7 @@ using System; using Babushka.scripts.CSharp.Low_Code.Events; using Godot; -using Microsoft.VisualBasic; + namespace Babushka.scripts.CSharp.Low_Code.Randomizer; From c96e6da78e75a0ec91b41ea4cae4435328024466 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 28 Oct 2025 11:57:36 +0100 Subject: [PATCH 08/10] :sparkles: Separated events from variables and adjusted test scene --- .../babushka_dialogue_style.tres | 10 --- addons/dialogic/vesna_style.tres | 9 --- dialog/NPC_narrative.tres | 9 --- project.godot | 5 +- resources/events/ColorEvent.tres | 9 --- .../test/event_colorButtonClicked.tres} | 8 +-- .../low code/test/event_textLabelClicked.tres | 7 ++ .../low code/test/var_ColorTestValue.tres | 8 +++ scenes/testing/eventTest.tscn | 44 ++++++------ .../CSharp/Low Code/Events/EventListener.cs | 37 +--------- .../CSharp/Low Code/Events/EventResource.cs | 34 +-------- .../Low Code/Randomizer/VariantRandomizer.cs | 11 +-- .../Low Code/Variables/VariableListener.cs | 69 +++++++++++++++++++ .../Variables/VariableListener.cs.uid | 1 + .../Low Code/Variables/VariableResource.cs | 69 +++++++++++++++++++ .../Variables/VariableResource.cs.uid | 1 + 16 files changed, 195 insertions(+), 136 deletions(-) delete mode 100644 resources/events/ColorEvent.tres rename resources/{events/TestStringEvent.tres => low code/test/event_colorButtonClicked.tres} (51%) create mode 100644 resources/low code/test/event_textLabelClicked.tres create mode 100644 resources/low code/test/var_ColorTestValue.tres create mode 100644 scripts/CSharp/Low Code/Variables/VariableListener.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariableListener.cs.uid create mode 100644 scripts/CSharp/Low Code/Variables/VariableResource.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariableResource.cs.uid diff --git a/addons/babushkahelpers/babushka_dialogue_style.tres b/addons/babushkahelpers/babushka_dialogue_style.tres index ec319c2..647f7c8 100644 --- a/addons/babushkahelpers/babushka_dialogue_style.tres +++ b/addons/babushkahelpers/babushka_dialogue_style.tres @@ -12,42 +12,34 @@ [sub_resource type="Resource" id="Resource_w535h"] script = ExtResource("1_hr3vo") -overrides = {} [sub_resource type="Resource" id="Resource_j3dy5"] script = ExtResource("1_hr3vo") scene = ExtResource("2_cpmol") -overrides = {} [sub_resource type="Resource" id="Resource_d5o1r"] script = ExtResource("1_hr3vo") scene = ExtResource("3_12uyf") -overrides = {} [sub_resource type="Resource" id="Resource_g7mor"] script = ExtResource("1_hr3vo") scene = ExtResource("4_ncyk4") -overrides = {} [sub_resource type="Resource" id="Resource_wgjgg"] script = ExtResource("1_hr3vo") scene = ExtResource("5_qg2g4") -overrides = {} [sub_resource type="Resource" id="Resource_45hxc"] script = ExtResource("1_hr3vo") scene = ExtResource("6_c5ex4") -overrides = {} [sub_resource type="Resource" id="Resource_c53vn"] script = ExtResource("1_hr3vo") scene = ExtResource("7_bopa1") -overrides = {} [sub_resource type="Resource" id="Resource_n6k7j"] script = ExtResource("1_hr3vo") scene = ExtResource("8_oycnw") -overrides = {} [resource] script = ExtResource("9_i6i1n") @@ -63,6 +55,4 @@ layer_info = { "15": SubResource("Resource_c53vn"), "16": SubResource("Resource_n6k7j") } -base_overrides = {} -layers = Array[ExtResource("1_hr3vo")]([]) metadata/_latest_layer = "" diff --git a/addons/dialogic/vesna_style.tres b/addons/dialogic/vesna_style.tres index 89a40f3..1bfe954 100644 --- a/addons/dialogic/vesna_style.tres +++ b/addons/dialogic/vesna_style.tres @@ -22,17 +22,14 @@ overrides = { [sub_resource type="Resource" id="Resource_awdqn"] script = ExtResource("1_kc0s3") scene = ExtResource("2_wjopr") -overrides = {} [sub_resource type="Resource" id="Resource_5pou4"] script = ExtResource("1_kc0s3") scene = ExtResource("3_depsi") -overrides = {} [sub_resource type="Resource" id="Resource_6xrvb"] script = ExtResource("1_kc0s3") scene = ExtResource("4_wy5ku") -overrides = {} [sub_resource type="Resource" id="Resource_k1327"] script = ExtResource("1_kc0s3") @@ -55,7 +52,6 @@ overrides = { [sub_resource type="Resource" id="Resource_qtijl"] script = ExtResource("1_kc0s3") scene = ExtResource("6_iipq0") -overrides = {} [sub_resource type="Resource" id="Resource_nalij"] script = ExtResource("1_kc0s3") @@ -72,17 +68,14 @@ overrides = { [sub_resource type="Resource" id="Resource_ymn1b"] script = ExtResource("1_kc0s3") scene = ExtResource("8_4ig6v") -overrides = {} [sub_resource type="Resource" id="Resource_8j3qh"] script = ExtResource("1_kc0s3") scene = ExtResource("9_gni8k") -overrides = {} [sub_resource type="Resource" id="Resource_uu1x2"] script = ExtResource("1_kc0s3") scene = ExtResource("6_iipq0") -overrides = {} [resource] script = ExtResource("10_l174f") @@ -100,6 +93,4 @@ layer_info = { "17": SubResource("Resource_8j3qh"), "18": SubResource("Resource_uu1x2") } -base_overrides = {} -layers = Array[ExtResource("1_kc0s3")]([]) metadata/_latest_layer = "13" diff --git a/dialog/NPC_narrative.tres b/dialog/NPC_narrative.tres index 8d2e8b1..8acc773 100644 --- a/dialog/NPC_narrative.tres +++ b/dialog/NPC_narrative.tres @@ -24,17 +24,14 @@ overrides = { [sub_resource type="Resource" id="Resource_uxnk3"] script = ExtResource("1_0jwhi") scene = ExtResource("2_8wrfq") -overrides = {} [sub_resource type="Resource" id="Resource_ihoat"] script = ExtResource("1_0jwhi") scene = ExtResource("3_t7aeg") -overrides = {} [sub_resource type="Resource" id="Resource_pw0bl"] script = ExtResource("1_0jwhi") scene = ExtResource("4_85y6g") -overrides = {} [sub_resource type="Resource" id="Resource_lfav5"] script = ExtResource("1_0jwhi") @@ -58,7 +55,6 @@ overrides = { [sub_resource type="Resource" id="Resource_clhbu"] script = ExtResource("1_0jwhi") scene = ExtResource("6_i6h15") -overrides = {} [sub_resource type="Resource" id="Resource_umvdi"] script = ExtResource("1_0jwhi") @@ -75,17 +71,14 @@ overrides = { [sub_resource type="Resource" id="Resource_ci2ul"] script = ExtResource("1_0jwhi") scene = ExtResource("8_h83v4") -overrides = {} [sub_resource type="Resource" id="Resource_sadu5"] script = ExtResource("1_0jwhi") scene = ExtResource("9_4c2uo") -overrides = {} [sub_resource type="Resource" id="Resource_0jwhi"] script = ExtResource("1_0jwhi") scene = ExtResource("6_i6h15") -overrides = {} [resource] script = ExtResource("10_e3ue2") @@ -103,6 +96,4 @@ layer_info = { "17": SubResource("Resource_sadu5"), "18": SubResource("Resource_0jwhi") } -base_overrides = {} -layers = Array[ExtResource("1_0jwhi")]([]) metadata/_latest_layer = "13" diff --git a/project.godot b/project.godot index 4b22b5d..4a1f774 100644 --- a/project.godot +++ b/project.godot @@ -121,7 +121,6 @@ directories/tres_directory={ "8_goto_bed": "res://resources/quests/demo/8_goto_bed.tres", "9_talk_to_chuga": "res://resources/quests/demo/9_talk_to_chuga.tres", "Babushka_NPC_Namebox_background": "res://dialog/Babushka_NPC_Namebox_background.tres", -"ColorEvent": "res://resources/events/ColorEvent.tres", "InputFieldsStyle": "res://addons/dialogic/Editor/Events/styles/InputFieldsStyle.tres", "MainTheme": "res://addons/dialogic/Editor/Theme/MainTheme.tres", "NPC_narrative": "res://dialog/NPC_narrative.tres", @@ -133,7 +132,6 @@ directories/tres_directory={ "SectionPanel": "res://addons/dialogic/Editor/Events/styles/SectionPanel.tres", "SimpleButtonHover": "res://addons/dialogic/Editor/Events/styles/SimpleButtonHover.tres", "SimpleButtonNormal": "res://addons/dialogic/Editor/Events/styles/SimpleButtonNormal.tres", -"TestStringEvent": "res://resources/events/TestStringEvent.tres", "TextBackground": "res://addons/dialogic/Editor/Events/styles/TextBackground.tres", "TitleBgStylebox": "res://addons/dialogic/Editor/Common/TitleBgStylebox.tres", "babushka_dialogue_style": "res://addons/babushkahelpers/babushka_dialogue_style.tres", @@ -146,6 +144,8 @@ directories/tres_directory={ "default_bus_layout": "res://audio/default_bus_layout.tres", "default_stylebox": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_SpeakerPortraitTextbox/default_stylebox.tres", "default_vn_style": "res://addons/dialogic/Modules/DefaultLayoutParts/Style_VN_Default/default_vn_style.tres", +"event_colorButtonClicked": "res://resources/low code/test/event_colorButtonClicked.tres", +"event_textLabelClicked": "res://resources/low code/test/event_textLabelClicked.tres", "farming_equipment_glossary": "res://dialog/farming_equipment_glossary.tres", "hoe": "res://resources/items/hoe.tres", "inventory_interactable_outline": "res://art/materials/inventory_interactable_outline.tres", @@ -168,6 +168,7 @@ directories/tres_directory={ "tomato": "res://resources/items/tomato.tres", "tomato_seed": "res://resources/items/tomato_seed.tres", "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", +"var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", "vn_textbox_name_label_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_name_label_panel.tres", diff --git a/resources/events/ColorEvent.tres b/resources/events/ColorEvent.tres deleted file mode 100644 index 03399f5..0000000 --- a/resources/events/ColorEvent.tres +++ /dev/null @@ -1,9 +0,0 @@ -[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://dc7e13hq47uma"] - -[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_ufwo5"] - -[resource] -script = ExtResource("1_ufwo5") -_showLog = true -Payload = Color(0.84002423, 0.44197178, 0.5653889, 1) -metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/events/TestStringEvent.tres b/resources/low code/test/event_colorButtonClicked.tres similarity index 51% rename from resources/events/TestStringEvent.tres rename to resources/low code/test/event_colorButtonClicked.tres index aa7a312..39d8efc 100644 --- a/resources/events/TestStringEvent.tres +++ b/resources/low code/test/event_colorButtonClicked.tres @@ -1,9 +1,7 @@ -[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"] +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bfw1dfd0r8avr"] -[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_dd3u7"] +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_yg3mc"] [resource] -script = ExtResource("1_dd3u7") -_showLog = true -Payload = "This is a test." +script = ExtResource("1_yg3mc") metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/low code/test/event_textLabelClicked.tres b/resources/low code/test/event_textLabelClicked.tres new file mode 100644 index 0000000..1c2fe6f --- /dev/null +++ b/resources/low code/test/event_textLabelClicked.tres @@ -0,0 +1,7 @@ +[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://boijwlxmth68v"] + +[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_vfqv2"] + +[resource] +script = ExtResource("1_vfqv2") +metadata/_custom_type_script = "uid://ci3t5mvnopntg" diff --git a/resources/low code/test/var_ColorTestValue.tres b/resources/low code/test/var_ColorTestValue.tres new file mode 100644 index 0000000..1c579b1 --- /dev/null +++ b/resources/low code/test/var_ColorTestValue.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://dpnre2bn041jm"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_h8big"] + +[resource] +script = ExtResource("1_h8big") +Payload = Color(0, 0, 0, 1) +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/testing/eventTest.tscn b/scenes/testing/eventTest.tscn index d7a968c..6a0923e 100644 --- a/scenes/testing/eventTest.tscn +++ b/scenes/testing/eventTest.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=6 format=3 uid="uid://6n3p3psmxovj"] +[gd_scene load_steps=7 format=3 uid="uid://6n3p3psmxovj"] +[ext_resource type="Script" uid="uid://pqemey80frcq" path="res://scripts/CSharp/Low Code/Variables/VariableListener.cs" id="1_4h3ry"] [ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="1_w5ykc"] -[ext_resource type="Resource" uid="uid://dc7e13hq47uma" path="res://resources/events/ColorEvent.tres" id="2_4h3ry"] +[ext_resource type="Resource" uid="uid://dpnre2bn041jm" path="res://resources/low code/test/var_ColorTestValue.tres" id="2_bj4kf"] [ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_bj4kf"] -[ext_resource type="Resource" uid="uid://bgfxakxxfmoxs" path="res://resources/events/TestStringEvent.tres" id="4_5dsed"] +[ext_resource type="Resource" uid="uid://boijwlxmth68v" path="res://resources/low code/test/event_textLabelClicked.tres" id="5_4h3ry"] [ext_resource type="Script" uid="uid://co1b320qemg1i" path="res://scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs" id="5_nm8dh"] [node name="EventTest" type="Node2D"] @@ -19,45 +20,48 @@ offset_bottom = 329.0 layout_mode = 0 offset_right = 178.0 offset_bottom = 145.0 -script = ExtResource("1_w5ykc") -_eventResources = Array[Object]([ExtResource("2_4h3ry")]) -_showLog = true +script = ExtResource("1_4h3ry") +_variableResources = Array[Object]([ExtResource("2_bj4kf")]) -[node name="LabelTextEventButton" type="Button" parent="Control"] +[node name="ChangeColorButton" type="Button" parent="Control"] layout_mode = 0 -offset_left = 194.0 offset_top = 148.0 -offset_right = 351.0 +offset_right = 112.0 offset_bottom = 179.0 -text = "Show Event Text +text = "Change Color " -script = ExtResource("3_bj4kf") -_eventResources = Array[Object]([ExtResource("4_5dsed")]) +script = ExtResource("5_nm8dh") +_variableResource = ExtResource("2_bj4kf") -[node name="ChangeColorButton" type="Button" parent="Control"] +[node name="LabelTextEventButton" type="Button" parent="Control"] layout_mode = 0 +offset_left = 194.0 offset_top = 148.0 -offset_right = 112.0 +offset_right = 351.0 offset_bottom = 179.0 -text = "Change Color +text = "Show Event Text " -script = ExtResource("5_nm8dh") -_eventResource = ExtResource("2_4h3ry") +script = ExtResource("3_bj4kf") +_eventResources = Array[Object]([ExtResource("5_4h3ry")]) [node name="TestLabel" type="Label" parent="Control"] +visible = false layout_mode = 0 offset_left = 237.0 offset_top = 54.0 offset_right = 277.0 offset_bottom = 77.0 +text = "[Dieser Text erscheint, +wenn das Event richtig +verknüpft ist]" script = ExtResource("1_w5ykc") -_eventResources = Array[Object]([ExtResource("4_5dsed")]) +_eventResources = Array[Object]([ExtResource("5_4h3ry")]) [node name="Camera2D" type="Camera2D" parent="."] position = Vector2(239, 110) zoom = Vector2(3.4, 3.4) [connection signal="NewEventPayload" from="Control/ColorRect" to="Control/ColorRect" method="set_color"] -[connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"] [connection signal="pressed" from="Control/ChangeColorButton" to="Control/ChangeColorButton" method="RandomizeEventResource"] -[connection signal="EventRaisedWithPayload" from="Control/TestLabel" to="Control/TestLabel" method="set_text"] +[connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"] +[connection signal="EventRaised" from="Control/TestLabel" to="Control/TestLabel" method="show"] diff --git a/scripts/CSharp/Low Code/Events/EventListener.cs b/scripts/CSharp/Low Code/Events/EventListener.cs index caa2801..085fbf4 100644 --- a/scripts/CSharp/Low Code/Events/EventListener.cs +++ b/scripts/CSharp/Low Code/Events/EventListener.cs @@ -23,27 +23,6 @@ public partial class EventListener : Node /// [Signal] public delegate void EventRaisedEventHandler(); - /// - /// The signal that is triggered when this listener is called by one of the . - /// - [Signal] public delegate void EventRaisedWithPayloadEventHandler(Variant payload); - - /// - /// A signal that is triggered when the payload of one of the changed. - /// - [Signal] public delegate void PayloadChangedEventHandler(Variant payload, Variant oldPayload); - - /// - /// A signal that is triggered when the payload of one of the changed. - /// - [Signal] public delegate void NewEventPayloadEventHandler(Variant payload); - - /// - /// A signal that is triggered when the payload of one of the changed. - /// - [Signal] public delegate void OldEventPayloadEventHandler(Variant oldPayload); - - /// /// Subscribes to all s present in the array. /// @@ -72,24 +51,12 @@ public partial class EventListener : Node /// Called by a s from the array. /// Propagates the event by emitting signal. /// - public void EventInvoked(Variant payload) + public void EventInvoked() { if(_showLog) GD.Print("Event Raised on: " + Name); EmitSignal(SignalName.EventRaised); - EmitSignal(SignalName.EventRaisedWithPayload, payload); } - /// - /// Called by a s from the array. - /// Propagates the event by emitting signal. - /// - public void EventPayloadChanged(Variant payload, Variant oldPayload) - { - if(_showLog) - GD.Print($"Calling Event Payload Changed Signals on: " + Name); - EmitSignal(SignalName.PayloadChanged, payload, oldPayload); - EmitSignal(SignalName.NewEventPayload, payload); - EmitSignal(SignalName.OldEventPayload, oldPayload); - } + } \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Events/EventResource.cs b/scripts/CSharp/Low Code/Events/EventResource.cs index 4811348..4b829a3 100644 --- a/scripts/CSharp/Low Code/Events/EventResource.cs +++ b/scripts/CSharp/Low Code/Events/EventResource.cs @@ -14,24 +14,6 @@ public partial class EventResource : Resource /// Log into console when this event resource is adding or removing listeners, and when it's raised. /// [Export] private bool _showLog; - - [Export] - public Variant Payload - { - get { return _payload; } - set - { - if (!_payload.Equals(value)) - { - _lastPayload = _payload; - _payload = value; - ValueChangeHandler(); - } - } - } - - private Variant _payload; - private Variant _lastPayload; /// /// Raise-Button Call with Editor Export for easier debugging. @@ -74,22 +56,10 @@ public partial class EventResource : Resource foreach (var eventListener in _eventListeners) { - eventListener.EventInvoked(_payload); + eventListener.EventInvoked(); } } - /// - /// Called when the Payload value changed. - /// - public void ValueChangeHandler() - { - if(_showLog) - GD.Print($"Event payload changed from {_lastPayload} to {_payload} on event resource: " + ResourcePath.GetFile().TrimSuffix(".tres")); - - foreach (var eventListener in _eventListeners) - { - eventListener.EventPayloadChanged(_payload, _lastPayload); - } - } + } \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs index 178af0d..140b400 100644 --- a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs @@ -1,5 +1,6 @@ using System; using Babushka.scripts.CSharp.Low_Code.Events; +using Babushka.scripts.CSharp.Low_Code.Variables; using Godot; @@ -13,23 +14,23 @@ public partial class VariantRandomizer : Node /// /// The event resource to work on. /// - [Export] public EventResource _eventResource; + [Export] public VariableResource _variableResource; /// /// Sets the payload of a randomizable event resource to a random value. /// public void RandomizeEventResource() { - switch (_eventResource.Payload.VariantType) + switch (_variableResource.Payload.VariantType) { case Variant.Type.Color: - _eventResource.Payload= GetRandomColor(); + _variableResource.Payload= GetRandomColor(); break; case Variant.Type.Int: - _eventResource.Payload= GetRandomInt(); + _variableResource.Payload= GetRandomInt(); break; case Variant.Type.Float: - _eventResource.Payload= GetRandomFloat(); + _variableResource.Payload= GetRandomFloat(); break; } } diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs b/scripts/CSharp/Low Code/Variables/VariableListener.cs new file mode 100644 index 0000000..238381f --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs @@ -0,0 +1,69 @@ +using Godot; +using Godot.Collections; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +public partial class VariableListener : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private Array _variableResources; + + /// + /// Log to console when this event is being raised. + /// + [Export] private bool _showLog; + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void PayloadChangedEventHandler(Variant payload, Variant oldPayload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void NewEventPayloadEventHandler(Variant payload); + + /// + /// A signal that is triggered when the payload of one of the changed. + /// + [Signal] public delegate void OldEventPayloadEventHandler(Variant oldPayload); + + /// + /// Subscribes to all s present in the array. + /// + /// + public override void _EnterTree() + { + foreach (var resource in _variableResources) + { + resource.RegisterListener(this); + } + } + + /// + /// Unsubscribes from all s present in the array. + /// + /// + public override void _ExitTree() + { + foreach (var variableResource in _variableResources) + { + variableResource.UnregisterListener(this); + } + } + + /// + /// Called by a s from the array. + /// Propagates the event by emitting signal. + /// + public void EventPayloadChanged(Variant payload, Variant oldPayload) + { + if(_showLog) + GD.Print($"Calling Event Payload Changed Signals on: " + Name); + EmitSignal(SignalName.PayloadChanged, payload, oldPayload); + EmitSignal(SignalName.NewEventPayload, payload); + EmitSignal(SignalName.OldEventPayload, oldPayload); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid b/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid new file mode 100644 index 0000000..8ed0b0c --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs.uid @@ -0,0 +1 @@ +uid://pqemey80frcq diff --git a/scripts/CSharp/Low Code/Variables/VariableResource.cs b/scripts/CSharp/Low Code/Variables/VariableResource.cs new file mode 100644 index 0000000..77bc13e --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableResource.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +[GlobalClass] +public partial class VariableResource : Resource +{ + /// + /// Log into console when this event resource is adding or removing listeners, and when it's raised. + /// + [Export] private bool _showLog; + + [Export] + public Variant Payload + { + get { return _payload; } + set + { + if (!_payload.Equals(value)) + { + _lastPayload = _payload; + _payload = value; + ValueChangeHandler(); + } + } + } + + private Variant _payload; + private Variant _lastPayload; + + private List _varListeners = new (); + + /// + /// Adds an EventListener to the calling list for this event. + /// + /// + public void RegisterListener(VariableListener listener) + { + if(_showLog) + GD.Print("Registering listener " + listener); + _varListeners.Add(listener); + } + + /// + /// Removes an Eventlistener from the calling list for this event. + /// + /// + public void UnregisterListener(VariableListener listener) + { + if(_showLog) + GD.Print("Unregistering listener " + listener); + _varListeners.Remove(listener); + } + + /// + /// Called when the Payload value changed. + /// + public void ValueChangeHandler() + { + if(_showLog) + GD.Print($"Event payload changed from {_lastPayload} to {_payload} on event resource: " + ResourcePath.GetFile().TrimSuffix(".tres")); + + foreach (var eventListener in _varListeners) + { + eventListener.EventPayloadChanged(_payload, _lastPayload); + } + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid b/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid new file mode 100644 index 0000000..dc3a112 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableResource.cs.uid @@ -0,0 +1 @@ +uid://dtvx2cakx0bey From 8c1157c26e4b15c32fcc855ac0f106ec30683ed4 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 28 Oct 2025 12:04:41 +0100 Subject: [PATCH 09/10] :fire: removed indexed RaiseEvent-Call from EventRaiser --- scripts/CSharp/Low Code/Events/EventRaiser.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scripts/CSharp/Low Code/Events/EventRaiser.cs b/scripts/CSharp/Low Code/Events/EventRaiser.cs index 2bebce3..07e419e 100644 --- a/scripts/CSharp/Low Code/Events/EventRaiser.cs +++ b/scripts/CSharp/Low Code/Events/EventRaiser.cs @@ -23,13 +23,4 @@ public partial class EventRaiser : Node eventRes.Raise(); } } - - /// - /// Raises at index. - /// - /// - public void RaiseEvent(int index) - { - _eventResources[index].Raise(); - } } \ No newline at end of file From 3fe79f2fd8f6fd5b8cadc69387d3269d41471802 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 28 Oct 2025 13:09:36 +0100 Subject: [PATCH 10/10] :sparkles: Added VariableGetter functionality and some Variable setting components. Also added them to test scene. --- project.godot | 1 + resources/low code/test/var_Counter.tres | 8 +++++ scenes/testing/eventTest.tscn | 36 ++++++++++++++++++- .../Low Code/Variables/VariableGetter.cs | 30 ++++++++++++++++ .../Low Code/Variables/VariableGetter.cs.uid | 1 + .../Low Code/Variables/VariableListener.cs | 3 ++ .../Low Code/Variables/VariableResource.cs | 7 ++++ .../VariantValueChanger/VariantIncrementor.cs | 22 ++++++++++++ .../VariantIncrementor.cs.uid | 1 + .../VariantValueChanger/VariantToString.cs | 16 +++++++++ .../VariantToString.cs.uid | 1 + 11 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 resources/low code/test/var_Counter.tres create mode 100644 scripts/CSharp/Low Code/Variables/VariableGetter.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid create mode 100644 scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid create mode 100644 scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs create mode 100644 scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid diff --git a/project.godot b/project.godot index 4a1f774..6112bd3 100644 --- a/project.godot +++ b/project.godot @@ -169,6 +169,7 @@ directories/tres_directory={ "tomato_seed": "res://resources/items/tomato_seed.tres", "unselected_stylebox": "res://addons/dialogic/Editor/Events/styles/unselected_stylebox.tres", "var_ColorTestValue": "res://resources/low code/test/var_ColorTestValue.tres", +"var_Counter": "res://resources/low code/test/var_Counter.tres", "vesna_style": "res://addons/dialogic/vesna_style.tres", "vn_textbox_default_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_default_panel.tres", "vn_textbox_name_label_panel": "res://addons/dialogic/Modules/DefaultLayoutParts/Layer_VN_Textbox/vn_textbox_name_label_panel.tres", diff --git a/resources/low code/test/var_Counter.tres b/resources/low code/test/var_Counter.tres new file mode 100644 index 0000000..02a605b --- /dev/null +++ b/resources/low code/test/var_Counter.tres @@ -0,0 +1,8 @@ +[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://c6iw30ydc0qa0"] + +[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_sbnhb"] + +[resource] +script = ExtResource("1_sbnhb") +Payload = 0 +metadata/_custom_type_script = "uid://dtvx2cakx0bey" diff --git a/scenes/testing/eventTest.tscn b/scenes/testing/eventTest.tscn index 6a0923e..f6dae4b 100644 --- a/scenes/testing/eventTest.tscn +++ b/scenes/testing/eventTest.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://6n3p3psmxovj"] +[gd_scene load_steps=10 format=3 uid="uid://6n3p3psmxovj"] [ext_resource type="Script" uid="uid://pqemey80frcq" path="res://scripts/CSharp/Low Code/Variables/VariableListener.cs" id="1_4h3ry"] [ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="1_w5ykc"] @@ -6,6 +6,9 @@ [ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_bj4kf"] [ext_resource type="Resource" uid="uid://boijwlxmth68v" path="res://resources/low code/test/event_textLabelClicked.tres" id="5_4h3ry"] [ext_resource type="Script" uid="uid://co1b320qemg1i" path="res://scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs" id="5_nm8dh"] +[ext_resource type="Script" uid="uid://dco37q6ddm8kv" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs" id="7_nm8dh"] +[ext_resource type="Resource" uid="uid://c6iw30ydc0qa0" path="res://resources/low code/test/var_Counter.tres" id="9_44nfx"] +[ext_resource type="Script" uid="uid://d1y23ytkt1w2j" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs" id="10_p6d2q"] [node name="EventTest" type="Node2D"] @@ -57,11 +60,42 @@ verknüpft ist]" script = ExtResource("1_w5ykc") _eventResources = Array[Object]([ExtResource("5_4h3ry")]) +[node name="LabelTextEventButton2" type="Button" parent="Control"] +layout_mode = 0 +offset_left = 361.0 +offset_top = 148.0 +offset_right = 518.0 +offset_bottom = 179.0 +text = "get current number +" + +[node name="TestLabel2" type="Label" parent="Control"] +layout_mode = 0 +offset_left = 432.0 +offset_top = 117.0 +offset_right = 472.0 +offset_bottom = 166.0 +text = "0 +" +script = ExtResource("7_nm8dh") +_resource = ExtResource("9_44nfx") + [node name="Camera2D" type="Camera2D" parent="."] position = Vector2(239, 110) zoom = Vector2(3.4, 3.4) +[node name="Timer" type="Timer" parent="."] +wait_time = 0.5 +autostart = true + +[node name="CountLoop" type="Node" parent="Timer"] +script = ExtResource("10_p6d2q") +_resource = ExtResource("9_44nfx") + [connection signal="NewEventPayload" from="Control/ColorRect" to="Control/ColorRect" method="set_color"] [connection signal="pressed" from="Control/ChangeColorButton" to="Control/ChangeColorButton" method="RandomizeEventResource"] [connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"] [connection signal="EventRaised" from="Control/TestLabel" to="Control/TestLabel" method="show"] +[connection signal="pressed" from="Control/LabelTextEventButton2" to="Control/TestLabel2" method="ConvertToString"] +[connection signal="PayloadAsString" from="Control/TestLabel2" to="Control/TestLabel2" method="set_text"] +[connection signal="timeout" from="Timer" to="Timer/CountLoop" method="Increment"] diff --git a/scripts/CSharp/Low Code/Variables/VariableGetter.cs b/scripts/CSharp/Low Code/Variables/VariableGetter.cs new file mode 100644 index 0000000..d5138f9 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableGetter.cs @@ -0,0 +1,30 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables; + +/// +/// An active getter component for calling the payload value of a . +/// +public partial class VariableGetter : Node +{ + /// + /// The event resource to listen to. + /// + [Export] private VariableResource _variableResource; + + /// + /// A signal that is triggered when the payload of one of the is called. + /// + [Signal] public delegate void GetPayloadEventHandler(Variant payload); + + /// + /// Gets the Variant payload of a VariableResource on demand. + /// + /// + public Variant Get() + { + Variant payload = _variableResource.Payload; + EmitSignal(SignalName.GetPayload, payload); + return payload; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid b/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid new file mode 100644 index 0000000..1a4682f --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariableGetter.cs.uid @@ -0,0 +1 @@ +uid://34okoih6wkmu diff --git a/scripts/CSharp/Low Code/Variables/VariableListener.cs b/scripts/CSharp/Low Code/Variables/VariableListener.cs index 238381f..2576015 100644 --- a/scripts/CSharp/Low Code/Variables/VariableListener.cs +++ b/scripts/CSharp/Low Code/Variables/VariableListener.cs @@ -3,6 +3,9 @@ using Godot.Collections; namespace Babushka.scripts.CSharp.Low_Code.Variables; +/// +/// A passive Node that listens to valuechange-events on a . +/// public partial class VariableListener : Node { /// diff --git a/scripts/CSharp/Low Code/Variables/VariableResource.cs b/scripts/CSharp/Low Code/Variables/VariableResource.cs index 77bc13e..20d5240 100644 --- a/scripts/CSharp/Low Code/Variables/VariableResource.cs +++ b/scripts/CSharp/Low Code/Variables/VariableResource.cs @@ -3,6 +3,9 @@ using Godot; namespace Babushka.scripts.CSharp.Low_Code.Variables; +/// +/// A value wrapper resource used to store state values and notify ingame scripts. +/// [GlobalClass] public partial class VariableResource : Resource { @@ -11,6 +14,10 @@ public partial class VariableResource : Resource /// [Export] private bool _showLog; + /// + /// Public property that manages the access to the payload. + /// Triggers the ValueChange-function when set to a new value. + /// [Export] public Variant Payload { diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs new file mode 100644 index 0000000..3118535 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs @@ -0,0 +1,22 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger; + +public partial class VariantIncrementor : Node +{ + [Export] private VariableResource _resource; + + public void Increment() + { + int integerValue = _resource.Payload.AsInt32(); + integerValue++; + _resource.Payload = integerValue; + } + + public void Decrement() + { + int integerValue = _resource.Payload.AsInt32(); + integerValue--; + _resource.Payload = integerValue; + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid new file mode 100644 index 0000000..f6133c0 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs.uid @@ -0,0 +1 @@ +uid://d1y23ytkt1w2j diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs new file mode 100644 index 0000000..1219487 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs @@ -0,0 +1,16 @@ +using Godot; + +namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger; + +public partial class VariantToString : Node +{ + [Export] private VariableResource _resource; + + [Signal] public delegate void PayloadAsStringEventHandler(string payloadAsString); + + + public void ConvertToString() + { + EmitSignal(SignalName.PayloadAsString, _resource.Payload.AsString()); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid new file mode 100644 index 0000000..9aced51 --- /dev/null +++ b/scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs.uid @@ -0,0 +1 @@ +uid://dco37q6ddm8kv