4 #include "../item/checkbox.qh"
5 #include "../item/container.qh"
6 #include "../item/checkbox.qh"
8 entity makeXonoticCvarList()
11 me = NEW(XonoticCvarList);
12 me.configureXonoticCvarList(me);
15 void XonoticCvarList_configureXonoticCvarList(entity me)
17 me.configureXonoticListBox(me);
18 me.handle = buf_create();
21 void CvarList_Load(entity me, string filter)
26 buf_cvarlist(me.handle, filter, "_");
27 me.nItems = buf_getsize(me.handle);
28 if(autocvar_menu_cvarlist_onlymodified)
30 float newbuf = buf_create();
31 for (int i = 0; i < me.nItems; ++i)
33 string k = bufstr_get(me.handle, i);
34 if(cvar_string(k) != cvar_defstring(k))
35 bufstr_add(newbuf, k, false);
39 me.nItems = buf_getsize(me.handle);
42 void XonoticCvarList_showNotify(entity me)
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);
51 void XonoticCvarList_hideNotify(entity me)
55 me.handle = buf_create();
58 void XonoticCvarList_destroy(entity me)
63 string autocvar_menu_forced_saved_cvars;
64 string autocvar_menu_reverted_nonsaved_cvars;
65 float XonoticCvarList_updateCvarType(entity me)
68 t = cvar_type(me.cvarName);
71 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
73 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
76 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName))
78 // Currently claims to be saved, but won't be on next startup.
79 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
82 else if(t & CVAR_TYPEFLAG_SAVED)
84 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
89 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
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"));
96 if(t & CVAR_TYPEFLAG_READONLY)
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);
102 void XonoticCvarList_setSelected(entity me, float i)
106 SUPER(XonoticCvarList).setSelected(me, i);
111 strunzone(me.cvarName);
112 if(me.cvarDescription)
113 strunzone(me.cvarDescription);
115 strunzone(me.cvarType);
117 strunzone(me.cvarDefault);
118 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
119 me.cvarDescription = strzone(cvar_description(me.cvarName));
120 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
121 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
122 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
123 float needsForcing = me.updateCvarType(me);
124 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
126 // this one can handle tempstrings
127 s = cvar_string(me.cvarName);
128 me.cvarNeedsForcing = 0;
129 me.cvarValueBox.setText(me.cvarValueBox, s);
130 me.cvarNeedsForcing = needsForcing;
131 me.cvarValueBox.cursorPos = strlen(s);
133 void CvarList_Filter_Change(entity box, entity me)
135 CvarList_Load(me, box.text);
136 me.setSelected(me, 0);
138 void CvarList_Filter_ModifiedCvars(entity box, entity me)
140 cvar_set("menu_cvarlist_onlymodified", ftos(!autocvar_menu_cvarlist_onlymodified));
141 box.setChecked(box, autocvar_menu_cvarlist_onlymodified);
142 CvarList_Load(me, me.controlledTextbox.text);
143 me.setSelected(me, 0);
145 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
147 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
149 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
150 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
151 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
153 me.columnNameOrigin = 0;
154 me.columnValueSize = me.realFontSize.x * 20;
155 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
156 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
158 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
169 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
172 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
173 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
176 k = bufstr_get(me.handle, i);
179 d = cvar_defstring(k);
181 if(strhasword(autocvar_menu_forced_saved_cvars, k))
182 theAlpha = SKINALPHA_CVARLIST_SAVED;
183 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, k))
184 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
185 else if(t & CVAR_TYPEFLAG_SAVED)
186 theAlpha = SKINALPHA_CVARLIST_SAVED;
188 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
190 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
192 theColor = SKINCOLOR_CVARLIST_CHANGED;
194 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
195 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
196 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
197 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
200 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
202 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
204 CvarList_Revert_Click(NULL, me);
207 else if(scan == K_ENTER)
209 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
212 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
214 else if(!me.controlledTextbox)
217 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
220 float XonoticCvarList_mouseRelease(entity me, vector pos)
223 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
224 return SUPER(XonoticCvarList).mouseRelease(me, pos);
227 void CvarList_Value_Change(entity box, entity me)
229 cvar_set(me.cvarNameBox.text, box.text);
230 if(me.cvarNeedsForcing)
232 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
233 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
234 if (autocvar_menu_forced_saved_cvars == "")
235 cvar_set("menu_forced_saved_cvars", me.cvarName);
237 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
238 me.cvarNeedsForcing = 0;
239 me.updateCvarType(me);
243 void CvarList_Revert_Click(entity btn, entity me)
245 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
246 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
247 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
249 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
250 if (autocvar_menu_reverted_nonsaved_cvars == "")
251 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
253 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
255 me.cvarNeedsForcing = me.updateCvarType(me);
258 void CvarList_End_Editing(entity box, entity me)
260 box.parent.setFocus(box.parent, me);