ExperimentalGear/scripts/songselect/filterwheel.lua

439 lines
13 KiB
Lua
Raw Normal View History

2022-05-06 00:05:20 +02:00
local Easing = require('common.easing')
local Dim = require("common.dimensions")
local SongSelectHeader = require('components.headers.songSelectHeader')
2022-05-06 00:05:20 +02:00
local Footer = require('components.footer')
2021-11-22 20:39:56 +01:00
local defaultFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/bg.png', 0)
local collectionFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/col_bg.png', 0)
local subFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/sub_bg.png', 0)
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
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
gfx.CreateSkinImage("song_select/cursor_exc.png", 1), -- Excessive rate
gfx.CreateSkinImage("song_select/cursor_perm.png", 1), -- Premissive rate
gfx.CreateSkinImage("song_select/cursor_blast.png", 1), -- Blastive rate
}
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
local ITEM_HEIGHT = 172
2021-08-12 11:49:15 +02:00
local specialFolders = {
{
keys = {
'SOUND VOLTEX BOOTH', 'SDVX BOOTH', 'SOUND VOLTEX I', 'SDVX I',
'SOUND VOLTEX 1', 'SDVX 1', 'SDVX I BOOTH'
2021-08-12 11:49:15 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Booth.png', 0)
}, {
2021-08-12 11:49:15 +02:00
keys = {
'SOUND VOLTEX INFINITE INFECTION', 'SDVX INFINITE INFECTION',
'SOUND VOLTEX II', 'SDVX II', 'SOUND VOLTEX 2', 'SDVX 2', 'SDVX II INFINITE INFECTION'
2021-08-12 11:49:15 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Infinite Infection.png',
0)
},
{
keys = {
'SOUND VOLTEX GRAVITY WARS',
'SDVX GRAVITY WARS',
'SOUND VOLTEX III',
'SDVX III',
'SOUND VOLTEX 3',
'SDVX 3',
'SDVX III GRAVITY WARS',
},
folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Gravity Wars.png', 0)
},
2021-08-12 11:49:15 +02:00
{
keys = {
'SOUND VOLTEX HEAVENLY HAVEN', 'SDVX HEAVENLY HAVEN',
'SOUND VOLTEX IV', 'SDVX IV', 'SOUND VOLTEX 4', 'SDVX 4', 'SDVX IV HEAVENLY HAVEN'
2021-08-12 11:49:15 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Heavenly Haven.png', 0)
}, {
2021-08-12 11:49:15 +02:00
keys = {
'SOUND VOLTEX VIVID WAVE', 'SDVX VIVID WAVE', 'SOUND VOLTEX V',
'SDVX V', 'SOUND VOLTEX 5', 'SDVX 5', 'SDVX V VIVID WAVE'
2021-08-12 11:49:15 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Vivid Wave.png', 0)
}, {
2021-08-12 11:49:15 +02:00
keys = {
'SOUND VOLTEX EXCEED GEAR', 'SDVX EXCEED GEAR', 'SOUND VOLTEX VI',
'SDVX VI', 'SOUND VOLTEX 6', 'SDVX 6', 'SDVX VI EXCEED GEAR'
2021-08-12 11:49:15 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Exceed Gear.png', 0)
}, {
keys = {
'NAUTICA',
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/Nautica.png', 0)
2021-10-22 21:01:46 +02:00
}, {
keys = {
2021-10-26 02:07:47 +02:00
'KSHOOTMANIA', 'K-SHOOT MANIA', "K SHOOT MANIA"
2021-10-22 21:01:46 +02:00
},
folderBg = gfx.CreateSkinImage(
'song_select/filter_wheel/special_folder_bgs/KShootMania.png', 0)
},
2021-08-12 11:49:15 +02:00
}
-- AUDIO
2022-05-06 00:05:20 +02:00
game.LoadSkinSample('song_wheel/cursor_change.wav')
game.LoadSkinSample('filter_wheel/open_close.wav')
2021-08-12 11:49:15 +02:00
local resx, resy = game.GetResolution()
local desw, desh = 1080, 1920
2022-05-06 00:05:20 +02:00
local scale = 1
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
local isFilterWheelActive = false
local previousActiveState = false -- for open/close sounds
2022-05-06 00:05:20 +02:00
local selectionMode = 'folders'
local selectedFolder = 1
local selectedLevel = 1
2021-07-25 20:10:06 +02:00
2022-05-06 00:05:20 +02:00
local transitionScrollScale = 0
local transitionScrollOffsetY = 0
local scrollingUp = false
2021-07-25 20:10:06 +02:00
2022-05-06 00:05:20 +02:00
local transitionLeaveScale = 1
local transitionLeaveReappearTimer = 0
local TRANSITION_LEAVE_DURATION = 0.1
2021-11-22 20:39:56 +01:00
-- Window variables
local resX, resY
-- Aspect Ratios
local landscapeWidescreenRatio = 16 / 9
local landscapeStandardRatio = 4 / 3
local portraitWidescreenRatio = 9 / 16
-- Portrait sizes
local fullX, fullY
local resolutionChange = function(x, y)
resX = x
resY = y
fullX = portraitWidescreenRatio * y
fullY = y
end
2021-08-12 11:49:15 +02:00
function resetLayoutInformation()
resx, resy = game.GetResolution()
scale = resx / desw
end
function getCorrectedIndex(from, offset)
2022-05-06 00:05:20 +02:00
local total = 1
2021-08-12 11:49:15 +02:00
if selectionMode == 'folders' then
2022-05-06 00:05:20 +02:00
total = #filters.folder
2021-08-12 11:49:15 +02:00
else
2022-05-06 00:05:20 +02:00
total = #filters.level
2021-07-25 20:10:06 +02:00
end
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
index = from + offset
2021-08-12 11:49:15 +02:00
if index < 1 then
index = total + (from + offset) -- this only happens if the offset is negative
end
if index > total then
2022-05-06 00:05:20 +02:00
indexesUntilEnd = total - from
2021-08-12 11:49:15 +02:00
index = offset - indexesUntilEnd -- this only happens if the offset is positive
end
2022-05-06 00:05:20 +02:00
return index
2021-08-12 11:49:15 +02:00
end
function getFolderData(folderLabel)
2022-05-06 00:05:20 +02:00
local folderType = 'unknown'
local isSpecial = false
local folderBgImage = defaultFolderBgImage
2021-08-13 17:35:26 +02:00
if not folderLabel then
return {
type = folderType,
label = 'UNKNOWN',
bgImage = folderBgImage,
isSpecial = isSpecial
}
end
if selectionMode == 'levels' then
folderBgImage = subFolderBgImage
end
2021-08-12 11:49:15 +02:00
if (string.find(folderLabel, 'Folder: ')) then
2022-05-06 00:05:20 +02:00
folderType = 'folder'
2021-08-12 13:23:49 +02:00
folderLabel = folderLabel:gsub('Folder: ', '') -- Delete default prefix
elseif (string.find(folderLabel, 'Collection: ')) then
2022-05-06 00:05:20 +02:00
folderType = 'collection'
folderLabel = folderLabel:gsub('Collection: ', '') -- Delete default prefix
2022-05-06 00:05:20 +02:00
folderBgImage = collectionFolderBgImage
2021-08-12 13:23:49 +02:00
elseif (string.find(folderLabel, 'Level: ')) then
2022-05-06 00:05:20 +02:00
folderType = 'level'
2021-08-12 13:23:49 +02:00
folderLabel = folderLabel:gsub('Level: ', '') -- Delete default prefix
2022-05-06 00:05:20 +02:00
folderLabel = 'LEVEL ' .. folderLabel
2021-08-12 11:49:15 +02:00
end
local labelMatcherString = string.upper(folderLabel)
for i, specialFolder in ipairs(specialFolders) do
for i, specialFolderKey in ipairs(specialFolder.keys) do
2021-08-12 11:49:15 +02:00
if (specialFolderKey == labelMatcherString) then
2022-05-06 00:05:20 +02:00
folderBgImage = specialFolder.folderBg
isSpecial = true
2021-07-25 20:10:06 +02:00
end
end
2021-08-12 11:49:15 +02:00
end
return {
type = folderType,
label = folderLabel,
bgImage = folderBgImage,
isSpecial = isSpecial
2021-08-12 11:49:15 +02:00
}
end
function drawFolder(label, y)
if (not label) then return end
gfx.LoadSkinFont('NotoSans-Regular.ttf')
2021-08-12 11:49:15 +02:00
local x = desw / 2 + 0
local folderData = getFolderData(label)
-- Draw the bg
gfx.BeginPath()
gfx.ImageRect(x, y, 630 * 0.86, 200 * 0.86, folderData.bgImage, 1, 0)
2021-08-12 11:49:15 +02:00
-- Draw the folder label, but only if the folder is not special
if (not folderData.isSpecial) then
2022-05-06 00:05:20 +02:00
gfx.BeginPath()
2021-08-12 11:49:15 +02:00
gfx.FontSize(38)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
2022-05-06 00:05:20 +02:00
gfx.FillColor(255, 255, 255, 255)
gfx.Text(folderData.label, x + 18, y + 72)
2021-08-12 11:49:15 +02:00
end
end
function drawFolderList()
gfx.GlobalAlpha(1-transitionLeaveScale)
2022-05-06 00:05:20 +02:00
local numOfItemsAround = 7
local selectedIndex = 1
local folderList = filters.folder
2021-08-12 13:23:49 +02:00
2021-08-12 11:49:15 +02:00
if selectionMode == 'folders' then
selectedIndex = selectedFolder
2022-05-06 00:05:20 +02:00
folderList = filters.folder
2021-07-25 20:10:06 +02:00
else
2021-08-12 11:49:15 +02:00
selectedIndex = selectedLevel
2022-05-06 00:05:20 +02:00
folderList = filters.level
2021-08-12 11:49:15 +02:00
end
2022-05-06 00:05:20 +02:00
local yOffset = transitionScrollOffsetY
2021-08-12 16:55:10 +02:00
2022-05-06 00:05:20 +02:00
local i = 1
2021-08-12 11:49:15 +02:00
while (i <= numOfItemsAround) do
local index = getCorrectedIndex(selectedIndex, -i)
drawFolder(folderList[index],
desh / 2 - ITEM_HEIGHT / 2 - ITEM_HEIGHT * i + yOffset)
2022-05-06 00:05:20 +02:00
i = i + 1
2021-08-12 11:49:15 +02:00
end
-- Draw the selected song
drawFolder(folderList[selectedIndex], desh / 2 - ITEM_HEIGHT / 2 + yOffset)
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
i = 1
2021-08-12 11:49:15 +02:00
while (i <= numOfItemsAround) do
local index = getCorrectedIndex(selectedIndex, i)
drawFolder(folderList[index],
desh / 2 - ITEM_HEIGHT / 2 + ITEM_HEIGHT * i + yOffset)
2022-05-06 00:05:20 +02:00
i = i + 1
2021-08-12 11:49:15 +02:00
end
2022-05-06 00:05:20 +02:00
gfx.GlobalAlpha(1)
2021-08-12 11:49:15 +02:00
end
function drawCursor()
if not isFilterWheelActive or transitionLeaveScale ~= 0 then return end
2021-08-12 11:49:15 +02:00
gfx.BeginPath()
local cursorImageIndex = game.GetSkinSetting('_gaugeType')
2022-05-06 00:05:20 +02:00
local cursorImage = cursorImages[cursorImageIndex or 1]
gfx.ImageRect(desw / 2 - 14, desh / 2 - 213 / 2, 555, 213, cursorImage, 1, 0)
2021-08-12 11:49:15 +02:00
end
function drawScrollbar()
if not isFilterWheelActive or transitionLeaveScale ~= 0 then return end
2021-11-22 20:39:56 +01:00
gfx.BeginPath()
2022-05-06 00:05:20 +02:00
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)
2022-05-06 00:05:20 +02:00
gfx.BeginPath()
local sw, sh = gfx.ImageSize(scrollBarFillImage)
local sw = sw * resize
local sh = sh * resize
local fillXPos = xPos - 6
-- 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
2022-05-06 00:05:20 +02:00
local minScrollYPos = backgroundYPos
local maxScrollYPos = backgroundYPos + lh - sh
local scrollStep = (maxScrollYPos - minScrollYPos) / (total - 1)
local scrollbarYOffset = (index - 1) * scrollStep
local scrollbarYPos = minScrollYPos + scrollbarYOffset
2022-05-06 00:05:20 +02:00
gfx.ImageRect(fillXPos, scrollbarYPos, sw, sh, scrollBarFillImage, 1, 0)
end
2021-08-12 11:49:15 +02:00
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) *
2022-05-06 00:05:20 +02:00
ITEM_HEIGHT
2021-08-12 11:49:15 +02:00
else
transitionScrollOffsetY = Easing.inQuad(1 - transitionScrollScale) *
2022-05-06 00:05:20 +02:00
-ITEM_HEIGHT
2021-07-25 20:10:06 +02:00
end
2021-08-12 16:55:10 +02:00
-- LEAVE TRANSITION
if (not isFilterWheelActive) then
if transitionLeaveScale < 1 then
transitionLeaveScale = transitionLeaveScale + deltaTime / TRANSITION_LEAVE_DURATION -- transition should last for that time in seconds
else
transitionLeaveScale = 1
end
2022-05-06 00:05:20 +02:00
transitionLeaveReappearTimer = 1
2021-08-12 16:55:10 +02:00
else
if (transitionLeaveReappearTimer == 1) then
-- This stuff happens right after filterwheel is deactivated
end
transitionLeaveReappearTimer = transitionLeaveReappearTimer - deltaTime / (TRANSITION_LEAVE_DURATION + 0.05) -- same reasoning as in the songwheel
if (transitionLeaveReappearTimer <= 0) then
2022-05-06 00:05:20 +02:00
transitionLeaveScale = 0
transitionLeaveReappearTimer = 0
end
end
2021-08-12 11:49:15 +02:00
end
2021-11-22 20:39:56 +01:00
function drawFilterWheelContent(deltatime)
2022-05-06 00:05:20 +02:00
tickTransitions(deltatime)
2021-08-12 11:49:15 +02:00
drawFolderList()
end
2022-05-06 00:05:20 +02:00
local drawFilterWheel = function (deltaTime)
2021-11-22 20:39:56 +01:00
drawFilterWheelContent(deltaTime)
drawCursor()
drawScrollbar()
if (game.GetSkinSetting('_currentScreen') == 'songwheel') then
2022-05-06 00:05:20 +02:00
SongSelectHeader.draw(deltaTime)
Footer.draw(deltaTime)
end
2021-11-20 19:52:54 +01:00
if (isFilterWheelActive ~= previousActiveState) then
2022-05-06 00:05:20 +02:00
game.PlaySample('filter_wheel/open_close.wav')
previousActiveState = isFilterWheelActive
2021-11-20 19:52:54 +01:00
end
2021-08-12 11:49:15 +02:00
-- Debug text
2022-05-06 00:05:20 +02:00
gfx.BeginPath()
2021-08-12 11:49:15 +02:00
gfx.FontSize(18)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
2022-05-06 00:05:20 +02:00
gfx.FillColor(255, 255, 255, 255)
if game.GetSkinSetting('debug_showInformation') then
gfx.Text('S_M: ' .. selectionMode .. ' // S_F: ' .. selectedFolder ..
' // S_L: ' .. selectedLevel .. ' // L_TS: ' ..
transitionLeaveScale .. ' // L_TRT: ' .. transitionLeaveReappearTimer, 8, 1870)
end
2021-07-25 20:10:06 +02:00
end
2021-11-22 20:39:56 +01:00
render = function(deltaTime, shown)
2022-05-06 00:05:20 +02:00
isFilterWheelActive = shown
2021-11-22 20:39:56 +01:00
if not shown then
2022-05-06 00:05:20 +02:00
game.SetSkinSetting('_songWheelOverlayActive', 0)
2021-11-22 20:39:56 +01:00
else
2022-05-06 00:05:20 +02:00
game.SetSkinSetting('_songWheelOverlayActive', 1)
2021-11-22 20:39:56 +01:00
end
2022-05-06 00:05:20 +02:00
game.SetSkinSetting('_songWheelActiveFolderLabel', getFolderData(filters.folder[selectedFolder]).label)
game.SetSkinSetting('_songWheelActiveSubFolderLabel', getFolderData(filters.level[selectedLevel]).label)
2021-11-22 20:39:56 +01:00
2022-05-06 00:05:20 +02:00
Dim.updateResolution()
Dim.transformToScreenSpace()
2021-11-22 20:39:56 +01:00
gfx.GlobalAlpha(1)
2022-05-06 00:05:20 +02:00
drawFilterWheel(deltaTime)
2021-11-22 20:39:56 +01:00
end
2021-07-25 20:10:06 +02:00
set_selection = function(newIndex, isFolder)
2022-05-06 00:05:20 +02:00
local oldIndex = 1
local total = 1
2021-07-25 20:10:06 +02:00
if isFolder then
2021-08-12 11:49:15 +02:00
oldIndex = selectedFolder
selectedFolder = newIndex
2022-05-06 00:05:20 +02:00
total = #filters.folder
2021-07-25 20:10:06 +02:00
else
2021-08-12 11:49:15 +02:00
oldIndex = selectedLevel
selectedLevel = newIndex
2022-05-06 00:05:20 +02:00
total = #filters.level
2021-07-25 20:10:06 +02:00
end
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
transitionScrollScale = 0
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
scrollingUp = false
if ((newIndex > oldIndex and not (newIndex == total and oldIndex == 1)) or
2022-05-06 00:05:20 +02:00
(newIndex == 1 and oldIndex == total)) then scrollingUp = true end
2021-08-12 11:49:15 +02:00
2022-05-06 00:05:20 +02:00
game.PlaySample('song_wheel/cursor_change.wav')
2021-07-25 20:10:06 +02:00
end
set_mode = function(isFolder)
2021-08-12 11:49:15 +02:00
if isFolder then
selectionMode = 'folders'
else
selectionMode = 'levels'
end
2021-07-25 20:10:06 +02:00
end