Prepicked plants editor
This commit is contained in:
parent
9eba7d3069
commit
56f75a5d06
43 changed files with 532 additions and 50 deletions
16
addons/pvzadventure/scripts/BaseEditor.cs
Normal file
16
addons/pvzadventure/scripts/BaseEditor.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public abstract partial class BaseEditor : Node
|
||||
{
|
||||
public AdventureLevelResource editedResource;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
public virtual void SetEditedData(AdventureLevelResource data)
|
||||
{
|
||||
editedResource = data;
|
||||
}
|
||||
public virtual void Save()
|
||||
{
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
}
|
||||
1
addons/pvzadventure/scripts/BaseEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/BaseEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dxtrrfg1pba4p
|
||||
5
addons/pvzadventure/scripts/BaseWaveEditor.cs
Normal file
5
addons/pvzadventure/scripts/BaseWaveEditor.cs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
public abstract partial class BaseWaveEditor : BaseEditor
|
||||
{
|
||||
public WaveData editedWave;
|
||||
public abstract void SetEditedWave(WaveData wave);
|
||||
}
|
||||
1
addons/pvzadventure/scripts/BaseWaveEditor.cs.uid
Normal file
1
addons/pvzadventure/scripts/BaseWaveEditor.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b23csior6audk
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class InitialEditor : Node
|
||||
public partial class InitialEditor : BaseEditor
|
||||
{
|
||||
public AdventureLevelResource editedResource;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
public override void _Ready()
|
||||
{
|
||||
foreach (var child in GetChild(0).GetChildren())
|
||||
|
|
@ -15,7 +13,7 @@ public partial class InitialEditor : Node
|
|||
}
|
||||
}
|
||||
}
|
||||
public void SetData(AdventureLevelResource resource)
|
||||
public override void SetEditedData(AdventureLevelResource resource)
|
||||
{
|
||||
editedResource = resource;
|
||||
for (int i = 0; i < GetChild(0).GetChildCount(); i++)
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ public partial class AdventureResourceInspector : Node
|
|||
const string ZOMBIES_ITEM_NAME = "Zombies";
|
||||
const string EVENTS_ITEM_NAME = "Events";
|
||||
const string HUGEWAVE_ITEM_NAME = "Is huge wave?";
|
||||
const string SEEDPACKETS_ITEM_NAME = "Seedpackets editor";
|
||||
private PackedScene zombieEditorScene = ResourceLoader.Load<PackedScene>("uid://db5ah76l43ng2");
|
||||
private PackedScene initialEditorScene = ResourceLoader.Load<PackedScene>("uid://sqessjn0m4o3");
|
||||
private PackedScene seedpacketEditorScene = ResourceLoader.Load<PackedScene>("uid://drc0o8du38apr");
|
||||
|
||||
private Tree tree;
|
||||
private AdventureLevelResource heldResource;
|
||||
|
|
@ -28,6 +30,7 @@ public partial class AdventureResourceInspector : Node
|
|||
|
||||
private TreeItem root;
|
||||
private TreeItem initialData;
|
||||
private TreeItem seedpacketData;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -48,6 +51,7 @@ public partial class AdventureResourceInspector : Node
|
|||
root = CreateItem(LEVEL_ITEM_NAME);
|
||||
|
||||
initialData = CreateItem(INITIAL_ITEM_NAME, root);
|
||||
seedpacketData = CreateItem(SEEDPACKETS_ITEM_NAME, root);
|
||||
|
||||
for (int i = 0; i < heldResource.waves.Count; i++)
|
||||
{
|
||||
|
|
@ -58,7 +62,7 @@ public partial class AdventureResourceInspector : Node
|
|||
CreateItem(EVENTS_ITEM_NAME, wave);
|
||||
CreateItem(HUGEWAVE_ITEM_NAME, TreeItem.TreeCellMode.Check, true, wave)
|
||||
.SetChecked(0, heldResource.waves[i].isHugeWave);
|
||||
|
||||
|
||||
|
||||
var delay = tree.CreateItem(wave);
|
||||
if (heldResource.waves[i].customWaveDelay > 0)
|
||||
|
|
@ -94,8 +98,7 @@ public partial class AdventureResourceInspector : Node
|
|||
var editor = zombieEditorScene.Instantiate<ZombieEditor>();
|
||||
|
||||
editorContainer.AddChild(editor);
|
||||
editor.SetEditedWave(heldResource.waves[GetWaveIndex(selected.GetParent())]);
|
||||
editor.SaveCallback += adventureEditor.Save;
|
||||
SetupWaveEditor(editor, heldResource.waves[GetWaveIndex(selected.GetParent())]);
|
||||
return;
|
||||
case EVENTS_ITEM_NAME:
|
||||
|
||||
|
|
@ -103,9 +106,14 @@ public partial class AdventureResourceInspector : Node
|
|||
case INITIAL_ITEM_NAME:
|
||||
var initialEditor = initialEditorScene.Instantiate<InitialEditor>();
|
||||
editorContainer.AddChild(initialEditor);
|
||||
initialEditor.SetData(heldResource);
|
||||
initialEditor.SaveCallback += adventureEditor.Save;
|
||||
SetupEditor(initialEditor);
|
||||
break;
|
||||
case SEEDPACKETS_ITEM_NAME:
|
||||
var seedpacketEditor = seedpacketEditorScene.Instantiate<SeedpacketEditor>();
|
||||
editorContainer.AddChild(seedpacketEditor);
|
||||
SetupEditor(seedpacketEditor);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -161,10 +169,21 @@ public partial class AdventureResourceInspector : Node
|
|||
private TreeItem CreateItem(string Name, TreeItem.TreeCellMode cellMode, bool editable, TreeItem root = null)
|
||||
{
|
||||
var item = tree.CreateItem(root);
|
||||
item.SetCellMode(0,cellMode);
|
||||
item.SetCellMode(0, cellMode);
|
||||
item.SetEditable(0, editable);
|
||||
item.SetText(0, Name);
|
||||
return item;
|
||||
}
|
||||
private void SetupEditor(BaseEditor editor)
|
||||
{
|
||||
editor.SetEditedData(heldResource);
|
||||
editor.SaveCallback += adventureEditor.Save;
|
||||
}
|
||||
private void SetupWaveEditor(BaseWaveEditor editor, WaveData editedWave)
|
||||
{
|
||||
SetupEditor(editor);
|
||||
editor.SetEditedWave(editedWave);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using Godot;
|
||||
using Newlon.Resources;
|
||||
|
||||
[Tool]
|
||||
public partial class DnDSeedpacket : TextureButton
|
||||
{
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
[Export] private TextureRect preview;
|
||||
public PlantResource HeldResource;
|
||||
|
||||
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
if (data.VariantType == Variant.Type.Dictionary)
|
||||
{
|
||||
if ((string)data.AsGodotDictionary()["type"] == "files")
|
||||
{
|
||||
return ResourceLoader.Load(data.AsGodotDictionary()["files"].AsGodotArray<string>()[0]) is PlantResource;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void _DropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
HeldResource = ResourceLoader.Load(data.AsGodotDictionary()["files"].AsGodotArray<string>()[0]) as PlantResource;
|
||||
Update();
|
||||
}
|
||||
public override void _Pressed()
|
||||
{
|
||||
HeldResource = null;
|
||||
Update();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
RefreshTexture();
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
public void RefreshTexture()
|
||||
{
|
||||
if (HeldResource != null)
|
||||
{
|
||||
preview.Texture = HeldResource.Preview;
|
||||
}
|
||||
else
|
||||
{
|
||||
preview.Texture = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bhah157u6q56b
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Newlon.Resources;
|
||||
|
||||
[Tool]
|
||||
public partial class SeedpacketEditor : BaseEditor
|
||||
{
|
||||
private const string PLANTS_DIRECTORY = "res://assets/plants/";
|
||||
public override void SetEditedData(AdventureLevelResource data)
|
||||
{
|
||||
base.SetEditedData(data);
|
||||
SetPrepickedPlants();
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
CalculatePrepickedPlants();
|
||||
base.Save();
|
||||
}
|
||||
private void SetPrepickedPlants()
|
||||
{
|
||||
for (int i = 0; i < editedResource.prepickedPlants.Count; i++)
|
||||
{
|
||||
if (GetNode("%PrepickedContainer").GetChild(i).GetNode("Seedpacket") is DnDSeedpacket packet)
|
||||
{
|
||||
packet.HeldResource = TryGetPlant(editedResource.prepickedPlants[i]);
|
||||
packet.RefreshTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CalculatePrepickedPlants()
|
||||
{
|
||||
Array<string> prepicked = new();
|
||||
foreach (var child in GetNode("%PrepickedContainer").GetChildren())
|
||||
{
|
||||
if (child.GetNode("Seedpacket") is DnDSeedpacket packet && packet.HeldResource != null)
|
||||
{
|
||||
prepicked.Add(packet.HeldResource.GetInternalID());
|
||||
}
|
||||
}
|
||||
editedResource.prepickedPlants = prepicked;
|
||||
}
|
||||
private PlantResource TryGetPlant(string plantName)
|
||||
{
|
||||
foreach (var file in ResourceLoader.ListDirectory(PLANTS_DIRECTORY))
|
||||
{
|
||||
if (plantName != file.TrimSuffix(".tres").ToLower()) continue;
|
||||
return ResourceLoader.Load<PlantResource>(PLANTS_DIRECTORY + file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://d1ks2q0c3eu0v
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
@tool
|
||||
extends TextureButton
|
||||
|
||||
signal save_callback
|
||||
|
||||
var held_data : PlantResource = null
|
||||
@export var preview : TextureRect
|
||||
|
||||
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
|
||||
if typeof(data) == TYPE_DICTIONARY:
|
||||
if data.type == "files":
|
||||
return load(data.files[0]) is PlantResource
|
||||
return false
|
||||
|
||||
func _drop_data(at_position: Vector2, data: Variant) -> void:
|
||||
held_data = load(data.files[0]) as PlantResource
|
||||
update()
|
||||
|
||||
func update():
|
||||
if held_data:
|
||||
preview.texture = held_data.Preview
|
||||
else:
|
||||
preview.texture = null
|
||||
save_callback.emit()
|
||||
|
||||
func _pressed() -> void:
|
||||
held_data = null
|
||||
update()
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://donugf6vnchij
|
||||
|
|
@ -2,19 +2,13 @@ using Godot;
|
|||
|
||||
|
||||
[Tool]
|
||||
public partial class ZombieEditor : VBoxContainer
|
||||
public partial class ZombieEditor : BaseWaveEditor
|
||||
{
|
||||
public WaveData editedWave;
|
||||
[Export] private ZE_GridContainer container;
|
||||
[Signal] public delegate void SaveCallbackEventHandler();
|
||||
|
||||
public void SetEditedWave(WaveData data)
|
||||
public override void SetEditedWave(WaveData data)
|
||||
{
|
||||
editedWave = data;
|
||||
container.SetData(editedWave);
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
EmitSignal(SignalName.SaveCallback);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue