diff --git a/scripts/songselect/chalwheel.lua b/scripts/songselect/chalwheel.lua index d5351a5..d3debd7 100644 --- a/scripts/songselect/chalwheel.lua +++ b/scripts/songselect/chalwheel.lua @@ -215,157 +215,155 @@ draw_challenge = function(challenge, x, y, w, h, selected) check_or_create_cache(challenge) - local _draw_card_bg = function() + ---------------------------------------------------------- + -- draw card bg section + ---------------------------------------------------------- + if not selected then gfx.BeginPath() gfx.ImageRect(x, y, w, h, challengeCardBGImage, 1, 0) end - local _draw_info = function() - local stateLabel = challengeCache[challenge.id]["pass_state"] - local stateLabelWidth, stateLabelHeight = gfx.ImageSize(stateLabel) - local stateLabelAspect = stateLabelWidth / stateLabelHeight + ---------------------------------------------------------- + -- draw info section + ---------------------------------------------------------- + local stateLabel = challengeCache[challenge.id]["pass_state"] + local stateLabelWidth, stateLabelHeight = gfx.ImageSize(stateLabel) + local stateLabelAspect = stateLabelWidth / stateLabelHeight - local stateWidth = w / 5 - local stateHeight = stateWidth / stateLabelAspect - local stateOffsetX = x + w / 32 - local stateOffsetY = y + h / 32 + local stateWidth = w / 5 + local stateHeight = stateWidth / stateLabelAspect + local stateOffsetX = x + w / 32 + local stateOffsetY = y + h / 32 - local titleMargin = 6 - local titleFontSize = math.floor(0.11 * h) -- must be an integer - local titleMaxWidth = 6 / 9 * w - local titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right - local titleBaselineY = y + 0.025 * h -- align baseline + local titleMargin = 6 + local titleFontSize = math.floor(0.11 * h) -- must be an integer + local titleMaxWidth = 6 / 9 * w + local titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right + local titleBaselineY = y + 0.025 * h -- align baseline - if selected then - stateWidth = stateWidth / 0.9 - stateHeight = stateHeight / 0.9 - stateOffsetY = y + h / 16 + if selected then + stateWidth = stateWidth / 0.9 + stateHeight = stateHeight / 0.9 + stateOffsetY = y + h / 16 - titleFontSize = math.floor(0.075 * h) -- must be an integer - titleMaxWidth = 3 / 5 * w - titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right - titleBaselineY = y + 0.09 * h -- align baseline - end - - update_cache_labels(challenge, titleFontSize) - - gfx.BeginPath() - gfx.ImageRect(stateOffsetX, stateOffsetY, stateWidth, stateHeight, stateLabel, 1, 0) - - gfx.FontFace("divlit_custom.ttf") - gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_BASELINE) - gfx.DrawLabel(challengeCache[challenge.id]["title"], titleCenterX, titleBaselineY, titleMaxWidth) + titleFontSize = math.floor(0.075 * h) -- must be an integer + titleMaxWidth = 3 / 5 * w + titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right + titleBaselineY = y + 0.09 * h -- align baseline end - local _draw_jacket = function() - local size = h * 0.68 - local offsetX = x + w / 32 - local offsetY = y + h - size - h * 0.05 + update_cache_labels(challenge, titleFontSize) - if not selected then - size = h * 0.66 - offsetX = x + w * 0.058 - offsetY = y + h - size - h * 0.066 - end + gfx.BeginPath() + gfx.ImageRect(stateOffsetX, stateOffsetY, stateWidth, stateHeight, stateLabel, 1, 0) - gfx.BeginPath() - gfx.ImageRect(offsetX, offsetY, size, size, challengeCache[challenge.id]["jackets"][1], 1, 0) - end + gfx.FontFace("divlit_custom.ttf") + gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_BASELINE) + gfx.DrawLabel(challengeCache[challenge.id]["title"], titleCenterX, titleBaselineY, titleMaxWidth) - local _draw_stats = function() - local textSizeCorrection = h / gfx.ImageSize(scoreNumber[1]) - - local percentOffsetX = x + 6 / 12 * w - local percentOffsetY = y + 0.87 * h - local percentSize = 0.17 * textSizeCorrection - - local scoreUpperOffsetX = 0 - local scoreUpperOffsetY = 0 - local scoreOffsetX = x + w * 0.74 - local scoreOffsetY = y + h * 0.9 - local scoreUpperSize = 0.2 * textSizeCorrection - local scoreSize = 0.125 * textSizeCorrection - - local percent = challengeCache[challenge.id]["percent"] - local scoreUpper = math.floor(challengeCache[challenge.id]["total_score"] / 10000) - local score = challengeCache[challenge.id]["total_score"] - - if selected then - percentOffsetX = x + 11 / 24 * w - percentOffsetY = y + 49 / 64 * h - percentSize = 0.12 * textSizeCorrection - - scoreUpperOffsetX = x + w * 0.63 - scoreUpperOffsetY = y + h * 0.82 - scoreOffsetX = x + w * 0.755 - scoreOffsetY = y + h * 0.835 - scoreUpperSize = 0.12 * textSizeCorrection - scoreSize = 0.09 * textSizeCorrection - end - - Numbers.draw_number(percentOffsetX, percentOffsetY, 1, percent, 3, scoreNumber, true, percentSize, 1) - -- TODO: Missing percentage character - - if selected then - Numbers.draw_number( - scoreUpperOffsetX, scoreUpperOffsetY, 1, scoreUpper, 4, scoreNumber, true, scoreUpperSize, 1 - ) - Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, score, 4, scoreNumber, true, scoreSize, 1) - else - Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, score, 8, scoreNumber, true, scoreSize, 1) - end - - -- TODO: Missing completion bar - - -- TODO: Missing completion badge (COMP, HARD, UC, PUC) - -- TODO: Missing completion grade (S+, S, AAA+, etc.) - end - - local _draw_charts = function() - local diffIconHeight = 0.124 * h - local diffIconWidth = 140 / 31 * diffIconHeight -- only scaling, no stretching textures - -- diffIconWidth = 0.8 * diffIconWidth -- okay, maybe a little squishing must be done - - local paddingY = 0.18 * h - local offsetX = x + 0.252 * w - local offsetY = y + 0.246 * h - - local titleMargin = 6 - local titleMaxWidth = 6 / 9 * w - local titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right - - if selected then - diffIconHeight = h / 12 - diffIconWidth = 140 / 31 * diffIconHeight -- only scaling, no stretching textures - -- diffIconWidth = 0.8 * diffIconWidth -- okay, maybe a little squishing must be done - - paddingY = 0.122 * h - offsetX = x + 0.268 * w - offsetY = y + 0.256 * h - - titleFontSize = math.floor(0.075 * h) -- must be an integer - titleMaxWidth = 3 / 5 * w - titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right - end - - for i, chart in ipairs(challengeCache[challenge.id]["charts"]) do - local ypos = offsetY + paddingY * (i - 1) - - draw_diff_icon(chart, offsetX, ypos, diffIconWidth, diffIconHeight, selected) - - gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_MIDDLE) - gfx.DrawLabel(chart.title, titleCenterX, ypos + diffIconHeight / 2, titleMaxWidth) - end - end + ---------------------------------------------------------- + -- draw jacket section + ---------------------------------------------------------- + local size = h * 0.68 + local offsetX = x + w / 32 + local offsetY = y + h - size - h * 0.05 if not selected then - _draw_card_bg() + size = h * 0.66 + offsetX = x + w * 0.058 + offsetY = y + h - size - h * 0.066 end - _draw_info() - _draw_jacket() - _draw_stats() - _draw_charts() + gfx.BeginPath() + gfx.ImageRect(offsetX, offsetY, size, size, challengeCache[challenge.id]["jackets"][1], 1, 0) + + ---------------------------------------------------------- + -- draw stats section + ---------------------------------------------------------- + local textSizeCorrection = h / gfx.ImageSize(scoreNumber[1]) + + local percentOffsetX = x + 6 / 12 * w + local percentOffsetY = y + 0.87 * h + local percentSize = 0.17 * textSizeCorrection + + local scoreUpperOffsetX = 0 + local scoreUpperOffsetY = 0 + local scoreOffsetX = x + w * 0.74 + local scoreOffsetY = y + h * 0.9 + local scoreUpperSize = 0.2 * textSizeCorrection + local scoreSize = 0.125 * textSizeCorrection + + local percent = challengeCache[challenge.id]["percent"] + local scoreUpper = math.floor(challengeCache[challenge.id]["total_score"] / 10000) + local score = challengeCache[challenge.id]["total_score"] + + if selected then + percentOffsetX = x + 11 / 24 * w + percentOffsetY = y + 49 / 64 * h + percentSize = 0.12 * textSizeCorrection + + scoreUpperOffsetX = x + w * 0.63 + scoreUpperOffsetY = y + h * 0.82 + scoreOffsetX = x + w * 0.755 + scoreOffsetY = y + h * 0.835 + scoreUpperSize = 0.12 * textSizeCorrection + scoreSize = 0.09 * textSizeCorrection + end + + Numbers.draw_number(percentOffsetX, percentOffsetY, 1, percent, 3, scoreNumber, true, percentSize, 1) + -- TODO: Missing percentage character + + if selected then + Numbers.draw_number( + scoreUpperOffsetX, scoreUpperOffsetY, 1, scoreUpper, 4, scoreNumber, true, scoreUpperSize, 1 + ) + Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, score, 4, scoreNumber, true, scoreSize, 1) + else + Numbers.draw_number(scoreOffsetX, scoreOffsetY, 1, score, 8, scoreNumber, true, scoreSize, 1) + end + + -- TODO: Missing completion bar + + -- TODO: Missing completion badge (COMP, HARD, UC, PUC) + -- TODO: Missing completion grade (S+, S, AAA+, etc.) + + ---------------------------------------------------------- + -- draw charts section + ---------------------------------------------------------- + local diffIconHeight = 0.124 * h + local diffIconWidth = 140 / 31 * diffIconHeight -- only scaling, no stretching textures + -- diffIconWidth = 0.8 * diffIconWidth -- okay, maybe a little squishing must be done + + local paddingY = 0.18 * h + local offsetX = x + 0.252 * w + local offsetY = y + 0.246 * h + + local titleMargin = 6 + local titleMaxWidth = 6 / 9 * w + local titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right + + if selected then + diffIconHeight = h / 12 + diffIconWidth = 140 / 31 * diffIconHeight -- only scaling, no stretching textures + -- diffIconWidth = 0.8 * diffIconWidth -- okay, maybe a little squishing must be done + + paddingY = 0.122 * h + offsetX = x + 0.268 * w + offsetY = y + 0.256 * h + + titleFontSize = math.floor(0.075 * h) -- must be an integer + titleMaxWidth = 3 / 5 * w + titleCenterX = x + w - titleMargin - titleMaxWidth / 2 -- align right + end + + for i, chart in ipairs(challengeCache[challenge.id]["charts"]) do + local ypos = offsetY + paddingY * (i - 1) + + draw_diff_icon(chart, offsetX, ypos, diffIconWidth, diffIconHeight, selected) + + gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_MIDDLE) + gfx.DrawLabel(chart.title, titleCenterX, ypos + diffIconHeight / 2, titleMaxWidth) + end gfx.ForceRender()