Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cvarlist.qc
Go to the documentation of this file.
1#include "cvarlist.qh"
2
3#include "inputbox.qh"
4#include "../item/checkbox.qh"
6#include "../item/checkbox.qh"
7
9{
11 me.configureXonoticCvarList(me);
12 return me;
13}
15{
16 me.configureXonoticListBox(me);
17 me.handle = buf_create();
18 me.nItems = 0;
19}
21{
22 int c = me.nItems;
23 static string cvarlistResultCount = string_null;
24 strcpy(cvarlistResultCount, c == 1 ? _("1 result") : sprintf(_("%d results"), c));
25 me.cvarlistResultCountBox.setText(me.cvarlistResultCountBox, cvarlistResultCount);
26}
27void CvarList_Load(entity me, string filter)
28{
29 if(me.handle < 0)
30 return;
31
32 // buf_cvarlist and matchpattern(..., MATCH_AUTO) filtering works in this way:
33 // *aa* finds aa anywhere in the cvar name
34 // *aa finds aa in the end of the cvar name
35 // aa* finds aa in the beginning of the cvar name
36 // aa finds aa in the beginning of the cvar name (not anywhere!)
37 // The last case is not very intuitive so here we make it work like *aa*
38 // and make it behave like the apropos command
39 // Filter, cvar names and cvar descriptions are changed to lowercase to simulate a
40 // case insensitive search, like the apropos command
41 // Unlike the apropos command, hidden cvars starting with _ are filtered out
42 if (filter == "*") // work around weird case where * doesn't list any cvar
43 filter = "";
44 else if (filter != "")
45 {
46 bool ispattern = ((strstrofs(filter, "*", 0) >= 0) || (strstrofs(filter, "?", 0) >= 0));
47 filter = strtolower(filter);
48 if (!ispattern)
49 filter = strcat("*", filter, "*");
50 }
51
53 && (!autocvar_menu_cvarlist_descriptions || filter == ""))
54 {
55 // simplest case where we filter only cvar names (or no filter at all)
56 buf_cvarlist(me.handle, filter, "_"); // exclude hidden cvars starting with "_"
57 me.nItems = buf_getsize(me.handle);
59 return;
60 }
61
62 // get the complete cvar list
63 buf_cvarlist(me.handle, "", "_"); // exclude hidden cvars starting with "_"
64 me.nItems = buf_getsize(me.handle);
65
66 // filter
67 float newbuf = buf_create();
68 for (int i = 0; i < me.nItems; ++i)
69 {
70 string cvar_name = bufstr_get(me.handle, i);
72 {
73 continue;
74 }
75 if (filter != "" && !matchpattern(strtolower(cvar_name), filter, MATCH_AUTO)
77 || !matchpattern(strtolower(cvar_description(cvar_name)), filter, MATCH_AUTO)))
78 {
79 continue;
80 }
81 bufstr_add(newbuf, cvar_name, false);
82 }
83 buf_del(me.handle);
84 me.handle = newbuf;
85 me.nItems = buf_getsize(me.handle);
87}
89{
90 bool force_initial_selection = false;
91 if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet?
92 force_initial_selection = true;
93 CvarList_Load(me, me.controlledTextbox.text);
94 if(force_initial_selection)
95 me.setSelected(me, 0);
96}
98{
99 if(me.handle)
100 buf_del(me.handle);
101 me.handle = buf_create();
102 me.nItems = 0;
103}
105{
106 if(me.handle)
107 buf_del(me.handle);
108}
112{
113 float t = cvar_type(me.cvarName);
114 me.cvarType = "";
115 bool needsForcing;
117 {
118 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
119 needsForcing = false;
120 }
122 {
123 // Currently claims to be saved, but won't be on next startup.
124 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
125 needsForcing = true;
126 }
127 else if(t & CVAR_TYPEFLAG_SAVED)
128 {
129 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
130 needsForcing = false;
131 }
132 else
133 {
134 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
135 needsForcing = true;
136 }
138 me.cvarType = strcat(me.cvarType, ", ", _("private"));
140 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
142 {
143 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
144 me.cvarValueBox.disabled = true;
145 me.cvarDefaultBox.disabled = true;
146 }
147 else
148 {
149 me.cvarValueBox.disabled = false;
150 me.cvarDefaultBox.disabled = false;
151 }
152 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
153 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
154 return needsForcing;
155}
157{
158 string s;
159
160 SUPER(XonoticCvarList).setSelected(me, i);
161 if(me.nItems == 0)
162 return;
163
164 strfree(me.cvarType);
165 strcpy(me.cvarName, bufstr_get(me.handle, me.selectedItem));
166 strcpy(me.cvarDescription, cvar_description(me.cvarName));
167 strcpy(me.cvarDefault, cvar_defstring(me.cvarName));
168 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
169 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
170 bool needsForcing = me.updateCvarType(me);
171 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
172
173 // this one can handle tempstrings
174 s = cvar_string(me.cvarName);
175 me.cvarNeedsForcing = false;
176 me.cvarValueBox.setText(me.cvarValueBox, s);
177 me.cvarNeedsForcing = needsForcing;
178 me.cvarValueBox.cursorPos = strlen(s);
179}
181{
182 CvarList_Load(me, box.text);
183 me.setSelected(me, 0);
184}
186{
187 cvar_set("menu_cvarlist_onlymodified", ftos(!autocvar_menu_cvarlist_onlymodified));
188 box.setChecked(box, autocvar_menu_cvarlist_onlymodified);
189 CvarList_Load(me, me.controlledTextbox.text);
190 me.setSelected(me, 0);
191}
193{
194 cvar_set("menu_cvarlist_descriptions", ftos(!autocvar_menu_cvarlist_descriptions));
195 box.setChecked(box, autocvar_menu_cvarlist_descriptions);
196 CvarList_Load(me, me.controlledTextbox.text);
197 me.setSelected(me, 0);
198}
199void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
200{
201 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
202
203 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
204 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
205 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
206
207 me.columnNameOrigin = 0;
208 me.columnValueSize = me.realFontSize.x * 20;
209 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
210 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
211}
212void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
213{
214 string k, v, d;
215 float t;
216
217 vector theColor;
218 float theAlpha;
219
220 string s;
221
222 if(isSelected)
223 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
224 else if(isFocused)
225 {
226 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
227 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
228 }
229
230 k = bufstr_get(me.handle, i);
231
232 v = cvar_string(k);
233 d = cvar_defstring(k);
234 t = cvar_type(k);
236 theAlpha = SKINALPHA_CVARLIST_SAVED;
238 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
239 else if(t & CVAR_TYPEFLAG_SAVED)
240 theAlpha = SKINALPHA_CVARLIST_SAVED;
241 else
242 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
243 if(v == d)
244 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
245 else
246 theColor = SKINCOLOR_CVARLIST_CHANGED;
247
248 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
249 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
250 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
251 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
252}
253
254float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
255{
256 if (!me.cvarValueBox.disabled && (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE)))
257 {
259 return 1;
260 }
261 else if(!me.cvarValueBox.disabled && scan == K_ENTER)
262 {
263 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
264 return 1;
265 }
266 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
267 return 1;
268 else if(!me.controlledTextbox || me.cvarValueBox.disabled)
269 return 0;
270 else
271 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
272}
273
275{
276 if (!me.cvarValueBox.disabled && me.pressed == 2)
277 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
278 return SUPER(XonoticCvarList).mouseRelease(me, pos);
279}
280
282{
283 if (box.disabled)
284 return;
285 cvar_set(me.cvarNameBox.text, box.text);
286 if(me.cvarNeedsForcing)
287 {
288 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
289 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
291 cvar_set("menu_forced_saved_cvars", me.cvarName);
292 else
293 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
294 me.cvarNeedsForcing = false;
295 me.updateCvarType(me);
296 }
297}
298
300{
301 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
302 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
304 {
305 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
307 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
308 else
309 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
310 }
311 me.cvarNeedsForcing = me.updateCvarType(me);
312}
313
315{
316 if (!box.disabled)
317 box.parent.setFocus(box.parent, me);
318}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string strtolower(string s)
float CVAR_TYPEFLAG_ENGINE
float CVAR_TYPEFLAG_READONLY
float CVAR_TYPEFLAG_SAVED
float CVAR_TYPEFLAG_PRIVATE
void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition cvarlist.qc:212
void CvarList_UpdateResults(entity me)
Definition cvarlist.qc:20
void CvarList_Filter_Descriptions(entity box, entity me)
Definition cvarlist.qc:192
string autocvar_menu_forced_saved_cvars
Definition cvarlist.qc:109
void XonoticCvarList_setSelected(entity me, float i)
Definition cvarlist.qc:156
void CvarList_Filter_Change(entity box, entity me)
Definition cvarlist.qc:180
float XonoticCvarList_mouseRelease(entity me, vector pos)
Definition cvarlist.qc:274
void CvarList_Value_Change(entity box, entity me)
Definition cvarlist.qc:281
void CvarList_End_Editing(entity box, entity me)
Definition cvarlist.qc:314
entity makeXonoticCvarList()
Definition cvarlist.qc:8
void XonoticCvarList_configureXonoticCvarList(entity me)
Definition cvarlist.qc:14
string autocvar_menu_reverted_nonsaved_cvars
Definition cvarlist.qc:110
bool XonoticCvarList_updateCvarType(entity me)
Definition cvarlist.qc:111
void CvarList_Filter_ModifiedCvars(entity box, entity me)
Definition cvarlist.qc:185
void CvarList_Revert_Click(entity btn, entity me)
Definition cvarlist.qc:299
float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
Definition cvarlist.qc:254
void XonoticCvarList_destroy(entity me)
Definition cvarlist.qc:104
void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition cvarlist.qc:199
void XonoticCvarList_hideNotify(entity me)
Definition cvarlist.qc:97
void XonoticCvarList_showNotify(entity me)
Definition cvarlist.qc:88
void CvarList_Load(entity me, string filter)
Definition cvarlist.qc:27
bool autocvar_menu_cvarlist_descriptions
Definition cvarlist.qh:50
bool autocvar_menu_cvarlist_onlymodified
Definition cvarlist.qh:49
const float MATCH_AUTO
#define strstrofs
#define strlen
#define buf_create
const int S_CTRL
Definition hud.qh:130
float K_MOUSE3
Definition keycodes.qc:131
float K_SPACE
Definition keycodes.qc:10
float K_ENTER
Definition keycodes.qc:8
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:378
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
void localcmd(string command,...)
void cvar_set(string name, string value)
string substring(string s, float start, float length)
const string cvar_string(string name)
string ftos(float f)
const string cvar_defstring(string name)
string strzone(string s)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NEW(cname,...)
Definition oo.qh:117
#define SUPER(cname)
Definition oo.qh:231
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
#define strfree(this)
Definition string.qh:59
#define strhasword(s, w)
Definition string.qh:370
#define strcpy(this, s)
Definition string.qh:52
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44