Skip to content

Commit dcbd209

Browse files
authored
Fix: #2762 + OnExiting Updates V2 (#2789)
(PR #2788 was not finished) This Commit finishes the job and fixes #2762 as well - No more SDL hack for Linux, args.Cancel = true should be sufficient for all platforms (MonoGame). - Improved logic working for: simplified and regular game menus desktop/logout buttons, Alt+F4 and X close button - Improved logic works either in game and mainmenu - Prevents game crash due to disposal of already disposed UI elements
1 parent 813481c commit dcbd209

File tree

4 files changed

+92
-87
lines changed

4 files changed

+92
-87
lines changed

Intersect.Client.Core/Interface/Game/SimplifiedEscapeMenu.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public SimplifiedEscapeMenu(Canvas gameCanvas, Func<SettingsWindow> settingsWind
3535
_settings.Clicked += OpenSettingsWindow;
3636
_character.Clicked += LogoutToCharacterSelectSelectClicked;
3737
_logout.Clicked += LogoutToMainToMainMenuClicked;
38-
_exit.Clicked += ExitToDesktopToDesktopClicked;
38+
_exit.Clicked += ExitToDesktopClicked;
3939

4040
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer?.GetResolutionString());
4141
}
@@ -80,7 +80,13 @@ private void LogoutToCharacterSelectSelectClicked(Base sender, MouseButtonState
8080
{
8181
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
8282
{
83-
ShowCombatWarning();
83+
AlertWindow.Open(
84+
Strings.Combat.WarningCharacterSelect,
85+
Strings.Combat.WarningTitle,
86+
AlertType.Warning,
87+
handleSubmit: LogoutToCharacterSelect,
88+
inputType: InputType.YesNo
89+
);
8490
}
8591
else
8692
{
@@ -92,37 +98,51 @@ private void LogoutToMainToMainMenuClicked(Base sender, MouseButtonState argumen
9298
{
9399
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
94100
{
95-
ShowCombatWarning();
101+
AlertWindow.Open(
102+
Strings.Combat.WarningLogout,
103+
Strings.Combat.WarningTitle,
104+
AlertType.Warning,
105+
handleSubmit: LogoutToMainMenu,
106+
inputType: InputType.YesNo
107+
);
96108
}
97109
else
98110
{
99111
LogoutToMainMenu(null, null);
100112
}
101113
}
102114

103-
private void ExitToDesktopToDesktopClicked(Base sender, MouseButtonState arguments)
115+
private void ExitToDesktopClicked(Base sender, MouseButtonState arguments)
104116
{
105-
if (Globals.Me?.CombatTimer > Timing.Global.Milliseconds)
117+
if (Globals.Me?.CombatTimer > Timing.Global?.Milliseconds)
106118
{
107-
ShowCombatWarning();
119+
AlertWindow.Open(
120+
Strings.Combat.WarningExitDesktop,
121+
Strings.Combat.WarningTitle,
122+
AlertType.Warning,
123+
inputType: InputType.YesNo,
124+
handleSubmit: (_, _) =>
125+
{
126+
Globals.Me.CombatTimer = 0;
127+
Globals.IsRunning = false;
128+
}
129+
);
108130
}
109131
else
110132
{
111-
ExitToDesktop(null, null);
133+
AlertWindow.Open(
134+
Strings.General.QuitPrompt,
135+
Strings.General.QuitTitle,
136+
AlertType.Warning,
137+
inputType: InputType.YesNo,
138+
handleSubmit: (_, _) =>
139+
{
140+
Globals.IsRunning = false;
141+
}
142+
);
112143
}
113144
}
114145

115-
private static void ShowCombatWarning()
116-
{
117-
AlertWindow.Open(
118-
Strings.Combat.WarningCharacterSelect,
119-
Strings.Combat.WarningTitle,
120-
AlertType.Warning,
121-
handleSubmit: LogoutToCharacterSelect,
122-
inputType: InputType.YesNo
123-
);
124-
}
125-
126146
private void OpenSettingsWindow(object? sender, EventArgs? e)
127147
{
128148
var settingsWindow = _settingsWindowProvider();
@@ -153,23 +173,4 @@ private static void LogoutToMainMenu(object? sender, EventArgs? e)
153173

154174
Main.Logout(false);
155175
}
156-
157-
private static void ExitToDesktop(object? sender, EventArgs? e)
158-
{
159-
AlertWindow.Open(
160-
Strings.General.QuitPrompt,
161-
Strings.General.QuitTitle,
162-
AlertType.Warning,
163-
inputType: InputType.YesNo,
164-
handleSubmit: (_, _) =>
165-
{
166-
if (Globals.Me != null)
167-
{
168-
Globals.Me.CombatTimer = 0;
169-
}
170-
171-
Globals.IsRunning = false;
172-
}
173-
);
174-
}
175176
}

Intersect.Client.Core/MonoGame/IntersectGame.cs

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ internal partial class IntersectGame : Game
4343

4444
private GraphicsDeviceManager mGraphics;
4545

46-
private bool _isShowingExitConfirmation = false;
47-
4846
#region "Autoupdate Variables"
4947

5048
private Updater? _updater;
@@ -341,64 +339,57 @@ protected override void Draw(GameTime gameTime)
341339

342340
protected override void OnExiting(object sender, ExitingEventArgs args)
343341
{
344-
// If already showing dialog, just cancel and return
345-
if (_isShowingExitConfirmation)
342+
// If game is already shutting down, allow it to exit normally
343+
if (!Globals.IsRunning)
346344
{
347-
args.Cancel = true;
345+
ApplicationContext.Context.Value?.Logger.LogInformation("System window closing (due to user interaction most likely).");
346+
TryExit(sender, args);
348347
return;
349348
}
350349

351-
ApplicationContext.Context.Value?.Logger.LogInformation("System window closing (due to user interaction most likely).");
352-
353-
// Check if player is logged in and in game
354-
if (Globals.Me != null && Globals.LoggedIn && Globals.GameState == GameStates.InGame)
355-
{
356-
// Set flag to prevent multiple dialogs
357-
_isShowingExitConfirmation = true;
358-
359-
// Check if player is in combat
360-
bool inCombat = Globals.Me.CombatTimer > Timing.Global?.Milliseconds;
350+
// Cancel the exit event
351+
args.Cancel = true;
361352

362-
// Cancel the exit event
363-
args.Cancel = true;
353+
// Check if there's a player in combat
354+
bool inCombat = Globals.Me != null &&
355+
Globals.Me.CombatTimer > Timing.Global?.Milliseconds &&
356+
Globals.GameState == GameStates.InGame;
364357

365-
if (inCombat)
366-
{
367-
// Show combat warning
368-
var inputBox = new InputBox(
369-
title: Strings.Combat.WarningTitle,
370-
prompt: Strings.Combat.WarningExitDesktop,
371-
inputType: InputType.YesNo,
372-
onSubmit: (s, e) =>
358+
if (inCombat)
359+
{
360+
AlertWindow.Open(
361+
Strings.Combat.WarningExitDesktop,
362+
Strings.Combat.WarningTitle,
363+
AlertType.Warning,
364+
inputType: InputType.YesNo,
365+
handleSubmit: (_, _) =>
366+
{
367+
if (Globals.Me != null)
373368
{
374369
Globals.Me.CombatTimer = 0;
375-
_isShowingExitConfirmation = false;
376-
Globals.IsRunning = false;
377-
},
378-
onCancel: (s, e) => { _isShowingExitConfirmation = false; }
379-
);
380-
inputBox.Closed += (s, e) => { _isShowingExitConfirmation = false; };
381-
}
382-
else
383-
{
384-
// Show quit confirmation
385-
var inputBox = new InputBox(
386-
title: Strings.General.QuitTitle,
387-
prompt: Strings.General.QuitPrompt,
388-
inputType: InputType.YesNo,
389-
onSubmit: (s, e) =>
390-
{
391-
_isShowingExitConfirmation = false;
392-
Globals.IsRunning = false;
393-
},
394-
onCancel: (s, e) => { _isShowingExitConfirmation = false; }
395-
);
396-
inputBox.Closed += (s, e) => { _isShowingExitConfirmation = false; };
397-
}
370+
}
398371

399-
return;
372+
Globals.IsRunning = false;
373+
}
374+
);
400375
}
376+
else
377+
{
378+
AlertWindow.Open(
379+
Strings.General.QuitPrompt,
380+
Strings.General.QuitTitle,
381+
AlertType.Warning,
382+
inputType: InputType.YesNo,
383+
handleSubmit: (_, _) =>
384+
{
385+
Globals.IsRunning = false;
386+
}
387+
);
388+
}
389+
}
401390

391+
private void TryExit(object sender, ExitingEventArgs args)
392+
{
402393
try
403394
{
404395
_updater?.Stop();

Intersect.Client.Framework/Gwen/Control/Base.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,12 @@ public bool IsHidden
861861

862862
private static void SetVisible(Base @this, bool value)
863863
{
864+
// Check if already disposed
865+
if (@this._disposed)
866+
{
867+
return;
868+
}
869+
864870
var wasVisibleInParent = @this._visible;
865871

866872
if (@this.GetType().Name == "VersionPanel")

Intersect.Client.Framework/Gwen/Control/WindowControl.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ private void Close(Base sender, EventArgs args)
273273
return;
274274
}
275275

276-
IsHidden = true;
276+
try
277+
{
278+
IsHidden = true;
279+
}
280+
catch (ObjectDisposedException)
281+
{
282+
// Canvas already disposed during shutdown, this is fine
283+
}
277284

278285
if (_modal != null)
279286
{

0 commit comments

Comments
 (0)