Framework/EndScreen.cs

Definitions for end-of-game UI data types. It declares EndTone (win/lose/neutral), EndScreen record holding title, detail, tone and actions, EndActionKind enum for button behaviors, and EndAction record with helpers for common buttons and a Custom factory.

using System.Collections.Generic;

namespace CardGames;

/// <summary>
/// The mood of an end-of-game overlay - drives its accent colour (win = green, loss = red).
/// </summary>
public enum EndTone
{
	Neutral,
	Win,
	Loss
}

/// <summary>
/// What the HUD shows when a game reaches <see cref="GameState.GameOver"/>: a title, an optional detail
/// line, a tone, and the buttons to offer. A game customises this by overriding
/// <see cref="CardGame.GetEndScreen"/>; the default is a neutral "Game Over" with Play Again / Keep
/// Playing / Main Menu.
/// </summary>
public readonly record struct EndScreen(
	string Title,
	string Detail = null,
	EndTone Tone = EndTone.Neutral,
	IReadOnlyList<EndAction> Actions = null );

/// <summary>
/// How an <see cref="EndAction"/> behaves when clicked. The three system kinds are handled by the HUD/
/// director; <see cref="Custom"/> routes back to the game via <see cref="CardGame.OnEndAction"/>.
/// </summary>
public enum EndActionKind
{
	PlayAgain,   // deal a fresh round (director.DealRound)
	MainMenu,    // quit to the launcher (director.QuitGame)
	KeepPlaying, // dismiss the overlay back to the board (local, per-client)
	Custom       // game-specific: sent to the game's OnEndAction
}

/// <summary>
/// One button on the end-of-game overlay. Use the static helpers for the common ones, or
/// <see cref="Custom"/> for a game-specific action.
/// </summary>
public readonly record struct EndAction( string Label, EndActionKind Kind, bool Primary = false, string Id = null )
{
	public static EndAction PlayAgain => new( "Play Again", EndActionKind.PlayAgain, Primary: true );
	public static EndAction MainMenu => new( "Main Menu", EndActionKind.MainMenu );
	public static EndAction KeepPlaying => new( "Keep Playing", EndActionKind.KeepPlaying );

	/// <summary>A game-specific action; its <paramref name="id"/> arrives at <see cref="CardGame.OnEndAction"/>.</summary>
	public static EndAction Custom( string id, string label, bool primary = false ) => new( label, EndActionKind.Custom, primary, id );
}