Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Intersect.Client.Core/Interface/Game/SimplifiedEscapeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using Intersect.Client.General;
using Intersect.Client.Interface.Shared;
using Intersect.Client.Localization;
using Intersect.Client.MonoGame;
using Intersect.Framework.Core;
using Intersect.Utilities;

namespace Intersect.Client.Interface.Game;

Expand Down Expand Up @@ -114,6 +114,11 @@ private void LogoutToMainToMainMenuClicked(Base sender, MouseButtonState argumen

private void ExitToDesktopClicked(Base sender, MouseButtonState arguments)
{
if (IntersectGame._isShowingExitConfirmation)
{
return;
}

if (Globals.Me?.CombatTimer > Timing.Global?.Milliseconds)
{
AlertWindow.Open(
Expand All @@ -123,8 +128,13 @@ private void ExitToDesktopClicked(Base sender, MouseButtonState arguments)
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
Globals.Me.CombatTimer = 0;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
}
);
}
Expand All @@ -137,10 +147,17 @@ private void ExitToDesktopClicked(Base sender, MouseButtonState arguments)
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
}
);
}

IntersectGame._isShowingExitConfirmation = true;
}

private void OpenSettingsWindow(object? sender, EventArgs? e)
Expand Down
14 changes: 13 additions & 1 deletion Intersect.Client.Core/Interface/Menu/EscapeMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Intersect.Client.General;
using Intersect.Client.Interface.Shared;
using Intersect.Client.Localization;
using Intersect.Client.MonoGame;
using Intersect.Framework.Core;
using Intersect.Utilities;

namespace Intersect.Client.Interface.Menu;

Expand Down Expand Up @@ -217,6 +217,11 @@ private void ShowCombatWarning()

private void ExitToDesktop(object? sender, EventArgs? e)
{
if (IntersectGame._isShowingExitConfirmation)
{
return;
}

AlertWindow.Open(
Strings.General.QuitPrompt,
Strings.General.QuitTitle,
Expand All @@ -229,8 +234,15 @@ private void ExitToDesktop(object? sender, EventArgs? e)
Globals.Me.CombatTimer = 0;
}

IntersectGame._isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
IntersectGame._isShowingExitConfirmation = false;
}
);

IntersectGame._isShowingExitConfirmation = true;
}
}
12 changes: 12 additions & 0 deletions Intersect.Client.Core/Interface/Shared/AlertWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public record struct Alert(string Message, string? Title = default, AlertType Ty
public class AlertWindow : InputBox
{
private static readonly HashSet<AlertWindow> _instances = [];
private readonly GwenEventHandler<EventArgs>? _handleCancel;

private AlertWindow(
string title,
Expand All @@ -39,6 +40,8 @@ private AlertWindow(
userData: userData
)
{
_handleCancel = handleCancel;

Icon = GameContentManager.Current.GetTexture(
TextureType.Gui,
$"icon.alert.{alertType.ToString().ToLowerInvariant()}.png"
Expand All @@ -49,6 +52,15 @@ private AlertWindow(

var titleLabelMargin = TitleLabel.Margin;
TitleLabel.Margin = titleLabelMargin with { Left = titleLabelMargin.Left + 4 };

// Subscribe to the Closed event to handle X button clicks
Closed += OnWindowClosed;
}

private void OnWindowClosed(Base sender, EventArgs args)
{
// Trigger the cancel handler when window is closed via X button
_handleCancel?.Invoke(this, args);
}

protected override void OnCanceled(Base sender, EventArgs args)
Expand Down
20 changes: 18 additions & 2 deletions Intersect.Client.Core/MonoGame/IntersectGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Intersect.Configuration;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Diagnostics;
using System.Reflection;
using Intersect.Client.Framework.Database;
using Intersect.Client.Framework.Graphics;
using Intersect.Client.ThirdParty;
Expand Down Expand Up @@ -58,6 +56,8 @@ internal partial class IntersectGame : Game
private SpriteBatch? updateBatch;

private bool updaterGraphicsReset;

public static bool _isShowingExitConfirmation;

#endregion

Expand Down Expand Up @@ -355,6 +355,11 @@ protected override void OnExiting(object sender, ExitingEventArgs args)
Globals.Me.CombatTimer > Timing.Global?.Milliseconds &&
Globals.GameState == GameStates.InGame;

if (_isShowingExitConfirmation)
{
return;
}

if (inCombat)
{
AlertWindow.Open(
Expand All @@ -369,7 +374,12 @@ protected override void OnExiting(object sender, ExitingEventArgs args)
Globals.Me.CombatTimer = 0;
}

_isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
_isShowingExitConfirmation = false;
}
);
}
Expand All @@ -382,10 +392,16 @@ protected override void OnExiting(object sender, ExitingEventArgs args)
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
_isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
handleCancel: (_, _) =>
{
_isShowingExitConfirmation = false;
}
);
}
_isShowingExitConfirmation = true;
}

private void TryExit(object sender, ExitingEventArgs args)
Expand Down
Loading