93 lines
2.5 KiB
C#
93 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
using XFramework;
|
|
|
|
//一个通用的提示窗口 会遮挡其他界面 需关闭后才能操作其他界面
|
|
//初始化可注入显示内容和确定按钮的事件
|
|
//点击本界面关闭按钮时 隐藏本窗口 不做任何逻辑
|
|
//点击确认按钮时 会执行外界传入的确定事件
|
|
public class PromptWindows : BasePanel
|
|
{
|
|
const string windowName = "Panel_promptWindow";
|
|
Text text_msg;
|
|
UnityAction buttonSure;
|
|
public PromptWindows() : base(new UIType(windowName))
|
|
{
|
|
|
|
}
|
|
|
|
protected override void InitEvent()
|
|
{
|
|
text_msg = ActivePanel.GetComponentInChildren<Text>();
|
|
ActivePanel.FindChildTrans("Button_sure").GetComponentInChildren<Button>().onClick.AddListener(SureButtonOn);
|
|
ActivePanel.FindChildTrans("Button_Close").GetComponentInChildren<Button>().onClick.AddListener(CloseButtonOn);
|
|
|
|
}
|
|
|
|
|
|
public override void Change(object newData)
|
|
{
|
|
PromptWindowInitData initData = (PromptWindowInitData)newData;
|
|
if (!string.IsNullOrEmpty(initData.formatKey))
|
|
{
|
|
LocalizationManager.SetFormatted(text_msg, initData.formatKey, initData.formatArgs);
|
|
}
|
|
else
|
|
{
|
|
ShowPromptWindow(initData.showMsg);
|
|
}
|
|
buttonSure = initData.buttonSure;//注册确定事件
|
|
}
|
|
|
|
|
|
void ShowPromptWindow(string value)
|
|
{
|
|
// If the value is already localized (from Format/Get), set directly.
|
|
// RefreshAll will handle re-translation if the source key is found.
|
|
text_msg.text = value;
|
|
}
|
|
|
|
private void CloseButtonOn()
|
|
{
|
|
ClosePanel();
|
|
}
|
|
|
|
//确定事件
|
|
public void SureButtonOn()
|
|
{
|
|
ClosePanel();
|
|
buttonSure?.Invoke();
|
|
}
|
|
|
|
//关闭本界面
|
|
private void ClosePanel()
|
|
{
|
|
Pop();
|
|
}
|
|
}
|
|
|
|
//
|
|
public class PromptWindowInitData
|
|
{
|
|
public string showMsg;
|
|
public UnityAction buttonSure;//确认操作按钮
|
|
public string formatKey; // localization key for SetFormatted
|
|
public object[] formatArgs; // args for SetFormatted
|
|
|
|
public PromptWindowInitData(string msg, UnityAction action)
|
|
{
|
|
showMsg = msg;
|
|
buttonSure = action;
|
|
}
|
|
|
|
public PromptWindowInitData(string locKey, object[] args, UnityAction action)
|
|
{
|
|
formatKey = locKey;
|
|
formatArgs = args;
|
|
buttonSure = action;
|
|
}
|
|
}
|