Пример #1
0
 /// <summary>
 /// Show the message box with caption and buttons.
 /// </summary>
 /// <param name="id">Message Box ID</param>
 /// <param name="message">Message.</param>
 /// <param name="caption">Caption.</param>
 /// <param name="buttons">Buttons.</param>
 /// <param name="style">Style of message box</param>
 /// <param name="method">Called method with result</param>
 /// <param name="modal">if <c>true</c> then blocked other GUI elements</param>
 /// <param name="btnText0">Text for button Yes/Ok. "" - use default value</param>
 /// <param name="btnText1">Text for button No. "" - use default value</param>
 /// <param name="btnText2">Text for button Cancel. "" - use default value</param>
 private static void Show(int id, string message, string caption, MsgBoxButtons buttons, MSGBoxStyle style, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
 {
     Close();
     _lastMsgBox = Instantiate(prefab);
     _lastMsgBox.BuildMessageBox(id, message, caption, buttons, style, method, modal, btnText0, btnText1, btnText2);
     if (EventSystem.current == null)
     {
         _lastMsgBox._eventer.SetActive(true);
     }
 }
Пример #2
0
 /// <summary>
 /// Show the message box with caption.
 /// </summary>
 /// <param name="id">Message Box ID</param>
 /// <param name="message">Message.</param>
 /// <param name="caption">Caption.</param>
 /// <param name="buttons">Buttons.</param>
 /// <param name="customStyleID">ID custom style.</param>
 /// <param name="method">Called method with result</param>
 /// <param name="modal">if <c>true</c> then blocked other GUI elements</param>
 /// <param name="btnText0">Text for button Yes/Ok. "" - use default value</param>
 /// <param name="btnText1">Text for button No. "" - use default value</param>
 /// <param name="btnText2">Text for button Cancel. "" - use default value</param>
 public static void Show(int id, string message, string caption, MsgBoxButtons buttons, int customStyleID, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
 {
     if (customStyleID < 0 || customStyleID >= prefab._customStyles.Count)
     {
         Debug.LogError("Custom style not found by ID");
         return;
     }
     Show(id, message, caption, buttons, prefab._customStyles[customStyleID], method, modal, btnText0, btnText1, btnText2);
 }
Пример #3
0
 /// <summary>
 /// Show the message box with caption.
 /// </summary>
 /// <param name="id">Message Box ID</param>
 /// <param name="message">Message.</param>
 /// <param name="caption">Caption.</param>
 /// <param name="buttons">Buttons.</param>
 /// <param name="style">Message Box Style.</param>
 /// <param name="method">Called method with result</param>
 /// <param name="modal">if <c>true</c> then blocked other GUI elements</param>
 /// <param name="btnText0">Text for button Yes/Ok. "" - use default value</param>
 /// <param name="btnText1">Text for button No. "" - use default value</param>
 /// <param name="btnText2">Text for button Cancel. "" - use default value</param>
 public static void Show(int id, string message, string caption, MsgBoxButtons buttons, MsgBoxStyle style, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
 {
     Show(id, message, caption, buttons, GetStyle(style), method, modal, btnText0, btnText1, btnText2);
 }
Пример #4
0
 /// <summary>
 /// Show the message box with caption.
 /// </summary>
 /// <param name="id">Message Box ID</param>
 /// <param name="message">Message.</param>
 /// <param name="caption">Caption.</param>
 /// <param name="method">Called method with result</param>
 /// <param name="modal">if <c>true</c> then blocked other GUI elements</param>
 /// <param name="btnText0">Text for button Yes/Ok. "" - use default value</param>
 /// <param name="btnText1">Text for button No. "" - use default value</param>
 /// <param name="btnText2">Text for button Cancel. "" - use default value</param>
 public static void Show(int id, string message, string caption, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
 {
     Show(id, message, caption, MsgBoxButtons.OK, MsgBoxStyle.Information, method, modal, btnText0, btnText1, btnText2);
 }
Пример #5
0
        /// <summary>
        /// Генерация окна сообщения.
        /// </summary>
        /// <param name="mess">Сообщение.</param>
        /// <param name="caption">Заголовок.</param>
        /// <param name="btns">Кнопки.</param>
        /// <param name="style">Стиль.</param>
        /// <param name="btnText0">Текст кнопки "Да"/"Ок".</param>
        /// <param name="btnText1">Текст кнопки "Нет".</param>
        /// <param name="btnText2">Текст кнопки "Отмена".</param>
        private void BuildMessageBox(int id, string mess, string caption, MsgBoxButtons btns, MSGBoxStyle style, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
        {
            //Сохраняем ID
            messageID = id;
            //Статус блокировки других GUI
            _blockPanel.SetActive(modal);
            //Сохранение метода
            calledMethod = method;
            //Устанавливаем заголовок
            this._captionText.text = caption;
            //Устанавливаем сообщение
            this._mainText.text = mess;
            //Устанавливаем цвет заголовка
            this._captionImg.color = style.captionColor;
            //Устанавливаем цвет фона
            this._backgroundImg.color = style.backgroundColor;
            //Устанавливаем цвет кнопок
            this._btnYesImg.color    = style.btnYesColor;
            this._btnNoImg.color     = style.btnNoColor;
            this._btnCancelImg.color = style.btnCancelColor;
            //Устанавливаем иконку
            this._iconImg.sprite = style.icon;
            //Устанавливаем размер
            Vector2 mainSize = new Vector2(Mathf.Clamp(Mathf.Max(_captionText.preferredWidth, 150 + _mainText.preferredWidth), 256, Screen.width), Mathf.Clamp(_mainText.preferredHeight, 256, Screen.height));
            //this._mainPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, mainSize.x);
            //this._mainPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y);

            RectTransform btnTr;
            Text          btnText;
            float         cancelW;
            float         noW;

            //Устанавливаем нужные кнопки
            switch (btns)
            {
            //Кнопка "Ок"
            case MsgBoxButtons.OK:
                //Получаем рект кнопки "Ок"
                btnTr = _btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-25.0f, -46.46f);
                //Получаем элемент "текст"
                btnText = _btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                // btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 20, 70, mainSize.x / 2 - 30));
                //btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Отключаем кнопку "Нет"
                _btnNoImg.gameObject.SetActive(false);
                //Отключаем кнопку "Отмена"
                _btnCancelImg.gameObject.SetActive(false);
                break;

            //Кнопки "Ок" и "Отмена"
            case MsgBoxButtons.OK_CANCEL:
                //Получаем элемент "текст"
                btnText = _btnCancelImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText2 == "") ? "Cancel" : btnText2;
                //Получаем рект кнопки "Отмена"
                btnTr = _btnCancelImg.rectTransform;
                //Устанавливаем размер
                cancelW = Mathf.Clamp(btnText.preferredWidth + 20, 70, mainSize.x / 2 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cancelW);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-25.0f, -46.46f);
                //Получаем рект кнопки "Ок"
                btnTr = _btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-(20.0f + cancelW), -46.46f);
                //Получаем элемент "текст"
                btnText = _btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 20, 70, mainSize.x / 2 - 30));
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Отключаем кнопку "Нет"
                _btnNoImg.gameObject.SetActive(false);
                break;

            //Кнопки "Да" и "Нет"
            case MsgBoxButtons.YES_NO:
                //Получаем элемент "текст"
                btnText = _btnNoImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText1 == "") ? "No" : btnText1;
                //Получаем рект кнопки "Нет"
                btnTr = _btnNoImg.rectTransform;
                //Устанавливаем размер
                noW = Mathf.Clamp(btnText.preferredWidth + 20, 70, mainSize.x / 2 - 30);
                //btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, noW);
                //btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-25.0f, -46.46f);
                //Получаем рект кнопки "Ок"
                btnTr = _btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-165, -46.46f);
                //Получаем элемент "текст"
                btnText = _btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Yes" : btnText0;
                //Устанавливаем размер
                //btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 20, 70, mainSize.x / 2 - 30));
                //btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Отключаем кнопку "Отмена"
                _btnCancelImg.gameObject.SetActive(false);
                break;

            case MsgBoxButtons.YES_NO_CANCEL:
                //Получаем элемент "текст"
                btnText = _btnCancelImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText2 == "") ? "Cancel" : btnText2;
                //Получаем рект кнопки "Отмена"
                btnTr = _btnCancelImg.rectTransform;
                //Устанавливаем размер
                cancelW = Mathf.Clamp(btnText.preferredWidth + 20, 35, mainSize.x / 3 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cancelW);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-25.0f, -46.46f);
                //Получаем элемент "текст"
                btnText = _btnNoImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText1 == "") ? "No" : btnText1;
                //Получаем рект кнопки "Нет"
                btnTr = _btnNoImg.rectTransform;
                //Устанавливаем размер
                noW = Mathf.Clamp(btnText.preferredWidth + 20, 35, mainSize.x / 3 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, noW);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                btnTr.anchoredPosition = new Vector2(-(20.0f + cancelW), -46.46f);
                //Получаем рект кнопки "Ок"
                btnTr = _btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-(30.0f + cancelW + noW), -46.46f);
                //Получаем элемент "текст"
                btnText = _btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 20, 35, mainSize.x / 3 - 30));
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mainSize.y * 0.2f);
                break;

            default:
                break;
            }
        }
