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()); } }