ExperimentalGear/scripts/result.lua

157 lines
3.8 KiB
Lua
Raw Normal View History

2021-07-27 21:18:13 +02:00
local Easing = require('common.easings');
local resx, resy = game.GetResolution()
2021-07-27 20:00:02 +02:00
local desw = 1080
local desh = 1920
2021-07-25 20:10:06 +02:00
2021-07-27 20:00:02 +02:00
local bgSfxPlayed = false;
2021-07-25 20:10:06 +02:00
2021-07-27 20:00:02 +02:00
local backgroundImage = gfx.CreateSkinImage("bg.png", 1);
2021-07-27 21:18:13 +02:00
local topBarImage = gfx.CreateSkinImage("result/top_bar.png", 1);
local jacketPanelImage = gfx.CreateSkinImage("result/panels/jacket.png", 1);
local rightPanelImage = gfx.CreateSkinImage("result/panels/right.png", 1);
local bottomPanelImage = gfx.CreateSkinImage("result/panels/bottom.png", 1);
local jacketImage = gfx.CreateSkinImage("result/default_jacket.png", 1);
local transitionEnterScale = 0;
local jacketPanelX = 0;
local jacketPanelY = 820;
local JACKET_PANEL_TRANSTION_ENTER_OFFSET = -128;
local RIGHT_PANEL_TRANSTION_ENTER_OFFSET = 128;
local BOTTOM_PANEL_TRANSTION_ENTER_OFFSET = 128;
2021-07-27 20:00:02 +02:00
game.LoadSkinSample("result")
2021-07-25 20:10:06 +02:00
2021-07-27 20:00:02 +02:00
function resetLayoutInformation()
resx, resy = game.GetResolution()
desw = 1080
desh = 1920
scale = resx / desw
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
local handleSfx = function()
2021-07-27 20:00:02 +02:00
if not bgSfxPlayed then
2021-07-25 20:10:06 +02:00
game.PlaySample("result", true)
2021-07-27 20:00:02 +02:00
bgSfxPlayed = true
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
if game.GetButton(game.BUTTON_STA) then game.StopSample("result") end
if game.GetButton(game.BUTTON_BCK) then game.StopSample("result") end
end
local drawTopBar = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(topBarImage);
gfx.ImageRect(0, -th * (1 - Easing.outQuad(transitionEnterScale)), desw, th,
topBarImage, 1, 0);
gfx.ClosePath();
end
local drawRightPanel = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(rightPanelImage);
gfx.ImageRect(
0+(RIGHT_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale))),
850,
tw,
th,
rightPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
gfx.ClosePath();
end
local drawBottomPanel = function ()
gfx.BeginPath();
local tw, th = gfx.ImageSize(bottomPanelImage);
gfx.ImageRect(
0,
1110+(BOTTOM_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale))),
tw,
th,
bottomPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
gfx.ClosePath();
end
local drawJacketPanel = function()
gfx.BeginPath();
local tw, th = gfx.ImageSize(jacketPanelImage);
gfx.ImageRect(
jacketPanelX,
jacketPanelY,
tw,
th,
jacketPanelImage,
Easing.outQuad(transitionEnterScale),
0
);
gfx.ClosePath();
end
local drawJacketPanelContent = function ()
gfx.BeginPath()
gfx.ImageRect(
jacketPanelX+12,
jacketPanelY+26,
273,
273,
jacketImage,
Easing.outQuad(transitionEnterScale),
0
);
gfx.ClosePath()
end
local tickTransitions = function(deltaTime)
if transitionEnterScale < 1 then
transitionEnterScale = transitionEnterScale + deltaTime / 5
else
transitionEnterScale = 1
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
jacketPanelX = 40 + (JACKET_PANEL_TRANSTION_ENTER_OFFSET * (1 - Easing.outQuad(transitionEnterScale)))
end
result_set = function ()
if result.jacketPath ~= nil and result.jacketPath ~= "" then
jacketImage = gfx.CreateImage(result.jacketPath, 1)
2021-07-25 20:10:06 +02:00
end
2021-07-27 21:18:13 +02:00
end
render = function(deltaTime, showStats)
resetLayoutInformation()
gfx.Scale(scale, scale)
gfx.ImageRect(0, 0, desw, desh, backgroundImage, 1, 0);
drawTopBar()
drawBottomPanel()
drawRightPanel()
drawJacketPanel()
drawJacketPanelContent()
handleSfx()
-- debug
gfx.Text('DELTA: ' .. deltaTime .. ' // TRANSITION_ENTER_SCALE: ' ..
transitionEnterScale .. ' // EASING_OUT_QUAD: ' ..
Easing.outQuad(transitionEnterScale), 255, 255);
tickTransitions(deltaTime)
end