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))
21 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
22 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
23 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
24 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
25 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
26 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
28 ATTRIB(XonoticCvarList, handle, float, -1)
29 ATTRIB(XonoticCvarList, cvarName, string, string_null)
30 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
31 ATTRIB(XonoticCvarList, cvarType, string, string_null)
32 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
33 ENDCLASS(XonoticCvarList)
34 entity makeXonoticCvarList();
35 void CvarList_Filter_Change(entity box, entity me);
36 void CvarList_Value_Change(entity box, entity me);
37 void CvarList_Revert_Click(entity btn, entity me);
41 entity makeXonoticCvarList()
44 me = spawnXonoticCvarList();
45 me.configureXonoticCvarList(me);
48 void XonoticCvarList_configureXonoticCvarList(entity me)
50 me.configureXonoticListBox(me);
52 me.handle = buf_create();
53 buf_cvarlist(me.handle, "", "_");
54 me.nItems = buf_getsize(me.handle);
56 void XonoticCvarList_destroy(entity me)
60 void XonoticCvarList_setSelected(entity me, float i)
64 SUPER(XonoticCvarList).setSelected(me, i);
69 strunzone(me.cvarName);
70 if(me.cvarDescription)
71 strunzone(me.cvarDescription);
73 strunzone(me.cvarType);
75 strunzone(me.cvarDefault);
76 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
77 me.cvarDescription = strzone(cvar_description(me.cvarName));
78 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
81 t = cvar_type(me.cvarName);
83 if(t & CVAR_TYPEFLAG_SAVED)
84 me.cvarType = strcat(me.cvarType, _(", will be saved to config.cfg"));
86 me.cvarType = strcat(me.cvarType, _(", will not be saved"));
87 if(t & CVAR_TYPEFLAG_PRIVATE)
88 me.cvarType = strcat(me.cvarType, _(", private"));
89 if(t & CVAR_TYPEFLAG_ENGINE)
90 me.cvarType = strcat(me.cvarType, _(", engine setting"));
91 if(t & CVAR_TYPEFLAG_READONLY)
92 me.cvarType = strcat(me.cvarType, _(", read only"));
93 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
95 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
96 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
97 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
98 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
100 // this one can handle tempstrings
101 s = cvar_string(me.cvarName);
102 me.cvarValueBox.setText(me.cvarValueBox, s);
103 me.cvarValueBox.cursorPos = strlen(s);
105 void CvarList_Filter_Change(entity box, entity me)
107 buf_cvarlist(me.handle, box.text, "_");
108 me.nItems = buf_getsize(me.handle);
110 me.setSelected(me, 0);
112 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
114 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
116 me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
117 me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
118 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
120 me.columnNameOrigin = 0;
121 me.columnValueSize = me.realFontSize_x * 20;
122 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x;
123 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
125 me.setSelected(me, me.selectedItem);
127 void XonoticCvarList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
138 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
140 k = bufstr_get(me.handle, i);
143 d = cvar_defstring(k);
145 if(t & CVAR_TYPEFLAG_SAVED)
146 theAlpha = SKINALPHA_CVARLIST_SAVED;
148 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
150 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
152 theColor = SKINCOLOR_CVARLIST_CHANGED;
154 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
155 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
156 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
157 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
160 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
162 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
164 CvarList_Revert_Click(world, me);
167 else if(scan == K_ENTER)
168 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
169 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
171 else if(!me.controlledTextbox)
174 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
177 float XonoticCvarList_mouseRelease(entity me, vector pos)
180 me.cvarValueBox.parent.setFocus(me.cvarValueBox.parent, me.cvarValueBox);
181 return SUPER(XonoticCvarList).mouseRelease(me, pos);
184 void CvarList_Value_Change(entity box, entity me)
186 cvar_set(me.cvarNameBox.text, box.text);
189 void CvarList_Revert_Click(entity btn, entity me)
191 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
192 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);