ui 추상화 로직 강제

This commit is contained in:
NTG 2025-08-29 12:53:54 +09:00
parent 8445640c20
commit 75f09e75d2
13 changed files with 318 additions and 392 deletions

View File

@ -25,24 +25,11 @@ public abstract class BaseUi : MonoBehaviour
public bool IsInitialized { get; protected set; } public bool IsInitialized { get; protected set; }
public bool IsBlockingTime => false; public bool IsBlockingTime => false;
public bool IsOpen => _panel != null && _panel.activeSelf; public bool IsOpen => _panel != null && _panel.activeSelf;
protected virtual void Awake() protected virtual void OnEnable() { }
{
_canvasGroup = GetComponent<CanvasGroup>();
_panel = transform.Find(CommonConstants.Panel).gameObject;
_blockImage = transform.Find(CommonConstants.BlockImage).gameObject;
if (_enableBlockImage)
{
_blockImage.SetActive(false);
}
_panel.SetActive(false);
}
protected virtual void Start() { } protected virtual void Start() { }
protected virtual void Update() { } protected virtual void Update() { }
protected virtual void OnDisable() { }
protected virtual void OnDestroy() protected virtual void OnDestroy()
{ {
_bindingContext?.Dispose(); _bindingContext?.Dispose();
@ -51,22 +38,29 @@ protected virtual void OnDestroy()
} }
public void CreateInitialize() public void CreateInitialize()
{
OnCreatedInitialize();
}
protected virtual void OnCreatedInitialize()
{ {
UiManager.Instance.UiState.RegisterUI(this); UiManager.Instance.UiState.RegisterUI(this);
_bindingContext = new BindingContext(); _canvasGroup = GetComponent<CanvasGroup>();
SetupBindings(); _panel = transform.Find(CommonConstants.Panel).gameObject;
} _blockImage = transform.Find(CommonConstants.BlockImage).gameObject;
protected virtual void OnOpenedEvents() { }
protected virtual void OnClosedEvents() { }
// BaseUi 메서드들을 직접 구현 _panel.SetActive(false);
public virtual void OpenPanel() _bindingContext = new BindingContext();
OnCreatedInitialize();
if (_enableBlockImage)
{
_blockImage.SetActive(false);
}
}
protected abstract void OnCreatedInitialize();
protected abstract void OnOpenedEvents();
protected abstract void OnClosedEvents();
protected void OpenPanel()
{ {
if (_enableBlockImage) if (_enableBlockImage)
{ {
@ -74,11 +68,10 @@ public virtual void OpenPanel()
} }
_panel.SetActive(true); _panel.SetActive(true);
OnOpenedEvents(); OnOpenedEvents();
} }
public virtual void ClosePanel() protected void ClosePanel()
{ {
if (_enableBlockImage) if (_enableBlockImage)
{ {
@ -91,7 +84,7 @@ public virtual void ClosePanel()
IsInitialized = false; IsInitialized = false;
} }
public virtual void SetUiInteractable(bool active) public void SetUiInteractable(bool active)
{ {
if (_canvasGroup) if (_canvasGroup)
{ {
@ -102,15 +95,10 @@ public virtual void SetUiInteractable(bool active)
public bool IsOpenPanel() => _panel && _panel.activeInHierarchy; public bool IsOpenPanel() => _panel && _panel.activeInHierarchy;
/// <summary>
/// 추가 바인딩 설정 - 하위 클래스에서 구현
/// </summary>
protected virtual void SetupBindings() { }
/// <summary> /// <summary>
/// ViewModel 속성 변경 이벤트 핸들러 /// ViewModel 속성 변경 이벤트 핸들러
/// </summary> /// </summary>
protected virtual void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) protected void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
HandleCustomPropertyChanged(e.PropertyName); HandleCustomPropertyChanged(e.PropertyName);
} }

View File

@ -1,74 +0,0 @@
namespace DDD
{
public class BaseViewModelUi<TViewModel> : BaseUi where TViewModel : SimpleViewModel
{
protected TViewModel _viewModel;
protected override void Awake()
{
base.Awake();
_viewModel = GetComponent<TViewModel>();
}
protected override void OnOpenedEvents()
{
base.OnOpenedEvents();
if (_viewModel && _bindingContext != null)
{
_bindingContext.SetDataContext(_viewModel);
_viewModel.PropertyChanged += OnViewModelPropertyChanged;
}
}
protected override void OnClosedEvents()
{
base.OnClosedEvents();
if (_viewModel != null)
{
_viewModel.PropertyChanged -= OnViewModelPropertyChanged;
}
}
public override void OpenPanel()
{
base.OpenPanel();
_viewModel?.Initialize();
}
public override void ClosePanel()
{
base.ClosePanel();
_viewModel?.Cleanup();
}
/// <summary>
/// ViewModel 메서드 호출 헬퍼
/// </summary>
protected void InvokeViewModelMethod(string methodName, params object[] parameters)
{
if (_viewModel == null) return;
var method = _viewModel.GetType().GetMethod(methodName);
method?.Invoke(_viewModel, parameters);
}
/// <summary>
/// ViewModel 속성 설정 헬퍼
/// </summary>
protected void SetViewModelProperty(string propertyName, object value)
{
if (_viewModel == null) return;
var property = _viewModel.GetType().GetProperty(propertyName);
if (property != null && property.CanWrite)
{
property.SetValue(_viewModel, value);
}
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: df6384ea09a44f188d636ca7ee47db13
timeCreated: 1755678434

View File

@ -15,14 +15,22 @@ protected override void OnDestroy()
protected override void OnCreatedInitialize() protected override void OnCreatedInitialize()
{ {
base.OnCreatedInitialize();
_canvasGroup.alpha = 0f; _canvasGroup.alpha = 0f;
EventBus.Register<FadeInEvent>(this); EventBus.Register<FadeInEvent>(this);
EventBus.Register<FadeOutEvent>(this); EventBus.Register<FadeOutEvent>(this);
} }
protected override void OnOpenedEvents()
{
}
protected override void OnClosedEvents()
{
}
public void HandleEvent(FadeInEvent evt) public void HandleEvent(FadeInEvent evt)
{ {
_ = FadeInAsync(evt); _ = FadeInAsync(evt);

View File

@ -23,14 +23,22 @@ protected override void OnDestroy()
protected override void OnCreatedInitialize() protected override void OnCreatedInitialize()
{ {
base.OnCreatedInitialize();
_canvasGroup.alpha = 0; _canvasGroup.alpha = 0;
_messageText.text = null; _messageText.text = null;
EventBus.Register(this); EventBus.Register(this);
} }
protected override void OnOpenedEvents()
{
}
protected override void OnClosedEvents()
{
}
public void HandleEvent(ShowGlobalMessageEvent evt) public void HandleEvent(ShowGlobalMessageEvent evt)
{ {
_messageQueue.Enqueue(evt); _messageQueue.Enqueue(evt);

View File

@ -4,9 +4,17 @@ public class RestaurantHud : BaseUi
{ {
protected override void OnCreatedInitialize() protected override void OnCreatedInitialize()
{ {
base.OnCreatedInitialize();
OpenPanel(); OpenPanel();
} }
protected override void OnOpenedEvents()
{
}
protected override void OnClosedEvents()
{
}
} }
} }

View File

@ -27,14 +27,23 @@ protected override void OnDestroy()
protected override void OnCreatedInitialize() protected override void OnCreatedInitialize()
{ {
base.OnCreatedInitialize();
_filledImage.fillAmount = 0f; _filledImage.fillAmount = 0f;
EventBus.Register<ShowInteractionUiEvent>(this); EventBus.Register<ShowInteractionUiEvent>(this);
EventBus.Register<HideInteractionUiEvent>(this); EventBus.Register<HideInteractionUiEvent>(this);
} }
protected override void OnOpenedEvents()
{
}
protected override void OnClosedEvents()
{
}
public void HandleEvent(ShowInteractionUiEvent evt) public void HandleEvent(ShowInteractionUiEvent evt)
{ {
ShowInteractionUiEvent(evt); ShowInteractionUiEvent(evt);
@ -47,14 +56,13 @@ public void HandleEvent(HideInteractionUiEvent evt)
private void ShowInteractionUiEvent(ShowInteractionUiEvent evt) private void ShowInteractionUiEvent(ShowInteractionUiEvent evt)
{ {
var currentLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey); _previousLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey);
if (currentLocalizedString != _previousLocalizedString)
{
_textLabelLocalizeStringEvent.StringReference = currentLocalizedString;
_previousLocalizedString = LocalizationManager.Instance.GetLocalizedString(evt.TextKey);
}
_textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor; _textLabel.color = evt.CanInteract ? _canInteractTextColor : _cannotInteractTextColor;
if (_textLabelLocalizeStringEvent.StringReference != _previousLocalizedString)
{
_textLabelLocalizeStringEvent.StringReference = _previousLocalizedString;
}
_filledImage.fillAmount = evt.HoldProgress; _filledImage.fillAmount = evt.HoldProgress;
if (_panel.activeInHierarchy == false) if (_panel.activeInHierarchy == false)

View File

@ -8,13 +8,6 @@ public abstract class BasePopupUi : BaseUi
public bool IsTopPopup => UiManager.Instance.UiState.IsTopPopup(this); public bool IsTopPopup => UiManager.Instance.UiState.IsTopPopup(this);
public InputActionMaps InputActionMaps { get; protected set; } public InputActionMaps InputActionMaps { get; protected set; }
protected override void Awake()
{
_enableBlockImage = true;
base.Awake();
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -39,33 +32,46 @@ protected override void OnDestroy()
UiManager.Instance?.UiState?.UnregisterPopupUI(this); UiManager.Instance?.UiState?.UnregisterPopupUI(this);
} }
protected abstract GameObject GetInitialSelected();
protected abstract void OnCreatedInitializeBasePopup();
protected abstract void OnOpenedEventsBasePopup(OpenPopupUiEvent evt);
protected abstract void OnClosedEventsBasePopup(ClosePopupUiEvent evt);
protected override void OnCreatedInitialize() protected override void OnCreatedInitialize()
{ {
base.OnCreatedInitialize();
UiManager.Instance.UiState.RegisterPopupUI(this); UiManager.Instance.UiState.RegisterPopupUI(this);
_enableBlockImage = true;
OnCreatedInitializeBasePopup();
} }
public virtual void Open(OpenPopupUiEvent evt) protected override void OnOpenedEvents() { }
protected override void OnClosedEvents() { }
public void OpenPopup(OpenPopupUiEvent evt)
{ {
OpenPanel(); OpenPanel();
var initialSelected = GetInitialSelected(); var initialSelected = GetInitialSelected();
if (initialSelected != null) if (initialSelected)
{ {
EventSystem.current.SetSelectedGameObject(initialSelected); EventSystem.current.SetSelectedGameObject(initialSelected);
} }
transform.SetAsLastSibling(); transform.SetAsLastSibling();
OnOpenedEventsBasePopup(evt);
IsInitialized = true;
} }
public virtual void Close() public void Close()
{ {
var evt = GameEvents.ClosePopupUiEvent; var evt = GameEvents.ClosePopupUiEvent;
evt.UiType = GetType(); evt.UiType = GetType();
OnClosedEventsBasePopup(evt);
ClosePanel();
EventBus.Broadcast(evt); EventBus.Broadcast(evt);
} }
protected abstract GameObject GetInitialSelected();
} }
} }

View File

@ -19,17 +19,9 @@ protected override GameObject GetInitialSelected()
return _confirmButton.gameObject; return _confirmButton.gameObject;
} }
protected override void OnCreatedInitialize() protected override void OnCreatedInitializePopup()
{ {
base.OnCreatedInitialize();
_messageLabelLocalizeStringEvent.OnUpdateString.Invoke(string.Empty); _messageLabelLocalizeStringEvent.OnUpdateString.Invoke(string.Empty);
SetupBindings();
}
protected override void SetupBindings()
{
base.SetupBindings();
BindingHelper.BindLocalizedStringEvent(_bindingContext, _messageLabelLocalizeStringEvent, nameof(_viewModel.MessageLocalizedString)); BindingHelper.BindLocalizedStringEvent(_bindingContext, _messageLabelLocalizeStringEvent, nameof(_viewModel.MessageLocalizedString));
BindingHelper.BindActive(_bindingContext, _cancelButton.gameObject, nameof(_viewModel.IsCancelButtonVisible)); BindingHelper.BindActive(_bindingContext, _cancelButton.gameObject, nameof(_viewModel.IsCancelButtonVisible));
@ -46,28 +38,27 @@ protected override void SetupBindings()
Close(); Close();
}); });
} }
public override void Open(OpenPopupUiEvent evt) protected override void OnOpenedEventsPopup(OpenPopupUiEvent evt)
{ {
base.Open(evt);
UnityAction onConfirmAction = evt.OnConfirm != null ? new UnityAction(evt.OnConfirm) : null; UnityAction onConfirmAction = evt.OnConfirm != null ? new UnityAction(evt.OnConfirm) : null;
UnityAction onCancelAction = evt.OnCancel != null ? new UnityAction(evt.OnCancel) : null; UnityAction onCancelAction = evt.OnCancel != null ? new UnityAction(evt.OnCancel) : null;
_viewModel?.SetupConfirm(evt.NewMessageKey, onConfirmAction, onCancelAction, evt.IsCancelButtonVisible); _viewModel?.SetupConfirm(evt.NewMessageKey, onConfirmAction, onCancelAction, evt.IsCancelButtonVisible);
} }
protected override void OnOpenedEvents()
{
base.OnOpenedEvents();
IsInitialized = true;
}
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
if (base.OnInputPerformed(actionEnum, context) == false) return false;
protected override void OnClosedEventsPopup(ClosePopupUiEvent evt)
{
}
protected override void OnInputStartedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
protected override void OnInputPerformedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
switch (actionEnum) switch (actionEnum)
{ {
case RestaurantUiActions.Cancel: case RestaurantUiActions.Cancel:
@ -77,8 +68,11 @@ protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAc
HandleInteract1Performed(); HandleInteract1Performed();
break; break;
} }
}
return true; protected override void OnInputCanceledPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
} }
private void HandleCancelPerformed() private void HandleCancelPerformed()

