Inventory management of granted abilities
This commit is contained in:
@@ -1,55 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Godot;
|
||||
using Movementtests.systems;
|
||||
|
||||
[Tool, GlobalClass]
|
||||
public partial class AbilitySelection : Control
|
||||
{
|
||||
[Signal] public delegate void AbilityAddedEventHandler(WeaponSystem.WeaponEvent forEvent, string abilityName);
|
||||
[Signal] public delegate void AbilityAddedEventHandler(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior behavior);
|
||||
[Signal] public delegate void AbilityRemovedEventHandler(WeaponSystem.WeaponEvent forEvent, ForgeAbilityBehavior behavior);
|
||||
|
||||
[Export] public WeaponSystem.WeaponEvent ForEvent { get; set; } = WeaponSystem.WeaponEvent.StartedFlying;
|
||||
|
||||
private string _title = string.Empty;
|
||||
[Export] public string Title {
|
||||
get => _title;
|
||||
set
|
||||
{
|
||||
_title = value;
|
||||
TitleChanged();
|
||||
}
|
||||
}
|
||||
[Export] public string Title { get; set; } = string.Empty;
|
||||
|
||||
[Export] public PackedScene AbilitySelectionItem { get; set; }
|
||||
[Export] public PackedScene AbilitySelectedItem { get; set; }
|
||||
|
||||
[Export] public ForgeAbilityBehavior[] AbilityBehaviors { get; set; }
|
||||
|
||||
private VBoxContainer _abilities;
|
||||
private VBoxContainer _selectedAbilities;
|
||||
private MenuButton _addAbility;
|
||||
private PopupMenu _addAbilityMenu;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_abilities = GetNode<VBoxContainer>("%SelectedAbilities");
|
||||
var titleLabel = GetNode<Label>("%TitleLabel");
|
||||
titleLabel.Text = Title;
|
||||
|
||||
_selectedAbilities = GetNode<VBoxContainer>("%SelectedAbilities");
|
||||
_addAbility = GetNode<MenuButton>("%AddAbility");
|
||||
_addAbilityMenu = _addAbility.GetPopup();
|
||||
|
||||
_addAbilityMenu.IdPressed += AddAbilityMenuOnIdPressed;
|
||||
if (Engine.IsEditorHint()) return;
|
||||
|
||||
var i = 0;
|
||||
foreach (var behavior in AbilityBehaviors)
|
||||
{
|
||||
_addAbilityMenu.AddIconItem(behavior.Icon, behavior.Name);
|
||||
_addAbilityMenu.SetItemMetadata(i, behavior);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
_addAbilityMenu.IndexPressed += AddAbilityMenuOnIndexPressed;
|
||||
}
|
||||
|
||||
public void Initialize(IEnumerable<Resource> equippedAbilities)
|
||||
{
|
||||
foreach (var equippedAbility in equippedAbilities)
|
||||
{
|
||||
if (equippedAbility is not ForgeAbilityBehavior ability) continue;
|
||||
AddSelectedAbility(ability);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAbilityMenuOnIndexPressed(long index)
|
||||
{
|
||||
var indexInt = Convert.ToInt32(index);
|
||||
var metadata = _addAbilityMenu.GetItemMetadata(indexInt);
|
||||
var name = _addAbilityMenu.GetItemText(indexInt);
|
||||
EmitSignalAbilityAdded(ForEvent, name);
|
||||
var metadata = (ForgeAbilityBehavior) _addAbilityMenu.GetItemMetadata(indexInt);
|
||||
EmitSignalAbilityAdded(ForEvent, metadata);
|
||||
}
|
||||
|
||||
private void AddAbilityMenuOnIdPressed(long id)
|
||||
public void AddSelectedAbility(ForgeAbilityBehavior behavior)
|
||||
{
|
||||
var newSelectedAbilityItem = AbilitySelectedItem.Instantiate() as SelectedAbility;
|
||||
if (newSelectedAbilityItem == null) return;
|
||||
|
||||
newSelectedAbilityItem.SetAbility(behavior);
|
||||
newSelectedAbilityItem.AbilityRemoved += ability => EmitSignalAbilityRemoved(ForEvent, ability);
|
||||
_selectedAbilities.AddChild(newSelectedAbilityItem);
|
||||
}
|
||||
|
||||
public void TitleChanged()
|
||||
|
||||
public void RemoveSelectedAbility(ForgeAbilityBehavior behavior)
|
||||
{
|
||||
var titleLabel = GetNode<Label>("%TitleLabel");
|
||||
titleLabel.Text = Title;
|
||||
foreach (var child in _selectedAbilities.GetChildren())
|
||||
{
|
||||
if (child is not SelectedAbility selectedAbility || selectedAbility.Ability != behavior) continue;
|
||||
_selectedAbilities.RemoveChild(selectedAbility);
|
||||
_addAbility.GrabFocus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
menus/scenes/components/SelectedAbility.cs
Normal file
56
menus/scenes/components/SelectedAbility.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
|
||||
[Tool, GlobalClass]
|
||||
public partial class SelectedAbility : Control
|
||||
{
|
||||
[Signal] public delegate void AbilityRemovedEventHandler(ForgeAbilityBehavior ability);
|
||||
|
||||
private ForgeAbilityBehavior? _ability;
|
||||
[Export]
|
||||
public ForgeAbilityBehavior? Ability
|
||||
{
|
||||
get => _ability;
|
||||
set
|
||||
{
|
||||
_ability = value;
|
||||
if (_ability == null || !Engine.IsEditorHint()) return;
|
||||
AbilityUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
private TextureRect? _icon;
|
||||
private Label? _title;
|
||||
private Button? _remove;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_icon = GetNode<TextureRect>("%Icon");
|
||||
_title = GetNode<Label>("%Title");
|
||||
_remove = GetNode<Button>("%Remove");
|
||||
|
||||
_remove.Pressed += () => EmitSignalAbilityRemoved(Ability);
|
||||
}
|
||||
|
||||
public void SetAbility(ForgeAbilityBehavior ability)
|
||||
{
|
||||
_ability = ability;
|
||||
AbilityUpdated();
|
||||
}
|
||||
|
||||
public void AbilityUpdated()
|
||||
{
|
||||
var icon = _icon ?? GetNode<TextureRect>("%Icon");
|
||||
var title = _title ?? GetNode<Label>("%Title");
|
||||
if (icon == null || title == null) return;
|
||||
if (_ability == null)
|
||||
{
|
||||
icon.Texture = null;
|
||||
title.Text = "";
|
||||
return;
|
||||
}
|
||||
icon.Texture = _ability.Icon;
|
||||
title.Text = _ability.Name;
|
||||
}
|
||||
}
|
||||
1
menus/scenes/components/SelectedAbility.cs.uid
Normal file
1
menus/scenes/components/SelectedAbility.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://duest06l5answ
|
||||
@@ -1,8 +1,9 @@
|
||||
[gd_scene format=3 uid="uid://dmv685sskgh3l"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://5emed8iegtui" path="res://menus/scenes/components/AbilitySelection.cs" id="1_fcxyu"]
|
||||
[ext_resource type="Resource" uid="uid://ifeavnlps7hy" path="res://scenes/player_controller/resources/forge/exploding_sword.tres" id="2_j1yif"]
|
||||
[ext_resource type="Texture2D" uid="uid://by5v33lu8v1fm" path="res://assets/ui/input-prompts/Flairs/Vector/flair_plus.svg" id="2_uf3m5"]
|
||||
[ext_resource type="Texture2D" uid="uid://c2akxlg7tdb67" path="res://assets/ui/IconGodotNode/node/icon_projectile.png" id="3_41pdy"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjnimmo2jyvx7" path="res://menus/scenes/components/selected_ability.tscn" id="3_cndde"]
|
||||
|
||||
[node name="AbilitySelection" type="MarginContainer" unique_id=1373426933]
|
||||
size_flags_horizontal = 3
|
||||
@@ -11,6 +12,9 @@ theme_override_constants/margin_top = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
theme_override_constants/margin_bottom = 4
|
||||
script = ExtResource("1_fcxyu")
|
||||
Title = "Test"
|
||||
AbilitySelectedItem = ExtResource("3_cndde")
|
||||
AbilityBehaviors = [ExtResource("2_j1yif")]
|
||||
|
||||
[node name="HBoxContainer" type="VBoxContainer" parent="." unique_id=364343452]
|
||||
layout_mode = 2
|
||||
@@ -18,6 +22,7 @@ layout_mode = 2
|
||||
[node name="TitleLabel" type="Label" parent="HBoxContainer" unique_id=8350369]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Test"
|
||||
|
||||
[node name="SelectedAbilities" type="VBoxContainer" parent="HBoxContainer" unique_id=1173689490]
|
||||
unique_name_in_owner = true
|
||||
@@ -39,7 +44,3 @@ layout_mode = 2
|
||||
focus_mode = 2
|
||||
text = "Add ability"
|
||||
icon = ExtResource("2_uf3m5")
|
||||
item_count = 1
|
||||
popup/item_0/text = "Weapon explosion"
|
||||
popup/item_0/icon = ExtResource("3_41pdy")
|
||||
popup/item_0/id = 0
|
||||
|
||||
30
menus/scenes/components/selected_ability.tscn
Normal file
30
menus/scenes/components/selected_ability.tscn
Normal file
@@ -0,0 +1,30 @@
|
||||
[gd_scene format=3 uid="uid://cjnimmo2jyvx7"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://duest06l5answ" path="res://menus/scenes/components/SelectedAbility.cs" id="1_dc51o"]
|
||||
[ext_resource type="Resource" uid="uid://ifeavnlps7hy" path="res://scenes/player_controller/resources/forge/exploding_sword.tres" id="2_um64s"]
|
||||
[ext_resource type="Texture2D" uid="uid://b3403ry3yxw1t" path="res://assets/ui/input-prompts/Flairs/Vector/flair_cross.svg" id="4_x7nho"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2nvj1"]
|
||||
atlas = ExtResource("4_x7nho")
|
||||
region = Rect2(20, 20, 24, 24)
|
||||
|
||||
[node name="SelectedAbility" type="PanelContainer" unique_id=931414010]
|
||||
script = ExtResource("1_dc51o")
|
||||
Ability = ExtResource("2_um64s")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=489712453]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Icon" type="TextureRect" parent="HBoxContainer" unique_id=1615158957]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
stretch_mode = 3
|
||||
|
||||
[node name="Title" type="Label" parent="HBoxContainer" unique_id=809638027]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Remove" type="Button" parent="HBoxContainer" unique_id=1761723956]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
icon = SubResource("AtlasTexture_2nvj1")
|
||||
@@ -37,6 +37,7 @@ option_name = "Joystick Sensitivity"
|
||||
option_section = 1
|
||||
key = "LookSensitivity"
|
||||
section = "InputSettings"
|
||||
default_value = 1.1
|
||||
|
||||
[node name="OptionLabel" parent="VBoxContainer/MarginContainer/VBoxContainer/LookSensitivityControl" index="0" unique_id=1789907427]
|
||||
text = "Joystick Sensitivity :"
|
||||
@@ -44,8 +45,8 @@ text = "Joystick Sensitivity :"
|
||||
[node name="HSlider" parent="VBoxContainer/MarginContainer/VBoxContainer/LookSensitivityControl" index="1" unique_id=494926010]
|
||||
min_value = 0.2
|
||||
max_value = 2.0
|
||||
step = 0.2
|
||||
value = 0.6000000000000001
|
||||
step = 0.1
|
||||
value = 1.1
|
||||
tick_count = 10
|
||||
|
||||
[node name="MouseSensitivityControl" parent="VBoxContainer/MarginContainer/VBoxContainer" unique_id=1444662884 instance=ExtResource("2_iyvrj")]
|
||||
@@ -54,16 +55,17 @@ option_name = "Mouse Sensitivity"
|
||||
option_section = 1
|
||||
key = "MouseSensitivity"
|
||||
section = "InputSettings"
|
||||
default_value = 25.0
|
||||
|
||||
[node name="OptionLabel" parent="VBoxContainer/MarginContainer/VBoxContainer/MouseSensitivityControl" index="0" unique_id=1789907427]
|
||||
text = "Mouse Sensitivity :"
|
||||
|
||||
[node name="HSlider" parent="VBoxContainer/MarginContainer/VBoxContainer/MouseSensitivityControl" index="1" unique_id=494926010]
|
||||
min_value = 1.0
|
||||
max_value = 20.0
|
||||
max_value = 50.0
|
||||
step = 1.0
|
||||
value = 8.0
|
||||
tick_count = 20
|
||||
value = 25.0
|
||||
tick_count = 10
|
||||
|
||||
[node name="HeadBobbingControl" parent="VBoxContainer/MarginContainer/VBoxContainer" unique_id=1905029466 instance=ExtResource("2_iyvrj")]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://7yil0fiftvaf
|
||||
81
menus/scenes/overlaid_menus/InventoryUi.cs
Normal file
81
menus/scenes/overlaid_menus/InventoryUi.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
1
menus/scenes/overlaid_menus/InventoryUi.cs.uid
Normal file
1
menus/scenes/overlaid_menus/InventoryUi.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cvwiftuay8jep
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user