From ad5b56a589f3919679aa8e6d336d55bbd0cc92f6 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 2 Jun 2021 16:21:22 +0200 Subject: [PATCH] Make the quitButton a stand-alone entity --- qcsrc/menu/menu.qh | 6 --- qcsrc/menu/xonotic/_mod.inc | 1 + qcsrc/menu/xonotic/_mod.qh | 1 + .../menu/xonotic/dialog_multiplayer_create.qc | 11 +--- .../menu/xonotic/dialog_multiplayer_create.qh | 1 - qcsrc/menu/xonotic/dialog_multiplayer_join.qc | 11 +--- qcsrc/menu/xonotic/dialog_multiplayer_join.qh | 1 - qcsrc/menu/xonotic/dialog_quit.qc | 20 +------ qcsrc/menu/xonotic/dialog_quit.qh | 1 - qcsrc/menu/xonotic/dialog_singleplayer.qc | 11 +--- qcsrc/menu/xonotic/dialog_singleplayer.qh | 1 - qcsrc/menu/xonotic/quitbutton.qc | 53 +++++++++++++++++++ qcsrc/menu/xonotic/quitbutton.qh | 9 ++++ qcsrc/menu/xonotic/util.qc | 24 --------- qcsrc/menu/xonotic/util.qh | 3 -- 15 files changed, 72 insertions(+), 82 deletions(-) create mode 100644 qcsrc/menu/xonotic/quitbutton.qc create mode 100644 qcsrc/menu/xonotic/quitbutton.qh diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index 239c66152..2df331950 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -15,12 +15,6 @@ 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 -// see also m_draw -const string QUITGAME_CMD = "defer 0.4 disconnect; defer 0.4 wait; defer 0.4 \"g_campaign 0\"; defer 0.4 menu_sync\n"; - const int S_SHIFT = 1; const int S_CTRL = 2; const int S_ALT = 4; diff --git a/qcsrc/menu/xonotic/_mod.inc b/qcsrc/menu/xonotic/_mod.inc index e936a063a..8d37e0486 100644 --- a/qcsrc/menu/xonotic/_mod.inc +++ b/qcsrc/menu/xonotic/_mod.inc @@ -96,6 +96,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/menu/xonotic/_mod.qh b/qcsrc/menu/xonotic/_mod.qh index 726c84428..7982295e9 100644 --- a/qcsrc/menu/xonotic/_mod.qh +++ b/qcsrc/menu/xonotic/_mod.qh @@ -96,6 +96,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc index 8b2873e5d..7ca58a07a 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qc @@ -14,6 +14,7 @@ #include "mainwindow.qh" #include "button.qh" #include "commandbutton.qh" +#include "quitbutton.qh" #include "inputbox.qh" void GameType_ConfigureSliders(entity me, string pLabel, float pMin, float pMax, float pStep, string pCvar, string tCvar, string pTooltip) @@ -66,14 +67,6 @@ entity makeXonoticServerCreateTab() } .entity quitGameButton; -void XonoticServerCreateTab_draw(entity me) -{ - entity e = me.quitGameButton; - e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)); - e.setText(e, quitGameButton_getText(e)); - setZonedTooltip(e, quitGameButton_getTooltip(e), string_null); - SUPER(XonoticServerCreateTab).draw(me); -} void XonoticServerCreateTab_fill(entity me) { @@ -218,7 +211,7 @@ void XonoticServerCreateTab_fill(entity me) // bottom row me.gotoRC(me, me.rows - 1, 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, me.quitGameButton = makeXonoticQuitButton('0 0 0', 0)); me.TD(me, 1, me.columns * 5/12, e = makeXonoticButton(_("Start multiplayer!"), '0 0 0')); e.onClick = MapList_LoadMap; e.onClickEntity = me.mapListBox; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh index 15bceb10d..e27552286 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create.qh @@ -2,7 +2,6 @@ #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_multiplayer_join.qc b/qcsrc/menu/xonotic/dialog_multiplayer_join.qc index 2c0847601..9f05d0c2a 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_join.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_join.qc @@ -6,6 +6,7 @@ #include "inputbox.qh" #include "checkbox.qh" #include "commandbutton.qh" +#include "quitbutton.qh" #include "button.qh" entity makeXonoticServerListTab() @@ -23,14 +24,6 @@ void XonoticServerListTab_refresh(entity this, entity slist) } .entity quitGameButton; -void XonoticServerListTab_draw(entity me) -{ - entity e = me.quitGameButton; - e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)); - e.setText(e, quitGameButton_getText(e)); - setZonedTooltip(e, quitGameButton_getTooltip(e), string_null); - SUPER(XonoticServerListTab).draw(me); -} void XonoticServerListTab_fill(entity me) { @@ -99,7 +92,7 @@ void XonoticServerListTab_fill(entity me) e.onClickEntity = slist; slist.infoButton = e; me.TR(me); - me.TD(me, 1, me.columns * 0.5, me.quitGameButton = makeXonoticCommandButton(string_null, '0 0 0', QUITGAME_CMD, 0)); + me.TD(me, 1, me.columns * 0.5, me.quitGameButton = makeXonoticQuitButton('0 0 0', 0)); me.TD(me, 1, me.columns * 0.5, e = makeXonoticButton(_("Join!"), '0 0 0')); e.onClick = ServerList_Connect_Click; e.onClickEntity = slist; diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_join.qh b/qcsrc/menu/xonotic/dialog_multiplayer_join.qh index 33f63209e..a663eb527 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_join.qh +++ b/qcsrc/menu/xonotic/dialog_multiplayer_join.qh @@ -3,7 +3,6 @@ #include "tab.qh" CLASS(XonoticServerListTab, XonoticTab) METHOD(XonoticServerListTab, fill, void(entity)); - METHOD(XonoticServerListTab, draw, void(entity)); ATTRIB(XonoticServerListTab, intendedWidth, float, 0.9); ATTRIB(XonoticServerListTab, rows, float, 23); ATTRIB(XonoticServerListTab, columns, float, 6.5); diff --git a/qcsrc/menu/xonotic/dialog_quit.qc b/qcsrc/menu/xonotic/dialog_quit.qc index dbab87aad..fcf937c6b 100644 --- a/qcsrc/menu/xonotic/dialog_quit.qc +++ b/qcsrc/menu/xonotic/dialog_quit.qc @@ -2,31 +2,15 @@ #include "textlabel.qh" #include "commandbutton.qh" +#include "quitbutton.qh" #include "button.qh" -void Disconnect_Click(entity btn, entity me) -{ - localcmd(QUITGAME_CMD); - Dialog_Close(btn, me); -} - -void XonoticQuitDialog_draw(entity me) -{ - entity e = me.disconnectButton; - e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)); - e.setText(e, quitGameButton_getText(e)); - setZonedTooltip(e, quitGameButton_getTooltip(e), string_null); - SUPER(XonoticQuitDialog).draw(me); -} - void XonoticQuitDialog_fill(entity me) { entity e; me.TR(me); me.TDempty(me, 0.5); - me.TD(me, 1, 1, me.disconnectButton = makeXonoticButton(string_null, '0 0 0')); - me.disconnectButton.onClick = Disconnect_Click; - me.disconnectButton.onClickEntity = me; + me.TD(me, 1, 1, me.disconnectButton = makeXonoticQuitButton('0 0 0', COMMANDBUTTON_CLOSE)); me.TR(me); me.TR(me); me.TD(me, 1, 1, e = makeXonoticCommandButton(_("Quit Xonotic"), '1 0 0', "echo ]quit; quit", 0)); diff --git a/qcsrc/menu/xonotic/dialog_quit.qh b/qcsrc/menu/xonotic/dialog_quit.qh index 511422dc6..59b4752ac 100644 --- a/qcsrc/menu/xonotic/dialog_quit.qh +++ b/qcsrc/menu/xonotic/dialog_quit.qh @@ -3,7 +3,6 @@ #include "dialog.qh" CLASS(XonoticQuitDialog, XonoticDialog) METHOD(XonoticQuitDialog, fill, void(entity)); - METHOD(XonoticQuitDialog, draw, void(entity)); ATTRIB(XonoticQuitDialog, title, string, _("Quit")); ATTRIB(XonoticQuitDialog, tooltip, string, _("Quit the game")); ATTRIB(XonoticQuitDialog, color, vector, SKINCOLOR_DIALOG_QUIT); diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qc b/qcsrc/menu/xonotic/dialog_singleplayer.qc index 41b5c9f55..e310e69d2 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qc @@ -3,6 +3,7 @@ #include #include "bigbutton.qh" #include "commandbutton.qh" +#include "quitbutton.qh" #include "radiobutton.qh" #include "textlabel.qh" #include "campaign.qh" @@ -140,14 +141,6 @@ void InstantAction_LoadMap(entity btn, entity dummy) } .entity quitGameButton; -void XonoticSingleplayerDialog_draw(entity me) -{ - entity e = me.quitGameButton; - e.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)); - e.setText(e, quitGameButton_getText(e)); - setZonedTooltip(e, quitGameButton_getTooltip(e), string_null); - SUPER(XonoticSingleplayerDialog).draw(me); -} void XonoticSingleplayerDialog_fill(entity me) { @@ -181,7 +174,7 @@ void XonoticSingleplayerDialog_fill(entity me) me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "2", ZCTX(_("CSKL^Hard")))); 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.TD(me, 1, me.columns * 5/13, me.quitGameButton = makeXonoticQuitButton('0 0 0', 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; diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qh b/qcsrc/menu/xonotic/dialog_singleplayer.qh index 54dda8837..c7691fbba 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qh +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qh @@ -2,7 +2,6 @@ #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/quitbutton.qc b/qcsrc/menu/xonotic/quitbutton.qc new file mode 100644 index 000000000..757f086c7 --- /dev/null +++ b/qcsrc/menu/xonotic/quitbutton.qc @@ -0,0 +1,53 @@ +#include "quitbutton.qh" + +// 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 +// see also m_draw +const string QUITGAME_CMD = "defer 0.4 disconnect; defer 0.4 wait; defer 0.4 \"g_campaign 0\"; defer 0.4 menu_sync\n"; + +string quitGameButton_getText(entity me) +{ + if (me.disabled) + return _("Quit current game"); + else if(cvar("g_campaign")) + return _("Quit campaign"); + else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1") + return _("Quit singleplayer"); + else + return _("Quit multiplayer"); +} + +string quitGameButton_getTooltip(entity me) +{ + if (me.disabled) + return "-"; + else if(cvar("g_campaign")) + return "-"; + else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1") + return "-"; + else + return _("Quit multiplayer / Disconnect from the server"); +} + +entity makeXonoticQuitButton(vector theColor, int theFlags) +{ + entity me; + me = NEW(XonoticQuitButton); + me.configureXonoticQuitButton(me, theColor, theFlags); + return me; +} + +void XonoticQuitButton_draw(entity me) +{ + SUPER(XonoticCommandButton).draw(me); + me.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)); + me.setText(me, quitGameButton_getText(me)); + setZonedTooltip(me, quitGameButton_getTooltip(me), string_null); +} + +void XonoticQuitButton_configureXonoticQuitButton(entity me, vector theColor, int theFlags) +{ + me.configureXonoticCommandButton(me, string_null, theColor, QUITGAME_CMD, theFlags, string_null); + me.draw = XonoticQuitButton_draw; +} diff --git a/qcsrc/menu/xonotic/quitbutton.qh b/qcsrc/menu/xonotic/quitbutton.qh new file mode 100644 index 000000000..f23e9dcfb --- /dev/null +++ b/qcsrc/menu/xonotic/quitbutton.qh @@ -0,0 +1,9 @@ +#pragma once + +#include "commandbutton.qh" +CLASS(XonoticQuitButton, XonoticCommandButton) + METHOD(XonoticQuitButton, draw, void(entity)); + METHOD(XonoticQuitButton, configureXonoticQuitButton, void(entity, vector, int)); +ENDCLASS(XonoticQuitButton) + +entity makeXonoticQuitButton(vector theColor, int theFlags); diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index 5d5b2d166..7064dc8db 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -823,30 +823,6 @@ void makeServerSingleplayer() localcmd("defer 0.1 \"sv_cmd settemp net_address_ipv6 ::1\"\n"); } -string quitGameButton_getText(entity btn) -{ - if (btn.disabled) - return _("Quit current game"); - else if(cvar("g_campaign")) - return _("Quit campaign"); - else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1") - return _("Quit singleplayer"); - else - return _("Quit multiplayer"); -} - -string quitGameButton_getTooltip(entity btn) -{ - if (btn.disabled) - return "-"; - else if(cvar("g_campaign")) - return "-"; - else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1") - return "-"; - else - return _("Quit multiplayer / Disconnect from the server"); -} - float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha) { if(startAlpha < targetAlpha) diff --git a/qcsrc/menu/xonotic/util.qh b/qcsrc/menu/xonotic/util.qh index 4fa6e66db..5ad84cb7a 100644 --- a/qcsrc/menu/xonotic/util.qh +++ b/qcsrc/menu/xonotic/util.qh @@ -40,9 +40,6 @@ void dialog_hudpanel_main_checkbox(entity me, string panelname); void dialog_hudpanel_main_settings(entity me, string panelname); void makeServerSingleplayer(); -string quitGameButton_getText(entity btn); -string quitGameButton_getTooltip(entity btn); - float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha); string _Nex_ExtResponseSystem_BannedServers; -- 2.39.2