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