189 lines
6.4 KiB
C#
189 lines
6.4 KiB
C#
using System.Collections.Generic;
|
|
using CurvedUI;
|
|
using Steamworks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LeaderboardGUI : MonoBehaviour
|
|
{
|
|
public LeaderboardWidget widgetPrefab;
|
|
|
|
public Transform widgetsParent;
|
|
|
|
public ScrollRect scrollWindow;
|
|
|
|
public float scrollWidgetsOffset = 100f;
|
|
|
|
private Vector2 scrollParentStartPos = Vector2.zero;
|
|
|
|
public bool sortList;
|
|
|
|
[HideInInspector]
|
|
public bool isVisible;
|
|
|
|
[HideInInspector]
|
|
public LeaderboardsManager leaderboardsManager;
|
|
|
|
[HideInInspector]
|
|
public List<LeaderboardWidget> widgetsList = new List<LeaderboardWidget>();
|
|
|
|
public LeaderboardWidget myWidget;
|
|
|
|
public Text header;
|
|
|
|
public Text sandboxMessage;
|
|
|
|
[Space(10f)]
|
|
public List<Image> sortBackgrounds = new List<Image>();
|
|
|
|
public List<Text> sortHeaders = new List<Text>();
|
|
|
|
public Color sortHeaderColor = Color.white;
|
|
|
|
public LeaderboardsManager.LeaderboardType currentLeaderboardType;
|
|
|
|
public string currentLeaderboardFishery = string.Empty;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
for (int i = 0; i < sortBackgrounds.Count; i++)
|
|
{
|
|
sortBackgrounds[i].enabled = false;
|
|
sortHeaders[i].color = Color.white;
|
|
}
|
|
isVisible = true;
|
|
myWidget.RefreshEmptyWidget();
|
|
leaderboardsManager = LeaderboardsManager.Instance;
|
|
leaderboardsManager.leaderboardGUI = this;
|
|
if (currentLeaderboardFishery == string.Empty)
|
|
{
|
|
currentLeaderboardFishery = ".MAIN.";
|
|
}
|
|
header.text = Utilities.GetTranslation("GUI_HEADERS/LEADERBOARDS");
|
|
sandboxMessage.gameObject.SetActive(GlobalSettings.Instance.playerSettings.IsSandbox());
|
|
if ((bool)leaderboardsManager && (int)leaderboardsManager.currentServerYear != -1 && (int)leaderboardsManager.currentServerMonth != -1)
|
|
{
|
|
Text text = header;
|
|
string text2 = text.text;
|
|
text.text = text2 + " - " + leaderboardsManager.currentServerYear.ToString() + "." + leaderboardsManager.currentServerMonth.ToString("D2");
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
foreach (LeaderboardWidget widgets in widgetsList)
|
|
{
|
|
Object.Destroy(widgets.gameObject);
|
|
}
|
|
widgetsList.Clear();
|
|
isVisible = false;
|
|
}
|
|
|
|
public void FindLeaderboard()
|
|
{
|
|
if (GlobalSettings.Instance.playerSettings.IsSandbox())
|
|
{
|
|
return;
|
|
}
|
|
leaderboardsManager = LeaderboardsManager.Instance;
|
|
if (leaderboardsManager == null || leaderboardsManager.GetCurrentLeaderboardSettings(currentLeaderboardType, currentLeaderboardFishery) == null)
|
|
{
|
|
return;
|
|
}
|
|
leaderboardsManager.leaderboardGUI = this;
|
|
foreach (LeaderboardWidget widgets in widgetsList)
|
|
{
|
|
Object.Destroy(widgets.gameObject);
|
|
}
|
|
widgetsList.Clear();
|
|
bool flag = false;
|
|
if (leaderboardsManager.GetCurrentLeaderboardSettings(currentLeaderboardType, currentLeaderboardFishery).leaderboardHandle.m_SteamLeaderboard == 0)
|
|
{
|
|
leaderboardsManager.FindLeaderboard(currentLeaderboardType, currentLeaderboardFishery);
|
|
}
|
|
else
|
|
{
|
|
leaderboardsManager.UploadScore(currentLeaderboardType, currentLeaderboardFishery);
|
|
}
|
|
}
|
|
|
|
public void Refresh(LeaderboardSettings leaderboardSettings)
|
|
{
|
|
if (!SteamManager.Initialized)
|
|
{
|
|
return;
|
|
}
|
|
foreach (LeaderboardWidget widgets in widgetsList)
|
|
{
|
|
Object.Destroy(widgets.gameObject);
|
|
}
|
|
widgetsList.Clear();
|
|
int num = 20;
|
|
int[] array = new int[7];
|
|
int num2 = -1;
|
|
int num3 = 0;
|
|
string empty = string.Empty;
|
|
ulong num4 = 0uL;
|
|
for (int i = 0; i < leaderboardSettings.leaderboardEntriesCount; i++)
|
|
{
|
|
SteamUserStats.GetDownloadedLeaderboardEntry(leaderboardSettings.scoresDownloaded_t.m_hSteamLeaderboardEntries, i, out leaderboardSettings.leaderboardEntries[i], array, array.Length);
|
|
LeaderboardEntry_t leaderboardEntry_t = leaderboardSettings.leaderboardEntries[i];
|
|
num4 = leaderboardEntry_t.m_steamIDUser.m_SteamID;
|
|
empty = SteamFriends.GetFriendPersonaName(leaderboardEntry_t.m_steamIDUser);
|
|
if (num2 == -1)
|
|
{
|
|
num2 = leaderboardSettings.leaderboardMyEntry.m_nGlobalRank;
|
|
}
|
|
if (GlobalSettings.Instance.CheckCheatSteamID(leaderboardEntry_t.m_steamIDUser.m_SteamID) || !GlobalSettings.Instance.playerSettings.CheckStatsIntegrity(currentLeaderboardType, leaderboardSettings.fisheryName, leaderboardEntry_t.m_nScore, array))
|
|
{
|
|
Debug.Log("LeaderboardLoad CheatPlayer: " + SteamFriends.GetFriendPersonaName(leaderboardEntry_t.m_steamIDUser) + " " + leaderboardEntry_t.m_steamIDUser.m_SteamID);
|
|
continue;
|
|
}
|
|
LeaderboardWidget leaderboardWidget = null;
|
|
leaderboardWidget = Object.Instantiate(widgetPrefab);
|
|
leaderboardWidget.transform.SetParent(widgetsParent);
|
|
RectTransform component = leaderboardWidget.GetComponent<RectTransform>();
|
|
component.localPosition = Vector3.zero + new Vector3(0f, (float)num3 * (0f - scrollWidgetsOffset) + scrollWidgetsOffset, 0f);
|
|
component.localRotation = Quaternion.identity;
|
|
component.localScale = Vector3.one;
|
|
leaderboardWidget.RefreshWidget(num4, empty, array, num3 + 1);
|
|
if (num4 == GlobalSettings.Instance.GetPlatformProfileID())
|
|
{
|
|
num2 = num3 + 1;
|
|
}
|
|
widgetsList.Add(leaderboardWidget);
|
|
num3++;
|
|
}
|
|
for (int j = leaderboardSettings.leaderboardEntriesCount; j < num; j++)
|
|
{
|
|
LeaderboardWidget leaderboardWidget2 = Object.Instantiate(widgetPrefab);
|
|
leaderboardWidget2.transform.SetParent(widgetsParent);
|
|
leaderboardWidget2.GetComponent<RectTransform>().localPosition = Vector3.zero + new Vector3(0f, (float)j * (0f - scrollWidgetsOffset) + scrollWidgetsOffset, 0f);
|
|
leaderboardWidget2.GetComponent<RectTransform>().localScale = Vector3.one;
|
|
leaderboardWidget2.RefreshEmptyWidget();
|
|
widgetsList.Add(leaderboardWidget2);
|
|
}
|
|
for (int k = 0; k < sortBackgrounds.Count; k++)
|
|
{
|
|
sortBackgrounds[k].enabled = k == (int)currentLeaderboardType;
|
|
sortHeaders[k].color = ((k != (int)currentLeaderboardType) ? Color.white : sortHeaderColor);
|
|
}
|
|
scrollParentStartPos = scrollWindow.content.localPosition;
|
|
scrollWindow.content.sizeDelta = new Vector2(scrollWindow.content.sizeDelta.x, scrollWidgetsOffset * (float)Mathf.Max(num3, num));
|
|
scrollWindow.content.localPosition = scrollParentStartPos;
|
|
Canvas.ForceUpdateCanvases();
|
|
scrollWindow.verticalScrollbar.value = 1f;
|
|
Canvas.ForceUpdateCanvases();
|
|
myWidget.RefreshMyWidget(num2, LeaderboardsManager.Instance.GetCurrentLeaderboardPlayerStats(currentLeaderboardFishery));
|
|
scrollWindow.verticalNormalizedPosition = 1f;
|
|
if ((bool)base.transform.parent.parent.GetComponent<CurvedUISettings>())
|
|
{
|
|
base.transform.parent.parent.GetComponent<CurvedUISettings>().SetAllChildrenDirty(true);
|
|
}
|
|
}
|
|
}
|