using System; using Core; using DG.Tweening; using PermanentSystems; using Systems; using TMPro; using UnityEngine; using UnityEngine.UI; using Application = Core.Application; namespace Panels { public class MenuPanel : PanelBase { [SerializeField] private RectTransform leftArrow; [SerializeField] private RectTransform rightArrow; [SerializeField] private Button startBtn; [SerializeField] private Button settingsBtn; [SerializeField] private TextMeshProUGUI distanceText; [SerializeField] private TextMeshProUGUI blueCountText; private Tween _leftArrowTween; private Tween _rightArrowTween; private GameManager _manager; private GameManager GameManager { get { if (_manager == null) _manager = Application.GetSystem(); return _manager; } } private SettingsPanel _settingsPanel; private SettingsPanel SettingsPanel { get { if (_settingsPanel == null) _settingsPanel = Application.GetPanel(); return _settingsPanel; } } protected override void ReleaseReferences() { _manager = null; startBtn = null; base.ReleaseReferences(); } public override void Initialize() { var data = Application.GetSystem().PlayerData; UpdatePlayerScore(data); startBtn.onClick.AddListener(StartGame); settingsBtn.onClick.AddListener(() => SettingsPanel.OpenPanel()); } public override void OpenPanelImmediately() { PlayTitleAnimation(); base.OpenPanelImmediately(); } public override void ClosePanelImmediately() { base.ClosePanelImmediately(); _leftArrowTween?.Kill(); _rightArrowTween?.Kill(); } public override void OpenPanel(Action callBack = null) { base.OpenPanel(callBack); PlayTitleAnimation(); } public override void ClosePanel(Action callBack = null) { base.ClosePanel(() => { _leftArrowTween?.Kill(); _rightArrowTween?.Kill(); callBack?.Invoke(); }); } private void PlayTitleAnimation() { _leftArrowTween = leftArrow.DOLocalMoveX(-450f, .8f) .SetEase(Ease.OutSine) .SetLoops(-1, LoopType.Yoyo); _rightArrowTween = rightArrow.DOLocalMoveX(450f, .8f) .SetEase(Ease.OutSine) .SetLoops(-1, LoopType.Yoyo); } private void StartGame() { // ClosePanelImmediately(); AudioSystem.PlaySoundEffect(AudioList.ButtonClickA); ClosePanel(); GameManager.StartGame(); } private void UpdatePlayerScore(PersistantData inData) { distanceText.text = $"{(int) inData.highestScore}"; blueCountText.text = inData.totalBlueOrbs.ToString(); } } }