]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow to select multiple weapons for weapon arena in the menu
authorterencehill <piuntn@gmail.com>
Tue, 23 Apr 2013 17:35:25 +0000 (19:35 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 23 Apr 2013 18:03:16 +0000 (20:03 +0200)
defaultXonotic.cfg
qcsrc/menu/classes.c
qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c
qcsrc/menu/xonotic/radiobutton.c
qcsrc/menu/xonotic/weaponarenacheckbox.c [new file with mode: 0644]

index 2af290f9abd445b5170f7af1c3ed86859b6d1a9a..7305170298205925dcc3a2da08c04386c8406f85 100644 (file)
@@ -989,8 +989,7 @@ seta menu_slist_showfull 1 "show servers even if they are full and have no slots
 seta menu_slist_showempty 1 "show servers even if they are no empty and have no opponents to play against"
 seta menu_slist_modfilter "" // set to either: !modname or modname. modname of = means "same as we are running now".
 
 seta menu_slist_showempty 1 "show servers even if they are no empty and have no opponents to play against"
 seta menu_slist_modfilter "" // set to either: !modname or modname. modname of = means "same as we are running now".
 
-// for menu weapon arena
-set menu_weaponarena_with_laser 0 "also enable the Laser in this weapon arena"
+seta menu_weaponarena ""
 
 seta menu_maxplayers 16 "maxplayers value when the menu starts a game"
 
 
 seta menu_maxplayers 16 "maxplayers value when the menu starts a game"
 
index 0a3a55c5f1d4bc214045b2c32731adac5779c156..f00971674ef8bca06675809fcc1526744450969b 100644 (file)
@@ -43,6 +43,7 @@
 #include "xonotic/slider_resolution.c"
 #include "xonotic/checkbox.c"
 #include "xonotic/checkbox_string.c"
 #include "xonotic/slider_resolution.c"
 #include "xonotic/checkbox.c"
 #include "xonotic/checkbox_string.c"
+#include "xonotic/weaponarenacheckbox.c"
 #include "xonotic/radiobutton.c"
 #include "xonotic/nexposee.c"
 #include "xonotic/rootdialog.c"
 #include "xonotic/radiobutton.c"
 #include "xonotic/nexposee.c"
 #include "xonotic/rootdialog.c"
index e4128235f2aece53fd9eb666c84db928668381c1..be9370bf4ef3c3d2f2383401116172f8a260d8bf 100644 (file)
@@ -108,59 +108,6 @@ string XonoticMutatorsDialog_toString(entity me)
                return substring(s, 2, strlen(s) - 2);
 }
 
                return substring(s, 2, strlen(s) - 2);
 }
 
-
-
-// WARNING: dirty hack. TODO clean this up by putting this behaviour in extra classes.
-void loadCvarsLaserWeaponArenaWeaponButton(entity me)
-{
-       tokenize_console(cvar_string("g_weaponarena"));
-       me.checked = (argv(0) == me.cvarValue);
-}
-
-void saveCvarsLaserWeaponArenaWeaponButton(entity me)
-{
-       string suffix;
-
-       suffix = "";
-       if(me.cvarValue != "laser" && me.cvarValue != "most")
-               if(cvar("menu_weaponarena_with_laser"))
-                       suffix = " laser";
-       if(me.checked)
-               cvar_set("g_weaponarena", strcat(me.cvarValue, suffix));
-       else
-               cvar_set("g_weaponarena", me.cvarOffValue);
-}
-
-.void(entity) draw_weaponarena;
-.void(entity) saveCvars_weaponarena;
-void saveCvarsLaserWeaponArenaLaserButton(entity me)
-{
-       // run the old function
-       me.saveCvars_weaponarena(me);
-
-       me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
-
-       if not(me.disabled)
-       {
-               // check for the laser suffix
-               string s;
-               s = cvar_string("g_weaponarena");
-               if(me.checked && substring(s, strlen(s) - 6, 6) != " laser")
-                       s = strcat(s, " laser");
-               else if(!me.checked && substring(s, strlen(s) - 6, 6) == " laser")
-                       s = substring(s, 0, strlen(s) - 6);
-               cvar_set("g_weaponarena", s);
-       }
-}
-
-void preDrawLaserWeaponArenaLaserButton(entity me)
-{
-       me.disabled = ((cvar_string("g_weaponarena") == "0") || (cvar_string("g_weaponarena") == "laser") || (cvar_string("g_weaponarena") == "most"));
-       // run the old function
-       me.draw_weaponarena(me);
-}
-// WARNING: end of dirty hack. Do not try this at home.
-
 float checkCompatibility_pinata(entity me)
 {
        if(cvar("g_minstagib"))
 float checkCompatibility_pinata(entity me)
 {
        if(cvar("g_minstagib"))
@@ -187,12 +134,25 @@ float checkCompatibility_newtoys(entity me)
                return 0;
        return 1;
 }
                return 0;
        return 1;
 }
