Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/GlobalTournamentScreen.cs
2026-02-21 16:45:37 +08:00

505 lines
17 KiB
C#

using System.Collections.Generic;
using Steamworks;
using UnityEngine;
using UnityEngine.UI;
public class GlobalTournamentScreen : MonoBehaviour
{
[Header("Info")]
public Image iconImage;
public Text nameText;
public Text wholeInfoText;
public Text fisheriesValue;
public Text fishValue;
public Text restrictionsValue;
public Text startValue;
public Text finishValue;
public Text timeLeftValue;
public Text goalTypeValue;
public Button getRewardButton;
public GameObject getRewardWindow;
public Text getRewardWholeText;
public GameObject rewardsWindow;
public Text rewardsWholeText;
public Button signInButton;
public Text signInText;
[Header("Ranking")]
public TournamentScreenWidget widgetPrefab;
public Transform widgetsParent;
public ScrollRect scrollWindow;
public float scrollWidgetsOffset = 100f;
private Vector2 scrollParentStartPos = Vector2.zero;
public bool sortList;
public int myPlace;
public int topPlayersToPrint = 3;
[HideInInspector]
public bool isVisible;
[HideInInspector]
public List<TournamentScreenWidget> widgetsList = new List<TournamentScreenWidget>();
public TournamentScreenWidget myWidget;
public List<GlobalTournamentWidget> globalTournamentWidgets = new List<GlobalTournamentWidget>();
[HideInInspector]
public GlobalTournamentSteamworks globalTournamentSteamworks;
[HideInInspector]
public GlobalTournamentManager.GlobalTournamentDefinition tournamentDefinition;
[HideInInspector]
public LeaderboardSettings currentLeaderboardSettings;
public void OnEnable()
{
if ((bool)GlobalTournamentSteamworks.Instance)
{
globalTournamentSteamworks = GlobalTournamentSteamworks.Instance;
ShowGetRewardWindow(false);
ShowRewardsWindow(false);
RefreshInfo();
isVisible = true;
if ((bool)myWidget)
{
myWidget.RefreshEmptyWidget();
}
currentLeaderboardSettings = globalTournamentSteamworks.GetCurrentLeaderboardSettings();
FindLeaderboard();
}
}
private void OnDisable()
{
foreach (TournamentScreenWidget widgets in widgetsList)
{
Object.Destroy(widgets.gameObject);
}
widgetsList.Clear();
isVisible = false;
}
public void Update()
{
}
public void FindLeaderboard()
{
if (!(globalTournamentSteamworks == null) && currentLeaderboardSettings != null)
{
globalTournamentSteamworks.globalTournamentScreen = this;
if (GlobalTournamentManager.Instance.currentTournament.state == GlobalTournamentManager.TournamentState.ACTIVE)
{
UploadScores();
}
else
{
DownloadScores();
}
}
}
public void UploadScores()
{
if (!(globalTournamentSteamworks == null))
{
globalTournamentSteamworks.globalTournamentScreen = this;
globalTournamentSteamworks.UploadScore(currentLeaderboardSettings);
SteamStatsManager.Instance.StoreStats();
}
}
public void DownloadScores()
{
if (!(globalTournamentSteamworks == null))
{
globalTournamentSteamworks.globalTournamentScreen = this;
currentLeaderboardSettings.DownloadScores();
}
}
public void RefreshInfo()
{
if (!GlobalTournamentManager.Instance)
{
return;
}
Debug.Log("GlobalTournamentScreen.Refresh()");
tournamentDefinition = GlobalTournamentManager.Instance.currentTournament;
signInButton.gameObject.SetActive(tournamentDefinition.state != GlobalTournamentManager.TournamentState.FINISHED && !tournamentDefinition.isSignedUp);
signInText.gameObject.SetActive(tournamentDefinition.state != GlobalTournamentManager.TournamentState.FINISHED && tournamentDefinition.isSignedUp);
if (!tournamentDefinition.CheckPlayerLevel(GlobalSettings.Instance.playerSettings.playersLevel))
{
Debug.LogError("!tournamentDefinition.CheckPlayerLevel");
signInButton.gameObject.SetActive(false);
}
if (!tournamentDefinition.CheckPlayerDifficulty(GlobalSettings.Instance.playerSettings.difficulty))
{
Debug.LogError("!tournamentDefinition.CheckPlayerDifficulty");
signInButton.gameObject.SetActive(false);
}
iconImage.sprite = tournamentDefinition.icon;
nameText.text = tournamentDefinition.tournamentName;
wholeInfoText.text = string.Empty;
goalTypeValue.text = string.Empty;
Text text = wholeInfoText;
text.text = text.text + MakeHeaderString(Utilities.GetTranslation("GUI/TOURNAMENTS_GOAL_TYPE")) + ":\n";
string[] args = new string[1] { ((int)(float)tournamentDefinition.limit/*cast due to .constrained prefix*/).ToString() };
if (tournamentDefinition.goalType == GlobalTournamentManager.GoalType.WEIGHT_SUM)
{
wholeInfoText.text += string.Format(Utilities.GetTranslation("TOURNAMENT/GOAL_TOTAL_WEIGHT"), args);
}
else if (tournamentDefinition.goalType == GlobalTournamentManager.GoalType.WEIGHT_MAX)
{
wholeInfoText.text += string.Format(Utilities.GetTranslation("TOURNAMENT/GOAL_BIGGEST_WEIGHT"), args);
}
else if (tournamentDefinition.goalType == GlobalTournamentManager.GoalType.AMOUNT)
{
wholeInfoText.text += string.Format(Utilities.GetTranslation("Amount"), args);
}
wholeInfoText.text += "\n\n";
fisheriesValue.text = string.Empty;
if (tournamentDefinition.fisheryIds.Count == 0)
{
fisheriesValue.text = Utilities.GetTranslation("TOURNAMENT/ANY");
}
else
{
for (int i = 0; i < tournamentDefinition.fisheryIds.Count; i++)
{
Text text2 = fisheriesValue;
text2.text = text2.text + Utilities.GetTranslation(GlobalSettings.Instance.levelsManager.GetFisheryById(tournamentDefinition.fisheryIds[i]).name) + ",\n";
}
fisheriesValue.text = fisheriesValue.text.Remove(fisheriesValue.text.Length - 2, 2);
}
Text text3 = wholeInfoText;
text3.text = text3.text + MakeHeaderString(Utilities.GetTranslation("GUI_HEADERS/FISHERIES")) + ":\n";
Text text4 = wholeInfoText;
text4.text = text4.text + MakeValueString(fisheriesValue.text) + "\n\n";
fishValue.text = string.Empty;
if (tournamentDefinition.fishIds.Count == 0)
{
fishValue.text = Utilities.GetTranslation("TOURNAMENT/ANY");
}
else
{
for (int j = 0; j < tournamentDefinition.fishIds.Count; j++)
{
Text text5 = fishValue;
text5.text = text5.text + GlobalSettings.Instance.fishManager.GetFishName((Fish.Species)(int)tournamentDefinition.fishIds[j]) + ", ";
}
fishValue.text = fishValue.text.Remove(fishValue.text.Length - 2, 2);
}
Text text6 = wholeInfoText;
text6.text = text6.text + MakeHeaderString(Utilities.GetTranslation("LEVELS/FISH_SPECIES")) + ":\n";
Text text7 = wholeInfoText;
text7.text = text7.text + MakeValueString(fishValue.text) + "\n\n";
if (!tournamentDefinition.HasAnyRestrictions())
{
restrictionsValue.text = Utilities.GetTranslation("TOURNAMENT/NO_RESTRICTIONS");
}
else
{
restrictionsValue.text = string.Empty;
if (tournamentDefinition.playerLevel.x != 0f || tournamentDefinition.playerLevel.y != 666f)
{
Text text8 = restrictionsValue;
string text9 = text8.text;
text8.text = text9 + Utilities.GetTranslation("LEADERBOARDS/LEVEL") + ": " + Mathf.RoundToInt(tournamentDefinition.playerLevel.x) + "-" + Mathf.RoundToInt(tournamentDefinition.playerLevel.y) + ",\n";
}
if (tournamentDefinition.difficulties.Count > 0)
{
Text text10 = restrictionsValue;
text10.text = text10.text + Utilities.GetTranslation("GUI/PROFILES_DIFFICULTY") + ": ";
for (int k = 0; k < tournamentDefinition.difficulties.Count; k++)
{
restrictionsValue.text += PlayerSettingsMy.GetDifficultyTranslation(tournamentDefinition.difficulties[k]);
}
restrictionsValue.text += "\n";
}
if (!tournamentDefinition.techniqueSpinning || !tournamentDefinition.techniqueFloat || !tournamentDefinition.techniqueFly || !tournamentDefinition.techniqueGround)
{
if ((bool)tournamentDefinition.techniqueSpinning)
{
Text text11 = restrictionsValue;
text11.text = text11.text + Utilities.GetTranslation("GUI/METHODS_SPINNING") + ", ";
}
if ((bool)tournamentDefinition.techniqueFloat)
{
Text text12 = restrictionsValue;
text12.text = text12.text + Utilities.GetTranslation("GUI/METHODS_FLOAT") + ", ";
}
if ((bool)tournamentDefinition.techniqueFly)
{
Text text13 = restrictionsValue;
text13.text = text13.text + Utilities.GetTranslation("GUI/METHODS_FLY") + ", ";
}
if ((bool)tournamentDefinition.techniqueGround)
{
Text text14 = restrictionsValue;
text14.text = text14.text + Utilities.GetTranslation("GUI/METHODS_BOTTOM") + ", ";
}
}
if ((bool)tournamentDefinition.fromBoat && !tournamentDefinition.fromCoast)
{
if (restrictionsValue.text.Length > 0)
{
restrictionsValue.text += "\n";
}
Text text15 = restrictionsValue;
text15.text = text15.text + Utilities.GetTranslation("TOURNAMENT/ONLY_BOAT") + ", ";
}
else if (!tournamentDefinition.fromBoat && (bool)tournamentDefinition.fromCoast)
{
if (restrictionsValue.text.Length > 0)
{
restrictionsValue.text += "\n";
}
Text text16 = restrictionsValue;
text16.text = text16.text + Utilities.GetTranslation("TOURNAMENT/NO_BOAT") + ", ";
}
if (tournamentDefinition.hours.x != 0f || tournamentDefinition.hours.y != 24f)
{
if (restrictionsValue.text.Length > 0)
{
restrictionsValue.text += "\n";
}
Text text17 = restrictionsValue;
string text9 = text17.text;
text17.text = text9 + string.Empty + Mathf.RoundToInt(tournamentDefinition.hours.x) + ":00-" + Mathf.RoundToInt(tournamentDefinition.hours.y) + ":00, ";
}
restrictionsValue.text = restrictionsValue.text.Remove(restrictionsValue.text.Length - 2, 2);
}
Text text18 = wholeInfoText;
text18.text = text18.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/RESTRICTIONS")) + ":\n";
Text text19 = wholeInfoText;
text19.text = text19.text + MakeValueString(restrictionsValue.text) + "\n\n";
startValue.text = GlobalTournamentManager.Instance.GetDateString(tournamentDefinition.startTime);
Text text20 = wholeInfoText;
text20.text = text20.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/START_TIME")) + ":\n";
Text text21 = wholeInfoText;
text21.text = text21.text + MakeValueString(startValue.text) + "\n\n";
finishValue.text = GlobalTournamentManager.Instance.GetDateString(tournamentDefinition.finishTime);
Text text22 = wholeInfoText;
text22.text = text22.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/FINISH_TIME")) + ":\n";
Text text23 = wholeInfoText;
text23.text = text23.text + MakeValueString(finishValue.text) + "\n\n";
if (tournamentDefinition.state == GlobalTournamentManager.TournamentState.INACTIVE)
{
Text text24 = wholeInfoText;
text24.text = text24.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/TIME_TO_START")) + ":\n";
Text text25 = wholeInfoText;
text25.text = text25.text + MakeValueString(tournamentDefinition.timeLeftString) + "\n\n";
}
else if (tournamentDefinition.state == GlobalTournamentManager.TournamentState.ACTIVE)
{
Text text26 = wholeInfoText;
text26.text = text26.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/TIME_LEFT")) + ":\n";
Text text27 = wholeInfoText;
text27.text = text27.text + MakeValueString(tournamentDefinition.timeLeftString) + "\n\n";
}
else if (tournamentDefinition.state == GlobalTournamentManager.TournamentState.FINISHED)
{
Text text28 = wholeInfoText;
text28.text = text28.text + MakeHeaderString(Utilities.GetTranslation("TOURNAMENT/STATUS")) + ":\n";
Text text29 = wholeInfoText;
text29.text = text29.text + MakeValueString(tournamentDefinition.GetStateName()) + "\n\n";
}
wholeInfoText.text = wholeInfoText.text.Trim();
}
public void RefreshRanking()
{
if (currentLeaderboardSettings == null || !SteamManager.Initialized)
{
return;
}
int num = 20;
int[] array = new int[6];
scrollParentStartPos = scrollWindow.content.localPosition;
scrollWindow.content.sizeDelta = new Vector2(scrollWindow.content.sizeDelta.x, scrollWidgetsOffset * (float)Mathf.Max(currentLeaderboardSettings.leaderboardEntriesCount, num));
scrollWindow.content.localPosition = scrollParentStartPos;
Canvas.ForceUpdateCanvases();
scrollWindow.verticalScrollbar.value = 1f;
Canvas.ForceUpdateCanvases();
foreach (TournamentScreenWidget widgets in widgetsList)
{
Object.Destroy(widgets.gameObject);
}
widgetsList.Clear();
if (tournamentDefinition.state == GlobalTournamentManager.TournamentState.INACTIVE)
{
return;
}
int rankPosition = 0;
int num2 = -1;
int rank = -1;
int num3 = 0;
myPlace = 0;
string empty = string.Empty;
string empty2 = string.Empty;
ulong num4 = 0uL;
for (int i = 0; i < currentLeaderboardSettings.leaderboardEntriesCount; i++)
{
for (int j = 0; j < array.Length; j++)
{
array[j] = 0;
}
SteamUserStats.GetDownloadedLeaderboardEntry(currentLeaderboardSettings.scoresDownloaded_t.m_hSteamLeaderboardEntries, i, out currentLeaderboardSettings.leaderboardEntries[i], array, 6);
num4 = currentLeaderboardSettings.leaderboardEntries[i].m_steamIDUser.m_SteamID;
empty2 = SteamFriends.GetFriendPersonaName(currentLeaderboardSettings.leaderboardEntries[i].m_steamIDUser);
if (currentLeaderboardSettings.leaderboardEntries[i].m_nScore != num2)
{
rankPosition = num3 + 1;
num2 = currentLeaderboardSettings.leaderboardEntries[i].m_nScore;
}
if (array[0] == 0)
{
}
if (!tournamentDefinition.CheckPlayerLevel(array[0]))
{
}
array[0] = Mathf.Clamp(array[0], (int)tournamentDefinition.playerLevel.x, (int)tournamentDefinition.playerLevel.y);
TournamentScreenWidget tournamentScreenWidget = Object.Instantiate(widgetPrefab);
tournamentScreenWidget.transform.SetParent(widgetsParent);
tournamentScreenWidget.GetComponent<RectTransform>().localPosition = Vector3.zero + new Vector3(0f, (float)num3 * (0f - scrollWidgetsOffset) + scrollWidgetsOffset, 0f);
tournamentScreenWidget.GetComponent<RectTransform>().localScale = Vector3.one;
tournamentScreenWidget.RefreshWidget(num4, empty2, array, rankPosition, num2);
if (num4 == GlobalSettings.Instance.GetPlatformProfileID() && SteamStatsManager.Instance.GetMySteamUser() != null && array[2] > 0)
{
myPlace = rankPosition;
}
num3++;
widgetsList.Add(tournamentScreenWidget);
}
for (int k = num3; k < num; k++)
{
TournamentScreenWidget tournamentScreenWidget2 = Object.Instantiate(widgetPrefab);
tournamentScreenWidget2.transform.SetParent(widgetsParent);
tournamentScreenWidget2.GetComponent<RectTransform>().localPosition = Vector3.zero + new Vector3(0f, (float)k * (0f - scrollWidgetsOffset) + scrollWidgetsOffset, 0f);
tournamentScreenWidget2.GetComponent<RectTransform>().localScale = Vector3.one;
tournamentScreenWidget2.RefreshEmptyWidget();
widgetsList.Add(tournamentScreenWidget2);
}
if ((bool)myWidget)
{
myWidget.RefreshMyWidget(rank);
}
scrollWindow.verticalNormalizedPosition = 1f;
getRewardButton.gameObject.SetActive(tournamentDefinition.state == GlobalTournamentManager.TournamentState.FINISHED && myPlace > 0 && myPlace <= tournamentDefinition.moneyRewards.Count && (int)SteamStatsManager.Instance.mySteamUser.tournamentCanGatherReward == 1);
}
public void ServerTimeUpdated()
{
foreach (GlobalTournamentWidget globalTournamentWidget in globalTournamentWidgets)
{
globalTournamentWidget.Refresh();
}
if (base.transform.parent.gameObject.activeSelf)
{
RefreshInfo();
}
}
public void SignIn()
{
tournamentDefinition.isSignedUp = true;
RefreshInfo();
GlobalSettings.Instance.playerSettings.Save();
}
public void ShowGetRewardWindow(bool show)
{
if (show)
{
getRewardWholeText.text = "<b>" + Utilities.GetTranslation("TOURNAMENT/CONGRATULATIONS") + "!</b>\n\n";
Text text = getRewardWholeText;
string text2 = text.text;
text.text = text2 + Utilities.GetTranslation("TOURNAMENT/YOUR_PLACE") + ": " + myPlace + ".\n\n";
Text text3 = getRewardWholeText;
text2 = text3.text;
text3.text = text2 + Utilities.GetTranslation("TOURNAMENT/YOUR_REWARD") + ": " + tournamentDefinition.moneyRewards[myPlace - 1] + " $";
if (myPlace == 1)
{
++SteamStatsManager.Instance.mySteamUser.tournamentTrophyGold;
}
else if (myPlace == 2)
{
++SteamStatsManager.Instance.mySteamUser.tournamentTrophySilver;
}
else if (myPlace == 3)
{
++SteamStatsManager.Instance.mySteamUser.tournamentTrophyBronze;
}
SteamStatsManager.Instance.mySteamUser.tournamentCanGatherReward = 0;
SteamStatsManager.Instance.StoreStats();
GlobalSettings.Instance.playerSettings.AddMoney(tournamentDefinition.moneyRewards[myPlace - 1]);
getRewardButton.gameObject.SetActive(false);
}
getRewardWindow.SetActive(show);
}
public void ShowRewardsWindow(bool show)
{
if (show)
{
rewardsWholeText.text = string.Empty;
for (int i = 0; i < tournamentDefinition.moneyRewards.Count; i++)
{
if (i < 9)
{
rewardsWholeText.text += " ";
}
Text text = rewardsWholeText;
text.text = text.text + string.Empty + (i + 1) + ".\t\t";
if (i < 9)
{
rewardsWholeText.text += "\t";
}
Text text2 = rewardsWholeText;
text2.text = text2.text + tournamentDefinition.GetMoneyReward(i) + " $";
if (i < tournamentDefinition.moneyRewards.Count - 1)
{
rewardsWholeText.text += "\n";
}
}
}
rewardsWindow.SetActive(show);
}
public string MakeHeaderString(string text)
{
return "<i>" + text + "</i>";
}
public string MakeValueString(string text)
{
return "<size=15>" + text + "</size>";
}
}