From: terencehill Date: Tue, 23 Apr 2013 17:35:25 +0000 (+0200) Subject: Allow to select multiple weapons for weapon arena in the menu X-Git-Tag: xonotic-v0.7.0~67^2~7 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f6ca2b61500c9f8ab88964ee404cae8760c7ceac;p=xonotic%2Fxonotic-data.pk3dir.git Allow to select multiple weapons for weapon arena in the menu --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 2af290f9a..730517029 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -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". -// 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" diff --git a/qcsrc/menu/classes.c b/qcsrc/menu/classes.c index 0a3a55c5f..f00971674 100644 --- a/qcsrc/menu/classes.c +++ b/qcsrc/menu/classes.c @@ -43,6 +43,7 @@ #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" diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c index e4128235f..be9370bf4 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.c @@ -108,59 +108,6 @@ string XonoticMutatorsDialog_toString(entity me) 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")) @@ -187,12 +134,25 @@ float checkCompatibility_newtoys(entity me) 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); @@ -254,10 +214,11 @@ void XonoticMutatorsDialog_fill(entity 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); @@ -265,26 +226,12 @@ void XonoticMutatorsDialog_fill(entity me) 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); diff --git a/qcsrc/menu/xonotic/radiobutton.c b/qcsrc/menu/xonotic/radiobutton.c index 8c353eae6..4ac5aa7b1 100644 --- a/qcsrc/menu/xonotic/radiobutton.c +++ b/qcsrc/menu/xonotic/radiobutton.c @@ -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, getCvarValueFromCvar, float, 0) 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) - 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); } diff --git a/qcsrc/menu/xonotic/weaponarenacheckbox.c b/qcsrc/menu/xonotic/weaponarenacheckbox.c new file mode 100644 index 000000000..163f9c63b --- /dev/null +++ b/qcsrc/menu/xonotic/weaponarenacheckbox.c @@ -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