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 316 of file cvarlist.qc.

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

References entity().

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

◆ CvarList_Filter_Change()

void CvarList_Filter_Change ( entity box,
entity me )

Definition at line 182 of file cvarlist.qc.

183{
184 CvarList_Load(me, box.text);
185 me.setSelected(me, 0);
186}
void CvarList_Load(entity me, string filter)
Definition cvarlist.qc:28

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 194 of file cvarlist.qc.

195{
196 cvar_set("menu_cvarlist_descriptions", ftos(!autocvar_menu_cvarlist_descriptions));
197 box.setChecked(box, autocvar_menu_cvarlist_descriptions);
198 CvarList_Load(me, me.controlledTextbox.text);
199 me.setSelected(me, 0);
200}
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 187 of file cvarlist.qc.

188{
189 cvar_set("menu_cvarlist_onlymodified", ftos(!autocvar_menu_cvarlist_onlymodified));
190 box.setChecked(box, autocvar_menu_cvarlist_onlymodified);
191 CvarList_Load(me, me.controlledTextbox.text);
192 me.setSelected(me, 0);
193}
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 28 of file cvarlist.qc.

29{
30 if(me.handle < 0)
31 return;
32
33 // buf_cvarlist and matchpattern(..., MATCH_AUTO) filtering works in this way:
34 // *aa* finds aa anywhere in the cvar name
35 // *aa finds aa in the end of the cvar name
36 // aa* finds aa in the beginning of the cvar name
37 // aa finds aa in the beginning of the cvar name (not anywhere!)
38 // The last case is not very intuitive so here we make it work like *aa*
39 // and make it behave like the apropos command
40 // Filter, cvar names and cvar descriptions are changed to lowercase to simulate a
41 // case insensitive search, like the apropos command
42 // Unlike the apropos command, hidden cvars starting with _ are filtered out
43 if (filter == "*") // work around weird case where * doesn't list any cvar
44 filter = "";
45 else if (filter != "")
46 {
47 bool ispattern = ((strstrofs(filter, "*", 0) >= 0) || (strstrofs(filter, "?", 0) >= 0));
48 filter = strtolower(filter);
49 if (!ispattern)
50 filter = strcat("*", filter, "*");
51 }
52
54 && (!autocvar_menu_cvarlist_descriptions || filter == ""))
55 {
56 // simplest case where we filter only cvar names (or no filter at all)
57 buf_cvarlist(me.handle, filter, "_"); // exclude hidden cvars starting with "_"
58 me.nItems = buf_getsize(me.handle);
60 return;
61 }
62
63 // get the complete cvar list
64 buf_cvarlist(me.handle, "", "_"); // exclude hidden cvars starting with "_"
65 me.nItems = buf_getsize(me.handle);
66
67 // filter
68 float newbuf = buf_create();
69 for (int i = 0; i < me.nItems; ++i)
70 {
71 string cvar_name = bufstr_get(me.handle, i);
73 {
74 continue;
75 }
76 if (filter != "" && !matchpattern(strtolower(cvar_name), filter, MATCH_AUTO)
78 || !matchpattern(strtolower(cvar_description(cvar_name)), filter, MATCH_AUTO)))
79 {
80 continue;
81 }
82 bufstr_add(newbuf, cvar_name, false);
83 }
84 buf_del(me.handle);
85 me.handle = newbuf;
86 me.nItems = buf_getsize(me.handle);
88}
string strtolower(string s)
void CvarList_UpdateResults(entity me)
Definition cvarlist.qc:21
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 301 of file cvarlist.qc.

302{
303 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
304 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
306 {
307 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
309 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
310 else
311 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
312 }
313 me.cvarNeedsForcing = me.updateCvarType(me);
314}
string autocvar_menu_forced_saved_cvars
Definition cvarlist.qc:110
string autocvar_menu_reverted_nonsaved_cvars
Definition cvarlist.qc:111
#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 21 of file cvarlist.qc.

22{
23 int c = me.nItems;
24 static string cvarlistResultCount = string_null;
25 strcpy(cvarlistResultCount, c == 1 ? _("1 result") : sprintf(_("%d results"), c));
26 me.cvarlistResultCountBox.setText(me.cvarlistResultCountBox, cvarlistResultCount);
27}
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 283 of file cvarlist.qc.

284{
285 if (box.disabled)
286 return;
287 cvar_set(me.cvarNameBox.text, box.text);
288 if(me.cvarNeedsForcing)
289 {
290 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
291 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
293 cvar_set("menu_forced_saved_cvars", me.cvarName);
294 else
295 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
296 me.cvarNeedsForcing = false;
297 me.updateCvarType(me);
298 }
299}
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{
10 entity me;
11 me = NEW(XonoticCvarList);
12 me.configureXonoticCvarList(me);
13 return me;
14}
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 15 of file cvarlist.qc.

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

