From a2520877dd2630493a52cc7b51d8ecb0c1dcda17 Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Fri, 30 Jul 2021 20:18:03 +0200 Subject: [PATCH] + infinite scroll to songwheel --- scripts/songselect/songwheel.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index d9c1557..b7e7acb 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -74,6 +74,23 @@ function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern) end end +function getCorrectedIndex(from, offset) + total = #songwheel.songs; + + index = from + offset; + + if index < 1 then + index = total + (from+offset) -- this only happens if the offset is negative + end; + + if index > total then + indexesUntilEnd = total - from; + index = offset - indexesUntilEnd -- this only happens if the offset is positive + end; + + return index; +end; + function getJacketImage(song) if not jacketCache[song.id] then jacketCache[song.id] = gfx.CreateImage(song.difficulties[1].jacketPath, 0) @@ -129,7 +146,8 @@ function drawSongList() local i=1; while (i <= numOfSongsAround) do - drawSong(songwheel.songs[selectedIndex-i], desh/2-172/2-172*i) + local songIndex = getCorrectedIndex(selectedIndex, -i) + drawSong(songwheel.songs[songIndex], desh/2-172/2-172*i) i=i+1; end; @@ -138,7 +156,8 @@ function drawSongList() i=1; while (i <= numOfSongsAround) do - drawSong(songwheel.songs[selectedIndex+i], desh/2-172/2+172*i) + local songIndex = getCorrectedIndex(selectedIndex, i) + drawSong(songwheel.songs[songIndex], desh/2-172/2+172*i) i=i+1; end; end