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, previouslyFocusedCell, vector, '-1 -1 0')
21 ENDCLASS(XonoticCharmap)
22 entity makeXonoticCharmap(entity controlledInputBox);
27 #define CHARMAP_COLS 14
28 #define CHARMAP_ROWS 10
31 "๐๐๐๐๐๐ฝ๐ซโโโโโโโ"
32 "โ โฃโขโโกโ๐ฅโโ โโฐโฑโฒโณ"
33 "โ
โโ โฎโฐโฌโฃโคโฅโขโโฒโถโผ"
34 "๐๐๐๐๐๐๐๐๐๐๐๐โค "
35 "๐๐๐๐ฎ๐ฒ๐๐๐ ๐ฃ๐ญ๐ต๐ด "
36 "๎ก๎ข๎ฃ๎ค๎ฅ๎ฆ๎ง๎จ๎ฉ๎ช๎ซ๎ฌ๎ญ๎ฎ"
37 "๎ฏ๎ฐ๎ฑ๎ฒ๎ณ๎ด๎ต๎ถ๎ท๎ธ๎น๎บ๎๎"
38 "๎ฐ๎ฑ๎ฒ๎ณ๎ด๎ต๎ถ๎ท๎ธ๎น๎ก๎ฟ๎ฆ๎ฅ"
39 "๎๎๎๎๎
๎๎๎๎๎๎๎๎๎"
40 "๎๎๎๎๎๎๎๎๎๎๎๎๎๎";
42 string charmap_cellToChar(vector cell)
44 string character = substring(CHARMAP, cell_y * CHARMAP_COLS + cell_x, 1);
52 entity makeXonoticCharmap(entity controlledInputBox)
55 me = spawnXonoticCharmap();
56 me.configureXonoticCharmap(me, controlledInputBox);
60 void XonoticCharmap_configureXonoticCharmap(entity me, entity controlledInputBox)
62 me.inputBox = controlledInputBox;
63 me.realCellSize = eX / CHARMAP_COLS + eY / CHARMAP_ROWS;
66 void XonoticCharmap_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
68 SUPER(XonoticCharmap).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
70 float maxFontWidth = SKINFONTSIZE_NORMAL / absSize_x;
71 float maxFontHeight = SKINFONTSIZE_NORMAL / absSize_y;
73 if((me.realCellSize_x * absSize_x) > (me.realCellSize_y * absSize_y))
75 me.realFontSize_x = me.realCellSize_y * absSize_y / absSize_x;
76 me.realFontSize_y = me.realCellSize_y;
80 me.realFontSize_x = me.realCellSize_x;
81 me.realFontSize_y = me.realCellSize_x * absSize_x / absSize_y;
84 if(me.realFontSize_x > maxFontWidth || me.realFontSize_y > maxFontHeight)
85 me.realFontSize = eX * maxFontWidth + eY * maxFontHeight;
88 float XonoticCharmap_mouseMove(entity me, vector coords)
90 me.focusedCell_x = floor(coords_x * CHARMAP_COLS);
91 me.focusedCell_y = floor(coords_y * CHARMAP_ROWS);
93 if(me.focusedCell_x < 0 || me.focusedCell_y < 0 ||
94 me.focusedCell_x >= CHARMAP_COLS || me.focusedCell_y >= CHARMAP_ROWS)
96 me.focusedCell = '-1 -1 0';
103 float XonoticCharmap_mouseDrag(entity me, vector coords)
105 return me.mouseMove(me, coords);
108 float XonoticCharmap_mousePress(entity me, vector coords)
110 me.mouseMove(me, coords);
112 if(me.focusedCell_x >= 0)
115 me.previouslyFocusedCell = me.focusedCell;
121 float XonoticCharmap_mouseRelease(entity me, vector coords)
126 me.mouseMove(me, coords);
128 if(me.focusedCell == me.previouslyFocusedCell)
135 float XonoticCharmap_keyDown(entity me, float key, float ascii, float shift)
141 me.moveFocus(me, me.focusedCell, '-1 0 0');
144 case K_KP_RIGHTARROW:
145 me.moveFocus(me, me.focusedCell, '1 0 0');
149 me.moveFocus(me, me.focusedCell, '0 -1 0');
153 me.moveFocus(me, me.focusedCell, '0 1 0');
157 me.focusedCell = '0 0 0';
161 me.focusedCell_x = CHARMAP_COLS - 1;
162 me.focusedCell_y = CHARMAP_ROWS - 1;
171 return me.inputBox.keyDown(me.inputBox, key, ascii, shift);
175 void XonoticCharmap_moveFocus(entity me, vector initialCell, vector step)
177 me.focusedCell_x = mod(me.focusedCell_x + step_x + CHARMAP_COLS, CHARMAP_COLS);
178 me.focusedCell_y = mod(me.focusedCell_y + step_y + CHARMAP_ROWS, CHARMAP_ROWS);
180 if(me.focusedCell != initialCell) // Recursion break
181 if(charmap_cellToChar(me.focusedCell) == "")
182 me.moveFocus(me, initialCell, step);
185 void XonoticCharmap_enterChar(entity me)
187 string character = charmap_cellToChar(me.focusedCell);
189 me.inputBox.enterText(me.inputBox, character);
192 void XonoticCharmap_focusLeave(entity me)
194 me.inputBox.saveCvars(me.inputBox);
197 void XonoticCharmap_draw(entity me)
200 vector cell, cellPos, charPos;
205 float CHAR_OFFSET_X = me.realCellSize_x / 2;
206 float CHAR_OFFSET_Y = (me.realCellSize_y - me.realFontSize_y) / 2;
208 for(cell_y = 0; cell_y < CHARMAP_ROWS; ++cell_y)
210 charPos_y = cell_y / CHARMAP_ROWS + CHAR_OFFSET_Y;
211 for(cell_x = 0; cell_x < CHARMAP_COLS; ++cell_x)
213 character = charmap_cellToChar(cell);
219 if(cell == me.focusedCell && me.focused)
221 if(!me.pressed || me.focusedCell == me.previouslyFocusedCell)
223 cellPos_x = mod(me.focusedCell_x, CHARMAP_COLS) / CHARMAP_COLS;
224 cellPos_y = mod(me.focusedCell_y, CHARMAP_ROWS) / CHARMAP_ROWS;
225 draw_Fill(cellPos, me.realCellSize, SKINCOLOR_CHARMAP_FOCUS, SKINALPHA_CHARMAP_FOCUS);
230 charPos_x = cell_x / CHARMAP_COLS + CHAR_OFFSET_X;
231 draw_CenterText(charPos, character, me.realFontSize, SKINCOLOR_CHARMAP_CHAR, SKINALPHA_CHARMAP_CHAR, 0);