Zombie editor
This commit is contained in:
parent
623362e430
commit
7d1ca26baa
23 changed files with 435 additions and 25 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
19
addons/pvzadventure/scripts/ZE_AssetBrowser.cs
Normal file
19
addons/pvzadventure/scripts/ZE_AssetBrowser.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZE_AssetBrowser.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bnuno3uhya4sg
|
||||
22
addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs
Normal file
22
addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZE_AssetBrowserButton.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cpedvgx23hlko
|
||||
38
addons/pvzadventure/scripts/ZE_GridContainer.cs
Normal file
38
addons/pvzadventure/scripts/ZE_GridContainer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZE_GridContainer.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZE_GridContainer.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://do7s5mo36c280
|
||||
47
addons/pvzadventure/scripts/ZE_GridItem.cs
Normal file
47
addons/pvzadventure/scripts/ZE_GridItem.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZE_GridItem.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZE_GridItem.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://fof6kr0et8ng
|
||||
25
addons/pvzadventure/scripts/ZE_RowEditor.cs
Normal file
25
addons/pvzadventure/scripts/ZE_RowEditor.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZE_RowEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZE_RowEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://q84g5imvatfl
|
||||
15
addons/pvzadventure/scripts/ZombieEditor.cs
Normal file
15
addons/pvzadventure/scripts/ZombieEditor.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/ZombieEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/ZombieEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bd5hl0etgvf5a
|
||||
Loading…
Add table
Add a link
Reference in a new issue