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