Split equipment status from Inventory, fix equip/unequip bonuses being reflected correctly in code and inventory menu
This commit is contained in:
@@ -9,7 +9,7 @@ namespace GameJamDungeon;
|
||||
|
||||
public interface IInventoryMenu : IControl
|
||||
{
|
||||
public Task RedrawInventory();
|
||||
public Task RefreshInventoryScreen();
|
||||
|
||||
public Task ShowMessage(string message);
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
[Dependency] private IGameRepo _gameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
@@ -91,9 +91,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
Player.Stats.CurrentExp.Sync += CurrentExp_Sync;
|
||||
Player.Stats.ExpToNextLevel.Sync += ExpToNextLevel_Sync;
|
||||
Player.Stats.CurrentLevel.Sync += CurrentLevel_Sync;
|
||||
Player.Inventory.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.Inventory.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.Inventory.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Player.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
|
||||
SetProcessInput(false);
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
await ShowInventoryInfo();
|
||||
ItemEffectLabel.Text = message;
|
||||
await ToSignal(GetTree().CreateTimer(1f), "timeout");
|
||||
await RedrawInventory();
|
||||
await RefreshInventoryScreen();
|
||||
SetProcessInput(true);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private void CurrentHP_Sync(int obj) => HPValue.Text = $"{obj}/{Player.Stats.MaximumHP.Value}";
|
||||
|
||||
public async Task RedrawInventory()
|
||||
public async Task RefreshInventoryScreen()
|
||||
{
|
||||
await ClearItems();
|
||||
PopulateInventory();
|
||||
@@ -223,7 +223,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
inventory.Sort();
|
||||
GameEventDepot.OnInventorySorted();
|
||||
RedrawInventory();
|
||||
RefreshInventoryScreen();
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
@@ -245,7 +245,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private void PopulatePlayerInfo()
|
||||
{
|
||||
FloorLabel.Text = $"Floor {GameRepo.CurrentFloor:D2}";
|
||||
FloorLabel.Text = $"Floor {_gameRepo.CurrentFloor:D2}";
|
||||
|
||||
if (ItemSlots.Any())
|
||||
{
|
||||
@@ -268,12 +268,12 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
if (currentItem is IEquipableItem equipable)
|
||||
{
|
||||
var isEquipped = Player.Inventory.IsEquipped(equipable);
|
||||
UseButton.Text = isEquipped ? "Unequip" : "Equip";
|
||||
ThrowButton.Disabled = isEquipped ? true : false;
|
||||
ThrowButton.FocusMode = isEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
DropButton.Disabled = isEquipped ? true : false;
|
||||
DropButton.FocusMode = isEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
;
|
||||
UseButton.Text = equipable.IsEquipped ? "Unequip" : "Equip";
|
||||
ThrowButton.Disabled = equipable.IsEquipped ? true : false;
|
||||
ThrowButton.FocusMode = equipable.IsEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
DropButton.Disabled = equipable.IsEquipped ? true : false;
|
||||
DropButton.FocusMode = equipable.IsEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -306,7 +306,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
_currentIndex = 0;
|
||||
_currentPageNumber = pageToChangeTo;
|
||||
await RedrawInventory();
|
||||
await RefreshInventoryScreen();
|
||||
GameEventDepot.OnMenuScrolled();
|
||||
}
|
||||
|
||||
@@ -339,14 +339,14 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
itemSlot.Item = item;
|
||||
ItemsPage.AddChildEx(itemSlot);
|
||||
|
||||
if (itemSlot.Item is IEquipableItem equipable && Player.Inventory.IsEquipped(equipable))
|
||||
if (itemSlot.Item is IEquipableItem equipable && equipable.IsEquipped)
|
||||
itemSlot.SetEquippedItemStyle();
|
||||
}
|
||||
|
||||
if (ItemSlots.Any())
|
||||
{
|
||||
ItemSlots.ElementAt(_currentIndex).SetSelectedItemStyle();
|
||||
if (ItemSlots.ElementAt(_currentIndex).Item is IEquipableItem equipable && Player.Inventory.IsEquipped(equipable))
|
||||
if (ItemSlots.ElementAt(_currentIndex).Item is IEquipableItem equipable && equipable.IsEquipped)
|
||||
ItemSlots.ElementAt(_currentIndex).SetEquippedSelectedItemStyle();
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
itemSlot.SetItemStyle();
|
||||
if (itemSlot.Item is IEquipableItem equipable && Player.Inventory.IsEquipped(equipable))
|
||||
if (itemSlot.Item is IEquipableItem equipable && equipable.IsEquipped)
|
||||
itemSlot.SetEquippedItemStyle();
|
||||
}
|
||||
|
||||
@@ -372,16 +372,16 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
var itemSlot = ItemSlots[_currentIndex];
|
||||
if (itemSlot.Item is IEquipableItem equipableItem)
|
||||
{
|
||||
if (Player.Inventory.IsEquipped(equipableItem))
|
||||
if (equipableItem.IsEquipped)
|
||||
{
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.GetType()} unequipped.";
|
||||
Player.Inventory.Unequip(equipableItem);
|
||||
Player.Unequip(equipableItem);
|
||||
itemSlot.SetSelectedItemStyle();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.GetType()} equipped.";
|
||||
Player.Inventory.Equip(equipableItem);
|
||||
Player.Equip(equipableItem);
|
||||
itemSlot.SetEquippedSelectedItemStyle();
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
SetProcessInput(false);
|
||||
await HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
await RedrawInventory();
|
||||
await RefreshInventoryScreen();
|
||||
await ToSignal(GetTree().CreateTimer(1f), "timeout");
|
||||
SetProcessInput(true);
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ public partial class ItemSlot : HBoxContainer, IItemSlot
|
||||
ItemName.Text = Item.ItemName;
|
||||
//EquipBonus.Text = "...";
|
||||
ItemTexture.Texture = Item.GetTexture();
|
||||
Player.Inventory.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.Inventory.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.Inventory.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Player.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Sync(Weapon obj)
|
||||
@@ -90,7 +90,7 @@ public partial class ItemSlot : HBoxContainer, IItemSlot
|
||||
}
|
||||
public void SetSelectedItemStyle()
|
||||
{
|
||||
if (Item is IEquipableItem equipableItem && Player.Inventory.IsEquipped(equipableItem))
|
||||
if (Item is IEquipableItem equipableItem && equipableItem.IsEquipped)
|
||||
{
|
||||
ItemName.LabelSettings = SelectedEquippedItemFont;
|
||||
//EquipBonus.LabelSettings = EquippedItemFont;
|
||||
|
||||
Reference in New Issue
Block a user