+ ir leaderboard to songwheel
This commit is contained in:
parent
c42c5da314
commit
899af3170e
|
@ -103,6 +103,13 @@ game.LoadSkinSample('song_wheel/diff_change.wav');
|
|||
local scoreNumbers = Numbers.load_number_image("score_num")
|
||||
local difficultyNumbers = Numbers.load_number_image("diff_num")
|
||||
|
||||
local LEADERBOARD_PLACE_NAMES = {
|
||||
'1st',
|
||||
'2nd',
|
||||
'3rd',
|
||||
'4th',
|
||||
}
|
||||
|
||||
local songPlateHeight = 172;
|
||||
|
||||
local selectedIndex = 1;
|
||||
|
@ -112,6 +119,9 @@ local jacketCache = {}
|
|||
|
||||
local top50diffs = {}
|
||||
|
||||
local isIrLeaderboardRequested = false -- if false, we will request it after the scroll transition finishes to prevent spamming the API
|
||||
local irLeaderboard = {}
|
||||
|
||||
local transitionScrollScale = 0;
|
||||
local transitionScrollOffsetY = 0;
|
||||
local scrollingUp = false;
|
||||
|
@ -482,8 +492,20 @@ function drawData() -- Draws the song data on the left panel
|
|||
|
||||
-- Scoreboard
|
||||
|
||||
drawLocalLeaderboard(diff)
|
||||
drawIrLeaderboard()
|
||||
|
||||
gfx.FontSize(22)
|
||||
gfx.GlobalAlpha(transitionAfterscrollDataOverlayAlpha);
|
||||
gfx.Text(diff.effector, 270, 1180); -- effected by
|
||||
gfx.Text(diff.illustrator, 270, 1210); -- illustrated by
|
||||
gfx.GlobalAlpha(1);
|
||||
|
||||
end
|
||||
|
||||
function drawLocalLeaderboard(diff)
|
||||
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
|
||||
gfx.FontSize(32)
|
||||
gfx.FontSize(26)
|
||||
|
||||
local scoreBoardX = 75;
|
||||
local scoreBoardY = 1250;
|
||||
|
@ -491,7 +513,7 @@ function drawData() -- Draws the song data on the left panel
|
|||
local sbBarWidth = 336*1.2;
|
||||
local sbBarHeight = 33;
|
||||
|
||||
local sbBarContentLeftX = scoreBoardX + sbBarWidth/2 - 30;
|
||||
local sbBarContentLeftX = scoreBoardX + 80;
|
||||
local sbBarContentRightX = scoreBoardX + sbBarWidth/2 + 30;
|
||||
|
||||
-- Draw the header
|
||||
|
@ -503,27 +525,68 @@ function drawData() -- Draws the song data on the left panel
|
|||
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text("TOP", sbBarContentRightX, scoreBoardY + sbBarHeight/2);
|
||||
gfx.Text("LOCAL TOP", sbBarContentRightX, scoreBoardY + sbBarHeight/2);
|
||||
|
||||
for i = 1, 5, 1 do
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(scoreBoardX, scoreBoardY + i*sbBarHeight, sbBarWidth, sbBarHeight, scoreBoardBarBgImage, 1, 0);
|
||||
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_RIGHT + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text(game.GetSkinSetting("username"), sbBarContentLeftX, scoreBoardY + sbBarHeight/2 + i*sbBarHeight);
|
||||
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text((diff.scores[i]) and diff.scores[i].score or "- - - - - - - -", sbBarContentRightX, scoreBoardY + sbBarHeight/2 + i*sbBarHeight);
|
||||
end
|
||||
end
|
||||
|
||||
gfx.FontSize(22)
|
||||
gfx.GlobalAlpha(transitionAfterscrollDataOverlayAlpha);
|
||||
gfx.Text(diff.effector, 270, 1180); -- effected by
|
||||
gfx.Text(diff.illustrator, 270, 1210); -- illustrated by
|
||||
gfx.GlobalAlpha(1);
|
||||
function drawIrLeaderboard()
|
||||
gfx.LoadSkinFont('Digital-Serial-Bold.ttf')
|
||||
gfx.FontSize(26)
|
||||
|
||||
local scoreBoardX = 75;
|
||||
local scoreBoardY = 1500;
|
||||
|
||||
local sbBarWidth = 336*1.2;
|
||||
local sbBarHeight = 33;
|
||||
|
||||
local sbBarContentLeftX = scoreBoardX + 80;
|
||||
local sbBarContentRightX = scoreBoardX + sbBarWidth/2 + 30;
|
||||
|
||||
-- Draw the header
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(scoreBoardX, scoreBoardY, sbBarWidth, sbBarHeight, scoreBoardBarBgImage, 1, 0);
|
||||
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(205, 1252.5, 800*0.045, 600*0.045, crownImage, 1, 0);
|
||||
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text("IR TOP", scoreBoardX + (sbBarWidth / 2), scoreBoardY + sbBarHeight/2);
|
||||
|
||||
for i = 1, 4, 1 do
|
||||
local irScore = irLeaderboard[i];
|
||||
|
||||
gfx.BeginPath();
|
||||
gfx.ImageRect(scoreBoardX, scoreBoardY + i*sbBarHeight, sbBarWidth, sbBarHeight, scoreBoardBarBgImage, 1, 0);
|
||||
|
||||
if irScore then
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text(LEADERBOARD_PLACE_NAMES[i], sbBarContentLeftX-40, scoreBoardY + sbBarHeight/2 + i*sbBarHeight);
|
||||
|
||||
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
gfx.Text(string.upper(irScore.username), sbBarContentLeftX, scoreBoardY + sbBarHeight/2 + i*sbBarHeight);
|
||||
|
||||
gfx.BeginPath();
|
||||
gfx.Text(string.format("%d", irScore.score), sbBarContentRightX, scoreBoardY + sbBarHeight/2 + i*sbBarHeight);
|
||||
|
||||
local badgeImage = badgeImages[irScore.lamp+1];
|
||||
gfx.BeginPath()
|
||||
gfx.ImageRect(scoreBoardX + sbBarWidth - 50, scoreBoardY + sbBarHeight/2 + i*sbBarHeight - 12.5, 31.6, 27.6, badgeImage, 1, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function drawFilterInfo(deltatime)
|
||||
|
@ -576,6 +639,45 @@ function drawSearch()
|
|||
gfx.Text(songwheel.searchText, desw-200, 30);
|
||||
end
|
||||
|
||||
function refreshIrLeaderboard()
|
||||
if isIrLeaderboardRequested then
|
||||
return
|
||||
end
|
||||
isIrLeaderboardRequested = true;
|
||||
irLeaderboard = {}
|
||||
|
||||
local song = songwheel.songs[selectedIndex];
|
||||
local diff = song and song.difficulties[selectedDifficulty] or false;
|
||||
|
||||
if (not diff) then
|
||||
return;
|
||||
end
|
||||
|
||||
IR.Leaderboard(diff.hash, 'best', 4, onIrLeaderboardFetched)
|
||||
end
|
||||
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
function onIrLeaderboardFetched(res)
|
||||
if res.statusCode == IRData.States.Success then
|
||||
irLeaderboard = res.body;
|
||||
game.Log(dump(irLeaderboard), game.LOGGER_ERROR)
|
||||
else
|
||||
game.Log("IR error " .. res.statusCode, game.LOGGER_ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
function tickTransitions(deltaTime)
|
||||
if transitionScrollScale < 1 then
|
||||
transitionScrollScale = transitionScrollScale + deltaTime / 0.1 -- transition should last for that time in seconds
|
||||
|
@ -779,6 +881,10 @@ render = function (deltaTime)
|
|||
gfx.Fill()
|
||||
|
||||
draw_songwheel((resX - fullX) / 2, 0, fullX, fullY, deltaTime);
|
||||
|
||||
if (transitionScrollScale >= 1) then
|
||||
refreshIrLeaderboard(); -- For explantion, check where isIrLeaderboardRequested is defined
|
||||
end
|
||||
end
|
||||
|
||||
songs_changed = function (withAll)
|
||||
|
@ -837,4 +943,5 @@ set_diff = function(newDiff)
|
|||
end
|
||||
|
||||
selectedDifficulty = newDiff;
|
||||
isIrLeaderboardRequested = false;
|
||||
end;
|
Loading…
Reference in New Issue