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, vector))
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, selectedCell, vector, '-1 -1 0')
24 ATTRIB(XonoticPicker, focusedCell, vector, '-1 -1 0')
25 ATTRIB(XonoticPicker, focusedCellTime, float, 0)
26 ATTRIB(XonoticPicker, pressedCell, vector, '-1 -1 0')
27 ENDCLASS(XonoticPicker)
28 entity makeXonoticPicker();
33 entity makeXonoticPicker()
36 me = spawnXonoticPicker();
37 me.configureXonoticPicker(me);
41 void XonoticPicker_configureXonoticPicker(entity me)
43 me.realCellSize = eX / me.columns + eY / me.rows;
46 float XonoticPicker_mouseMove(entity me, vector coords)
48 vector prevFocusedCell = me.focusedCell;
49 me.focusedCell_x = floor(coords.x * me.columns);
50 me.focusedCell_y = floor(coords.y * me.rows);
52 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
53 me.focusedCell.x >= me.columns || me.focusedCell.y >= me.rows)
55 me.focusedCell = '-1 -1 0';
59 if(me.focusedCell != prevFocusedCell)
60 me.focusedCellTime = time;
65 float XonoticPicker_mouseDrag(entity me, vector coords)
67 return me.mouseMove(me, coords);
70 float XonoticPicker_mousePress(entity me, vector coords)
72 me.mouseMove(me, coords);
74 if(me.focusedCell.x >= 0)
77 me.pressedCell = me.focusedCell;
83 float XonoticPicker_mouseRelease(entity me, vector coords)
88 me.mouseMove(me, coords);
90 if(me.focusedCell == me.pressedCell)
91 me.cellSelect(me, me.focusedCell);
97 float XonoticPicker_keyDown(entity me, float key, float ascii, float shift)
103 me.moveFocus(me, me.focusedCell, '-1 0 0');
106 case K_KP_RIGHTARROW:
107 me.moveFocus(me, me.focusedCell, '1 0 0');
111 me.moveFocus(me, me.focusedCell, '0 -1 0');
115 me.moveFocus(me, me.focusedCell, '0 1 0');
119 me.focusedCell = '0 0 0';
123 me.focusedCell_x = me.columns - 1;
124 me.focusedCell_y = me.rows - 1;
130 me.cellSelect(me, me.focusedCell);
136 void XonoticPicker_moveFocus(entity me, vector initialCell, vector step)
138 me.focusedCell_x = mod(me.focusedCell.x + step.x + me.columns, me.columns);
139 me.focusedCell_y = mod(me.focusedCell.y + step.y + me.rows, me.rows);
141 if(me.focusedCell != initialCell) // Recursion break
142 if(!me.cellIsValid(me, me.focusedCell))
143 me.moveFocus(me, initialCell, step);
146 void XonoticPicker_cellSelect(entity me, vector cell)
148 me.selectedCell = cell;
151 bool XonoticPicker_cellIsValid(entity me, vector cell)
156 void XonoticPicker_cellDraw(entity me, vector cell, vector cellPos, float highlightTime)
160 void XonoticPicker_draw(entity me)
164 me.focusable = !me.disabled;
168 draw_alpha *= me.disabledAlpha;
170 vector cell, cellPos;
174 for(cell_y = 0; cell.y < me.rows; ++cell.y)
176 cellPos_y = mod(cell.y, me.rows) / me.rows;
177 for(cell_x = 0; cell.x < me.columns; ++cell.x)
179 if(!me.cellIsValid(me, cell))
182 cellPos_x = mod(cell.x, me.columns) / me.columns;
184 if(cell == me.selectedCell)
185 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
186 else if(cell == me.focusedCell && me.focused)
188 if(!me.pressed || me.focusedCell == me.pressedCell)
189 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, getHighlightAlpha(SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED, me.focusedCellTime));
192 me.cellDraw(me, cell, cellPos, (me.focusedCell == cell) ? me.focusedCellTime : 0);
198 SUPER(XonoticPicker).draw(me);