]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/inputbox.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / inputbox.qc
1 #include "inputbox.qh"
2
3 entity makeXonoticInputBox_T(float doEditColorCodes, string theCvar, string theTooltip)
4 {
5         entity me;
6         me = NEW(XonoticInputBox);
7         me.configureXonoticInputBox(me, doEditColorCodes, theCvar, theTooltip);
8         return me;
9 }
10 entity makeXonoticInputBox(float doEditColorCodes, string theCvar)
11 {
12         return makeXonoticInputBox_T(doEditColorCodes, theCvar, string_null);
13 }
14 void XonoticInputBox_configureXonoticInputBox(entity me, float doEditColorCodes, string theCvar, string theTooltip)
15 {
16         me.configureInputBox(me, "", 0, me.fontSize, me.image);
17         me.editColorCodes = doEditColorCodes;
18         me.cvarName = (theCvar) ? theCvar : string_null;
19         me.loadCvars(me);
20         setZonedTooltip(me, theTooltip, theCvar);
21         me.cursorPos = strlen(me.text);
22 }
23 void XonoticInputBox_focusLeave(entity me)
24 {
25         me.saveCvars(me);
26 }
27 void XonoticInputBox_setText(entity me, string val)
28 {
29         if (me.text != val) {
30                 SUPER(XonoticInputBox).setText(me, val);
31                 if (me.onChange) {
32                         me.onChange(me, me.onChangeEntity);
33                 }
34                 if (me.saveImmediately) {
35                         me.saveCvars(me);
36                 }
37         } else {
38                 SUPER(XonoticInputBox).setText(me, val);
39         }
40 }
41 void XonoticInputBox_loadCvars(entity me)
42 {
43         if (!me.cvarName) {
44                 return;
45         }
46         SUPER(XonoticInputBox).setText(me, cvar_string(me.cvarName));
47 }
48 void XonoticInputBox_saveCvars(entity me)
49 {
50         if (!me.cvarName) {
51                 return;
52         }
53         cvar_set(me.cvarName, me.text);
54         CheckSendCvars(me, me.cvarName);
55 }
56 float XonoticInputBox_keyDown(entity me, float key, float ascii, float shift)
57 {
58         float r;
59         r = 0;
60         if (key == K_ENTER || key == K_KP_ENTER) {
61                 if (me.cvarName) {
62                         me.saveCvars(me);
63                         r = 1;
64                 }
65                 if (me.onEnter) {
66                         me.onEnter(me, me.onEnterEntity);
67                 }
68         }
69         if (SUPER(XonoticInputBox).keyDown(me, key, ascii, shift)) {
70                 r = 1;
71         }
72         return r;
73 }