diff --git a/src/Leaderboards.hx b/src/Leaderboards.hx index 27b96a57..19908966 100644 --- a/src/Leaderboards.hx +++ b/src/Leaderboards.hx @@ -14,6 +14,12 @@ typedef LBScore = { rewind:Int, } +enum abstract LeaderboardsKind(Int) { + var All; + var Rewind; + var NoRewind; +} + class Leaderboards { static var host = "http://127.0.0.1:7000"; static var game = "Platinum"; @@ -40,10 +46,10 @@ class Leaderboards { }); } - public static function getScores(mission:String, cb:Array->Void) { + public static function getScores(mission:String, kind:LeaderboardsKind, cb:Array->Void) { if (!StringTools.startsWith(mission, "data/")) mission = "data/" + mission; - return Http.get('${host}/api/scores?mission=${StringTools.urlEncode(mission)}&game=${game}', (b) -> { + return Http.get('${host}/api/scores?mission=${StringTools.urlEncode(mission)}&game=${game}&view=${kind}', (b) -> { var s = b.toString(); var scores:Array = Json.parse(s).scores; cb(scores); @@ -61,10 +67,10 @@ class Leaderboards { }); } - public static function watchTopReplay(mission:String, cb:haxe.io.Bytes->Void) { + public static function watchTopReplay(mission:String, kind:LeaderboardsKind, cb:haxe.io.Bytes->Void) { if (!StringTools.startsWith(mission, "data/")) mission = "data/" + mission; - return Http.get('${host}/api/replay?mission=${StringTools.urlEncode(mission)}&game=${game}', (b) -> { + return Http.get('${host}/api/replay?mission=${StringTools.urlEncode(mission)}&game=${game}&view=${kind}', (b) -> { cb(b); }, (e) -> { Console.log("Failed to get replay: " + e); diff --git a/src/gui/PlayMissionGui.hx b/src/gui/PlayMissionGui.hx index c9748d9d..ce4bfb1d 100644 --- a/src/gui/PlayMissionGui.hx +++ b/src/gui/PlayMissionGui.hx @@ -353,11 +353,18 @@ class PlayMissionGui extends GuiImage { pmScoreText.extent = new Vector(235, 14); pmBox.addChild(pmScoreText); + var scoreView:LeaderboardsKind = All; + var showLBs = false; + pmScoreButton = new GuiButton([tmpprevtile, tmpprevtile, tmpprevtile]); pmScoreButton.position = new Vector(438, 282); pmScoreButton.extent = new Vector(240, 39); pmScoreButton.pressedAction = (e) -> { - scoreShowing = !scoreShowing; + if (showLBs) { + scoreView = cast((cast(scoreView, Int) + 1) % 3); + } else { + scoreShowing = !scoreShowing; + } setSelectedFunc(currentSelection); }; pmBox.addChild(pmScoreButton); @@ -822,7 +829,7 @@ class PlayMissionGui extends GuiImage { scoreBox.text.onHyperlink = (url) -> { if (url == "watch") { var currentMission = currentList[currentSelection]; - Leaderboards.watchTopReplay(currentMission.path, (b) -> { + Leaderboards.watchTopReplay(currentMission.path, scoreView, (b) -> { if (b != null) { var replayF = new Replay(""); if (replayF.read(b)) { @@ -882,8 +889,6 @@ class PlayMissionGui extends GuiImage { var lbImgs = loadButtonImages("data/ui/play/lb"); var infoImgs = loadButtonImages("data/ui/play/info"); - var showLBs = false; - var pmLBToggle = new GuiButton(lbImgs); pmLBToggle.position = new Vector(118, 98); pmLBToggle.extent = new Vector(43, 43); @@ -895,8 +900,8 @@ class PlayMissionGui extends GuiImage { @:privateAccess pmLBToggle.anim.frames = infoImgs; } - pmScoreButton.disabled = showLBs; - pmScoreText.text.visible = !showLBs; + // pmScoreButton.disabled = showLBs; + // pmScoreText.text.visible = !showLBs; setSelectedFunc(currentSelection); if (showLBs) { @@ -1041,35 +1046,51 @@ class PlayMissionGui extends GuiImage { setScoreHover = (isHover) -> { var currentMission = currentList[currentSelection]; - pmScoreText.text.dropShadow = { - dx: 1 * Settings.uiScale, - dy: 1 * Settings.uiScale, - alpha: 0.5, - color: 0 - }; - var scoreTextTime = ""; - var scoreData = Settings.getScores(currentMission.path); - if (scoreData.length == 0) { - scoreTextTime = '99:59.999'; - } else { - var topScore = scoreData[0]; - var scoreColor = "#FFFFFF"; - if (topScore.time < currentMission.ultimateTime) { - scoreColor = "#FFCC33"; - } else if (topScore.time < currentMission.goldTime) { - if (currentMission.game == "gold" || currentMission.game.toLowerCase() == "ultra") - scoreColor = "#FFFF00" - else - scoreColor = "#CCCCCC"; + if (!showLBs) { + pmScoreText.text.dropShadow = { + dx: 1 * Settings.uiScale, + dy: 1 * Settings.uiScale, + alpha: 0.5, + color: 0 + }; + var scoreTextTime = ""; + var scoreData = Settings.getScores(currentMission.path); + if (scoreData.length == 0) { + scoreTextTime = '99:59.999'; + } else { + var topScore = scoreData[0]; + var scoreColor = "#FFFFFF"; + if (topScore.time < currentMission.ultimateTime) { + scoreColor = "#FFCC33"; + } else if (topScore.time < currentMission.goldTime) { + if (currentMission.game == "gold" || currentMission.game.toLowerCase() == "ultra") + scoreColor = "#FFFF00" + else + scoreColor = "#CCCCCC"; + } + + scoreTextTime = '${Util.formatTime(topScore.time)}'; } - scoreTextTime = '${Util.formatTime(topScore.time)}'; - } - - if (isHover) { - pmScoreText.text.text = '

${this.scoreShowing ? "Hide" : "Show"} 5 Top Times

'; + if (isHover) { + pmScoreText.text.text = '

${this.scoreShowing ? "Hide" : "Show"} 5 Top Times

'; + } else { + pmScoreText.text.text = '

Best Time: ${scoreTextTime}

'; + } } else { - pmScoreText.text.text = '

Best Time: ${scoreTextTime}

'; + var kindList = ["All Scores", "Rewind Only", "No Rewind"]; + + pmScoreText.text.dropShadow = { + dx: 1 * Settings.uiScale, + dy: 1 * Settings.uiScale, + alpha: 0.5, + color: 0 + }; + if (isHover) { + pmScoreText.text.text = '

Show ${kindList[(cast(scoreView, Int) + 1) % 3]}

'; + } else { + pmScoreText.text.text = '

Showing: ${kindList[cast(scoreView, Int)]}

'; + } } } @@ -1200,7 +1221,7 @@ class PlayMissionGui extends GuiImage { Http.cancel(lbRequest); #end var lTok = lbToken++; - var req = Leaderboards.getScores(currentMission.path, (scoreList) -> { + var req = Leaderboards.getScores(currentMission.path, scoreView, (scoreList) -> { if (lTok + 1 != lbToken || !showLBs) return; var sFmt = [];