Add more interactive effects to inventory menu
This commit is contained in:
@@ -4,6 +4,7 @@ using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface IInventoryMenu : IControl
|
||||
{
|
||||
@@ -20,6 +21,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
[Dependency]
|
||||
public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Dependency]
|
||||
public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
// Player Info
|
||||
[Node] public Label FloorLabel { get; set; } = default!;
|
||||
[Node] public Label CurrentLevelLabel { get; set; } = default!;
|
||||
@@ -43,12 +47,14 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
// User Prompt Menu
|
||||
[Node] public Label UseItemPrompt { get; set; } = default!;
|
||||
[Node] public Button UseButton { get; set; } = default!;
|
||||
[Node] public Button EquipButton { get; set; } = default!;
|
||||
[Node] public Button ThrowButton { get; set; } = default!;
|
||||
[Node] public Button DropButton { get; set; } = default!;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
EquipButton.Pressed += EquipButtonPressed;
|
||||
UseButton.Pressed += UseButtonPressed;
|
||||
ThrowButton.Pressed += ThrowButtonPressed;
|
||||
DropButton.Pressed += DropButtonPressed;
|
||||
}
|
||||
|
||||
private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage;
|
||||
@@ -127,30 +133,27 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
var inventory = GameRepo.InventoryItems.Value;
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage)
|
||||
if (@event.IsActionPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage)
|
||||
ChangeInventoryPage(InventoryPageNumber.SecondPage);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiLeft) && _currentPageNumber == InventoryPageNumber.SecondPage)
|
||||
if (@event.IsActionPressed(GameInputs.UiLeft) && _currentPageNumber == InventoryPageNumber.SecondPage)
|
||||
ChangeInventoryPage(InventoryPageNumber.FirstPage);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiDown))
|
||||
if (@event.IsActionPressed(GameInputs.UiDown))
|
||||
{
|
||||
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
_currentIndex = new[] { _currentIndex + 1, _itemsPerPage - 1, ItemSlots.Length - 1 }.Min();
|
||||
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiUp))
|
||||
if (@event.IsActionPressed(GameInputs.UiUp))
|
||||
{
|
||||
if (ItemSlots.Length == 0)
|
||||
return;
|
||||
|
||||
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
_currentIndex = new[] { _currentIndex - 1, 0 }.Max();
|
||||
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiAccept))
|
||||
if (@event.IsActionPressed(GameInputs.UiAccept))
|
||||
{
|
||||
if (ItemSlots.Length == 0 || GetViewport().GuiGetFocusOwner() is Button)
|
||||
return;
|
||||
@@ -164,42 +167,42 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
ItemEffectLabel.Hide();
|
||||
UseItemPrompt.Show();
|
||||
UseButton.Show();
|
||||
EquipButton.Show();
|
||||
EquipButton.Disabled = false;
|
||||
ThrowButton.Show();
|
||||
DropButton.Show();
|
||||
|
||||
var currentItem = ItemSlots.ElementAt(_currentIndex).Item;
|
||||
|
||||
if (currentItem is IEquipable equipable)
|
||||
{
|
||||
EquipButton.Disabled = false;
|
||||
EquipButton.FocusMode = FocusModeEnum.All;
|
||||
EquipButton.Text = GameRepo.IsItemEquipped(equipable) ? "Unequip" : "Equip";
|
||||
var isEquipped = GameRepo.IsItemEquipped(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;
|
||||
}
|
||||
else
|
||||
{
|
||||
EquipButton.Disabled = true;
|
||||
EquipButton.FocusMode = FocusModeEnum.None;
|
||||
UseButton.Text = "Use";
|
||||
}
|
||||
|
||||
UseButton.Text = currentItem is ThrowableItem ? "Throw" : "Use";
|
||||
|
||||
UseButton.GrabFocus();
|
||||
}
|
||||
|
||||
private void HideUserActionPrompt()
|
||||
private async Task HideUserActionPrompt()
|
||||
{
|
||||
ItemDescriptionTitle.Show();
|
||||
ItemEffectLabel.Show();
|
||||
UseItemPrompt.Hide();
|
||||
UseButton.Hide();
|
||||
EquipButton.Hide();
|
||||
ThrowButton.Hide();
|
||||
DropButton.Hide();
|
||||
}
|
||||
|
||||
private void ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
|
||||
private async void ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
|
||||
{
|
||||
ClearItems();
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
_currentIndex = 0;
|
||||
_currentPageNumber = pageToChangeTo;
|
||||
PopulateItems();
|
||||
@@ -246,15 +249,17 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
}
|
||||
}
|
||||
|
||||
private void SetToUnselectedStyle(IItemSlot itemSlot)
|
||||
private async void SetToUnselectedStyle(IItemSlot itemSlot)
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
itemSlot.SetItemStyle();
|
||||
if (itemSlot.Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
|
||||
itemSlot.SetEquippedItemStyle();
|
||||
}
|
||||
|
||||
private void SetToSelectedStyle(IItemSlot itemSlot)
|
||||
private async void SetToSelectedStyle(IItemSlot itemSlot)
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
itemSlot.SetSelectedItemStyle();
|
||||
if (itemSlot.Item is IEquipable newEquipable && GameRepo.IsItemEquipped(newEquipable))
|
||||
itemSlot.SetEquippedSelectedItemStyle();
|
||||
@@ -262,9 +267,10 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.Info.Description}";
|
||||
}
|
||||
|
||||
private void EquipOrUnequipItem()
|
||||
private async void EquipOrUnequipItem()
|
||||
{
|
||||
var itemSlot = ItemSlots[_currentIndex];
|
||||
await ToSignal(GetTree().CreateTimer(0.2f), "timeout");
|
||||
if (itemSlot.Item is IEquipable equipableItem)
|
||||
{
|
||||
if (GameRepo.IsItemEquipped(equipableItem))
|
||||
@@ -300,10 +306,43 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
VTValue.Text = $"{currentVT}/{maxVT}";
|
||||
}
|
||||
|
||||
private void EquipButtonPressed()
|
||||
private async void UseButtonPressed()
|
||||
{
|
||||
EquipOrUnequipItem();
|
||||
HideUserActionPrompt();
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
if (currentItem is IEquipable)
|
||||
EquipOrUnequipItem();
|
||||
if (currentItem is ConsumableItem consumable)
|
||||
consumable.Use();
|
||||
|
||||
// TODO: Replace with animation player (for visual effects/sound effects?)
|
||||
await ToSignal(GetTree().CreateTimer(0.25f), "timeout");
|
||||
await HideUserActionPrompt();
|
||||
PopulatePlayerInfo();
|
||||
}
|
||||
|
||||
private async void ThrowButtonPressed()
|
||||
{
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
|
||||
if (_currentIndex >= ItemSlots.Length - 1)
|
||||
_currentIndex--;
|
||||
if (_currentIndex <= 0)
|
||||
_currentIndex = 0;
|
||||
Game.ToggleInventory();
|
||||
currentItem.Throw();
|
||||
}
|
||||
|
||||
private async void DropButtonPressed()
|
||||
{
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
|
||||
if (_currentIndex >= ItemSlots.Length - 1)
|
||||
_currentIndex--;
|
||||
if (_currentIndex <= 0)
|
||||
_currentIndex = 0;
|
||||
|
||||
Game.ToggleInventory();
|
||||
currentItem.Drop();
|
||||
}
|
||||
|
||||
private enum InventoryPageNumber
|
||||
|
||||
@@ -73,16 +73,16 @@ font_color = Color(0.737255, 0.705882, 0.690196, 1)
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_0kb6l"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ascpt"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_abpb1"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_545ij"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fu7o2"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_nkvce"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_545ij"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ascpt"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_abpb1"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_omlgh"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_uerb4"]
|
||||
@@ -373,31 +373,15 @@ autowrap_mode = 2
|
||||
|
||||
[node name="UseButton" type="Button" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
focus_neighbor_top = NodePath("../DropButton")
|
||||
focus_neighbor_bottom = NodePath("../EquipButton")
|
||||
theme = ExtResource("8_khyvo")
|
||||
theme_override_colors/font_disabled_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_pressed_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_focus_color = Color(1, 0.94902, 0, 1)
|
||||
theme_override_colors/font_color = Color(0.737255, 0.705882, 0.690196, 1)
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_0kb6l")
|
||||
theme_override_styles/disabled = SubResource("StyleBoxEmpty_ascpt")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxEmpty_abpb1")
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_545ij")
|
||||
button_mask = 0
|
||||
text = "Use"
|
||||
alignment = 0
|
||||
|
||||
[node name="EquipButton" type="Button" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
focus_neighbor_left = NodePath(".")
|
||||
focus_neighbor_top = NodePath(".")
|
||||
focus_neighbor_right = NodePath(".")
|
||||
focus_neighbor_bottom = NodePath("../ThrowButton")
|
||||
theme = ExtResource("8_khyvo")
|
||||
theme_override_colors/font_disabled_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_pressed_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
@@ -408,17 +392,44 @@ theme_override_styles/disabled = SubResource("StyleBoxEmpty_fu7o2")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxEmpty_nkvce")
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_545ij")
|
||||
button_mask = 0
|
||||
text = "Equip"
|
||||
text = "Use"
|
||||
alignment = 0
|
||||
|
||||
[node name="DropButton" type="Button" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
|
||||
[node name="ThrowButton" type="Button" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
focus_neighbor_top = NodePath("../EquipButton")
|
||||
focus_neighbor_bottom = NodePath("../UseButton")
|
||||
focus_neighbor_left = NodePath(".")
|
||||
focus_neighbor_top = NodePath("../UseButton")
|
||||
focus_neighbor_right = NodePath(".")
|
||||
focus_neighbor_bottom = NodePath("../DropButton")
|
||||
theme = ExtResource("8_khyvo")
|
||||
theme_override_colors/font_disabled_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_pressed_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_focus_color = Color(1, 0.94902, 0, 1)
|
||||
theme_override_colors/font_color = Color(0.737255, 0.705882, 0.690196, 1)
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_0kb6l")
|
||||
theme_override_styles/disabled = SubResource("StyleBoxEmpty_ascpt")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxEmpty_abpb1")
|
||||
theme_override_styles/normal = SubResource("StyleBoxEmpty_545ij")
|
||||
button_mask = 0
|
||||
text = "Throw"
|
||||
alignment = 0
|
||||
|
||||
[node name="DropButton" type="Button" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(200, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
focus_neighbor_left = NodePath(".")
|
||||
focus_neighbor_top = NodePath("../ThrowButton")
|
||||
focus_neighbor_right = NodePath(".")
|
||||
focus_neighbor_bottom = NodePath(".")
|
||||
theme = ExtResource("8_khyvo")
|
||||
theme_override_colors/font_disabled_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
theme_override_colors/font_pressed_color = Color(0.137255, 0.121569, 0.12549, 1)
|
||||
@@ -436,30 +447,30 @@ alignment = 0
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 20
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="InventoryInfo/HBoxContainer/ItemInfo"]
|
||||
[node name="CenterContainer" type="CenterContainer" parent="InventoryInfo/HBoxContainer/ItemInfo"]
|
||||
custom_minimum_size = Vector2(800, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
|
||||
[node name="BackArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/HBoxContainer"]
|
||||
[node name="BackArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 100)
|
||||
custom_minimum_size = Vector2(800, 0)
|
||||
layout_mode = 2
|
||||
text = "◄"
|
||||
label_settings = SubResource("LabelSettings_x4aj3")
|
||||
horizontal_alignment = 2
|
||||
|
||||
[node name="ItemsTitle" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/HBoxContainer"]
|
||||
custom_minimum_size = Vector2(600, 0)
|
||||
[node name="ItemsTitle" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
|
||||
custom_minimum_size = Vector2(450, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
text = " ITEMS"
|
||||
label_settings = SubResource("LabelSettings_31kc7")
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="ForwardArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/HBoxContainer"]
|
||||
[node name="ForwardArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 100)
|
||||
custom_minimum_size = Vector2(800, 100)
|
||||
layout_mode = 2
|
||||
text = "►"
|
||||
label_settings = SubResource("LabelSettings_x4aj3")
|
||||
|
||||
Reference in New Issue
Block a user