View File

@ -14,25 +14,30 @@ public abstract class PopupUi<TInputEnum, TViewModel> : BasePopupUi
protected readonly List<(InputAction action, Action<InputAction.CallbackContext> handler)> _registeredHandlers = new(); protected readonly List<(InputAction action, Action<InputAction.CallbackContext> handler)> _registeredHandlers = new();
protected TViewModel _viewModel; protected TViewModel _viewModel;
protected abstract void OnCreatedInitializePopup();
protected abstract void OnOpenedEventsPopup(OpenPopupUiEvent evt);
protected abstract void OnClosedEventsPopup(ClosePopupUiEvent evt);
protected abstract void OnInputStartedPopup(TInputEnum actionEnum, InputAction.CallbackContext context);
protected abstract void OnInputPerformedPopup(TInputEnum actionEnum, InputAction.CallbackContext context);
protected abstract void OnInputCanceledPopup(TInputEnum actionEnum, InputAction.CallbackContext context);
protected override void Awake() protected override void OnCreatedInitializeBasePopup()
{ {
base.Awake();
_viewModel = GetComponent<TViewModel>(); _viewModel = GetComponent<TViewModel>();
OnCreatedInitializePopup();
} }
protected override void OnOpenedEvents() protected override void OnOpenedEventsBasePopup(OpenPopupUiEvent evt)
{ {
base.OnOpenedEvents(); _viewModel?.Initialize();
if (_viewModel && _bindingContext != null) if (_viewModel && _bindingContext != null)
{ {
_bindingContext.SetDataContext(_viewModel); _bindingContext.SetDataContext(_viewModel);
_viewModel.PropertyChanged += OnViewModelPropertyChanged;
} }
// PopupUi의 입력 바인딩 등록
foreach (var actionEnum in _uiActionsInputBinding.BindingActions.GetFlags()) foreach (var actionEnum in _uiActionsInputBinding.BindingActions.GetFlags())
{ {
if (actionEnum.Equals(default(TInputEnum))) continue; if (actionEnum.Equals(default(TInputEnum))) continue;
@ -65,18 +70,17 @@ protected override void OnOpenedEvents()
} }
InputActionMaps = _uiActionsInputBinding.InputActionMaps; InputActionMaps = _uiActionsInputBinding.InputActionMaps;
OnOpenedEventsPopup(evt);
if (IsTopPopup)
{
InputManager.Instance.SwitchCurrentActionMap(_uiActionsInputBinding.InputActionMaps);
}
} }
protected override void OnClosedEvents() protected override void OnClosedEventsBasePopup(ClosePopupUiEvent evt)
{ {
base.OnClosedEvents();
if (_viewModel != null)
{
_viewModel.PropertyChanged -= OnViewModelPropertyChanged;
}
// 입력 핸들러 해제
foreach (var (action, handler) in _registeredHandlers) foreach (var (action, handler) in _registeredHandlers)
{ {
if (action != null) if (action != null)
@ -86,32 +90,30 @@ protected override void OnClosedEvents()
action.canceled -= handler; action.canceled -= handler;
} }
} }
_registeredHandlers.Clear();
}
public override void Open(OpenPopupUiEvent evt)
{
base.Open(evt);
_viewModel?.Initialize();
if (IsTopPopup)
{
InputManager.Instance.SwitchCurrentActionMap(_uiActionsInputBinding.InputActionMaps);
}
}
public override void Close()
{
base.Close();
OnClosedEventsPopup(evt);
_viewModel?.Cleanup(); _viewModel?.Cleanup();
} }
private void OnInputStarted(TInputEnum actionEnum, InputAction.CallbackContext context)
{
if (IsTopPopup == false) return;
OnInputStartedPopup(actionEnum, context);
}
// 입력 처리 메서드들 private void OnInputPerformed(TInputEnum actionEnum, InputAction.CallbackContext context)
protected virtual bool OnInputStarted(TInputEnum actionEnum, InputAction.CallbackContext context) => IsTopPopup; {
protected virtual bool OnInputPerformed(TInputEnum actionEnum, InputAction.CallbackContext context) => IsTopPopup; if (IsTopPopup == false) return;
protected virtual bool OnInputCanceled(TInputEnum actionEnum, InputAction.CallbackContext context) => IsTopPopup;
OnInputPerformedPopup(actionEnum, context);
}
private void OnInputCanceled(TInputEnum actionEnum, InputAction.CallbackContext context)
{
if (IsTopPopup == false) return;
OnInputCanceledPopup(actionEnum, context);
}
} }
} }

