UI/HQ/Elements/ArenaLauncher.razor
@using Sandbox.UI;
@inherits Panel
@namespace PlanetMeat

<root>
	<div class="pm-body">
		<div class="tool-list pm-inset scroll-v">
			@foreach (var tool in Research.Current.ActiveTechTools)
			{
				<div class="tool">
					<div class="tool-head">
						<span class="mat-icon">@(GetDisplayIcon(tool))</span>
						<span>#@(BaseTech.GetToolTitle(tool))</span>
					</div>
					<span class="tool-desc">#@(BaseTech.GetToolDesc(tool))</span>
				</div>
			}
		</div>
		<div class="actions">
			@{
				var maxSkip = MaxRoundSkip;
				if (maxSkip > 1)
				{
					<div class="round-skip">
						<span>#hq.skip.prefix</span>
						<TextEntry Value:bind=@WantedSkip Numeric MinValue=@(1) MaxValue=@maxSkip NumberFormat="N0"></TextEntry>
						<span>/@maxSkip</span>
					</div>
				}
			}
			<span class="btn-play">
				<button class="click-active" onclick=@GoToArena>
					<span>#button.hq.play</span>
				</button>
			</span>
		</div>
		@if (!HqDeciding.IsFreshStart)
		{
			<span class="resetter">
				<button class="click-active @LockedPressed mat-icon" onmousedown=@ToggleResetLocked>
					<span>@LockedIcon</span>
				</button>
				<button class="click-active @LockedDisabled" onclick=@ResetCareer>
					<span>#button.hq.reset</span>
				</button>
			</span>
		}
	</div>
</root>

@code
{
	private static int PreviousSkip { get; set; } = 1;

	public string GetDisplayIcon(string tool) => Catalogue.Current.Categories[tool].DisplayIcon;

	private bool CanSkip => Research.Current.HasTech("skip_rounds");
	private int MaxRoundSkip => CanSkip ? Career.Current.HighestRoundCompleted : -1;
	public string WantedSkip { get; set; } = PreviousSkip.ToString();

	private bool _resetLocked = true;

	private void ToggleResetLocked()
	{
		_resetLocked = !_resetLocked;
	}

	private void ResetCareer()
	{
		if (!_resetLocked)
			Career.Current.Reset();
	}

	private string LockedIcon => _resetLocked ? "lock" : "lock_open";
	private string LockedPressed => _resetLocked ? "" : "pressed";
	private string LockedDisabled => _resetLocked ? "disabled" : "";

	private void GoToArena()
	{
		var maxSkip = MaxRoundSkip;
		var relocator = HqNavigator.Local.Relocator;
		if (!(relocator?.Travelling ?? false))
		{
			if (maxSkip > 0 && System.Int32.TryParse(WantedSkip, out var skip))
			{
				PreviousSkip = skip.Clamp(1, maxSkip);
				relocator.BeginRelocation(PreviousSkip);
			}
			else
			{
				relocator.BeginRelocation();
			}
		}
	}
}