Пример #6
0
        /// <summary>
        /// Генерация окна сообщения.
        /// </summary>
        /// <param name="mess">Сообщение.</param>
        /// <param name="caption">Заголовок.</param>
        /// <param name="btns">Кнопки.</param>
        /// <param name="style">Стиль.</param>
        /// <param name="btnText0">Текст кнопки "Да"/"Ок".</param>
        /// <param name="btnText1">Текст кнопки "Нет".</param>
        /// <param name="btnText2">Текст кнопки "Отмена".</param>
        public void BuildMessageBox(int id, string mess, string caption, MsgBoxButtons btns, MsgBoxStyle style, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
        {
            //Сохраняем ID
            messageID = id;
            //Статус блокировки других GUI
            blockPanel.SetActive(modal);
            //Сохранение метода
            calledMethod = method;
            //Узнаём ID стиля
            int styleId = (int)style;

            //Устанавливаем заголовок
            this.captionText.text = caption;
            //Устанавливаем сообщение
            this.mainText.text = mess;
            //Устанавливаем цвет заголовка
            this.captionImg.color = boxStyles[styleId].caption;
            //Устанавливаем цвет фона
            this.backgroundImg.color = boxStyles[styleId].background;
            //Устанавливаем цвет кнопок
            this.btnYesImg.color    = boxStyles[styleId].btnYesColor;
            this.btnNoImg.color     = boxStyles[styleId].btnNoColor;
            this.btnCancelImg.color = boxStyles[styleId].btnCancelColor;
            //Устанавливаем иконку
            this.iconImg.sprite = boxStyles[styleId].icon;
            //Устанавливаем размер
            this.mainPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(Mathf.Max(captionText.preferredWidth, 150 + mainText.preferredWidth), 512, canvasRect.rect.width));
            this.mainPanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Mathf.Clamp(mainText.preferredHeight, 256, canvasRect.rect.height));

            RectTransform btnTr;
            Text          btnText;
            float         cancelW;
            float         noW;

            //Устанавливаем нужные кнопки
            switch (btns)
            {
            //Кнопка "Ок"
            case MsgBoxButtons.OK:
                //Получаем рект кнопки "Ок"
                btnTr = btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-10.0f, -10.0f);
                //Получаем элемент "текст"
                btnText = btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 2 - 30));
                //Отключаем кнопку "Нет"
                btnNoImg.gameObject.SetActive(false);
                //Отключаем кнопку "Отмена"
                btnCancelImg.gameObject.SetActive(false);
                break;

            //Кнопки "Ок" и "Отмена"
            case MsgBoxButtons.OK_CANCEL:
                //Получаем элемент "текст"
                btnText = btnCancelImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText2 == "") ? "Cancel" : btnText2;
                //Получаем рект кнопки "Отмена"
                btnTr = btnCancelImg.rectTransform;
                //Устанавливаем размер
                cancelW = Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 3 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cancelW);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-10, -10);
                //Получаем рект кнопки "Ок"
                btnTr = btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-(20.0f + cancelW), -10.0f);
                //Получаем элемент "текст"
                btnText = btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 2 - 30));
                //Отключаем кнопку "Нет"
                btnNoImg.gameObject.SetActive(false);
                break;

            //Кнопки "Да" и "Нет"
            case MsgBoxButtons.YES_NO:
                //Получаем элемент "текст"
                btnText = btnNoImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText1 == "") ? "No" : btnText1;
                //Получаем рект кнопки "Нет"
                btnTr = btnNoImg.rectTransform;
                //Устанавливаем размер
                noW = Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 2 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, noW);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-10, -10);
                //Получаем рект кнопки "Ок"
                btnTr = btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-(20.0f + noW), -10.0f);
                //Получаем элемент "текст"
                btnText = btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Yes" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 2 - 30));
                //Отключаем кнопку "Отмена"
                btnCancelImg.gameObject.SetActive(false);
                break;

            case MsgBoxButtons.YES_NO_CANCEL:
                //Получаем элемент "текст"
                btnText = btnCancelImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText2 == "") ? "Cancel" : btnText2;
                //Получаем рект кнопки "Отмена"
                btnTr = btnCancelImg.rectTransform;
                //Устанавливаем размер
                cancelW = Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 3 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cancelW);
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-10, -10);
                //Получаем элемент "текст"
                btnText = btnNoImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText1 == "") ? "No" : btnText1;
                //Получаем рект кнопки "Нет"
                btnTr = btnNoImg.rectTransform;
                //Устанавливаем размер
                noW = Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 3 - 30);
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, noW);
                btnTr.anchoredPosition = new Vector2(-(20.0f + cancelW), -10);
                //Получаем рект кнопки "Ок"
                btnTr = btnYesImg.rectTransform;
                //Устанавливаем позицию
                btnTr.anchoredPosition = new Vector2(-(30.0f + cancelW + noW), -10.0f);
                //Получаем элемент "текст"
                btnText = btnYesImg.GetComponentInChildren <Text>();
                //Устанавливаем текст
                btnText.text = (btnText0 == "") ? "Ok" : btnText0;
                //Устанавливаем размер
                btnTr.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Clamp(btnText.preferredWidth + 10, 130, mainPanel.rect.width / 3 - 30));
                break;

            default:
                break;
            }
        }
