98 lines
2.9 KiB
C#
98 lines
2.9 KiB
C#
using System;
|
|
using BrewMonster.UI;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
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 TMP_Text titleText;
|
|
[SerializeField] private TMP_Text messageText;
|
|
[SerializeField] private Button okButton;
|
|
[SerializeField] private Button _noButton;
|
|
[SerializeField] private Button _closeButton;
|
|
|
|
private MessageBoxData _messageData;
|
|
|
|
public override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
okButton.onClick.AddListener(OnOkClicked);
|
|
_noButton.onClick.AddListener(OnNoClicked);
|
|
_closeButton.onClick.AddListener(OnCloseClicked);
|
|
|
|
}
|
|
|
|
public override void OnDisable()
|
|
{
|
|
okButton.onClick.RemoveListener(OnOkClicked);
|
|
_noButton.onClick.RemoveListener(OnNoClicked);
|
|
_closeButton.onClick.RemoveListener(OnCloseClicked);
|
|
}
|
|
|
|
#region Button Events
|
|
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);
|
|
}
|
|
|
|
private void OnCloseClicked()
|
|
{
|
|
// treat the close button as OK button
|
|
OnOkClicked();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void ShowMessageBox(MessageBoxData messageBoxData)
|
|
{
|
|
_messageData = messageBoxData;
|
|
SetName(string.IsNullOrEmpty(messageBoxData.Title) ? "" : messageBoxData.Title);
|
|
messageText.text = string.IsNullOrEmpty(messageBoxData.Message) ? "" : 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);
|
|
}
|
|
}
|
|
}
|