4 CLASS(XonoticPicker, Item)
5 METHOD(XonoticPicker, configureXonoticPicker, void(entity))
6 METHOD(XonoticPicker, mousePress, float(entity, vector))
7 METHOD(XonoticPicker, mouseRelease, float(entity, vector))
8 METHOD(XonoticPicker, mouseMove, float(entity, vector))
9 METHOD(XonoticPicker, mouseDrag, float(entity, vector))
10 METHOD(XonoticPicker, keyDown, float(entity, float, float, float))
11 METHOD(XonoticPicker, draw, void(entity))
12 ATTRIB(XonoticPicker, focusable, float, 1)
13 ATTRIB(XonoticPicker, disabled, float, 0)
14 ATTRIB(XonoticPicker, alpha, float, 1)
15 ATTRIB(XonoticPicker, disabledAlpha, float, SKINALPHA_DISABLED)
17 ATTRIB(XonoticPicker, rows, float, 3)
18 ATTRIB(XonoticPicker, columns, float, 2)
20 METHOD(XonoticPicker, moveFocus, void(entity, vector, vector))
21 METHOD(XonoticPicker, cellSelect, void(entity, vector))
22 METHOD(XonoticPicker, cellDraw, void(entity, vector, vector))
23 METHOD(XonoticPicker, cellIsValid, bool(entity, vector))
24 ATTRIB(XonoticPicker, realCellSize, vector, '0 0 0')
25 ATTRIB(XonoticPicker, selectedCell, vector, '-1 -1 0')
26 ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
27 ATTRIB(XonoticPicker, focusedCellAlpha, float, 0)
28 ATTRIB(XonoticPicker, focusedCellTime, float, 0)
29 ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
30 ENDCLASS(XonoticPicker)
31 entity makeXonoticPicker();
36 entity makeXonoticPicker()
39 me = NEW(XonoticPicker);
40 me.configureXonoticPicker(me);
44 void XonoticPicker_configureXonoticPicker(entity me)
46 me.realCellSize = eX / me.columns + eY / me.rows;
49 float XonoticPicker_mouseMove(entity me, vector coords)
51 vector prevFocusedCell = me.focusedCell;
52 me.focusedCell_x = floor(coords.x * me.columns);
53 me.focusedCell_y = floor(coords.y * me.rows);
55 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
56 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
58 me.focusedCell = '-1 -1 0';
62 if(me.focusedCell != prevFocusedCell)
63 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
68 float XonoticPicker_mouseDrag(entity me, vector coords)
70 return me.mouseMove(me, coords);
73 float XonoticPicker_mousePress(entity me, vector coords)
75 me.mouseMove(me, coords);
77 if(me.focusedCell.x >= 0)
80 me.pressedCell = me.focusedCell;
86 float XonoticPicker_mouseRelease(entity me, vector coords)
91 me.mouseMove(me, coords);
93 if(me.focusedCell == me.pressedCell)
94 me.cellSelect(me, me.focusedCell);
100 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
106 // lower left cell then left arrow to select the last valid cell
107 me.focusedCell = eY * (me.rows - 1);
110 me.moveFocus(me, me.focusedCell, '-1 0 0');
114 // upper right cell then right arrow to select the first valid cell
115 me.focusedCell = eX * (me.columns - 1);
117 case K_KP_RIGHTARROW:
118 me.moveFocus(me, me.focusedCell, '1 0 0');
122 me.moveFocus(me, me.focusedCell, '0 -1 0');
126 me.moveFocus(me, me.focusedCell, '0 1 0');
132 me.cellSelect(me, me.focusedCell);
138 void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
140 me.focusedCell_x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
141 me.focusedCell_y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
143 if(me.focusedCell != initialCell) // Recursion break
144 if(!me.cellIsValid(me, me.focusedCell))
145 me.moveFocus(me, initialCell, step);
147 me.focusedCellAlpha = SKINALPHA_LISTBOX_FOCUSED;
150 void XonoticPicker_cellSelect(entity me, vector cell)
152 me.selectedCell = cell;
155 bool XonoticPicker_cellIsValid(entity me, vector cell)
160 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos)
164 void XonoticPicker_draw(entity me)
168 me.focusable = !me.disabled;
172 draw_alpha *= me.disabledAlpha;
174 vector cell, cellPos;
178 for(cell_y = 0; cell.y < me.rows; ++cell.y)
180 cellPos_y = mod(cell.y, me.rows) / me.rows;
181 for(cell_x = 0; cell.x < me.columns; ++cell.x)
183 if(!me.cellIsValid(me, cell))
186 cellPos_x = mod(cell.x, me.columns) / me.columns;
188 if(cell == me.selectedCell)
189 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
190 else if(cell == me.focusedCell && me.focused)
192 if(!me.pressed || me.focusedCell == me.pressedCell)
194 me.focusedCellAlpha = getFadedAlpha(me.focusedCellAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
195 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, me.focusedCellAlpha);
199 me.cellDraw(me, cell, cellPos);
205 SUPER(XonoticPicker).draw(me);