Inventory management of granted abilities

This commit is contained in:
2026-04-21 11:38:04 +02:00
parent 667d6b2588
commit b0fe2549ea
18 changed files with 322 additions and 92 deletions

View File

@@ -1,26 +0,0 @@
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<AbilitySelection>("%StartedFlying");
_whileFlyingSelection = GetNode<AbilitySelection>("%WhileFlying");
_stoppedFlyingSelection = GetNode<AbilitySelection>("%StoppedFlying");
_startedFlyingSelection.AbilityAdded += AddAbilityForEvent;
_whileFlyingSelection.AbilityAdded += AddAbilityForEvent;
_stoppedFlyingSelection.AbilityAdded += AddAbilityForEvent;
}
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, string abilityName)
{
InventoryManager.Instance.AddAbilityForWeaponEvent(forEvent, abilityName);
}
}

View File

@@ -1 +0,0 @@
uid://7yil0fiftvaf

View File

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

View File

@@ -0,0 +1 @@
uid://cvwiftuay8jep

View File

@@ -2,7 +2,7 @@
[ext_resource type="Script" uid="uid://vu5kh5amnta" path="res://menus/scenes/overlaid_menus/inventory_wrapper.gd" id="1_yst23"]
[ext_resource type="Script" uid="uid://1nf36h0gms3q" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="2_ijoei"]
[ext_resource type="Script" uid="uid://7yil0fiftvaf" path="res://menus/scenes/overlaid_menus/Inventory.cs" id="2_sb1gh"]
[ext_resource type="Script" uid="uid://cvwiftuay8jep" path="res://menus/scenes/overlaid_menus/InventoryUi.cs" id="2_sb1gh"]
[ext_resource type="PackedScene" uid="uid://dmv685sskgh3l" path="res://menus/scenes/components/ability_selection.tscn" id="3_ijoei"]
[node name="InventoryWrapper" type="Control" unique_id=1853168495]