Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
picker.qc
Go to the documentation of this file.
1#include "picker.qh"
2
3.bool pressed;
4
6{
8 me.configureXonoticPicker(me);
9 return me;
10}
11
13{
14 me.realCellSize = eX / me.columns + eY / me.rows;
15}
16
18{
19 vector prevFocusedCell = me.focusedCell;
20 me.focusedCell.x = floor(coords.x * me.columns);
21 me.focusedCell.y = floor(coords.y * me.rows);
22
23 if (me.focusedCell.x < 0 || me.focusedCell.y < 0 || me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
24 {
25 me.focusedCell = '-1 -1 0';
26 return 0;
27 }
28
29 if (me.focusedCell != prevFocusedCell)
30 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
31
32 return 1;
33}
34
36{
37 return me.mouseMove(me, coords);
38}
39
41{
42 this.mouseMove(this, pos);
43
44 if (this.focusedCell.x >= 0)
45 {
46 this.pressed = 1;
47 this.pressedCell = this.focusedCell;
48 }
49
50 return true;
51}
52
54{
55 if (!me.pressed)
56 return 0;
57
58 me.mouseMove(me, coords);
59
60 if (me.focusedCell == me.pressedCell)
61 me.cellSelect(me, me.focusedCell);
62
63 me.pressed = 0;
64 return 1;
65}
66
67float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
68{
69 switch(key)
70 {
71 case K_END:
72 case K_KP_END:
73 // lower left cell then left arrow to select the last valid cell
74 me.focusedCell = eY * (me.rows - 1);
75 case K_LEFTARROW:
76 case K_KP_LEFTARROW:
77 me.moveFocus(me, me.focusedCell, '-1 0 0');
78 return 1;
79 case K_HOME:
80 case K_KP_HOME:
81 // upper right cell then right arrow to select the first valid cell
82 me.focusedCell = eX * (me.columns - 1);
83 case K_RIGHTARROW:
84 case K_KP_RIGHTARROW:
85 me.moveFocus(me, me.focusedCell, '1 0 0');
86 return 1;
87 case K_UPARROW:
88 case K_KP_UPARROW:
89 me.moveFocus(me, me.focusedCell, '0 -1 0');
90 return 1;
91 case K_DOWNARROW:
92 case K_KP_DOWNARROW:
93 me.moveFocus(me, me.focusedCell, '0 1 0');
94 return 1;
95 case K_ENTER:
96 case K_KP_ENTER:
97 case K_INS:
98 case K_KP_INS:
99 me.cellSelect(me, me.focusedCell);
100 return 1;
101 }
102 return 0;
103}
104
105void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
106{
107 me.focusedCell.x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
108 me.focusedCell.y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
109
110 if (me.focusedCell != initialCell && !me.cellIsValid(me, me.focusedCell))
111 me.moveFocus(me, initialCell, step);
112
113 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
114}
115
117{
118 me.selectedCell = cell;
119}
120
122{
123 return true;
124}
125
127{
128}
129
131{
132 me.focusable = !me.disabled;
133
134 float save = draw_alpha;
135 if (me.disabled)
136 draw_alpha *= me.disabledAlpha;
137
138 vector cell = '0 0 0';
139 vector cellPos = '0 0 0';
140
141 for (cell.y = 0; cell.y < me.rows; ++cell.y)
142 {
143 cellPos.y = mod(cell.y, me.rows) / me.rows;
144 for (cell.x = 0; cell.x < me.columns; ++cell.x)
145 {
146 if (!me.cellIsValid(me, cell))
147 continue;
148
149 cellPos.x = mod(cell.x, me.columns) / me.columns;
150
151 if (cell == me.selectedCell)
152 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
153 else if (cell == me.focusedCell && me.focused)
154 {
155 if (!me.pressed || me.focusedCell == me.pressedCell)
156 {
157 me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
158 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
159 }
160 }
161
162 me.cellDraw(me, cell, cellPos);
163 }
164 }
165
166 draw_alpha = save;
167
168 SUPER(XonoticPicker).draw(me);
169}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
vector pressedCell
Definition picker.qh:29
virtual void mousePress()
Definition picker.qc:40
vector focusedCell
Definition picker.qh:26
virtual void mouseMove()
float K_KP_RIGHTARROW
Definition keycodes.qc:60
float K_UPARROW
Definition keycodes.qc:15
float K_DOWNARROW
Definition keycodes.qc:16
float K_RIGHTARROW
Definition keycodes.qc:18
float K_KP_UPARROW
Definition keycodes.qc:64
float K_KP_LEFTARROW
Definition keycodes.qc:57
float K_ENTER
Definition keycodes.qc:8
float K_KP_HOME
Definition keycodes.qc:62
float K_KP_DOWNARROW
Definition keycodes.qc:53
float K_LEFTARROW
Definition keycodes.qc:17
float K_HOME
Definition keycodes.qc:41
float K_KP_ENTER
Definition keycodes.qc:74
float K_END
Definition keycodes.qc:42
float K_INS
Definition keycodes.qc:37
float K_KP_END
Definition keycodes.qc:51
float K_KP_INS
Definition keycodes.qc:49
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
float draw_alpha
Definition draw.qh:9
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:824
float mod(float val, float m)
float floor(float f)
#define NEW(cname,...)
Definition oo.qh:120
#define SUPER(cname)
Definition oo.qh:236
#define METHOD(cname, name, prototype)
Definition oo.qh:274
bool pressed
Definition picker.qc:3
entity makeXonoticPicker()
Definition picker.qc:5
void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
Definition picker.qc:126
float XonoticPicker_mouseDrag(entity me, vector coords)
Definition picker.qc:35
bool XonoticPicker_cellIsValid(entity me, vector cell)
Definition picker.qc:121
void XonoticPicker_draw(entity me)
Definition picker.qc:130
void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
Definition picker.qc:105
void XonoticPicker_configureXonoticPicker(entity me)
Definition picker.qc:12
float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
Definition picker.qc:67
float XonoticPicker_mouseRelease(entity me, vector coords)
Definition picker.qc:53
void XonoticPicker_cellSelect(entity me, vector cell)
Definition picker.qc:116
float XonoticPicker_mouseMove(entity me, vector coords)
Definition picker.qc:17
vector
Definition self.qh:96
const vector eY
Definition vector.qh:44
const vector eX
Definition vector.qh:43