5 entity makeXonoticDemoList()
8 me = NEW(XonoticDemoList);
9 me.configureXonoticDemoList(me);
13 void XonoticDemoList_configureXonoticDemoList(entity me)
15 me.configureXonoticListBox(me);
19 string XonoticDemoList_demoName(entity me, float i)
22 s = bufstr_get(me.listDemo, i);
24 if(substring(s, 0, 1) == "/")
25 s = substring(s, 1, strlen(s) - 1); // remove the first forward slash
30 // if subdir is true look in subdirectories too (1 level)
31 void getDemos_for_ext(entity me, string ext, float subdir)
39 s=strcat(s, me.filterString, ext);
41 s=strcat(s, "*", ext);
44 list = search_begin(s, false, true);
47 n = search_getsize(list);
48 for(i = 0; i < n; ++i)
50 s = search_getfilename(list, i); // get initial full file name
51 s = substring(s, 6, (strlen(s) - 6 - 4)); // remove "demos/" prefix and ".dem" suffix
52 s = strdecolorize(s); // remove any pre-existing colors
55 s = strreplace("/", "^7/", s); // clear colors at the forward slash
56 s = strcat("/", rgb_to_hexcolor(SKINCOLOR_DEMOLIST_SUBDIR), s); // add a forward slash for sorting, then color
57 bufstr_add(me.listDemo, s, true);
59 else { bufstr_add(me.listDemo, s, true); }
65 getDemos_for_ext(me, ext, false);
68 void XonoticDemoList_getDemos(entity me)
72 me.listDemo = buf_create();
78 getDemos_for_ext(me, ".dem", true);
79 me.nItems = buf_getsize(me.listDemo);
81 buf_sort(me.listDemo, 128, false);
84 void XonoticDemoList_destroy(entity me)
90 void XonoticDemoList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
92 me.itemAbsSize = '0 0 0';
93 SUPER(XonoticDemoList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
95 me.itemAbsSize.y = absSize.y * me.itemHeight;
96 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
97 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
98 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
99 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
101 me.columnNameOrigin = me.realFontSize.x;
102 me.columnNameSize = 1 - 2 * me.realFontSize.x;
105 void XonoticDemoList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
109 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
112 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
113 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
116 s = me.demoName(me,i);
117 s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
118 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);
121 void XonoticDemoList_showNotify(entity me)
126 void DemoList_Refresh_Click(entity btn, entity me)
129 me.setSelected(me, 0); //always select the first element after a list update
132 void DemoList_Filter_Change(entity box, entity me)
134 strfree(me.filterString);
138 if (strstrofs(box.text, "*", 0) >= 0 || strstrofs(box.text, "?", 0) >= 0)
139 me.filterString = strzone(box.text);
141 me.filterString = strzone(strcat("*", box.text, "*"));
144 me.filterString = string_null;
149 void XonoticDemoList_startDemo(entity me)
152 s = me.demoName(me, me.selectedItem);
153 s = strdecolorize(s);
155 localcmd("playdemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
158 void XonoticDemoList_timeDemo(entity me)
161 s = me.demoName(me, me.selectedItem);
162 s = strdecolorize(s);
164 localcmd("timedemo \"demos/", s, ".dem\" \nwait \ntogglemenu\n");
167 void DemoConfirm_ListClick_Check_Gamestatus(entity me)
169 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER))) // we're not in a match, lets watch the demo
173 else // already in a match, player has to confirm
175 DialogOpenButton_Click_withCoords(
177 main.demostartconfirmDialog,
178 boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size),
179 boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size)
184 void XonoticDemoList_doubleClickListBoxItem(entity me, float i, vector where)
186 DemoConfirm_ListClick_Check_Gamestatus(me);
189 float XonoticDemoList_keyDown(entity me, float scan, float ascii, float shift)
191 if(scan == K_ENTER || scan == K_KP_ENTER)
193 DemoConfirm_ListClick_Check_Gamestatus(me);
198 return SUPER(XonoticDemoList).keyDown(me, scan, ascii, shift);