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("%StartedFlying"); _whileFlyingSelection = GetNode("%WhileFlying"); _stoppedFlyingSelection = GetNode("%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.StartedFlying, _startedFlyingSelection }, { WeaponSystem.WeaponEvent.StoppedFlying, _stoppedFlyingSelection }, { WeaponSystem.WeaponEvent.FlyingTick, _whileFlyingSelection }, }; return abilitiesSelectionsMap[forEvent]; } }