5 CLASS(XonoticDemoList, XonoticListBox)
6 METHOD(XonoticDemoList, configureXonoticDemoList, void(entity));
7 ATTRIB(XonoticDemoList, rowsPerItem, float, 1)
8 METHOD(XonoticDemoList, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(XonoticDemoList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticDemoList, getDemos, void(entity));
11 METHOD(XonoticDemoList, startDemo, void(entity));
12 METHOD(XonoticDemoList, timeDemo, void(entity));
13 METHOD(XonoticDemoList, demoName, string(entity, float));
14 METHOD(XonoticDemoList, doubleClickListBoxItem, void(entity, float, vector));
15 METHOD(XonoticDemoList, keyDown, float(entity, float, float, float));
16 METHOD(XonoticDemoList, destroy, void(entity));
17 METHOD(XonoticDemoList, showNotify, void(entity));
19 ATTRIB(XonoticDemoList, listDemo, float, -1)
20 ATTRIB(XonoticDemoList, realFontSize, vector, '0 0 0')
21 ATTRIB(XonoticDemoList, columnNameOrigin, float, 0)
22 ATTRIB(XonoticDemoList, columnNameSize, float, 0)
23 ATTRIB(XonoticDemoList, realUpperMargin, float, 0)
24 ATTRIB(XonoticDemoList, origin, vector, '0 0 0')
25 ATTRIB(XonoticDemoList, itemAbsSize, vector, '0 0 0')
27 ATTRIB(XonoticDemoList, filterString, string, string_null)
28 ENDCLASS(XonoticDemoList)
30 #ifndef IMPLEMENTATION
32 entity demolist; // for reference elsewhere
33 entity makeXonoticDemoList();
35 void DemoList_Refresh_Click(entity btn, entity me);
36 void DemoList_Filter_Change(entity box, entity me);
41 entity makeXonoticDemoList()
44 me = NEW(XonoticDemoList);
45 me.configureXonoticDemoList(me);
49 void XonoticDemoList_configureXonoticDemoList(entity me)
51 me.configureXonoticListBox(me);
55 string XonoticDemoList_demoName(entity me, float i)
58 s = bufstr_get(me.listDemo, i);
60 if(substring(s, 0, 1) == "/")
61 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
66 // if subdir is true look in subdirectories too (1 level)
67 void getDemos_for_ext(entity me, string ext, float subdir)
75 s=strcat(s, me.filterString, ext);
77 s=strcat(s, "*", ext);
80 list = search_begin(s, false, true);
83 n = search_getsize(list);
84 for(i = 0; i < n; ++i)
86 s = search_getfilename(list, i); // get initial full file name
87 s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix
88 s = strdecolorize(s); // remove any pre-existing colors
91 s = strreplace("/", "^7/", s); // clear colors at the forward slash
92 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color
93 bufstr_add(me.listDemo, s, true);
95 else { bufstr_add(me.listDemo, s, true); }
101 getDemos_for_ext(me, ext, false);
104 void XonoticDemoList_getDemos(entity me)
106 if (me.listDemo >= 0)
107 buf_del(me.listDemo);
108 me.listDemo = buf_create();
114 getDemos_for_ext(me, ".dem", true);
115 me.nItems = buf_getsize(me.listDemo);
117 buf_sort(me.listDemo, 128, false);
120 void XonoticDemoList_destroy(entity me)
123 buf_del(me.listDemo);
126 void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
128 me.itemAbsSize = '0 0 0';
129 SUPER(XonoticDemoList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
131 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
132 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
133 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
135 me.columnNameOrigin = me.realFontSize.x;
136 me.columnNameSize = 1 - 2 * me.realFontSize.x;
139 void XonoticDemoList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
143 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
146 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
147 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
150 s = me.demoName(me,i);
151 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
152 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);
155 void XonoticDemoList_showNotify(entity me)
160 void DemoList_Refresh_Click(entity btn, entity me)
163 me.setSelected(me, 0); //always select the first element after a list update
166 void DemoList_Filter_Change(entity box, entity me)
169 strunzone(me.filterString);
173 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
174 me.filterString = strzone(box.text);
176 me.filterString = strzone(strcat("*", box.text, "*"));
179 me.filterString = string_null;
184 void XonoticDemoList_startDemo(entity me)
187 s = me.demoName(me, me.selectedItem);
188 s = strdecolorize(s);
190 localcmd("playdemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
193 void XonoticDemoList_timeDemo(entity me)
196 s = me.demoName(me, me.selectedItem);
197 s = strdecolorize(s);
199 localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
202 void DemoConfirm_ListClick_Check_Gamestatus(entity me)
204 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo
208 else // already in a match, player has to confirm
210 DialogOpenButton_Click_withCoords(
212 main.demostartconfirmDialog,
213 boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size),
214 boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size)
219 void XonoticDemoList_doubleClickListBoxItem(entity me, float i, vector where)
221 DemoConfirm_ListClick_Check_Gamestatus(me);
224 float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
226 if(scan == K_ENTER || scan == K_KP_ENTER)
228 DemoConfirm_ListClick_Check_Gamestatus(me);
233 return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);