Implement BGM and SFX event system

This commit is contained in:
2024-09-14 16:01:55 -07:00
parent 0a71339bbe
commit cd8806a9fe
38 changed files with 718 additions and 116 deletions

View File

@@ -24,6 +24,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
[Dependency]
public IGame Game => this.DependOn<IGame>();
[Dependency]
public IGameEventDepot GameEventDepot => this.DependOn<IGameEventDepot>();
[Signal]
public delegate void ClosedMenuEventHandler();
@@ -100,7 +103,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
await HideUserActionPrompt();
await ShowInventoryInfo();
ItemEffectLabel.Text = statRaisedAlert;
await ToSignal(GetTree().CreateTimer(1.5f), "timeout");
await ToSignal(GetTree().CreateTimer(1f), "timeout");
await RedrawInventory();
SetProcessInput(true);
}
@@ -151,6 +154,8 @@ public partial class InventoryMenu : Control, IInventoryMenu
await ClearItems();
PopulateInventory();
PopulatePlayerInfo();
await HideUserActionPrompt();
await ShowInventoryInfo();
}
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
@@ -164,6 +169,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
{
HideUserActionPrompt();
ShowInventoryInfo();
GameEventDepot.OnMenuBackedOut();
}
else
{
@@ -182,16 +188,29 @@ public partial class InventoryMenu : Control, IInventoryMenu
if (@event.IsActionPressed(GameInputs.UiDown))
{
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
_currentIndex = new[] { _currentIndex + 1, _itemsPerPage - 1, ItemSlots.Length - 1 }.Min();
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
var oldIndex = _currentIndex;
var newIndex = new[] { _currentIndex + 1, _itemsPerPage - 1, ItemSlots.Length - 1 }.Min();
if (oldIndex == newIndex)
return;
SetToUnselectedStyle(ItemSlots.ElementAt(oldIndex));
SetToSelectedStyle(ItemSlots.ElementAt(newIndex));
GameEventDepot.OnMenuScrolled();
_currentIndex = newIndex;
}
if (@event.IsActionPressed(GameInputs.UiUp))
{
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
_currentIndex = new[] { _currentIndex - 1, 0 }.Max();
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
var oldIndex = _currentIndex;
var newIndex = new[] { _currentIndex - 1, 0 }.Max();
if (oldIndex == newIndex)
return;
SetToUnselectedStyle(ItemSlots.ElementAt(oldIndex));
SetToSelectedStyle(ItemSlots.ElementAt(newIndex));
GameEventDepot.OnMenuScrolled();
_currentIndex = newIndex;
}
if (@event.IsActionPressed(GameInputs.UiAccept))
@@ -202,6 +221,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
if (@event.IsActionPressed(GameInputs.InventorySort))
{
inventory.Sort();
GameEventDepot.OnInventorySorted();
RedrawInventory();
}
}
@@ -283,9 +303,10 @@ public partial class InventoryMenu : Control, IInventoryMenu
_currentIndex = 0;
_currentPageNumber = pageToChangeTo;
await RedrawInventory();
GameEventDepot.OnMenuScrolled();
}
private void PopulateInventory()
private async void PopulateInventory()
{
var inventory = GameRepo.PlayerData.Inventory;
var numberOfItemsToDisplay = _currentPageNumber == InventoryPageNumber.FirstPage ? Mathf.Min(inventory.Items.Count, _itemsPerPage) : Mathf.Min(inventory.Items.Count - _itemsPerPage, _itemsPerPage);
@@ -362,7 +383,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
SetProcessInput(false);
await HideUserActionPrompt();
await ShowInventoryInfo();
await ToSignal(GetTree().CreateTimer(1.5f), "timeout");
await ToSignal(GetTree().CreateTimer(1f), "timeout");
await RedrawInventory();
SetProcessInput(true);
}
@@ -376,6 +397,11 @@ public partial class InventoryMenu : Control, IInventoryMenu
else if (currentItem is ConsumableItem consumable)
{
GameRepo.PlayerData.Inventory.Use(consumable);
GameEventDepot.OnHealingItemConsumed(consumable.ConsumableItemInfo);
if (_currentIndex >= ItemSlots.Length - 1)
_currentIndex--;
if (_currentIndex <= 0)
_currentIndex = 0;
}
}

View File

@@ -189,10 +189,10 @@ layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_bottom = 194.0
offset_bottom = -3.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_top = 112
theme_override_constants/margin_top = 100
[node name="HBoxContainer" type="HBoxContainer" parent="InventoryInfo"]
layout_mode = 2
@@ -507,31 +507,36 @@ alignment = 0
layout_mode = 2
theme_override_constants/separation = 20
[node name="CenterContainer" type="CenterContainer" parent="InventoryInfo/HBoxContainer/ItemInfo"]
custom_minimum_size = Vector2(800, 0)
[node name="ItemTitleContainer" type="MarginContainer" parent="InventoryInfo/HBoxContainer/ItemInfo"]
custom_minimum_size = Vector2(800, 125)
layout_mode = 2
size_flags_horizontal = 4
[node name="BackArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
[node name="BackArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/ItemTitleContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(800, 0)
visible = false
custom_minimum_size = Vector2(100, 0)
layout_mode = 2
text = "◄"
label_settings = SubResource("LabelSettings_x4aj3")
[node name="ItemsTitle" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
[node name="ItemsTitle" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/ItemTitleContainer"]
custom_minimum_size = Vector2(450, 0)
layout_mode = 2
size_flags_horizontal = 4
size_flags_horizontal = 3
size_flags_vertical = 1
text = " ITEMS"
label_settings = SubResource("LabelSettings_31kc7")
horizontal_alignment = 1
vertical_alignment = 1
[node name="ForwardArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/CenterContainer"]
[node name="ForwardArrow" type="Label" parent="InventoryInfo/HBoxContainer/ItemInfo/ItemTitleContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(800, 100)
visible = false
custom_minimum_size = Vector2(800, 0)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
text = "►"
label_settings = SubResource("LabelSettings_x4aj3")
horizontal_alignment = 2