From 543bf7b4473b4b1a0a877855754fb6d9dfaad60b Mon Sep 17 00:00:00 2001 From: FajsiEx Date: Mon, 22 Nov 2021 22:25:38 +0100 Subject: [PATCH] + letterboxing to songwheel, filterwheel and sortwheel --- scripts/components/footer.lua | 3 +- .../components/headers/songSelectHeader.lua | 8 --- scripts/songselect/filterwheel.lua | 1 - scripts/songselect/songwheel.lua | 20 ++++--- scripts/songselect/sortwheel.lua | 52 ++++++++++++++----- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/scripts/components/footer.lua b/scripts/components/footer.lua index a23530e..e3a9c4b 100644 --- a/scripts/components/footer.lua +++ b/scripts/components/footer.lua @@ -74,8 +74,7 @@ local draw = function (deltaTime, params) end gfx.Save() - resetLayoutInformation() - gfx.Scale(scale, scale) + gfx.LoadSkinFont("NotoSans-Regular.ttf"); diff --git a/scripts/components/headers/songSelectHeader.lua b/scripts/components/headers/songSelectHeader.lua index 7df649d..f51e216 100644 --- a/scripts/components/headers/songSelectHeader.lua +++ b/scripts/components/headers/songSelectHeader.lua @@ -17,12 +17,6 @@ local animationHeaderGlowAlpha = 0; local headerTitleImage = gfx.CreateSkinImage("song_select/header/title.png", 1) local headerGlowTitleImage = gfx.CreateSkinImage("song_select/header/title_glow.png", 1) -function resetLayoutInformation() - resx, resy = game.GetResolution() - desw = 1080 - desh = 1920 - scale = resx / desw -end local drawHeader = function () gfx.BeginPath(); @@ -53,8 +47,6 @@ end local draw = function (deltatime) gfx.Save() - resetLayoutInformation() - gfx.Scale(scale, scale) gfx.LoadSkinFont("NotoSans-Regular.ttf"); diff --git a/scripts/songselect/filterwheel.lua b/scripts/songselect/filterwheel.lua index d451a91..ae36e1d 100644 --- a/scripts/songselect/filterwheel.lua +++ b/scripts/songselect/filterwheel.lua @@ -349,7 +349,6 @@ function drawFilterWheelContent(deltatime) end local drawFilterWheel = function (x,y,w,h, deltaTime) - gfx.Scissor(x,y,w,h); gfx.Translate(x,y); gfx.Scale(w/1080, h/1920); diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index d1c6221..858614b 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -163,11 +163,8 @@ local resolutionChange = function(x, y) resY = y fullX = portraitWidescreenRatio * y fullY = y -end -function resetLayoutInformation() - resx, resy = game.GetResolution() - scale = resx / desw + game.Log('resX:' .. resX .. ' // resY:' .. resY .. ' // fullX:' .. fullX .. ' // fullY:' .. fullY, game.LOGGER_ERROR); end function load_number_image(path) @@ -250,13 +247,14 @@ function getGradeImageForScore(score) end function drawLaserAnim() + gfx.Save(); gfx.BeginPath() - + gfx.Scissor(0, transitionLaserY, desw, 100); - + gfx.ImageRect(0, 0, desw, desh, laserAnimBaseImage, 1, 0) - - gfx.ResetScissor(); + + gfx.Restore(); end function drawBackground(deltaTime) @@ -765,9 +763,11 @@ function tickTransitions(deltaTime) end draw_songwheel = function(x,y,w,h, deltaTime) - gfx.Scissor(x,y,w,h); + gfx.Translate(x,y); gfx.Scale(w/1080, h/1920); + gfx.Scissor(0,0,1080,1920); + drawBackground(deltaTime); @@ -803,8 +803,6 @@ render = function (deltaTime) difficultyNumbers = load_number_image('diff_num') end - game.SetSkinSetting('_currentScreen', 'title') - -- detect resolution change local resx, resy = game.GetResolution(); if resx ~= resX or resy ~= resY then diff --git a/scripts/songselect/sortwheel.lua b/scripts/songselect/sortwheel.lua index cfe44ca..aea8bbe 100644 --- a/scripts/songselect/sortwheel.lua +++ b/scripts/songselect/sortwheel.lua @@ -1,6 +1,9 @@ require('common') local Easing = require('common.easings'); +local resx, resy = game.GetResolution() +local desw, desh = 1080, 1920 + -- AUDIO game.LoadSkinSample('sort_wheel/enter.wav'); game.LoadSkinSample('sort_wheel/leave.wav'); @@ -12,10 +15,6 @@ local activeItemBgImage = gfx.CreateSkinImage( local titleTextImage = gfx.CreateSkinImage('song_select/sort_wheel/title.png', 0) -local resx, resy = game.GetResolution() -local desw, desh = 1080, 1920; -local scale = 1; - local selection = 1; local renderedButtonLabels = {} @@ -48,9 +47,24 @@ local transitionEnterOffsetX = 0; local previousActiveState = false; -function resetLayoutInformation() - resx, resy = game.GetResolution() - scale = resx / desw +-- Window variables +local resX, resY + +-- Aspect Ratios +local landscapeWidescreenRatio = 16 / 9 +local landscapeStandardRatio = 4 / 3 +local portraitWidescreenRatio = 9 / 16 --+ 0.0035 + +-- Portrait sizes +local fullX, fullY + +local resolutionChange = function(x, y) + resX = x + resY = y + fullX = portraitWidescreenRatio * y + fullY = y + + game.Log('resX:' .. resX .. ' // resY:' .. resY .. ' // fullX:' .. fullX .. ' // fullY:' .. fullY, game.LOGGER_ERROR); end function tableContains(table, value) @@ -136,11 +150,16 @@ function tickTransitions(deltaTime) transitionEnterOffsetX = Easing.inOutQuad(1 - transitionEnterScale) * 416 end -function drawSortWheel(deltaTime) +local drawSortWheel = function (x,y,w,h, deltaTime) + gfx.Scissor(x,y,w,h); + gfx.Translate(x,y); + gfx.Scale(w/1080, h/1920); + gfx.Scissor(0,0,1080,1920); + -- Draw the dark overlay above song wheel gfx.BeginPath(); gfx.FillColor(0, 0, 0, math.floor(transitionEnterScale * 192)); - gfx.Rect(0, 0, desw, desh); + gfx.Rect(0, 0, 1080, 1920); gfx.Fill(); -- Draw the panel background @@ -188,8 +207,7 @@ function render(deltaTime, shown) gfx.Save() gfx.ResetTransform() renderedButtonLabels = {}; - resetLayoutInformation() - gfx.Scale(scale, scale) + if (shown ~= previousActiveState) then if (shown) then @@ -201,12 +219,20 @@ function render(deltaTime, shown) previousActiveState = shown; end + -- detect resolution change + local resx, resy = game.GetResolution(); + if resx ~= resX or resy ~= resY then + resolutionChange(resx, resy) + end + + gfx.GlobalAlpha(1) + if not shown then transitionEnterReverse = true - if (transitionEnterScale > 0) then drawSortWheel(deltaTime) end + if (transitionEnterScale > 0) then drawSortWheel((resX - fullX) / 2, 0, fullX, fullY, deltaTime) end else transitionEnterReverse = false - drawSortWheel(deltaTime) + drawSortWheel((resX - fullX) / 2, 0, fullX, fullY, deltaTime) end tickTransitions(deltaTime) setSkinSetting();