#ifdef INTERFACE CLASS(VoretRadioButton) EXTENDS(RadioButton) METHOD(VoretRadioButton, configureVoretRadioButton, void(entity, float, string, string, string)) METHOD(VoretRadioButton, draw, void(entity)) METHOD(VoretRadioButton, setChecked, void(entity, float)) ATTRIB(VoretRadioButton, fontSize, float, SKINFONTSIZE_NORMAL) ATTRIB(VoretRadioButton, image, string, SKINGFX_RADIOBUTTON) ATTRIB(VoretRadioButton, color, vector, SKINCOLOR_RADIOBUTTON_N) ATTRIB(VoretRadioButton, colorC, vector, SKINCOLOR_RADIOBUTTON_C) ATTRIB(VoretRadioButton, colorF, vector, SKINCOLOR_RADIOBUTTON_F) ATTRIB(VoretRadioButton, colorD, vector, SKINCOLOR_RADIOBUTTON_D) ATTRIB(VoretRadioButton, cvarName, string, string_null) ATTRIB(VoretRadioButton, cvarValue, string, string_null) ATTRIB(VoretRadioButton, cvarOffValue, string, string_null) METHOD(VoretRadioButton, loadCvars, void(entity)) METHOD(VoretRadioButton, saveCvars, void(entity)) ATTRIB(VoretRadioButton, alpha, float, SKINALPHA_TEXT) ATTRIB(VoretRadioButton, disabledAlpha, float, SKINALPHA_DISABLED) ENDCLASS(VoretRadioButton) entity makeVoretRadioButton(float, string, string, string); #endif #ifdef IMPLEMENTATION entity makeVoretRadioButton(float theGroup, string theCvar, string theValue, string theText) { entity me; me = spawnVoretRadioButton(); me.configureVoretRadioButton(me, theGroup, theCvar, theValue, theText); return me; } void configureVoretRadioButtonVoretRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText) { if(theCvar) { me.cvarName = theCvar; me.cvarValue = theValue; me.tooltip = getZonedTooltipForIdentifier(theCvar); me.loadCvars(me); } me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0); } void setCheckedVoretRadioButton(entity me, float val) { if(val != me.checked) { me.checked = val; me.saveCvars(me); } } void loadCvarsVoretRadioButton(entity me) { if(me.cvarValue) { if(me.cvarName) me.checked = (cvar_string(me.cvarName) == me.cvarValue); } else { if(me.cvarName) { me.checked = !!cvar(me.cvarName); } else { // this is difficult // this is the "generic" selection... but at this time, not // everything is constructed yet. // we need to set this later in draw() me.checked = 0; } } } void drawVoretRadioButton(entity me) { if not(me.cvarValue) if not(me.cvarName) { // this is the "other" option // always select this if none other is entity e; float found; found = 0; for(e = me.parent.firstChild; e; e = e.nextSibling) if(e.group == me.group) if(e.checked) found = 1; if(!found) me.setChecked(me, 1); } drawCheckBox(me); } void saveCvarsVoretRadioButton(entity me) { if(me.cvarValue) { if(me.cvarName) { if(me.checked) cvar_set(me.cvarName, me.cvarValue); else if(me.cvarOffValue) cvar_set(me.cvarName, me.cvarOffValue); } } else { if(me.cvarName) { cvar_set(me.cvarName, ftos(me.checked)); } } } #endif