View File

@ -69,7 +69,7 @@ public void HandleEvent(OpenPopupUiEvent evt)
if (!popup.IsOpen) if (!popup.IsOpen)
{ {
PushPopup(popup); PushPopup(popup);
popup.Open(evt); popup.OpenPopup(evt);
if (popup.IsBlockingTime) if (popup.IsBlockingTime)
{ {
@ -83,21 +83,17 @@ public void HandleEvent(OpenPopupUiEvent evt)
} }
public void HandleEvent(ClosePopupUiEvent evt) public void HandleEvent(ClosePopupUiEvent evt)
{ {
if (_popupUis.TryGetValue(evt.UiType, out var popup)) if (_popupUis.TryGetValue(evt.UiType, out var popup))
{ {
if (popup.IsOpen) PopPopup(popup);
{
popup.ClosePanel();
PopPopup(popup);
if (popup.IsBlockingTime) if (popup.IsBlockingTime)
{ {
var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent; var timeScaleChangeEvent = GameEvents.RequestTimeScaleChangeEvent;
timeScaleChangeEvent.Requester = popup; timeScaleChangeEvent.Requester = popup;
timeScaleChangeEvent.NewTimeScale = 1f; timeScaleChangeEvent.NewTimeScale = 1f;
EventBus.Broadcast(timeScaleChangeEvent); EventBus.Broadcast(timeScaleChangeEvent);
}
} }
} }
} }

View File

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@ -26,65 +25,6 @@ public class CookUi : PopupUi<RestaurantUiActions, CookViewModel>
[SerializeField] private HorizontalLayoutGroup _tasteHashTagContentLayoutGroup; [SerializeField] private HorizontalLayoutGroup _tasteHashTagContentLayoutGroup;
[SerializeField] private RectTransform _tasteHashTagContent2; [SerializeField] private RectTransform _tasteHashTagContent2;
protected override void OnCreatedInitialize()
{
base.OnCreatedInitialize();
_addedCookTabGroup.Initialize(OnAddedCookTabSelected);
foreach (var selectedIngredient in _selectedIngredients)
{
selectedIngredient.Initialize();
}
}
public override void Open(OpenPopupUiEvent evt)
{
base.Open(evt);
if (evt.Payload is CookwareType cookwareType)
{
_viewModel.SetCookwareType(cookwareType);
}
_viewModel.CreateAddedCookItemSlot(_addedCookContent);
_viewModel.CreateIngredientInventoryItemSlot(_cookIngredientContent);
_addedCookTabGroup.SelectFirstTab();
IsInitialized = true;
}
protected override void OnOpenedEvents()
{
base.OnOpenedEvents();
_viewModel.OnAddedIngredients += OnAddedIngredients;
}
protected override void OnClosedEvents()
{
base.OnClosedEvents();
if (_viewModel)
{
_viewModel.OnAddedIngredients -= OnAddedIngredients;
}
}
protected override void SetupBindings()
{
base.SetupBindings();
BindingHelper.BindImage(_bindingContext, _cookwareImage, nameof(_viewModel.CookwareIcon));
BindingHelper.BindLocalizedStringEvent(_bindingContext, _cookwareName, nameof(_viewModel.CookwareName));
BindingHelper.BindLocalizedStringEvent<CookViewModel>(_bindingContext, _cookName, viewModel => viewModel.SelectedCookSnapshot.Name);
BindingHelper.BindLocalizedStringEvent<CookViewModel>(_bindingContext, _cookDescriptionName, viewModel => viewModel.SelectedCookSnapshot.Description);
BindingHelper.BindText<CookViewModel>(_bindingContext, _cookPrice, viewModel => viewModel.SelectedCookSnapshot.CookPrice);
BindingHelper.BindImage<CookViewModel>(_bindingContext, _cookImage, viewModel => viewModel.SelectedCookSnapshot.CookIcon);
}
protected override GameObject GetInitialSelected() protected override GameObject GetInitialSelected()
{ {
if (IsInitialized == false) return null; if (IsInitialized == false) return null;
@ -97,11 +37,49 @@ protected override GameObject GetInitialSelected()
return null; return null;
} }
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context) protected override void OnCreatedInitializePopup()
{ {
if (base.OnInputPerformed(actionEnum, context) == false) return false; _addedCookTabGroup.Initialize(OnAddedCookTabSelected);
foreach (var selectedIngredient in _selectedIngredients)
{
selectedIngredient.Initialize();
}
SetupBindings();
}
protected override void OnOpenedEventsPopup(OpenPopupUiEvent evt)
{
if (evt.Payload is CookwareType cookwareType)
{
_viewModel.SetCookwareType(cookwareType);
}
_viewModel.CreateAddedCookItemSlot(_addedCookContent);
_viewModel.CreateIngredientInventoryItemSlot(_cookIngredientContent);
_addedCookTabGroup.SelectFirstTab();
_viewModel.OnAddedIngredients += OnAddedIngredients;
}
protected override void OnClosedEventsPopup(ClosePopupUiEvent evt)
{
if (_viewModel)
{
_viewModel.OnAddedIngredients -= OnAddedIngredients;
}
}
protected override void OnInputStartedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
protected override void OnInputPerformedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
switch (actionEnum) switch (actionEnum)
{ {
case RestaurantUiActions.Cancel: case RestaurantUiActions.Cancel:
@ -110,9 +88,26 @@ protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAc
case RestaurantUiActions.Interact1: case RestaurantUiActions.Interact1:
HandleInteract1(); HandleInteract1();
break; break;
case RestaurantUiActions.Interact2:
HandleInteract2();
break;
} }
}
return true; protected override void OnInputCanceledPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
private void SetupBindings()
{
BindingHelper.BindImage(_bindingContext, _cookwareImage, nameof(_viewModel.CookwareIcon));
BindingHelper.BindLocalizedStringEvent(_bindingContext, _cookwareName, nameof(_viewModel.CookwareName));
BindingHelper.BindLocalizedStringEvent<CookViewModel>(_bindingContext, _cookName, viewModel => viewModel.SelectedCookSnapshot.Name);
BindingHelper.BindLocalizedStringEvent<CookViewModel>(_bindingContext, _cookDescriptionName, viewModel => viewModel.SelectedCookSnapshot.Description);
BindingHelper.BindText<CookViewModel>(_bindingContext, _cookPrice, viewModel => viewModel.SelectedCookSnapshot.CookPrice);
BindingHelper.BindImage<CookViewModel>(_bindingContext, _cookImage, viewModel => viewModel.SelectedCookSnapshot.CookIcon);
} }
private void HandleInteract1() private void HandleInteract1()
@ -122,6 +117,11 @@ private void HandleInteract1()
interactable?.OnInteract(); interactable?.OnInteract();
} }
private void HandleInteract2()
{
// TODO : 요리 선택 (미니게임 더미 연출)
}
private void OnAddedCookTabSelected(int index) private void OnAddedCookTabSelected(int index)
{ {
_viewModel.SetAddedCook(index); _viewModel.SetAddedCook(index);

View File

@ -35,65 +35,7 @@ protected override void Update()
_viewModel.UpdateHoldProgress(); _viewModel.UpdateHoldProgress();
} }
} }
protected override void OnCreatedInitialize()
{
base.OnCreatedInitialize();
InitializeViews();
InitializeTabGroups();
SetupCategoryTabs();
}
protected override void OnOpenedEvents()
{
base.OnOpenedEvents();
_sectionTabs.SelectFirstTab();
_menuCategoryTabs.SelectFirstTab();
if (_viewModel)
{
_viewModel.OnBatchCompleted += HandleBatchCompleted;
_viewModel.OnChecklistFailed += HandleChecklistFailed;
_viewModel.OnMenuSectionSelected += HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected += HandleCookwareSectionSelected;
_viewModel.OnTabMoved += HandleTabMoved;
_viewModel.OnInteractRequested += HandleInteractRequested;
_viewModel.OnCloseRequested += HandleCloseRequested;
_viewModel.OnMenuCategorySelected += HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnOpenedEvents();
}
IsInitialized = true;
}
protected override void OnClosedEvents()
{
base.OnClosedEvents();
if (_viewModel)
{
_viewModel.OnBatchCompleted -= HandleBatchCompleted;
_viewModel.OnChecklistFailed -= HandleChecklistFailed;
_viewModel.OnMenuSectionSelected -= HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected -= HandleCookwareSectionSelected;
_viewModel.OnTabMoved -= HandleTabMoved;
_viewModel.OnInteractRequested -= HandleInteractRequested;
_viewModel.OnCloseRequested -= HandleCloseRequested;
_viewModel.OnMenuCategorySelected -= HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnClosedEvents();
}
}
protected override GameObject GetInitialSelected() protected override GameObject GetInitialSelected()
{ {
if (IsInitialized == false) return null; if (IsInitialized == false) return null;
@ -118,11 +60,97 @@ protected override GameObject GetInitialSelected()
return null; return null;
} }
protected override void SetupBindings() protected override void OnCreatedInitializePopup()
{ {
base.SetupBindings(); InitializeViews();
InitializeTabGroups();
SetupCategoryTabs();
SetupBindings();
}
protected override void OnOpenedEventsPopup(OpenPopupUiEvent evt)
{
_sectionTabs.SelectFirstTab();
_menuCategoryTabs.SelectFirstTab();
if (_viewModel)
{
_viewModel.OnBatchCompleted += HandleBatchCompleted;
_viewModel.OnChecklistFailed += HandleChecklistFailed;
_viewModel.OnMenuSectionSelected += HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected += HandleCookwareSectionSelected;
_viewModel.OnTabMoved += HandleTabMoved;
_viewModel.OnInteractRequested += HandleInteractRequested;
_viewModel.OnCloseRequested += HandleCloseRequested;
_viewModel.OnMenuCategorySelected += HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnOpenedEvents();
}
}
protected override void OnClosedEventsPopup(ClosePopupUiEvent evt)
{
if (_viewModel)
{
_viewModel.OnBatchCompleted -= HandleBatchCompleted;
_viewModel.OnChecklistFailed -= HandleChecklistFailed;
_viewModel.OnMenuSectionSelected -= HandleMenuSectionSelected;
_viewModel.OnCookwareSectionSelected -= HandleCookwareSectionSelected;
_viewModel.OnTabMoved -= HandleTabMoved;
_viewModel.OnInteractRequested -= HandleInteractRequested;
_viewModel.OnCloseRequested -= HandleCloseRequested;
_viewModel.OnMenuCategorySelected -= HandleMenuCategorySelected;
}
foreach (var view in _subViews)
{
view.OnClosedEvents();
}
}
protected override void OnInputStartedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
}
protected override void OnInputPerformedPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
switch (actionEnum)
{
case RestaurantUiActions.Cancel:
_viewModel.CloseUi();
break;
case RestaurantUiActions.PreviousTab:
_viewModel.MoveTab(-1);
break;
case RestaurantUiActions.NextTab:
_viewModel.MoveTab(1);
break;
case RestaurantUiActions.Interact1:
_viewModel.InteractWithSelected();
break;
case RestaurantUiActions.Interact2:
_viewModel.StartHold();
break;
}
}
protected override void OnInputCanceledPopup(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
switch (actionEnum)
{
case RestaurantUiActions.Interact2:
_viewModel.CancelHold();
break;
}
}
private void SetupBindings()
{
BindingHelper.BindImageFilled(_bindingContext, _completeBatchFilledImage, nameof(RestaurantManagementViewModel.NormalizedHoldProgress)); BindingHelper.BindImageFilled(_bindingContext, _completeBatchFilledImage, nameof(RestaurantManagementViewModel.NormalizedHoldProgress));
_itemDetailView.SetupBindings(_bindingContext); _itemDetailView.SetupBindings(_bindingContext);
@ -191,8 +219,7 @@ protected override void HandleCustomPropertyChanged(string propertyName)
break; break;
} }
} }
// ViewModel 이벤트 핸들러들
private void HandleBatchCompleted() private void HandleBatchCompleted()
{ {
Close(); Close();
@ -239,8 +266,7 @@ private void HandleMenuCategorySelected(InventoryCategoryType category)
{ {
_menuCategoryTabs.SelectTab((int)category); _menuCategoryTabs.SelectTab((int)category);
} }
// UI 이벤트 핸들러들 (TabGroupUi 콜백)
private void OnSectionTabSelected(int sectionValue) private void OnSectionTabSelected(int sectionValue)
{ {
_viewModel?.SetSection((SectionButtonType)sectionValue); _viewModel?.SetSection((SectionButtonType)sectionValue);
@ -250,46 +276,5 @@ private void OnCategoryTabSelected(int categoryValue)
{ {
_viewModel?.SetCategory((InventoryCategoryType)categoryValue); _viewModel?.SetCategory((InventoryCategoryType)categoryValue);
} }
// 입력 처리 - ViewModel로 위임
protected override bool OnInputPerformed(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
if (base.OnInputPerformed(actionEnum, context) == false) return false;
switch (actionEnum)
{
case RestaurantUiActions.Cancel:
_viewModel.CloseUi();
break;
case RestaurantUiActions.PreviousTab:
_viewModel.MoveTab(-1);
break;
case RestaurantUiActions.NextTab:
_viewModel.MoveTab(1);
break;
case RestaurantUiActions.Interact1:
_viewModel.InteractWithSelected();
break;
case RestaurantUiActions.Interact2:
_viewModel.StartHold();
break;
}
return true;
}
protected override bool OnInputCanceled(RestaurantUiActions actionEnum, InputAction.CallbackContext context)
{
if (base.OnInputPerformed(actionEnum, context) == false) return false;
switch (actionEnum)
{
case RestaurantUiActions.Interact2:
_viewModel.CancelHold();
break;
}
return true;
}
} }
} }