Skip to content
Merged
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: 14 additions & 5 deletions Intersect.Client.Core/Interface/Game/SimplifiedEscapeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,20 @@ private static void LogoutToMainMenu(object? sender, EventArgs? e)

private static void ExitToDesktop(object? sender, EventArgs? e)
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}
AlertWindow.Open(
Strings.General.QuitPrompt,
Strings.General.QuitTitle,
AlertType.Warning,
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}

Globals.IsRunning = false;
Globals.IsRunning = false;
}
);
}
}
21 changes: 15 additions & 6 deletions Intersect.Client.Core/Interface/Menu/EscapeMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,20 @@ private void ShowCombatWarning()

private void ExitToDesktop(object? sender, EventArgs? e)
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}

Globals.IsRunning = false;
AlertWindow.Open(
Strings.General.QuitPrompt,
Strings.General.QuitTitle,
AlertType.Warning,
inputType: InputType.YesNo,
handleSubmit: (_, _) =>
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}

Globals.IsRunning = false;
}
);
}
}
6 changes: 6 additions & 0 deletions Intersect.Client.Core/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,12 @@ public partial struct General

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString PingLabelFormat = @"{0}ms";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString QuitTitle { get; set; } = @"Quit Game";

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public static LocalizedString QuitPrompt { get; set; } = @"Are you sure you want to quit the game?";
}

public partial struct Guilds
Expand Down
75 changes: 44 additions & 31 deletions Intersect.Client.Core/MonoGame/IntersectGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal partial class IntersectGame : Game

private GraphicsDeviceManager mGraphics;

private bool _isShowingExitConfirmation = false;

#region "Autoupdate Variables"

private Updater? _updater;
Expand Down Expand Up @@ -339,51 +341,62 @@ protected override void Draw(GameTime gameTime)

protected override void OnExiting(object sender, ExitingEventArgs args)
{
// If already showing dialog, just cancel and return
if (_isShowingExitConfirmation)
{
args.Cancel = true;
return;
}

ApplicationContext.Context.Value?.Logger.LogInformation("System window closing (due to user interaction most likely).");

if (Globals.Me != null && Globals.Me.CombatTimer > Timing.Global?.Milliseconds)
// Check if player is logged in and in game
if (Globals.Me != null && Globals.LoggedIn && Globals.GameState == GameStates.InGame)
{
//Try to prevent SDL Window Close
var exception = false;
try
{
var platform = GetType()
.GetField("Platform", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(this);
// Set flag to prevent multiple dialogs
_isShowingExitConfirmation = true;

var field = platform.GetType()
.GetField("_isExiting", BindingFlags.NonPublic | BindingFlags.Instance);
// Check if player is in combat
bool inCombat = Globals.Me.CombatTimer > Timing.Global?.Milliseconds;

field.SetValue(platform, 0);
}
catch
{
//TODO: Should we log here? I really don't know if it's necessary.
exception = true;
}
// Cancel the exit event
args.Cancel = true;

if (!exception)
if (inCombat)
{
//Show Message Getting Exit Confirmation From Player to Leave in Combat
_ = new InputBox(
// Show combat warning
var inputBox = new InputBox(
title: Strings.Combat.WarningTitle,
prompt: Strings.Combat.WarningCharacterSelect,
prompt: Strings.Combat.WarningExitDesktop,
inputType: InputType.YesNo,
onSubmit: (s, e) =>
{
if (Globals.Me != null)
{
Globals.Me.CombatTimer = 0;
}

Globals.Me.CombatTimer = 0;
_isShowingExitConfirmation = false;
Globals.IsRunning = false;
}
},
onCancel: (s, e) => { _isShowingExitConfirmation = false; }
);

//Restart the MonoGame RunLoop
Run();
return;
inputBox.Closed += (s, e) => { _isShowingExitConfirmation = false; };
}
else
{
// Show quit confirmation
var inputBox = new InputBox(
title: Strings.General.QuitTitle,
prompt: Strings.General.QuitPrompt,
inputType: InputType.YesNo,
onSubmit: (s, e) =>
{
_isShowingExitConfirmation = false;
Globals.IsRunning = false;
},
onCancel: (s, e) => { _isShowingExitConfirmation = false; }
);
inputBox.Closed += (s, e) => { _isShowingExitConfirmation = false; };
}

return;
}

try
Expand Down
Loading