Editor slight refactor
This commit is contained in:
parent
285b90f503
commit
8cfbad01cf
23 changed files with 9 additions and 8 deletions
20
addons/pvzadventure/scripts/zombie-editor/ZE_AssetBrowser.cs
Normal file
20
addons/pvzadventure/scripts/zombie-editor/ZE_AssetBrowser.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
|
||||
[Tool]
|
||||
public partial class ZE_AssetBrowser : HBoxContainer
|
||||
{
|
||||
const string ZOMBIE_PATH = "res://assets/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bnuno3uhya4sg
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cpedvgx23hlko
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class ZE_GridContainer : Control
|
||||
{
|
||||
private PackedScene rowEditorScene = ResourceLoader.Load<PackedScene>("uid://buvnw8a7pku78");
|
||||
private WaveData waveData;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
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;
|
||||
editor.SaveCallback += Save;
|
||||
AddChild(editor);
|
||||
}
|
||||
private void Save()
|
||||
{
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://do7s5mo36c280
|
||||
48
addons/pvzadventure/scripts/zombie-editor/ZE_GridItem.cs
Normal file
48
addons/pvzadventure/scripts/zombie-editor/ZE_GridItem.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://fof6kr0et8ng
|
||||
29
addons/pvzadventure/scripts/zombie-editor/ZE_RowEditor.cs
Normal file
29
addons/pvzadventure/scripts/zombie-editor/ZE_RowEditor.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
|
||||
[Tool]
|
||||
public partial class ZE_RowEditor : VBoxContainer
|
||||
{
|
||||
private PackedScene buttonScene = ResourceLoader.Load<PackedScene>("uid://segxys6udhyw");
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
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;
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://q84g5imvatfl
|
||||
20
addons/pvzadventure/scripts/zombie-editor/ZombieEditor.cs
Normal file
20
addons/pvzadventure/scripts/zombie-editor/ZombieEditor.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Godot;
|
||||
|
||||
|
||||
[Tool]
|
||||
public partial class ZombieEditor : VBoxContainer
|
||||
{
|
||||
public WaveData editedWave;
|
||||
[Export] private ZE_GridContainer container;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
|
||||
public void SetEditedWave(WaveData data)
|
||||
{
|
||||
editedWave = data;
|
||||
container.SetData(editedWave);
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bd5hl0etgvf5a
|
||||
Loading…
Add table
Add a link
Reference in a new issue