Stages/WorkshopStage.cs
namespace BlockParty;

/// <summary>
/// Workshop browser: a searchable, sortable grid of player-published levels (see
/// <see cref="WorkshopLevels"/>). Picking a level installs it and starts a run; its trophy chip opens
/// that level's leaderboard (a <see cref="HighscoreStage"/> pinned to the ws id, whose BACK returns
/// here). Reached from the title's WORKSHOP option; finished runs and watched replays route back here
/// too, with the last search/sort restored.
/// </summary>
public sealed class WorkshopStage : MenuStageBase
{
	private WorkshopScreen _screen;

	public WorkshopStage( GameManager manager ) : base( manager ) { }

	/// <summary>Same dark-fill treatment as the leaderboard: the browser lives on the transition
	/// square's colour rather than the teal playfield.</summary>
	public override bool CoveredBackground => true;

	protected override void OnEnter()
	{
		var go = CreateUiRoot();
		_screen = go.Components.Create<WorkshopScreen>();
		_screen.Stage = this;
	}

	public override void Tick( float dt )
	{
		base.Tick( dt );

		// An open character-picker overlay owns Back (close it, don't leave the screen).
		if ( _screen?.ModalOpen == true )
		{
			if ( InputState.BackJust )
				_screen.CloseModal();
			return;
		}

		if ( InputState.BackJust )
			GoBack();
	}

	public void GoBack() => FadeToStage( new TitleStage( Manager ) );
}