82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System;
|
|
using BrewMonster.UI;
|
|
using UnityEngine;
|
|
using static CECUIManager;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public enum MessageBoxType
|
|
{
|
|
YesButton,
|
|
NoButton,
|
|
BothYesNoButton,
|
|
}
|
|
public struct MessageBoxData
|
|
{
|
|
public string Title;
|
|
public string Message;
|
|
public AUIDialog Dlg;
|
|
public MessageBoxType MessageBoxType;
|
|
public Action OnClickedYes;
|
|
public Action OnClickedNo;
|
|
}
|
|
public class CDlgMessageBox : AUIDialog
|
|
{
|
|
[SerializeField] private TMPro.TextMeshProUGUI titleText;
|
|
[SerializeField] private TMPro.TextMeshProUGUI messageText;
|
|
[SerializeField] private UnityEngine.UI.Button okButton;
|
|
[SerializeField] private UnityEngine.UI.Button _noButton;
|
|
|
|
private MessageBoxData _messageData;
|
|
|
|
public override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
okButton.onClick.AddListener(OnOkClicked);
|
|
_noButton.onClick.AddListener(OnNoClicked);
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
okButton.onClick.RemoveListener(OnOkClicked);
|
|
_noButton.onClick.RemoveListener(OnNoClicked);
|
|
}
|
|
|
|
private void OnOkClicked()
|
|
{
|
|
EventBus.Publish(new MessageBoxEvent(1,_messageData.Dlg));
|
|
_messageData.OnClickedYes?.Invoke();
|
|
Show(false);
|
|
}
|
|
private void OnNoClicked()
|
|
{
|
|
EventBus.Publish(new MessageBoxEvent(0,_messageData.Dlg));
|
|
_messageData.OnClickedNo?.Invoke();
|
|
Show(false);
|
|
}
|
|
public void ShowMessageBox(MessageBoxData messageBoxData)
|
|
{
|
|
_messageData = messageBoxData;
|
|
SetName(messageBoxData.Title);
|
|
messageText.text = messageBoxData.Message;
|
|
|
|
okButton.gameObject.SetActive(false);
|
|
_noButton.gameObject.SetActive(false);
|
|
switch (_messageData.MessageBoxType)
|
|
{
|
|
case MessageBoxType.YesButton:
|
|
okButton.gameObject.SetActive(true);
|
|
break;
|
|
case MessageBoxType.NoButton:
|
|
_noButton.gameObject.SetActive(true);
|
|
break;
|
|
case MessageBoxType.BothYesNoButton:
|
|
okButton.gameObject.SetActive(true);
|
|
_noButton.gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
Show(true);
|
|
}
|
|
}
|
|
}
|