fixed inventory + using Sync bindings
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

This commit is contained in:
2026-05-04 10:19:00 +02:00
parent 99f383be00
commit bed1384dc7
13 changed files with 258 additions and 124 deletions

View File

@@ -90,4 +90,12 @@ public partial class AbilitySelection : Control
return;
}
}
public void ClearAbilities()
{
foreach (var child in SelectedAbilities.GetChildren())
{
SelectedAbilities.RemoveChild(child);
}
}
}

View File

@@ -1,6 +1,8 @@
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;
@@ -9,7 +11,7 @@ using Movementtests.systems;
[Tool, GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_crate.png"), Meta(typeof(IAutoNode))]
public partial class InventoryUi : Control
public partial class InventoryUi : Control, IDisposable
{
public override void _Notification(int what) => this.Notify(what);
@@ -27,6 +29,10 @@ public partial class InventoryUi : Control
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;
@@ -44,16 +50,34 @@ public partial class InventoryUi : Control
WhileFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.FlyingTick]);
StoppedFlying.Initialize(InventoryManager.WeaponEventsInventory[WeaponSystem.WeaponEvent.StoppedFlying]);
InventoryManager.WeaponEventAbilityAdded += OnWeaponEventInventoryAdded;
InventoryManager.WeaponEventAbilityRemoved += OnWeaponEventInventoryRemoved;
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 void OnExitTree()
public new void Dispose()
{
InventoryManager.WeaponEventAbilityAdded -= OnWeaponEventInventoryAdded;
InventoryManager.WeaponEventAbilityRemoved -= OnWeaponEventInventoryRemoved;
GC.SuppressFinalize(this);
StartedFlying.Dispose();
WhileFlying.Dispose();
StoppedFlying.Dispose();
base.Dispose();
}
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
InventoryManager.AddAbilityForWeaponEvent(forEvent, abilityBehavior);
@@ -64,16 +88,22 @@ public partial class InventoryUi : Control
InventoryManager.RemoveAbilityForWeaponEvent(forEvent, abilityBehavior);
}
public void OnWeaponEventInventoryAdded(WeaponEventAbilityData data)
public void OnWeaponEventInventoryAdded(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var selection = GetAbilitySelection(data.ForEvent);
selection.AddSelectedAbility(data.Ability);
var selection = GetAbilitySelection(forEvent);
selection.AddSelectedAbility(abilityBehavior);
}
public void OnWeaponEventInventoryRemoved(WeaponEventAbilityData data)
public void OnWeaponEventInventoryRemoved(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
{
var selection = GetAbilitySelection(data.ForEvent);
selection.RemoveSelectedAbility(data.Ability);
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)

View File

@@ -8,5 +8,8 @@ extends OverlaidMenu
func _ready() -> void:
if Engine.is_editor_hint(): return
func _handle_cancel_input() -> void:
hide_menu()
func _on_close_button_pressed() -> void:
close()
hide_menu()