From 7d1ca26baa65d14fcc89c96c24c918b1cccfb617 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 16 Jul 2025 04:11:26 +0500 Subject: [PATCH] Zombie editor --- addons/pvzadventure/RowSpawn.cs | 4 + addons/pvzadventure/WaveData.cs | 4 +- .../pvzadventure/scenes/adventure_editor.tscn | 10 +- .../scenes/asset_browser_button.tscn | 27 ++++ addons/pvzadventure/scenes/grid_item.tscn | 27 ++++ addons/pvzadventure/scenes/row_editor.tscn | 11 ++ addons/pvzadventure/scenes/zombie_editor.tscn | 132 +++++++++++++++++- .../scripts/AdventureResourceInspector.cs | 15 +- .../pvzadventure/scripts/ZE_AssetBrowser.cs | 19 +++ .../scripts/ZE_AssetBrowser.cs.uid | 1 + .../scripts/ZE_AssetBrowserButton.cs | 22 +++ .../scripts/ZE_AssetBrowserButton.cs.uid | 1 + .../pvzadventure/scripts/ZE_GridContainer.cs | 38 +++++ .../scripts/ZE_GridContainer.cs.uid | 1 + addons/pvzadventure/scripts/ZE_GridItem.cs | 47 +++++++ .../pvzadventure/scripts/ZE_GridItem.cs.uid | 1 + addons/pvzadventure/scripts/ZE_RowEditor.cs | 25 ++++ .../pvzadventure/scripts/ZE_RowEditor.cs.uid | 1 + addons/pvzadventure/scripts/ZombieEditor.cs | 15 ++ .../pvzadventure/scripts/ZombieEditor.cs.uid | 1 + resources/levels/testlvl.tres | 56 +++++--- scripts/resources/DisplayResource.cs | 1 + scripts/resources/ZombieResource.cs | 1 + 23 files changed, 435 insertions(+), 25 deletions(-) create mode 100644 addons/pvzadventure/scenes/asset_browser_button.tscn create mode 100644 addons/pvzadventure/scenes/grid_item.tscn create mode 100644 addons/pvzadventure/scenes/row_editor.tscn create mode 100644 addons/pvzadventure/scripts/ZE_AssetBrowser.cs create mode 100644 addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid create mode 100644 addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs create mode 100644 addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid create mode 100644 addons/pvzadventure/scripts/ZE_GridContainer.cs create mode 100644 addons/pvzadventure/scripts/ZE_GridContainer.cs.uid create mode 100644 addons/pvzadventure/scripts/ZE_GridItem.cs create mode 100644 addons/pvzadventure/scripts/ZE_GridItem.cs.uid create mode 100644 addons/pvzadventure/scripts/ZE_RowEditor.cs create mode 100644 addons/pvzadventure/scripts/ZE_RowEditor.cs.uid create mode 100644 addons/pvzadventure/scripts/ZombieEditor.cs create mode 100644 addons/pvzadventure/scripts/ZombieEditor.cs.uid diff --git a/addons/pvzadventure/RowSpawn.cs b/addons/pvzadventure/RowSpawn.cs index 5985e40..0ba3e96 100644 --- a/addons/pvzadventure/RowSpawn.cs +++ b/addons/pvzadventure/RowSpawn.cs @@ -1,5 +1,9 @@ using Godot; +using Godot.Collections; +[Tool] +[GlobalClass] public partial class RowSpawn : Resource { + [Export] public Array zombies = new(new ZombieResource[5]); } diff --git a/addons/pvzadventure/WaveData.cs b/addons/pvzadventure/WaveData.cs index 5c52164..75a7218 100644 --- a/addons/pvzadventure/WaveData.cs +++ b/addons/pvzadventure/WaveData.cs @@ -5,6 +5,6 @@ using Godot.Collections; [Tool] public partial class WaveData : Resource { - [Export] private Array zombiesOrdered; - [Export] private Array spawns; + [Export] public Array zombiesOrdered; + [Export] public Array spawns; } diff --git a/addons/pvzadventure/scenes/adventure_editor.tscn b/addons/pvzadventure/scenes/adventure_editor.tscn index 8f15747..6cfbb12 100644 --- a/addons/pvzadventure/scenes/adventure_editor.tscn +++ b/addons/pvzadventure/scenes/adventure_editor.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=3 uid="uid://dkq82o31vr3i2"] +[gd_scene load_steps=5 format=3 uid="uid://dkq82o31vr3i2"] [ext_resource type="Script" uid="uid://dkgxtig5fwdgi" path="res://addons/pvzadventure/scripts/AdventureEditor.cs" id="1_go5yu"] [ext_resource type="Script" uid="uid://binuuattefn7d" path="res://addons/pvzadventure/scripts/FileButton.cs" id="2_d5hwn"] +[ext_resource type="PackedScene" uid="uid://db5ah76l43ng2" path="res://addons/pvzadventure/scenes/zombie_editor.tscn" id="3_1ojhm"] [ext_resource type="Script" uid="uid://b0hl4ap18wbb2" path="res://addons/pvzadventure/scripts/AdventureResourceInspector.cs" id="3_d5hwn"] [node name="AdventureEditor" type="MarginContainer"] @@ -50,13 +51,18 @@ split_offset = 500 [node name="PanelContainer" type="PanelContainer" parent="VBoxContainer/WorkArea"] layout_mode = 2 +[node name="ZombieEditor" parent="VBoxContainer/WorkArea/PanelContainer" instance=ExtResource("3_1ojhm")] +visible = false +layout_mode = 2 + [node name="Inspector" type="VSplitContainer" parent="VBoxContainer/WorkArea"] layout_mode = 2 -[node name="ResourceInspector" type="VBoxContainer" parent="VBoxContainer/WorkArea/Inspector"] +[node name="ResourceInspector" type="VBoxContainer" parent="VBoxContainer/WorkArea/Inspector" node_paths=PackedStringArray("editorContainer")] layout_mode = 2 size_flags_vertical = 3 script = ExtResource("3_d5hwn") +editorContainer = NodePath("../../PanelContainer") [node name="Tree" type="Tree" parent="VBoxContainer/WorkArea/Inspector/ResourceInspector"] custom_minimum_size = Vector2(0, 100) diff --git a/addons/pvzadventure/scenes/asset_browser_button.tscn b/addons/pvzadventure/scenes/asset_browser_button.tscn new file mode 100644 index 0000000..5725a16 --- /dev/null +++ b/addons/pvzadventure/scenes/asset_browser_button.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://iwnklc62rni8"] + +[ext_resource type="Script" uid="uid://cpedvgx23hlko" path="res://addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs" id="1_jbknv"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbknv"] +bg_color = Color(0.18359, 0.18359, 0.18359, 1) +border_color = Color(0.140447, 0.140447, 0.140447, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[node name="AssetBrowserButton" type="PanelContainer"] +clip_contents = true +custom_minimum_size = Vector2(100, 100) +anchors_preset = -1 +anchor_right = 0.172 +anchor_bottom = 0.25 +offset_right = -0.200005 +offset_bottom = -15.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_jbknv") +script = ExtResource("1_jbknv") + +[node name="Texture" type="TextureRect" parent="."] +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 diff --git a/addons/pvzadventure/scenes/grid_item.tscn b/addons/pvzadventure/scenes/grid_item.tscn new file mode 100644 index 0000000..e355afc --- /dev/null +++ b/addons/pvzadventure/scenes/grid_item.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://segxys6udhyw"] + +[ext_resource type="Script" uid="uid://fof6kr0et8ng" path="res://addons/pvzadventure/scripts/ZE_GridItem.cs" id="1_agbb0"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jbknv"] +bg_color = Color(0.18359, 0.18359, 0.18359, 1) +border_color = Color(0.140447, 0.140447, 0.140447, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[node name="GridItem" type="PanelContainer"] +clip_contents = true +custom_minimum_size = Vector2(100, 100) +anchors_preset = -1 +anchor_right = 0.172 +anchor_bottom = 0.25 +offset_right = -0.200005 +offset_bottom = -15.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_jbknv") +script = ExtResource("1_agbb0") + +[node name="Texture" type="TextureRect" parent="."] +layout_mode = 2 +expand_mode = 1 +stretch_mode = 5 diff --git a/addons/pvzadventure/scenes/row_editor.tscn b/addons/pvzadventure/scenes/row_editor.tscn new file mode 100644 index 0000000..b06dfcd --- /dev/null +++ b/addons/pvzadventure/scenes/row_editor.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://buvnw8a7pku78"] + +[ext_resource type="Script" uid="uid://q84g5imvatfl" path="res://addons/pvzadventure/scripts/ZE_RowEditor.cs" id="1_wm7b4"] + +[node name="RowEditor" type="VBoxContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_wm7b4") diff --git a/addons/pvzadventure/scenes/zombie_editor.tscn b/addons/pvzadventure/scenes/zombie_editor.tscn index 3dc491f..89c00ff 100644 --- a/addons/pvzadventure/scenes/zombie_editor.tscn +++ b/addons/pvzadventure/scenes/zombie_editor.tscn @@ -1,9 +1,135 @@ -[gd_scene format=3 uid="uid://db5ah76l43ng2"] +[gd_scene load_steps=10 format=3 uid="uid://db5ah76l43ng2"] -[node name="ZombieEditor" type="Control"] -layout_mode = 3 +[ext_resource type="Script" uid="uid://bnuno3uhya4sg" path="res://addons/pvzadventure/scripts/ZE_AssetBrowser.cs" id="1_klhya"] +[ext_resource type="Script" uid="uid://bd5hl0etgvf5a" path="res://addons/pvzadventure/scripts/ZombieEditor.cs" id="1_thd7y"] +[ext_resource type="Script" uid="uid://do7s5mo36c280" path="res://addons/pvzadventure/scripts/ZE_GridContainer.cs" id="2_13ic4"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_thd7y"] +bg_color = Color(0.430693, 0.742747, 0.314214, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_a2umq"] +bg_color = Color(0.503317, 0.859941, 0.370424, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_13ic4"] +bg_color = Color(0.655235, 0.676224, 0.627655, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h81wb"] +bg_color = Color(1, 0.617482, 0.590722, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vak4b"] +bg_color = Color(0.655235, 0.676224, 0.627655, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nm0oj"] +bg_color = Color(0.999983, 0.30398, 0.31271, 1) +corner_radius_top_left = 5 +corner_radius_top_right = 5 +corner_radius_bottom_right = 5 +corner_radius_bottom_left = 5 + +[node name="ZombieEditor" type="VBoxContainer" node_paths=PackedStringArray("container")] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_thd7y") +container = NodePath("ZombieGrid/HBoxContainer/RowEditors") + +[node name="ZombieGrid" type="ScrollContainer" parent="."] +layout_mode = 2 +size_flags_vertical = 3 +size_flags_stretch_ratio = 3.0 +horizontal_scroll_mode = 2 +vertical_scroll_mode = 0 + +[node name="HBoxContainer" type="HBoxContainer" parent="ZombieGrid"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="RowEditors" type="HBoxContainer" parent="ZombieGrid/HBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +size_flags_stretch_ratio = 3.0 +script = ExtResource("2_13ic4") + +[node name="ControlButtons" type="VBoxContainer" parent="ZombieGrid/HBoxContainer"] +layout_mode = 2 + +[node name="NewButton" type="Button" parent="ZombieGrid/HBoxContainer/ControlButtons"] +custom_minimum_size = Vector2(32, 0) +layout_mode = 2 +size_flags_vertical = 3 +theme_override_colors/font_disabled_color = Color(1, 1, 1, 1) +theme_override_colors/font_hover_pressed_color = Color(1, 1, 1, 1) +theme_override_colors/font_hover_color = Color(1, 1, 1, 1) +theme_override_colors/font_color = Color(1, 1, 1, 1) +theme_override_colors/font_focus_color = Color(1, 1, 1, 1) +theme_override_colors/font_pressed_color = Color(0, 0, 0, 1) +theme_override_font_sizes/font_size = 24 +theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_thd7y") +theme_override_styles/disabled = SubResource("StyleBoxFlat_thd7y") +theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_a2umq") +theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_a2umq") +theme_override_styles/hover = SubResource("StyleBoxFlat_thd7y") +theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_13ic4") +theme_override_styles/pressed = SubResource("StyleBoxFlat_13ic4") +theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_thd7y") +theme_override_styles/normal = SubResource("StyleBoxFlat_thd7y") +text = "+" + +[node name="RemoveButton" type="Button" parent="ZombieGrid/HBoxContainer/ControlButtons"] +custom_minimum_size = Vector2(32, 0) +layout_mode = 2 +size_flags_vertical = 3 +theme_override_colors/font_disabled_color = Color(1, 1, 1, 1) +theme_override_colors/font_hover_pressed_color = Color(1, 1, 1, 1) +theme_override_colors/font_hover_color = Color(1, 1, 1, 1) +theme_override_colors/font_color = Color(1, 1, 1, 1) +theme_override_colors/font_focus_color = Color(1, 1, 1, 1) +theme_override_colors/font_pressed_color = Color(0, 0, 0, 1) +theme_override_font_sizes/font_size = 24 +theme_override_styles/disabled_mirrored = SubResource("StyleBoxFlat_h81wb") +theme_override_styles/disabled = SubResource("StyleBoxFlat_h81wb") +theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_h81wb") +theme_override_styles/hover_mirrored = SubResource("StyleBoxFlat_h81wb") +theme_override_styles/hover = SubResource("StyleBoxFlat_h81wb") +theme_override_styles/pressed_mirrored = SubResource("StyleBoxFlat_vak4b") +theme_override_styles/pressed = SubResource("StyleBoxFlat_vak4b") +theme_override_styles/normal_mirrored = SubResource("StyleBoxFlat_nm0oj") +theme_override_styles/normal = SubResource("StyleBoxFlat_nm0oj") +text = "-" + +[node name="AssetBrowser" type="ScrollContainer" parent="."] +layout_mode = 2 +size_flags_vertical = 3 +vertical_scroll_mode = 0 + +[node name="HBoxContainer" type="HBoxContainer" parent="AssetBrowser"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +script = ExtResource("1_klhya") + +[connection signal="pressed" from="ZombieGrid/HBoxContainer/ControlButtons/NewButton" to="ZombieGrid/HBoxContainer/RowEditors" method="AddSpawn"] +[connection signal="pressed" from="ZombieGrid/HBoxContainer/ControlButtons/RemoveButton" to="ZombieGrid/HBoxContainer/RowEditors" method="RemoveSpawn"] diff --git a/addons/pvzadventure/scripts/AdventureResourceInspector.cs b/addons/pvzadventure/scripts/AdventureResourceInspector.cs index 8e00e31..cb4d10c 100644 --- a/addons/pvzadventure/scripts/AdventureResourceInspector.cs +++ b/addons/pvzadventure/scripts/AdventureResourceInspector.cs @@ -6,6 +6,7 @@ public partial class AdventureResourceInspector : Node { const int ORDERED = 0; const int EVENTS = 1; + private PackedScene zombieEditorScene = ResourceLoader.Load("uid://db5ah76l43ng2"); private Tree tree; private AdventureLevelResource heldResource; @@ -14,6 +15,10 @@ public partial class AdventureResourceInspector : Node [Signal] public delegate void RefreshedEventHandler(); + + [Export] + public Control editorContainer; + public override void _Ready() { tree = GetNode("Tree"); @@ -57,6 +62,11 @@ public partial class AdventureResourceInspector : Node public void OnItemSelected() { + foreach (var child in editorContainer.GetChildren()) + { + child.QueueFree(); + } + var selected = tree.GetSelected(); if (selected == root) { @@ -70,7 +80,10 @@ public partial class AdventureResourceInspector : Node var index = selected.GetIndex(); if (index == ORDERED) { - GD.Print("Zombies pressed"); + var editor = zombieEditorScene.Instantiate(); + + editorContainer.AddChild(editor); + editor.SetEditedWave(heldResource.waves[int.Parse(selected.GetParent().GetText(0).Split(" ")[1])]); } else if (index == EVENTS) { diff --git a/addons/pvzadventure/scripts/ZE_AssetBrowser.cs b/addons/pvzadventure/scripts/ZE_AssetBrowser.cs new file mode 100644 index 0000000..9d866f6 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_AssetBrowser.cs @@ -0,0 +1,19 @@ +using Godot; + + +[Tool] +public partial class ZE_AssetBrowser : HBoxContainer +{ + const string ZOMBIE_PATH = "res://resources/zombies/"; + private PackedScene scene = ResourceLoader.Load("uid://iwnklc62rni8"); + public override void _Ready() + { + foreach (var file in ResourceLoader.ListDirectory(ZOMBIE_PATH)) + { + var data = ResourceLoader.Load(ZOMBIE_PATH + file); + var button = scene.Instantiate(); + button.SetData(data); + AddChild(button); + } + } +} diff --git a/addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid b/addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid new file mode 100644 index 0000000..1df9fc5 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid @@ -0,0 +1 @@ +uid://bnuno3uhya4sg diff --git a/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs b/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs new file mode 100644 index 0000000..c306323 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs @@ -0,0 +1,22 @@ +using Godot; + +[Tool] +public partial class ZE_AssetBrowserButton : PanelContainer +{ + private ZombieResource resource; + public void SetData(ZombieResource data) + { + resource = data; + UpdateContent(); + } + private void UpdateContent() + { + GetNode("Texture").Texture = resource.Preview; + } + + public override Variant _GetDragData(Vector2 atPosition) + { + return resource; + } + +} diff --git a/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid b/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid new file mode 100644 index 0000000..06a60b9 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid @@ -0,0 +1 @@ +uid://cpedvgx23hlko diff --git a/addons/pvzadventure/scripts/ZE_GridContainer.cs b/addons/pvzadventure/scripts/ZE_GridContainer.cs new file mode 100644 index 0000000..3822b71 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_GridContainer.cs @@ -0,0 +1,38 @@ +using Godot; + +[Tool] +public partial class ZE_GridContainer : Control +{ + private PackedScene rowEditorScene = ResourceLoader.Load("uid://buvnw8a7pku78"); + private WaveData waveData; + public void SetData(WaveData data) + { + waveData = data; + foreach (var child in GetChildren()) + { + child.QueueFree(); + } + foreach (var spawn in waveData.zombiesOrdered) + { + InitEditor(spawn); + } + } + public void AddSpawn() + { + var spawn = new RowSpawn(); + waveData.zombiesOrdered.Add(spawn); + InitEditor(spawn); + } + public void RemoveSpawn() + { + var editor = GetChild(GetChildCount() - 1); + waveData.zombiesOrdered.Remove(editor.editedSpawn); + editor.QueueFree(); + } + private void InitEditor(RowSpawn spawn) + { + var editor = rowEditorScene.Instantiate(); + editor.editedSpawn = spawn; + AddChild(editor); + } +} diff --git a/addons/pvzadventure/scripts/ZE_GridContainer.cs.uid b/addons/pvzadventure/scripts/ZE_GridContainer.cs.uid new file mode 100644 index 0000000..38c7f93 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_GridContainer.cs.uid @@ -0,0 +1 @@ +uid://do7s5mo36c280 diff --git a/addons/pvzadventure/scripts/ZE_GridItem.cs b/addons/pvzadventure/scripts/ZE_GridItem.cs new file mode 100644 index 0000000..557a73e --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_GridItem.cs @@ -0,0 +1,47 @@ +using Godot; + + +[Tool] +public partial class ZE_GridItem : Control +{ + private ZombieResource resource; + public int index; + [Signal] public delegate void ResourceChangedEventHandler(ZombieResource resource, int index); + public void SetData(ZombieResource data) + { + resource = data; + UpdateContent(); + } + private void UpdateContent() + { + if (resource == null) + { + GetNode("Texture").Texture = null; + return; + } + GetNode("Texture").Texture = resource.Preview; + } + + public override Variant _GetDragData(Vector2 atPosition) + { + return resource; + } + public override bool _CanDropData(Vector2 atPosition, Variant data) + { + return data.AsGodotObject() is ZombieResource; + } + public override void _DropData(Vector2 atPosition, Variant data) + { + SetData((ZombieResource)data.AsGodotObject()); + EmitSignal(SignalName.ResourceChanged, resource, index); + } + public override void _GuiInput(InputEvent @event) + { + if (@event is InputEventMouseButton buttonEvent && buttonEvent.ButtonIndex == MouseButton.Right ) + { + SetData(null); + EmitSignal(SignalName.ResourceChanged, resource, index); + } + } + +} diff --git a/addons/pvzadventure/scripts/ZE_GridItem.cs.uid b/addons/pvzadventure/scripts/ZE_GridItem.cs.uid new file mode 100644 index 0000000..997bc43 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_GridItem.cs.uid @@ -0,0 +1 @@ +uid://fof6kr0et8ng diff --git a/addons/pvzadventure/scripts/ZE_RowEditor.cs b/addons/pvzadventure/scripts/ZE_RowEditor.cs new file mode 100644 index 0000000..f7649ba --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_RowEditor.cs @@ -0,0 +1,25 @@ +using Godot; + +[Tool] +public partial class ZE_RowEditor : VBoxContainer +{ + private PackedScene buttonScene = ResourceLoader.Load("uid://segxys6udhyw"); + public RowSpawn editedSpawn; + public override void _Ready() + { + for (int i = 0; i < editedSpawn.zombies.Count; i++) + { + var button = buttonScene.Instantiate(); + AddChild(button); + button.index = i; + if (editedSpawn.zombies[i] != null) + button.SetData(editedSpawn.zombies[i]); + button.ResourceChanged += OnResourceChanged; + } + } + + public void OnResourceChanged(ZombieResource resource, int index) + { + editedSpawn.zombies[index] = resource; + } +} diff --git a/addons/pvzadventure/scripts/ZE_RowEditor.cs.uid b/addons/pvzadventure/scripts/ZE_RowEditor.cs.uid new file mode 100644 index 0000000..7b05cf6 --- /dev/null +++ b/addons/pvzadventure/scripts/ZE_RowEditor.cs.uid @@ -0,0 +1 @@ +uid://q84g5imvatfl diff --git a/addons/pvzadventure/scripts/ZombieEditor.cs b/addons/pvzadventure/scripts/ZombieEditor.cs new file mode 100644 index 0000000..3d2e032 --- /dev/null +++ b/addons/pvzadventure/scripts/ZombieEditor.cs @@ -0,0 +1,15 @@ +using Godot; + + +[Tool] +public partial class ZombieEditor : VBoxContainer +{ + public WaveData editedWave; + [Export] private ZE_GridContainer container; + + public void SetEditedWave(WaveData data) + { + editedWave = data; + container.SetData(editedWave); + } +} diff --git a/addons/pvzadventure/scripts/ZombieEditor.cs.uid b/addons/pvzadventure/scripts/ZombieEditor.cs.uid new file mode 100644 index 0000000..53c2d71 --- /dev/null +++ b/addons/pvzadventure/scripts/ZombieEditor.cs.uid @@ -0,0 +1 @@ +uid://bd5hl0etgvf5a diff --git a/resources/levels/testlvl.tres b/resources/levels/testlvl.tres index 8dd9f07..0592aa4 100644 --- a/resources/levels/testlvl.tres +++ b/resources/levels/testlvl.tres @@ -1,40 +1,62 @@ -[gd_resource type="Resource" script_class="AdventureLevelResource" load_steps=9 format=3 uid="uid://bx1wnrgickeyd"] +[gd_resource type="Resource" script_class="AdventureLevelResource" load_steps=18 format=3 uid="uid://bx1wnrgickeyd"] [ext_resource type="Script" uid="uid://bximdujbkj2n4" path="res://addons/pvzadventure/AdventureLevelResource.cs" id="1_ed2ji"] [ext_resource type="Script" uid="uid://7rptlb5qr3b6" path="res://addons/pvzadventure/WaveData.cs" id="2_46l53"] +[ext_resource type="Script" uid="uid://dl12rj75tk2qi" path="res://addons/pvzadventure/RowSpawn.cs" id="3_xqi0a"] +[ext_resource type="Script" uid="uid://cqxj7o8hdm82n" path="res://scripts/resources/ZombieResource.cs" id="4_ak572"] +[ext_resource type="Resource" uid="uid://buvacn56kyy2p" path="res://resources/zombies/basic.tres" id="5_ak572"] +[ext_resource type="Resource" uid="uid://c38vfdw5b60xw" path="res://resources/zombies/hobo.tres" id="6_pdnxq"] +[ext_resource type="Resource" uid="uid://dkhjlu7u0vny6" path="res://resources/zombies/buckethead.tres" id="7_w6xpy"] + +[sub_resource type="Resource" id="Resource_w6xpy"] +script = ExtResource("3_xqi0a") +zombies = Array[ExtResource("4_ak572")]([ExtResource("5_ak572"), ExtResource("5_ak572"), ExtResource("6_pdnxq"), ExtResource("5_ak572"), ExtResource("6_pdnxq")]) +metadata/_custom_type_script = "uid://dl12rj75tk2qi" + +[sub_resource type="Resource" id="Resource_pdnxq"] +script = ExtResource("3_xqi0a") +zombies = Array[ExtResource("4_ak572")]([ExtResource("5_ak572"), ExtResource("6_pdnxq"), ExtResource("5_ak572"), null, ExtResource("5_ak572")]) + +[sub_resource type="Resource" id="Resource_ypxtr"] +script = ExtResource("3_xqi0a") +zombies = Array[ExtResource("4_ak572")]([ExtResource("6_pdnxq"), null, null, ExtResource("5_ak572"), null]) [sub_resource type="Resource" id="Resource_46l53"] script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null +zombiesOrdered = [SubResource("Resource_w6xpy"), SubResource("Resource_pdnxq"), SubResource("Resource_ypxtr")] +spawns = [] + +[sub_resource type="Resource" id="Resource_wdkt5"] +script = ExtResource("3_xqi0a") +zombies = Array[ExtResource("4_ak572")]([null, ExtResource("5_ak572"), null, ExtResource("7_w6xpy"), null]) + +[sub_resource type="Resource" id="Resource_asf3k"] +script = ExtResource("3_xqi0a") +zombies = Array[ExtResource("4_ak572")]([ExtResource("5_ak572"), null, ExtResource("7_w6xpy"), null, null]) [sub_resource type="Resource" id="Resource_yo1i5"] script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null +zombiesOrdered = [SubResource("Resource_wdkt5"), SubResource("Resource_asf3k")] +spawns = [] [sub_resource type="Resource" id="Resource_xqi0a"] script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null +zombiesOrdered = [] +spawns = [] [sub_resource type="Resource" id="Resource_ak572"] script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null +zombiesOrdered = [] +spawns = [] [sub_resource type="Resource" id="Resource_vfl7c"] script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null - -[sub_resource type="Resource" id="Resource_pdnxq"] -script = ExtResource("2_46l53") -zombiesOrdered = null -spawns = null +zombiesOrdered = [] +spawns = [] [resource] script = ExtResource("1_ed2ji") startSun = 0.0 -waves = [SubResource("Resource_46l53"), SubResource("Resource_yo1i5"), SubResource("Resource_xqi0a"), SubResource("Resource_ak572"), SubResource("Resource_vfl7c"), SubResource("Resource_pdnxq")] +wavePercentage = 0.0 +waves = [SubResource("Resource_46l53"), SubResource("Resource_yo1i5"), SubResource("Resource_xqi0a"), SubResource("Resource_ak572"), SubResource("Resource_vfl7c")] metadata/_custom_type_script = "uid://bximdujbkj2n4" diff --git a/scripts/resources/DisplayResource.cs b/scripts/resources/DisplayResource.cs index f05cd53..afea310 100644 --- a/scripts/resources/DisplayResource.cs +++ b/scripts/resources/DisplayResource.cs @@ -1,5 +1,6 @@ using Godot; +[Tool] public partial class DisplayResource : Resource { [Export] public string name_key; diff --git a/scripts/resources/ZombieResource.cs b/scripts/resources/ZombieResource.cs index bee27b7..723656c 100644 --- a/scripts/resources/ZombieResource.cs +++ b/scripts/resources/ZombieResource.cs @@ -1,6 +1,7 @@ using Godot; [GlobalClass] +[Tool] public partial class ZombieResource : DisplayResource { }