]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/voret/inputbox.c
Tweak the system sound to use 0.5 as the default volume, instead of 1.0. This allows...
[voretournament/voretournament.git] / data / qcsrc / menu / voret / inputbox.c
1 #ifdef INTERFACE\r
2 CLASS(VoretInputBox) EXTENDS(InputBox)\r
3         METHOD(VoretInputBox, configureVoretInputBox, void(entity, float, string))\r
4         METHOD(VoretInputBox, focusLeave, void(entity))\r
5         METHOD(VoretInputBox, setText, void(entity, string))\r
6         ATTRIB(VoretInputBox, fontSize, float, SKINFONTSIZE_NORMAL)\r
7         ATTRIB(VoretInputBox, image, string, SKINGFX_INPUTBOX)\r
8         ATTRIB(VoretInputBox, onChange, void(entity, entity), SUB_Null)\r
9         ATTRIB(VoretInputBox, onChangeEntity, entity, NULL)\r
10         ATTRIB(VoretInputBox, onEnter, void(entity, entity), SUB_Null)\r
11         ATTRIB(VoretInputBox, onEnterEntity, entity, NULL)\r
12         ATTRIB(VoretInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)\r
13         ATTRIB(VoretInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)\r
14         ATTRIB(VoretInputBox, color, vector, SKINCOLOR_INPUTBOX_N)\r
15         ATTRIB(VoretInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)\r
16 \r
17         ATTRIB(VoretInputBox, alpha, float, SKINALPHA_TEXT)\r
18 \r
19         ATTRIB(VoretInputBox, cvarName, string, string_null)\r
20         METHOD(VoretInputBox, loadCvars, void(entity))\r
21         METHOD(VoretInputBox, saveCvars, void(entity))\r
22         METHOD(VoretInputBox, keyDown, float(entity, float, float, float))\r
23 ENDCLASS(VoretInputBox)\r
24 entity makeVoretInputBox(float, string);\r
25 #endif\r
26 \r
27 #ifdef IMPLEMENTATION\r
28 entity makeVoretInputBox(float doEditColorCodes, string theCvar)\r
29 {\r
30         entity me;\r
31         me = spawnVoretInputBox();\r
32         me.configureVoretInputBox(me, doEditColorCodes, theCvar);\r
33         return me;\r
34 }\r
35 void configureVoretInputBoxVoretInputBox(entity me, float doEditColorCodes, string theCvar)\r
36 {\r
37         me.configureInputBox(me, "", 0, me.fontSize, me.image);\r
38         me.editColorCodes = doEditColorCodes;\r
39         if(theCvar)\r
40         {\r
41                 me.cvarName = theCvar;\r
42                 me.tooltip = getZonedTooltipForIdentifier(theCvar);\r
43                 me.loadCvars(me);\r
44         }\r
45         me.cursorPos = strlen(me.text);\r
46 }\r
47 void focusLeaveVoretInputBox(entity me)\r
48 {\r
49         me.saveCvars(me);\r
50 }\r
51 void setTextVoretInputBox(entity me, string new)\r
52 {\r
53         if(me.text != new)\r
54         {\r
55                 setTextInputBox(me, new);\r
56                 me.onChange(me, me.onChangeEntity);\r
57         }\r
58         else\r
59                 setTextInputBox(me, new);\r
60 }\r
61 void loadCvarsVoretInputBox(entity me)\r
62 {\r
63         if not(me.cvarName)\r
64                 return;\r
65         setTextInputBox(me, cvar_string(me.cvarName));\r
66 }\r
67 void saveCvarsVoretInputBox(entity me)\r
68 {\r
69         if not(me.cvarName)\r
70                 return;\r
71         cvar_set(me.cvarName, me.text);\r
72 }\r
73 float keyDownVoretInputBox(entity me, float key, float ascii, float shift)\r
74 {\r
75         float r;\r
76         r = 0;\r
77         if(key == K_ENTER)\r
78         {\r
79                 if(me.cvarName)\r
80                 {\r
81                         me.saveCvars(me);\r
82                         r = 1;\r
83                 }\r
84                 me.onEnter(me, me.onEnterEntity);\r
85         }\r
86         if(keyDownInputBox(me, key, ascii, shift))\r
87                 r = 1;\r
88         return r;\r
89 }\r
90 #endif\r