using System.Collections.Generic; using Chickensoft.AutoInject; using Chickensoft.Introspection; 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"), Meta(typeof(IAutoNode))] public partial class InventoryUi : Control { public override void _Notification(int what) => this.Notify(what); #region Dependencies [Dependency] public InventoryManager InventoryManager => this.DependOn(); #endregion Dependencies #region Nodes [Node] public required AbilitySelection StartedFlying { get; set; } [Node] public required AbilitySelection WhileFlying { get; set; } [Node] public required AbilitySelection StoppedFlying { get; set; } #endregion Nodes public void OnReady() { StartedFlying.AbilityAdded += AddAbilityForEvent; WhileFlying.AbilityAdded += AddAbilityForEvent; StoppedFlying.AbilityAdded += AddAbilityForEvent; StartedFlying.AbilityRemoved += RemoveAbilityForEvent; WhileFlying.AbilityRemoved += RemoveAbilityForEvent; StoppedFlying.AbilityRemoved += RemoveAbilityForEvent; } public void OnResolved() { StartedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StartedFlying]); WhileFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]); StoppedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]); InventoryManager.WeaponEventAbilityAdded += OnWeaponEventInventoryAdded; InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventInventoryRemoved; } public void OnExitTree() { InventoryManager.WeaponEventAbilityAdded -= OnWeaponEventInventoryAdded; InventoryManager.WeaponEventAbilityRemoved -= OnWeaponEventInventoryRemoved; } public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { InventoryManager.AddAbilityForWeaponEvent(forEvent, abilityBehavior); } public void RemoveAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { InventoryManager.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, StartedFlying }, { WeaponSystem.WeaponEvent.StoppedFlying, StoppedFlying }, { WeaponSystem.WeaponEvent.FlyingTick, WhileFlying }, }; return abilitiesSelectionsMap[forEvent]; } }