2 CLASS(XonoticPicker) EXTENDS(Item)
3 METHOD(XonoticPicker, configureXonoticPicker, void(entity))
4 METHOD(XonoticPicker, mousePress, float(entity, vector))
5 METHOD(XonoticPicker, mouseRelease, float(entity, vector))
6 METHOD(XonoticPicker, mouseMove, float(entity, vector))
7 METHOD(XonoticPicker, mouseDrag, float(entity, vector))
8 METHOD(XonoticPicker, keyDown, float(entity, float, float, float))
9 METHOD(XonoticPicker, draw, void(entity))
10 ATTRIB(XonoticPicker, focusable, float, 1)
11 ATTRIB(XonoticPicker, disabled, float, 0)
12 ATTRIB(XonoticPicker, alpha, float, 1)
13 ATTRIB(XonoticPicker, disabledAlpha, float, SKINALPHA_DISABLED)
15 ATTRIB(XonoticPicker, rows, float, 3)
16 ATTRIB(XonoticPicker, columns, float, 2)
18 METHOD(XonoticPicker, moveFocus, void(entity, vector, vector))
19 METHOD(XonoticPicker, cellSelect, void(entity))
20 METHOD(XonoticPicker, cellDraw, void(entity, vector, vector, float))
21 METHOD(XonoticPicker, cellIsValid, bool(entity, vector))
22 ATTRIB(XonoticPicker, realCellSize, vector, '0 0 0')
23 ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
24 ATTRIB(XonoticPicker, focusedCellTime, float, 0)
25 ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
26 ENDCLASS(XonoticPicker)
27 entity makeXonoticPicker();
32 entity makeXonoticPicker()
35 me = spawnXonoticPicker();
36 me.configureXonoticPicker(me);
40 void XonoticPicker_configureXonoticPicker(entity me)
42 me.realCellSize = eX / me.columns + eY / me.rows;
45 float XonoticPicker_mouseMove(entity me, vector coords)
47 vector prevFocusedCell = me.focusedCell;
48 me.focusedCell_x = floor(coords.x * me.columns);
49 me.focusedCell_y = floor(coords.y * me.rows);
51 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
52 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
54 me.focusedCell = '-1 -1 0';
58 if(me.focusedCell != prevFocusedCell)
59 me.focusedCellTime = time;
64 float XonoticPicker_mouseDrag(entity me, vector coords)
66 return me.mouseMove(me, coords);
69 float XonoticPicker_mousePress(entity me, vector coords)
71 me.mouseMove(me, coords);
73 if(me.focusedCell.x >= 0)
76 me.pressedCell = me.focusedCell;
82 float XonoticPicker_mouseRelease(entity me, vector coords)
87 me.mouseMove(me, coords);
89 if(me.focusedCell == me.pressedCell)
96 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
102 me.moveFocus(me, me.focusedCell, '-1 0 0');
105 case K_KP_RIGHTARROW:
106 me.moveFocus(me, me.focusedCell, '1 0 0');
110 me.moveFocus(me, me.focusedCell, '0 -1 0');
114 me.moveFocus(me, me.focusedCell, '0 1 0');
118 me.focusedCell = '0 0 0';
122 me.focusedCell_x = me.columns - 1;
123 me.focusedCell_y = me.rows - 1;
135 void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
137 me.focusedCell_x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
138 me.focusedCell_y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
140 if(me.focusedCell != initialCell) // Recursion break
141 if(!me.cellIsValid(me, me.focusedCell))
142 me.moveFocus(me, initialCell, step);
145 void XonoticPicker_cellSelect(entity me)
149 bool XonoticPicker_cellIsValid(entity me, vector cell)
154 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos, float highlightTime)
158 void XonoticPicker_draw(entity me)
162 me.focusable = !me.disabled;
166 draw_alpha *= me.disabledAlpha;
168 vector cell, cellPos;
172 for(cell_y = 0; cell.y < me.rows; ++cell.y)
174 cellPos_y = mod(cell.y, me.rows) / me.rows;
175 for(cell_x = 0; cell.x < me.columns; ++cell.x)
177 if(!me.cellIsValid(me, cell))
180 cellPos_x = mod(cell.x, me.columns) / me.columns;
182 if(cell == me.focusedCell && me.focused)
184 if(!me.pressed || me.focusedCell == me.pressedCell)
185 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, getHighlightAlpha(SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED, me.focusedCellTime));
188 me.cellDraw(me, cell, cellPos, (me.focusedCell == cell) ? me.focusedCellTime : 0);
194 SUPER(XonoticPicker).draw(me);