2 CLASS(XonoticCrosshairButton) EXTENDS(RadioButton)
3 METHOD(XonoticCrosshairButton, configureXonoticCrosshairButton, void(entity, float, float))
4 METHOD(XonoticCrosshairButton, setChecked, void(entity, float))
5 METHOD(XonoticCrosshairButton, draw, void(entity))
6 ATTRIB(XonoticCrosshairButton, fontSize, float, SKINFONTSIZE_NORMAL)
7 ATTRIB(XonoticCrosshairButton, image, string, SKINGFX_CROSSHAIRBUTTON)
9 ATTRIB(XonoticCrosshairButton, useDownAsChecked, float, 1)
10 ATTRIB(XonoticCrosshairButton, src3, string, string_null)
11 ATTRIB(XonoticCrosshairButton, src4, string, string_null)
13 ATTRIB(XonoticCrosshairButton, cvarName, string, string_null)
14 ATTRIB(XonoticCrosshairButton, cvarValueFloat, float, 0)
15 METHOD(XonoticCrosshairButton, loadCvars, void(entity))
16 METHOD(XonoticCrosshairButton, saveCvars, void(entity))
17 ENDCLASS(XonoticCrosshairButton)
18 entity makeXonoticCrosshairButton(float, float);
22 entity makeXonoticCrosshairButton(float theGroup, float theCrosshair)
25 me = spawnXonoticCrosshairButton();
26 me.configureXonoticCrosshairButton(me, theGroup, theCrosshair);
29 void XonoticCrosshairButton_configureXonoticCrosshairButton(entity me, float theGroup, float theCrosshair)
31 me.cvarName = "crosshair";
32 me.cvarValueFloat = theCrosshair;
34 me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
36 if(me.cvarValueFloat == -1)
37 me.src3 = strzone(strcat("/gfx/crosshair", cvar("crosshair")));
39 me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat)));
40 me.src4 = "/gfx/crosshairdot";
42 void XonoticCrosshairButton_setChecked(entity me, float val)
44 if(me.cvarValueFloat != -1) // preview shouldn't work as a button
51 void XonoticCrosshairButton_loadCvars(entity me)
56 me.checked = (cvar(me.cvarName) == me.cvarValueFloat);
58 void XonoticCrosshairButton_saveCvars(entity me)
64 cvar_set(me.cvarName, ftos(me.cvarValueFloat));
65 // TODO on an apply button, read _cl_color and execute the color command for it
67 void XonoticCrosshairButton_draw(entity me)
72 rgb = stov(cvar_string("crosshair_color"));
73 a = cvar("crosshair_alpha");
75 if(!me.checked && !me.focused && me.cvarValueFloat != -1)
77 a *= me.disabledAlpha;
81 if(me.cvarValueFloat == -1) // update the preview if this is the preview button
85 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
90 SUPER(XonoticCrosshairButton).draw(me);
92 sz = draw_PictureSize(me.src3);
93 sz = globalToBoxSize(sz, draw_scale);
94 if(me.cvarValueFloat == -1)
96 sz = (6 * '1 1 0' + sz * cvar("crosshair_size")) * 0.08; // (6 * '1 1 0' + ...) * 0.08 here to make visible size changes happen also at bigger sizes
98 sz = sz * (0.95 / sz_x);
100 sz = sz * (0.95 / sz_y);
102 else // show the crosshair picker at full size
105 draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src3, sz, rgb, a);
106 if(cvar("crosshair_dot"))
108 if(cvar_string("crosshair_dot_color") != "0")
109 rgb = stov(cvar_string("crosshair_dot_color"));
110 draw_Picture('0.5 0.5 0' - 0.5 * sz * cvar("crosshair_dot_size"), me.src4, sz * cvar("crosshair_dot_size"), rgb, a * cvar("crosshair_dot_alpha"));