Skip to content

Commit

Permalink
Add replaydata to online leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Feb 12, 2018
1 parent 41f971e commit 74c6257
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- if score is ever nil we done goofed way before this screen is ever loaded -mina
local score = getOnlineScoreForPlot()
local replayData = score.replaydata

local tst = { 1.50,1.33,1.16,1.00,0.84,0.66,0.50,0.33,0.20 }
local plotWidth, plotHeight = SCREEN_WIDTH,SCREEN_WIDTH*0.3
local plotX, plotY = SCREEN_CENTER_X, SCREEN_CENTER_Y
local dotDims, plotMargin = 2, 4
local judge = GetTimingDifficulty()
local maxOffset = math.max(180, 180*tst[judge])

local o = Def.ActorFrame{
InitCommand=function(self)
self:xy(plotX,plotY)
end,
CodeMessageCommand=function(self,params)
if params.Name == "PlotCancel" or params.Name == "PlotExit" or params.Name == "PlotThickens" or params.Name == "PlotTwist" or params.Name == "StarPlot64" or params.Name == "SheriffOfPlottingham" then
SCREENMAN:GetTopScreen():Cancel()
end
if params.Name == "PrevJudge" and judge > 1 then
judge = judge - 1
elseif params.Name == "NextJudge" and judge < 9 then
judge = judge + 1
end
maxOffset = math.max(180, 180*tst[judge])
MESSAGEMAN:Broadcast("JudgeDisplayChanged")
end
}

local td = GAMESTATE:GetCurrentSteps(PLAYER_1):GetTimingData()
local finalSecond = GAMESTATE:GetCurrentSong(PLAYER_1):GetLastSecond()

local function fitX(x) -- Scale time values to fit within plot width.
return x/finalSecond*plotWidth - plotWidth/2
end

local function fitY(y) -- Scale offset values to fit within plot height
return -1*y/maxOffset*plotHeight/2
end

local function plotOffset(nr,dv)
if dv == 1000 then -- 1000 denotes a miss for which we use a different marker
return Def.Quad{
InitCommand=function(self)
self:xy(fitX(nr),fitY(math.max(184, tst[judge]*184))):zoomto(dotDims,dotDims):diffuse(offsetToJudgeColor(dv/1000)):valign(0)
end
}
end
return Def.Quad{
InitCommand=function(self)
self:xy(fitX(nr),fitY(dv)):zoomto(dotDims,dotDims):diffuse(offsetToJudgeColor(dv/1000))
end,
JudgeDisplayChangedMessageCommand=function(self)
local pos = fitY(dv)
if math.abs(pos) > plotHeight/2 then
self:y(fitY(math.max(184, tst[judge]*184)))
else
self:y(pos)
end
self:diffuse(offsetToJudgeColor(dv/1000, tst[judge]))
end
}
end

