Starting an inventory manager
This commit is contained in:
36
managers/InventoryManager.cs
Normal file
36
managers/InventoryManager.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Godot;
|
||||||
|
using Movementtests.systems;
|
||||||
|
|
||||||
|
namespace Movementtests.managers;
|
||||||
|
|
||||||
|
public partial class WeaponEventInventoryChangedData(WeaponSystem.WeaponEvent forEvent, string abilityName)
|
||||||
|
: RefCounted
|
||||||
|
{
|
||||||
|
public WeaponSystem.WeaponEvent ForEvent { get; private set; } = forEvent;
|
||||||
|
public string Ability { get; private set; } = abilityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class InventoryManager : Node
|
||||||
|
{
|
||||||
|
[Signal]
|
||||||
|
public delegate void InventoryChangedEventHandler();
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
public delegate void WeaponEventInventoryChangedEventHandler(WeaponEventInventoryChangedData data);
|
||||||
|
|
||||||
|
public Dictionary<string, Resource> Inventory { get; } = new();
|
||||||
|
|
||||||
|
public static InventoryManager Instance { get; private set; }
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddAbilityForWeaponEvent(WeaponSystem.WeaponEvent forEvent, string abilityName)
|
||||||
|
{
|
||||||
|
EmitSignalWeaponEventInventoryChanged(new WeaponEventInventoryChangedData(forEvent, abilityName));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
managers/InventoryManager.cs.uid
Normal file
1
managers/InventoryManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://cgwhrwfqsiing
|
||||||
@@ -343,7 +343,7 @@ transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, -7.25, 20.5, -27.5)
|
|||||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.3647223, 23.75, -13.75)
|
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.3647223, 23.75, -13.75)
|
||||||
|
|
||||||
[node name="Enemy28" parent="Tutorial" index="2" unique_id=1765389924 node_paths=PackedStringArray("Target") instance=ExtResource("7_egib5")]
|
[node name="Enemy28" parent="Tutorial" index="2" unique_id=1765389924 node_paths=PackedStringArray("Target") instance=ExtResource("7_egib5")]
|
||||||
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -5, 22, 16.5)
|
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -5, 22, 15.5)
|
||||||
Target = NodePath("../../Player")
|
Target = NodePath("../../Player")
|
||||||
RHealth = SubResource("Resource_invhv")
|
RHealth = SubResource("Resource_invhv")
|
||||||
RDamage = SubResource("Resource_cgfmf")
|
RDamage = SubResource("Resource_cgfmf")
|
||||||
@@ -520,15 +520,15 @@ size = Vector3(1, 1, 4.75)
|
|||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="CSGBox3D137" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="10" unique_id=1930091014]
|
[node name="CSGBox3D137" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="10" unique_id=1930091014]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 22.5, 58)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 22.5, 57.5)
|
||||||
use_collision = true
|
use_collision = true
|
||||||
size = Vector3(1, 1, 11)
|
size = Vector3(1, 1, 12)
|
||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="CSGBox3D138" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="11" unique_id=1299444131]
|
[node name="CSGBox3D138" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="11" unique_id=1299444131]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 22.5, 58)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 22.5, 57.5)
|
||||||
use_collision = true
|
use_collision = true
|
||||||
size = Vector3(1, 1, 11)
|
size = Vector3(1, 1, 12)
|
||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="CSGBox3D139" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="12" unique_id=1708119368]
|
[node name="CSGBox3D139" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="12" unique_id=1708119368]
|
||||||
@@ -628,9 +628,9 @@ size = Vector3(9.5, 5, 11.75)
|
|||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="CSGBox3D133" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="28" unique_id=672467040]
|
[node name="CSGBox3D133" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="28" unique_id=672467040]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 21.487345, 58)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4, 21.487345, 57.5)
|
||||||
use_collision = true
|
use_collision = true
|
||||||
size = Vector3(5, 1, 11)
|
size = Vector3(5, 1, 12)
|
||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="CSGBox3D141" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="29" unique_id=1207463075]
|
[node name="CSGBox3D141" type="CSGBox3D" parent="Tutorial/DashWithMantle" index="29" unique_id=1207463075]
|
||||||
@@ -765,10 +765,10 @@ use_collision = true
|
|||||||
size = Vector3(2, 3.25, 1)
|
size = Vector3(2, 3.25, 1)
|
||||||
material = ExtResource("3_4m8g1")
|
material = ExtResource("3_4m8g1")
|
||||||
|
|
||||||
[node name="Player" parent="." index="9" unique_id=1309399929]
|
[node name="Player" parent="." index="10" unique_id=1309399929]
|
||||||
transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, -0.5, 0, 0)
|
transform = Transform3D(0.99999994, 0, 0, 0, 1, 0, 0, 0, 0.99999994, -0.5, 0, 0)
|
||||||
|
|
||||||
[node name="PlayerFellRespawn" parent="." index="10" unique_id=479136076]
|
[node name="PlayerFellRespawn" parent="." index="11" unique_id=479136076]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.5, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.5, 0)
|
||||||
|
|
||||||
[node name="OmniLight3D" type="OmniLight3D" parent="." index="13" unique_id=702421172]
|
[node name="OmniLight3D" type="OmniLight3D" parent="." index="13" unique_id=702421172]
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Movementtests.managers;
|
||||||
using Movementtests.systems;
|
using Movementtests.systems;
|
||||||
|
|
||||||
[Tool, GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_crate.png")]
|
[Tool, GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_crate.png")]
|
||||||
public partial class Inventory : Control
|
public partial class InventoryUI : Control
|
||||||
{
|
{
|
||||||
public PlayerController? Player { get; set; }
|
|
||||||
|
|
||||||
private AbilitySelection _startedFlyingSelection;
|
private AbilitySelection _startedFlyingSelection;
|
||||||
private AbilitySelection _whileFlyingSelection;
|
private AbilitySelection _whileFlyingSelection;
|
||||||
private AbilitySelection _stoppedFlyingSelection;
|
private AbilitySelection _stoppedFlyingSelection;
|
||||||
@@ -22,7 +21,6 @@ public partial class Inventory : Control
|
|||||||
|
|
||||||
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, string abilityName)
|
public void AddAbilityForEvent(WeaponSystem.WeaponEvent forEvent, string abilityName)
|
||||||
{
|
{
|
||||||
if (Player is null) return;
|
InventoryManager.Instance.AddAbilityForWeaponEvent(forEvent, abilityName);
|
||||||
Player.GrantWeaponExplosionAbilityForEvent(forEvent, abilityName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,10 @@
|
|||||||
class_name InventoryWrapper
|
class_name InventoryWrapper
|
||||||
extends OverlaidMenu
|
extends OverlaidMenu
|
||||||
|
|
||||||
@export var player: PlayerController
|
|
||||||
|
|
||||||
@onready var inventory: Control = %Inventory
|
@onready var inventory: Control = %Inventory
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if Engine.is_editor_hint(): return
|
if Engine.is_editor_hint(): return
|
||||||
inventory.Player = player
|
|
||||||
|
|
||||||
func _on_close_button_pressed() -> void:
|
func _on_close_button_pressed() -> void:
|
||||||
close()
|
close()
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ Shaker="*uid://c7flmumgr5w3u"
|
|||||||
CsgToolkitAutoload="*uid://w8ad8q4lneis"
|
CsgToolkitAutoload="*uid://w8ad8q4lneis"
|
||||||
"Forge Bootstrap"="*uid://ba8fquhtwu5mu"
|
"Forge Bootstrap"="*uid://ba8fquhtwu5mu"
|
||||||
GlobalHelpers="*uid://dqcm83o8e66a2"
|
GlobalHelpers="*uid://dqcm83o8e66a2"
|
||||||
|
InventoryManager="*uid://cgwhrwfqsiing"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ using Movementtests.player_controller.Scripts;
|
|||||||
using Movementtests.scenes.player_controller.scripts;
|
using Movementtests.scenes.player_controller.scripts;
|
||||||
using Movementtests.tools;
|
using Movementtests.tools;
|
||||||
using Movementtests.forge.abilities;
|
using Movementtests.forge.abilities;
|
||||||
|
using Movementtests.managers;
|
||||||
using Movementtests.tools.calculators;
|
using Movementtests.tools.calculators;
|
||||||
using RustyOptions;
|
using RustyOptions;
|
||||||
using Node = Godot.Node;
|
using Node = Godot.Node;
|
||||||
@@ -715,6 +716,9 @@ public partial class PlayerController : CharacterBody3D,
|
|||||||
_parryStandard.StateEntered += OnStandardParryStarted;
|
_parryStandard.StateEntered += OnStandardParryStarted;
|
||||||
_parryDash.StateEntered += OnDashParryStarted;
|
_parryDash.StateEntered += OnDashParryStarted;
|
||||||
|
|
||||||
|
// Inventory Management
|
||||||
|
InventoryManager.Instance.WeaponEventInventoryChanged += OnWeaponEventInventoryChanged;
|
||||||
|
|
||||||
// Forge events
|
// Forge events
|
||||||
var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft);
|
var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft);
|
||||||
var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStoppedFlyingEventTag, OnWeaponLanded);
|
var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStoppedFlyingEventTag, OnWeaponLanded);
|
||||||
@@ -747,9 +751,9 @@ public partial class PlayerController : CharacterBody3D,
|
|||||||
out var failures);
|
out var failures);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GrantWeaponExplosionAbilityForEvent(WeaponSystem.WeaponEvent forEvent, string abilityName)
|
public void OnWeaponEventInventoryChanged(WeaponEventInventoryChangedData data)
|
||||||
{
|
{
|
||||||
WeaponSystem.GrantNewAbilityForEvent(forEvent, WeaponExplosionBehavior);
|
WeaponSystem.GrantNewAbilityForEvent(data.ForEvent, WeaponExplosionBehavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func open_toolbox() -> void:
|
|||||||
|
|
||||||
func open_inventory() -> void:
|
func open_inventory() -> void:
|
||||||
var inventory: Control = open_overlaid_menu(inventory_scene)
|
var inventory: Control = open_overlaid_menu(inventory_scene)
|
||||||
inventory.player = player
|
# inventory.player = player
|
||||||
inventory_layer.call_deferred("add_child", inventory)
|
inventory_layer.call_deferred("add_child", inventory)
|
||||||
|
|
||||||
func on_player_died() -> void:
|
func on_player_died() -> void:
|
||||||
|
|||||||
Reference in New Issue
Block a user