@@ -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,58 @@ 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+ // Show combat warning
361+ AlertWindow . Open (
362+ Strings . Combat . WarningExitDesktop ,
363+ Strings . Combat . WarningTitle ,
364+ AlertType . Warning ,
365+ inputType : InputType . YesNo ,
366+ handleSubmit : ( _ , _ ) =>
367+ {
368+ if ( Globals . Me != null )
373369 {
374370 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- }
371+ }
398372
399- return ;
373+ Globals . IsRunning = false ;
374+ }
375+ ) ;
400376 }
377+ else
378+ {
379+ AlertWindow . Open (
380+ Strings . General . QuitPrompt ,
381+ Strings . General . QuitTitle ,
382+ AlertType . Warning ,
383+ inputType : InputType . YesNo ,
384+ handleSubmit : ( _ , _ ) =>
385+ {
386+ Globals . IsRunning = false ;
387+ }
388+ ) ;
389+ }
390+ }
401391
392+ private void TryExit ( object sender , ExitingEventArgs args )
393+ {
402394 try
403395 {
404396 _updater ? . Stop ( ) ;
0 commit comments