-- Center Bar
o[#o+1] = Def.Quad{InitCommand=function(self)
self:zoomto(plotWidth+plotMargin,1):diffuse(byJudgment("TapNoteScore_W1"))
end}
local fantabars = {22.5, 45, 90, 135}
local bantafars = {"TapNoteScore_W2", "TapNoteScore_W3", "TapNoteScore_W4", "TapNoteScore_W5"}
for i=1, #fantabars do
o[#o+1] = Def.Quad{InitCommand=function(self)
self:y( fitY(tst[judge]*fantabars[i])): zoomto(plotWidth+plotMargin,1):diffuse(byJudgment(bantafars[i]))
end}
o[#o+1] = Def.Quad{InitCommand=function(self)
self:y( fitY(-tst[judge]*fantabars[i])): zoomto(plotWidth+plotMargin,1):diffuse(byJudgment(bantafars[i]))
end}
end
-- Background
o[#o+1] = Def.Quad{InitCommand=function(self)
self:zoomto(plotWidth+plotMargin,plotHeight+plotMargin):diffuse(color("0.05,0.05,0.05,0.05")):diffusealpha(0.95)
end}
-- Convert noterows to timestamps and plot dots
for i=1,#replayData do
o[#o+1] = plotOffset(replayData[i][1], replayData[i][2])
end

-- Early/Late markers
o[#o+1] = LoadFont("Common Normal")..{
InitCommand=function(self)
self:xy(-plotWidth/2,-plotHeight/2+2):settextf("Late (+%ims)", maxOffset):zoom(0.35):halign(0):valign(0)
end,
JudgeDisplayChangedMessageCommand=function(self)
self:settextf("Late (+%ims)", maxOffset)
end
}
o[#o+1] = LoadFont("Common Normal")..{
InitCommand=function(self)
self:xy(-plotWidth/2,plotHeight/2-2):settextf("Early (-%ims)", maxOffset):zoom(0.35):halign(0):valign(1)
end,
JudgeDisplayChangedMessageCommand=function(self)
self:settextf("Early (-%ims)", maxOffset)
end
}

return o
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ local offsetX = 10
local offsetY = 30
local netScoresPerPage = 5
local netScoresCurrentPage = 1
local netScores = {}
local nestedTabButtonWidth = 50
local nestedTabButtonHeight = offsetY*2/3
local netPageButtonWidth = 40
Expand Down Expand Up @@ -519,38 +518,18 @@ local netscoreframeWidth = capWideScale(get43size(300),300)
local netscorespacing = 34
local netscoreframex = capWideScale(get43size(70),70)
local netscoreframey = offsetY+netscorespacing/2+capWideScale(get43size(70),70)
function updateNetScores(self)
if not (netScoresCurrentPage < math.ceil(DLMAN:GetTopChartScoreCount(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey())/netScoresPerPage)) then
netScoresCurrentPage = 1
end
MESSAGEMAN:Broadcast("NetScoreUpdate")
end
local netTab = Def.ActorFrame {
SetCommand = function(self)
netScores = {}
local steps = GAMESTATE:GetCurrentSteps(PLAYER_1)
if steps and GAMESTATE:GetCurrentSong() then
local ck = GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey()
for i=1,DLMAN:GetTopChartScoreCount(ck) do
netScores[i] = DLMAN:GetTopChartScore(ck, i)
end
end
if not (netScoresCurrentPage < math.ceil(#netScores/netScoresPerPage)) then
netScoresCurrentPage = 1
end
MESSAGEMAN:Broadcast("NetScoreUpdate")
end,
ChartLeaderboardUpdateCommand = function(self)
self:queuecommand("Set")
end,
ChartLeaderboardUpdateMessageCommand = function(self)
self:queuecommand("Set")
updateNetScores(self)
end,
PlayerJoinedMessageCommand=function(self)
self:queuecommand("Set")
end,
CurrentSongChangedMessageCommand=function(self)
self:queuecommand("Set")
end,
CurrentStepsP1ChangedMessageCommand=function(self)
self:queuecommand("Set")
end,
CurrentStepsP2ChangedMessageCommand=function(self)
self:queuecommand("Set")
CurrentStepsP1ChangedMessageCommand=function(self)
updateNetScores(self)
end,
VisibilityCommand=function(self)
self:visible(nestedTab == 2)
Expand All @@ -576,7 +555,7 @@ local netTab = Def.ActorFrame {
if netScoresCurrentPage > 1 then
netScoresCurrentPage = netScoresCurrentPage - 1
else
netScoresCurrentPage = math.ceil(#netScores/netScoresPerPage)
netScoresCurrentPage = math.ceil(DLMAN:GetTopChartScoreCount(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey())/netScoresPerPage)
end
MESSAGEMAN:Broadcast("NetScoreUpdate")
end
Expand All @@ -602,7 +581,7 @@ local netTab = Def.ActorFrame {
end,
MouseLeftClickMessageCommand=function(self)
if ButtonActive(self) and update and nestedTab == 2 then
if netScoresCurrentPage < math.ceil(#netScores/netScoresPerPage) then
if netScoresCurrentPage < math.ceil(DLMAN:GetTopChartScoreCount(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey())/netScoresPerPage) then
netScoresCurrentPage = netScoresCurrentPage + 1
else
netScoresCurrentPage = 1
Expand All @@ -623,31 +602,40 @@ local netTab = Def.ActorFrame {
}
}
local function netscoreitem(drawindex)
local tmpScore
local index = drawindex
local t = Def.ActorFrame {
Name="scoreItem"..tostring(i),
SetCommand=function(self)
self:visible(nestedTab == 2 and netScores ~= nil and netScores[drawindex + (netScoresCurrentPage-1)*netScoresPerPage] ~= nil)
end,
NetScoreUpdateMessageCommand=function(self)
self:queuecommand("Set")
index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
tmpScore = DLMAN:GetTopChartScore(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey(), index)
self:visible(nestedTab == 2 and tmpScore ~= nil)
end,
NestedTabChangedMessageCommand=function(self)
self:queuecommand("Set")
self:visible(nestedTab == 2 and tmpScore ~= nil)
end,
--The main quad
Def.Quad{
InitCommand=function(self)
self:xy(netscoreframex,netscoreframey+(drawindex*netscorespacing)):zoomto(netscoreframeWidth,30):halign(0):valign(0):diffuse(color("#444444")):diffusealpha(1)
end,
NetScoreUpdateMessageCommand=function(self)
self:diffuse(tmpScore and tmpScore.replaydata and color("#666666") or color("#444444"))
end,
MouseLeftClickMessageCommand=function(self)
if ButtonActive(self) and update and nestedTab == 2 and tmpScore and tmpScore.replaydata then
setOnlineScoreForPlot(tmpScore)
SCREENMAN:AddNewScreenToTop("ScreenOnlineScoreTabOffsetPlot")
end
end
},
--rank
LoadFont("Common normal")..{
InitCommand=function(self)
self:xy(netscoreframex-8,netscoreframey+netscorespacing/2+(drawindex*netscorespacing)-2):zoom(0.35)
end,
SetCommand=function(self)
local index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
if netScores[index] then
if tmpScore then
self:settext(index)
else
self:settext("")
Expand All @@ -667,9 +655,8 @@ local function netscoreitem(drawindex)
self:xy(netscoreframex+10,netscoreframey+10+(drawindex*netscorespacing)+4):zoom(0.35):halign(0):maxwidth((netscoreframeWidth-15)/0.35)
end,
SetCommand=function(self)
local index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
if netScores[index] then
self:settext(netScores[index].modifiers)
if tmpScore then
self:settext(tmpScore.modifiers)
else
self:settext("")
end
Expand All @@ -688,8 +675,7 @@ local function netscoreitem(drawindex)
self:xy(netscoreframex+130+capWideScale(get43size(0),50),netscoreframey+2+(drawindex*netscorespacing)):zoom(0.35):halign(0.5):maxwidth((netscoreframeWidth-15)/0.35)
end,
SetCommand=function(self)
local index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
if netScores[index] then
if tmpScore then
--self:settext(calcGradeFromWife(netScores[index].wife))
else
self:settext("")
Expand All @@ -709,17 +695,16 @@ local function netscoreitem(drawindex)
self:xy(netscoreframex+10,netscoreframey+(drawindex*netscorespacing)+4):zoom(0.35):halign(0):maxwidth((netscoreframeWidth-15)/0.35)
end,
SetCommand=function(self)
local index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
if netScores[index] then
if tmpScore then
self:settextf("%05.5f%% (Wife) %d / %d / %d / %d / %d / %d x%d",
netScores[index].wife*10000/100,
netScores[index].marvelous,
netScores[index].perfect,
netScores[index].great,
netScores[index].good,
netScores[index].bad,
netScores[index].miss,
netScores[index].maxcombo)
tmpScore.wife*10000/100,
tmpScore.marvelous,
tmpScore.perfect,
tmpScore.great,
tmpScore.good,
tmpScore.bad,
tmpScore.miss,
tmpScore.maxcombo)
else
self:settext("")
end
Expand All @@ -739,9 +724,8 @@ local function netscoreitem(drawindex)
self:xy(netscoreframex+10,netscoreframey+20+(drawindex*netscorespacing)+4):zoom(0.35):halign(0)
end,
SetCommand=function(self)
local index = drawindex + (netScoresCurrentPage-1)*netScoresPerPage
if netScores[index] then
self:settext(netScores[index].datetime.." "..netScores[index].username)
if tmpScore then
self:settext(tmpScore.datetime.." "..tmpScore.username)
else
self:settext("")
end
Expand Down
4 changes: 4 additions & 0 deletions Themes/Til Death/Scripts/Scores.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ local migsWeight = { -- Score Weights for MIGS score
local ScoreForPlot = nil
function setScoreForPlot(hs) ScoreForPlot = hs end
function getScoreForPlot() return ScoreForPlot end
--Same as above for online scores
local NetScoreForPlot = nil
function setOnlineScoreForPlot(hs) NetScoreForPlot = hs end
function getOnlineScoreForPlot() return NetScoreForPlot end



Expand Down
4 changes: 4 additions & 0 deletions Themes/Til Death/metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ CodePlotTwist="MenuRight"
CodeStarPlot64="MenuUp"
CodeSheriffOfPlottingham="MenuDown"


[ScreenOnlineScoreTabOffsetPlot]
Fallback="ScreenScoreTabOffsetPlot"

[ScreenColorChange]
Class="ScreenWithMenuElements"
Fallback="ScreenWithMenuElements"
Expand Down
Loading

0 comments on commit 74c6257

Please sign in to comment.