231 lines
6.9 KiB
C#
231 lines
6.9 KiB
C#
using System;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Uis;
|
|
using TMPro;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Titles
|
|
{
|
|
public class TycoonTitle : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private GameObject _titleMenuUiPanel;
|
|
|
|
[SerializeField]
|
|
private TitleOptions titleOptions;
|
|
|
|
[SerializeField]
|
|
private Button _startGameButton;
|
|
|
|
[SerializeField]
|
|
private Button _settingButton;
|
|
|
|
[SerializeField]
|
|
private Button _exitButton;
|
|
|
|
[SerializeField]
|
|
private bool _isTitleScene = true;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _versionText;
|
|
|
|
[SerializeField]
|
|
private string _dailyBgm = "DailyBgm1";
|
|
|
|
private PlayerInputKeyManager _playerInputKeyManager;
|
|
private SceneController _sceneController;
|
|
private InputAction _interactionEAction;
|
|
private InputAction _openAction;
|
|
private InputAction _closeAction;
|
|
private bool _isQuitting;
|
|
private bool _onButtonClicked;
|
|
|
|
private void Awake()
|
|
{
|
|
PopupUiController.ClearPopup();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_playerInputKeyManager = PlayerInputKeyManager.Instance;
|
|
_interactionEAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, "InteractionE");
|
|
_openAction = _playerInputKeyManager.GetAction(InputActionMaps.Tycoon, "Options");
|
|
_closeAction = _playerInputKeyManager.GetAction(InputActionMaps.TycoonUi, "Cancel");
|
|
|
|
if (_isTitleScene)
|
|
{
|
|
_sceneController = SceneController.Instance;
|
|
_startGameButton.onClick.AddListener(_sceneController.FadeIn);
|
|
AudioManager.Instance.PlayBgm(_dailyBgm);
|
|
|
|
Open();
|
|
}
|
|
else
|
|
{
|
|
_panel.SetActive(false);
|
|
_openAction.performed += OnOpen;
|
|
}
|
|
|
|
_startGameButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_settingButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_exitButton.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
|
|
_playerInputKeyManager.AddOnActionKeyboard(OnKeyboard);
|
|
_playerInputKeyManager.AddOnActionMouse(OnMouse);
|
|
|
|
_versionText.text = GetVersion();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
_startGameButton.onClick.RemoveListener(_sceneController.FadeIn);
|
|
}
|
|
|
|
_playerInputKeyManager.RemoveOnActionKeyboard(OnKeyboard);
|
|
_playerInputKeyManager.RemoveOnActionMouse(OnMouse);
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_openAction.performed -= OnOpen;
|
|
_closeAction.performed -= OnClose;
|
|
titleOptions.CancelAction.performed -= OnSettingCancel;
|
|
}
|
|
|
|
public void OnOpen(InputAction.CallbackContext context)
|
|
{
|
|
Open();
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
}
|
|
else
|
|
{
|
|
if (!PopupUiController.IsPopupListEmpty())
|
|
{
|
|
foreach (var element in PopupUiController.PopupUis)
|
|
{
|
|
print(element.gameObject.name);
|
|
}
|
|
return;
|
|
}
|
|
|
|
_openAction.performed -= OnOpen;
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
_closeAction.performed += OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
_playerInputKeyManager.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
_openAction.performed += OnOpen;
|
|
}
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
private void OnKeyboard()
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
|
|
}
|
|
|
|
private void OnMouse()
|
|
{
|
|
if (!_onButtonClicked)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(null);
|
|
}
|
|
}
|
|
|
|
private string GetVersion()
|
|
{
|
|
#if UNITY_EDITOR
|
|
return PlayerSettings.bundleVersion;
|
|
#else
|
|
return Application.version;
|
|
#endif
|
|
}
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
{
|
|
var current = EventSystem.current.currentSelectedGameObject;
|
|
if (!current) return;
|
|
|
|
var currenButton = current.GetComponent<Button>();
|
|
currenButton.onClick.Invoke();
|
|
}
|
|
|
|
public void QuitGame()
|
|
{
|
|
#if UNITY_EDITOR
|
|
EditorApplication.isPlaying = false;
|
|
#else
|
|
Application.Quit();
|
|
#endif
|
|
}
|
|
|
|
public void OnSettingCancel(InputAction.CallbackContext context)
|
|
{
|
|
HideSettingUi();
|
|
}
|
|
|
|
public void ShowSettingUi()
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
_titleMenuUiPanel.SetActive(false);
|
|
titleOptions.ShowUi();
|
|
titleOptions.CancelAction.performed += OnSettingCancel;
|
|
}
|
|
|
|
public void HideSettingUi()
|
|
{
|
|
titleOptions.CancelAction.performed -= OnSettingCancel;
|
|
titleOptions.HideUi();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public void MoveLobbyScene()
|
|
{
|
|
SceneManager.LoadScene("00.TycoonTitle");
|
|
}
|
|
}
|
|
} |