2025-02-14 03:17:41 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using DG.Tweening;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using Sequence = DG.Tweening.Sequence;
|
|
|
|
|
|
|
|
namespace DDD.Uis.Tycoon
|
|
|
|
{
|
|
|
|
public class MenuBoardUi : PopupUi
|
|
|
|
{
|
|
|
|
[Title("프리팹")]
|
|
|
|
[SerializeField]
|
|
|
|
private TodayMenu _todayMenuPrefab;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private TodayMenu _reverseTodayMenuPrefab;
|
|
|
|
|
|
|
|
[Title("컴포넌트")]
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _panel;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _todayMenusPanel;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private RectTransform _todayMenusPanelRect;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private AddMenuUi _addMenuUi;
|
|
|
|
|
|
|
|
[Title("클래스")]
|
|
|
|
[SerializeField]
|
|
|
|
private UiEventsController _uiEventsController;
|
|
|
|
|
|
|
|
[Title("오늘의 메뉴")]
|
|
|
|
[SerializeField, Tooltip("메뉴판에 표시할 메뉴 갯수")]
|
|
|
|
private int _maxTodayMenuCount = 6;
|
|
|
|
|
|
|
|
[Title("연출")]
|
|
|
|
[SerializeField]
|
|
|
|
private Vector3 _originalTodayMenuPanelPosition = new(0f, -75f, 0f);
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Vector2 _todayMenuPanelPositionX = new(0f, -395f);
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float _duration = 0.5f;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Ease _ease = Ease.Linear;
|
|
|
|
|
|
|
|
[Title("실시간 데이터")]
|
|
|
|
[SerializeField]
|
|
|
|
private List<TodayMenu> _todayMenus;
|
|
|
|
|
|
|
|
private Sequence _openAddMenuUiSequence;
|
|
|
|
private Sequence _closeAddMenuUiSequence;
|
|
|
|
private InputAction _interactionEAction;
|
|
|
|
private InputAction _cancelAction;
|
|
|
|
private InputAction _pressFAction;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
// 더미 데이터 삭제
|
|
|
|
foreach (Transform element in _todayMenusPanel.transform)
|
|
|
|
{
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
Destroy(element.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_addMenuUi = FindAnyObjectByType<AddMenuUi>();
|
2025-02-14 07:22:20 +00:00
|
|
|
}
|
2025-02-14 03:17:41 +00:00
|
|
|
|
2025-02-14 07:22:20 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
|
|
_cancelAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
|
|
|
|
_pressFAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.PressF);
|
|
|
|
|
2025-02-14 03:17:41 +00:00
|
|
|
_openAddMenuUiSequence = DOTween.Sequence()
|
|
|
|
.Append(_todayMenusPanelRect.DOAnchorPosX(_todayMenuPanelPositionX.y, _duration)
|
|
|
|
.SetEase(_ease))
|
|
|
|
.Append(_addMenuUi.OpenTween)
|
|
|
|
.SetAutoKill(false)
|
|
|
|
.Pause();
|
|
|
|
|
|
|
|
_closeAddMenuUiSequence = DOTween.Sequence()
|
|
|
|
.Append(_addMenuUi.CloseTween)
|
|
|
|
.Append(_todayMenusPanelRect.DOAnchorPosX(_todayMenuPanelPositionX.x, _duration)
|
|
|
|
.SetEase(_ease))
|
|
|
|
.SetAutoKill(false)
|
|
|
|
.Pause();
|
|
|
|
|
|
|
|
_todayMenus = new List<TodayMenu>(_maxTodayMenuCount);
|
|
|
|
for (int i = 0; i < _maxTodayMenuCount; i++)
|
|
|
|
{
|
|
|
|
TodayMenu menuPrefab = i % 2 == 0 ? _todayMenuPrefab : _reverseTodayMenuPrefab;
|
|
|
|
TodayMenu todayMenu = Instantiate(menuPrefab, _todayMenusPanel.transform);
|
|
|
|
todayMenu.RegisterButtonListener(() => OnClickEmptyButton(todayMenu));
|
|
|
|
_todayMenus.Add(todayMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetNavigationTodayMenus();
|
|
|
|
|
|
|
|
_todayMenusPanelRect.anchoredPosition = _originalTodayMenuPanelPosition;
|
|
|
|
_addMenuUi.SetCloseSequence(_closeAddMenuUiSequence);
|
|
|
|
_panel.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
_openAddMenuUiSequence?.Kill();
|
|
|
|
_closeAddMenuUiSequence?.Kill();
|
|
|
|
_interactionEAction = null;
|
|
|
|
_cancelAction = null;
|
|
|
|
_pressFAction = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Open()
|
|
|
|
{
|
|
|
|
_todayMenusPanelRect.anchoredPosition = _originalTodayMenuPanelPosition;
|
|
|
|
|
|
|
|
base.Open();
|
|
|
|
_panel.SetActive(true);
|
|
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
{
|
|
|
|
_panel.SetActive(false);
|
|
|
|
base.Close();
|
|
|
|
|
|
|
|
if (PopupUiController.IsPopupListEmpty() || !PopupUiController.IsPausedPopupList())
|
|
|
|
{
|
|
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void EnableInput()
|
|
|
|
{
|
2025-02-14 07:22:20 +00:00
|
|
|
//_interactionEAction.performed += OnInteractionE;
|
2025-02-14 03:17:41 +00:00
|
|
|
_cancelAction.performed += OnClose;
|
|
|
|
_pressFAction.performed += OnClose;
|
|
|
|
_uiEventsController.EnableAutoNavigate();
|
|
|
|
|
|
|
|
GameObject selectObject = _todayMenus[0].MenuButton.gameObject;
|
|
|
|
foreach (TodayMenu todayMenu in _todayMenus)
|
|
|
|
{
|
|
|
|
if (todayMenu.IsAddedMenu) continue;
|
|
|
|
|
|
|
|
selectObject = todayMenu.MenuButton.gameObject;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_uiEventsController.SetSelectObject(selectObject);
|
|
|
|
EventSystem.current.SetSelectedGameObject(_uiEventsController.SelectObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void DisableInput()
|
|
|
|
{
|
2025-02-14 07:22:20 +00:00
|
|
|
//_interactionEAction.performed -= OnInteractionE;
|
2025-02-14 03:17:41 +00:00
|
|
|
_cancelAction.performed -= OnClose;
|
|
|
|
_pressFAction.performed -= OnClose;
|
|
|
|
_uiEventsController.DisableAutoNavigate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnInteractionE(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (!EventSystem.current) return;
|
|
|
|
|
|
|
|
EventSystem.current.currentSelectedGameObject.GetComponent<Button>()?.onClick.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnClickEmptyButton(TodayMenu clickedTodayMenu)
|
|
|
|
{
|
|
|
|
_addMenuUi.SetCurrentTodayMenu(clickedTodayMenu);
|
|
|
|
_addMenuUi.Open();
|
|
|
|
_openAddMenuUiSequence?.Restart();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetNavigationTodayMenus()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _maxTodayMenuCount; i++)
|
|
|
|
{
|
|
|
|
Navigation navigation = _todayMenus[i].MenuButton.navigation;
|
|
|
|
navigation.mode = Navigation.Mode.Explicit;
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
navigation.selectOnDown = _todayMenus[i + 1].MenuButton;
|
|
|
|
}
|
|
|
|
else if (i == _maxTodayMenuCount - 1)
|
|
|
|
{
|
|
|
|
navigation.selectOnUp = _todayMenus[i - 1].MenuButton;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
navigation.selectOnDown = _todayMenus[i + 1].MenuButton;
|
|
|
|
navigation.selectOnUp = _todayMenus[i - 1].MenuButton;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|