Inventory management of granted abilities
This commit is contained in:
81
menus/scenes/overlaid_menus/InventoryUi.cs
Normal file
81
menus/scenes/overlaid_menus/InventoryUi.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Godot;
|
||||
using Movementtests.managers;
|
||||
using Movementtests.systems;
|
||||
|
||||
[Tool, GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_crate.png")]
|
||||
public partial class InventoryUi : Control
|
||||
{
|
||||
private AbilitySelection _startedFlyingSelection;
|
||||
private AbilitySelection _whileFlyingSelection;
|
||||
private AbilitySelection _stoppedFlyingSelection;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_startedFlyingSelection = GetNode<AbilitySelection>("%StartedFlying");
|
||||
_whileFlyingSelection = GetNode<AbilitySelection>("%WhileFlying");
|
||||
_stoppedFlyingSelection = GetNode<AbilitySelection>("%StoppedFlying");
|
||||
|
||||
_startedFlyingSelection.Initialize(InventoryManager.Instance.WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying]);
|
||||
_whileFlyingSelection.Initialize(InventoryManager.Instance.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]);
|
||||
_stoppedFlyingSelection.Initialize(InventoryManager.Instance.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]);
|
||||
|
||||
_startedFlyingSelection.AbilityAdded += AddAbilityForEvent;
|
||||
_whileFlyingSelection.AbilityAdded += AddAbilityForEvent;
|
||||
_stoppedFlyingSelection.AbilityAdded += AddAbilityForEvent;
|
||||
|
||||
_startedFlyingSelection.AbilityRemoved += RemoveAbilityForEvent;
|
||||
_whileFlyingSelection.AbilityRemoved += RemoveAbilityForEvent;
|
||||
_stoppedFlyingSelection.AbilityRemoved += RemoveAbilityForEvent;
|
||||
|
||||
InventoryManager.Instance.WeaponEventAbilityAdded += OnWeaponEventInventoryAdded;
|
||||
InventoryManager.Instance.WeaponEventAbilityRemoved += OnWeaponEventInventoryRemoved;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryManager.Instance.WeaponEventAbilityAdded -= OnWeaponEventInventoryAdded;
|
||||
InventoryManager.Instance.WeaponEventAbilityRemoved -= OnWeaponEventInventoryRemoved;
|
||||
base._ExitTree();
|
||||
}
|
||||
|
||||
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
InventoryManager.Instance.AddAbilityForWeaponEvent(forEvent, abilityBehavior);
|
||||
}
|
||||
|
||||
public void RemoveAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
InventoryManager.Instance.RemoveAbilityForWeaponEvent(forEvent, abilityBehavior);
|
||||
}
|
||||
|
||||
public void OnWeaponEventInventoryAdded(WeaponEventAbilityData data)
|
||||
{
|
||||
if (data.Ability is not ForgeAbilityBehavior abilityBehavior) return;
|
||||
|
||||
var selection = GetAbilitySelection(data.ForEvent);
|
||||
selection.AddSelectedAbility(abilityBehavior);
|
||||
}
|
||||
|
||||
public void OnWeaponEventInventoryRemoved(WeaponEventAbilityData data)
|
||||
{
|
||||
if (data.Ability is not ForgeAbilityBehavior abilityBehavior) return;
|
||||
|
||||
var selection = GetAbilitySelection(data.ForEvent);
|
||||
selection.RemoveSelectedAbility(abilityBehavior);
|
||||
}
|
||||
|
||||
public AbilitySelection GetAbilitySelection(WeaponSystem.WeaponEvent forEvent)
|
||||
{
|
||||
var abilitiesSelectionsMap = new Dictionary<WeaponSystem.WeaponEvent, AbilitySelection>
|
||||
{
|
||||
{ WeaponSystem.WeaponEvent.StartedFlying, _startedFlyingSelection },
|
||||
{ WeaponSystem.WeaponEvent.StoppedFlying, _stoppedFlyingSelection },
|
||||
{ WeaponSystem.WeaponEvent.FlyingTick, _whileFlyingSelection },
|
||||
};
|
||||
|
||||
return abilitiesSelectionsMap[forEvent];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user