ExperimentalGear/scripts/songselect/sortwheel.lua

192 lines
6.1 KiB
Lua
Raw Normal View History

2021-08-13 20:47:00 +02:00
require('common')
local Easing = require('common.easings');
-- IMAGES
local panelBgImage = gfx.CreateSkinImage('song_select/sort_wheel/bg.png', 0)
local activeItemBgImage = gfx.CreateSkinImage(
2021-08-13 20:47:00 +02:00
'song_select/sort_wheel/active_bg.png', 0)
local titleTextImage =
gfx.CreateSkinImage('song_select/sort_wheel/title.png', 0)
2021-07-25 20:10:06 +02:00
2021-08-13 20:57:38 +02:00
local resx, resy = game.GetResolution()
local desw, desh = 1080, 1920;
local scale = 1;
local selection = 1;
local renderedButtonLabels = {}
local FONT_SIZE = 32;
local MARGIN = 16;
local SUB_FONT_SIZE = 26;
local SUB_MARGIN = 8;
local SORT_ORDER_LABEL_TEXTS = {
{
label = 'Title',
asc = '# to A to Z to かな to 漢字',
dsc = '漢字 to かな to Z to A to #'
2021-08-13 20:47:00 +02:00
}, {label = 'Score', asc = 'Worst to best', dsc = 'Best to worst'},
{label = 'Date', asc = 'Oldest to newest', dsc = 'Newest to oldest'},
{label = 'Badge', asc = 'None to D to S', dsc = 'S to D to None'}, {
label = 'Artist',
asc = '# to A to Z to かな to 漢字',
dsc = '漢字 to かな to Z to A to #'
2021-08-13 20:47:00 +02:00
}, {
label = 'Effector',
asc = '# to A to Z to かな to 漢字',
dsc = '漢字 to かな to Z to A to #'
2021-08-13 20:47:00 +02:00
}
}
2021-08-13 20:47:00 +02:00
local transitionEnterReverse = false;
local transitionEnterScale = 0;
local transitionEnterOffsetX = 0;
function resetLayoutInformation()
resx, resy = game.GetResolution()
scale = resx / desw
end
function tableContains(table, value)
2021-08-13 20:47:00 +02:00
for i, v in ipairs(table) do if v == value then return true end end
return false;
end
2021-08-13 20:47:00 +02:00
function drawButton(i, f, x, y)
local spaceAfter = (FONT_SIZE + MARGIN)
local sortOrder = 'asc';
2021-08-13 20:47:00 +02:00
if (string.find(f, 'v')) then sortOrder = 'dsc' end
local label = f:gsub(' ^', '')
label = label:gsub(' v', '')
if (string.find(sorts[selection], label) and sorts[selection] ~= f) then
-- If there is a button active with the same label, but different sort order, don't render this one
return 0;
else
-- If there is no active button with this label, if one with a label was already rendered, don't render this one
2021-08-13 20:47:00 +02:00
if (tableContains(renderedButtonLabels, label)) then return 0; end
table.insert(renderedButtonLabels, label);
end
if (i == selection) then
2021-08-14 17:49:12 +02:00
game.SetSkinSetting('_songWheelActiveSortOptionLabel', label);
local ascLabelText = 'Ascending'
local dscLabelText = 'Descending'
2021-08-13 20:47:00 +02:00
for i, obj in ipairs(SORT_ORDER_LABEL_TEXTS) do
if (obj.label == label) then
ascLabelText = obj.asc;
dscLabelText = obj.dsc;
end
end
gfx.BeginPath()
2021-08-13 20:47:00 +02:00
gfx.ImageRect(x - 182, y - 38, 365, 82, activeItemBgImage, 1, 0)
gfx.BeginPath()
if sortOrder == 'asc' then
2021-08-13 20:47:00 +02:00
gfx.ImageRect(x - 150, y + FONT_SIZE + SUB_MARGIN * 2 - 31, 300, 67,
activeItemBgImage, 1, 0)
elseif sortOrder == 'dsc' then
2021-08-13 20:47:00 +02:00
gfx.ImageRect(x - 150, y + FONT_SIZE + SUB_MARGIN * 2 +
SUB_FONT_SIZE + SUB_MARGIN - 31, 300, 67,
activeItemBgImage, 1, 0)
end
gfx.Save()
gfx.FontSize(SUB_FONT_SIZE)
2021-08-13 20:47:00 +02:00
gfx.Text(ascLabelText, x, y + FONT_SIZE + SUB_MARGIN * 2);
gfx.Text(dscLabelText, x,
y + FONT_SIZE + SUB_MARGIN * 2 + SUB_FONT_SIZE + SUB_MARGIN);
gfx.Restore()
2021-08-13 20:47:00 +02:00
spaceAfter = spaceAfter + SUB_FONT_SIZE * 2 + SUB_MARGIN * 4;
2021-07-25 20:10:06 +02:00
end
gfx.BeginPath();
gfx.Text(label, x, y);
return spaceAfter;
end
2021-08-13 20:47:00 +02:00
function tickTransitions(deltaTime)
-- ENTRY TRANSITION
if transitionEnterReverse then
if transitionEnterScale > 0 then
transitionEnterScale = transitionEnterScale - deltaTime / 0.25 -- transition should last for that time in seconds
else
transitionEnterScale = 0
end
else
if transitionEnterScale < 1 then
transitionEnterScale = transitionEnterScale + deltaTime / 0.25 -- transition should last for that time in seconds
else
transitionEnterScale = 1
end
end
2021-08-13 20:47:00 +02:00
transitionEnterOffsetX = Easing.inOutQuad(1 - transitionEnterScale) * 416
end
2021-08-13 20:47:00 +02:00
function drawSortWheel(deltaTime)
-- Draw the dark overlay above song wheel
2021-07-25 20:10:06 +02:00
gfx.BeginPath();
2021-08-13 20:47:00 +02:00
gfx.FillColor(0, 0, 0, math.floor(transitionEnterScale * 192));
gfx.Rect(0, 0, desw, desh);
gfx.Fill();
-- Draw the panel background
gfx.BeginPath()
2021-08-13 20:47:00 +02:00
gfx.ImageRect(desw - 416 + transitionEnterOffsetX, 0, 416, desh,
panelBgImage, 1, 0)
gfx.LoadSkinFont("Digital-Serial-Bold.ttf");
gfx.FontSize(FONT_SIZE);
gfx.FillColor(255, 255, 255, 255);
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE);
2021-08-13 20:47:00 +02:00
gfx.GlobalAlpha(transitionEnterScale)
-- Starting position of the first sort option
2021-08-13 20:47:00 +02:00
local x = 889 + transitionEnterOffsetX;
local y = desh / 2 - -- Center point
2021-08-13 20:47:00 +02:00
(#sorts / 2 / 2) * (FONT_SIZE + MARGIN) - -- Space taken up by half the sort options (we remove the duplicate one)
((SUB_FONT_SIZE * 2 + SUB_MARGIN * 4) / 2); -- Space for taken by order options
-- Draw the title image
gfx.BeginPath()
2021-08-13 20:47:00 +02:00
gfx.ImageRect(x - 72, y - 27, 144, 54, titleTextImage, 1, 0)
y = y + (54 + MARGIN)
2021-08-13 20:47:00 +02:00
-- Draw all the sorting options
for i, f in ipairs(sorts) do
2021-08-13 20:47:00 +02:00
local spaceAfter = drawButton(i, f, x, y);
y = y + spaceAfter;
2021-07-25 20:10:06 +02:00
end
2021-08-13 20:47:00 +02:00
end
function render(deltaTime, shown)
gfx.Save()
gfx.ResetTransform()
2021-08-13 20:57:38 +02:00
renderedButtonLabels = {};
resetLayoutInformation()
gfx.Scale(scale, scale)
2021-08-13 20:47:00 +02:00
if not shown then
transitionEnterReverse = true
if (transitionEnterScale > 0) then drawSortWheel(deltaTime) end
else
transitionEnterReverse = false
drawSortWheel(deltaTime)
end
tickTransitions(deltaTime)
2021-07-25 20:10:06 +02:00
gfx.Restore()
end
function set_selection(index) selection = index end