ShopInterface.razor
@using Sandbox;
@using Sandbox.UI;
@inherits PanelComponent
@namespace Sandbox
<root>
<header>
<h1>UPGRADE SHOP</h1>
</header>
<p class="smaller">You have @Currency goodies to spend! More upgrades may appear later...</p>
<div class="items">
@foreach (var upgrade in Upgrades)
{
<ShopUpgrade Upgrade=@upgrade Currency:bind=@Currency UpgradeList=@Upgrades Purchase=@Purchase></ShopUpgrade>
}
</div>
<div class="empty"></div>
<button id="continue" onclick=@((e) => CloseShop())>I'm ready.</button>
</root>
@code
{
[Property]
public List<Upgrade> Upgrades { get; set; } = [];
[Property]
public SoundEvent Purchase { get; set; }
protected override void OnEnabled()
{
base.OnEnabled();
// move mouse to middle of screen every time shop opens
Mouse.Position = Screen.Size / 2;
// pause the game
Scene.TimeScale = 0;
}
protected override void OnDisabled()
{
base.OnDisabled();
// resume the game
Scene.TimeScale = 1;
}
private void CloseShop()
{
GameObject.Enabled = false;
}
public int Currency
{
get
{
return Scene.Get<ShopSystem>().Currency;
}
set
{
Scene.Get<ShopSystem>().Currency = value;
}
}
/// <summary>
/// the hash determines if the system should be rebuilt. If it changes, it will be rebuilt
/// </summary>
protected override int BuildHash() => System.HashCode.Combine( Currency, Upgrades );
}