Prepicked plants editor
This commit is contained in:
parent
9eba7d3069
commit
56f75a5d06
43 changed files with 532 additions and 50 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue