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_string("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)
73 if(me.cvarValueFloat == -1)
75 rgb = stov(cvar_string("crosshair_color"));
76 a = cvar("crosshair_alpha");
78 else if(me.checked || me.focused)
89 if(me.cvarValueFloat == -1) // update the preview if this is the preview button
93 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
98 SUPER(XonoticCrosshairButton).draw(me);
100 sz = draw_PictureSize(me.src3);
101 sz = globalToBoxSize(sz, me.size);
102 if(me.cvarValueFloat == -1)
104 sz = sz * cvar("crosshair_size"); // (6 * '1 1 0' + ...) * 0.08 here to make visible size changes happen also at bigger sizes
107 sz = sz * (0.95 / sz_x);
109 sz = sz * (0.95 / sz_y);
112 else // show the crosshair picker at full size
114 sz = sz * (0.95 / sz.x);
116 sz = sz * (0.95 / sz.y);
119 draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src3, sz, rgb, a);
120 if(cvar("crosshair_dot"))
122 if(cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0"))
123 rgb = stov(cvar_string("crosshair_dot_color"));
125 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"));