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"))
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;
- string str, hstr;
me.TR(me);
me.TD(me, 1, 2, makeXonoticTextLabel(0, _("Gameplay mutators:")));
me.TR(me);
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.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);
continue;
if(j & 1 == 0)
me.TR(me);
- str = w.netname;
- hstr = w.message;
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);
- 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);
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))
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);
}
--- /dev/null
+#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