4 CLASS(XonoticPlayList, XonoticListBox)
5 METHOD(XonoticPlayList, configureXonoticPlayList, void(entity));
6 ATTRIB(XonoticPlayList, rowsPerItem, float, 1)
7 METHOD(XonoticPlayList, resizeNotify, void(entity, vector, vector, vector, vector));
8 METHOD(XonoticPlayList, draw, void(entity));
9 METHOD(XonoticPlayList, drawListBoxItem, void(entity, int, vector, bool, bool));
10 METHOD(XonoticPlayList, stopSound, void(entity));
11 METHOD(XonoticPlayList, startSound, void(entity, float));
12 METHOD(XonoticPlayList, resumeSound, void(entity));
13 METHOD(XonoticPlayList, pauseSound, void(entity));
14 METHOD(XonoticPlayList, doubleClickListBoxItem, void(entity, float, vector));
15 METHOD(XonoticPlayList, keyDown, float(entity, float, float, float));
16 METHOD(XonoticPlayList, mouseDrag, float(entity, vector));
18 METHOD(XonoticPlayList, addToPlayList, void(entity, string));
19 METHOD(XonoticPlayList, removeSelectedFromPlayList, void(entity));
20 ATTRIB(XonoticPlayList, playingTrack, float, -1)
22 ATTRIB(XonoticPlayList, realFontSize, vector, '0 0 0')
23 ATTRIB(XonoticPlayList, columnNameOrigin, float, 0)
24 ATTRIB(XonoticPlayList, columnNameSize, float, 0)
25 ATTRIB(XonoticPlayList, columnNumberOrigin, float, 0)
26 ATTRIB(XonoticPlayList, columnNumberSize, float, 0)
27 ATTRIB(XonoticPlayList, realUpperMargin, float, 0)
28 ATTRIB(XonoticPlayList, origin, vector, '0 0 0')
29 ATTRIB(XonoticPlayList, itemAbsSize, vector, '0 0 0')
30 ENDCLASS(XonoticPlayList)
32 entity makeXonoticPlayList();
33 void PlayList_Remove(entity btn, entity me);
34 void PlayList_Remove_All(entity btn, entity me);
35 void StopSound_Click(entity btn, entity me);
36 void StartSound_Click(entity btn, entity me);
37 void PauseSound_Click(entity btn, entity me);
38 void PrevSound_Click(entity btn, entity me);
39 void NextSound_Click(entity btn, entity me);
44 entity makeXonoticPlayList()
47 me = NEW(XonoticPlayList);
48 me.configureXonoticPlayList(me);
52 void XonoticPlayList_configureXonoticPlayList(entity me)
54 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
55 me.configureXonoticListBox(me);
58 void XonoticPlayList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
60 me.itemAbsSize = '0 0 0';
61 SUPER(XonoticPlayList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
63 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
64 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
65 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
67 me.columnNumberOrigin = 0;
68 me.columnNumberSize = 3 * me.realFontSize.x;
70 me.columnNameOrigin = me.columnNumberSize + me.realFontSize.x;
71 me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize.x;
74 void XonoticPlayList_addToPlayList(entity me, string track)
76 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
79 cvar_set("music_playlist_list0", track);
83 for(i = 0; i < me.nItems; ++i)
86 return; // track is already in playlist
88 cvar_set("music_playlist_list0", strcat(cvar_string("music_playlist_list0"), " ", track));
91 void XonoticPlayList_removeSelectedFromPlayList(entity me)
95 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
98 for(i = 0; i < me.nItems; ++i)
100 if(i == me.selectedItem)
102 if(i == me.nItems - 1)
103 me.setSelected(me, me.selectedItem - 1);
104 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
106 if(cvar("music_playlist_current0") == i)
107 cpt = true; // current playing track (we can't start next track here because startSound calls tokenize_console)
108 else if(cvar("music_playlist_current0") > i)
109 cvar_set("music_playlist_current0", ftos(cvar("music_playlist_current0") - 1));
113 s = strcat(s, " ", argv(i));
115 // we must stop the current playing track if it has been removed
116 // otherwise pause/play button will resume from another track
119 cvar_set("music_playlist_list0", "");
125 cvar_set("music_playlist_list0", substring(s, 1, strlen(s))); // remove initial space
127 me.startSound(me, 0);
131 void PlayList_Remove(entity btn, entity me)
133 me.removeSelectedFromPlayList(me);
136 void PlayList_Remove_All(entity btn, entity me)
138 cvar_set("music_playlist_list0", "");
143 float XonoticPlayList_mouseDrag(entity me, vector pos)
147 f = SUPER(XonoticPlayList).mouseDrag(me, pos);
149 if(me.pressed != 1) // don't change priority if the person is just scrolling
151 if(me.selectedItem != i)
153 cvar_set("music_playlist_list0", swapInPriorityList(cvar_string("music_playlist_list0"), me.selectedItem, i));
154 float c = cvar("music_playlist_current0");
156 cvar_set("music_playlist_current0", ftos(me.selectedItem));
157 else if(c == me.selectedItem)
158 cvar_set("music_playlist_current0", ftos(i));
165 void XonoticPlayList_draw(entity me)
167 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
168 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
169 me.playingTrack = cvar("music_playlist_current0");
171 me.playingTrack = -1;
172 SUPER(XonoticPlayList).draw(me);
175 void XonoticPlayList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
179 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
182 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
183 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
186 if(i == me.playingTrack)
188 float f = cvar("music_playlist_sampleposition0");
189 if(f <= 0 || (((time * 2) & 1) && f > 0))
190 draw_Text(me.realUpperMargin * eY + (me.columnNumberOrigin + me.columnNumberSize) * eX, "\xE2\x96\xB6", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
194 draw_CenterText(me.realUpperMargin * eY + (me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
196 s = draw_TextShortenToWidth(argv(i), me.columnNameSize, 0, me.realFontSize);
197 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
200 void XonoticPlayList_stopSound(entity me)
202 // STOP: list 0 is disabled by setting the index to -1
203 // we set sampleposition0 to 0 to forget the position that the engine saves in this frame (for this reason we need to wait a frame)
204 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
206 cvar_set("music_playlist_index", "-1");
207 localcmd("\nwait; music_playlist_sampleposition0 0\n");
208 localcmd("\ndefer 3 \"cd play $menu_cdtrack\"\n");
212 void StopSound_Click(entity btn, entity me)
217 void XonoticPlayList_startSound(entity me, float offset)
220 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
223 if(cvar("music_playlist_index") == -1)
225 f = bound(0, cvar("music_playlist_current0") + offset, me.nItems - 1);
226 if(f == cvar("music_playlist_current0"))
232 // if it was paused then resume
233 if(f == cvar("music_playlist_current0"))
234 if(cvar("music_playlist_index") == 999)
239 // if it was not paused then proceed with restart
242 // START: list 0 is disabled by setting the index to 999
243 // we set current0 to the selected track and sampleposition0 to 0 to forget the position that the engine saves in this frame (for this reason we need to wait a frame)
244 // then we switch back to list 0
245 cvar_set("music_playlist_index", "999");
246 cvar_set("music_playlist_current0", ftos(f));
247 localcmd("\nwait; music_playlist_sampleposition0 0; wait; music_playlist_index 0\n");
250 void StartSound_Click(entity btn, entity me)
252 me.startSound(me, 0);
255 void PrevSound_Click(entity btn, entity me)
257 me.startSound(me, -1);
260 void NextSound_Click(entity btn, entity me)
262 me.startSound(me, +1);
265 void XonoticPlayList_resumeSound(entity me)
267 // RESUME: list 0 is enabled by setting the index to 0
268 // (we reset sampleposition0 to 0 to mark the track as in playing back state)
269 if(cvar("music_playlist_index") == 999)
270 localcmd("\nmusic_playlist_index 0; wait; music_playlist_sampleposition0 0\n");
272 void XonoticPlayList_pauseSound(entity me)
274 // PAUSE: list 0 is disabled by setting the index to 999
275 // (we know the track is paused because the engine sets sampleposition0 to remember current position)
276 if(cvar("music_playlist_index") == 0)
277 localcmd("\nmusic_playlist_index 999\n");
278 else me.resumeSound(me);
281 void PauseSound_Click(entity btn, entity me)
286 void XonoticPlayList_doubleClickListBoxItem(entity me, float i, vector where)
288 me.startSound(me, 0);
291 float XonoticPlayList_keyDown(entity me, float scan, float ascii, float shift)
293 if(scan == K_ENTER || scan == K_KP_ENTER) {
294 me.startSound(me, 0);
297 else if(scan == K_SPACE) {
301 else if(scan == K_DEL || scan == K_KP_DEL || scan == K_BACKSPACE || scan == K_MOUSE3) {
302 me.removeSelectedFromPlayList(me);
306 return SUPER(XonoticPlayList).keyDown(me, scan, ascii, shift);