DiamondPanel.Leave.cs
using System;
using Sandbox;

namespace Diamonds;

public sealed partial class DiamondPanel
{
	public Action LeaveRequested { get; set; }

	static Rect LeaveButton( Vector2 size ) => new( LetterboxCenter( size, true ) - 136, Top + 876, 272, 64 );

	/// <summary>The letterbox Leave button fades straight back to the title; its flashing red hover is the warning.</summary>
	public bool HandleLeaveClick( Vector2 mouse, Vector2 size )
	{
		if ( TitleScreen || ModalOpen || TransitionPending || Board is null ) return false;
		float scale = MathF.Min( size.x / CanvasWidth, size.y / CanvasHeight );
		if ( scale <= 0 ) return false;
		var point = (mouse - (size - new Vector2( CanvasWidth, CanvasHeight ) * scale) * 0.5f) / scale;
		if ( !LeaveButton( size ).IsInside( point ) ) return false;
		PlayClickSound();
		BeginTransition( toGame: false );
		return true;
	}

	void DrawLeaveButton( Painter p, float scale )
	{
		var size = Box.Rect.Size;
		var mouse = (MousePosition - (size - new Vector2( CanvasWidth, CanvasHeight ) * scale) * 0.5f) / scale;
		DrawTitleButton( p, LeaveButton( size ), "LEAVE", mouse, scale, fontSize: 26, brightness: 0.7f, danger: true );
	}
}