UI/ReplayCodeDialog.razor

A Razor UI panel that shows a dialog for pasting a replay code. It displays a title, a text entry for the code, an optional error label, and Cancel/Confirm buttons that invoke provided callbacks and play UI sound effects.

Native Interop
@using Sandbox.UI
@inherits Panel
@namespace BlockParty
@attribute [StyleSheet( "ReplayCodeDialog.razor.scss" )]

<root>
	<div class="shade">
		<div class="dialog">
			<label class="title">@Title</label>
			<TextEntry class="code-entry" Value=@_text Placeholder="PASTE REPLAY CODE"
				OnTextEdited=@((string v) => OnEdited( v ))></TextEntry>
			@if ( !string.IsNullOrEmpty( Error ) )
			{
				<label class="error">@Error</label>
			}
			<div class="buttons">
				<button class="cancel" onclick=@Cancel>CANCEL</button>
				<button class="confirm" onclick=@(() => Submit( _text ))>@ConfirmLabel</button>
			</div>
		</div>
	</div>
</root>

@code
{
	[Parameter] public string Title { get; set; } = "REPLAY CODE";
	[Parameter] public string ConfirmLabel { get; set; } = "CONFIRM";
	[Parameter] public string Error { get; set; } = "";
	[Parameter] public Action<string> OnConfirm { get; set; }
	[Parameter] public Action OnCancel { get; set; }

	private string _text = "";

	private void OnEdited( string value ) => _text = value ?? "";
	private void Submit( string value )
	{
		Audio.PlaySfx( SfxType.MenuStart );
		OnConfirm?.Invoke( value ?? "" );
	}
	private void Cancel()
	{
		Audio.PlaySfx( SfxType.MenuBlip );
		OnCancel?.Invoke();
	}

	protected override int BuildHash() => System.HashCode.Combine( _text, Error, Title, ConfirmLabel );
}