]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make the quitButton a stand-alone entity
authorterencehill <piuntn@gmail.com>
Wed, 2 Jun 2021 14:21:22 +0000 (16:21 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 2 Jun 2021 14:21:22 +0000 (16:21 +0200)
15 files changed:
qcsrc/menu/menu.qh
qcsrc/menu/xonotic/_mod.inc
qcsrc/menu/xonotic/_mod.qh
qcsrc/menu/xonotic/dialog_multiplayer_create.qc
qcsrc/menu/xonotic/dialog_multiplayer_create.qh
qcsrc/menu/xonotic/dialog_multiplayer_join.qc
qcsrc/menu/xonotic/dialog_multiplayer_join.qh
qcsrc/menu/xonotic/dialog_quit.qc
qcsrc/menu/xonotic/dialog_quit.qh
qcsrc/menu/xonotic/dialog_singleplayer.qc
qcsrc/menu/xonotic/dialog_singleplayer.qh
qcsrc/menu/xonotic/quitbutton.qc [new file with mode: 0644]
qcsrc/menu/xonotic/quitbutton.qh [new file with mode: 0644]
qcsrc/menu/xonotic/util.qc
qcsrc/menu/xonotic/util.qh

index 239c66152e9dcca17a6af58583266968c0c5d267..2df331950848c1dcdab9c53b63d9ebd553a3cb9a 100644 (file)
@@ -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;
index e936a063ab36a9a3ddecd37b72c41d900cbcbdf3..8d37e048624d02621e96071bff9f0c66c5fc927d 100644 (file)
@@ -96,6 +96,7 @@
 #include <menu/xonotic/playerlist.qc>
 #include <menu/xonotic/playermodel.qc>
 #include <menu/xonotic/playlist.qc>
+#include <menu/xonotic/quitbutton.qc>
 #include <menu/xonotic/radiobutton.qc>
 #include <menu/xonotic/rootdialog.qc>
 #include <menu/xonotic/screenshotimage.qc>
index 726c84428694470b7bb9b89f0462ccafe8308054..7982295e90387480b66d83dcd4d3d9111096fed6 100644 (file)
@@ -96,6 +96,7 @@
 #include <menu/xonotic/playerlist.qh>
 #include <menu/xonotic/playermodel.qh>
 #include <menu/xonotic/playlist.qh>
+#include <menu/xonotic/quitbutton.qh>
 #include <menu/xonotic/radiobutton.qh>
 #include <menu/xonotic/rootdialog.qh>
 #include <menu/xonotic/screenshotimage.qh>
index 8b2873e5d9c5ab75ffbc12be0b74779c1b7051c4..7ca58a07af769afff4d67d6ed5ca85b499a5309f 100644 (file)
@@ -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;
index 15bceb10da83ee07727f194ecf2da67e861d52dd..e275522864a84ee9af820e0cb6f55f7323df9efb 100644 (file)
@@ -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));
index 2c08476012d7c2975a10584c7ababdf225ee34c0..9f05d0c2a1ed91e9a479435d275264beaf979377 100644 (file)
@@ -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;
index 33f63209e3bc2907690748109bd70ed470482663..a663eb527be116ba9e0b75bf953e6aba47f2dc2c 100644 (file)
@@ -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);
index dbab87aad3bda99b6ff2c15d98ec1680e2e72fa7..fcf937c6bf5ef313bf77102ec4ca1a50b2cd6ce7 100644 (file)
@@ -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));
index 511422dc645f97acf60a9b89d43b81b4675392f3..59b4752ac2aa9259c5fbfa3e10fdbe196e072896 100644 (file)
@@ -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);
index 41b5c9f55ae29475409f763a7e09000c57ad37a7..e310e69d2559a14d57c9ea6add70ed41245003e5 100644 (file)
@@ -3,6 +3,7 @@
 #include <common/gamemodes/_mod.qh>
 #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;
index 54dda8837a4ec3f9524e6fcd29099ab2f2370ac1..c7691fbba4e16ba81eb483b8c0f748c9e6d4f2ba 100644 (file)
@@ -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 (file)
index 0000000..757f086
--- /dev/null
@@ -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 (file)
index 0000000..f23e9dc
--- /dev/null
@@ -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);
index 5d5b2d166edd5758918c8e7850f9cffa83662b13..7064dc8db2a9931b6d42c524afd98301226f9cf2 100644 (file)
@@ -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)
index 4fa6e66db1d06ccd23010d3e26b715887d43716f..5ad84cb7a8bd2ad5474c4177b04bc45c3478697d 100644 (file)
@@ -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;