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