summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/HighscoreTable.cs
blob: fbfdc4c02ccb18e5b5643a114d526f651f2d739d (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Collections.Generic;
using Steamworks;
using UnityEngine;

public class HighscoreTable : MonoBehaviour
{
	private ScoreTag[] scoreTags = new ScoreTag[0];

	private string currentHighscoreTableToCall = "";

	public Transform scoreTagParent;

	public GameObject loading;

	public GameObject notConnectedToSteam;

	public GameObject noScore;

	public GameObject noFriends;

	private bool subscribedToSteamManager;

	public void SetAndDownloadHighscoreTable(string _highscoreTableName)
	{
		noScore.SetActive(value: false);
		noFriends.SetActive(value: false);
		currentHighscoreTableToCall = _highscoreTableName;
		scoreTags = new ScoreTag[scoreTagParent.childCount];
		for (int i = 0; i < scoreTagParent.childCount; i++)
		{
			scoreTags[i] = scoreTagParent.GetChild(i).GetComponent<ScoreTag>();
			scoreTagParent.GetChild(i).gameObject.SetActive(value: false);
		}
		if (SteamManager.Initialized)
		{
			SubscribeToSteamManger();
			SteamManager.Instance.DownloadFriendsHighscores(currentHighscoreTableToCall);
			loading.SetActive(value: true);
			notConnectedToSteam.SetActive(value: false);
		}
		else
		{
			loading.SetActive(value: false);
			notConnectedToSteam.SetActive(value: true);
		}
	}

	private void OnEnable()
	{
		SetAndDownloadHighscoreTable(LevelInteractor.lastActivatedLevelInteractor.sceneName);
	}

	private void SubscribeToSteamManger()
	{
		if (!subscribedToSteamManager)
		{
			SteamManager.Instance.OnLeaderboardDownloadCallbackComplete.AddListener(RefreshUI);
			subscribedToSteamManager = true;
		}
	}

	private void RefreshUI()
	{
		for (int i = 0; i < scoreTags.Length; i++)
		{
			scoreTags[i].gameObject.SetActive(value: false);
		}
		List<SteamManager.LeaderboardEntry> lastDownloadedLeaderboardEntires = SteamManager.Instance.lastDownloadedLeaderboardEntires;
		if (lastDownloadedLeaderboardEntires.Count > 0)
		{
			loading.SetActive(value: false);
			notConnectedToSteam.SetActive(value: false);
			bool flag = false;
			foreach (SteamManager.LeaderboardEntry item in lastDownloadedLeaderboardEntires)
			{
				if (item.username == SteamFriends.GetPersonaName())
				{
					flag = true;
					break;
				}
			}
			noScore.SetActive(!flag);
			noFriends.SetActive(lastDownloadedLeaderboardEntires.Count == 1 && flag);
		}
		else
		{
			loading.SetActive(value: false);
			notConnectedToSteam.SetActive(value: false);
			noScore.SetActive(value: true);
			noFriends.SetActive(value: true);
		}
		for (int j = 0; j < lastDownloadedLeaderboardEntires.Count && j <= scoreTags.Length - 1; j++)
		{
			bool isPlayer = lastDownloadedLeaderboardEntires[j].username == SteamFriends.GetPersonaName();
			scoreTags[j].gameObject.SetActive(value: true);
			scoreTags[j].SetNameAndScore(lastDownloadedLeaderboardEntires[j].username, lastDownloadedLeaderboardEntires[j].score, j + 1, isPlayer);
		}
	}
}