UI/MainMenu/NavBar.razor
@using Sandbox.UI;
@using Sandbox.UI.Navigation;
@using Sandbox;
@namespace Sandbox
@inherits Panel
<root class="navbar">
<div class="group left">
@if ( ShowBack )
{
<div id="BackToMenu" class="button" onclick=@GoBack>
<img src="/ui/back_to_main_menu.png" />
<span>Back to Main Menu</span>
</div>
}
</div>
<div class="group center">
@if ( ShowBackToGame )
{
<div class="button bigicon" onclick=@BackToGame>
<img src="/ui/back_to_game.png" />
<span>Back to Game</span>
</div>
}
</div>
<div class="group right">
</div>
</root>
@code
{
[Parameter] public MainMenuHost Host { get; set; }
bool ShowBackToGame => Host?.IsInGameMenu ?? false;
bool ShowBack => this.GetNavigator()?.CurrentUrl != "/";
string _lastUrl;
bool _lastShowBackToGame;
public override void Tick()
{
var url = this.GetNavigator()?.CurrentUrl;
var showBackToGame = ShowBackToGame;
if ( url != _lastUrl || showBackToGame != _lastShowBackToGame )
{
_lastUrl = url;
_lastShowBackToGame = showBackToGame;
StateHasChanged();
}
}
void GoBack()
{
this.GetNavigator()?.Navigate( "/" );
}
void BackToGame()
{
Host?.ResumeGame();
}
}