Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cvarlist.qc File Reference
#include "cvarlist.qh"
#include "inputbox.qh"
#include "../item/checkbox.qh"
#include "../item/container.qh"
Include dependency graph for cvarlist.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void CvarList_End_Editing (entity box, entity me)
void CvarList_Filter_Change (entity box, entity me)
void CvarList_Filter_Descriptions (entity box, entity me)
void CvarList_Filter_ModifiedCvars (entity box, entity me)
void CvarList_Load (entity me, string filter)
void CvarList_Revert_Click (entity btn, entity me)
void CvarList_UpdateResults (entity me)
void CvarList_Value_Change (entity box, entity me)
entity makeXonoticCvarList ()
void XonoticCvarList_configureXonoticCvarList (entity me)
void XonoticCvarList_destroy (entity me)
void XonoticCvarList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
void XonoticCvarList_hideNotify (entity me)
float XonoticCvarList_keyDown (entity me, float scan, float ascii, float shift)
float XonoticCvarList_mouseRelease (entity me, vector pos)
void XonoticCvarList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticCvarList_setSelected (entity me, float i)
void XonoticCvarList_showNotify (entity me)
bool XonoticCvarList_updateCvarType (entity me)

Variables

string autocvar_menu_forced_saved_cvars
string autocvar_menu_reverted_nonsaved_cvars

Function Documentation

◆ CvarList_End_Editing()

void CvarList_End_Editing ( entity box,
entity me )

Definition at line 314 of file cvarlist.qc.

315{
316 if (!box.disabled)
317 box.parent.setFocus(box.parent, me);
318}

References entity().

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ CvarList_Filter_Change()

void CvarList_Filter_Change ( entity box,
entity me )

Definition at line 180 of file cvarlist.qc.

181{
182 CvarList_Load(me, box.text);
183 me.setSelected(me, 0);
184}
void CvarList_Load(entity me, string filter)
Definition cvarlist.qc:27

References CvarList_Load(), and entity().

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ CvarList_Filter_Descriptions()

void CvarList_Filter_Descriptions ( entity box,
entity me )

Definition at line 192 of file cvarlist.qc.

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}
bool autocvar_menu_cvarlist_descriptions
Definition cvarlist.qh:50
void cvar_set(string name, string value)
string ftos(float f)

References autocvar_menu_cvarlist_descriptions, cvar_set(), CvarList_Load(), entity(), and ftos().

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ CvarList_Filter_ModifiedCvars()

void CvarList_Filter_ModifiedCvars ( entity box,
entity me )

Definition at line 185 of file cvarlist.qc.

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}
bool autocvar_menu_cvarlist_onlymodified
Definition cvarlist.qh:49

References autocvar_menu_cvarlist_onlymodified, cvar_set(), CvarList_Load(), entity(), and ftos().

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ CvarList_Load()

void CvarList_Load ( entity me,
string filter )

Definition at line 27 of file cvarlist.qc.

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}
string strtolower(string s)
void CvarList_UpdateResults(entity me)
Definition cvarlist.qc:20
const float MATCH_AUTO
#define strstrofs
#define buf_create
const string cvar_string(string name)
const string cvar_defstring(string name)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References autocvar_menu_cvarlist_descriptions, autocvar_menu_cvarlist_onlymodified, buf_create, cvar_defstring(), cvar_string(), CvarList_UpdateResults(), entity(), MATCH_AUTO, strcat(), strstrofs, and strtolower().

Referenced by CvarList_Filter_Change(), CvarList_Filter_Descriptions(), CvarList_Filter_ModifiedCvars(), and XonoticCvarList_showNotify().

◆ CvarList_Revert_Click()

void CvarList_Revert_Click ( entity btn,
entity me )

Definition at line 299 of file cvarlist.qc.

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}
string autocvar_menu_forced_saved_cvars
Definition cvarlist.qc:109
string autocvar_menu_reverted_nonsaved_cvars
Definition cvarlist.qc:110
#define strlen
string substring(string s, float start, float length)
#define strhasword(s, w)
Definition string.qh:370

References autocvar_menu_forced_saved_cvars, autocvar_menu_reverted_nonsaved_cvars, cvar_set(), entity(), strcat(), strhasword, strlen, and substring().

Referenced by XonoticCvarList::ATTRIB(), XonoticCvarList_keyDown(), and XonoticCvarsDialog_fill().

◆ CvarList_UpdateResults()

void CvarList_UpdateResults ( entity me)

Definition at line 20 of file cvarlist.qc.

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}
string string_null
Definition nil.qh:9
#define strcpy(this, s)
Definition string.qh:52

References entity(), strcpy, and string_null.

