MatchExitFlow.cs

Part of MatchController that handles the leave-match flow. Blocks navigation away from an unfinished match and opens a pause prompt, with options to continue or finish the match in text mode.

using Sandbox;
using Sandbox.UI;
using Socer;

public sealed partial class MatchController
{
    MatchSimulation enteredMatch;
    bool exitPromptWasPaused;
    public bool MatchExitPromptOpen {get;private set;}

    // The reference covers the introduction and a paused first frame before
    // the clock moves. A fresh club-view fixture has not been entered yet.
    public bool MustFinishMatchBeforeLeaving=>Match!=null && !Match.Finished &&
        !IsRulesPreview && !MatchTutorialActive && !FootballLabActive && !StrategyLabOpen &&
        !PreparingMatch && !MatchModeSelection &&
        (Match.Seconds>0 || ReferenceEquals(enteredMatch,Match) || QuickMatchRunning);

    bool RequireFinishedMatchForNavigation()
    {
        if(!MustFinishMatchBeforeLeaving)return true;
        if(QuickMatchRunning || QuickBroadcastOpen)return false;
        if(MatchExitPromptOpen)return false;
        if(GameSettingsOpen)ToggleGameSettings();
        exitPromptWasPaused=Paused;
        CloseSubstitutions();CloseCommandWheel();CancelDirectOrder();SetFieldDragSlow(false);
        InputFocus.Clear();
        MatchExitPromptOpen=true;ClubOpen=false;Paused=true;accumulator=0;Revision++;
        return false;
    }

    public void ContinueAfterMatchExitPrompt()
    {
        if(!MatchExitPromptOpen)return;
        InputFocus.Clear();MatchExitPromptOpen=false;
        Paused=exitPromptWasPaused || InjuryChoiceOpen || SubstitutionOpen;
        accumulator=0;Revision++;
    }

    public void ConfirmMatchExitInText()
    {
        if(!MatchExitPromptOpen || !CanFinishCurrentMatchQuickly)return;
        ContinueAfterMatchExitPrompt();
        FinishCurrentMatchQuickly();
    }

    public string MatchExitTextUnavailable=>Match.ShootoutActive
        ?(GamePreferences.Russian?"Сначала завершите серию пенальти на поле.":"Finish the penalty shootout on the pitch first.")
        :(GamePreferences.Russian?"Сначала завершите выбор замены, затем можно доиграть матч текстом.":"Complete the substitution choice, then you can finish in text mode.");
}