Zombie editor

This commit is contained in:
Rendo 2025-07-16 04:11:26 +05:00
commit 7d1ca26baa
23 changed files with 435 additions and 25 deletions

View file

@ -1,5 +1,9 @@
using Godot;
using Godot.Collections;
[Tool]
[GlobalClass]
public partial class RowSpawn : Resource
{
[Export] public Array<ZombieResource> zombies = new(new ZombieResource[5]);
}

View file

@ -5,6 +5,6 @@ using Godot.Collections;
[Tool]
public partial class WaveData : Resource
{
[Export] private Array<RowSpawn> zombiesOrdered;
[Export] private Array<WaveEvent> spawns;
[Export] public Array<RowSpawn> zombiesOrdered;
[Export] public Array<WaveEvent> spawns;
}

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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")

View file

@ -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"]

View file

@ -6,6 +6,7 @@ public partial class AdventureResourceInspector : Node
{
const int ORDERED = 0;
const int EVENTS = 1;
private PackedScene zombieEditorScene = ResourceLoader.Load<PackedScene>("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>("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<ZombieEditor>();
editorContainer.AddChild(editor);
editor.SetEditedWave(heldResource.waves[int.Parse(selected.GetParent().GetText(0).Split(" ")[1])]);
}
else if (index == EVENTS)
{

View file

@ -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<PackedScene>("uid://iwnklc62rni8");
public override void _Ready()
{
foreach (var file in ResourceLoader.ListDirectory(ZOMBIE_PATH))
{
var data = ResourceLoader.Load<ZombieResource>(ZOMBIE_PATH + file);
var button = scene.Instantiate<ZE_AssetBrowserButton>();
button.SetData(data);
AddChild(button);
}
}
}

View file

@ -0,0 +1 @@
uid://bnuno3uhya4sg

View file

@ -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<TextureRect>("Texture").Texture = resource.Preview;
}
public override Variant _GetDragData(Vector2 atPosition)
{
return resource;
}
}

View file

@ -0,0 +1 @@
uid://cpedvgx23hlko

View file

@ -0,0 +1,38 @@
using Godot;
[Tool]
public partial class ZE_GridContainer : Control
{
private PackedScene rowEditorScene = ResourceLoader.Load<PackedScene>("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<ZE_RowEditor>(GetChildCount() - 1);
waveData.zombiesOrdered.Remove(editor.editedSpawn);
editor.QueueFree();
}
private void InitEditor(RowSpawn spawn)
{
var editor = rowEditorScene.Instantiate<ZE_RowEditor>();
editor.editedSpawn = spawn;
AddChild(editor);
}
}

View file

@ -0,0 +1 @@
uid://do7s5mo36c280

View file

@ -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<TextureRect>("Texture").Texture = null;
return;
}
GetNode<TextureRect>("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);
}
}
}

View file

@ -0,0 +1 @@
uid://fof6kr0et8ng

View file

@ -0,0 +1,25 @@
using Godot;
[Tool]
public partial class ZE_RowEditor : VBoxContainer
{
private PackedScene buttonScene = ResourceLoader.Load<PackedScene>("uid://segxys6udhyw");
public RowSpawn editedSpawn;
public override void _Ready()
{
for (int i = 0; i < editedSpawn.zombies.Count; i++)
{
var button = buttonScene.Instantiate<ZE_GridItem>();
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;
}
}

View file

@ -0,0 +1 @@
uid://q84g5imvatfl

View file

@ -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);
}
}

View file

@ -0,0 +1 @@
uid://bd5hl0etgvf5a

View file

@ -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"

View file

@ -1,5 +1,6 @@
using Godot;
[Tool]
public partial class DisplayResource : Resource
{
[Export] public string name_key;

View file

@ -1,6 +1,7 @@
using Godot;
[GlobalClass]
[Tool]
public partial class ZombieResource : DisplayResource
{
}