]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/soundlist.c
More fun stuff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / soundlist.c
index 17d53833c37e1813a9bd981080675a23f773d103..7d1515062ab5428aa09b0c272272aa4722a2f4c7 100644 (file)
@@ -5,11 +5,8 @@ CLASS(XonoticSoundList) EXTENDS(XonoticListBox)
        METHOD(XonoticSoundList, resizeNotify, void(entity, vector, vector, vector, vector))
        METHOD(XonoticSoundList, drawListBoxItem, void(entity, float, vector, float))
        METHOD(XonoticSoundList, getSounds, void(entity))
-       METHOD(XonoticSoundList, stopSound, void(entity))
-       METHOD(XonoticSoundList, startSound, void(entity, float))
-       METHOD(XonoticSoundList, pauseSound, void(entity))
        METHOD(XonoticSoundList, soundName, string(entity, float))
-       METHOD(XonoticSoundList, clickListBoxItem, void(entity, float, vector))
+       METHOD(XonoticSoundList, doubleClickListBoxItem, void(entity, float, vector))
        METHOD(XonoticSoundList, keyDown, float(entity, float, float, float))
        METHOD(XonoticSoundList, destroy, void(entity))
        METHOD(XonoticSoundList, showNotify, void(entity))
@@ -18,22 +15,20 @@ CLASS(XonoticSoundList) EXTENDS(XonoticListBox)
        ATTRIB(XonoticSoundList, realFontSize, vector, '0 0 0')
        ATTRIB(XonoticSoundList, columnNameOrigin, float, 0)
        ATTRIB(XonoticSoundList, columnNameSize, float, 0)
+       ATTRIB(XonoticSoundList, columnNumberOrigin, float, 0)
+       ATTRIB(XonoticSoundList, columnNumberSize, float, 0)
        ATTRIB(XonoticSoundList, realUpperMargin, float, 0)
        ATTRIB(XonoticSoundList, origin, vector, '0 0 0')
        ATTRIB(XonoticSoundList, itemAbsSize, vector, '0 0 0')
 
-       ATTRIB(XonoticSoundList, lastClickedSound, float, -1)
-       ATTRIB(XonoticSoundList, lastClickedTime, float, 0)
        ATTRIB(XonoticSoundList, filterString, string, string_null)
+       ATTRIB(XonoticSoundList, playlist, entity, world)
 ENDCLASS(XonoticSoundList)
 
 entity makeXonoticSoundList();
-void StopSound_Click(entity btn, entity me);
-void StartSound_Click(entity btn, entity me);
-void PauseSound_Click(entity btn, entity me);
-void PrevSound_Click(entity btn, entity me);
-void NextSound_Click(entity btn, entity me);
 void SoundList_Filter_Change(entity box, entity me);
+void SoundList_Add(entity box, entity me);
+void SoundList_Add_All(entity box, entity me);
 void SoundList_Menu_Track_Change(entity box, entity me);
 void SoundList_Menu_Track_Reset(entity box, entity me);
 #endif
@@ -66,13 +61,12 @@ string XonoticSoundList_soundName(entity me, float i )
 void XonoticSoundList_getSounds(entity me)
 {
        string s;
-       float i;
 
        if(me.filterString)
                //subdirectory in filterString allowed
-               s=strcat("sound/cdtracks/*", me.filterString, "*.ogg");
+               s = strcat("sound/cdtracks/*", me.filterString, "*.ogg");
        else
-               s="sound/cdtracks/*.ogg";
+               s = "sound/cdtracks/*.ogg";
 
        if(me.listSound >= 0)
                search_end(me.listSound);
@@ -83,18 +77,12 @@ void XonoticSoundList_getSounds(entity me)
                me.nItems=0;
        else
                me.nItems=search_getsize(me.listSound);
-
-       cvar_set("music_playlist_list0", "");
-       s = "";
-       for(i=0; i<me.nItems; ++i)
-       {
-               cvar_set("music_playlist_list0", strcat(cvar_string("music_playlist_list0"), me.soundName(me,i), " "));
-       }
 }
 
 void XonoticSoundList_destroy(entity me)
 {
-       search_end(me.listSound);
+       if(me.listSound >= 0)
+               search_end(me.listSound);
 }
 
 void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
@@ -106,8 +94,11 @@ void XonoticSoundList_resizeNotify(entity me, vector relOrigin, vector relSize,
        me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize_x * (1 - me.controlWidth)));
        me.realUpperMargin = 0.5 * (1 - me.realFontSize_y);
 
-       me.columnNameOrigin = me.realFontSize_x;
-       me.columnNameSize = 1 - 2 * me.realFontSize_x;
+       me.columnNumberOrigin = 0;
+       me.columnNumberSize = me.realFontSize_x * 3;
+
+       me.columnNameOrigin = me.columnNumberSize;
+       me.columnNameSize = 1 - me.columnNameOrigin - me.realFontSize_x;
 }
 
 void XonoticSoundList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
