using System; using BrewMonster.UI; using PerfectWorld.Scripts.Common; using UnityEngine; using TMPro; using UnityEngine.Serialization; 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 _yesButton; [SerializeField] private Button _noButton; [SerializeField] private Button _closeButton; private Action _onClickedYesBtn; private Action _onClickedNoBtn; private MessageBoxData _messageData; public override void OnEnable() { base.OnEnable(); _yesButton.onClick.AddListener(OnYesClicked); _noButton.onClick.AddListener(OnNoClicked); _closeButton.onClick.AddListener(OnCloseClicked); } public override void OnDisable() { _yesButton.onClick.RemoveListener(OnYesClicked); _noButton.onClick.RemoveListener(OnNoClicked); _closeButton.onClick.RemoveListener(OnCloseClicked); } #region Button Events private void OnYesClicked() { EventBus.Publish(new MessageBoxEvent(1,_messageData.Dlg)); _onClickedYesBtn?.Invoke(); Show(false); } private void OnNoClicked() { EventBus.Publish(new MessageBoxEvent(0,_messageData.Dlg)); _messageData.OnClickedNo?.Invoke(); _onClickedNoBtn?.Invoke(); Show(false); } private void OnCloseClicked() { Show(false); // treat the close button as OK button //OnYesClicked(); } #endregion // public void ShowMessageBox(MessageBoxData messageBoxData) // { // _messageData = messageBoxData; // messageBoxData.Message = EC_TextFormatter.FormatForTextMeshPro(messageBoxData.Message); // SetName(string.IsNullOrEmpty(messageBoxData.Title) ? "" : messageBoxData.Title); // messageText.text = string.IsNullOrEmpty(messageBoxData.Message) ? "" : messageBoxData.Message; // // _yesButton.gameObject.SetActive(false); // _noButton.gameObject.SetActive(false); // switch (_messageData.MessageBoxType) // { // case MessageBoxType.YesButton: // _yesButton.gameObject.SetActive(true); // break; // case MessageBoxType.NoButton: // _noButton.gameObject.SetActive(true); // break; // case MessageBoxType.BothYesNoButton: // _yesButton.gameObject.SetActive(true); // _noButton.gameObject.SetActive(true); // break; // } // Show(true); // } /// /// message with title and message only /// /// /// /// public void ShowMessageBoxGeneral(string title, string message, AUIDialog dlg) { _onClickedYesBtn = null; _onClickedYesBtn = null; string formattedMessage = EC_TextFormatter.FormatForTextMeshPro(message); SetName(string.IsNullOrEmpty(title) ? "" : title); messageText.text = string.IsNullOrEmpty(formattedMessage) ? "" : formattedMessage; _noButton.gameObject.SetActive(false); _yesButton.gameObject.SetActive(true); Show(true); transform.SetAsLastSibling(); } /// /// message with yes button only /// /// /// /// /// public void ShowMessageBoxYes(string title, string message, AUIDialog dlg, Action onClickedYes) { _onClickedYesBtn = onClickedYes; string formattedMessage = EC_TextFormatter.FormatForTextMeshPro(message); SetName(string.IsNullOrEmpty(title) ? "" : title); messageText.text = string.IsNullOrEmpty(formattedMessage) ? "" : formattedMessage; _noButton.gameObject.SetActive(false); _yesButton.gameObject.SetActive(true); Show(true); transform.SetAsLastSibling(); } /// /// message with no button only /// /// /// /// /// public void ShowMessageBoxNo(string title, string message, AUIDialog dlg, Action onClickedNo) { _onClickedNoBtn = onClickedNo; string formattedMessage = EC_TextFormatter.FormatForTextMeshPro(message); SetName(string.IsNullOrEmpty(title) ? "" : title); messageText.text = string.IsNullOrEmpty(formattedMessage) ? "" : formattedMessage; _yesButton.gameObject.SetActive(false); _noButton.gameObject.SetActive(true); Show(true); transform.SetAsLastSibling(); } /// /// message with yes and no button /// /// /// /// /// /// public void ShowMessageBoxYesAndNo(string title, string message, AUIDialog dlg, Action onClickedYes, Action onClickedNo) { _onClickedYesBtn = onClickedYes; _onClickedNoBtn = onClickedNo; string formattedMessage = EC_TextFormatter.FormatForTextMeshPro(message); SetName(string.IsNullOrEmpty(title) ? "" : title); messageText.text = string.IsNullOrEmpty(formattedMessage) ? "" : formattedMessage; _yesButton.gameObject.SetActive(true); _noButton.gameObject.SetActive(true); Show(true); transform.SetAsLastSibling(); } } }