using System.Diagnostics;
using ADOFAIRenderer.Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ADOFAIRenderer.UI;
///
/// Hold-Escape-to-cancel handler shown during a render.
///
/// Created by RenderManager when the render reaches the OnScene stage, on a GameObject kept across scene loads.
/// While Escape is held, a centered panel shows a countdown from 3 seconds; holding it for the full 3 seconds
/// (measured in real time with a , independent of the patched game time) calls
/// RenderManager.CancelRender. Releasing Escape earlier hides the panel and resets the countdown.
/// The component destroys its GameObject as soon as RenderManager.IsActive is false (stage below OnScene).
/// Runs on the main Unity thread.
///
///
internal class EscapeHandlerUI : MonoBehaviour
{
/// Centered countdown panel (background and text); inactive while Escape is not held.
private GameObject _containerObj = null!;
/// Countdown text inside .
private TextMeshProUGUI _textComponent = null!;
/// Real-time hold duration of the current Escape press; null while Escape is not held.
private Stopwatch? _escapeStopwatch;
///
/// Builds the overlay canvas and the hidden countdown panel. Layout values are canvas units at the 1920x1080
/// reference resolution.
///
private void Start()
{
// Set UI layer (5, Unity's built-in "UI" layer)
gameObject.layer = 5;
// Canvas setup
var canvas = gameObject.AddComponent