Add plastique item
Add Door object Initial work for look up animation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
@@ -62,144 +62,144 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
SetProcessInput(false);
|
||||
SetProcessInput(false);
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
ItemSlots = [ItemSlot1, ItemSlot2, ItemSlot3, ItemSlot4, ItemSlot5, ItemSlot6, ItemSlot7, ItemSlot8, ItemSlot9, ItemSlot10, ItemSlot11, ItemSlot12, ItemSlot13, ItemSlot14, ItemSlot15, ItemSlot16, ItemSlot17, ItemSlot18, ItemSlot19, ItemSlot20];
|
||||
_currentlySelectedItem = ItemSlot1;
|
||||
foreach (var item in ItemSlots)
|
||||
{
|
||||
item.ItemPressed += Item_Pressed;
|
||||
item.ItemEnterFocus += Item_FocusEntered;
|
||||
item.ItemExitFocus += Item_ItemExitFocus;
|
||||
}
|
||||
ItemSlots = [ItemSlot1, ItemSlot2, ItemSlot3, ItemSlot4, ItemSlot5, ItemSlot6, ItemSlot7, ItemSlot8, ItemSlot9, ItemSlot10, ItemSlot11, ItemSlot12, ItemSlot13, ItemSlot14, ItemSlot15, ItemSlot16, ItemSlot17, ItemSlot18, ItemSlot19, ItemSlot20];
|
||||
_currentlySelectedItem = ItemSlot1;
|
||||
foreach (var item in ItemSlots)
|
||||
{
|
||||
item.ItemPressed += Item_Pressed;
|
||||
item.ItemEnterFocus += Item_FocusEntered;
|
||||
item.ItemExitFocus += Item_ItemExitFocus;
|
||||
}
|
||||
|
||||
_player.AttackComponent.CurrentAttack.Sync += Attack_Sync;
|
||||
_player.AttackComponent.MaximumAttack.Sync += Attack_Sync;
|
||||
_player.DefenseComponent.CurrentDefense.Sync += Defense_Sync;
|
||||
_player.DefenseComponent.MaximumDefense.Sync += Defense_Sync;
|
||||
_player.EquipmentComponent.EquipmentChanged += EquipmentComponent_EquipmentChanged;
|
||||
_player.Inventory.InventoryChanged += Inventory_InventoryChanged;
|
||||
_player.AttackComponent.CurrentAttack.Sync += Attack_Sync;
|
||||
_player.AttackComponent.MaximumAttack.Sync += Attack_Sync;
|
||||
_player.DefenseComponent.CurrentDefense.Sync += Defense_Sync;
|
||||
_player.DefenseComponent.MaximumDefense.Sync += Defense_Sync;
|
||||
_player.EquipmentComponent.EquipmentChanged += EquipmentComponent_EquipmentChanged;
|
||||
_player.Inventory.InventoryChanged += Inventory_InventoryChanged;
|
||||
|
||||
UseButton.Pressed += UseButtonPressed;
|
||||
ThrowButton.Pressed += ThrowButtonPressed;
|
||||
DropButton.Pressed += DropButtonPressed;
|
||||
UseButton.Pressed += UseButtonPressed;
|
||||
ThrowButton.Pressed += ThrowButtonPressed;
|
||||
DropButton.Pressed += DropButtonPressed;
|
||||
|
||||
UseButton.FocusEntered += ActionButtonFocusChanged;
|
||||
ThrowButton.FocusEntered += ActionButtonFocusChanged;
|
||||
DropButton.FocusEntered += ActionButtonFocusChanged;
|
||||
UseButton.FocusEntered += ActionButtonFocusChanged;
|
||||
ThrowButton.FocusEntered += ActionButtonFocusChanged;
|
||||
DropButton.FocusEntered += ActionButtonFocusChanged;
|
||||
|
||||
VisibilityChanged += InventoryMenu_VisibilityChanged;
|
||||
VisibilityChanged += InventoryMenu_VisibilityChanged;
|
||||
}
|
||||
|
||||
private void ActionButtonFocusChanged()
|
||||
{
|
||||
if (!_enableMenuSound)
|
||||
SfxDatabase.Instance.Play(SoundEffect.MoveUI);
|
||||
if (!_enableMenuSound)
|
||||
SfxDatabase.Instance.Play(SoundEffect.MoveUI);
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (!Visible)
|
||||
return;
|
||||
if (!Visible)
|
||||
return;
|
||||
|
||||
if ((!Input.IsActionJustPressed(GameInputs.UiUp) && Input.IsActionPressed(GameInputs.UiUp)) || (!Input.IsActionJustPressed(GameInputs.UiDown) && Input.IsActionPressed(GameInputs.UiDown)))
|
||||
AcceptEvent();
|
||||
if ((!Input.IsActionJustPressed(GameInputs.UiUp) && Input.IsActionPressed(GameInputs.UiUp)) || (!Input.IsActionJustPressed(GameInputs.UiDown) && Input.IsActionPressed(GameInputs.UiDown)))
|
||||
AcceptEvent();
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiCancel) && (UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus()))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
AcceptEvent();
|
||||
HideUserActionPrompt();
|
||||
}
|
||||
else if (Input.IsActionJustPressed(GameInputs.UiCancel))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
AcceptEvent();
|
||||
_gameRepo.CloseInventory();
|
||||
}
|
||||
if (Input.IsActionJustPressed(GameInputs.UiCancel) && (UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus()))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
AcceptEvent();
|
||||
HideUserActionPrompt();
|
||||
}
|
||||
else if (Input.IsActionJustPressed(GameInputs.UiCancel))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
AcceptEvent();
|
||||
_gameRepo.CloseInventory();
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.InventorySort))
|
||||
{
|
||||
var isChanged = _player.Inventory.Sort(_player.EquipmentComponent.EquippedWeapon.Value, _player.EquipmentComponent.EquippedArmor.Value, _player.EquipmentComponent.EquippedAccessory.Value);
|
||||
if (!isChanged)
|
||||
return;
|
||||
if (Input.IsActionJustPressed(GameInputs.InventorySort))
|
||||
{
|
||||
var isChanged = _player.Inventory.Sort(_player.EquipmentComponent.EquippedWeapon.Value, _player.EquipmentComponent.EquippedArmor.Value, _player.EquipmentComponent.EquippedAccessory.Value);
|
||||
if (!isChanged)
|
||||
return;
|
||||
|
||||
SfxDatabase.Instance.Play(SoundEffect.SortInventory);
|
||||
Inventory_InventoryChanged();
|
||||
foreach (var slot in ItemSlots)
|
||||
slot.SetItemStyle();
|
||||
Item_ItemExitFocus(_currentlySelectedItem);
|
||||
_currentlySelectedItem = ItemSlot1;
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
}
|
||||
SfxDatabase.Instance.Play(SoundEffect.SortInventory);
|
||||
Inventory_InventoryChanged();
|
||||
foreach (var slot in ItemSlots)
|
||||
slot.SetItemStyle();
|
||||
Item_ItemExitFocus(_currentlySelectedItem);
|
||||
_currentlySelectedItem = ItemSlot1;
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
}
|
||||
}
|
||||
|
||||
private void InventoryMenu_VisibilityChanged()
|
||||
{
|
||||
if (Visible)
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.OpenInventory);
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
_enableMenuSound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
_enableMenuSound = false;
|
||||
}
|
||||
if (Visible)
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.OpenInventory);
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
_enableMenuSound = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.CancelUI);
|
||||
_enableMenuSound = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Item_ItemExitFocus(IItemSlot itemSlot)
|
||||
{
|
||||
ItemDescriptionTitle.Text = string.Empty;
|
||||
ItemEffectLabel.Text = string.Empty;
|
||||
itemSlot.IsSelected = false;
|
||||
itemSlot.SetItemStyle();
|
||||
ItemDescriptionTitle.Text = string.Empty;
|
||||
ItemEffectLabel.Text = string.Empty;
|
||||
itemSlot.IsSelected = false;
|
||||
itemSlot.SetItemStyle();
|
||||
}
|
||||
|
||||
private void Item_FocusEntered(IItemSlot itemSlot)
|
||||
{
|
||||
if (itemSlot.Item.Value == null)
|
||||
return;
|
||||
if (itemSlot.Item.Value == null)
|
||||
return;
|
||||
|
||||
if (_enableMenuSound)
|
||||
SfxDatabase.Instance.Play(SoundEffect.MoveUI);
|
||||
if (_enableMenuSound)
|
||||
SfxDatabase.Instance.Play(SoundEffect.MoveUI);
|
||||
|
||||
ItemDescriptionTitle.Text = $"{itemSlot.Item.Value.ItemName}";
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.Value.Description}";
|
||||
_currentlySelectedItem = itemSlot;
|
||||
itemSlot.IsSelected = true;
|
||||
itemSlot.SetItemStyle();
|
||||
AcceptEvent();
|
||||
ItemDescriptionTitle.Text = $"{itemSlot.Item.Value.ItemName}";
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.Value.Description}";
|
||||
_currentlySelectedItem = itemSlot;
|
||||
itemSlot.IsSelected = true;
|
||||
itemSlot.SetItemStyle();
|
||||
AcceptEvent();
|
||||
}
|
||||
|
||||
private void Item_Pressed(InventoryItem item) => DisplayUserActionPrompt(item);
|
||||
|
||||
private async void Inventory_InventoryChanged()
|
||||
{
|
||||
foreach (var slot in ItemSlots)
|
||||
{
|
||||
slot.Visible = false;
|
||||
slot.SetItemStyle();
|
||||
}
|
||||
foreach (var slot in ItemSlots)
|
||||
{
|
||||
slot.Visible = false;
|
||||
slot.SetItemStyle();
|
||||
}
|
||||
|
||||
var itemsToDisplay = _player.Inventory.Items;
|
||||
for (var i = 0; i < itemsToDisplay.Count; i++)
|
||||
{
|
||||
ItemSlots[i].Item.OnNext(itemsToDisplay[i]);
|
||||
ItemSlots[i].Visible = true;
|
||||
}
|
||||
var itemsToDisplay = _player.Inventory.Items;
|
||||
for (var i = 0; i < itemsToDisplay.Count; i++)
|
||||
{
|
||||
ItemSlots[i].Item.OnNext(itemsToDisplay[i]);
|
||||
ItemSlots[i].Visible = true;
|
||||
}
|
||||
|
||||
if (!_player.Inventory.Items.Contains(_currentlySelectedItem.Item.Value))
|
||||
{
|
||||
_currentlySelectedItem.Item.OnNext(null);
|
||||
var elementToSelect = Mathf.Max(0, ItemSlots.IndexOf(_currentlySelectedItem) - 1);
|
||||
_currentlySelectedItem = ItemSlots.ElementAt(elementToSelect);
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
}
|
||||
if (!_player.Inventory.Items.Contains(_currentlySelectedItem.Item.Value))
|
||||
{
|
||||
_currentlySelectedItem.Item.OnNext(null);
|
||||
var elementToSelect = Mathf.Max(0, ItemSlots.IndexOf(_currentlySelectedItem) - 1);
|
||||
_currentlySelectedItem = ItemSlots.ElementAt(elementToSelect);
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
}
|
||||
}
|
||||
|
||||
private void Attack_Sync(int obj) => ATKValue.Text = $"{_player.AttackComponent.CurrentAttack.Value}/{_player.AttackComponent.MaximumAttack.Value}";
|
||||
@@ -207,111 +207,125 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private void EquipmentComponent_EquipmentChanged(EquipableItem equipableItem)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{_player.EquipmentComponent.BonusAttack:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{_player.EquipmentComponent.BonusDefense:+0;-#;\\.\\.\\.}";
|
||||
ATKBonusLabel.Text = $"{_player.EquipmentComponent.BonusAttack:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{_player.EquipmentComponent.BonusDefense:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
|
||||
private async void UseButtonPressed()
|
||||
{
|
||||
UseButton.Disabled = true;
|
||||
if (_currentlySelectedItem.Item.Value is EquipableItem equipable)
|
||||
await EquipOrUnequipItem(equipable);
|
||||
else
|
||||
await _game.UseItem(_currentlySelectedItem.Item.Value);
|
||||
UseButton.Disabled = false;
|
||||
UseButton.Disabled = true;
|
||||
if (_currentlySelectedItem.Item.Value is EquipableItem equipable)
|
||||
await EquipOrUnequipItem(equipable);
|
||||
else if (_currentlySelectedItem.Item.Value is Plastique plastique)
|
||||
SetItem();
|
||||
else
|
||||
await _game.UseItem(_currentlySelectedItem.Item.Value);
|
||||
UseButton.Disabled = false;
|
||||
|
||||
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
await ToSignal(GetTree().CreateTimer(1f), "timeout");
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
await ToSignal(GetTree().CreateTimer(1f), "timeout");
|
||||
}
|
||||
|
||||
private async void SetItem()
|
||||
{
|
||||
_game.SetItem(_currentlySelectedItem.Item.Value);
|
||||
_player.Inventory.Remove(_currentlySelectedItem.Item.Value);
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
_gameRepo.CloseInventory();
|
||||
}
|
||||
|
||||
private async void ThrowButtonPressed()
|
||||
{
|
||||
_game.ThrowItem(_currentlySelectedItem.Item.Value);
|
||||
_player.Inventory.Remove(_currentlySelectedItem.Item.Value);
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
_gameRepo.CloseInventory();
|
||||
_game.ThrowItem(_currentlySelectedItem.Item.Value);
|
||||
_player.Inventory.Remove(_currentlySelectedItem.Item.Value);
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
_gameRepo.CloseInventory();
|
||||
}
|
||||
|
||||
private async void DropButtonPressed()
|
||||
{
|
||||
_game.DropItem(_currentlySelectedItem.Item.Value);
|
||||
_player.Inventory.Remove(_currentlySelectedItem.Item.Value);
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
_gameRepo.CloseInventory();
|
||||
_game.DropItem(_currentlySelectedItem.Item.Value);
|
||||
_player.Inventory.Remove(_currentlySelectedItem.Item.Value);
|
||||
HideUserActionPrompt();
|
||||
await ShowInventoryInfo();
|
||||
}
|
||||
|
||||
private void DisplayUserActionPrompt(InventoryItem item)
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.SelectUI);
|
||||
ItemDescriptionTitle.Hide();
|
||||
ItemEffectLabel.Hide();
|
||||
UseItemPrompt.Show();
|
||||
UseButton.Show();
|
||||
ThrowButton.Show();
|
||||
DropButton.Show();
|
||||
SfxDatabase.Instance.Play(SoundEffect.SelectUI);
|
||||
ItemDescriptionTitle.Hide();
|
||||
ItemEffectLabel.Hide();
|
||||
UseItemPrompt.Show();
|
||||
UseButton.Show();
|
||||
ThrowButton.Show();
|
||||
DropButton.Show();
|
||||
|
||||
if (item is EquipableItem equipable)
|
||||
{
|
||||
var isItemEquipped = _player.EquipmentComponent.IsItemEquipped(equipable);
|
||||
UseButton.Text = isItemEquipped ? "Unequip" : "Equip";
|
||||
ThrowButton.Disabled = isItemEquipped;
|
||||
ThrowButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
DropButton.Disabled = isItemEquipped;
|
||||
DropButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
else
|
||||
{
|
||||
UseButton.Text = "Use";
|
||||
}
|
||||
if (item is EquipableItem equipable)
|
||||
{
|
||||
var isItemEquipped = _player.EquipmentComponent.IsItemEquipped(equipable);
|
||||
UseButton.Text = isItemEquipped ? "Unequip" : "Equip";
|
||||
ThrowButton.Disabled = isItemEquipped;
|
||||
ThrowButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
DropButton.Disabled = isItemEquipped;
|
||||
DropButton.FocusMode = isItemEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
else if (item is Plastique plastique)
|
||||
{
|
||||
UseButton.Text = "Set";
|
||||
}
|
||||
else
|
||||
{
|
||||
UseButton.Text = "Use";
|
||||
}
|
||||
|
||||
UseButton.GrabFocus();
|
||||
_enableMenuSound = false;
|
||||
UseButton.GrabFocus();
|
||||
_enableMenuSound = false;
|
||||
}
|
||||
|
||||
private void HideUserActionPrompt()
|
||||
{
|
||||
UseItemPrompt.Hide();
|
||||
UseButton.Hide();
|
||||
ThrowButton.Hide();
|
||||
DropButton.Hide();
|
||||
UseButton.ReleaseFocus();
|
||||
ThrowButton.ReleaseFocus();
|
||||
DropButton.ReleaseFocus();
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
_enableMenuSound = true;
|
||||
UseItemPrompt.Hide();
|
||||
UseButton.Hide();
|
||||
ThrowButton.Hide();
|
||||
DropButton.Hide();
|
||||
UseButton.ReleaseFocus();
|
||||
ThrowButton.ReleaseFocus();
|
||||
DropButton.ReleaseFocus();
|
||||
_currentlySelectedItem.GrabFocus();
|
||||
_enableMenuSound = true;
|
||||
}
|
||||
|
||||
private async Task EquipOrUnequipItem(EquipableItem equipable)
|
||||
{
|
||||
if (_player.EquipmentComponent.IsItemEquipped(equipable))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.Unequip);
|
||||
ItemEffectLabel.Text = $"{equipable.GetType().Name} unequipped.";
|
||||
_player.Unequip(equipable);
|
||||
}
|
||||
else
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.Equip);
|
||||
var itemSlot = _currentlySelectedItem;
|
||||
ItemEffectLabel.Text = $"{equipable.GetType().Name} equipped.";
|
||||
_player.Equip(equipable);
|
||||
_currentlySelectedItem = itemSlot;
|
||||
}
|
||||
if (_player.EquipmentComponent.IsItemEquipped(equipable))
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.Unequip);
|
||||
ItemEffectLabel.Text = $"{equipable.GetType().Name} unequipped.";
|
||||
_player.Unequip(equipable);
|
||||
}
|
||||
else
|
||||
{
|
||||
SfxDatabase.Instance.Play(SoundEffect.Equip);
|
||||
var itemSlot = _currentlySelectedItem;
|
||||
ItemEffectLabel.Text = $"{equipable.GetType().Name} equipped.";
|
||||
_player.Equip(equipable);
|
||||
_currentlySelectedItem = itemSlot;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ShowInventoryInfo()
|
||||
{
|
||||
ItemDescriptionTitle.Show();
|
||||
ItemEffectLabel.Show();
|
||||
ItemDescriptionTitle.Show();
|
||||
ItemEffectLabel.Show();
|
||||
}
|
||||
|
||||
private enum InventoryPageNumber
|
||||
{
|
||||
FirstPage,
|
||||
SecondPage
|
||||
FirstPage,
|
||||
SecondPage
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user