Files
HDRobotics/Assets/Scripts/View/PopupView.cs
2025-10-30 09:31:05 +09:00

77 lines
2.6 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
// 팝업 응답 타입
public enum PopupResponse
{
Confirm, // 확정
Cancel, // 취소
Option1, // (예: 여기로 이동)
Option2 // (예: 삭제)
}
public interface IPopupView
{
event Action<PopupResponse> OnPopupResponse;
void ShowConfirmPopup(string title, string message); // 2, 5단계용 (확정/취소)
void ShowOptionPopup(string title, string message, string opt1Text, string opt2Text); // 8단계용 (이동/삭제)
void HidePopup();
}
public class PopupView : MonoBehaviour, IPopupView
{
public event Action<PopupResponse> OnPopupResponse;
[SerializeField] private GameObject popupPanel;
[SerializeField] private TextMeshProUGUI titleText;
[SerializeField] private TextMeshProUGUI messageText;
[SerializeField] private Button confirmButton; // '확정' 버튼
[SerializeField] private Button cancelButton; // '취소' 버튼
[SerializeField] private Button option1Button; // '옵션1(이동)' 버튼
[SerializeField] private Button option2Button; // '옵션2(삭제)' 버튼
void Start()
{
// 각 버튼이 클릭되면 Presenter에게 응답 이벤트를 보냄
confirmButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Confirm));
cancelButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Cancel));
option1Button.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Option1));
option2Button.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Option2));
popupPanel.SetActive(false);
}
public void ShowConfirmPopup(string title, string message)
{
titleText.text = title;
messageText.text = message;
confirmButton.gameObject.SetActive(true);
cancelButton.gameObject.SetActive(true);
option1Button.gameObject.SetActive(false);
option2Button.gameObject.SetActive(false);
popupPanel.SetActive(true);
}
public void ShowOptionPopup(string title, string message, string opt1Text, string opt2Text)
{
titleText.text = title;
messageText.text = message;
option1Button.GetComponentInChildren<Text>().text = opt1Text;
option2Button.GetComponentInChildren<Text>().text = opt2Text;
confirmButton.gameObject.SetActive(false);
cancelButton.gameObject.SetActive(true); // 취소 버튼은 공용으로 사용
option1Button.gameObject.SetActive(true);
option2Button.gameObject.SetActive(true);
popupPanel.SetActive(true);
}
public void HidePopup()
{
popupPanel.SetActive(false);
}
}