+float checkCompatibility_weaponarena_weapon(entity me)
+{
+       if(cvar("g_minstagib"))
+               return 0;
+       if(cvar_string("g_weaponarena") == "most")
+               return 0;
+       if(cvar_string("g_weaponarena") == "all")
+               return 0;
+       if(cvar_string("g_weaponarena") == "0")
+               return 0;
+       if(cvar_string("g_start_weapon_laser") == "0")
+               return 0;
+       return 1;
+}
 
 void XonoticMutatorsDialog_fill(entity me)
 {
        entity e, s, w;
        float i, j;
 
 void XonoticMutatorsDialog_fill(entity me)
 {
        entity e, s, w;
        float i, j;
-       string str, hstr;
        me.TR(me);
                me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:")));
        me.TR(me);
        me.TR(me);
                me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:")));
        me.TR(me);
@@ -254,10 +214,11 @@ void XonoticMutatorsDialog_fill(entity me)
        me.TR(me);
 
        me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn);
        me.TR(me);
 
        me.gotoRC(me, 0, 2); me.setFirstColumn(me, me.currentColumn);
-               me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Weapon arenas:")));
+               me.TD(me, 1, 2, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)")));
        me.TR(me);
        me.TR(me);
-               me.TDempty(me, 0.2);
-               me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, string_null, string_null, _("Regular (no arena)")));
+               me.TD(me, 1, 2, e = makeXonoticRadioButton(1, "g_weaponarena", "menu_weaponarena", _("Weapon arenas:")));
+                       e.getCvarValueFromCvar = TRUE;
+                       e.cvarOffValue = "0";
        for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i)
        {
                w = get_weaponinfo(i);
        for(i = WEP_FIRST, j = 0; i <= WEP_LAST; ++i)
        {
                w = get_weaponinfo(i);
@@ -265,26 +226,12 @@ void XonoticMutatorsDialog_fill(entity me)
                        continue;
                if(j & 1 == 0)
                        me.TR(me);
                        continue;
                if(j & 1 == 0)
                        me.TR(me);
-               str = w.netname;
-               hstr = w.message;
                me.TDempty(me, 0.2);
                me.TDempty(me, 0.2);
-               me.TD(me, 1, 1.8, e = makeXonoticRadioButton(1, "g_weaponarena", strzone(str), strzone(hstr)));
-                       e.cvarOffValue = "0";
-                       // custom load/save logic that ignores a " laser" suffix, or adds it 
-                       e.loadCvars = loadCvarsLaserWeaponArenaWeaponButton;
-                       e.saveCvars = saveCvarsLaserWeaponArenaWeaponButton;
-                       e.loadCvars(e);
+               me.TD(me, 1, 1.8, e = makeXonoticWeaponarenaCheckBox(strzone(w.netname), strzone(w.message)));
+                       setDependentWeird(e, checkCompatibility_weaponarena_weapon);
                ++j;
        }
        me.TR(me);
                ++j;
        }
        me.TR(me);
-               me.TDempty(me, 0.2);
-               me.TD(me, 1, 1.8, e = makeXonoticCheckBox(0, "menu_weaponarena_with_laser", _("with laser")));
-                       // hook the draw function to gray it out
-                       e.draw_weaponarena = e.draw;
-                       e.draw = preDrawLaserWeaponArenaLaserButton;
-                       // hook the save function to notify about the cvar
-                       e.saveCvars_weaponarena = e.saveCvars;
-                       e.saveCvars = saveCvarsLaserWeaponArenaLaserButton;
        me.TR(me);
                me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:")));
        me.TR(me);
        me.TR(me);
                me.TD(me, 1, 4, makeXonoticTextLabel(0, _("Special arenas:")));
        me.TR(me);
