@@ -495,16 +495,77 @@ public override void ApplySchemeSettings(IScheme scheme) {
495495 SetTextInset ( 0 , 0 ) ;
496496 }
497497}
498+ public class SaveBeforeQuitQueryDialog : Frame
499+ {
500+ public SaveBeforeQuitQueryDialog ( Panel parent , ReadOnlySpan < char > name ) : base ( parent , name ) {
501+ LoadControlSettings ( "resource/SaveBeforeQuitDialog.res" ) ;
502+ SetDeleteSelfOnClose ( true ) ;
503+ SetSizeable ( false ) ;
504+ }
505+
506+ public override void DoModal ( ) {
507+ base . Activate ( ) ;
508+ Input . SetAppModalSurface ( this ) ;
509+ MoveToCenterOfScreen ( ) ;
510+ Surface . RestrictPaintToSinglePanel ( this ) ;
511+
512+ gameUI . PreventEngineHideGameUI ( ) ;
513+ }
514+
515+ public override void OnKeyCodeTyped ( ButtonCode code ) {
516+ if ( code == ButtonCode . KeyEscape )
517+ Close ( ) ;
518+ else
519+ base . OnKeyCodeTyped ( code ) ;
520+ }
521+
522+ public override void OnKeyCodePressed ( ButtonCode code ) {
523+ switch ( code ) {
524+ case ButtonCode . KeyXButtonB : Close ( ) ; break ;
525+ case ButtonCode . KeyXButtonA : OnCommand ( "SaveAndQuit" ) ; break ;
526+ case ButtonCode . KeyXButtonX : OnCommand ( "Quit" ) ; break ;
527+ default : base . OnKeyCodePressed ( code ) ; break ;
528+ }
529+ }
530+
531+ public override void OnCommand ( ReadOnlySpan < char > command ) {
532+ if ( 0 == stricmp ( command , "Quit" ) )
533+ PostMessage ( GetParent ( ) , new KeyValues ( "Command" , "command" , "QuitNoConfirm" ) ) ;
534+ else if ( 0 == stricmp ( command , "SaveAndQuit" ) ) {
535+ // find a new name to save
536+ Span < char > saveName = stackalloc char [ 128 ] ;
537+ // TODO: SaveGameDialog.FindSaveSlot(saveName, sizeof(saveName));
538+ // TODO: if (saveName[0] != '\0') {
539+ // TODO: // save the game
540+ // TODO: Span<char> sz = stackalloc char[256];
541+ // TODO: sprintf(sz, "save %s\n").S(saveName);
542+ // TODO: engine.ClientCmd_Unrestricted(sz.SliceNullTerminatedString());
543+ // TODO: }
544+
545+ // quit
546+ PostMessage ( GetParent ( ) , new KeyValues ( "Command" , "command" , "QuitNoConfirm" ) ) ;
547+ }
548+ else if ( 0 == stricmp ( command , "Cancel" ) )
549+ Close ( ) ;
550+ else
551+ base . OnCommand ( command ) ;
552+ }
553+
554+ public override void OnClose ( ) {
555+ base . OnClose ( ) ;
556+ Surface . RestrictPaintToSinglePanel ( null ) ;
557+ gameUI . AllowEngineHideGameUI ( ) ;
558+ }
559+ }
560+
498561public class QuitQueryBox : QueryBox
499562{
500563 public QuitQueryBox ( ReadOnlySpan < char > title , ReadOnlySpan < char > queryText , Panel ? parent = null ) : base ( title , queryText , parent ) { }
501564
502- IGameUI GameUI = Singleton < IGameUI > ( ) ;
503-
504565 public override void DoModal ( Frame ? frameOver ) {
505566 base . DoModal ( frameOver ) ;
506567 Surface . RestrictPaintToSinglePanel ( this ) ;
507- GameUI . PreventEngineHideGameUI ( ) ;
568+ gameUI . PreventEngineHideGameUI ( ) ;
508569 }
509570 public override void OnKeyCodeTyped ( ButtonCode code ) {
510571 if ( code == ButtonCode . KeyEscape )
@@ -515,15 +576,14 @@ public override void OnKeyCodeTyped(ButtonCode code) {
515576 public override void OnClose ( ) {
516577 base . OnClose ( ) ;
517578 Surface . RestrictPaintToSinglePanel ( null ) ;
518- GameUI . AllowEngineHideGameUI ( ) ;
579+ gameUI . AllowEngineHideGameUI ( ) ;
519580 }
520581}
521582public class BasePanel : Panel
522583{
523584 GameMenu ? GameMenu ;
524585
525586 readonly public IFileSystem FileSystem = Singleton < IFileSystem > ( ) ;
526- readonly public GameUI GameUI ;
527587 readonly public IEngineClient engine = Singleton < IEngineClient > ( ) ;
528588 readonly public ModInfo ModInfo = Singleton < ModInfo > ( ) ;
529589
@@ -587,7 +647,7 @@ private void RunMenuCommand(ReadOnlySpan<char> command) {
587647 engine . ClientCmd_Unrestricted ( "quit\n " ) ;
588648 break ;
589649 case "QuitRestartNoConfirm" : break ;
590- case "ResumeGame" : GameUI . HideGameUI ( ) ; break ;
650+ case "ResumeGame" : gameUI . HideGameUI ( ) ; break ;
591651 case "Disconnect" : engine . ClientCmd_Unrestricted ( "disconnect" ) ; break ;
592652 case "DisconnectNoConfirm" : break ;
593653 case "ReleaseModalWindow" : Surface . RestrictPaintToSinglePanel ( null ) ; break ;
@@ -635,12 +695,13 @@ public void PositionDialog(Panel? dialog) {
635695 }
636696
637697 public void OnOpenQuitConfirmationDialog ( ) {
638- if ( GameUI . IsConsoleUI ( ) ) {
698+ if ( gameUI . IsConsoleUI ( ) ) {
639699 throw new NotImplementedException ( ) ;
640700 }
641701
642- if ( GameUI . IsInLevel ( ) && engine . GetMaxClients ( ) == 1 ) {
643- throw new NotImplementedException ( ) ;
702+ if ( gameUI . IsInLevel ( ) && engine . GetMaxClients ( ) == 1 ) {
703+ SaveBeforeQuitQueryDialog box = new SaveBeforeQuitQueryDialog ( this , "SaveBeforeQuitQueryDialog" ) ;
704+ box . DoModal ( ) ;
644705 }
645706 else {
646707 QueryBox box = new QuitQueryBox ( "#GameUI_QuitConfirmationTitle" , "#GameUI_QuitConfirmationText" , this ) ;
@@ -660,8 +721,7 @@ static BackgroundMenuButton CreateMenuButton(BasePanel parent, ReadOnlySpan<char
660721 return button ;
661722 }
662723
663- public BasePanel ( GameUI gameUI ) : base ( null , "BaseGameUIPanel" ) {
664- GameUI = gameUI ;
724+ public BasePanel ( ) : base ( null , "BaseGameUIPanel" ) {
665725 g_BasePanel = this ;
666726 CreateGameMenu ( ) ;
667727 CreateGameLogo ( ) ;
@@ -677,7 +737,7 @@ public BasePanel(GameUI gameUI) : base(null, "BaseGameUIPanel") {
677737 IFont ? FontTest ;
678738
679739 public override void PaintBackground ( ) {
680- if ( ! GameUI . IsInLevel ( ) || GameUI . LoadingDialog != null || ExitingFrameCount > 0 )
740+ if ( ! gameUI . IsInLevel ( ) || GameUI . LoadingDialog != null || ExitingFrameCount > 0 )
681741 DrawBackgroundImage ( ) ;
682742
683743 if ( BackgroundFillAlpha > 0 ) {
@@ -753,9 +813,9 @@ public void SetBackgroundRenderState(BackgroundState state) {
753813 public void UpdateBackgroundState ( ) {
754814 if ( ExitingFrameCount != 0 )
755815 SetBackgroundRenderState ( BackgroundState . Exiting ) ;
756- else if ( GameUI . IsInLevel ( ) )
816+ else if ( gameUI . IsInLevel ( ) )
757817 SetBackgroundRenderState ( BackgroundState . Level ) ;
758- else if ( GameUI . IsInBackgroundLevel ( ) && ! LevelLoading )
818+ else if ( gameUI . IsInBackgroundLevel ( ) && ! LevelLoading )
759819 SetBackgroundRenderState ( BackgroundState . MainMenu ) ;
760820 else if ( LevelLoading )
761821 SetBackgroundRenderState ( BackgroundState . Loading ) ;
@@ -767,7 +827,7 @@ public void UpdateBackgroundState() {
767827
768828 int i ;
769829 bool haveActiveDialogs = false ;
770- bool isInLevel = GameUI . IsInLevel ( ) ;
830+ bool isInLevel = gameUI . IsInLevel ( ) ;
771831 for ( i = 0 ; i < GetChildCount ( ) ; ++ i ) {
772832 Panel ? child = GetChild ( i ) ;
773833 if ( child != null && child . IsVisible ( ) && child . IsPopup ( ) && child != GameMenu )
@@ -1030,7 +1090,7 @@ internal void OnGameUIActivated() {
10301090
10311091 int LastGameMenuState = - 1 ;
10321092 private void UpdateGameMenus ( ) {
1033- bool isInGame = GameUI . IsInLevel ( ) ;
1093+ bool isInGame = gameUI . IsInLevel ( ) ;
10341094 bool isMulti = isInGame && engine . GetMaxClients ( ) > 1 ;
10351095
10361096 int state = ( isInGame ? 1 : 0 ) | ( isMulti ? 2 : 0 ) ;
0 commit comments