]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/inputbox.qc
Unify boolean constants
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / inputbox.qc
1 #ifdef INTERFACE
2 CLASS(XonoticInputBox) EXTENDS(InputBox)
3         METHOD(XonoticInputBox, configureXonoticInputBox, void(entity, float, string))
4         METHOD(XonoticInputBox, focusLeave, void(entity))
5         METHOD(XonoticInputBox, setText, void(entity, string))
6         ATTRIB(XonoticInputBox, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(XonoticInputBox, image, string, SKINGFX_INPUTBOX)
8         ATTRIB(XonoticInputBox, onChange, void(entity, entity), func_null)
9         ATTRIB(XonoticInputBox, onChangeEntity, entity, NULL)
10         ATTRIB(XonoticInputBox, onEnter, void(entity, entity), func_null)
11         ATTRIB(XonoticInputBox, onEnterEntity, entity, NULL)
12         ATTRIB(XonoticInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)
13         ATTRIB(XonoticInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)
14         ATTRIB(XonoticInputBox, color, vector, SKINCOLOR_INPUTBOX_N)
15         ATTRIB(XonoticInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)
16
17         ATTRIB(XonoticInputBox, alpha, float, SKINALPHA_TEXT)
18
19         // Clear button attributes
20         ATTRIB(XonoticInputBox, cb_offset, float, SKINOFFSET_CLEARBUTTON) // bound to range -1, 0
21         ATTRIB(XonoticInputBox, cb_src, string, SKINGFX_CLEARBUTTON)
22         ATTRIB(XonoticInputBox, cb_color, vector, SKINCOLOR_CLEARBUTTON_N)
23         ATTRIB(XonoticInputBox, cb_colorF, vector, SKINCOLOR_CLEARBUTTON_F)
24         ATTRIB(XonoticInputBox, cb_colorC, vector, SKINCOLOR_CLEARBUTTON_C)
25
26         ATTRIB(XonoticInputBox, cvarName, string, string_null)
27         METHOD(XonoticInputBox, loadCvars, void(entity))
28         METHOD(XonoticInputBox, saveCvars, void(entity))
29         ATTRIB(XonoticInputBox, sendCvars, float, 0)
30         METHOD(XonoticInputBox, keyDown, float(entity, float, float, float))
31
32         ATTRIB(XonoticInputBox, saveImmediately, float, 0)
33 ENDCLASS(XonoticInputBox)
34 entity makeXonoticInputBox(float, string);
35 #endif
36
37 #ifdef IMPLEMENTATION
38 entity makeXonoticInputBox(float doEditColorCodes, string theCvar)
39 {
40         entity me;
41         me = spawnXonoticInputBox();
42         me.configureXonoticInputBox(me, doEditColorCodes, theCvar);
43         return me;
44 }
45 void XonoticInputBox_configureXonoticInputBox(entity me, float doEditColorCodes, string theCvar)
46 {
47         me.configureInputBox(me, "", 0, me.fontSize, me.image);
48         me.editColorCodes = doEditColorCodes;
49         if(theCvar)
50         {
51                 me.cvarName = theCvar;
52                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
53                 me.loadCvars(me);
54         }
55         me.cursorPos = strlen(me.text);
56 }
57 void XonoticInputBox_focusLeave(entity me)
58 {
59         me.saveCvars(me);
60 }
61 void XonoticInputBox_setText(entity me, string new)
62 {
63         if(me.text != new)
64         {
65                 SUPER(XonoticInputBox).setText(me, new);
66                 if(me.onChange)
67                         me.onChange(me, me.onChangeEntity);
68                 if(me.saveImmediately)
69                         me.saveCvars(me);
70         }
71         else
72                 SUPER(XonoticInputBox).setText(me, new);
73 }
74 void XonoticInputBox_loadCvars(entity me)
75 {
76         if (!me.cvarName)
77                 return;
78         SUPER(XonoticInputBox).setText(me, cvar_string(me.cvarName));
79 }
80 void XonoticInputBox_saveCvars(entity me)
81 {
82         if (!me.cvarName)
83                 return;
84         cvar_set(me.cvarName, me.text);
85         CheckSendCvars(me, me.cvarName);
86 }
87 float XonoticInputBox_keyDown(entity me, float key, float ascii, float shift)
88 {
89         float r;
90         r = 0;
91         if(key == K_ENTER || key == K_KP_ENTER)
92         {
93                 if(me.cvarName)
94                 {
95                         me.saveCvars(me);
96                         r = 1;
97                 }
98                 if(me.onEnter)
99                         me.onEnter(me, me.onEnterEntity);
100         }
101         if(SUPER(XonoticInputBox).keyDown(me, key, ascii, shift))
102                 r = 1;
103         return r;
104 }
105 #endif