diff --git a/addons/forge/resources/abilities/ForgeAbilityBehavior.cs b/addons/forge/resources/abilities/ForgeAbilityBehavior.cs index c2f032cb..a7cfd454 100644 --- a/addons/forge/resources/abilities/ForgeAbilityBehavior.cs +++ b/addons/forge/resources/abilities/ForgeAbilityBehavior.cs @@ -10,5 +10,9 @@ namespace Gamesmiths.Forge.Godot.Resources.Abilities; [Icon("uid://bcx7anhepqfmd")] public abstract partial class ForgeAbilityBehavior : Resource { + [Export] public string? Name { get; set; } + [Export] public string? Description { get; set; } + [Export] public Texture2D? Icon { get; set; } + public abstract IAbilityBehavior GetBehavior(); } diff --git a/managers/InventoryManager.cs b/managers/InventoryManager.cs index 104bf226..8b920629 100644 --- a/managers/InventoryManager.cs +++ b/managers/InventoryManager.cs @@ -1,15 +1,15 @@ -using System; using System.Collections.Generic; +using Gamesmiths.Forge.Godot.Resources.Abilities; using Godot; using Movementtests.systems; namespace Movementtests.managers; -public partial class WeaponEventInventoryChangedData(WeaponSystem.WeaponEvent forEvent, string abilityName) +public partial class WeaponEventAbilityData(WeaponSystem.WeaponEvent forEvent, Resource ability) : RefCounted { public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent; - public string Ability { get; private set; } = abilityName; + public Resource Ability { get; private set; } = ability; } public partial class InventoryManager : Node @@ -18,19 +18,41 @@ public partial class InventoryManager : Node public delegate void InventoryChangedEventHandler(); [Signal] - public delegate void WeaponEventInventoryChangedEventHandler(WeaponEventInventoryChangedData data); + public delegate void WeaponEventInventoryChangedEventHandler(); + [Signal] + public delegate void WeaponEventAbilityAddedEventHandler(WeaponEventAbilityData data); + [Signal] + public delegate void WeaponEventAbilityRemovedEventHandler(WeaponEventAbilityData data); - public Dictionary Inventory { get; } = new(); + public Dictionary> WeaponEventsInventory { get; } = []; public static InventoryManager Instance { get; private set; } public override void _Ready() { Instance = this; + WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick] = new HashSet(); + WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying] = new HashSet(); + WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying] = new HashSet(); } - public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, string abilityName) + public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { - EmitSignalWeaponEventInventoryChanged(new WeaponEventInventoryChangedData(forEvent, abilityName)); + var inventoryForEvent = WeaponEventsInventory[forEvent]; + var addedAbilityToInventory = inventoryForEvent.Add(abilityBehavior); + if (!addedAbilityToInventory) return; + + EmitSignalWeaponEventInventoryChanged(); + EmitSignalWeaponEventAbilityAdded(new WeaponEventAbilityData(forEvent, abilityBehavior)); + } + + public void RemoveAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) + { + var inventoryForEvent = WeaponEventsInventory[forEvent]; + var removedFromInventory = inventoryForEvent.Remove(abilityBehavior); + if (!removedFromInventory) return; + + EmitSignalWeaponEventInventoryChanged(); + EmitSignalWeaponEventAbilityRemoved(new WeaponEventAbilityData(forEvent, abilityBehavior)); } } diff --git a/menus/scenes/components/AbilitySelection.cs b/menus/scenes/components/AbilitySelection.cs index 5d4445ea..f3863997 100644 --- a/menus/scenes/components/AbilitySelection.cs +++ b/menus/scenes/components/AbilitySelection.cs @@ -1,55 +1,83 @@ using System; +using System.Collections.Generic; +using Gamesmiths.Forge.Godot.Resources.Abilities; using Godot; using Movementtests.systems; [Tool, GlobalClass] public partial class AbilitySelection : Control { - [Signal] public delegate void AbilityAddedEventHandler(WeaponSystem.WeaponEvent forEvent, string abilityName); + [Signal] public delegate void AbilityAddedEventHandler(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior behavior); + [Signal] public delegate void AbilityRemovedEventHandler(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior behavior); [Export] public WeaponSystem.WeaponEvent ForEvent { get; set; } = WeaponSystem.WeaponEvent.StartedFlying; - private string _title = string.Empty; - [Export] public string Title { - get => _title; - set - { - _title = value; - TitleChanged(); - } - } + [Export] public string Title { get; set; } = string.Empty; - [Export] public PackedScene AbilitySelectionItem { get; set; } + [Export] public PackedScene AbilitySelectedItem { get; set; } + + [Export] public ForgeAbilityBehavior[] AbilityBehaviors { get; set; } - private VBoxContainer _abilities; + private VBoxContainer _selectedAbilities; private MenuButton _addAbility; private PopupMenu _addAbilityMenu; public override void _Ready() { - _abilities = GetNode("%SelectedAbilities"); + var titleLabel = GetNode