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))
11 METHOD(XonoticCvarList, destroy, void(entity))
13 ATTRIB(XonoticCvarList, realFontSize, vector, '0 0 0')
14 ATTRIB(XonoticCvarList, realUpperMargin, float, 0)
15 ATTRIB(XonoticCvarList, columnNameOrigin, float, 0)
16 ATTRIB(XonoticCvarList, columnNameSize, float, 0)
17 ATTRIB(XonoticCvarList, columnValueOrigin, float, 0)
18 ATTRIB(XonoticCvarList, columnValueSize, float, 0)
20 METHOD(XonoticCvarList, mouseRelease, float(entity, vector))
21 METHOD(XonoticCvarList, setSelected, void(entity, float))
22 METHOD(XonoticCvarList, updateCvarType, float(entity))
24 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
25 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
26 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
27 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
28 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
29 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
30 ATTRIB(XonoticCvarList, cvarNeedsForcing, float, 0)
32 ATTRIB(XonoticCvarList, handle, float, -1)
33 ATTRIB(XonoticCvarList, cvarName, string, string_null)
34 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
35 ATTRIB(XonoticCvarList, cvarType, string, string_null)
36 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
37 ENDCLASS(XonoticCvarList)
38 entity makeXonoticCvarList();
39 void CvarList_Filter_Change(entity box, entity me);
40 void CvarList_Value_Change(entity box, entity me);
41 void CvarList_Revert_Click(entity btn, entity me);
42 void CvarList_End_Editing(entity box, entity me);
46 entity makeXonoticCvarList()
49 me = NEW(XonoticCvarList);
50 me.configureXonoticCvarList(me);
53 void XonoticCvarList_configureXonoticCvarList(entity me)
55 me.configureXonoticListBox(me);
57 me.handle = buf_create();
58 buf_cvarlist(me.handle, "", "_");
59 me.nItems = buf_getsize(me.handle);
61 void XonoticCvarList_destroy(entity me)
65 string autocvar_menu_forced_saved_cvars;
66 string autocvar_menu_reverted_nonsaved_cvars;
67 float XonoticCvarList_updateCvarType(entity me)
70 t = cvar_type(me.cvarName);
73 if(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
75 me.cvarType = strcat(me.cvarType, ", ", _("forced to be saved to config.cfg"));
78 else if(strstrofs(strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
80 // Currently claims to be saved, but won't be on next startup.
81 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
84 else if(t & CVAR_TYPEFLAG_SAVED)
86 me.cvarType = strcat(me.cvarType, ", ", _("will be saved to config.cfg"));
91 me.cvarType = strcat(me.cvarType, ", ", _("will not be saved"));
94 if(t & CVAR_TYPEFLAG_PRIVATE)
95 me.cvarType = strcat(me.cvarType, ", ", _("private"));
96 if(t & CVAR_TYPEFLAG_ENGINE)
97 me.cvarType = strcat(me.cvarType, ", ", _("engine setting"));
98 if(t & CVAR_TYPEFLAG_READONLY)
99 me.cvarType = strcat(me.cvarType, ", ", _("read only"));
100 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
101 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
104 void XonoticCvarList_setSelected(entity me, float i)
108 SUPER(XonoticCvarList).setSelected(me, i);
113 strunzone(me.cvarName);
114 if(me.cvarDescription)
115 strunzone(me.cvarDescription);
117 strunzone(me.cvarType);
119 strunzone(me.cvarDefault);
120 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
121 me.cvarDescription = strzone(cvar_description(me.cvarName));
122 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
123 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
124 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
125 float needsForcing = me.updateCvarType(me);
126 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
128 // this one can handle tempstrings
129 s = cvar_string(me.cvarName);
130 me.cvarNeedsForcing = 0;
131 me.cvarValueBox.setText(me.cvarValueBox, s);
132 me.cvarNeedsForcing = needsForcing;
133 me.cvarValueBox.cursorPos = strlen(s);
135 void CvarList_Filter_Change(entity box, entity me)
137 buf_cvarlist(me.handle, box.text, "_");
138 me.nItems = buf_getsize(me.handle);
140 me.setSelected(me, 0);
142 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
144 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
146 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
147 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
148 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
150 me.columnNameOrigin = 0;
151 me.columnValueSize = me.realFontSize.x * 20;
152 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize.x;
153 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
155 me.setSelected(me, me.selectedItem);
157 void XonoticCvarList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
168 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
171 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
172 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
175 k = bufstr_get(me.handle, i);
178 d = cvar_defstring(k);
180 if(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", k, " "), 0) >= 0)
181 theAlpha = SKINALPHA_CVARLIST_SAVED;
182 else if(strstrofs(strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " "), strcat(" ", k, " "), 0) >= 0)
183 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
184 else if(t & CVAR_TYPEFLAG_SAVED)
185 theAlpha = SKINALPHA_CVARLIST_SAVED;
187 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
189 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
191 theColor = SKINCOLOR_CVARLIST_CHANGED;
193 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
194 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
195 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
196 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
199 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
201 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
203 CvarList_Revert_Click(world, me);
206 else if(scan == K_ENTER)
208 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
211 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
213 else if(!me.controlledTextbox)
216 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
219 float XonoticCvarList_mouseRelease(entity me, vector pos)
222 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
223 return SUPER(XonoticCvarList).mouseRelease(me, pos);
226 void CvarList_Value_Change(entity box, entity me)
228 cvar_set(me.cvarNameBox.text, box.text);
229 if(me.cvarNeedsForcing)
231 localcmd(sprintf("\nseta %1$s \"$%1$s\"\n", me.cvarName));
232 cvar_set("menu_reverted_nonsaved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_reverted_nonsaved_cvars, " ")), 1, -2));
233 if (autocvar_menu_forced_saved_cvars == "")
234 cvar_set("menu_forced_saved_cvars", me.cvarName);
236 cvar_set("menu_forced_saved_cvars", strcat(autocvar_menu_forced_saved_cvars, " ", me.cvarName));
237 me.cvarNeedsForcing = 0;
238 me.updateCvarType(me);
242 void CvarList_Revert_Click(entity btn, entity me)
244 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
245 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);
246 if(strstrofs(strcat(" ", autocvar_menu_forced_saved_cvars, " "), strcat(" ", me.cvarName, " "), 0) >= 0)
248 cvar_set("menu_forced_saved_cvars", substring(strreplace(strcat(" ", me.cvarName, " "), " ", strcat(" ", autocvar_menu_forced_saved_cvars, " ")), 1, -2));
249 if (autocvar_menu_reverted_nonsaved_cvars == "")
250 cvar_set("menu_reverted_nonsaved_cvars", me.cvarName);
252 cvar_set("menu_reverted_nonsaved_cvars", strcat(autocvar_menu_reverted_nonsaved_cvars, " ", me.cvarName));
254 me.cvarNeedsForcing = me.updateCvarType(me);
257 void CvarList_End_Editing(entity box, entity me)
259 box.parent.setFocus(box.parent, me);