first commit
This commit is contained in:
71
Assets/Scripts/UI/MessageBox.cs
Normal file
71
Assets/Scripts/UI/MessageBox.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
using System;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
using NBC;
|
||||
using UIPanel = NBC.UIPanel;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class MessageBox : UIPanel
|
||||
{
|
||||
private static string _confirmText;
|
||||
private static string _cancelText;
|
||||
private static string _title;
|
||||
private static string _content;
|
||||
private static Action<bool> _callback = null;
|
||||
private static int _style;
|
||||
|
||||
public static void ShowMessage(string msg, Action<bool> callback, string title = "", int style = 0,
|
||||
string confirmText = "", string cancelText = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(title))
|
||||
{
|
||||
title = "提示";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(confirmText))
|
||||
{
|
||||
confirmText = "确定";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(cancelText))
|
||||
{
|
||||
cancelText = "取消";
|
||||
}
|
||||
|
||||
_confirmText = confirmText;
|
||||
_cancelText = cancelText;
|
||||
_callback = callback;
|
||||
_content = msg;
|
||||
_title = title;
|
||||
_style = style;
|
||||
UI.Inst.OpenUI<MessageBox>();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
this.AutoAddClick(OnClick);
|
||||
IsModal = true;
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
// Modal.SetTitle(_title);
|
||||
TextTitle.text = _title;
|
||||
BtnConfirm.title = _confirmText;
|
||||
BtnCancel.title = _cancelText;
|
||||
TextDesc.text = _content;
|
||||
MessageStyle.selectedIndex = _style;
|
||||
}
|
||||
|
||||
private void OnClick(GComponent btn)
|
||||
{
|
||||
var ret = btn == BtnConfirm;
|
||||
UI.Inst.DestroyUI<MessageBox>();
|
||||
_callback?.Invoke(ret);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user