2 CLASS(XonoticCharmap) EXTENDS(Item)
3 METHOD(XonoticCharmap, configureXonoticCharmap, void(entity, entity))
4 METHOD(XonoticCharmap, mousePress, float(entity, vector))
5 METHOD(XonoticCharmap, mouseRelease, float(entity, vector))
6 METHOD(XonoticCharmap, mouseMove, float(entity, vector))
7 METHOD(XonoticCharmap, mouseDrag, float(entity, vector))
8 METHOD(XonoticCharmap, keyDown, float(entity, float, float, float))
9 METHOD(XonoticCharmap, focusLeave, void(entity))
10 METHOD(XonoticCharmap, resizeNotify, void(entity, vector, vector, vector, vector))
11 METHOD(XonoticCharmap, draw, void(entity))
12 ATTRIB(XonoticCharmap, focusable, float, 1)
14 METHOD(XonoticCharmap, moveFocus, void(entity, vector, vector))
15 METHOD(XonoticCharmap, enterChar, void(entity))
16 ATTRIB(XonoticCharmap, inputBox, entity, NULL)
17 ATTRIB(XonoticCharmap, realFontSize, vector, '0 0 0')
18 ATTRIB(XonoticCharmap, realCellSize, vector, '0 0 0')
19 ATTRIB(XonoticCharmap, focusedCell, vector, '-1 -1 0')
20 ATTRIB(XonoticCharmap, focusedCellTime, float, 0)
21 ATTRIB(XonoticCharmap, pressedCell, vector, '-1 -1 0')
22 ENDCLASS(XonoticCharmap)
23 entity makeXonoticCharmap(entity controlledInputBox);
28 const float CHARMAP_COLS = 14;
29 const float CHARMAP_ROWS = 10;
37 "\xEE\x83\xA1\xEE\x83\xA2\xEE\x83\xA3\xEE\x83\xA4\xEE\x83\xA5\xEE\x83\xA6\xEE\x83\xA7"
38 "\xEE\x83\xA8\xEE\x83\xA9\xEE\x83\xAA\xEE\x83\xAB\xEE\x83\xAC\xEE\x83\xAD\xEE\x83\xAE"
39 "\xEE\x83\xAF\xEE\x83\xB0\xEE\x83\xB1\xEE\x83\xB2\xEE\x83\xB3\xEE\x83\xB4\xEE\x83\xB5"
40 "\xEE\x83\xB6\xEE\x83\xB7\xEE\x83\xB8\xEE\x83\xB9\xEE\x83\xBA\xEE\x80\x90\xEE\x80\x91"
41 "\xEE\x82\xB0\xEE\x82\xB1\xEE\x82\xB2\xEE\x82\xB3\xEE\x82\xB4\xEE\x82\xB5\xEE\x82\xB6"
42 "\xEE\x82\xB7\xEE\x82\xB8\xEE\x82\xB9\xEE\x82\xA1\xEE\x82\xBF\xEE\x82\xA6\xEE\x82\xA5"
43 "\xEE\x83\x81\xEE\x83\x82\xEE\x83\x83\xEE\x83\x84\xEE\x83\x85\xEE\x83\x86\xEE\x83\x87"
44 "\xEE\x83\x88\xEE\x83\x89\xEE\x83\x8A\xEE\x83\x8B\xEE\x83\x8C\xEE\x83\x8D\xEE\x83\x8E"
45 "\xEE\x83\x8F\xEE\x83\x90\xEE\x83\x91\xEE\x83\x92\xEE\x83\x93\xEE\x83\x94\xEE\x83\x95"
46 "\xEE\x83\x96\xEE\x83\x97\xEE\x83\x98\xEE\x83\x99\xEE\x83\x9A\xEE\x81\x9B\xEE\x81\x9D";
48 string charmap_cellToChar(vector cell)
50 string character = substring(CHARMAP, cell.y * CHARMAP_COLS + cell.x, 1);
58 entity makeXonoticCharmap(entity controlledInputBox)
61 me = spawnXonoticCharmap();
62 me.configureXonoticCharmap(me, controlledInputBox);
66 void XonoticCharmap_configureXonoticCharmap(entity me, entity controlledInputBox)
68 me.inputBox = controlledInputBox;
69 me.realCellSize = eX / CHARMAP_COLS + eY / CHARMAP_ROWS;
72 void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
74 SUPER(XonoticCharmap).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
76 float maxFontWidth = SKINFONTSIZE_NORMAL / absSize.x;
77 float maxFontHeight = SKINFONTSIZE_NORMAL / absSize.y;
79 if((me.realCellSize.x * absSize.x) > (me.realCellSize.y * absSize.y))
81 me.realFontSize_x = me.realCellSize.y * absSize.y / absSize.x;
82 me.realFontSize_y = me.realCellSize.y;
86 me.realFontSize_x = me.realCellSize.x;
87 me.realFontSize_y = me.realCellSize.x * absSize.x / absSize.y;
90 if(me.realFontSize.x > maxFontWidth || me.realFontSize.y > maxFontHeight)
91 me.realFontSize = eX * maxFontWidth + eY * maxFontHeight;
94 float XonoticCharmap_mouseMove(entity me, vector coords)
96 vector prevFocusedCell = me.focusedCell;
97 me.focusedCell_x = floor(coords.x * CHARMAP_COLS);
98 me.focusedCell_y = floor(coords.y * CHARMAP_ROWS);
100 if(me.focusedCell.x < 0 || me.focusedCell.y < 0 ||
101 me.focusedCell.x >= CHARMAP_COLS || me.focusedCell.y >= CHARMAP_ROWS)
103 me.focusedCell = '-1 -1 0';
107 if(me.focusedCell != prevFocusedCell)
108 me.focusedCellTime = time;
113 float XonoticCharmap_mouseDrag(entity me, vector coords)
115 return me.mouseMove(me, coords);
118 float XonoticCharmap_mousePress(entity me, vector coords)
120 me.mouseMove(me, coords);
122 if(me.focusedCell.x >= 0)
125 me.pressedCell = me.focusedCell;
131 float XonoticCharmap_mouseRelease(entity me, vector coords)
136 me.mouseMove(me, coords);
138 if(me.focusedCell == me.pressedCell)
145 float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift)
151 me.moveFocus(me, me.focusedCell, '-1 0 0');
154 case K_KP_RIGHTARROW:
155 me.moveFocus(me, me.focusedCell, '1 0 0');
159 me.moveFocus(me, me.focusedCell, '0 -1 0');
163 me.moveFocus(me, me.focusedCell, '0 1 0');
167 me.focusedCell = '0 0 0';
171 me.focusedCell_x = CHARMAP_COLS - 1;
172 me.focusedCell_y = CHARMAP_ROWS - 1;
181 return me.inputBox.keyDown(me.inputBox, key, ascii, shift);
185 void XonoticCharmap_moveFocus(entity me, vector initialCell, vector step)
187 me.focusedCell_x = mod(me.focusedCell.x + step.x + CHARMAP_COLS, CHARMAP_COLS);
188 me.focusedCell_y = mod(me.focusedCell.y + step.y + CHARMAP_ROWS, CHARMAP_ROWS);
190 if(me.focusedCell != initialCell) // Recursion break
191 if(charmap_cellToChar(me.focusedCell) == "")
192 me.moveFocus(me, initialCell, step);
195 void XonoticCharmap_enterChar(entity me)
197 string character = charmap_cellToChar(me.focusedCell);
199 me.inputBox.enterText(me.inputBox, character);
202 void XonoticCharmap_focusLeave(entity me)
204 me.inputBox.saveCvars(me.inputBox);
207 void XonoticCharmap_draw(entity me)
210 vector cell, cellPos, charPos;
215 float CHAR_OFFSET_X = me.realCellSize.x / 2;
216 float CHAR_OFFSET_Y = (me.realCellSize.y - me.realFontSize.y) / 2;
218 for(cell_y = 0; cell.y < CHARMAP_ROWS; ++cell.y)
220 charPos_y = cell.y / CHARMAP_ROWS + CHAR_OFFSET_Y;
221 for(cell_x = 0; cell.x < CHARMAP_COLS; ++cell.x)
223 character = charmap_cellToChar(cell);
229 if(cell == me.focusedCell && me.focused)
231 if(!me.pressed || me.focusedCell == me.pressedCell)
233 cellPos_x = mod(me.focusedCell.x, CHARMAP_COLS) / CHARMAP_COLS;
234 cellPos_y = mod(me.focusedCell.y, CHARMAP_ROWS) / CHARMAP_ROWS;
235 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_LISTBOX_FOCUSED, getHighlightAlpha(SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED, me.focusedCellTime));
240 charPos_x = cell.x / CHARMAP_COLS + CHAR_OFFSET_X;
241 draw_CenterText(charPos, character, me.realFontSize, SKINCOLOR_CHARMAP_CHAR, SKINALPHA_CHARMAP_CHAR, 0);
244 SUPER(XonoticCharmap).draw(me);