index 8c353eae6725aec683419db78b88d6e3ce5274d5..4ac5aa7b188030dc40c316a4982d71370946d9bc 100644 (file)
@@ -13,6 +13,7 @@ CLASS(XonoticRadioButton) EXTENDS(RadioButton)
        ATTRIB(XonoticRadioButton, cvarName, string, string_null)
        ATTRIB(XonoticRadioButton, cvarValue, string, string_null)
        ATTRIB(XonoticRadioButton, cvarOffValue, string, string_null)
        ATTRIB(XonoticRadioButton, cvarName, string, string_null)
        ATTRIB(XonoticRadioButton, cvarValue, string, string_null)
        ATTRIB(XonoticRadioButton, cvarOffValue, string, string_null)
+       ATTRIB(XonoticRadioButton, getCvarValueFromCvar, float, 0)
        METHOD(XonoticRadioButton, loadCvars, void(entity))
        METHOD(XonoticRadioButton, saveCvars, void(entity))
 
        METHOD(XonoticRadioButton, loadCvars, void(entity))
        METHOD(XonoticRadioButton, saveCvars, void(entity))
 
@@ -98,7 +99,12 @@ void XonoticRadioButton_saveCvars(entity me)
                if(me.cvarName)
                {
                        if(me.checked)
                if(me.cvarName)
                {
                        if(me.checked)
-                               cvar_set(me.cvarName, me.cvarValue);
+                       {
+                               if(me.getCvarValueFromCvar)
+                                       cvar_set(me.cvarName, cvar_string(me.cvarValue));
+                               else
+                                       cvar_set(me.cvarName, me.cvarValue);
+                       }
                        else if(me.cvarOffValue)
                                cvar_set(me.cvarName, me.cvarOffValue);
                }
                        else if(me.cvarOffValue)
                                cvar_set(me.cvarName, me.cvarOffValue);
                }
diff --git a/qcsrc/menu/xonotic/weaponarenacheckbox.c b/qcsrc/menu/xonotic/weaponarenacheckbox.c
new file mode 100644 (file)
index 0000000..163f9c6
--- /dev/null
@@ -0,0 +1,57 @@
+#ifdef INTERFACE
+CLASS(XonoticWeaponarenaCheckBox) EXTENDS(CheckBox)
+       METHOD(XonoticWeaponarenaCheckBox, configureXonoticWeaponarenaCheckBox, void(entity, string, string))
+       METHOD(XonoticWeaponarenaCheckBox, setChecked, void(entity, float))
+       ATTRIB(XonoticWeaponarenaCheckBox, fontSize, float, SKINFONTSIZE_NORMAL)
+       ATTRIB(XonoticWeaponarenaCheckBox, image, string, SKINGFX_CHECKBOX)
+       ATTRIB(XonoticWeaponarenaCheckBox, netname, string, string_null)
+
+       METHOD(XonoticWeaponarenaCheckBox, loadCvars, void(entity))
+       METHOD(XonoticWeaponarenaCheckBox, saveCvars, void(entity))
+ENDCLASS(XonoticWeaponarenaCheckBox)
+entity makeXonoticWeaponarenaCheckBox(string, string);
+#endif
+
+#ifdef IMPLEMENTATION
+entity makeXonoticWeaponarenaCheckBox(string theWeapon, string theText)
+{
+       entity me;
+       me = spawnXonoticWeaponarenaCheckBox();
+       me.configureXonoticWeaponarenaCheckBox(me, theWeapon, theText);
+       return me;
+}
+void XonoticWeaponarenaCheckBox_configureXonoticWeaponarenaCheckBox(entity me, string theWeapon, string theText)
+{
+       me.netname = theWeapon;
+       me.checked = FALSE;
+       me.loadCvars(me);
+       me.configureCheckBox(me, theText, me.fontSize, me.image);
+}
+void XonoticWeaponarenaCheckBox_setChecked(entity me, float foo)
+{
+       me.checked = !me.checked;
+       me.saveCvars(me);
+}
+void XonoticWeaponarenaCheckBox_loadCvars(entity me)
+{
+       float n = tokenize_console(cvar_string("menu_weaponarena"));
+       float i;
+       for(i=0; i<n; ++i)
+       {
+               if(argv(i) == me.netname)
+               {
+                       me.checked = TRUE;
+                       break;
+               }
+       }
+}
+
+void XonoticWeaponarenaCheckBox_saveCvars(entity me)
+{
+       if(me.checked)
+               localcmd(strcat("\nmenu_cmd addtolist menu_weaponarena ", me.netname, "\n"));
+       else
+               localcmd(strcat("\nmenu_cmd removefromlist menu_weaponarena ", me.netname, "\n"));
+       localcmd("\ng_weaponarena \"$menu_weaponarena\"\n");
+}
+#endif