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

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