2021-11-17 22:28:26 +01:00
|
|
|
local Easing = require("common.easings");
|
|
|
|
local Footer = require("components.footer");
|
2021-11-21 18:37:21 +01:00
|
|
|
local DiffRectangle = require('components.diff_rectangle');
|
2021-11-21 16:34:12 +01:00
|
|
|
local common = require('common.common');
|
2021-12-10 03:41:44 +01:00
|
|
|
local Numbers = require('common.numbers')
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-17 22:28:26 +01:00
|
|
|
local VolforceWindow = require("components.volforceWindow")
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-12-03 03:28:45 +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
|
2021-08-18 17:29:54 +02:00
|
|
|
local desw = 1080
|
|
|
|
local desh = 1920
|
2021-12-03 03:28:45 +01:00
|
|
|
|
|
|
|
local function resolutionChange(x, y)
|
|
|
|
resX = x
|
|
|
|
resY = y
|
|
|
|
fullX = portraitWidescreenRatio * y
|
|
|
|
fullY = y
|
|
|
|
end
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-10-23 01:27:44 +02:00
|
|
|
local bgSfxPlayed = false;
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
local BAR_ALPHA = 191;
|
|
|
|
local HEADER_HEIGHT = 100
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-12-03 03:28:45 +01:00
|
|
|
local backgroundImage = gfx.CreateSkinImage("bg_pattern.png", gfx.IMAGE_REPEATX | gfx.IMAGE_REPEATY)
|
|
|
|
local resultBgImage = gfx.CreateSkinImage("challenge_result/bg.png", 0);
|
2021-08-18 17:29:54 +02:00
|
|
|
local playerInfoOverlayBgImage = gfx.CreateSkinImage("challenge_result/player_info_overlay_bg.png", 0);
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-08-18 19:05:37 +02:00
|
|
|
local headerTitleImage = gfx.CreateSkinImage("challenge_result/header/title.png", 0);
|
|
|
|
|
2021-11-17 22:28:26 +01:00
|
|
|
local username = game.GetSkinSetting("username");
|
2021-10-25 21:39:16 +02:00
|
|
|
local appealCardImage = gfx.CreateSkinImage("crew/appeal_card.png", 0);
|
2021-08-18 19:05:37 +02:00
|
|
|
local danBadgeImage = gfx.CreateSkinImage("dan/inf.png", 0);
|
2021-10-25 09:53:50 +02:00
|
|
|
local crewImage = gfx.CreateSkinImage("crew/portrait.png", 0);
|
2021-08-18 19:05:37 +02:00
|
|
|
|
2021-11-21 18:37:21 +01:00
|
|
|
local notchesImage = gfx.CreateSkinImage("challenge_result/notches.png", 0);
|
|
|
|
local trackBarsImage = gfx.CreateSkinImage("challenge_result/track_bars.png", 0);
|
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
local completionFailImage = gfx.CreateSkinImage("challenge_result/pass_states/fail.png", 0);
|
|
|
|
local completionPassImage = gfx.CreateSkinImage("challenge_result/pass_states/pass.png", 0);
|
|
|
|
|
2021-08-18 20:22:57 +02:00
|
|
|
local irHeartbeatRequested = false;
|
2021-11-17 22:28:26 +01:00
|
|
|
local IRserverName = "";
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-21 18:37:21 +01:00
|
|
|
local badgeImages = {
|
|
|
|
gfx.CreateSkinImage("song_select/medal/nomedal.png", 1),
|
|
|
|
gfx.CreateSkinImage("song_select/medal/played.png", 1),
|
|
|
|
gfx.CreateSkinImage("song_select/medal/clear.png", 1),
|
|
|
|
gfx.CreateSkinImage("song_select/medal/hard.png", 1),
|
|
|
|
gfx.CreateSkinImage("song_select/medal/uc.png", 1),
|
|
|
|
gfx.CreateSkinImage("song_select/medal/puc.png", 1),
|
|
|
|
}
|
|
|
|
|
|
|
|
local gradeImages = {
|
|
|
|
S = gfx.CreateSkinImage("common/grades/S.png", 0),
|
|
|
|
AAA_P = gfx.CreateSkinImage("common/grades/AAA+.png", 0),
|
|
|
|
AAA = gfx.CreateSkinImage("common/grades/AAA.png", 0),
|
|
|
|
AA_P = gfx.CreateSkinImage("common/grades/AA+.png", 0),
|
|
|
|
AA = gfx.CreateSkinImage("common/grades/AA.png", 0),
|
|
|
|
A_P = gfx.CreateSkinImage("common/grades/A+.png", 0),
|
|
|
|
A = gfx.CreateSkinImage("common/grades/A.png", 0),
|
|
|
|
B = gfx.CreateSkinImage("common/grades/B.png", 0),
|
|
|
|
C = gfx.CreateSkinImage("common/grades/C.png", 0),
|
|
|
|
D = gfx.CreateSkinImage("common/grades/D.png", 0),
|
|
|
|
none = gfx.CreateSkinImage("common/grades/none.png", 0),
|
|
|
|
}
|
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
local percRequired = 1;
|
2021-11-21 21:09:39 +01:00
|
|
|
local percGet = 0;
|
2021-11-21 20:11:26 +01:00
|
|
|
|
2021-10-23 01:27:44 +02:00
|
|
|
-- AUDIO
|
|
|
|
game.LoadSkinSample("challenge_result.wav")
|
|
|
|
|
2021-08-18 17:29:54 +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-10-23 01:27:44 +02:00
|
|
|
local function handleSfx()
|
|
|
|
if not bgSfxPlayed then
|
2021-11-21 16:34:12 +01:00
|
|
|
common.stopMusic();
|
2021-10-23 01:27:44 +02:00
|
|
|
game.PlaySample("challenge_result.wav", true)
|
|
|
|
bgSfxPlayed = true
|
|
|
|
end
|
2021-11-17 22:28:26 +01:00
|
|
|
if game.GetButton(game.BUTTON_STA) then
|
|
|
|
game.StopSample("challenge_result.wav")
|
|
|
|
end
|
|
|
|
if game.GetButton(game.BUTTON_BCK) then
|
|
|
|
game.StopSample("challenge_result.wav")
|
|
|
|
end
|
2021-10-23 01:27:44 +02:00
|
|
|
end
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
function drawBackground()
|
2021-07-25 20:10:06 +02:00
|
|
|
gfx.BeginPath()
|
2021-12-03 03:28:45 +01:00
|
|
|
gfx.ImageRect(0, 0, desw, desh, resultBgImage, 1, 0);
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
function drawHeader()
|
|
|
|
gfx.BeginPath();
|
|
|
|
gfx.FillColor(0, 0, 0, BAR_ALPHA);
|
|
|
|
gfx.Rect(0, 0, desw, HEADER_HEIGHT);
|
|
|
|
gfx.Fill();
|
|
|
|
gfx.ClosePath()
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.ImageRect(desw / 2 - 209, HEADER_HEIGHT / 2 - 52, 419, 105, headerTitleImage, 1, 0)
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
function drawPlayerInfo()
|
2021-08-18 20:22:57 +02:00
|
|
|
-- Draw crew
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(460, 215, 522, 362, crewImage, 1, 0);
|
|
|
|
|
2021-08-18 19:05:37 +02:00
|
|
|
-- Draw the info bg
|
2021-07-25 20:10:06 +02:00
|
|
|
gfx.BeginPath()
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.ImageRect(300, 352, 374 * 0.85, 222 * 0.85, playerInfoOverlayBgImage, 1, 0);
|
2021-08-18 19:05:37 +02:00
|
|
|
|
|
|
|
-- Draw appeal card
|
|
|
|
gfx.BeginPath();
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.ImageRect(145, 364, 103 * 1.25, 132 * 1.25, appealCardImage, 1, 0);
|
2021-08-18 19:05:37 +02:00
|
|
|
|
|
|
|
-- Draw description
|
|
|
|
gfx.FontSize(28)
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.LoadSkinFont("Digital-Serial-Bold.ttf")
|
2021-08-18 19:05:37 +02:00
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.Text("Hellooooooo", 310, 370);
|
2021-08-18 19:05:37 +02:00
|
|
|
|
|
|
|
-- Draw username
|
|
|
|
gfx.FontSize(40)
|
|
|
|
gfx.Text(username, 310, 413);
|
|
|
|
|
2021-08-18 20:22:57 +02:00
|
|
|
-- Draw IR server name
|
|
|
|
gfx.FontSize(28)
|
|
|
|
gfx.Text(IRserverName, 310, 453);
|
|
|
|
|
2021-08-18 19:05:37 +02:00
|
|
|
-- Draw dan badge
|
|
|
|
gfx.BeginPath();
|
2021-11-17 22:28:26 +01:00
|
|
|
gfx.ImageRect(311, 490, 107 * 1.25, 29 * 1.25, danBadgeImage, 1, 0);
|
2021-07-25 20:10:06 +02:00
|
|
|
end
|
|
|
|
|
2021-12-10 03:41:44 +01:00
|
|
|
local scoreNumber = Numbers.load_number_image("score_num");
|
2021-10-23 01:27:44 +02:00
|
|
|
|
2021-11-21 18:37:21 +01:00
|
|
|
function drawChartResult(deltaTime, x, y, chartResult)
|
|
|
|
gfx.Save()
|
|
|
|
gfx.LoadSkinFont('NotoSans-Regular.ttf')
|
|
|
|
|
|
|
|
gfx.FontSize(28)
|
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.GlobalAlpha(1);
|
|
|
|
gfx.Text(chartResult.title, x+160,y+32);
|
|
|
|
|
|
|
|
DiffRectangle.render(deltaTime, x+287.5, y+67, 0.85, chartResult.difficulty, chartResult.level)
|
|
|
|
|
|
|
|
local score = chartResult.score or 0;
|
|
|
|
|
2021-12-10 03:41:44 +01:00
|
|
|
Numbers.draw_number(x + 500, y+80, 1.0, math.floor(score / 10000), 4, scoreNumber, true, 0.30, 1.12)
|
|
|
|
Numbers.draw_number(x + 655, y+85, 1.0, score, 4, scoreNumber, true, 0.22, 1.12)
|
2021-11-21 18:37:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
local gradeImageKey = string.gsub(chartResult.grade, '+', '_P');
|
|
|
|
local gradeImage = gradeImages[gradeImageKey] or gradeImages.D
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(x+800, y+12, 79, 79, gradeImage, 1, 0)
|
|
|
|
|
|
|
|
|
|
|
|
if chartResult.badge then
|
|
|
|
local badgeImage = badgeImages[chartResult.badge+1];
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(x+900, y+16, 79*1.05, 69*1.05, badgeImage, 1, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
gfx.Restore()
|
|
|
|
end
|
|
|
|
|
|
|
|
function drawScorePanelContent(deltaTime)
|
|
|
|
-- game.Log("Drawing scores...", game.LOGGER_INFO) -- debug
|
2021-11-17 22:28:26 +01:00
|
|
|
for i, chart in ipairs(result.charts) do
|
2021-11-21 18:37:21 +01:00
|
|
|
-- if chart.score == nil then
|
|
|
|
-- game.Log("Score does not exist? Quitting loop...", game.LOGGER_WARNING)
|
|
|
|
-- break
|
|
|
|
-- end
|
|
|
|
|
|
|
|
drawChartResult(deltaTime, 0, 836+(165*(i-1)), chart);
|
2021-10-23 01:27:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2021-11-21 18:37:21 +01:00
|
|
|
function drawDecorations()
|
2021-11-21 20:11:26 +01:00
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(118, 846.5, 43*0.855, 429*0.855, notchesImage, 1, 0)
|
2021-11-21 18:37:21 +01:00
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(400, 807, 367*0.857, 429*0.857, trackBarsImage, 1, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function drawCompletion()
|
|
|
|
local completitionImage = completionFailImage;
|
|
|
|
if result.passed then
|
|
|
|
completitionImage = completionPassImage;
|
|
|
|
end
|
|
|
|
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.ImageRect(63, 1331, 766*0.85, 130*0.85, completitionImage, 1, 0)
|
|
|
|
|
2021-12-10 03:41:44 +01:00
|
|
|
Numbers.draw_number(925, 1370, 1.0, percGet, 3, scoreNumber, true, 0.3, 1.12)
|
2021-11-21 20:11:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
gfx.BeginPath();
|
2021-11-21 21:09:39 +01:00
|
|
|
gfx.Rect(741, 1402, 278*math.min(1, percGet / percRequired), 6);
|
2021-11-21 20:11:26 +01:00
|
|
|
gfx.FillColor(255, 128, 0, 255);
|
|
|
|
gfx.Fill()
|
2021-11-21 18:37:21 +01:00
|
|
|
end
|
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
|
|
|
|
function result_set()
|
2021-12-10 03:41:44 +01:00
|
|
|
local reqTextWords = common.splitString(result.requirement_text, ' ');
|
2021-11-21 20:11:26 +01:00
|
|
|
for index, word in ipairs(reqTextWords) do
|
|
|
|
if string.find(word, '%%') ~= nil then -- %% = %, because % is an escape char
|
|
|
|
local percNumber = tonumber(string.gsub(word, '%%', ''), 10)
|
|
|
|
percRequired = percNumber;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
game.Log(percRequired, game.LOGGER_ERROR);
|
2021-11-21 21:09:39 +01:00
|
|
|
|
|
|
|
local a = 0;
|
|
|
|
for i, chart in ipairs(result.charts) do
|
|
|
|
a = a + chart.percent;
|
|
|
|
game.Log('#' .. i .. ' got ' .. chart.percent .. '% // ACC at ' .. a, game.LOGGER_ERROR);
|
|
|
|
end
|
|
|
|
percGet = a / #result.charts;
|
2021-11-21 20:11:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2021-08-18 20:22:57 +02:00
|
|
|
local IR_HeartbeatResponse = function(res)
|
|
|
|
if res.statusCode == IRData.States.Success then
|
2021-11-17 22:28:26 +01:00
|
|
|
IRserverName = res.body.serverName .. " " .. res.body.irVersion;
|
2021-08-18 20:22:57 +02:00
|
|
|
else
|
|
|
|
game.Log("Can't connect to IR!", game.LOGGER_WARNING)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local IR_Handle = function()
|
|
|
|
if not irHeartbeatRequested then
|
|
|
|
IR.Heartbeat(IR_HeartbeatResponse)
|
|
|
|
irHeartbeatRequested = true;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-03 03:28:45 +01:00
|
|
|
local function drawResultScreen(x, y, w, h, deltaTime)
|
|
|
|
gfx.BeginPath()
|
|
|
|
|
|
|
|
gfx.Translate(x, y);
|
|
|
|
gfx.Scale(w / 1080, h / 1920);
|
|
|
|
gfx.Scissor(0, 0, 1080, 1920);
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-10-23 01:27:44 +02:00
|
|
|
handleSfx()
|
2021-08-18 20:22:57 +02:00
|
|
|
IR_Handle()
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
drawBackground()
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
drawDecorations()
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
drawPlayerInfo()
|
2021-07-25 20:10:06 +02:00
|
|
|
|
2021-11-21 18:37:21 +01:00
|
|
|
drawScorePanelContent(deltaTime)
|
2021-10-23 01:27:44 +02:00
|
|
|
|
2021-11-21 20:11:26 +01:00
|
|
|
drawCompletion()
|
|
|
|
|
2021-08-18 17:29:54 +02:00
|
|
|
drawHeader()
|
|
|
|
Footer.draw(deltaTime);
|
2021-12-03 03:28:45 +01:00
|
|
|
|
|
|
|
gfx.ResetTransform()
|
|
|
|
end
|
|
|
|
|
|
|
|
function render(deltaTime)
|
|
|
|
-- detect resolution change
|
|
|
|
local resx, resy = game.GetResolution()
|
|
|
|
if resx ~= resX or resy ~= resY then
|
|
|
|
resolutionChange(resx, resy)
|
|
|
|
end
|
|
|
|
|
|
|
|
gfx.BeginPath()
|
|
|
|
local bgImageWidth, bgImageHeight = gfx.ImageSize(backgroundImage)
|
|
|
|
gfx.Rect(0, 0, resX, resY)
|
|
|
|
gfx.FillPaint(gfx.ImagePattern(0, 0, bgImageWidth, bgImageHeight, 0, backgroundImage, 0.2))
|
|
|
|
gfx.Fill()
|
|
|
|
|
|
|
|
drawResultScreen((resX - fullX) / 2, 0, fullX, fullY, deltaTime)
|
2021-11-17 22:28:26 +01:00
|
|
|
end
|