From 841fb1fa353ca60c3a8ca0dfed8894d69e124727 Mon Sep 17 00:00:00 2001 From: Kyle Humphrey Date: Tue, 15 Mar 2022 23:51:53 -0500 Subject: [PATCH] reimplement scrollbar for songSelect and folderSelect --- scripts/songselect/filterwheel.lua | 52 ++++++++++++++++++------------ scripts/songselect/songwheel.lua | 33 +++++++++++++++++++ 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/scripts/songselect/filterwheel.lua b/scripts/songselect/filterwheel.lua index c9030b3..40b2180 100644 --- a/scripts/songselect/filterwheel.lua +++ b/scripts/songselect/filterwheel.lua @@ -9,8 +9,8 @@ local defaultFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/bg.pn local collectionFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/col_bg.png', 0) local subFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/sub_bg.png', 0) -local scrollbarBgImage = gfx.CreateSkinImage("song_select/scrollbar/bg.png", 1) -local scrollbarFillImage = gfx.CreateSkinImage("song_select/scrollbar/fill.png", 1) +local scrollBarBackgroundImage = gfx.CreateSkinImage("song_select/scrollbar/bg.png", 1) +local scrollBarFillImage = gfx.CreateSkinImage("song_select/scrollbar/fill.png", 1) local cursorImages = { gfx.CreateSkinImage("song_select/cursor.png", 1), -- Effective rate or fallback @@ -283,27 +283,39 @@ function drawScrollbar() if not isFilterWheelActive or transitionLeaveScale ~= 0 then return end gfx.BeginPath() - local bgW = 13*0.85; - local bgH = 1282*0.85; - local scrollPosX = desw-20 - local scrollPosY = desh/2-bgH/2 - - gfx.ImageRect(scrollPosX, scrollPosY, bgW, bgH, scrollbarBgImage, 1, 0) - - local total = game.GetSkinSetting('_songWheelScrollbarTotal') - local index = game.GetSkinSetting('_songWheelScrollbarIndex') - - if (index == nil) then return end; + local resize = 0.85; + local lw, lh = gfx.ImageSize(scrollBarBackgroundImage); + local lw = lw * resize; + local lh = lh * resize; + local xPos = desw-20 + local backgroundYPos = desh/2 - lh/2 + gfx.ImageRect(xPos, backgroundYPos, lw, lh, scrollBarBackgroundImage, 1, 0) gfx.BeginPath() - local fillW = 27*0.85 - local fillH = 65*0.85 - local fillPosOffsetY = (bgH-fillH)*( - (index-1) / - math.max(1,total-1) - ) + local sw, sh = gfx.ImageSize(scrollBarFillImage); + local sw = sw * resize; + local sh = sh * resize; + local fillXPos = xPos - 6; - gfx.ImageRect(scrollPosX-6, scrollPosY+fillPosOffsetY, fillW, fillH, scrollbarFillImage, 1, 0) + -- figure out index and total + local index = 1; + local total = 1; + if selectionMode == 'folders' then + index = selectedFolder + total = #filters.folder; + else + index = selectedLevel + total = #filters.level; + end + + + local minScrollYPos = backgroundYPos; + local maxScrollYPos = backgroundYPos + lh - sh; + local scrollStep = (maxScrollYPos - minScrollYPos) / (total - 1); + local scrollbarYOffset = (index - 1) * scrollStep; + local scrollbarYPos = minScrollYPos + scrollbarYOffset; + + gfx.ImageRect(fillXPos, scrollbarYPos, sw, sh, scrollBarFillImage, 1, 0) end function tickTransitions(deltaTime) diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index 1d3aa83..c4cd5c9 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -26,6 +26,9 @@ local top50JacketOverlayImage = gfx.CreateSkinImage("song_select/top50_jacket.pn local diffCursorImage = gfx.CreateSkinImage("song_select/level_cursor.png", 1) +local scrollBarBackgroundImage = gfx.CreateSkinImage("song_select/scrollbar/bg.png", 1) +local scrollBarFillImage = gfx.CreateSkinImage("song_select/scrollbar/fill.png", 1) + local filterInfoBgImage = gfx.CreateSkinImage("song_select/filter_info_bg.png", 1) local sortInfoBgImage = gfx.CreateSkinImage("song_select/sort_info_bg.png", 1) @@ -744,6 +747,34 @@ function drawSearch() gfx.Text(songwheel.searchText, xPos + 160, yPos + 83.2); end +function drawScrollbar() + if isFilterWheelActive or transitionLeaveScale ~= 0 then return end + + gfx.BeginPath() + local resize = 0.85; + local lw, lh = gfx.ImageSize(scrollBarBackgroundImage); + local lw = lw * resize; + local lh = lh * resize; + local xPos = desw-20 + local backgroundYPos = desh/2 - lh/2 + gfx.ImageRect(xPos, backgroundYPos, lw, lh, scrollBarBackgroundImage, 1, 0) + + gfx.BeginPath() + local sw, sh = gfx.ImageSize(scrollBarFillImage); + local sw = sw * resize; + local sh = sh * resize; + local fillXPos = xPos - 6; + + local minScrollYPos = backgroundYPos; + local maxScrollYPos = backgroundYPos + lh - sh; + local scrollStep = (maxScrollYPos - minScrollYPos) / (#songwheel.songs - 1); + local scrollbarYOffset = (selectedIndex - 1) * scrollStep; + local scrollbarYPos = minScrollYPos + scrollbarYOffset; + + gfx.ImageRect(fillXPos, scrollbarYPos, sw, sh, scrollBarFillImage, 1, 0) + +end + function refreshIrLeaderboard(deltaTime) if not IRData.Active then return; @@ -1030,6 +1061,8 @@ draw_songwheel = function(x,y,w,h, deltaTime) drawSearch(); + drawScrollbar(); + gfx.BeginPath(); gfx.FontSize(18) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)