aboutsummaryrefslogtreecommitdiff
path: root/source/screens/LeaderBoardState.hx
blob: 67f726ec1c6f3dde07e11061e4a22a7d26abb2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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<Entry> = 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());
	}
}