Skip to content

Commit

Permalink
First attempt at a gameplay leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Oct 6, 2018
1 parent 57fd70e commit aa26758
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local t = Def.ActorFrame {}
t[#t + 1] = LoadActor("WifeJudgmentSpotting")
t[#t + 1] = LoadActor("titlesplash")
t[#t + 1] = LoadActor("leaderboard")
if GAMESTATE:GetPlayerState(PLAYER_1):GetPlayerController() == "PlayerController_Replay" then
t[#t + 1] = LoadActor("replayscrolling")
end
Expand Down
154 changes: 154 additions & 0 deletions Themes/Til Death/BGAnimations/ScreenGameplay overlay/leaderboard.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
local t =
Widg.Container {
y = SCREEN_HEIGHT / 10
}
local leaderboardEnabled = playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).leaderboardEnabled
if not leaderboardEnabled then
return t
end
local CRITERIA = "GetWifeScore"
local NUM_ENTRIES = 5
local ENTRY_HEIGHT = 35
local WIDTH = SCREEN_WIDTH * 0.3

if not DLMAN:GetCurrentRateFilter() then
DLMAN:ToggleRateFilter()
end
local onlineScores = DLMAN:RequestChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey())
local sortFunction = function(h1, h2)
return h1[CRITERIA](h1) > h2[CRITERIA](h2)
end
table.sort(onlineScores, sortFunction)
local curScore
curScore = {
GetDisplayName = function()
return DLMAN:GetUsername()
end,
GetWifeGrade = function()
return curScore.curGrade
end,
GetWifeScore = function()
return curScore.curWifeScore
end,
GetSkillsetSSR = function()
return -1
end,
GetJudgmentString = function()
return ""
end
}
curScore.curWifeScore = 0
curScore.curGrade = "Grade_Tier02"
local scoreboard = {}
for i = 1, NUM_ENTRIES do
scoreboard[i] = i == NUM_ENTRIES and curScore or onlineScores[i]
end

local entryActors = {}
for i = 1, NUM_ENTRIES do
entryActors[i] = {}
end
function scoreEntry(i)
local entryActor
local entry =
Widg.Container {
x = 20,
y = (i - 1) * ENTRY_HEIGHT * 1.3,
onInit = function(self)
entryActor = self
end
}
entry:add(
Widg.Rectangle {
width = WIDTH,
height = ENTRY_HEIGHT,
color = getLeaderboardColor("background"),
halign = 0.5
}
)
local labelContainer =
Widg.Container {
x = 60
}
entry:add(labelContainer)
local y
local addLabel = function(name, fn, x, y, valign, halign)
valign = valign or 1
halign = halign or 1
y = y or 0
labelContainer:add(
Widg.Label {
onInit = function(self)
entryActors[i][name] = self
self.updateLabel = function(hs)
fn(self, hs)
end
fn(self, scoreboard[i])
end,
halign = 0,
scale = 0.4,
x = (x - WIDTH / 2) * 0.4,
y = 10 + y,
color = getLeaderboardColor("text")
}
)
end
addLabel(
"rank",
function(self, hs)
self:settext(tostring(i))
end,
5,
ENTRY_HEIGHT / 2 - 10
)
addLabel(
"ssr",
function(self, hs)
local ssr = hs:GetSkillsetSSR("Overall")
if ssr < 0 then
self:settext("")
else
self:settextf("%.2f", ssr):diffuse(byMSD(ssr))
end
end,
40
)
addLabel(
"name",
function(self, hs)
self:settext(hs:GetDisplayName())
end,
140
)
--WIDTH - 84
addLabel(
"wife",
function(self, hs)
self:settextf("%05.2f%%", hs:GetWifeScore() * 100):diffuse(byGrade(hs:GetWifeGrade()))
end,
2 * WIDTH - 20
)
addLabel(
"judges",
function(self, hs)
self:settext(hs:GetJudgmentString())
end,
WIDTH,
ENTRY_HEIGHT / 2
)
return entry
end
for i = 1, NUM_ENTRIES do
t[#t + 1] = scoreEntry(i)
end

t.JudgmentMessageCommand = function(self, params)
table.sort(scoreboard, sortFunction)
for i, entry in ipairs(entryActors) do
for name, label in pairs(entry) do
label.updateLabel(scoreboard[i])
end
end
end

return t
186 changes: 9 additions & 177 deletions Themes/Til Death/BGAnimations/superscoreboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ local filts = {"All Rates", "Current Rate"}
local topornah = {"Top Scores", "All Scores"}

local scoretable
local scoretablegetter = function()
return scoretable
end

local o =
Def.ActorFrame {
Name = "ScoreDisplay",
Expand All @@ -107,7 +111,7 @@ local o =
self:queuecommand("ChartLeaderboardUpdate")
end,
ChartLeaderboardUpdateMessageCommand = function(self)
scoretable = DLMAN:RequestChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey(),getIsGlobalRanking())
scoretable = DLMAN:RequestChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey(), getIsGlobalRanking())
ind = 0
self:playcommand("Update")
end,
Expand Down Expand Up @@ -154,7 +158,8 @@ local o =
collapsed = true
self:diffusealpha(0.8)

if -- a generic bounds check function that snaps an actor onto the screen or within specified coordinates should be added as an actor member, ie, not this -mina
if
-- a generic bounds check function that snaps an actor onto the screen or within specified coordinates should be added as an actor member, ie, not this -mina
FILTERMAN:grabposx("ScoreDisplay") <= 10 or FILTERMAN:grabposy("ScoreDisplay") <= 45 or
FILTERMAN:grabposx("ScoreDisplay") >= SCREEN_WIDTH - 60 or
FILTERMAN:grabposy("ScoreDisplay") >= SCREEN_HEIGHT - 45
Expand Down Expand Up @@ -234,7 +239,7 @@ local o =
self:diffusealpha(0):zoomto(400, 400)
local nx = INPUTFILTER:GetMouseX() - width / 2
local ny = INPUTFILTER:GetMouseY() - self:GetY()
self:GetParent():SaveXY(nx, ny) -- this can probably be wrapped for convenience -mina
self:GetParent():SaveXY(nx, ny) -- this can probably be wrapped for convenience -mina
self:GetParent():LoadXY()
else
self:zoomto(dwidth / 2, pdh / 2)
Expand Down Expand Up @@ -298,181 +303,8 @@ local o =
}
}

