From c224aa928b31215fa8a15f4c8d00ff67c64d8f4b Mon Sep 17 00:00:00 2001 From: Hersi Date: Sat, 20 Nov 2021 23:51:53 +0100 Subject: [PATCH] implemented chalwheel stats --- scripts/common/numbers.lua | 36 ++++++++++++++++++++++++++++ scripts/result.lua | 35 ++++------------------------ scripts/songselect/chalwheel.lua | 40 ++++++++++++++++++++++---------- 3 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 scripts/common/numbers.lua diff --git a/scripts/common/numbers.lua b/scripts/common/numbers.lua new file mode 100644 index 0000000..fdd7c77 --- /dev/null +++ b/scripts/common/numbers.lua @@ -0,0 +1,36 @@ +function load_number_image(path) + local images = {} + for i = 0, 9 do + images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), 0) + end + return images +end + +function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern, dim_zeros) + scale = scale or 1 + kern = kern or 1 + + local tw, th = gfx.ImageSize(images[1]) + tw = tw * scale + th = th * scale + x = x + (tw * (digits - 1)) / 2 + y = y - th / 2 + + for i = 1, digits do + local mul = 10 ^ (i - 1) + local digit = math.floor(num / mul) % 10 + local a = alpha + + if is_dim and num < mul then a = 0.4 end + + gfx.BeginPath() + gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0) + + x = x - (tw * kern) + end +end + +return { + load_number_image = load_number_image, + draw_number = draw_number +} \ No newline at end of file diff --git a/scripts/result.lua b/scripts/result.lua index cd656ce..a100c4e 100644 --- a/scripts/result.lua +++ b/scripts/result.lua @@ -1,3 +1,4 @@ +local Numbers = require('common.numbers') local Easing = require('common.easings'); local Background = require('components.background'); local Footer = require('components.footer'); @@ -189,34 +190,6 @@ function drawTimingBar(y, value, max, type) gfx.ClosePath(); end -function load_number_image(path) - local images = {} - for i = 0, 9 do - images[i + 1] = gfx.CreateSkinImage(string.format("%s/%d.png", path, i), - 0) - end - return images -end - -function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern) - scale = scale or 1; - kern = kern or 1; - local tw, th = gfx.ImageSize(images[1]) - tw = tw * scale; - th = th * scale; - x = x + (tw * (digits - 1)) / 2 - y = y - th / 2 - for i = 1, digits do - local mul = 10 ^ (i - 1) - local digit = math.floor(num / mul) % 10 - local a = alpha - if is_dim and num < mul then a = 0.4 end - gfx.BeginPath() - gfx.ImageRect(x, y, tw, th, images[digit + 1], a, 0) - x = x - (tw * kern) - end -end - local drawIdol = function(deltaTime) local idolAnimTickRes = gfx.TickAnimation(idolAnimation, deltaTime); if idolAnimTickRes == 1 then @@ -279,7 +252,7 @@ local drawRightPanel = function() gfx.ImageRect(rightPanelX, rightPanelY, tw, th, rightPanelImage, 1, 0); end -local scoreNumber = load_number_image("score_num"); +local scoreNumber = Numbers.load_number_image("score_num"); local drawRightPanelContent = function() local highScoreScore = 0; @@ -305,10 +278,10 @@ local drawRightPanelContent = function() gfx.Text(result.artist, rightPanelX + 435, rightPanelY + 143); -- Draw score - draw_number(rightPanelX + 580, rightPanelY + 192, 1.0, + Numbers.draw_number(rightPanelX + 580, rightPanelY + 192, 1.0, math.floor(result.score / 10000), 4, scoreNumber, true, 0.40, 1.12) - draw_number(rightPanelX + 775, rightPanelY + 200, 1.0, result.score, 4, + Numbers.draw_number(rightPanelX + 775, rightPanelY + 200, 1.0, result.score, 4, scoreNumber, true, 0.25, 1.12) -- If this is the highscore, draw over the glowing best badge diff --git a/scripts/songselect/chalwheel.lua b/scripts/songselect/chalwheel.lua index eaebfe0..a9bcef7 100644 --- a/scripts/songselect/chalwheel.lua +++ b/scripts/songselect/chalwheel.lua @@ -1,3 +1,4 @@ +local Numbers = require('common.numbers') local DiffRectangle = require("components.diff_rectangle") -- Horizontal alignment @@ -88,6 +89,8 @@ local passStates = { gfx.CreateSkinImage("challenge_select/pass_states/cleared.png", 0), } +local scoreNumber = Numbers.load_number_image("score_num") + gfx.LoadSkinFont("divlit_custom.ttf") gfx.LoadSkinFont("dfmarugoth.ttf"); @@ -344,18 +347,32 @@ draw_challenge = function(challenge, x, y, w, h, selected) end local _draw_stats = function () - local percentOffsetX = x + 5/9 * w - local percentOffsetY = y + 5/6 * h - local scoreOffsetX = x - local scoreOffsetY = y + local percentOffsetX = x + 6/12 * w + local percentOffsetY = y + 14/16 * h - gfx.BeginPath() - gfx.FontFace("divlit_custom.ttf") - gfx.FontSize(56) - gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT) - gfx.Text(challengeCache[challenge.id]["percent"], percentOffsetX - 24, percentOffsetY) - gfx.FontSize(32) - gfx.Text("%", percentOffsetX, percentOffsetY) + local scoreUpperOffsetX = 0 + local scoreUpperOffsetY = 0 + local scoreOffsetX = x + w * 0.74 + local scoreOffsetY = y + h * 0.9 + + if selected then + percentOffsetX = x + 11/24 * w + percentOffsetY = y + 49/64 * h + + scoreUpperOffsetX = x + w * 0.63 + scoreUpperOffsetY = y + h * 0.82 + scoreOffsetX = x + w * 0.755 + scoreOffsetY = y + h * 0.835 + end + + Numbers.draw_number(percentOffsetX, percentOffsetY, 1, challengeCache[challenge.id]["percent"], 3, scoreNumber, true, 0.2, 1) + + if selected then + Numbers.draw_number(scoreUpperOffsetX, scoreUpperOffsetY, 1, math.floor(challengeCache[challenge.id]["total_score"] / 10000), 4, scoreNumber, true, 0.2, 1) + Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, challengeCache[challenge.id]["total_score"], 4, scoreNumber, true, 0.14, 1) + else + Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, challengeCache[challenge.id]["total_score"], 8, scoreNumber, true, 0.14, 1) + end end local _draw_chart = function () @@ -368,7 +385,6 @@ draw_challenge = function(challenge, x, y, w, h, selected) _draw_info() _draw_jacket() - _draw_stats() --[[