Files

75 lines
2.8 KiB
C#
Raw Permalink Normal View History

2022-07-15 21:41:58 +03:00
using System.Collections;
2022-07-15 20:42:47 +03:00
using System.Collections.Generic;
2022-07-15 19:40:57 +03:00
using UnityEngine;
2022-07-15 20:42:47 +03:00
using UnityEngine.SceneManagement;
using UnityEngine.UI;
2022-07-15 19:40:57 +03:00
public class ReplaysMenu : BaseMenu
{
2022-11-21 18:08:37 +02:00
[SerializeField] private BaseMenu _replayIncompatibleMenu = default;
[SerializeField] private RectTransform _scrollView = default;
[SerializeField] private RectTransform _replaysGroup = default;
[SerializeField] private GameObject _replayPrefab = default;
[SerializeField] private GameObject _noReplaysFound = default;
private readonly List<ReplayCard> _replayCards = new();
private ReplayCard _currentReplayCard;
2022-07-15 19:40:57 +03:00
2022-11-21 18:08:37 +02:00
void Start()
{
_replaysGroup.anchoredPosition = new Vector2(0.0f, _replaysGroup.anchoredPosition.y);
2023-10-24 01:24:58 +03:00
if (ReplayManager.Instance.ReplayAmount > 0)
2022-11-21 18:08:37 +02:00
{
2023-09-22 16:54:55 +03:00
for (int i = 0; i < ReplayManager.Instance.ReplayAmount; i++)
2022-11-21 18:08:37 +02:00
{
2023-10-24 01:24:58 +03:00
ReplayCard replayCard = Instantiate(_replayPrefab, _replaysGroup).transform.GetChild(0).GetComponent<ReplayCard>();
2022-11-21 18:08:37 +02:00
replayCard.SetData(ReplayManager.Instance.GetReplayData(i));
int index = i;
2023-12-03 02:36:58 +02:00
if (index == ReplayManager.Instance.ReplayAmount - 1 && index > 0)
2023-10-09 12:39:56 +03:00
replayCard.Initialize(index, this, _replaysGroup, _replayCards[index - 1].GetComponent<Selectable>(), true);
else
replayCard.Initialize(index, this, _replaysGroup);
2022-11-21 18:08:37 +02:00
_replayCards.Add(replayCard);
}
}
else
_noReplaysFound.SetActive(true);
StartCoroutine(SetUpScrollViewCoroutine());
}
2022-07-15 20:42:47 +03:00
2022-11-21 18:08:37 +02:00
public void LoadReplayMatch(int index)
{
_currentReplayCard = _replayCards[index];
2023-09-22 16:54:55 +03:00
if (_currentReplayCard.ReplayData.version.Trim() == ReplayManager.Instance.VersionNumber)
2022-11-21 18:08:37 +02:00
{
2023-01-26 00:38:34 +02:00
SceneSettings.IsOnline = false;
SceneSettings.SceneSettingsDecide = true;
2022-11-21 18:08:37 +02:00
SceneSettings.IsTrainingMode = false;
SceneSettings.ReplayIndex = index;
2023-03-11 16:35:39 +02:00
ReplayManager.Instance.SetReplay();
2023-07-03 17:57:46 +03:00
SceneManager.LoadScene(1);
2022-11-21 18:08:37 +02:00
}
else
{
_currentReplayCard.GetComponent<Animator>().Rebind();
_replayIncompatibleMenu.Show();
}
}
2022-07-15 21:41:58 +03:00
2023-09-22 16:54:55 +03:00
public void CloseIncompatible() => _currentReplayCard.GetComponent<Button>().Select();
2022-07-26 11:26:10 +03:00
2022-11-21 18:08:37 +02:00
void OnEnable()
{
_scrollView.anchoredPosition = Vector2.zero;
StartCoroutine(SetUpScrollViewCoroutine());
}
2022-07-15 21:41:58 +03:00
2022-11-21 18:08:37 +02:00
IEnumerator SetUpScrollViewCoroutine()
{
yield return null;
_replaysGroup.anchoredPosition = new Vector2(0.0f, -(_replaysGroup.rect.height / 2.0f));
_scrollView.anchoredPosition = Vector2.zero;
if (_replayCards.Count > 0)
_replayCards[0].GetComponent<Button>().Select();
}
2022-07-15 19:40:57 +03:00
}