Inventory management of granted abilities
This commit is contained in:
56
menus/scenes/components/SelectedAbility.cs
Normal file
56
menus/scenes/components/SelectedAbility.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
|
||||
[Tool, GlobalClass]
|
||||
public partial class SelectedAbility : Control
|
||||
{
|
||||
[Signal] public delegate void AbilityRemovedEventHandler(ForgeAbilityBehavior ability);
|
||||
|
||||
private ForgeAbilityBehavior? _ability;
|
||||
[Export]
|
||||
public ForgeAbilityBehavior? Ability
|
||||
{
|
||||
get => _ability;
|
||||
set
|
||||
{
|
||||
_ability = value;
|
||||
if (_ability == null || !Engine.IsEditorHint()) return;
|
||||
AbilityUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private TextureRect? _icon;
|
||||
private Label? _title;
|
||||
private Button? _remove;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_icon = GetNode<TextureRect>("%Icon");
|
||||
_title = GetNode<Label>("%Title");
|
||||
_remove = GetNode<Button>("%Remove");
|
||||
|
||||
_remove.Pressed += () => EmitSignalAbilityRemoved(Ability);
|
||||
}
|
||||
|
||||
public void SetAbility(ForgeAbilityBehavior ability)
|
||||
{
|
||||
_ability = ability;
|
||||
AbilityUpdated();
|
||||
}
|
||||
|
||||
public void AbilityUpdated()
|
||||
{
|
||||
var icon = _icon ?? GetNode<TextureRect>("%Icon");
|
||||
var title = _title ?? GetNode<Label>("%Title");
|
||||
if (icon == null || title == null) return;
|
||||
if (_ability == null)
|
||||
{
|
||||
icon.Texture = null;
|
||||
title.Text = "";
|
||||
return;
|
||||
}
|
||||
icon.Texture = _ability.Icon;
|
||||
title.Text = _ability.Name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user