2 CLASS(XonoticPlayList) EXTENDS(XonoticListBox)
3 METHOD(XonoticPlayList, configureXonoticPlayList, void(entity))
4 ATTRIB(XonoticPlayList, rowsPerItem, float, 1)
5 METHOD(XonoticPlayList, resizeNotify, void(entity, vector, vector, vector, vector))
6 METHOD(XonoticPlayList, draw, void(entity))
7 METHOD(XonoticPlayList, drawListBoxItem, void(entity, int, vector, bool, float))
8 METHOD(XonoticPlayList, stopSound, void(entity))
9 METHOD(XonoticPlayList, startSound, void(entity, float))
10 METHOD(XonoticPlayList, resumeSound, void(entity))
11 METHOD(XonoticPlayList, pauseSound, void(entity))
12 METHOD(XonoticPlayList, doubleClickListBoxItem, void(entity, float, vector))
13 METHOD(XonoticPlayList, keyDown, float(entity, float, float, float))
14 METHOD(XonoticPlayList, mouseDrag, float(entity, vector))
16 METHOD(XonoticPlayList, addToPlayList, void(entity, string))
17 METHOD(XonoticPlayList, removeSelectedFromPlayList, void(entity))
18 ATTRIB(XonoticPlayList, playingTrack, float, -1)
20 ATTRIB(XonoticPlayList, realFontSize, vector, '0 0 0')
21 ATTRIB(XonoticPlayList, columnNameOrigin, float, 0)
22 ATTRIB(XonoticPlayList, columnNameSize, float, 0)
23 ATTRIB(XonoticPlayList, columnNumberOrigin, float, 0)
24 ATTRIB(XonoticPlayList, columnNumberSize, float, 0)
25 ATTRIB(XonoticPlayList, realUpperMargin, float, 0)
26 ATTRIB(XonoticPlayList, origin, vector, '0 0 0')
27 ATTRIB(XonoticPlayList, itemAbsSize, vector, '0 0 0')
28 ENDCLASS(XonoticPlayList)
30 entity makeXonoticPlayList();
31 void PlayList_Remove(entity btn, entity me);
32 void PlayList_Remove_All(entity btn, entity me);
33 void StopSound_Click(entity btn, entity me);
34 void StartSound_Click(entity btn, entity me);
35 void PauseSound_Click(entity btn, entity me);
36 void PrevSound_Click(entity btn, entity me);
37 void NextSound_Click(entity btn, entity me);
42 entity makeXonoticPlayList()
45 me = spawnXonoticPlayList();
46 me.configureXonoticPlayList(me);
50 void XonoticPlayList_configureXonoticPlayList(entity me)
52 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
53 me.configureXonoticListBox(me);
56 void XonoticPlayList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
58 me.itemAbsSize = '0 0 0';
59 SUPER(XonoticPlayList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
61 me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
62 me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
63 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
65 me.columnNumberOrigin = 0;
66 me.columnNumberSize = 3 * me.realFontSize.x;
68 me.columnNameOrigin = me.columnNumberSize + me.realFontSize.x;
69 me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize.x;
72 void XonoticPlayList_addToPlayList(entity me, string track)
74 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
77 cvar_set("music_playlist_list0", track);
81 for(i = 0; i < me.nItems; ++i)
84 return; // track is already in playlist
86 cvar_set("music_playlist_list0", strcat(cvar_string("music_playlist_list0"), " ", track));
89 void XonoticPlayList_removeSelectedFromPlayList(entity me)
93 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
96 for(i = 0; i < me.nItems; ++i)
98 if(i == me.selectedItem)
100 if(i == me.nItems - 1)
101 me.setSelected(me, me.selectedItem - 1);
102 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
104 if(cvar("music_playlist_current0") == i)
105 cpt = true; // current playing track (we can't start next track here because startSound calls tokenize_console)
106 else if(cvar("music_playlist_current0") > i)
107 cvar_set("music_playlist_current0", ftos(cvar("music_playlist_current0") - 1));
111 s = strcat(s, " ", argv(i));
113 // we must stop the current playing track if it has been removed
114 // otherwise pause/play button will resume from another track
117 cvar_set("music_playlist_list0", "");
123 cvar_set("music_playlist_list0", substring(s, 1, strlen(s))); // remove initial space
125 me.startSound(me, 0);
129 void PlayList_Remove(entity btn, entity me)
131 me.removeSelectedFromPlayList(me);
134 void PlayList_Remove_All(entity btn, entity me)
136 cvar_set("music_playlist_list0", "");
141 float XonoticPlayList_mouseDrag(entity me, vector pos)
145 f = SUPER(XonoticPlayList).mouseDrag(me, pos);
147 if(me.pressed != 1) // don't change priority if the person is just scrolling
149 if(me.selectedItem != i)
151 cvar_set("music_playlist_list0", swapInPriorityList(cvar_string("music_playlist_list0"), me.selectedItem, i));
152 float c = cvar("music_playlist_current0");
154 cvar_set("music_playlist_current0", ftos(me.selectedItem));
155 else if(c == me.selectedItem)
156 cvar_set("music_playlist_current0", ftos(i));
163 void XonoticPlayList_draw(entity me)
165 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
166 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
167 me.playingTrack = cvar("music_playlist_current0");
169 me.playingTrack = -1;
170 SUPER(XonoticPlayList).draw(me);
173 void XonoticPlayList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, float highlightedTime)
177 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
178 else if(highlightedTime)
179 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, getHighlightAlpha(SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED, highlightedTime));
181 if(i == me.playingTrack)
183 float f = cvar("music_playlist_sampleposition0");
184 if(f <= 0 || (((time * 2) & 1) && f > 0))
185 draw_Text(me.realUpperMargin * eY + (me.columnNumberOrigin + me.columnNumberSize) * eX, "\xE2\x96\xB6", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
189 draw_CenterText(me.realUpperMargin * eY + (me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
191 s = draw_TextShortenToWidth(argv(i), me.columnNameSize, 0, me.realFontSize);
192 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
195 void XonoticPlayList_stopSound(entity me)
197 // STOP: list 0 is disabled by setting the index to -1
198 // 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)
199 if(cvar("music_playlist_index") == 0 || cvar("music_playlist_index") == 999)
201 cvar_set("music_playlist_index", "-1");
202 localcmd("\nwait; music_playlist_sampleposition0 0\n");
203 localcmd("\ndefer 3 \"cd play $menu_cdtrack\"\n");
207 void StopSound_Click(entity btn, entity me)
212 void XonoticPlayList_startSound(entity me, float offset)
215 me.nItems = tokenize_console(cvar_string("music_playlist_list0"));
218 if(cvar("music_playlist_index") == -1)
220 f = bound(0, cvar("music_playlist_current0") + offset, me.nItems - 1);
221 if(f == cvar("music_playlist_current0"))
227 // if it was paused then resume
228 if(f == cvar("music_playlist_current0"))
229 if(cvar("music_playlist_index") == 999)
234 // if it was not paused then proceed with restart
237 // START: list 0 is disabled by setting the index to 999
238 // 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)
239 // then we switch back to list 0
240 cvar_set("music_playlist_index", "999");
241 cvar_set("music_playlist_current0", ftos(f));
242 localcmd("\nwait; music_playlist_sampleposition0 0; wait; music_playlist_index 0\n");
245 void StartSound_Click(entity btn, entity me)
247 me.startSound(me, 0);
250 void PrevSound_Click(entity btn, entity me)
252 me.startSound(me, -1);
255 void NextSound_Click(entity btn, entity me)
257 me.startSound(me, +1);
260 void XonoticPlayList_resumeSound(entity me)
262 // RESUME: list 0 is enabled by setting the index to 0
263 // (we reset sampleposition0 to 0 to mark the track as in playing back state)
264 if(cvar("music_playlist_index") == 999)
265 localcmd("\nmusic_playlist_index 0; wait; music_playlist_sampleposition0 0\n");
267 void XonoticPlayList_pauseSound(entity me)
269 // PAUSE: list 0 is disabled by setting the index to 999
270 // (we know the track is paused because the engine sets sampleposition0 to remember current position)
271 if(cvar("music_playlist_index") == 0)
272 localcmd("\nmusic_playlist_index 999\n");
273 else me.resumeSound(me);
276 void PauseSound_Click(entity btn, entity me)
281 void XonoticPlayList_doubleClickListBoxItem(entity me, float i, vector where)
283 me.startSound(me, 0);
286 float XonoticPlayList_keyDown(entity me, float scan, float ascii, float shift)
288 if(scan == K_ENTER || scan == K_KP_ENTER) {
289 me.startSound(me, 0);
292 else if(scan == K_SPACE) {
296 else if(scan == K_DEL || scan == K_KP_DEL || scan == K_BACKSPACE || scan == K_MOUSE3) {
297 me.removeSelectedFromPlayList(me);
301 return SUPER(XonoticPlayList).keyDown(me, scan, ascii, shift);