Referenced by CvarList_Load().

◆ CvarList_Value_Change()

void CvarList_Value_Change ( entity box,
entity me )

Definition at line 281 of file cvarlist.qc.

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}
void localcmd(string command,...)

References autocvar_menu_forced_saved_cvars, autocvar_menu_reverted_nonsaved_cvars, cvar_set(), entity(), localcmd(), strcat(), and substring().

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ makeXonoticCvarList()

entity makeXonoticCvarList ( )

Definition at line 8 of file cvarlist.qc.

9{
11 me.configureXonoticCvarList(me);
12 return me;
13}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by XonoticCvarList::ATTRIB(), and XonoticCvarsDialog_fill().

◆ XonoticCvarList_configureXonoticCvarList()

void XonoticCvarList_configureXonoticCvarList ( entity me)

Definition at line 14 of file cvarlist.qc.

15{
16 me.configureXonoticListBox(me);
17 me.handle = buf_create();
18 me.nItems = 0;
19}

References buf_create, and entity().

◆ XonoticCvarList_destroy()

void XonoticCvarList_destroy ( entity me)

Definition at line 104 of file cvarlist.qc.

105{
106 if(me.handle)
107 buf_del(me.handle);
108}

References entity().

◆ XonoticCvarList_drawListBoxItem()

void XonoticCvarList_drawListBoxItem ( entity me,
int i,
vector absSize,
bool isSelected,
bool isFocused )

Definition at line 212 of file cvarlist.qc.

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}
float CVAR_TYPEFLAG_SAVED
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
vector
Definition self.qh:92
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References autocvar_menu_forced_saved_cvars, autocvar_menu_reverted_nonsaved_cvars, cvar_defstring(), cvar_string(), CVAR_TYPEFLAG_SAVED, draw_Fill(), draw_Text(), draw_TextShortenToWidth(), entity(), eX, eY, getFadedAlpha(), strhasword, and vector.

◆ XonoticCvarList_hideNotify()

void XonoticCvarList_hideNotify ( entity me)

Definition at line 97 of file cvarlist.qc.

98{
99 if(me.handle)
100 buf_del(me.handle);
101 me.handle = buf_create();
102 me.nItems = 0;
103}

References buf_create, and entity().

◆ XonoticCvarList_keyDown()

float XonoticCvarList_keyDown ( entity me,
float scan,
float ascii,
float shift )

Definition at line 254 of file cvarlist.qc.

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}
void CvarList_Revert_Click(entity btn, entity me)
Definition cvarlist.qc:299
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
#define SUPER(cname)
Definition oo.qh:231
#define NULL
Definition post.qh:14

References CvarList_Revert_Click(), entity(), K_ENTER, K_MOUSE3, K_SPACE, NULL, S_CTRL, and SUPER.

◆ XonoticCvarList_mouseRelease()

float XonoticCvarList_mouseRelease ( entity me,
vector pos )

Definition at line 274 of file cvarlist.qc.

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}

References entity(), SUPER, and vector.

◆ XonoticCvarList_resizeNotify()

void XonoticCvarList_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 199 of file cvarlist.qc.

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}

References entity(), SUPER, and vector.

◆ XonoticCvarList_setSelected()

void XonoticCvarList_setSelected ( entity me,
float i )

Definition at line 156 of file cvarlist.qc.

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}
#define strfree(this)
Definition string.qh:59

References cvar_defstring(), cvar_string(), entity(), strcpy, strfree, strlen, and SUPER.

◆ XonoticCvarList_showNotify()

void XonoticCvarList_showNotify ( entity me)

Definition at line 88 of file cvarlist.qc.

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}

References CvarList_Load(), and entity().

◆ XonoticCvarList_updateCvarType()

bool XonoticCvarList_updateCvarType ( entity me)

Definition at line 111 of file cvarlist.qc.

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}
float CVAR_TYPEFLAG_ENGINE
float CVAR_TYPEFLAG_READONLY
float CVAR_TYPEFLAG_PRIVATE
string strzone(string s)

References autocvar_menu_forced_saved_cvars, autocvar_menu_reverted_nonsaved_cvars, CVAR_TYPEFLAG_ENGINE, CVAR_TYPEFLAG_PRIVATE, CVAR_TYPEFLAG_READONLY, CVAR_TYPEFLAG_SAVED, entity(), strcat(), strhasword, strlen, strzone(), and substring().

Variable Documentation

◆ autocvar_menu_forced_saved_cvars

string autocvar_menu_forced_saved_cvars

◆ autocvar_menu_reverted_nonsaved_cvars

string autocvar_menu_reverted_nonsaved_cvars