@@ -116,19 +107,12 @@ void XonoticSoundList_drawListBoxItem(entity me, float i, vector absSize, float
        if(isSelected)
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
 
-       if(cvar("music_playlist_current0") == i)
-       {
-               float f = cvar("music_playlist_sampleposition0");
-               if(f == 0 || (((time * 2) & 1) && f > 0))
-                       draw_Text(me.realUpperMargin * eY, chr(0xE000 + 141), me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
-       }
-
        s = me.soundName(me,i);
-       if(s == cvar_defstring("menu_cdtrack"))
-               s = strcat(s, " [default menu track]");
-       else if(s == cvar_string("menu_cdtrack"))
-               s = strcat(s, " [current menu track]");
-       s = strcat(ftos(i+1), ") ", s);
+       if(s == cvar_string("menu_cdtrack")) // current menu track
+               draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[C]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+       else if(s == cvar_defstring("menu_cdtrack")) // default menu track
+               draw_CenterText((me.columnNumberOrigin + 0.5 * me.columnNumberSize) * eX + me.realUpperMargin * eY, "[D]", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+
        s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
 }
@@ -161,95 +145,27 @@ void SoundList_Filter_Change(entity box, entity me)
        me.getSounds(me);
 }
 
-void XonoticSoundList_stopSound(entity me)
-{
-       // STOP: list 0 is disabled by setting the index to -1
-       // we set sampleposition0 to -1 to indicate that music is stopped
-       if(cvar("music_playlist_index") != -1) // == 0 doesn't work when paused
-       {
-               cvar_set("music_playlist_index", "-1");
-               localcmd("\nwait; music_playlist_sampleposition0 -1\n");
-               localcmd("\ndefer 3 \"cd play $menu_cdtrack\"\n");
-       }
-}
-
-void StopSound_Click(entity btn, entity me)
-{
-       me.stopSound(me);
-}
-
-void XonoticSoundList_startSound(entity me, float offset)
-{
-       float f;
-       if(offset)
-       {
-               f = bound(0, cvar("music_playlist_current0") + offset, me.nItems - 1);
-               if(f == cvar("music_playlist_current0"))
-                       return;
-       }
-       else
-               f = me.selectedItem;
-       // START: list 0 is disabled by setting the index to 999
-       // we set current0 to the selected track and sampleposition0 to 0 to forget value saved by the engine
-       // then we switch back to list 0
-       cvar_set("music_playlist_index", "999");
-       cvar_set("music_playlist_current0", ftos(f));
-       localcmd("\nwait; music_playlist_sampleposition0 0; wait; music_playlist_index 0\n");
-}
-
-void StartSound_Click(entity btn, entity me)
+void SoundList_Add(entity box, entity me)
 {
-       me.startSound(me, 0);
+       me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
 }
 
-void PrevSound_Click(entity btn, entity me)
+void SoundList_Add_All(entity box, entity me)
 {
-       me.startSound(me, -1);
-}
-
-void NextSound_Click(entity btn, entity me)
-{
-       me.startSound(me, +1);
-}
-
-void XonoticSoundList_pauseSound(entity me)
-{
-       // PAUSE: list 0 is disabled by setting the index to 999
-       // (we know the track is paused because the engine sets sampleposition0 to remember current position)
-       // RESUME: list 0 is enabled by setting the index to 0
-       // (we reset sampleposition0 to 0 to mark the track as in playing back state)
-       if(cvar("music_playlist_index") == 0)
-               localcmd("\nmusic_playlist_index 999\n");
-       else
-               localcmd("\nmusic_playlist_index 0; wait; music_playlist_sampleposition0 0\n");
-}
-
-void PauseSound_Click(entity btn, entity me)
-{
-       me.pauseSound(me);
+       float i;
+       for(i = 0; i < me.nItems; ++i)
+               me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
 }
 
-void XonoticSoundList_clickListBoxItem(entity me, float i, vector where)
+void XonoticSoundList_doubleClickListBoxItem(entity me, float i, vector where)
 {
-       if(i == me.lastClickedSound)
-               if(time < me.lastClickedTime + 0.3)
-               {
-                       // DOUBLE CLICK!
-                       me.setSelected(me, i);
-                       me.startSound(me, 0);
-               }
-       me.lastClickedSound = i;
-       me.lastClickedTime = time;
+       me.playlist.addToPlayList(me.playlist, me.soundName(me, i));
 }
 
 float XonoticSoundList_keyDown(entity me, float scan, float ascii, float shift)
 {
-       if(scan == K_ENTER || scan == K_KP_ENTER) {
-               me.startSound(me, 0);
-               return 1;
-       }
-       else if(scan == K_SPACE) {
-               me.pauseSound(me);
+       if(scan == K_ENTER || scan == K_KP_ENTER || scan == K_SPACE) {
+               me.playlist.addToPlayList(me.playlist, me.soundName(me, me.selectedItem));
                return 1;
        }
        else