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();
60 void XonoticCvarList_showNotify(entity me)
62 bool force_initial_selection = false;
63 if(me.handle >= 0 && me.nItems <= 0) // me.handle not loaded yet?
64 force_initial_selection = true;
65 buf_cvarlist(me.handle, "", "_");
66 me.nItems = buf_getsize(me.handle);
67 if(force_initial_selection)
68 me.setSelected(me, 0);
70 void XonoticCvarList_destroy(entity me)
74 string autocvar_menu_forced_saved_cvars;
75 string autocvar_menu_reverted_nonsaved_cvars;
76 float XonoticCvarList_updateCvarType(entity me)
79 t = cvar_type(me.cvarName);
82 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
84 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
87 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, me.cvarName))
89 // Currently claims to be saved, but won't be on next startup.
90 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
93 else if(t & CVAR_TYPEFLAG_SAVED)
95 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
100 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
103 if(t & CVAR_TYPEFLAG_PRIVATE)
104 me.cvarType = strcat(me.cvarType, ", ", _("private"));
105 if(t & CVAR_TYPEFLAG_ENGINE)
106 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
107 if(t & CVAR_TYPEFLAG_READONLY)
108 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
109 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
110 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
113 void XonoticCvarList_setSelected(entity me, float i)
117 SUPER(XonoticCvarList).setSelected(me, i);
122 strunzone(me.cvarName);
123 if(me.cvarDescription)
124 strunzone(me.cvarDescription);
126 strunzone(me.cvarType);
128 strunzone(me.cvarDefault);
129 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
130 me.cvarDescription = strzone(cvar_description(me.cvarName));
131 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
132 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
133 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
134 float needsForcing = me.updateCvarType(me);
135 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
137 // this one can handle tempstrings
138 s = cvar_string(me.cvarName);
139 me.cvarNeedsForcing = 0;
140 me.cvarValueBox.setText(me.cvarValueBox, s);
141 me.cvarNeedsForcing = needsForcing;
142 me.cvarValueBox.cursorPos = strlen(s);
144 void CvarList_Filter_Change(entity box, entity me)
146 buf_cvarlist(me.handle, box.text, "_");
147 me.nItems = buf_getsize(me.handle);
149 me.setSelected(me, 0);
151 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
153 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
155 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
156 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
157 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
159 me.columnNameOrigin = 0;
160 me.columnValueSize = me.realFontSize.x * 20;
161 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
162 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
164 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
175 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
178 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
179 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
182 k = bufstr_get(me.handle, i);
185 d = cvar_defstring(k);
187 if(strhasword(autocvar_menu_forced_saved_cvars, k))
188 theAlpha = SKINALPHA_CVARLIST_SAVED;
189 else if(strhasword(autocvar_menu_reverted_nonsaved_cvars, k))
190 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
191 else if(t & CVAR_TYPEFLAG_SAVED)
192 theAlpha = SKINALPHA_CVARLIST_SAVED;
194 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
196 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
198 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))
210 CvarList_Revert_Click(NULL, me);
213 else if(scan == K_ENTER)
215 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
218 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
220 else if(!me.controlledTextbox)
223 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
226 float XonoticCvarList_mouseRelease(entity me, vector pos)
229 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
230 return SUPER(XonoticCvarList).mouseRelease(me, pos);
233 void CvarList_Value_Change(entity box, entity me)
235 cvar_set(me.cvarNameBox.text, box.text);
236 if(me.cvarNeedsForcing)
238 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
239 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
240 if (autocvar_menu_forced_saved_cvars == "")
241 cvar_set("menu_forced_saved_cvars", me.cvarName);
243 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
244 me.cvarNeedsForcing = 0;
245 me.updateCvarType(me);
249 void CvarList_Revert_Click(entity btn, entity me)
251 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
252 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
253 if(strhasword(autocvar_menu_forced_saved_cvars, me.cvarName))
255 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
256 if (autocvar_menu_reverted_nonsaved_cvars == "")
257 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
259 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
261 me.cvarNeedsForcing = me.updateCvarType(me);
264 void CvarList_End_Editing(entity box, entity me)
266 box.parent.setFocus(box.parent, me);