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)
27 buf_cvarlist(me.handle, filter, "_");
28 me.nItems = buf_getsize(me.handle);
29 if (autocvar_menu_cvarlist_onlymodified) {
30 float newbuf = buf_create();
31 for (int i = 0; i < me.nItems; ++i) {
32 string k = bufstr_get(me.handle, i);
33 if (cvar_string(k) != cvar_defstring(k)) {
34 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;
48 CvarList_Load(me, me.controlledTextbox.text);
49 if (force_initial_selection) {
50 me.setSelected(me, 0);
53 void XonoticCvarList_hideNotify(entity me)
58 me.handle = buf_create();
61 void XonoticCvarList_destroy(entity me)
67 string autocvar_menu_forced_saved_cvars;
68 string autocvar_menu_reverted_nonsaved_cvars;
69 float XonoticCvarList_updateCvarType(entity me)
72 t = cvar_type(me.cvarName);
75 if (strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) {
76 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
78 } else if (strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName)) {
79 // Currently claims to be saved, but won't be on next startup.
80 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
82 } else if (t & CVAR_TYPEFLAG_SAVED) {
83 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
86 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
89 if (t & CVAR_TYPEFLAG_PRIVATE) {
90 me.cvarType = strcat(me.cvarType, ", ", _("private"));
92 if (t & CVAR_TYPEFLAG_ENGINE) {
93 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
95 if (t & CVAR_TYPEFLAG_READONLY) {
96 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);
107 if (me.nItems == 0) {
112 strunzone(me.cvarName);
114 if (me.cvarDescription) {
115 strunzone(me.cvarDescription);
118 strunzone(me.cvarType);
120 if (me.cvarDefault) {
121 strunzone(me.cvarDefault);
123 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
124 me.cvarDescription = strzone(cvar_description(me.cvarName));
125 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
126 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
127 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
128 float needsForcing = me.updateCvarType(me);
129 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
131 // this one can handle tempstrings
132 s = cvar_string(me.cvarName);
133 me.cvarNeedsForcing = 0;
134 me.cvarValueBox.setText(me.cvarValueBox, s);
135 me.cvarNeedsForcing = needsForcing;
136 me.cvarValueBox.cursorPos = strlen(s);
138 void CvarList_Filter_Change(entity box, entity me)
140 CvarList_Load(me, box.text);
141 me.setSelected(me, 0);
143 void CvarList_Filter_ModifiedCvars(entity box, entity me)
145 cvar_set("menu_cvarlist_onlymodified", ftos(!autocvar_menu_cvarlist_onlymodified));
146 box.setChecked(box, autocvar_menu_cvarlist_onlymodified);
147 CvarList_Load(me, me.controlledTextbox.text);
148 me.setSelected(me, 0);
150 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
152 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
154 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
155 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
156 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
158 me.columnNameOrigin = 0;
159 me.columnValueSize = me.realFontSize.x * 20;
160 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
161 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
163 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
174 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
175 } else if (isFocused) {
176 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
177 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
180 k = bufstr_get(me.handle, i);
183 d = cvar_defstring(k);
185 if (strhasword(autocvar_menu_forced_saved_cvars, k)) {
186 theAlpha = SKINALPHA_CVARLIST_SAVED;
187 } else if (strhasword(autocvar_menu_reverted_nonsaved_cvars, k)) {
188 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
189 } else if (t & CVAR_TYPEFLAG_SAVED) {
190 theAlpha = SKINALPHA_CVARLIST_SAVED;
192 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
195 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
197 theColor = SKINCOLOR_CVARLIST_CHANGED;
200 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
201 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
202 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
203 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
206 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
208 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE)) {
209 CvarList_Revert_Click(NULL, me);
211 } else if (scan == K_ENTER) {
212 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
214 } else if (SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift)) {
216 } else if (!me.controlledTextbox) {
219 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
223 float XonoticCvarList_mouseRelease(entity me, vector pos)
225 if (me.pressed == 2) {
226 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
228 return SUPER(XonoticCvarList).mouseRelease(me, pos);
231 void CvarList_Value_Change(entity box, entity me)
233 cvar_set(me.cvarNameBox.text, box.text);
234 if (me.cvarNeedsForcing) {
235 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
236 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
237 if (autocvar_menu_forced_saved_cvars == "") {
238 cvar_set("menu_forced_saved_cvars", me.cvarName);
240 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
242 me.cvarNeedsForcing = 0;
243 me.updateCvarType(me);
247 void CvarList_Revert_Click(entity btn, entity me)
249 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
250 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
251 if (strhasword(autocvar_menu_forced_saved_cvars, me.cvarName)) {
252 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
253 if (autocvar_menu_reverted_nonsaved_cvars == "") {
254 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
256 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
259 me.cvarNeedsForcing = me.updateCvarType(me);
262 void CvarList_End_Editing(entity box, entity me)
264 box.parent.setFocus(box.parent, me);