]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/crosshairbutton.qc
Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / crosshairbutton.qc
1 #ifdef INTERFACE
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)
8
9         ATTRIB(XonoticCrosshairButton, useDownAsChecked, float, 1)
10         ATTRIB(XonoticCrosshairButton, src3, string, string_null)
11         ATTRIB(XonoticCrosshairButton, src4, string, string_null)
12
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);
19 #endif
20
21 #ifdef IMPLEMENTATION
22 entity makeXonoticCrosshairButton(float theGroup, float theCrosshair)
23 {
24         entity me;
25         me = spawnXonoticCrosshairButton();
26         me.configureXonoticCrosshairButton(me, theGroup, theCrosshair);
27         return me;
28 }
29 void XonoticCrosshairButton_configureXonoticCrosshairButton(entity me, float theGroup, float theCrosshair)
30 {
31         me.cvarName = "crosshair";
32         me.cvarValueFloat = theCrosshair;
33         me.loadCvars(me);
34         me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
35         me.srcMulti = 1;
36         if(me.cvarValueFloat == -1)
37                 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
38         else
39                 me.src3 = strzone(strcat("/gfx/crosshair", ftos(me.cvarValueFloat)));
40         me.src4 = "/gfx/crosshairdot";
41 }
42 void XonoticCrosshairButton_setChecked(entity me, float val)
43 {
44         if(me.cvarValueFloat != -1) // preview shouldn't work as a button
45         if(val != me.checked)
46         {
47                 me.checked = val;
48                 me.saveCvars(me);
49         }
50 }
51 void XonoticCrosshairButton_loadCvars(entity me)
52 {
53         if (!me.cvarName)
54                 return;
55
56         me.checked = (cvar(me.cvarName) == me.cvarValueFloat);
57 }
58 void XonoticCrosshairButton_saveCvars(entity me)
59 {
60         if (!me.cvarName)
61                 return;
62
63         if(me.checked)
64                 cvar_set(me.cvarName, ftos(me.cvarValueFloat));
65         // TODO on an apply button, read _cl_color and execute the color command for it
66 }
67 void XonoticCrosshairButton_draw(entity me)
68 {
69         vector sz, rgb;
70         float a;
71
72
73         if(me.cvarValueFloat == -1)
74         {
75                 rgb = stov(cvar_string("crosshair_color"));
76                 a = cvar("crosshair_alpha");
77         }
78         else if(me.checked || me.focused)
79         {
80                 a = 1;
81                 rgb = '1 1 1';
82         }
83         else
84         {
85                 a = me.disabledAlpha;
86                 rgb = '1 1 1';
87         }
88
89         if(me.cvarValueFloat == -1) // update the preview if this is the preview button
90         {
91                 if(me.src3)
92                         strunzone(me.src3);
93                 me.src3 = strzone(strcat("/gfx/crosshair", cvar_string("crosshair")));
94                 me.focused = 1;
95                 me.checked = 0;
96         }
97
98         SUPER(XonoticCrosshairButton).draw(me);
99
100         sz = draw_PictureSize(me.src3);
101         sz = globalToBoxSize(sz, me.size);
102         if(me.cvarValueFloat == -1)
103         {
104                 sz = sz * cvar("crosshair_size"); // (6 * '1 1 0' + ...) * 0.08 here to make visible size changes happen also at bigger sizes
105                 /*
106                 if(sz_x > 0.95)
107                         sz = sz * (0.95 / sz_x);
108                 if(sz_y > 0.95)
109                         sz = sz * (0.95 / sz_y);
110                 */
111         }
112         else // show the crosshair picker at full size
113         {
114                 sz = sz * (0.95 / sz.x);
115                 if(sz.y > 0.95)
116                         sz = sz * (0.95 / sz.y);
117         }
118
119         draw_Picture('0.5 0.5 0' - 0.5 * sz, me.src3, sz, rgb, a);
120         if(cvar("crosshair_dot"))
121         {
122                 if(cvar("crosshair_dot_color_custom") && (cvar_string("crosshair_dot_color") != "0"))
123                         rgb = stov(cvar_string("crosshair_dot_color"));
124
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"));
126         }
127 }
128 #endif