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, setSelected, void(entity, float))
19 ATTRIB(XonoticCvarList, controlledTextbox, entity, NULL)
20 ATTRIB(XonoticCvarList, cvarNameBox, entity, NULL)
21 ATTRIB(XonoticCvarList, cvarDescriptionBox, entity, NULL)
22 ATTRIB(XonoticCvarList, cvarTypeBox, entity, NULL)
23 ATTRIB(XonoticCvarList, cvarValueBox, entity, NULL)
24 ATTRIB(XonoticCvarList, cvarDefaultBox, entity, NULL)
26 ATTRIB(XonoticCvarList, handle, float, -1)
27 ATTRIB(XonoticCvarList, cvarName, string, string_null)
28 ATTRIB(XonoticCvarList, cvarDescription, string, string_null)
29 ATTRIB(XonoticCvarList, cvarType, string, string_null)
30 ATTRIB(XonoticCvarList, cvarDefault, string, string_null)
31 ENDCLASS(XonoticCvarList)
32 entity makeXonoticCvarList();
33 void CvarList_Filter_Change(entity box, entity me);
34 void CvarList_Value_Change(entity box, entity me);
35 void CvarList_Revert_Click(entity btn, entity me);
39 entity makeXonoticCvarList()
42 me = spawnXonoticCvarList();
43 me.configureXonoticCvarList(me);
46 void XonoticCvarList_configureXonoticCvarList(entity me)
48 me.configureXonoticListBox(me);
50 me.handle = buf_create();
51 buf_cvarlist(me.handle, "", "_");
52 me.nItems = buf_getsize(me.handle);
54 void XonoticCvarList_destroy(entity me)
58 void XonoticCvarList_setSelected(entity me, float i)
62 SUPER(XonoticCvarList).setSelected(me, i);
67 strunzone(me.cvarName);
68 if(me.cvarDescription)
69 strunzone(me.cvarDescription);
71 strunzone(me.cvarType);
73 strunzone(me.cvarDefault);
74 me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem));
75 me.cvarDescription = strzone(cvar_description(me.cvarName));
76 me.cvarDefault = strzone(cvar_defstring(me.cvarName));
79 t = cvar_type(me.cvarName);
81 if(t & CVAR_TYPEFLAG_SAVED)
82 me.cvarType = strcat(me.cvarType, ", will be saved to config.cfg");
84 me.cvarType = strcat(me.cvarType, ", will not be saved");
85 if(t & CVAR_TYPEFLAG_PRIVATE)
86 me.cvarType = strcat(me.cvarType, ", private");
87 if(t & CVAR_TYPEFLAG_ENGINE)
88 me.cvarType = strcat(me.cvarType, ", engine setting");
89 if(t & CVAR_TYPEFLAG_READONLY)
90 me.cvarType = strcat(me.cvarType, ", read only");
91 me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2));
93 me.cvarNameBox.setText(me.cvarNameBox, me.cvarName);
94 me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription);
95 me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType);
96 me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault);
98 // this one can handle tempstrings
99 s = cvar_string(me.cvarName);
100 me.cvarValueBox.setText(me.cvarValueBox, s);
101 me.cvarValueBox.cursorPos = strlen(s);
103 void CvarList_Filter_Change(entity box, entity me)
105 buf_cvarlist(me.handle, box.text, "_");
106 me.nItems = buf_getsize(me.handle);
108 me.setSelected(me, 0);
110 void XonoticCvarList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
112 SUPER(XonoticCvarList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
114 me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight);
115 me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth));
116 me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
118 me.columnNameOrigin = 0;
119 me.columnValueSize = me.realFontSize_x * 20;
120 me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x;
121 me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x;
123 me.setSelected(me, me.selectedItem);
125 void XonoticCvarList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
136 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
138 k = bufstr_get(me.handle, i);
141 d = cvar_defstring(k);
143 if(t & CVAR_TYPEFLAG_SAVED)
144 theAlpha = SKINALPHA_CVARLIST_SAVED;
146 theAlpha = SKINALPHA_CVARLIST_TEMPORARY;
148 theColor = SKINCOLOR_CVARLIST_UNCHANGED;
150 theColor = SKINCOLOR_CVARLIST_CHANGED;
152 s = draw_TextShortenToWidth(k, me.columnNameSize, 0, me.realFontSize);
153 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
154 s = draw_TextShortenToWidth(v, me.columnValueSize, 0, me.realFontSize);
155 draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
158 float XonoticCvarList_keyDown(entity me, float scan, float ascii, float shift)
160 if (scan == K_MOUSE3 || ((shift & S_CTRL) && scan == K_SPACE))
162 CvarList_Revert_Click(world, me);
165 else if(SUPER(XonoticCvarList).keyDown(me, scan, ascii, shift))
167 else if(!me.controlledTextbox)
170 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
173 void CvarList_Value_Change(entity box, entity me)
175 cvar_set(me.cvarNameBox.text, box.text);
178 void CvarList_Revert_Click(entity btn, entity me)
180 me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault);
181 me.cvarValueBox.cursorPos = strlen(me.cvarDefault);