reimplement scrollbar for songSelect and folderSelect #5

Merged
Kuenaimaku merged 1 commits from feature/TASK-21-Scrollbar-fix into master 2022-03-16 05:54:33 +01:00
2 changed files with 65 additions and 20 deletions

View File

@ -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)

View File

@ -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)