mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 07:45:33 +00:00
118 lines
No EOL
2.7 KiB
C#
118 lines
No EOL
2.7 KiB
C#
using Cirno.Scripts.Interactables;
|
|
using Cirno.Scripts.Resources;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Actors;
|
|
|
|
[Tool]
|
|
public partial class ItemMarker3D : Marker3D
|
|
{
|
|
private LootItem _item;
|
|
|
|
[Export]
|
|
public LootItem Item
|
|
{
|
|
get => _item;
|
|
set
|
|
{
|
|
_item = value;
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
QueueRedraw();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Export] public bool AutoSpawn { get; set; } = false;
|
|
|
|
[ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw);
|
|
[ExportToolButton("Clear Children")] public Callable ClearChildrenButton => Callable.From(ClearChildren);
|
|
|
|
// public override void _Draw()
|
|
// {
|
|
// if (!Engine.IsEditorHint()) return;
|
|
// if (Item is null) return;
|
|
// if (Item.InventorySprite is null) return;
|
|
//
|
|
// DrawTexture(Item.InventorySprite, - new Vector2(Item.InventorySprite.GetWidth() / 2f, Item.InventorySprite.GetHeight() / 2f));
|
|
// }
|
|
//
|
|
private void Redraw()
|
|
{
|
|
QueueRedraw();
|
|
}
|
|
|
|
private void ClearChildren()
|
|
{
|
|
var children = GetChildren();
|
|
foreach (var child in children)
|
|
{
|
|
if (child is Sprite3D)
|
|
{
|
|
child.QueueFree();
|
|
}
|
|
}
|
|
|
|
_sprite = null;
|
|
}
|
|
|
|
private void QueueRedraw()
|
|
{
|
|
if (!Engine.IsEditorHint()) return;
|
|
if (Item?.InventorySprite is null) return;
|
|
|
|
if (_sprite is null)
|
|
{
|
|
GD.Print("Remaking sprite");
|
|
_sprite = new EditorSprite3D();
|
|
this.AddChild(_sprite);
|
|
//_sprite.Owner = GetTree().EditedSceneRoot;
|
|
}
|
|
|
|
_sprite.Texture = Item.InventorySprite;
|
|
//_sprite.SetRotationDegrees(new Vector3(-45, 45, 0));
|
|
_sprite.FixedSize = true;
|
|
_sprite.SetBillboardMode(BaseMaterial3D.BillboardModeEnum.Enabled);
|
|
_sprite.TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest;
|
|
|
|
|
|
}
|
|
|
|
private Sprite3D _sprite;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_sprite = GetNodeOrNull<Sprite3D>("Sprite3D");
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
QueueRedraw();
|
|
|
|
return;
|
|
}
|
|
|
|
ClearChildren();
|
|
|
|
if (AutoSpawn)
|
|
{
|
|
Spawn(false);
|
|
}
|
|
}
|
|
|
|
// public override void _Process(double delta)
|
|
// {
|
|
//
|
|
// }
|
|
|
|
public ItemPickup3D Spawn(bool deleteMarker)
|
|
{
|
|
if (Engine.IsEditorHint()) return null;
|
|
if (Item is null) return null;
|
|
|
|
if (deleteMarker)
|
|
{
|
|
this.QueueFree();
|
|
}
|
|
|
|
return Item.Spawn3D(this);
|
|
}
|
|
} |