mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 03:15:54 +00:00
Generic marker pickups
This commit is contained in:
parent
6cbf2014b4
commit
692c33c939
15 changed files with 176 additions and 36 deletions
65
Scripts/Actors/ItemMarker.cs
Normal file
65
Scripts/Actors/ItemMarker.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/ItemMarker.cs.uid
Normal file
1
Scripts/Actors/ItemMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cqoqovfvk83wn
|
||||
15
Scripts/Editor/CreateWeapon.cs
Normal file
15
Scripts/Editor/CreateWeapon.cs
Normal 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
|
||||
1
Scripts/Editor/CreateWeapon.cs.uid
Normal file
1
Scripts/Editor/CreateWeapon.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://8y0ql44v5ckt
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue