4 CLASS(XonoticCvarList, XonoticListBox)
5 METHOD(XonoticCvarList, configureXonoticCvarList, void(entity));
6 ATTRIB(XonoticCvarList, rowsPerItem, float, 1)
7 METHOD(XonoticCvarList, drawListBoxItem, void(entity, int, vector, bool, bool));
8 METHOD(XonoticCvarList, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(XonoticCvarList, keyDown, float(entity, float, float, float));
10 METHOD(XonoticCvarList, showNotify, void(entity));
12 METHOD(XonoticCvarList, destroy, void(entity));
14 ATTRIB(XonoticCvarList, realFontSize, vector, '0 0 0')
15 ATTRIB(XonoticCvarList, realUpperMargin, float, 0)
16 ATTRIB(XonoticCvarList, columnNameOrigin, float, 0)
17 ATTRIB(XonoticCvarList, columnNameSize, float, 0)
18 ATTRIB(XonoticCvarList, columnValueOrigin, float, 0)
19 ATTRIB(XonoticCvarList, columnValueSize, float, 0)
21 METHOD(XonoticCvarList, mouseRelease, float(entity, vector));
22 METHOD(XonoticCvarList, setSelected, void(entity, float));
23 METHOD(XonoticCvarList, updateCvarType, float(entity));
25 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
26 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
27 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
28 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
29 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
30 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
31 ATTRIB(XonoticCvarList, cvarNeedsForcing, float, 0)
33 ATTRIB(XonoticCvarList, handle, float, -1)
34 ATTRIB(XonoticCvarList, cvarName, string, string_null)
35 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
36 ATTRIB(XonoticCvarList, cvarType, string, string_null)
37 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
38 ENDCLASS(XonoticCvarList)
39 entity makeXonoticCvarList();
40 void CvarList_Filter_Change(entity box, entity me);
41 void CvarList_Value_Change(entity box, entity me);
42 void CvarList_Revert_Click(entity btn, entity me);
43 void CvarList_End_Editing(entity box, entity me);
47 entity makeXonoticCvarList()
50 me = NEW(XonoticCvarList);
51 me.configureXonoticCvarList(me);
54 void XonoticCvarList_configureXonoticCvarList(entity me)
56 me.configureXonoticListBox(me);
57 me.handle = buf_create();
59 void XonoticCvarList_showNotify(entity me)
61 buf_cvarlist(me.handle, "", "_");
62 me.nItems = buf_getsize(me.handle);
64 void XonoticCvarList_destroy(entity me)
68 string autocvar_menu_forced_saved_cvars;
69 string autocvar_menu_reverted_nonsaved_cvars;
70 float XonoticCvarList_updateCvarType(entity me)
73 t = cvar_type(me.cvarName);
76 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
78 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
81 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName))
83 // Currently claims to be saved, but won't be on next startup.
84 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
87 else if(t & CVAR_TYPEFLAG_SAVED)
89 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
94 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
97 if(t & CVAR_TYPEFLAG_PRIVATE)
98 me.cvarType = strcat(me.cvarType, ", ", _("private"));
99 if(t & CVAR_TYPEFLAG_ENGINE)
100 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
101 if(t & CVAR_TYPEFLAG_READONLY)
102 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
103 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
104 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
107 void XonoticCvarList_setSelected(entity me, float i)
111 SUPER(XonoticCvarList).setSelected(me, i);
116 strunzone(me.cvarName);
117 if(me.cvarDescription)
118 strunzone(me.cvarDescription);
120 strunzone(me.cvarType);
122 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 buf_cvarlist(me.handle, box.text, "_");
141 me.nItems = buf_getsize(me.handle);
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 me.setSelected(me, me.selectedItem);
160 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
171 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
174 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
175 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
178 k = bufstr_get(me.handle, i);
181 d = cvar_defstring(k);
183 if(strhasword(autocvar_menu_forced_saved_cvars, k))
184 theAlpha = SKINALPHA_CVARLIST_SAVED;
185 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, k))
186 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
187 else if(t & CVAR_TYPEFLAG_SAVED)
188 theAlpha = SKINALPHA_CVARLIST_SAVED;
190 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
192 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
194 theColor = SKINCOLOR_CVARLIST_CHANGED;
196 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
197 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
198 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
199 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
202 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
204 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
206 CvarList_Revert_Click(NULL, me);
209 else if(scan == K_ENTER)
211 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);
222 float XonoticCvarList_mouseRelease(entity me, vector pos)
225 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
226 return SUPER(XonoticCvarList).mouseRelease(me, pos);
229 void CvarList_Value_Change(entity box, entity me)
231 cvar_set(me.cvarNameBox.text, box.text);
232 if(me.cvarNeedsForcing)
234 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
235 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
236 if (autocvar_menu_forced_saved_cvars == "")
237 cvar_set("menu_forced_saved_cvars", me.cvarName);
239 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
240 me.cvarNeedsForcing = 0;
241 me.updateCvarType(me);
245 void CvarList_Revert_Click(entity btn, entity me)
247 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
248 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
249 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
251 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
252 if (autocvar_menu_reverted_nonsaved_cvars == "")
253 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
255 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
257 me.cvarNeedsForcing = me.updateCvarType(me);
260 void CvarList_End_Editing(entity box, entity me)
262 box.parent.setFocus(box.parent, me);