3 CLASS(XonoticDemoList, XonoticListBox)
4 METHOD(XonoticDemoList, configureXonoticDemoList, void(entity))
5 ATTRIB(XonoticDemoList, rowsPerItem, float, 1)
6 METHOD(XonoticDemoList, resizeNotify, void(entity, vector, vector, vector, vector))
7 METHOD(XonoticDemoList, drawListBoxItem, void(entity, float, vector, float))
8 METHOD(XonoticDemoList, getDemos, void(entity))
9 METHOD(XonoticDemoList, startDemo, void(entity))
10 METHOD(XonoticDemoList, timeDemo, void(entity))
11 METHOD(XonoticDemoList, demoName, string(entity, float))
12 METHOD(XonoticDemoList, doubleClickListBoxItem, void(entity, float, vector))
13 METHOD(XonoticDemoList, keyDown, float(entity, float, float, float))
14 METHOD(XonoticDemoList, destroy, void(entity))
15 METHOD(XonoticDemoList, showNotify, void(entity))
17 ATTRIB(XonoticDemoList, listDemo, float, -1)
18 ATTRIB(XonoticDemoList, realFontSize, vector, '0 0 0')
19 ATTRIB(XonoticDemoList, columnNameOrigin, float, 0)
20 ATTRIB(XonoticDemoList, columnNameSize, float, 0)
21 ATTRIB(XonoticDemoList, realUpperMargin, float, 0)
22 ATTRIB(XonoticDemoList, origin, vector, '0 0 0')
23 ATTRIB(XonoticDemoList, itemAbsSize, vector, '0 0 0')
25 ATTRIB(XonoticDemoList, filterString, string, string_null)
26 ENDCLASS(XonoticDemoList)
28 #ifndef IMPLEMENTATION
30 entity demolist; // for reference elsewhere
31 entity makeXonoticDemoList();
33 void DemoList_Refresh_Click(entity btn, entity me);
34 void DemoList_Filter_Change(entity box, entity me);
39 entity makeXonoticDemoList()
42 me = NEW(XonoticDemoList);
43 me.configureXonoticDemoList(me);
47 void XonoticDemoList_configureXonoticDemoList(entity me)
49 me.configureXonoticListBox(me);
53 string XonoticDemoList_demoName(entity me, float i)
56 s = bufstr_get(me.listDemo, i);
58 if(substring(s, 0, 1) == "/")
59 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
64 // if subdir is true look in subdirectories too (1 level)
65 void getDemos_for_ext(entity me, string ext, float subdir)
73 s=strcat(s, me.filterString, ext);
75 s=strcat(s, "*", ext);
78 list = search_begin(s, false, true);
81 n = search_getsize(list);
82 for(i = 0; i < n; ++i)
84 s = search_getfilename(list, i); // get initial full file name
85 s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix
86 s = strdecolorize(s); // remove any pre-existing colors
89 s = strreplace("/", "^7/", s); // clear colors at the forward slash
90 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color
91 bufstr_add(me.listDemo, s, true);
93 else { bufstr_add(me.listDemo, s, true); }
99 getDemos_for_ext(me, ext, false);
102 void XonoticDemoList_getDemos(entity me)
104 if (me.listDemo >= 0)
105 buf_del(me.listDemo);
106 me.listDemo = buf_create();
112 getDemos_for_ext(me, ".dem", true);
113 me.nItems = buf_getsize(me.listDemo);
115 buf_sort(me.listDemo, 128, false);
118 void XonoticDemoList_destroy(entity me)
121 buf_del(me.listDemo);
124 void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
126 me.itemAbsSize = '0 0 0';
127 SUPER(XonoticDemoList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
129 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
130 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
131 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
133 me.columnNameOrigin = me.realFontSize.x;
134 me.columnNameSize = 1 - 2 * me.realFontSize.x;
137 void XonoticDemoList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
141 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
143 s = me.demoName(me,i);
144 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
145 draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_TEXT, SKINALPHA_TEXT, 1);
148 void XonoticDemoList_showNotify(entity me)
153 void DemoList_Refresh_Click(entity btn, entity me)
156 me.setSelected(me, 0); //always select the first element after a list update
159 void DemoList_Filter_Change(entity box, entity me)
162 strunzone(me.filterString);
166 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
167 me.filterString = strzone(box.text);
169 me.filterString = strzone(strcat("*", box.text, "*"));
172 me.filterString = string_null;
177 void XonoticDemoList_startDemo(entity me)
180 s = me.demoName(me, me.selectedItem);
181 s = strdecolorize(s);
183 localcmd("playdemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
186 void XonoticDemoList_timeDemo(entity me)
189 s = me.demoName(me, me.selectedItem);
190 s = strdecolorize(s);
192 localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
195 void DemoConfirm_ListClick_Check_Gamestatus(entity me)
197 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo
201 else // already in a match, player has to confirm
203 DialogOpenButton_Click_withCoords(
205 main.demostartconfirmDialog,
206 boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size),
207 boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size)
212 void XonoticDemoList_doubleClickListBoxItem(entity me, float i, vector where)
214 DemoConfirm_ListClick_Check_Gamestatus(me);
217 float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
219 if(scan == K_ENTER || scan == K_KP_ENTER)
221 DemoConfirm_ListClick_Check_Gamestatus(me);
226 return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);