Пример #7
0
        /// <summary>
        /// Show the message box with caption and buttons.
        /// </summary>
        /// <param name="id">Message Box ID</param>
        /// <param name="message">Message.</param>
        /// <param name="caption">Caption.</param>
        /// <param name="buttons">Buttons.</param>
        /// <param name="style">Style of message box</param>
        /// <param name="method">Called method with result</param>
        /// <param name="modal">if <c>true</c> then blocked other GUI elements</param>
        /// <param name="btnText0">Text for button Yes/Ok. "" - use default value</param>
        /// <param name="btnText1">Text for button No. "" - use default value</param>
        /// <param name="btnText2">Text for button Cancel. "" - use default value</param>
        public static void Show(int id, string message, string caption, MsgBoxButtons buttons, MsgBoxStyle style, DialogResultMethod method, bool modal = false, string btnText0 = "", string btnText1 = "", string btnText2 = "")
        {
            Close();
            _lastMsgBox = (GameObject)Instantiate(Resources.Load("PXMSG/MSG"));
            MsgBox box = _lastMsgBox.GetComponent <MsgBox>();

            box.BuildMessageBox(id, message, caption, buttons, style, method, modal, btnText0, btnText1, btnText2);
            if (EventSystem.current == null)
            {
                box.eventer.SetActive(true);
            }
        }