2 CLASS(XonoticCvarList) EXTENDS(XonoticListBox)
3 METHOD(XonoticCvarList, configureXonoticCvarList, void(entity))
4 ATTRIB(XonoticCvarList, rowsPerItem, float, 1)
5 METHOD(XonoticCvarList, drawListBoxItem, void(entity, float, vector, float))
6 METHOD(XonoticCvarList, resizeNotify, void(entity, vector, vector, vector, vector))
7 METHOD(XonoticCvarList, keyDown, float(entity, float, float, float))
9 METHOD(XonoticCvarList, destroy, void(entity))
11 ATTRIB(XonoticCvarList, realFontSize, vector, '0 0 0')
12 ATTRIB(XonoticCvarList, realUpperMargin, float, 0)
13 ATTRIB(XonoticCvarList, columnNameOrigin, float, 0)
14 ATTRIB(XonoticCvarList, columnNameSize, float, 0)
15 ATTRIB(XonoticCvarList, columnValueOrigin, float, 0)
16 ATTRIB(XonoticCvarList, columnValueSize, float, 0)
18 METHOD(XonoticCvarList, mouseRelease, float(entity, vector))
19 METHOD(XonoticCvarList, setSelected, void(entity, float))
20 METHOD(XonoticCvarList, updateCvarType, float(entity))
22 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
23 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
24 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
25 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
26 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
27 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
28 ATTRIB(XonoticCvarList, cvarNeedsForcing, float, 0)
30 ATTRIB(XonoticCvarList, handle, float, -1)
31 ATTRIB(XonoticCvarList, cvarName, string, string_null)
32 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
33 ATTRIB(XonoticCvarList, cvarType, string, string_null)
34 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
35 ENDCLASS(XonoticCvarList)
36 entity makeXonoticCvarList();
37 void CvarList_Filter_Change(entity box, entity me);
38 void CvarList_Value_Change(entity box, entity me);
39 void CvarList_Revert_Click(entity btn, entity me);
40 void CvarList_End_Editing(entity box, entity me);
44 entity makeXonoticCvarList()
47 me = spawnXonoticCvarList();
48 me.configureXonoticCvarList(me);
51 void XonoticCvarList_configureXonoticCvarList(entity me)
53 me.configureXonoticListBox(me);
55 me.handle = buf_create();
56 buf_cvarlist(me.handle, "", "_");
57 me.nItems = buf_getsize(me.handle);
59 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(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
73 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
76 else if(strstrofs(strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
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 buf_cvarlist(me.handle, box.text, "_");
136 me.nItems = buf_getsize(me.handle);
138 me.setSelected(me, 0);
140 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
142 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
144 me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
145 me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
146 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
148 me.columnNameOrigin = 0;
149 me.columnValueSize = me.realFontSize_x * 20;
150 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x;
151 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
153 me.setSelected(me, me.selectedItem);
155 void XonoticCvarList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
166 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
168 k = bufstr_get(me.handle, i);
171 d = cvar_defstring(k);
173 if(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", k, " "), 0) >= 0)
174 theAlpha = SKINALPHA_CVARLIST_SAVED;
175 else if(strstrofs(strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " "), strcat(" ", k, " "), 0) >= 0)
176 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
177 else if(t & CVAR_TYPEFLAG_SAVED)
178 theAlpha = SKINALPHA_CVARLIST_SAVED;
180 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
182 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
184 theColor = SKINCOLOR_CVARLIST_CHANGED;
186 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
187 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
188 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
189 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
192 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
194 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
196 CvarList_Revert_Click(world, me);
199 else if(scan == K_ENTER)
201 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
204 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
206 else if(!me.controlledTextbox)
209 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
212 float XonoticCvarList_mouseRelease(entity me, vector pos)
215 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
216 return SUPER(XonoticCvarList).mouseRelease(me, pos);
219 void CvarList_Value_Change(entity box, entity me)
221 cvar_set(me.cvarNameBox.text, box.text);
222 if(me.cvarNeedsForcing)
224 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
225 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
226 if (autocvar_menu_forced_saved_cvars == "")
227 cvar_set("menu_forced_saved_cvars", me.cvarName);
229 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
230 me.cvarNeedsForcing = 0;
231 me.updateCvarType(me);
235 void CvarList_Revert_Click(entity btn, entity me)
237 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
238 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
239 if(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
241 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
242 if (autocvar_menu_reverted_nonsaved_cvars == "")
243 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
245 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
247 me.cvarNeedsForcing = me.updateCvarType(me);
250 void CvarList_End_Editing(entity box, entity me)
252 box.parent.setFocus(box.parent, me);