]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/crosshairpicker.qc
f79cea51b4ae73c11cf42b603d009a40338c10e9
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / crosshairpicker.qc
1 #ifdef INTERFACE
2 CLASS(XonoticCrosshairPicker) EXTENDS(XonoticPicker)
3         METHOD(XonoticCrosshairPicker, configureXonoticCrosshairPicker, void(entity))
4
5         ATTRIB(XonoticCrosshairPicker, rows, float, 3)
6         ATTRIB(XonoticCrosshairPicker, columns, float, 12)
7
8         METHOD(XonoticCrosshairPicker, cellSelect, void(entity))
9         METHOD(XonoticCrosshairPicker, cellIsValid, bool(entity, vector))
10         METHOD(XonoticCrosshairPicker, cellDraw, void(entity, vector, vector, float))
11 ENDCLASS(XonoticCrosshairPicker)
12 entity makeXonoticCrosshairPicker();
13 #endif
14
15 #ifdef IMPLEMENTATION
16
17 string crosshairpicker_cellToCrosshair(entity me, vector cell)
18 {
19         float crosshair = 31 + cell.y * me.columns + cell.x;
20
21         if (crosshair >= 31 && crosshair < 31 + me.columns * me.rows)
22                 return ftos(crosshair);
23         else
24                 return "";
25 }
26
27 entity makeXonoticCrosshairPicker()
28 {
29         entity me;
30         me = spawnXonoticCrosshairPicker();
31         me.configureXonoticCrosshairPicker(me);
32         return me;
33 }
34
35 void XonoticCrosshairPicker_configureXonoticCrosshairPicker(entity me)
36 {
37         me.configureXonoticPicker(me);
38 }
39
40 void XonoticCrosshairPicker_cellSelect(entity me)
41 {
42         cvar_set("crosshair", crosshairpicker_cellToCrosshair(me, me.focusedCell));
43 }
44
45 bool XonoticCrosshairPicker_cellIsValid(entity me, vector cell)
46 {
47         if(crosshairpicker_cellToCrosshair(me, cell) == "")
48                 return false;
49         return true;
50 }
51
52 void XonoticCrosshairPicker_cellDraw(entity me, vector cell, vector cellPos, float highlightedTime)
53 {
54         vector sz, rgb;
55         string cross = strcat("/gfx/crosshair", crosshairpicker_cellToCrosshair(me, cell));
56         sz = draw_PictureSize(cross);
57         sz = globalToBoxSize(sz, me.size);
58
59         float ar = sz.x / sz.y;
60         sz.x = me.realCellSize.x;
61         sz.y = sz.x / ar;
62         sz = sz * 0.95;
63
64         rgb = '1 1 1';
65
66         vector crosshairPos = cellPos + 0.5 * me.realCellSize;
67         draw_Picture(crosshairPos - 0.5 * sz, cross, sz, rgb, me.alpha);
68
69         if(cvar("crosshair_dot"))
70                 draw_Picture(crosshairPos - 0.5 * sz * cvar("crosshair_dot_size"), "/gfx/crosshairdot", sz * cvar("crosshair_dot_size"), rgb, me.alpha);
71 }
72 #endif