local function makeScoreDisplay(i)
local hs

local o =
Def.ActorFrame {
InitCommand = function(self)
self:y(packspaceY * i + headeroff)
if i > numscores then
self:visible(false)
end
end,
UpdateCommand = function(self)
hs = scoretable[(i + ind)]
if hs and i <= numscores then
self:queuecommand("Display")
self:visible(true)
else
self:visible(false)
end
end,
Def.Quad {
InitCommand = function(self)
self:x(offx):zoomto(dwidth, pdh):halign(0)
end,
DisplayCommand = function(self)
self:diffuse(color("#111111CC"))
end,
HighlightCommand = function(self)
if isOver(self) and collapsed then
self:diffusealpha(1)
else
self:diffusealpha(0.6)
end
end
},
LoadFont("Common normal") ..
{
--rank
InitCommand = function(self)
self:x(c0x):zoom(tzoom):halign(0):valign(0)
if collapsed then
self:x(c0x):zoom(tzoom):halign(0):valign(0.5)
end
end,
DisplayCommand = function(self)
self:settextf("%i.", i + ind)
end
},
LoadFont("Common normal") ..
{
--ssr
InitCommand = function(self)
self:x(c2x - c1x + offx):zoom(tzoom + 0.05):halign(0.5):valign(1)
if collapsed then
self:x(46):zoom(tzoom + 0.15):halign(0.5):valign(0.5):maxwidth(20 / tzoom)
end
end,
DisplayCommand = function(self)
local ssr = hs:GetSkillsetSSR("Overall")
self:settextf("%.2f", ssr):diffuse(byMSD(ssr))
end
},
LoadFont("Common normal") ..
{
--rate
InitCommand = function(self)
self:x(c2x - c1x + offx):zoom(tzoom - 0.05):halign(0.5):valign(0):addy(row2yoff)
if collapsed then
self:x(c4x - 14):zoom(tzoom):halign(1):valign(0.5):addy(-row2yoff):maxwidth(30 / tzoom)
end
end,
DisplayCommand = function(self)
local ratestring = string.format("%.2f", hs:GetMusicRate()):gsub("%.?0$", "") .. "x"
self:settext(ratestring)
end,
ExpandCommand = function(self)
self:addy(-row2yoff)
end
},
LoadFont("Common normal") ..
{
--name
InitCommand = function(self)
self:x(c2x):zoom(tzoom + 0.1):maxwidth((c3x - c2x - capWideScale(10, 40)) / tzoom):halign(0):valign(1)
if collapsed then
self:x(c2x + 10):maxwidth(60 / tzoom):zoom(tzoom + 0.2):valign(0.5)
end
end,
DisplayCommand = function(self)
self:settext(hs:GetDisplayName())
if hs:GetChordCohesion() then
self:diffuse(color("#F0EEA6"))
else
self:diffuse(getMainColor("positive"))
end
end,
HighlightCommand = function(self)
highlightIfOver(self)
end,
MouseLeftClickMessageCommand = function(self)
if isOver(self) then
local urlstringyo = "https://etternaonline.com/user/" .. hs:GetDisplayName()
GAMESTATE:ApplyGameCommand("urlnoexit," .. urlstringyo)
end
end
},
LoadFont("Common normal") ..
{
--judgments
InitCommand = function(self)
if not collapsed then
self:x(c2x):zoom(tzoom - 0.05):halign(0):valign(0):maxwidth(width / 2 / tzoom):addy(row2yoff)
end
end,
DisplayCommand = function(self)
self:settext(hs:GetJudgmentString())
if hs:GetChordCohesion() then
self:diffuse(color("#F0EEA6"))
else
self:diffuse(getMainColor("positive"))
end
end,
HighlightCommand = function(self)
highlightIfOver(self)
end,
MouseLeftClickMessageCommand = function(self)
if isOver(self) then
local urlstringyo = "https://etternaonline.com/score/view/" .. hs:GetScoreid() .. hs:GetUserid()
GAMESTATE:ApplyGameCommand("urlnoexit," .. urlstringyo)
end
end,
CollapseCommand = function(self)
self:visible(false)
end,
ExpandCommand = function(self)
self:visible(true):addy(-row2yoff)
end
},
LoadFont("Common normal") ..
{
--percent
InitCommand = function(self)
self:x(c5x):zoom(tzoom + 0.15):halign(1):valign(1)
if collapsed then
self:x(c5x):zoom(tzoom + 0.15):halign(1):valign(0.5):maxwidth(30 / tzoom)
end
end,
DisplayCommand = function(self)
self:settextf("%05.2f%%", hs:GetWifeScore() * 10000 / 100):diffuse(byGrade(hs:GetWifeGrade()))
end
},
LoadFont("Common normal") ..
{
--date
InitCommand = function(self)
if not collapsed then
self:x(c5x):zoom(tzoom - 0.05):halign(1):valign(0):maxwidth(width / 4 / tzoom):addy(row2yoff)
end
end,
DisplayCommand = function(self)
self:settext(hs:GetDate())
end,
CollapseCommand = function(self)
self:visible(false)
end,
ExpandCommand = function(self)
self:visible(true):addy(-row2yoff)
end
}
}
return o
end

for i = 1, numscores do
o[#o + 1] = makeScoreDisplay(i)
o[#o + 1] = Scores.makeDisplay(i, scoretablegetter)
end

return o
Loading

0 comments on commit aa26758

Please sign in to comment.