]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/leavematchbutton.qc
Rename quitbutton.qc/qh files to leavematchbutton.qc/qh
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / leavematchbutton.qc
1 #include "leavematchbutton.qh"
2
3 // resets g_campaign and updates menu items to reflect cvar values that may have been restored after leaving the campaign
4 // the delay is for allowing listening to the button sound (if enabled), since the disconnect command stops all sounds
5 // menu_sync is also useful when quitting Instant Action mode
6 // see also m_draw
7 const string QUITGAME_CMD = "defer 0.4 disconnect; defer 0.4 wait; defer 0.4 \"g_campaign 0\"; defer 0.4 menu_sync\n";
8
9 string quitGameButton_getText(entity me)
10 {
11         if (me.disabled)
12                 return _("Quit current game");
13         else if(cvar("g_campaign"))
14                 return _("Quit campaign");
15         else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1")
16                 return _("Quit singleplayer");
17         else
18                 return _("Quit multiplayer");
19 }
20
21 string quitGameButton_getTooltip(entity me)
22 {
23         if (me.disabled)
24                 return "-";
25         else if(cvar("g_campaign"))
26                 return _("Quit current campaign level");
27         else if (cvar_string("net_address") == "127.0.0.1" && cvar_string("net_address_ipv6") == "::1")
28                 return _("Quit current singleplayer match");
29         else
30                 return _("Quit current multiplayer match / Disconnect from the server");
31 }
32
33 entity makeXonoticQuitButton(vector theColor, int theFlags)
34 {
35         entity me;
36         me = NEW(XonoticQuitButton);
37         me.configureXonoticQuitButton(me, theColor, theFlags);
38         return me;
39 }
40
41 void XonoticQuitButton_draw(entity me)
42 {
43         SUPER(XonoticCommandButton).draw(me);
44         me.disabled = !(gamestatus & (GAME_ISSERVER | GAME_CONNECTED));
45         me.setText(me, quitGameButton_getText(me));
46         setZonedTooltip(me, quitGameButton_getTooltip(me), string_null);
47 }
48
49 void XonoticQuitButton_configureXonoticQuitButton(entity me, vector theColor, int theFlags)
50 {
51         me.configureXonoticCommandButton(me, string_null, theColor, QUITGAME_CMD, theFlags, string_null);
52         me.draw = XonoticQuitButton_draw;
53 }