diff --git a/scripts/challengeresult.lua b/scripts/challengeresult.lua index 6a65536..6cadbae 100644 --- a/scripts/challengeresult.lua +++ b/scripts/challengeresult.lua @@ -28,6 +28,9 @@ local crewImage = gfx.CreateSkinImage("crew/portrait.png", 0); local notchesImage = gfx.CreateSkinImage("challenge_result/notches.png", 0); local trackBarsImage = gfx.CreateSkinImage("challenge_result/track_bars.png", 0); +local completionFailImage = gfx.CreateSkinImage("challenge_result/pass_states/fail.png", 0); +local completionPassImage = gfx.CreateSkinImage("challenge_result/pass_states/pass.png", 0); + local irHeartbeatRequested = false; local IRserverName = ""; @@ -54,6 +57,8 @@ local gradeImages = { none = gfx.CreateSkinImage("common/grades/none.png", 0), } +local percRequired = 1; + -- AUDIO game.LoadSkinSample("challenge_result.wav") @@ -78,6 +83,17 @@ local function handleSfx() end end +function splitString(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + table.insert(t, str) + end + return t +end + local function load_number_image(path) local images = {} for i = 0, 9 do @@ -171,7 +187,7 @@ function drawChartResult(deltaTime, x, y, chartResult) local score = chartResult.score or 0; draw_number(x + 500, y+80, 1.0, math.floor(score / 10000), 4, scoreNumber, true, 0.30, 1.12) - draw_number(x + 660, y+85, 1.0, score, 4, scoreNumber, true, 0.22, 1.12) + draw_number(x + 655, y+85, 1.0, score, 4, scoreNumber, true, 0.22, 1.12) local gradeImageKey = string.gsub(chartResult.grade, '+', '_P'); @@ -204,9 +220,45 @@ function drawScorePanelContent(deltaTime) end function drawDecorations() + gfx.BeginPath() + gfx.ImageRect(118, 846.5, 43*0.855, 429*0.855, notchesImage, 1, 0) + 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) + + draw_number(925, 1370, 1.0, result.avgPercentage, 3, scoreNumber, true, 0.3, 1.12) + + + gfx.BeginPath(); + gfx.Rect(741, 1402, 278*math.min(1, result.avgPercentage / percRequired), 6); + gfx.FillColor(255, 128, 0, 255); + gfx.Fill() +end + + +function result_set() + local reqTextWords = splitString(result.requirement_text, ' '); + 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); +end + + local IR_HeartbeatResponse = function(res) if res.statusCode == IRData.States.Success then IRserverName = res.body.serverName .. " " .. res.body.irVersion; @@ -232,10 +284,14 @@ function render(deltaTime) drawBackground() + drawDecorations() + drawPlayerInfo() drawScorePanelContent(deltaTime) + drawCompletion() + drawHeader() Footer.draw(deltaTime); end