toggle between different lb categories

This commit is contained in:
RandomityGuy 2024-11-05 01:07:48 +05:30
parent ef51695d15
commit 07f703220c
2 changed files with 64 additions and 37 deletions

View file

@ -14,6 +14,12 @@ typedef LBScore = {
rewind:Int, rewind:Int,
} }
enum abstract LeaderboardsKind(Int) {
var All;
var Rewind;
var NoRewind;
}
class Leaderboards { class Leaderboards {
static var host = "http://127.0.0.1:7000"; static var host = "http://127.0.0.1:7000";
static var game = "Platinum"; static var game = "Platinum";
@ -40,10 +46,10 @@ class Leaderboards {
}); });
} }
public static function getScores(mission:String, cb:Array<LBScore>->Void) { public static function getScores(mission:String, kind:LeaderboardsKind, cb:Array<LBScore>->Void) {
if (!StringTools.startsWith(mission, "data/")) if (!StringTools.startsWith(mission, "data/"))
mission = "data/" + mission; 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 s = b.toString();
var scores:Array<LBScore> = Json.parse(s).scores; var scores:Array<LBScore> = Json.parse(s).scores;
cb(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/")) if (!StringTools.startsWith(mission, "data/"))
mission = "data/" + mission; 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); cb(b);
}, (e) -> { }, (e) -> {
Console.log("Failed to get replay: " + e); Console.log("Failed to get replay: " + e);

View file

@ -353,11 +353,18 @@ class PlayMissionGui extends GuiImage {
pmScoreText.extent = new Vector(235, 14); pmScoreText.extent = new Vector(235, 14);
pmBox.addChild(pmScoreText); pmBox.addChild(pmScoreText);
var scoreView:LeaderboardsKind = All;
var showLBs = false;
pmScoreButton = new GuiButton([tmpprevtile, tmpprevtile, tmpprevtile]); pmScoreButton = new GuiButton([tmpprevtile, tmpprevtile, tmpprevtile]);
pmScoreButton.position = new Vector(438, 282); pmScoreButton.position = new Vector(438, 282);
pmScoreButton.extent = new Vector(240, 39); pmScoreButton.extent = new Vector(240, 39);
pmScoreButton.pressedAction = (e) -> { pmScoreButton.pressedAction = (e) -> {
scoreShowing = !scoreShowing; if (showLBs) {
scoreView = cast((cast(scoreView, Int) + 1) % 3);
} else {
scoreShowing = !scoreShowing;
}
setSelectedFunc(currentSelection); setSelectedFunc(currentSelection);
}; };
pmBox.addChild(pmScoreButton); pmBox.addChild(pmScoreButton);
@ -822,7 +829,7 @@ class PlayMissionGui extends GuiImage {
scoreBox.text.onHyperlink = (url) -> { scoreBox.text.onHyperlink = (url) -> {
if (url == "watch") { if (url == "watch") {
var currentMission = currentList[currentSelection]; var currentMission = currentList[currentSelection];
Leaderboards.watchTopReplay(currentMission.path, (b) -> { Leaderboards.watchTopReplay(currentMission.path, scoreView, (b) -> {
if (b != null) { if (b != null) {
var replayF = new Replay(""); var replayF = new Replay("");
if (replayF.read(b)) { if (replayF.read(b)) {
@ -882,8 +889,6 @@ class PlayMissionGui extends GuiImage {
var lbImgs = loadButtonImages("data/ui/play/lb"); var lbImgs = loadButtonImages("data/ui/play/lb");
var infoImgs = loadButtonImages("data/ui/play/info"); var infoImgs = loadButtonImages("data/ui/play/info");
var showLBs = false;
var pmLBToggle = new GuiButton(lbImgs); var pmLBToggle = new GuiButton(lbImgs);
pmLBToggle.position = new Vector(118, 98); pmLBToggle.position = new Vector(118, 98);
pmLBToggle.extent = new Vector(43, 43); pmLBToggle.extent = new Vector(43, 43);
@ -895,8 +900,8 @@ class PlayMissionGui extends GuiImage {
@:privateAccess pmLBToggle.anim.frames = infoImgs; @:privateAccess pmLBToggle.anim.frames = infoImgs;
} }
pmScoreButton.disabled = showLBs; // pmScoreButton.disabled = showLBs;
pmScoreText.text.visible = !showLBs; // pmScoreText.text.visible = !showLBs;
setSelectedFunc(currentSelection); setSelectedFunc(currentSelection);
if (showLBs) { if (showLBs) {
@ -1041,35 +1046,51 @@ class PlayMissionGui extends GuiImage {
setScoreHover = (isHover) -> { setScoreHover = (isHover) -> {
var currentMission = currentList[currentSelection]; var currentMission = currentList[currentSelection];
pmScoreText.text.dropShadow = { if (!showLBs) {
dx: 1 * Settings.uiScale, pmScoreText.text.dropShadow = {
dy: 1 * Settings.uiScale, dx: 1 * Settings.uiScale,
alpha: 0.5, dy: 1 * Settings.uiScale,
color: 0 alpha: 0.5,
}; color: 0
var scoreTextTime = ""; };
var scoreData = Settings.getScores(currentMission.path); var scoreTextTime = "";
if (scoreData.length == 0) { var scoreData = Settings.getScores(currentMission.path);
scoreTextTime = '<font color="#FFFFFF">99:59.999</font>'; if (scoreData.length == 0) {
} else { scoreTextTime = '<font color="#FFFFFF">99:59.999</font>';
var topScore = scoreData[0]; } else {
var scoreColor = "#FFFFFF"; var topScore = scoreData[0];
if (topScore.time < currentMission.ultimateTime) { var scoreColor = "#FFFFFF";
scoreColor = "#FFCC33"; if (topScore.time < currentMission.ultimateTime) {
} else if (topScore.time < currentMission.goldTime) { scoreColor = "#FFCC33";
if (currentMission.game == "gold" || currentMission.game.toLowerCase() == "ultra") } else if (topScore.time < currentMission.goldTime) {
scoreColor = "#FFFF00" if (currentMission.game == "gold" || currentMission.game.toLowerCase() == "ultra")
else scoreColor = "#FFFF00"
scoreColor = "#CCCCCC"; else
scoreColor = "#CCCCCC";
}
scoreTextTime = '<font color="${scoreColor}">${Util.formatTime(topScore.time)}</font>';
} }
scoreTextTime = '<font color="${scoreColor}">${Util.formatTime(topScore.time)}</font>'; if (isHover) {
} pmScoreText.text.text = '<font color="#DDC1C1" face="MarkerFelt24"><p align="center">${this.scoreShowing ? "Hide" : "Show"} 5 Top Times</p></font>';
} else {
if (isHover) { pmScoreText.text.text = '<font color="#FFE3E3" face="MarkerFelt24"><p align="center">Best Time: ${scoreTextTime}</p></font>';
pmScoreText.text.text = '<font color="#DDC1C1" face="MarkerFelt24"><p align="center">${this.scoreShowing ? "Hide" : "Show"} 5 Top Times</p></font>'; }
} else { } else {
pmScoreText.text.text = '<font color="#FFE3E3" face="MarkerFelt24"><p align="center">Best Time: ${scoreTextTime}</p></font>'; 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 = '<font color="#DDC1C1" face="MarkerFelt24"><p align="center">Show ${kindList[(cast(scoreView, Int) + 1) % 3]}</p></font>';
} else {
pmScoreText.text.text = '<font color="#FFE3E3" face="MarkerFelt24"><p align="center">Showing: ${kindList[cast(scoreView, Int)]}</p></font>';
}
} }
} }
@ -1200,7 +1221,7 @@ class PlayMissionGui extends GuiImage {
Http.cancel(lbRequest); Http.cancel(lbRequest);
#end #end
var lTok = lbToken++; var lTok = lbToken++;
var req = Leaderboards.getScores(currentMission.path, (scoreList) -> { var req = Leaderboards.getScores(currentMission.path, scoreView, (scoreList) -> {
if (lTok + 1 != lbToken || !showLBs) if (lTok + 1 != lbToken || !showLBs)
return; return;
var sFmt = []; var sFmt = [];