References buf_create, and entity().

◆ XonoticCvarList_destroy()

void XonoticCvarList_destroy ( entity me)

Definition at line 105 of file cvarlist.qc.

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

References entity().

◆ XonoticCvarList_drawListBoxItem()

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

Definition at line 214 of file cvarlist.qc.

215{
216 string k, v, d;
217 float t;
218
219 vector theColor;
220 float theAlpha;
221
222 string s;
223
224 if(isSelected)
225 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
226 else if(isFocused)
227 {
228 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
229 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
230 }
231
232 k = bufstr_get(me.handle, i);
233
234 v = cvar_string(k);
235 d = cvar_defstring(k);
236 t = cvar_type(k);
238 theAlpha = SKINALPHA_CVARLIST_SAVED;
240 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
241 else if(t & CVAR_TYPEFLAG_SAVED)
242 theAlpha = SKINALPHA_CVARLIST_SAVED;
243 else
244 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
245 if(v == d)
246 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
247 else
248 theColor = SKINCOLOR_CVARLIST_CHANGED;
249
250 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
251 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
252 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
253 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
254}
float CVAR_TYPEFLAG_SAVED
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:377
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 98 of file cvarlist.qc.

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

References buf_create, and entity().

◆ XonoticCvarList_keyDown()

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

Definition at line 256 of file cvarlist.qc.

257{
258 if (!me.cvarValueBox.disabled && (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE)))
259 {
261 return 1;
262 }
263 else if(!me.cvarValueBox.disabled && scan == K_ENTER)
264 {
265 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
266 return 1;
267 }
268 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
269 return 1;
270 else if(!me.controlledTextbox || me.cvarValueBox.disabled)
271 return 0;
272 else
273 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
274}
void CvarList_Revert_Click(entity btn, entity me)
Definition cvarlist.qc:301
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 276 of file cvarlist.qc.

277{
278 if (!me.cvarValueBox.disabled && me.pressed == 2)
279 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
280 return SUPER(XonoticCvarList).mouseRelease(me, pos);
281}

References entity(), SUPER, and vector.

◆ XonoticCvarList_resizeNotify()

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

Definition at line 201 of file cvarlist.qc.

202{
203 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
204
205 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
206 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
207 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
208
209 me.columnNameOrigin = 0;
210 me.columnValueSize = me.realFontSize.x * 20;
211 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
212 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
213}

References entity(), SUPER, and vector.

◆ XonoticCvarList_setSelected()

void XonoticCvarList_setSelected ( entity me,
float i )

Definition at line 158 of file cvarlist.qc.

159{
160 string s;
161
162 SUPER(XonoticCvarList).setSelected(me, i);
163 if(me.nItems == 0)
164 return;
165
166 strfree(me.cvarType);
167 strcpy(me.cvarName, bufstr_get(me.handle, me.selectedItem));
168 strcpy(me.cvarDescription, cvar_description(me.cvarName));
169 strcpy(me.cvarDefault, cvar_defstring(me.cvarName));
170 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
171 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
172 bool needsForcing = me.updateCvarType(me);
173 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
174
175 // this one can handle tempstrings
176 s = cvar_string(me.cvarName);
177 me.cvarNeedsForcing = false;
178 me.cvarValueBox.setText(me.cvarValueBox, s);
179 me.cvarNeedsForcing = needsForcing;
180 me.cvarValueBox.cursorPos = strlen(s);
181}
#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 89 of file cvarlist.qc.

90{
91 bool force_initial_selection = false;
92 if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet?
93 force_initial_selection = true;
94 CvarList_Load(me, me.controlledTextbox.text);
95 if(force_initial_selection)
96 me.setSelected(me, 0);
97}

References CvarList_Load(), and entity().

◆ XonoticCvarList_updateCvarType()

bool XonoticCvarList_updateCvarType ( entity me)

Definition at line 112 of file cvarlist.qc.

113{
114 float t;
115 t = cvar_type(me.cvarName);
116 me.cvarType = "";
117 bool needsForcing;
119 {
120 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
121 needsForcing = false;
122 }
124 {
125 // Currently claims to be saved, but won't be on next startup.
126 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
127 needsForcing = true;
128 }
129 else if(t & CVAR_TYPEFLAG_SAVED)
130 {
131 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
132 needsForcing = false;
133 }
134 else
135 {
136 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
137 needsForcing = true;
138 }
140 me.cvarType = strcat(me.cvarType, ", ", _("private"));
142 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
144 {
145 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
146 me.cvarValueBox.disabled = true;
147 me.cvarDefaultBox.disabled = true;
148 }
149 else
150 {
151 me.cvarValueBox.disabled = false;
152 me.cvarDefaultBox.disabled = false;
153 }
154 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
155 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
156 return needsForcing;
157}
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