]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/cvarlist.c
fix display of the welcome text
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / cvarlist.c
1 #ifdef INTERFACE
2 CLASS(XonoticCvarList) EXTENDS(XonoticListBox)
3         METHOD(XonoticCvarList, configureXonoticCvarList, void(entity))
4         ATTRIB(XonoticCvarList, rowsPerItem, float, 1)
5         METHOD(XonoticCvarList, drawListBoxItem, void(entity, float, vector, float))
6         METHOD(XonoticCvarList, resizeNotify, void(entity, vector, vector, vector, vector))
7         METHOD(XonoticCvarList, keyDown, float(entity, float, float, float))
8
9         METHOD(XonoticCvarList, destroy, void(entity))
10
11         ATTRIB(XonoticCvarList, realFontSize, vector, '0 0 0')
12         ATTRIB(XonoticCvarList, realUpperMargin, float, 0)
13         ATTRIB(XonoticCvarList, columnNameOrigin, float, 0)
14         ATTRIB(XonoticCvarList, columnNameSize, float, 0)
15         ATTRIB(XonoticCvarList, columnValueOrigin, float, 0)
16         ATTRIB(XonoticCvarList, columnValueSize, float, 0)
17
18         METHOD(XonoticCvarList, mouseRelease, float(entity, vector))
19         METHOD(XonoticCvarList, setSelected, void(entity, float))
20
21         ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
22         ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
23         ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
24         ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
25         ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
26         ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
27
28         ATTRIB(XonoticCvarList, handle, float, -1)
29         ATTRIB(XonoticCvarList, cvarName, string, string_null)
30         ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
31         ATTRIB(XonoticCvarList, cvarType, string, string_null)
32         ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
33 ENDCLASS(XonoticCvarList)
34 entity makeXonoticCvarList();
35 void CvarList_Filter_Change(entity box, entity me);
36 void CvarList_Value_Change(entity box, entity me);
37 void CvarList_Revert_Click(entity btn, entity me);
38 #endif
39
40 #ifdef IMPLEMENTATION
41 entity makeXonoticCvarList()
42 {
43         entity me;
44         me = spawnXonoticCvarList();
45         me.configureXonoticCvarList(me);
46         return me;
47 }
48 void XonoticCvarList_configureXonoticCvarList(entity me)
49 {
50         me.configureXonoticListBox(me);
51
52         me.handle = buf_create();
53         buf_cvarlist(me.handle, "", "_");
54         me.nItems = buf_getsize(me.handle);
55 }
56 void XonoticCvarList_destroy(entity me)
57 {
58         buf_del(me.handle);
59 }
60 void XonoticCvarList_setSelected(entity me, float i)
61 {
62         string s;
63
64         SUPER(XonoticCvarList).setSelected(me, i);
65         if(me.nItems == 0)
66                 return;
67         
68         if(me.cvarName)
69                 strunzone(me.cvarName);
70         if(me.cvarDescription)
71                 strunzone(me.cvarDescription);
72         if(me.cvarType)
73                 strunzone(me.cvarType);
74         if(me.cvarDefault)
75                 strunzone(me.cvarDefault);
76         me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
77         me.cvarDescription = strzone(cvar_description(me.cvarName));
78         me.cvarDefault = strzone(cvar_defstring(me.cvarName));
79
80         float t;
81         t = cvar_type(me.cvarName);
82         me.cvarType = "";
83         if(t & CVAR_TYPEFLAG_SAVED)
84                 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
85         else
86                 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
87         if(t & CVAR_TYPEFLAG_PRIVATE)
88                 me.cvarType = strcat(me.cvarType, ", ", _("private"));
89         if(t & CVAR_TYPEFLAG_ENGINE)
90                 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
91         if(t & CVAR_TYPEFLAG_READONLY)
92                 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
93         me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
94
95         me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
96         me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
97         me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
98         me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
99
100         // this one can handle tempstrings
101         s = cvar_string(me.cvarName);
102         me.cvarValueBox.setText(me.cvarValueBox, s);
103         me.cvarValueBox.cursorPos = strlen(s);
104 }
105 void CvarList_Filter_Change(entity box, entity me)
106 {
107         buf_cvarlist(me.handle, box.text, "_");
108         me.nItems = buf_getsize(me.handle);
109
110         me.setSelected(me, 0);
111 }
112 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
113 {
114         SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
115
116         me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
117         me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
118         me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
119
120         me.columnNameOrigin = 0;
121         me.columnValueSize = me.realFontSize_x * 20;
122         me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x;
123         me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
124
125         me.setSelected(me, me.selectedItem);
126 }
127 void XonoticCvarList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
128 {
129         string k, v, d;
130         float t;
131
132         vector theColor;
133         float theAlpha;
134
135         string s;
136
137         if(isSelected)
138                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
139         
140         k = bufstr_get(me.handle, i);
141
142         v = cvar_string(k);
143         d = cvar_defstring(k);
144         t = cvar_type(k);
145         if(t & CVAR_TYPEFLAG_SAVED)
146                 theAlpha = SKINALPHA_CVARLIST_SAVED;
147         else
148                 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
149         if(v == d)
150                 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
151         else
152                 theColor = SKINCOLOR_CVARLIST_CHANGED;
153
154         s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
155         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
156         s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
157         draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
158 }
159
160 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
161 {
162         if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
163         {
164                 CvarList_Revert_Click(world, me);
165                 return 1;
166         }
167         else if(scan == K_ENTER)
168                 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
169         else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
170                 return 1;
171         else if(!me.controlledTextbox)
172                 return 0;
173         else
174                 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
175 }
176
177 float XonoticCvarList_mouseRelease(entity me, vector pos)
178 {
179         if(me.pressed == 2)
180                 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
181         return SUPER(XonoticCvarList).mouseRelease(me, pos);
182 }
183
184 void CvarList_Value_Change(entity box, entity me)
185 {
186         cvar_set(me.cvarNameBox.text, box.text);
187 }
188
189 void CvarList_Revert_Click(entity btn, entity me)
190 {
191         me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
192         me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
193 }
194
195 #endif