From 9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Wed, 22 Sep 2021 10:10:50 +0530 Subject: * Initial Commit * Leaderboard Implementation for dreamlo * FlxSave for Player Data * GUID Generation for Unique User --- source/screens/LeaderBoardState.hx | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 source/screens/LeaderBoardState.hx (limited to 'source/screens/LeaderBoardState.hx') diff --git a/source/screens/LeaderBoardState.hx b/source/screens/LeaderBoardState.hx new file mode 100644 index 0000000..67f726e --- /dev/null +++ b/source/screens/LeaderBoardState.hx @@ -0,0 +1,74 @@ +package screens; + +import flixel.FlxG; +import flixel.FlxState; +import flixel.addons.ui.FlxUIGroup; +import flixel.addons.ui.FlxUIList; +import flixel.addons.ui.FlxUIRegion; +import flixel.addons.ui.FlxUIText; +import flixel.text.FlxText; +import flixel.ui.FlxButton; +import flixel.util.FlxColor; +import shared.PlayerSave; +import shared.ScoreBoard; +import shared.Types.Entry; +import shared.Types.ScoreBoardData; + +class LeaderBoardState extends FlxState +{ + var scoreBoardList:FlxUIList; + var previousState:FlxState; + + public function new() + { + super(); + var scoreLabel:FlxText = new FlxText(FlxG.width / 2 - 50, 10, "Leaderboard", 13); + scoreLabel.borderSize = 1; + scoreLabel.borderColor = FlxColor.PURPLE; + scoreLabel.borderQuality = 1; + scoreLabel.borderStyle = FlxTextBorderStyle.OUTLINE; + scoreBoardList = new FlxUIList(FlxG.width / 2 - 100, 70, [], 300, 300, "More"); + scoreBoardList.loadGraphic(AssetPaths.space_bg__png); + var backButton:FlxButton = new FlxButton(FlxG.width / 2 - 40, 410, "Back", onBackButtonClick); + add(scoreLabel); + add(scoreBoardList); + add(backButton); + getScores(); + } + + override public function create() + { + super.create(); + } + + private function getScores() + { + var scoreboard:ScoreBoard = new ScoreBoard(); + var scoresData:ScoreBoardData = scoreboard.getScores(); + trace(scoresData.dreamlo.leaderboard); + if (scoresData.dreamlo.leaderboard != null) + { + var scores:Array = scoresData.dreamlo.leaderboard.entry; + for (i in 0...400) + { + scores.push(scores[0]); + } + for (score in scores) + { + var widgetGroup:FlxUIGroup = new FlxUIGroup(0, 0); + var nameTxt:FlxUIText = new FlxUIText(0, 0, 100, '${score.text}', 11); + var scoreTxt:FlxUIText = new FlxUIText(100, 0, 100, '${score.score}', 11); + nameTxt.alignment = FlxTextAlign.LEFT; + scoreTxt.alignment = FlxTextAlign.RIGHT; + widgetGroup.add(nameTxt); + widgetGroup.add(scoreTxt); + scoreBoardList.add(widgetGroup); + } + } + } + + private function onBackButtonClick() + { + FlxG.switchState(new MenuState()); + } +} -- cgit v1.2.3