@@ -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 ( ) ;
0 commit comments