]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add "Quit campaign" / "Quit current game" button to Singleplayer and Multiplayer...
authorterencehill <piuntn@gmail.com>
Mon, 3 May 2021 23:25:59 +0000 (01:25 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 3 May 2021 23:25:59 +0000 (01:25 +0200)
This way it's no longer possible to start a multiplayer game while the campaign settings are still visible in Multiplayer / Create window (these settings are temporary and won't be applied anyway)

qcsrc/menu/menu.qh
qcsrc/menu/xonotic/dialog_multiplayer_create.qc
qcsrc/menu/xonotic/dialog_multiplayer_create.qh
qcsrc/menu/xonotic/dialog_singleplayer.qc
qcsrc/menu/xonotic/dialog_singleplayer.qh
qcsrc/menu/xonotic/maplist.qc

index 2df331950848c1dcdab9c53b63d9ebd553a3cb9a..d4c8ea6baae8331c296e1350cb980fe3cd1f51f6 100644 (file)
@@ -15,6 +15,11 @@ const int GAME_DEVELOPER    = BIT(2);
 bool Menu_Active;
 int gamestatus;
 
+// resets g_campaign and updates menu items to reflect cvar values that may have been restored after leaving the campaign
+// the delay is for allowing listening to the button sound (if enabled), since the disconnect command stops all sounds
+// menu_sync is also useful when quitting Instant Action mode
+const string QUITGAME_CMD = "defer 0.4 disconnect; defer 0.4 wait; defer 0.4 \"g_campaign 0\"; defer 0.4 menu_sync";
+
 const int S_SHIFT = 1;
 const int S_CTRL = 2;
 const int S_ALT = 4;
index ba09c311e4bf0e3fbf99a69898bf91b7fb70e638..32cbd21ae6344c8e81042efb67d9fdbf74d34803 100644 (file)
@@ -64,6 +64,18 @@ entity makeXonoticServerCreateTab()
        return me;
 }
 
+.entity quitGameButton;
+void XonoticServerCreateTab_draw(entity me)
+{
+       entity e = me.quitGameButton;
+       e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED));
+       if(cvar("g_campaign"))
+               e.setText(e, _("Quit campaign"));
+       else
+               e.setText(e, _("Quit current game"));
+       SUPER(XonoticServerCreateTab).draw(me);
+}
+
 void XonoticServerCreateTab_fill(entity me)
 {
        entity e, e0;
@@ -200,10 +212,11 @@ void XonoticServerCreateTab_fill(entity me)
                        e.onClick = MapList_Remove_All;
                        e.onClickEntity = me.mapListBox;
 
-       // The big button at the bottom
-
+       // bottom row
        me.gotoRC(me, me.rows - 1, 0);
-               me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Multiplayer!"), '0 0 0'));
+               me.TDempty(me, me.columns * 1/12);
+               me.TD(me, 1, me.columns * 5/12, me.quitGameButton = makeXonoticCommandButton(string_null, '0 0 0', QUITGAME_CMD, 0));
+               me.TD(me, 1, me.columns * 5/12, e = makeXonoticButton(_("Start multiplayer!"), '0 0 0'));
                        e.onClick = MapList_LoadMap;
                        e.onClickEntity = me.mapListBox;
                        me.mapListBox.startButton = e;
index e275522864a84ee9af820e0cb6f55f7323df9efb..15bceb10da83ee07727f194ecf2da67e861d52dd 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "tab.qh"
 CLASS(XonoticServerCreateTab, XonoticTab)
+       METHOD(XonoticServerCreateTab, draw, void(entity));
        METHOD(XonoticServerCreateTab, fill, void(entity));
        METHOD(XonoticServerCreateTab, gameTypeChangeNotify, void(entity));
        METHOD(XonoticServerCreateTab, gameTypeSelectNotify, void(entity));
index a223f5807b318dd645f8441628a1b1e30bd50721..5a59dccde345da95619841ffdb4b81ce088cfdf6 100644 (file)
@@ -136,6 +136,18 @@ void InstantAction_LoadMap(entity btn, entity dummy)
        cvar_set("lastlevel", "1");
 }
 
+.entity quitGameButton;
+void XonoticSingleplayerDialog_draw(entity me)
+{
+       entity e = me.quitGameButton;
+       e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED));
+       if(cvar("g_campaign"))
+               e.setText(e, _("Quit campaign"));
+       else
+               e.setText(e, _("Quit current game"));
+       SUPER(XonoticSingleplayerDialog).draw(me);
+}
+
 void XonoticSingleplayerDialog_fill(entity me)
 {
        entity e, btnPrev, btnNext, lblTitle;
@@ -166,8 +178,11 @@ void XonoticSingleplayerDialog_fill(entity me)
                me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy"))));
                me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Medium"))));
                me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "2", ZCTX(_("CSKL^Hard"))));
-               me.TR(me);
-               me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0'));
+       me.TR(me);
+               me.TDempty(me, me.columns * 1/13);
+               me.TD(me, 1, me.columns * 5/13, me.quitGameButton = makeXonoticCommandButton(string_null, '0 0 0', QUITGAME_CMD, 0));
+               me.TDempty(me, me.columns * 1/13);
+               me.TD(me, 1, me.columns * 5/13, e = makeXonoticButton(_("Play campaign!"), '0 0 0'));
                        e.onClick = CampaignList_LoadMap;
                        e.onClickEntity = me.campaignBox;
 }
index c7691fbba4e16ba81eb483b8c0f748c9e6d4f2ba..54dda8837a4ec3f9524e6fcd29099ab2f2370ac1 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "dialog.qh"
 CLASS(XonoticSingleplayerDialog, XonoticDialog)
+       METHOD(XonoticSingleplayerDialog, draw, void(entity));
        METHOD(XonoticSingleplayerDialog, fill, void(entity));
        ATTRIB(XonoticSingleplayerDialog, title, string, _("Singleplayer"));
        ATTRIB(XonoticSingleplayerDialog, tooltip, string, _("Play the singleplayer campaign or instant action matches against bots"));
index a18037db63178830a7e85d675a66564cf01a7a47..72421150852367bb1379ccc6427cbef05cec4a37 100644 (file)
@@ -79,7 +79,8 @@ void XonoticMapList_g_maplistCacheToggle(entity me, float i)
 void XonoticMapList_draw(entity me)
 {
        if(me.startButton)
-               me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
+               me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems)
+                       || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED) && cvar("g_campaign")));
        SUPER(XonoticMapList).draw(me);
 }