96 lines
2.6 KiB
C#
96 lines
2.6 KiB
C#
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
|
|
|
using System;
|
|
using FairyGUI;
|
|
using UnityEngine;
|
|
using NBC;
|
|
using UIPanel = NBC.UIPanel;
|
|
|
|
namespace NBF
|
|
{
|
|
public partial class MessageBox : UIPanel
|
|
{
|
|
public override string UIPackName => "Common";
|
|
public override string UIResName => "MessageBox";
|
|
|
|
private static string _confirmText;
|
|
private static string _cancelText;
|
|
private static string _title;
|
|
private static string _content;
|
|
private static Action<bool> _callback;
|
|
private static int _style;
|
|
|
|
public static void Show(string msg, Action<bool> callback, string title = "", int style = 0,
|
|
string confirm = "", string cancel = "")
|
|
{
|
|
if (string.IsNullOrEmpty(title))
|
|
{
|
|
title = Lan.Get("TEXT_NOTE");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(confirm))
|
|
{
|
|
confirm = Lan.Get("TEXT_CONFIRM");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(cancel))
|
|
{
|
|
cancel = Lan.Get("TEXT_CANCEL");
|
|
}
|
|
|
|
_confirmText = confirm;
|
|
_cancelText = cancel;
|
|
_callback = callback;
|
|
_content = msg;
|
|
_title = title;
|
|
_style = style;
|
|
UI.Inst.OpenUI<MessageBox>();
|
|
}
|
|
|
|
protected override void OnInit()
|
|
{
|
|
this.AutoAddClick(OnClick);
|
|
ShowAnim = UIPanelAnimation.GetCenterScaleBig(this);
|
|
HideAnim = UIPanelAnimation.GetCenterScaleBig(this, true);
|
|
IsModal = true;
|
|
IsDontBack = true;
|
|
InputManager.OnUICanceled += OnUICanceled;
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
TextTitle.text = _title;
|
|
BtnConfirm.title = _confirmText;
|
|
BtnCancel.title = _cancelText;
|
|
TextContent.text = _content;
|
|
MessageStyle.selectedIndex = _style;
|
|
}
|
|
|
|
private void OnUICanceled(string action)
|
|
{
|
|
if (!IsShowing) return;
|
|
if (!IsTop) return;
|
|
if (action == InputDef.UI.Enter)
|
|
{
|
|
OnClick(BtnConfirm);
|
|
}
|
|
else if (action == InputDef.UI.Back)
|
|
{
|
|
OnClick(BtnCancel);
|
|
}
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
InputManager.OnUICanceled -= OnUICanceled;
|
|
}
|
|
|
|
|
|
private void OnClick(GComponent btn)
|
|
{
|
|
_callback?.Invoke(btn == BtnConfirm);
|
|
Hide();
|
|
}
|
|
}
|
|
} |