+ filter wheel pretty much

This commit is contained in:
FajsiEx 2021-08-12 11:49:15 +02:00
parent a411e2bb8f
commit 0958417879
1 changed files with 250 additions and 65 deletions

View File

@ -1,83 +1,268 @@
--Horizontal alignment require('common')
TEXT_ALIGN_LEFT = 1; local Easing = require('common.easings');
TEXT_ALIGN_CENTER = 2;
TEXT_ALIGN_RIGHT = 4;
--Vertical alignment
TEXT_ALIGN_TOP = 8;
TEXT_ALIGN_MIDDLE = 16;
TEXT_ALIGN_BOTTOM = 32;
TEXT_ALIGN_BASELINE = 64;
local timer = 0; local defaultFolderBgImage = gfx.CreateSkinImage('song_select/filter_wheel/bg.png', 0)
local selectingFolders = true; local cursorImage = gfx.CreateSkinImage('song_select/cursor.png', 0)
local selectedLevel = 1;
local ITEM_HEIGHT = 172;
local specialFolders = {
{
keys = {
'SOUND VOLTEX BOOTH',
'SDVX BOOTH',
'SOUND VOLTEX I',
'SDVX I',
'SOUND VOLTEX 1',
'SDVX 1'
},
folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Booth.png', 0)
},
{
keys = {
'SOUND VOLTEX INFINITE INFECTION',
'SDVX INFINITE INFECTION',
'SOUND VOLTEX II',
'SDVX II',
'SOUND VOLTEX 2',
'SDVX 2'
},
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'
-- },
-- folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Infinite Infection.png', 0)
-- },
{
keys = {
'SOUND VOLTEX HEAVENLY HAVEN',
'SDVX HEAVENLY HAVEN',
'SOUND VOLTEX IV',
'SDVX IV',
'SOUND VOLTEX 4',
'SDVX 4'
},
folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Heavenly Haven.png', 0)
},
{
keys = {
'SOUND VOLTEX VIVID WAVE',
'SDVX VIVID WAVE',
'SOUND VOLTEX V',
'SDVX V',
'SOUND VOLTEX 5',
'SDVX 5'
},
folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Vivid Wave.png', 0)
},
{
keys = {
'SOUND VOLTEX EXCEED GEAR',
'SDVX EXCEED GEAR',
'SOUND VOLTEX VI',
'SDVX VI',
'SOUND VOLTEX 6',
'SDVX 6'
},
folderBg = gfx.CreateSkinImage('song_select/filter_wheel/special_folder_bgs/Exceed Gear.png', 0)
},
}
-- AUDIO
game.LoadSkinSample('song_wheel/cursor_change.wav');
local resx, resy = game.GetResolution()
local desw, desh = 1080, 1920
local scale = 1;
local selectionMode = 'folders';
local selectedFolder = 1; local selectedFolder = 1;
local levelLabels = {} local selectedLevel = 1;
local folderLabels = {}
--timing settings local transitionScrollScale = 0;
local levelOffset = 0; local transitionScrollOffsetY = 0;
local folderOffset = 0; local scrollingUp = false;
function resetLayoutInformation()
resx, resy = game.GetResolution()
scale = resx / desw
end
function getCorrectedIndex(from, offset)
local total = 1;
if selectionMode == 'folders' then
total = #filters.folder;
else
total = #filters.level;
end
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 getFolderData(folderLabel)
local folderType = 'unknown';
if (string.find(folderLabel, 'Folder: ')) then
folderType = 'folder';
folderLabel = folderLabel:gsub('Folder: ', '') -- Delete the useless info
end
local labelMatcherString = string.upper(folderLabel)
local folderBgImage = defaultFolderBgImage;
local isSpecial = false;
for i,specialFolder in ipairs(specialFolders) do
for i,specialFolderKey in ipairs(specialFolder.keys) do
if (specialFolderKey == labelMatcherString) then
folderBgImage = specialFolder.folderBg;
isSpecial = true;
end
end
end
return {
type = folderType,
label = folderLabel,
bgImage = folderBgImage,
isSpecial = isSpecial,
}
end
function drawFolder(label, y)
if (not label) then return end
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)
-- Draw the folder label, but only if the folder is not special
if (not folderData.isSpecial) then
gfx.BeginPath();
gfx.FontSize(38)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.FillColor(255, 255, 255, 255);
gfx.Text(folderData.label, x+18, y+72);
end
end
function drawFolderList()
local numOfItemsAround = 7;
local selectedIndex = 1;
if selectionMode == 'folders' then
selectedIndex = selectedFolder
else
selectedIndex = selectedLevel
end
local i = 1;
while (i <= numOfItemsAround) do
local index = getCorrectedIndex(selectedIndex, -i)
drawFolder(filters.folder[index], desh / 2 - ITEM_HEIGHT / 2 -
ITEM_HEIGHT * i + transitionScrollOffsetY)
i = i + 1;
end
-- Draw the selected song
drawFolder(filters.folder[selectedIndex],
desh / 2 - ITEM_HEIGHT / 2 + transitionScrollOffsetY)
i = 1;
while (i <= numOfItemsAround) do
local index = getCorrectedIndex(selectedIndex, i)
drawFolder(filters.folder[index], desh / 2 - ITEM_HEIGHT / 2 +
ITEM_HEIGHT * i + transitionScrollOffsetY)
i = i + 1;
end
end
function drawCursor()
gfx.BeginPath()
gfx.ImageRect(desw/2-14, desh/2-213/2, 555, 213, cursorImage, 1, 0)
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) * ITEM_HEIGHT;
else
transitionScrollOffsetY = Easing.inQuad(1-transitionScrollScale) * -ITEM_HEIGHT;
end
end
render = function(deltaTime, shown) render = function(deltaTime, shown)
if not shown then if not shown then return end
return
end
gfx.ResetTransform() gfx.ResetTransform()
timer = (timer + deltaTime) resetLayoutInformation()
timer = timer % 2 tickTransitions(deltaTime);
resx,resy = game.GetResolution(); gfx.Scale(scale,scale);
gfx.FillColor(0,0,0,200)
gfx.FastRect(0,0,resx,resy) drawFolderList()
drawCursor()
-- Debug text
gfx.BeginPath(); gfx.BeginPath();
gfx.LoadSkinFont("segoeui.ttf"); gfx.FontSize(18)
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE); gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
gfx.FontSize(40); gfx.FillColor(255, 255, 255, 255);
gfx.FastText(folderOffset,0,0) gfx.Text('S_M: ' .. selectionMode .. ' // S_F: ' .. selectedFolder ..
if selectingFolders then ' // S_L: ' .. selectedLevel .. ' // T_S_S: ' .. transitionScrollScale, 8, 1900);
for i,f in ipairs(filters.folder) do
if not folderLabels[i] then
folderLabels[i] = gfx.CreateLabel(f, 40, 0)
end
if i == selectedFolder then
gfx.FillColor(255,255,255,255)
else
gfx.FillColor(255,255,255,128)
end
local xpos = resx - 100 + ((i - selectedFolder - folderOffset) ^ 2) * 1
local ypos = resy/2 + 50 * (i - selectedFolder - folderOffset)
gfx.DrawLabel(folderLabels[i], xpos, ypos);
end
else
for i,l in ipairs(filters.level) do
if not levelLabels[i] then
levelLabels[i] = gfx.CreateLabel(l, 40, 0)
end
if i == selectedLevel then
gfx.FillColor(255,255,255,255)
else
gfx.FillColor(255,255,255,128)
end
local xpos = resx - 100 + ((i - selectedLevel - levelOffset) ^ 2) * 1
local ypos = resy/2 + 50 * (i - selectedLevel - levelOffset)
gfx.DrawLabel(levelLabels[i], xpos, ypos);
end
end
levelOffset = levelOffset * 0.7
folderOffset = folderOffset * 0.7
end end
set_selection = function(newIndex, isFolder) set_selection = function(newIndex, isFolder)
local oldIndex = 1;
local total = 1;
if isFolder then if isFolder then
folderOffset = folderOffset + selectedFolder - newIndex oldIndex = selectedFolder
selectedFolder = newIndex selectedFolder = newIndex
total = #filters.folder;
else else
levelOffset = levelOffset + selectedLevel - newIndex oldIndex = selectedLevel
selectedLevel = newIndex selectedLevel = newIndex
total = #filters.level;
end end
transitionScrollScale = 0;
scrollingUp = false;
if ((newIndex > oldIndex and not (newIndex == total and oldIndex == 1)) or (newIndex == 1 and oldIndex == total)) then
scrollingUp = true;
end;
game.PlaySample('song_wheel/cursor_change.wav');
end end
set_mode = function(isFolder) set_mode = function(isFolder)
selectingFolders = isFolder if isFolder then
selectionMode = 'folders'
else
selectionMode = 'levels'
end
end end