Generic marker pickups

This commit is contained in:
Marco 2025-05-01 10:04:15 +02:00
commit 692c33c939
15 changed files with 176 additions and 36 deletions

View file

@ -0,0 +1,65 @@
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Actors;
[Tool]
public partial class ItemMarker : Marker2D
{
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);
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();
}
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
if (AutoSpawn)
{
Spawn(true);
}
}
public ItemPickup Spawn(bool deleteMarker)
{
if (Engine.IsEditorHint()) return null;
if (Item is null) return null;
if (deleteMarker)
{
this.QueueFree();
}
return Item.Spawn(this);
}
}

View file

@ -0,0 +1 @@
uid://cqoqovfvk83wn

View file

@ -0,0 +1,15 @@
#if TOOLS
using Godot;
namespace Cirno.Scripts.Editor;
[Tool]
public partial class CreateWeapon : EditorScript
{
// Called when the script is executed (using File -> Run in Script Editor).
public override void _Run()
{
}
}
#endif

View file

@ -0,0 +1 @@
uid://8y0ql44v5ckt

View file

@ -100,4 +100,11 @@ public partial class ItemPickup : Interactable
// }
// }
}
public void SetSprite(Texture2D sprite)
{
var spriteNode = GetNodeOrNull<Sprite2D>("Sprite2D");
if (spriteNode is null) return;
spriteNode.Texture = sprite;
}
}

View file

@ -1,4 +1,5 @@
using Cirno.Scripts.Resources.ItemEffects;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources.ItemEffects;
using Godot;
namespace Cirno.Scripts.Resources;
@ -26,6 +27,20 @@ public partial class LootItem : Resource
//[Export] public SpriteFrames WorldSprite;
//[Export] public PackedScene HudItemScene;
[Export(PropertyHint.File)] public StringName DropScenePath { get; private set; } // Has to be a string path to avoid recursion issues
public ItemPickup Spawn(Node2D parent)
{
if (string.IsNullOrWhiteSpace(DropScenePath)) return null;
var itemScene = GD.Load<PackedScene>(DropScenePath);
var spawnedItem = parent.CreateSibling<ItemPickup>(itemScene);
spawnedItem.Name = this.ItemKey;
spawnedItem.LootTable.Add(this);
spawnedItem.SetSprite(InventorySprite);
return spawnedItem;
}
}
public enum UiItemType