renamed "song" to "challenge" in chalwheel

This commit is contained in:
Hersi 2021-11-18 00:26:25 +01:00
parent c3ae26521b
commit bef6a917c1
1 changed files with 74 additions and 60 deletions

View File

@ -13,7 +13,7 @@ TEXT_ALIGN_BASELINE = 64
local jacket = nil; local jacket = nil;
local selectedIndex = 1 local selectedIndex = 1
local selectedDiff = 1 local selectedDiff = 1
local songCache = {} local challengeCache = {}
local ioffset = 0 local ioffset = 0
local doffset = 0 local doffset = 0
local soffset = 0 local soffset = 0
@ -88,7 +88,7 @@ game.LoadSkinSample("menu_click")
game.LoadSkinSample("click-02") game.LoadSkinSample("click-02")
game.LoadSkinSample("woosh") game.LoadSkinSample("woosh")
local wheelSize = 12 local wheelSize = 6
get_page_size = function() get_page_size = function()
return math.floor(wheelSize / 2) return math.floor(wheelSize / 2)
@ -130,53 +130,53 @@ adjustScreen = function(x, y)
fullY = y fullY = y
end end
check_or_create_cache = function(song, full) check_or_create_cache = function(challenge, full)
if not songCache[song.id] then if not challengeCache[challenge.id] then
songCache[song.id] = {} challengeCache[challenge.id] = {}
end end
if not songCache[song.id]["title"] then if not challengeCache[challenge.id]["title"] then
songCache[song.id]["title"] = gfx.CreateLabel(song.title, 30, 0) challengeCache[challenge.id]["title"] = gfx.CreateLabel(challenge.title, 30, 0)
end end
if not songCache[song.id]["chart_names"] then if not challengeCache[challenge.id]["chart_names"] then
local names = "Charts:" local names = "Charts:"
for _, chart in ipairs(song.charts) do for _, chart in ipairs(challenge.charts) do
names = names .. " [" .. chart.title .. "]" names = names .. " [" .. chart.title .. "]"
end end
if song.missing_chart then if challenge.missing_chart then
names = names .. " *COULD NOT FIND ALL CHARTS!*" names = names .. " *COULD NOT FIND ALL CHARTS!*"
end end
songCache[song.id]["chart_names"] = gfx.CreateLabel(names, 20, 0) challengeCache[challenge.id]["chart_names"] = gfx.CreateLabel(names, 20, 0)
end end
if song.topBadge ~= 0 if challenge.topBadge ~= 0
and (not songCache[song.id]["percent"] or not songCache[song.id]["percent_value"] and (not challengeCache[challenge.id]["percent"] or not challengeCache[challenge.id]["percent_value"]
or songCache[song.id]["percent_value"] ~= song.bestScore) then or challengeCache[challenge.id]["percent_value"] ~= challenge.bestScore) then
songCache[song.id]["percent"] = gfx.CreateLabel( challengeCache[challenge.id]["percent"] = gfx.CreateLabel(
string.format( string.format(
"%u%%", math.max(0, (song.bestScore - 8000000) // 10000) "%u%%", math.max(0, (challenge.bestScore - 8000000) // 10000)
), 35, 0 ), 35, 0
) )
songCache[song.id]["percent_value"] = song.bestScore challengeCache[challenge.id]["percent_value"] = challenge.bestScore
end end
if full then if full then
if not songCache[song.id]["jackets"] then if not challengeCache[challenge.id]["jackets"] then
local jackets = {} local jackets = {}
for i, chart in ipairs(song.charts) do for i, chart in ipairs(challenge.charts) do
jackets[i] = gfx.LoadImageJob(chart.jacketPath, jacketFallback, 200, 200) jackets[i] = gfx.LoadImageJob(chart.jacketPath, jacketFallback, 200, 200)
end end
songCache[song.id]["jackets"] = jackets challengeCache[challenge.id]["jackets"] = jackets
end end
if not songCache[song.id]["desc"] then if not challengeCache[challenge.id]["desc"] then
local desc = "\n" local desc = "\n"
for _, chart in ipairs(song.charts) do for _, chart in ipairs(challenge.charts) do
desc = desc .. "" .. chart.title .. "\n\n" desc = desc .. "" .. chart.title .. "\n\n"
end end
if song.missing_chart then if challenge.missing_chart then
desc = desc .. "*COULD NOT FIND ALL CHARTS!*\n\n" desc = desc .. "*COULD NOT FIND ALL CHARTS!*\n\n"
end end
desc = desc .. "" desc = desc .. ""
songCache[song.id]["desc"] = gfx.CreateLabel(desc, 20, 0) challengeCache[challenge.id]["desc"] = gfx.CreateLabel(desc, 20, 0)
end end
end end
end end
@ -213,10 +213,13 @@ draw_scores = function(difficulty, x, y, w, h)
end end
end end
draw_song = function(song, x, y, w, h, selected) draw_challenge = function(challenge, x, y, w, h, selected)
check_or_create_cache(song) if not challenge then return end
check_or_create_cache(challenge)
gfx.BeginPath() gfx.BeginPath()
-- gfx.RoundedRectVarying(x,y, w, h,0,0,0,40) gfx.RoundedRectVarying(x,y, w, h,0,0,0,40)
gfx.FillColor(30, 30, 30) gfx.FillColor(30, 30, 30)
gfx.StrokeColor(0, 128, 255) gfx.StrokeColor(0, 128, 255)
gfx.StrokeWidth(1) gfx.StrokeWidth(1)
@ -226,15 +229,17 @@ draw_song = function(song, x, y, w, h, selected)
end end
gfx.Fill() gfx.Fill()
gfx.Stroke() gfx.Stroke()
gfx.FillColor(255, 255, 255) gfx.FillColor(255, 255, 255)
gfx.TextAlign(gfx.TEXT_ALIGN_TOP + gfx.TEXT_ALIGN_LEFT) gfx.TextAlign(gfx.TEXT_ALIGN_TOP + gfx.TEXT_ALIGN_LEFT)
-- gfx.DrawLabel(songCache[song.id]["title"], x+10, y + 5, w-10) gfx.DrawLabel(challengeCache[challenge.id]["title"], x+10, y + 5, w-10)
if (song.missing_chart) then
if (challenge.missing_chart) then
gfx.FillColor(255, 20, 20) gfx.FillColor(255, 20, 20)
end end
-- gfx.DrawLabel(songCache[song.id]["chart_names"], x+20, y + 50, w-10) gfx.DrawLabel(challengeCache[challenge.id]["chart_names"], x+20, y + 50, w-10)
-- gfx.DrawLabel(songCache[song.id]["artist"], x+20, y + 50, w-10) --gfx.DrawLabel(challengeCache[challenge.id]["artist"], x+20, y + 50, w-10)
gfx.ForceRender() gfx.ForceRender()
end end
@ -298,8 +303,11 @@ draw_diffs = function(diffs, x, y, w, h)
draw_cursor(x + w / 2, y + diffHeight / 2, timer * math.pi, diffHeight / 1.5) draw_cursor(x + w / 2, y + diffHeight / 2, timer * math.pi, diffHeight / 1.5)
end end
draw_selected = function(song, x, y, w, h) draw_selected = function(challenge, x, y, w, h)
check_or_create_cache(song, true) if not challenge then return end
check_or_create_cache(challenge, true)
-- set up padding and margins -- set up padding and margins
local xPadding = math.floor(w / 16) local xPadding = math.floor(w / 16)
local yPadding = math.floor(h / 32) local yPadding = math.floor(h / 32)
@ -322,16 +330,16 @@ draw_selected = function(song, x, y, w, h)
local imageSize = math.floor((height / 2) * 2) - 10 local imageSize = math.floor((height / 2) * 2) - 10
local imageXPos = x + xMargin + xPadding local imageXPos = x + xMargin + xPadding
local square_size = math.ceil(math.sqrt(#song.charts)) local square_size = math.ceil(math.sqrt(#challenge.charts))
local origImageSize = imageSize local origImageSize = imageSize
imageSize = math.floor(imageSize / square_size) imageSize = math.floor(imageSize / square_size)
local bottom_off = math.ceil((square_size - #song.charts)) local bottom_off = math.ceil((square_size - #challenge.charts))
local img_row = 0; local img_row = 0;
local img_col = 0; local img_col = 0;
for i, chart in ipairs(song.charts) do for i, chart in ipairs(challenge.charts) do
if songCache[song.id]["jackets"][i] == jacketFallback then if challengeCache[challenge.id]["jackets"][i] == jacketFallback then
songCache[song.id]["jackets"][i] = gfx.LoadImageJob(chart.jacketPath, jacketFallback, 200, 200) challengeCache[challenge.id]["jackets"][i] = gfx.LoadImageJob(chart.jacketPath, jacketFallback, 200, 200)
end end
gfx.BeginPath() gfx.BeginPath()
local xoff = img_col * imageSize local xoff = img_col * imageSize
@ -340,7 +348,7 @@ draw_selected = function(song, x, y, w, h)
end end
gfx.ImageRect( gfx.ImageRect(
62.52, 888.6 + (img_row / 200 * imageSize), imageSize * 1.19, imageSize * 1.19, 62.52, 888.6 + (img_row / 200 * imageSize), imageSize * 1.19, imageSize * 1.19,
songCache[song.id]["jackets"][i], 1, 0 challengeCache[challenge.id]["jackets"][i], 1, 0
) )
img_col = img_col + 1 img_col = img_col + 1
if img_col >= square_size then if img_col >= square_size then
@ -354,14 +362,14 @@ draw_selected = function(song, x, y, w, h)
num_img_rows = img_row num_img_rows = img_row
end end
if songCache[song.id][selectedDiff] then if challengeCache[challenge.id][selectedDiff] then
gfx.BeginPath() gfx.BeginPath()
-- gfx.ImageRect(imageXPos, y+yMargin+yPadding, imageSize, imageSize, songCache[song.id][selectedDiff], 1, 0) -- gfx.ImageRect(imageXPos, y+yMargin+yPadding, imageSize, imageSize, songCache[song.id][selectedDiff], 1, 0)
end end
local gradeImg = nil local gradeImg = nil
for i, v in ipairs(grades) do for i, v in ipairs(grades) do
if v.max > song.bestScore then if v.max > challenge.bestScore then
gfx.BeginPath() gfx.BeginPath()
gradeImg = v.image gradeImg = v.image
break break
@ -371,15 +379,15 @@ draw_selected = function(song, x, y, w, h)
scrollmulOffset = scrollmulOffset - scrollmul scrollmulOffset = scrollmulOffset - scrollmul
scrollmul = 0 scrollmul = 0
end end
local descw, desch = gfx.LabelSize(songCache[song.id]["desc"]) local descw, desch = gfx.LabelSize(challengeCache[challenge.id]["desc"])
local boxh, boxw = 0 local boxh, boxw = 0, 0
local starty, startx = 0 local starty, startx = 0, 0
gfx.FontSize(40) gfx.FontSize(40)
gfx.TextAlign(gfx.TEXT_ALIGN_TOP + gfx.TEXT_ALIGN_MIDDLE) gfx.TextAlign(gfx.TEXT_ALIGN_TOP + gfx.TEXT_ALIGN_MIDDLE)
starty = y + yMargin + yPadding starty = y + yMargin + yPadding
startx = xpos + xPadding + origImageSize + 10 startx = xpos + xPadding + origImageSize + 10
gfx.DrawLabel(songCache[song.id]["title"], 295, 845, width - origImageSize - 30) gfx.DrawLabel(challengeCache[challenge.id]["title"], 295, 845, width - origImageSize - 30)
gfx.FontSize(30) gfx.FontSize(30)
-- Scroll box info -- Scroll box info
@ -392,9 +400,9 @@ draw_selected = function(song, x, y, w, h)
-- gfx.FontSize(20) -- gfx.FontSize(20)
-- gfx.DrawLabel(songCache[song.id]["bpm"], xpos+xPadding+imageSize+3, y+yMargin+yPadding + 85, width-imageSize-20) -- gfx.DrawLabel(songCache[song.id]["bpm"], xpos+xPadding+imageSize+3, y+yMargin+yPadding + 85, width-imageSize-20)
-- gfx.FastText(string.format("Effector: %s", diff.effector), xpos+xPadding+imageSize+3, y+yMargin+yPadding + 115) -- gfx.FastText(string.format("Effector: %s", diff.effector), xpos+xPadding+imageSize+3, y+yMargin+yPadding + 115)
if song.topBadge ~= 0 then if challenge.topBadge ~= 0 then
gfx.BeginPath() gfx.BeginPath()
gfx.ImageRect(978, 1026.5, 50, 50, badges[song.topBadge], 1, 0) gfx.ImageRect(978, 1026.5, 50, 50, badges[challenge.topBadge], 1, 0)
local iar = 0 local iar = 0
if gradeImg ~= nil then if gradeImg ~= nil then
gfx.BeginPath() gfx.BeginPath()
@ -403,7 +411,7 @@ draw_selected = function(song, x, y, w, h)
gfx.ImageRect(961 - iar * 50, 1026.5, iar * 50, 50, gradeImg, 1, 0) gfx.ImageRect(961 - iar * 50, 1026.5, iar * 50, 50, gradeImg, 1, 0)
end end
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE) gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE)
gfx.DrawLabel(songCache[song.id]["percent"], 595, 1045, 200) gfx.DrawLabel(challengeCache[challenge.id]["percent"], 595, 1045, 200)
end end
-- Render desc scrolling box -- Render desc scrolling box
@ -435,7 +443,7 @@ draw_selected = function(song, x, y, w, h)
gfx.BeginPath() gfx.BeginPath()
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
gfx.DrawLabel(songCache[song.id]["desc"], 600, 942) gfx.DrawLabel(challengeCache[challenge.id]["desc"], 600, 942)
end end
-- if aspectRatio == "PortraitWidescreen" then -- if aspectRatio == "PortraitWidescreen" then
@ -446,41 +454,45 @@ draw_selected = function(song, x, y, w, h)
gfx.ForceRender() gfx.ForceRender()
end end
draw_songwheel = function(x, y, w, h) draw_challengewheel = function(x, y, w, h)
local offsetX = fifthX / 2 local offsetX = fifthX / 2
local width = math.floor((w / 5) * 4) local width = math.floor((w / 5) * 4)
local height = math.floor((h / wheelSize) * 1.5) local height = math.floor((h / wheelSize) * 1.5)
-- before selected
for i = math.max(selectedIndex - wheelSize / 2, 1), math.max(selectedIndex - 1, 0) do for i = math.max(selectedIndex - wheelSize / 2, 1), math.max(selectedIndex - 1, 0) do
local song = chalwheel.challenges[i] local challenge = chalwheel.challenges[i]
local xpos = x + offsetX + ((selectedIndex - i + ioffset) ^ 2) * 3 local xpos = x + offsetX + ((selectedIndex - i + ioffset) ^ 2) * 3
local offsetY = (selectedIndex - i + ioffset) local offsetY = (selectedIndex - i + ioffset)
* (height - (wheelSize / 2 * ((selectedIndex - i + ioffset) * aspectFloat))) * (height - (wheelSize / 2 * ((selectedIndex - i + ioffset) * aspectFloat)))
local ypos = y + ((h / 2 - height / 2) - offsetY) local ypos = y + ((h / 2 - height / 2) - offsetY)
draw_song(song, xpos, ypos, width, height) draw_challenge(challenge, xpos, ypos, width, height)
end end
-- after selected -- after selected
for i = math.min(selectedIndex + wheelSize / 2, #chalwheel.challenges), selectedIndex + 1, -1 do for i = math.min(selectedIndex + wheelSize / 2, #chalwheel.challenges), selectedIndex + 1, -1 do
local song = chalwheel.challenges[i] local challenge = chalwheel.challenges[i]
local xpos = x + offsetX + ((i - selectedIndex - ioffset) ^ 2) * 2 local xpos = x + offsetX + ((i - selectedIndex - ioffset) ^ 2) * 2
local offsetY = (selectedIndex - i + ioffset) local offsetY = (selectedIndex - i + ioffset)
* (height - (wheelSize / 2 * ((i - selectedIndex - ioffset) * aspectFloat))) * (height - (wheelSize / 2 * ((i - selectedIndex - ioffset) * aspectFloat)))
local ypos = y + ((h / 2 - height / 2) - (selectedIndex - i) - offsetY) local ypos = y + ((h / 2 - height / 2) - (selectedIndex - i) - offsetY)
local alpha = 255 - (selectedIndex - i + ioffset) * 31 local alpha = 255 - (selectedIndex - i + ioffset) * 31
draw_song(song, xpos, ypos, width, height) draw_challenge(challenge, xpos, ypos, width, height)
end end
-- draw selected -- draw selected
local xpos = x + offsetX / 1.2 + ((-ioffset) ^ 2) * 2 local xpos = x + offsetX / 1.2 + ((-ioffset) ^ 2) * 2
local offsetY = (ioffset) * (height - (wheelSize / 2 * ((1) * aspectFloat))) local offsetY = (ioffset) * (height - (wheelSize / 2 * ((1) * aspectFloat)))
local ypos = y + ((h / 2 - height / 2) - (ioffset) - offsetY) local ypos = y + ((h / 2 - height / 2) - (ioffset) - offsetY)
draw_song(chalwheel.challenges[selectedIndex], xpos, ypos, width, height, true) draw_challenge(chalwheel.challenges[selectedIndex], xpos, ypos, width, height, true)
return chalwheel.challenges[selectedIndex] return chalwheel.challenges[selectedIndex]
end end
draw_legend_pane = function(x, y, w, h, obj) draw_legend_pane = function(x, y, w, h, obj)
local xpos = x + 5 local xpos = x + 5
local ypos = y local ypos = y
local imageSize = h local imageSize = h
gfx.BeginPath() gfx.BeginPath()
gfx.TextAlign(gfx.TEXT_ALIGN_MIDDLE + gfx.TEXT_ALIGN_LEFT) gfx.TextAlign(gfx.TEXT_ALIGN_MIDDLE + gfx.TEXT_ALIGN_LEFT)
gfx.ImageRect(x, y, imageSize, imageSize, obj.image, 1, 0) gfx.ImageRect(x, y, imageSize, imageSize, obj.image, 1, 0)
@ -522,7 +534,8 @@ draw_search = function(x, y, w, h)
gfx.Fill() gfx.Fill()
gfx.ForceRender() gfx.ForceRender()
local xpos = x + (searchIndex + soffset) * w local xpos = x + (searchIndex + soffset) * w
gfx.UpdateLabel(searchText, string.format("Search: %s", chalwheel.searchText), 30, 0) gfx.UpdateLabel(searchText, string.format("Search: %s", chalwheel.searchText), 30)
gfx.BeginPath() gfx.BeginPath()
gfx.RoundedRect(xpos, y, w, h, h / 2) gfx.RoundedRect(xpos, y, w, h, h / 2)
gfx.FillColor(30, 30, 30) gfx.FillColor(30, 30, 30)
@ -530,6 +543,7 @@ draw_search = function(x, y, w, h)
gfx.StrokeWidth(1) gfx.StrokeWidth(1)
gfx.Fill() gfx.Fill()
gfx.Stroke() gfx.Stroke()
gfx.BeginPath(); gfx.BeginPath();
gfx.LoadSkinFont("dfmarugoth.ttf"); gfx.LoadSkinFont("dfmarugoth.ttf");
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE); gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE);
@ -541,18 +555,18 @@ render = function(deltaTime)
timer = (timer + deltaTime) timer = (timer + deltaTime)
timer = timer % 2 timer = timer % 2
resx, resy = game.GetResolution(); resx, resy = game.GetResolution();
gfx.BeginPath() gfx.BeginPath()
gfx.ImageRect(0, 0, resx, resy, backgroundImage, 1, 0) gfx.ImageRect(0, 0, resx, resy, backgroundImage, 1, 0)
adjustScreen(resx, resy); adjustScreen(resx, resy);
gfx.BeginPath(); gfx.BeginPath();
gfx.LoadSkinFont("dfmarugoth.ttf"); gfx.LoadSkinFont("dfmarugoth.ttf");
gfx.FontSize(40); gfx.FontSize(40);
gfx.FillColor(255, 255, 255); gfx.FillColor(255, 255, 255);
if chalwheel.challenges == nil then if chalwheel.challenges and chalwheel.challenges[1] then
elseif chalwheel.challenges[1] ~= nil then
-- draw chalwheel and get selected song -- draw chalwheel and get selected song
local song = draw_songwheel(0, 0, fullX, fullY) local song = draw_challengewheel(0, 0, fullX, fullY)
-- render selected song information -- render selected song information
draw_selected(song, 0, 0, fullX, fifthY) draw_selected(song, 0, 0, fullX, fifthY)
end end