+ scrolling transition to song wheel

This commit is contained in:
FajsiEx 2021-07-30 21:34:36 +02:00
parent a2520877dd
commit f25ab51cef
2 changed files with 42 additions and 6 deletions

View File

@ -23,7 +23,7 @@ local pow = function (a,b)
return a ^ b; return a ^ b;
end end
local function inQuad(t, b, c, d) local function inQuad(t)
t = t / 1 t = t / 1
return 1 * pow(t, 2) + 0 return 1 * pow(t, 2) + 0
end end

View File

@ -1,4 +1,6 @@
local Easing = require('common.easings');
local backgroundImage = gfx.CreateSkinImage("song_select/bg.png", 1) local backgroundImage = gfx.CreateSkinImage("song_select/bg.png", 1)
local songPlateBg = gfx.CreateSkinImage("song_select/plate/bg.png", 1) local songPlateBg = gfx.CreateSkinImage("song_select/plate/bg.png", 1)
local songPlateBottomBarOverlayImage = gfx.CreateSkinImage("song_select/plate/bottom_bar_overlay.png", 1) local songPlateBottomBarOverlayImage = gfx.CreateSkinImage("song_select/plate/bottom_bar_overlay.png", 1)
@ -33,11 +35,17 @@ local resx, resy = game.GetResolution()
local desw, desh; local desw, desh;
local scale; local scale;
local songPlateHeight = 172;
local selectedIndex = 1; local selectedIndex = 1;
local selectedDifficulty = 1; local selectedDifficulty = 1;
local jacketCache = {} local jacketCache = {}
local transitionScrollScale = 0;
local transitionScrollOffsetY = 0;
local scrollingUp = false;
function resetLayoutInformation() function resetLayoutInformation()
resx, resy = game.GetResolution() resx, resy = game.GetResolution()
desw = 1080 desw = 1080
@ -142,22 +150,23 @@ function drawSong(song, y)
end end
function drawSongList() function drawSongList()
local numOfSongsAround = 4; -- How many songs should be up and how many should be down of the selected one local numOfSongsAround = 7; -- How many songs should be up and how many should be down of the selected one
local i=1; local i=1;
while (i <= numOfSongsAround) do while (i <= numOfSongsAround) do
local songIndex = getCorrectedIndex(selectedIndex, -i) local songIndex = getCorrectedIndex(selectedIndex, -i)
drawSong(songwheel.songs[songIndex], desh/2-172/2-172*i) drawSong(songwheel.songs[songIndex], desh/2-songPlateHeight/2-songPlateHeight*i + transitionScrollOffsetY)
i=i+1; i=i+1;
end; end;
-- Draw the selected song -- Draw the selected song
drawSong(songwheel.songs[selectedIndex], desh/2-172/2) drawSong(songwheel.songs[selectedIndex], desh/2-songPlateHeight/2 + transitionScrollOffsetY)
i=1; i=1;
while (i <= numOfSongsAround) do while (i <= numOfSongsAround) do
local songIndex = getCorrectedIndex(selectedIndex, i) local songIndex = getCorrectedIndex(selectedIndex, i)
drawSong(songwheel.songs[songIndex], desh/2-172/2+172*i) drawSong(songwheel.songs[songIndex], desh/2-songPlateHeight/2+songPlateHeight*i + transitionScrollOffsetY)
i=i+1; i=i+1;
end; end;
end end
@ -167,8 +176,23 @@ function drawCursor()
gfx.ImageRect(desw/2-14, desh/2-213/2, 555, 213, cursorImage, 1, 0) gfx.ImageRect(desw/2-14, desh/2-213/2, 555, 213, cursorImage, 1, 0)
end end
function tickTransitions(deltaTime)
if transitionScrollScale < 1 then
transitionScrollScale = transitionScrollScale + deltaTime / 0.1 -- transition should last for that time in seconds
else
transitionScrollScale = 1
end
if scrollingUp then
transitionScrollOffsetY = Easing.inQuad(1-transitionScrollScale) * songPlateHeight;
else
transitionScrollOffsetY = Easing.inQuad(1-transitionScrollScale) * -songPlateHeight;
end
end
render = function (deltaTime) render = function (deltaTime)
resetLayoutInformation(); resetLayoutInformation();
tickTransitions(deltaTime);
gfx.Scale(scale, scale); gfx.Scale(scale, scale);
if not difficultyNumbers then if not difficultyNumbers then
@ -180,13 +204,25 @@ render = function (deltaTime)
drawSongList() drawSongList()
drawCursor() drawCursor()
gfx.BeginPath(); gfx.BeginPath();
gfx.FontSize(18) gfx.FontSize(18)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
gfx.Text('DELTA: ' .. deltaTime .. ' // SELECTED_INDEX: ' .. selectedIndex .. ' // SELECTED_DIFF: ' .. selectedDifficulty .. ' // #JACKET_CACHE: ' .. #jacketCache, 8, 8); local debugScrollingUp= "FALSE"
if scrollingUp then debugScrollingUp = "TRUE" end;
gfx.Text('DELTA: ' .. deltaTime .. ' // SELECTED_INDEX: ' .. selectedIndex .. ' // SELECTED_DIFF: ' .. selectedDifficulty .. ' // SCROLLING_UP: ' .. debugScrollingUp, 8, 8);
end end
set_index = function(newIndex) set_index = function(newIndex)
transitionScrollScale = 0;
scrollingUp = false;
if ((newIndex > selectedIndex and not (newIndex == #songwheel.songs and selectedIndex == 1)) or (newIndex == 1 and selectedIndex == #songwheel.songs)) then
scrollingUp = true;
end;
-- TODO: add sfx for cursor change
selectedIndex = newIndex; selectedIndex = newIndex;
end; end;