]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/inputbox.c
Merge remote branch 'remotes/origin/terencehill/newpanelhud' into terencehill/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / inputbox.c
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), SUB_Null)
9         ATTRIB(XonoticInputBox, onChangeEntity, entity, NULL)
10         ATTRIB(XonoticInputBox, onEnter, void(entity, entity), SUB_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         ATTRIB(XonoticInputBox, cvarName, string, string_null)
20         METHOD(XonoticInputBox, loadCvars, void(entity))
21         METHOD(XonoticInputBox, saveCvars, void(entity))
22         METHOD(XonoticInputBox, keyDown, float(entity, float, float, float))
23 ENDCLASS(XonoticInputBox)
24 entity makeXonoticInputBox(float, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeXonoticInputBox(float doEditColorCodes, string theCvar)
29 {
30         entity me;
31         me = spawnXonoticInputBox();
32         me.configureXonoticInputBox(me, doEditColorCodes, theCvar);
33         return me;
34 }
35 void XonoticInputBox_configureXonoticInputBox(entity me, float doEditColorCodes, string theCvar)
36 {
37         me.configureInputBox(me, "", 0, me.fontSize, me.image);
38         me.editColorCodes = doEditColorCodes;
39         if(theCvar)
40         {
41                 me.cvarName = theCvar;
42                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
43                 me.loadCvars(me);
44         }
45         me.cursorPos = strlen(me.text);
46 }
47 void XonoticInputBox_focusLeave(entity me)
48 {
49         me.saveCvars(me);
50 }
51 void XonoticInputBox_setText(entity me, string new)
52 {
53         if(me.text != new)
54         {
55                 SUPER(XonoticInputBox).setText(me, new);
56                 me.onChange(me, me.onChangeEntity);
57         }
58         else
59                 SUPER(XonoticInputBox).setText(me, new);
60 }
61 void XonoticInputBox_loadCvars(entity me)
62 {
63         if not(me.cvarName)
64                 return;
65         SUPER(XonoticInputBox).setText(me, cvar_string(me.cvarName));
66 }
67 void XonoticInputBox_saveCvars(entity me)
68 {
69         if not(me.cvarName)
70                 return;
71         cvar_set(me.cvarName, me.text);
72 }
73 float XonoticInputBox_keyDown(entity me, float key, float ascii, float shift)
74 {
75         float r;
76         r = 0;
77         if(key == K_ENTER || key == K_KP_ENTER)
78         {
79                 if(me.cvarName)
80                 {
81                         me.saveCvars(me);
82                         r = 1;
83                 }
84                 me.onEnter(me, me.onEnterEntity);
85         }
86         if(SUPER(XonoticInputBox).keyDown(me, key, ascii, shift))
87                 r = 1;
88         return r;
89 }
90 #endif