Fix inventory menu, add armor as equippable item
This commit is contained in:
7
src/inventory_menu/EquippedInventoryLabelSettings.tres
Normal file
7
src/inventory_menu/EquippedInventoryLabelSettings.tres
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://kpdmgv5ktypo"]
|
||||
|
||||
[sub_resource type="SystemFont" id="SystemFont_w2gvn"]
|
||||
|
||||
[resource]
|
||||
font = SubResource("SystemFont_w2gvn")
|
||||
font_color = Color(0, 0, 1, 1)
|
||||
6
src/inventory_menu/InventoryLabelSettings.tres
Normal file
6
src/inventory_menu/InventoryLabelSettings.tres
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://bl5xpqyq8vjtv"]
|
||||
|
||||
[sub_resource type="SystemFont" id="SystemFont_1ibjc"]
|
||||
|
||||
[resource]
|
||||
font = SubResource("SystemFont_1ibjc")
|
||||
@@ -29,7 +29,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var label = new WeaponLabel(item) { Text = item.Name };
|
||||
var label = new ItemLabel(item) { Text = item.Name };
|
||||
ItemList.AddChild(label);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,15 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
if (ItemList.GetChildCount() > 0)
|
||||
{
|
||||
var currentItem = ItemList.GetChild<Control>(_currentSelection);
|
||||
var currentItem = ItemList.GetChild<ItemLabel>(_currentSelection);
|
||||
SetCursorLocation(currentItem);
|
||||
}
|
||||
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem == GameRepo.EquippedWeapon || item.InventoryItem == GameRepo.EquippedArmor)
|
||||
item.EquipItem();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearItems()
|
||||
@@ -86,11 +92,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
}
|
||||
}
|
||||
|
||||
private void UnequipItem(WeaponLabel item)
|
||||
{
|
||||
item.UnequipItem();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var input = Vector2.Zero;
|
||||
@@ -98,12 +99,67 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
SetCursorToPrevious();
|
||||
if (Input.IsActionJustPressed(GameInputs.MoveDown))
|
||||
SetCursorToNext();
|
||||
if (Input.IsActionJustPressed(GameInputs.Attack))
|
||||
EquipOrUnequipCurrentItem();
|
||||
}
|
||||
|
||||
public void EquipOrUnequipCurrentItem()
|
||||
{
|
||||
if (ItemList.GetChildCount() == 0)
|
||||
return;
|
||||
|
||||
var currentlySelectedItem = ItemList.GetChild<ItemLabel>(_currentSelection);
|
||||
|
||||
if (currentlySelectedItem.InventoryItem is WeaponInfo weapon && GameRepo.EquippedWeapon == weapon)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnWeaponEquipped(WeaponInfo.Default);
|
||||
}
|
||||
else if (currentlySelectedItem.InventoryItem is ArmorInfo armor && GameRepo.EquippedArmor == armor)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnArmorEquipped(null);
|
||||
}
|
||||
else
|
||||
EquipItem(currentlySelectedItem);
|
||||
}
|
||||
|
||||
private void EquipItem(ItemLabel currentItem)
|
||||
{
|
||||
if (currentItem.InventoryItem is WeaponInfo weaponInfo)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is WeaponInfo)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnWeaponEquipped(weaponInfo);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
|
||||
if (currentItem.InventoryItem is ArmorInfo armorInfo)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is ArmorInfo)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnArmorEquipped(armorInfo);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
}
|
||||
|
||||
private void UnequipItem(ItemLabel item)
|
||||
{
|
||||
item.UnequipItem();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class WeaponLabel : Label
|
||||
public partial class ItemLabel : Label
|
||||
{
|
||||
public WeaponLabel(InventoryItemInfo inventoryItem)
|
||||
public ItemLabel(InventoryItemInfo inventoryItem)
|
||||
{
|
||||
InventoryItem = inventoryItem;
|
||||
LabelSettings = UnequippedItemFont;
|
||||
@@ -111,8 +167,8 @@ public partial class WeaponLabel : Label
|
||||
|
||||
public InventoryItemInfo InventoryItem { get; set; } = default!;
|
||||
|
||||
private static LabelSettings UnequippedItemFont => GD.Load<LabelSettings>("res://src/vfx/Fonts/InventoryLabelSettings.tres");
|
||||
private static LabelSettings EquippedItemFont => GD.Load<LabelSettings>("res://src/vfx/Fonts/EquippedInventoryLabelSettings.tres");
|
||||
private static LabelSettings UnequippedItemFont => GD.Load<LabelSettings>("res://src/inventory_menu/InventoryLabelSettings.tres");
|
||||
private static LabelSettings EquippedItemFont => GD.Load<LabelSettings>("res://src/inventory_menu/EquippedInventoryLabelSettings.tres");
|
||||
|
||||
public void EquipItem()
|
||||
{
|
||||
|
||||
@@ -14,13 +14,17 @@ size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_l64wl")
|
||||
|
||||
[node name="CenterContainer" type="CenterContainer" parent="."]
|
||||
[node name="CenterContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_constants/margin_left = 80
|
||||
theme_override_constants/margin_top = 80
|
||||
theme_override_constants/margin_right = 80
|
||||
theme_override_constants/margin_bottom = 80
|
||||
|
||||
[node name="ItemList" type="VBoxContainer" parent="CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
@@ -34,12 +38,3 @@ offset_top = -47.0
|
||||
offset_right = -48.0
|
||||
offset_bottom = -7.0
|
||||
texture = ExtResource("1_efrp8")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
Reference in New Issue
Block a user