Xonotic
cvarlist.qc
Go to the documentation of this file.
1 #include "cvarlist.qh"
2 
3 #include "inputbox.qh"
4 #include "../item/checkbox.qh"
5 #include "../item/container.qh"
6 #include "../item/checkbox.qh"
7 
9 {
10  entity me;
11  me = NEW(XonoticCvarList);
12  me.configureXonoticCvarList(me);
13  return me;
14 }
16 {
17  me.configureXonoticListBox(me);
18  me.handle = buf_create();
19  me.nItems = 0;
20 }
21 void CvarList_Load(entity me, string filter)
22 {
23  if(me.handle < 0)
24  return;
25 
26  buf_cvarlist(me.handle, filter, "_"); // cvars starting with "_" are excluded
27  me.nItems = buf_getsize(me.handle);
29  {
30  float newbuf = buf_create();
31  for (int i = 0; i < me.nItems; ++i)
32  {
33  string k = bufstr_get(me.handle, i);
34  if(cvar_string(k) != cvar_defstring(k))
35  bufstr_add(newbuf, k, false);
36  }
37  buf_del(me.handle);
38  me.handle = newbuf;
39  me.nItems = buf_getsize(me.handle);
40  }
41 }
43 {
44  bool force_initial_selection = false;
45  if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet?
46  force_initial_selection = true;
47  CvarList_Load(me, me.controlledTextbox.text);
48  if(force_initial_selection)
49  me.setSelected(me, 0);
50 }
52 {
53  if(me.handle)
54  buf_del(me.handle);
55  me.handle = buf_create();
56  me.nItems = 0;
57 }
59 {
60  if(me.handle)
61  buf_del(me.handle);
62 }
66 {
67  float t;
68  t = cvar_type(me.cvarName);
69  me.cvarType = "";
70  float needsForcing;
72  {
73  me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
74  needsForcing = 0;
75  }
77  {
78  // Currently claims to be saved, but won't be on next startup.
79  me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
80  needsForcing = 1;
81  }
82  else if(t & CVAR_TYPEFLAG_SAVED)
83  {
84  me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
85  needsForcing = 0;
86  }
87  else
88  {
89  me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
90  needsForcing = 1;
91  }
92  if(t & CVAR_TYPEFLAG_PRIVATE)
93  me.cvarType = strcat(me.cvarType, ", ", _("private"));
94  if(t & CVAR_TYPEFLAG_ENGINE)
95  me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
97  me.cvarType = strcat(me.cvarType, ", ", _("read only"));
98  me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
99  me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
100  return needsForcing;
101 }
103 {
104  string s;
105 
106  SUPER(XonoticCvarList).setSelected(me, i);
107  if(me.nItems == 0)
108  return;
109 
110  strfree(me.cvarType);
111  strcpy(me.cvarName, bufstr_get(me.handle, me.selectedItem));
112  strcpy(me.cvarDescription, cvar_description(me.cvarName));
113  strcpy(me.cvarDefault, cvar_defstring(me.cvarName));
114  me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
115  me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
116  float needsForcing = me.updateCvarType(me);
117  me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
118 
119  // this one can handle tempstrings
120  s = cvar_string(me.cvarName);
121  me.cvarNeedsForcing = 0;
122  me.cvarValueBox.setText(me.cvarValueBox, s);
123  me.cvarNeedsForcing = needsForcing;
124  me.cvarValueBox.cursorPos = strlen(s);
125 }
127 {
128  CvarList_Load(me, box.text);
129  me.setSelected(me, 0);
130 }
132 {
133  cvar_set("menu_cvarlist_onlymodified", ftos(!autocvar_menu_cvarlist_onlymodified));
134  box.setChecked(box, autocvar_menu_cvarlist_onlymodified);
135  CvarList_Load(me, me.controlledTextbox.text);
136  me.setSelected(me, 0);
137 }
138 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
139 {
140  SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
141 
142  me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
143  me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
144  me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
145 
146  me.columnNameOrigin = 0;
147  me.columnValueSize = me.realFontSize.x * 20;
148  me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
149  me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
150 }
151 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
152 {
153  string k, v, d;
154  float t;
155 
156  vector theColor;
157  float theAlpha;
158 
159  string s;
160 
161  if(isSelected)
162  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
163  else if(isFocused)
164  {
165  me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
166  draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
167  }
168 
169  k = bufstr_get(me.handle, i);
170 
171  v = cvar_string(k);
172  d = cvar_defstring(k);
173  t = cvar_type(k);
175  theAlpha = SKINALPHA_CVARLIST_SAVED;
177  theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
178  else if(t & CVAR_TYPEFLAG_SAVED)
179  theAlpha = SKINALPHA_CVARLIST_SAVED;
180  else
181  theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
182  if(v == d)
183  theColor = SKINCOLOR_CVARLIST_UNCHANGED;
184  else
185  theColor = SKINCOLOR_CVARLIST_CHANGED;
186 
187  s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
188  draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
189  s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
190  draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
191 }
192 
193 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
194 {
195  if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
196  {
198  return 1;
199  }
200  else if(scan == K_ENTER)
201  {
202  me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
203  return 1;
204  }
205  else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
206  return 1;
207  else if(!me.controlledTextbox)
208  return 0;
209  else
210  return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
211 }
212 
214 {
215  if(me.pressed == 2)
216  me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
217  return SUPER(XonoticCvarList).mouseRelease(me, pos);
218 }
219 
221 {
222  cvar_set(me.cvarNameBox.text, box.text);
223  if(me.cvarNeedsForcing)
224  {
225  localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
226  cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
228  cvar_set("menu_forced_saved_cvars", me.cvarName);
229  else
230  cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
231  me.cvarNeedsForcing = 0;
232  me.updateCvarType(me);
233  }
234 }
235 
237 {
238  me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
239  me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
241  {
242  cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
244  cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
245  else
246  cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
247  }
248  me.cvarNeedsForcing = me.updateCvarType(me);
249 }
250 
252 {
253  box.parent.setFocus(box.parent, me);
254 }
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
void CvarList_Revert_Click(entity btn, entity me)
Definition: cvarlist.qc:236
float K_MOUSE3
Definition: keycodes.qc:131
entity() spawn
string autocvar_menu_forced_saved_cvars
Definition: cvarlist.qc:63
void XonoticCvarList_destroy(entity me)
Definition: cvarlist.qc:58
void XonoticCvarList_configureXonoticCvarList(entity me)
Definition: cvarlist.qc:15
#define strhasword(s, w)
Definition: string.qh:352
float K_SPACE
Definition: keycodes.qc:10
void CvarList_Filter_ModifiedCvars(entity box, entity me)
Definition: cvarlist.qc:131
entity makeXonoticCvarList()
Definition: cvarlist.qc:8
void XonoticCvarList_hideNotify(entity me)
Definition: cvarlist.qc:51
#define strcpy(this, s)
Definition: string.qh:49
#define SUPER(cname)
Definition: oo.qh:219
void CvarList_Load(entity me, string filter)
Definition: cvarlist.qc:21
#define buf_create
Definition: dpextensions.qh:63
void CvarList_End_Editing(entity box, entity me)
Definition: cvarlist.qc:251
void XonoticCvarList_setSelected(entity me, float i)
Definition: cvarlist.qc:102
void CvarList_Filter_Change(entity box, entity me)
Definition: cvarlist.qc:126
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float CVAR_TYPEFLAG_READONLY
void CvarList_Value_Change(entity box, entity me)
Definition: cvarlist.qc:220
#define NULL
Definition: post.qh:17
float CVAR_TYPEFLAG_PRIVATE
void XonoticCvarList_showNotify(entity me)
Definition: cvarlist.qc:42
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float XonoticCvarList_mouseRelease(entity me, vector pos)
Definition: cvarlist.qc:213
float CVAR_TYPEFLAG_ENGINE
vector v
Definition: ent_cs.qc:116
const vector eX
Definition: vector.qh:44
string autocvar_menu_reverted_nonsaved_cvars
Definition: cvarlist.qc:64
float XonoticCvarList_updateCvarType(entity me)
Definition: cvarlist.qc:65
float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
Definition: cvarlist.qc:193
#define strfree(this)
Definition: string.qh:56
float K_ENTER
Definition: keycodes.qc:8
void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: cvarlist.qc:138
float CVAR_TYPEFLAG_SAVED
const int S_CTRL
Definition: hud.qh:128
float autocvar_menu_cvarlist_onlymodified
Definition: cvarlist.qh:47
void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
Definition: cvarlist.qc:151