5 CLASS(XonoticCvarList, XonoticListBox)
6 METHOD(XonoticCvarList, configureXonoticCvarList, void(entity));
7 ATTRIB(XonoticCvarList, rowsPerItem, float, 1)
8 METHOD(XonoticCvarList, drawListBoxItem, void(entity, int, vector, bool, bool));
9 METHOD(XonoticCvarList, resizeNotify, void(entity, vector, vector, vector, vector));
10 METHOD(XonoticCvarList, keyDown, float(entity, float, float, float));
11 METHOD(XonoticCvarList, showNotify, void(entity));
13 METHOD(XonoticCvarList, destroy, void(entity));
15 ATTRIB(XonoticCvarList, realFontSize, vector, '0 0 0')
16 ATTRIB(XonoticCvarList, realUpperMargin, float, 0)
17 ATTRIB(XonoticCvarList, columnNameOrigin, float, 0)
18 ATTRIB(XonoticCvarList, columnNameSize, float, 0)
19 ATTRIB(XonoticCvarList, columnValueOrigin, float, 0)
20 ATTRIB(XonoticCvarList, columnValueSize, float, 0)
22 METHOD(XonoticCvarList, mouseRelease, float(entity, vector));
23 METHOD(XonoticCvarList, setSelected, void(entity, float));
24 METHOD(XonoticCvarList, updateCvarType, float(entity));
26 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
27 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
28 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
29 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
30 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
31 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
32 ATTRIB(XonoticCvarList, cvarNeedsForcing, float, 0)
34 ATTRIB(XonoticCvarList, handle, float, -1)
35 ATTRIB(XonoticCvarList, cvarName, string, string_null)
36 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
37 ATTRIB(XonoticCvarList, cvarType, string, string_null)
38 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
39 ENDCLASS(XonoticCvarList)
40 entity makeXonoticCvarList();
41 void CvarList_Filter_Change(entity box, entity me);
42 void CvarList_Value_Change(entity box, entity me);
43 void CvarList_Revert_Click(entity btn, entity me);
44 void CvarList_End_Editing(entity box, entity me);
48 entity makeXonoticCvarList()
51 me = NEW(XonoticCvarList);
52 me.configureXonoticCvarList(me);
55 void XonoticCvarList_configureXonoticCvarList(entity me)
57 me.configureXonoticListBox(me);
58 me.handle = buf_create();
61 void XonoticCvarList_showNotify(entity me)
63 bool force_initial_selection = false;
64 if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet?
65 force_initial_selection = true;
66 buf_cvarlist(me.handle, "", "_");
67 me.nItems = buf_getsize(me.handle);
68 if(force_initial_selection)
69 me.setSelected(me, 0);
71 void XonoticCvarList_destroy(entity me)
75 string autocvar_menu_forced_saved_cvars;
76 string autocvar_menu_reverted_nonsaved_cvars;
77 float XonoticCvarList_updateCvarType(entity me)
80 t = cvar_type(me.cvarName);
83 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
85 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
88 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName))
90 // Currently claims to be saved, but won't be on next startup.
91 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
94 else if(t & CVAR_TYPEFLAG_SAVED)
96 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
101 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
104 if(t & CVAR_TYPEFLAG_PRIVATE)
105 me.cvarType = strcat(me.cvarType, ", ", _("private"));
106 if(t & CVAR_TYPEFLAG_ENGINE)
107 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
108 if(t & CVAR_TYPEFLAG_READONLY)
109 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
110 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
111 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
114 void XonoticCvarList_setSelected(entity me, float i)
118 SUPER(XonoticCvarList).setSelected(me, i);
123 strunzone(me.cvarName);
124 if(me.cvarDescription)
125 strunzone(me.cvarDescription);
127 strunzone(me.cvarType);
129 strunzone(me.cvarDefault);
130 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
131 me.cvarDescription = strzone(cvar_description(me.cvarName));
132 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
133 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
134 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
135 float needsForcing = me.updateCvarType(me);
136 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
138 // this one can handle tempstrings
139 s = cvar_string(me.cvarName);
140 me.cvarNeedsForcing = 0;
141 me.cvarValueBox.setText(me.cvarValueBox, s);
142 me.cvarNeedsForcing = needsForcing;
143 me.cvarValueBox.cursorPos = strlen(s);
145 void CvarList_Filter_Change(entity box, entity me)
147 buf_cvarlist(me.handle, box.text, "_");
148 me.nItems = buf_getsize(me.handle);
150 me.setSelected(me, 0);
152 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
154 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
156 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
157 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
158 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
160 me.columnNameOrigin = 0;
161 me.columnValueSize = me.realFontSize.x * 20;
162 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
163 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
165 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
176 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
179 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
180 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
183 k = bufstr_get(me.handle, i);
186 d = cvar_defstring(k);
188 if(strhasword(autocvar_menu_forced_saved_cvars, k))
189 theAlpha = SKINALPHA_CVARLIST_SAVED;
190 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, k))
191 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
192 else if(t & CVAR_TYPEFLAG_SAVED)
193 theAlpha = SKINALPHA_CVARLIST_SAVED;
195 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
197 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
199 theColor = SKINCOLOR_CVARLIST_CHANGED;
201 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
202 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
203 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
204 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
207 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
209 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
211 CvarList_Revert_Click(NULL, me);
214 else if(scan == K_ENTER)
216 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
219 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
221 else if(!me.controlledTextbox)
224 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
227 float XonoticCvarList_mouseRelease(entity me, vector pos)
230 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
231 return SUPER(XonoticCvarList).mouseRelease(me, pos);
234 void CvarList_Value_Change(entity box, entity me)
236 cvar_set(me.cvarNameBox.text, box.text);
237 if(me.cvarNeedsForcing)
239 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
240 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
241 if (autocvar_menu_forced_saved_cvars == "")
242 cvar_set("menu_forced_saved_cvars", me.cvarName);
244 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
245 me.cvarNeedsForcing = 0;
246 me.updateCvarType(me);
250 void CvarList_Revert_Click(entity btn, entity me)
252 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
253 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
254 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
256 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
257 if (autocvar_menu_reverted_nonsaved_cvars == "")
258 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
260 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
262 me.cvarNeedsForcing = me.updateCvarType(me);
265 void CvarList_End_Editing(entity box, entity me)
267 box.parent.setFocus(box.parent, me);