Files
MovementTests/menus/scenes/overlaid_menus/InventoryUi.cs
Minimata bed1384dc7
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 57s
Create tag and build when new code gets to main / Export (push) Successful in 5m13s
fixed inventory + using Sync bindings
2026-05-04 10:19:00 +02:00

121 lines
5.0 KiB
C#

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<InventoryManager>();
#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<ForgeAbilityBehavior>.Binding StartedFlyingBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.Binding FlyingTickBinding { get; set; }
public AutoSet<ForgeAbilityBehavior>.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, AbilitySelection>
{
{ WeaponSystem.WeaponEvent.StartedFlying, StartedFlying },
{ WeaponSystem.WeaponEvent.StoppedFlying, StoppedFlying },
{ WeaponSystem.WeaponEvent.FlyingTick, WhileFlying },
};
return abilitiesSelectionsMap[forEvent];
}
}