From: terencehill Date: Mon, 3 May 2021 23:25:59 +0000 (+0200) Subject: Add "Quit campaign" / "Quit current game" button to Singleplayer and Multiplayer... X-Git-Tag: xonotic-v0.8.5~129^2~23 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7aee456c7b8ee7e92e4fb59cf51ac51e4f35cd71;p=xonotic%2Fxonotic-data.pk3dir.git Add "Quit campaign" / "Quit current game" button to Singleplayer and Multiplayer / Create windows to properly quit campaign, and also disable the "Start Multiplayer!" button while playing the campaign. 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) --- diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index 2df331950..d4c8ea6ba 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -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; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc index ba09c311e..32cbd21ae 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc @@ -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; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh index e27552286..15bceb10d 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh @@ -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)); diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qc b/qcsrc/menu/xonotic/dialog_singleplayer.qc index a223f5807..5a59dccde 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qc @@ -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; } diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qh b/qcsrc/menu/xonotic/dialog_singleplayer.qh index c7691fbba..54dda8837 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qh +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qh @@ -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")); diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index a18037db6..724211508 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -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); }