]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/inputbox.c
cl_hitsound + some menu changes
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / inputbox.c
1 #ifdef INTERFACE
2 CLASS(NexuizInputBox) EXTENDS(InputBox)
3         METHOD(NexuizInputBox, configureNexuizInputBox, void(entity, float, string))
4         METHOD(NexuizInputBox, focusLeave, void(entity))
5         METHOD(NexuizInputBox, setText, void(entity, string))
6         ATTRIB(NexuizInputBox, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(NexuizInputBox, image, string, SKINGFX_INPUTBOX)
8         ATTRIB(NexuizInputBox, onChange, void(entity, entity), SUB_Null)
9         ATTRIB(NexuizInputBox, onChangeEntity, entity, NULL)
10         ATTRIB(NexuizInputBox, onEnter, void(entity, entity), SUB_Null)
11         ATTRIB(NexuizInputBox, onEnterEntity, entity, NULL)
12         ATTRIB(NexuizInputBox, marginLeft, float, SKINMARGIN_INPUTBOX_CHARS)
13         ATTRIB(NexuizInputBox, marginRight, float, SKINMARGIN_INPUTBOX_CHARS)
14         ATTRIB(NexuizInputBox, color, vector, SKINCOLOR_INPUTBOX_N)
15         ATTRIB(NexuizInputBox, colorF, vector, SKINCOLOR_INPUTBOX_F)
16
17         ATTRIB(NexuizInputBox, alpha, float, SKINALPHA_TEXT)
18
19         ATTRIB(NexuizInputBox, cvarName, string, string_null)
20         METHOD(NexuizInputBox, loadCvars, void(entity))
21         METHOD(NexuizInputBox, saveCvars, void(entity))
22         METHOD(NexuizInputBox, keyDown, float(entity, float, float, float))
23 ENDCLASS(NexuizInputBox)
24 entity makeNexuizInputBox(float, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeNexuizInputBox(float doEditColorCodes, string theCvar)
29 {
30         entity me;
31         me = spawnNexuizInputBox();
32         me.configureNexuizInputBox(me, doEditColorCodes, theCvar);
33         return me;
34 }
35 void configureNexuizInputBoxNexuizInputBox(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.loadCvars(me);
43         }
44         me.cursorPos = strlen(me.text);
45 }
46 void focusLeaveNexuizInputBox(entity me)
47 {
48         me.saveCvars(me);
49 }
50 void setTextNexuizInputBox(entity me, string new)
51 {
52         if(me.text != new)
53         {
54                 setTextInputBox(me, new);
55                 me.onChange(me, me.onChangeEntity);
56         }
57         else
58                 setTextInputBox(me, new);
59 }
60 void loadCvarsNexuizInputBox(entity me)
61 {
62         if not(me.cvarName)
63                 return;
64         setTextInputBox(me, cvar_string(me.cvarName));
65 }
66 void saveCvarsNexuizInputBox(entity me)
67 {
68         if not(me.cvarName)
69                 return;
70         cvar_set(me.cvarName, me.text);
71 }
72 float keyDownNexuizInputBox(entity me, float key, float ascii, float shift)
73 {
74         float r;
75         r = 0;
76         if(key == K_ENTER)
77         {
78                 if(me.cvarName)
79                 {
80                         me.saveCvars(me);
81                         r = 1;
82                 }
83                 me.onEnter(me, me.onEnterEntity);
84         }
85         if(keyDownInputBox(me, key, ascii, shift))
86                 r = 1;
87         return r;
88 }
89 #endif