using System; using System.Collections.Generic; using Chickensoft.AutoInject; using Chickensoft.Introspection; using Chickensoft.Sync.Primitives; 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, IDisposable { 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 AutoSet.Binding StartedFlyingBinding { get; set; } public AutoSet.Binding FlyingTickBinding { get; set; } public AutoSet.Binding StoppedFlyingBinding { get; set; } 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]); StartedFlyingBinding = InventoryManager.StartedFlyingAbilities.Bind(); StartedFlyingBinding .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StartedFlying, behavior)) .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StartedFlying, behavior)) .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StartedFlying)); FlyingTickBinding = InventoryManager.FlyingTickAbilities.Bind(); FlyingTickBinding .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.FlyingTick, behavior)) .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.FlyingTick, behavior)) .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.FlyingTick)); StoppedFlyingBinding = InventoryManager.StoppedFlyingAbilities.Bind(); StoppedFlyingBinding .OnAdd(behavior => OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) .OnRemove(behavior => OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent.StoppedFlying, behavior)) .OnClear(() => OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent.StoppedFlying)); } public new void Dispose() { GC.SuppressFinalize(this); StartedFlying.Dispose(); WhileFlying.Dispose(); StoppedFlying.Dispose(); base.Dispose(); } 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(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { var selection = GetAbilitySelection(forEvent); selection.AddSelectedAbility(abilityBehavior); } public void OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior) { var selection = GetAbilitySelection(forEvent); selection.RemoveSelectedAbility(abilityBehavior); } public void OnWeaponEventInventoryCleared(WeaponSystem.WeaponEvent forEvent) { var selection = GetAbilitySelection(forEvent); selection.ClearAbilities(); } 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]; } }