cirnogodot/Scripts/Actors/ItemMarker3D.cs
2025-08-12 14:37:48 +02:00

132 lines
No EOL
3.3 KiB
C#

using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Actors;
[Tool]
public partial class ItemMarker3D : PreviewMarker3D
{
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
private LootItem _item;
[Export]
public LootItem Item
{
get => _item;
set
{
_item = value;
if (Engine.IsEditorHint())
{
//QueueRedraw();
this.Texture = _item.InventorySprite;
}
}
}
[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()
{
base._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);
}
public override void _Process(double delta)
{
if (!Engine.IsEditorHint()) return;
#if !DISABLE_DD3D
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Blue);
#endif
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
}
}