242 lines
6.8 KiB
C#
242 lines
6.8 KiB
C#
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 _resumeGameButton;
|
|
|
|
[SerializeField]
|
|
private Button _optionsButton;
|
|
|
|
[SerializeField]
|
|
private Button _lobbyButton;
|
|
|
|
[SerializeField]
|
|
private Button _quitGameButton;
|
|
|
|
[SerializeField]
|
|
private bool _isTitleScene = true;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _versionText;
|
|
|
|
[SerializeField]
|
|
private string _dailyBgm = "DailyBgm1";
|
|
|
|
private SceneController _sceneController;
|
|
private InputAction _interactionEAction;
|
|
private InputAction _openAction;
|
|
private InputAction _closeAction;
|
|
private bool _isQuitting;
|
|
private bool _onButtonClicked;
|
|
|
|
private void Start()
|
|
{
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
_openAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.Tycoon, TycoonActions.Options);
|
|
_closeAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.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; });
|
|
_resumeGameButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_optionsButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_lobbyButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
_quitGameButton?.onClick.AddListener(() => { _onButtonClicked = true; });
|
|
|
|
PlayerInputKeyManager.Instance.AddOnActionKeyboard(OnKeyboard);
|
|
PlayerInputKeyManager.Instance.AddOnActionMouse(OnMouse);
|
|
|
|
titleOptions.CloseOptions = HideSettingUi;
|
|
_versionText.text = GetVersion();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
if (_startGameButton != null && _sceneController != null)
|
|
{
|
|
_startGameButton.onClick.RemoveListener(_sceneController.FadeIn);
|
|
}
|
|
}
|
|
|
|
PlayerInputKeyManager.Instance.RemoveOnActionKeyboard(OnKeyboard);
|
|
PlayerInputKeyManager.Instance.RemoveOnActionMouse(OnMouse);
|
|
|
|
if (_interactionEAction != null)
|
|
{
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
if (_openAction != null)
|
|
{
|
|
_openAction.performed -= OnOpen;
|
|
}
|
|
if (_closeAction != null)
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
}
|
|
}
|
|
|
|
public void OnOpen(InputAction.CallbackContext context)
|
|
{
|
|
Open();
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
if (!_isTitleScene)
|
|
{
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
}
|
|
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
if (!_isTitleScene)
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed += OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
_closeAction.performed -= OnClose;
|
|
}
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
}
|
|
|
|
private void OnKeyboard()
|
|
{
|
|
if (_isTitleScene)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_startGameButton.gameObject);
|
|
}
|
|
else
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(_resumeGameButton.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 ShowSettingUi()
|
|
{
|
|
_titleMenuUiPanel.SetActive(false);
|
|
titleOptions.Open();
|
|
}
|
|
|
|
public void HideSettingUi()
|
|
{
|
|
titleOptions.Close();
|
|
_titleMenuUiPanel.SetActive(true);
|
|
}
|
|
|
|
public void MoveLobbyScene()
|
|
{
|
|
SceneManager.LoadScene("00.TycoonTitle");
|
|
}
|
|
}
|
|
} |