备份CatanBuilding瘦身独立工程
This commit is contained in:
203
Assets/Scripts/UI/Home/NoticeConfirmPopupPanel.cs
Normal file
203
Assets/Scripts/UI/Home/NoticeConfirmPopupPanel.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class NoticeConfirmPopupPanel : MonoBehaviour
|
||||
{
|
||||
TMP_Text text_info;
|
||||
TMP_Text text_title;
|
||||
GameObject btn_1;
|
||||
Button btn_confirm;
|
||||
GameObject btn_2;
|
||||
Button btn_click1;
|
||||
TMP_Text btn_clickleft_text;
|
||||
Button btn_click2;
|
||||
TMP_Text btn_clickright_text;
|
||||
Button btn_close;
|
||||
Action onConfirm;
|
||||
Action onClickLeft;
|
||||
Action onClickRight;
|
||||
Action onClose;
|
||||
Animator animator;
|
||||
class NoticeInfo
|
||||
{
|
||||
public int type;
|
||||
public string title;
|
||||
public string info;
|
||||
public Action onClickLeft = null;
|
||||
public Action onClickRight = null;
|
||||
public Action onClose = null;
|
||||
public string btn_left_text = "";
|
||||
public string btn_right_text = "";
|
||||
}
|
||||
|
||||
private static Queue<NoticeInfo> noticeQuene = new Queue<NoticeInfo>();
|
||||
private static NoticeInfo currentNotice = null;
|
||||
|
||||
//private string defaultLBtnText;
|
||||
//private string defaultRBtnText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
text_info = transform.Find("root/text_info").GetComponent<TMP_Text>();
|
||||
text_title = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
||||
btn_1 = transform.Find("root/btn_1").gameObject;
|
||||
btn_confirm = transform.Find("root/btn_1/btn_confrim/btn_green").GetComponent<Button>();
|
||||
btn_2 = transform.Find("root/btn_2").gameObject;
|
||||
btn_click1 = transform.Find("root/btn_2/btn_back/btn_green").GetComponent<Button>();
|
||||
btn_clickleft_text = transform.Find("root/btn_2/btn_back/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
btn_click2 = transform.Find("root/btn_2/btn_confrim/btn_green").GetComponent<Button>();
|
||||
btn_clickright_text = transform.Find("root/btn_2/btn_confrim/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
||||
//defaultLBtnText = btn_clickleft_text.text;
|
||||
//defaultRBtnText = LocalizationMgr.GetText("UI_COMMON_cancel");// btn_clickright_text.text;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn_confirm.onClick.AddListener(OnClickConfirm);
|
||||
btn_click1.onClick.AddListener(OnClick1);
|
||||
btn_click2.onClick.AddListener(OnClick2);
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UIManager.UnblockInput();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UIManager.RestoreInputBlock();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(UIManager.isInputBlocked())
|
||||
{
|
||||
UIManager.UnblockInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
currentNotice = null;
|
||||
}
|
||||
|
||||
void OnClickConfirm()
|
||||
{
|
||||
onConfirm?.Invoke();
|
||||
OnClose();
|
||||
}
|
||||
void OnClick2()
|
||||
{
|
||||
onClickRight?.Invoke();
|
||||
OnClose();
|
||||
}
|
||||
void OnClick1()
|
||||
{
|
||||
onClickLeft?.Invoke();
|
||||
OnClose();
|
||||
}
|
||||
void OnClickClose()
|
||||
{
|
||||
onClose?.Invoke();
|
||||
OnClose();
|
||||
}
|
||||
|
||||
void ClearAction()
|
||||
{
|
||||
onConfirm = null;
|
||||
onClickRight = null;
|
||||
onClickLeft = null;
|
||||
onClose = null;
|
||||
}
|
||||
|
||||
void OnClose()
|
||||
{
|
||||
lock (noticeQuene)
|
||||
{
|
||||
ClearAction();
|
||||
if (noticeQuene.TryDequeue(out currentNotice))
|
||||
{
|
||||
animator.Play("popup_common_show", 0, 0);
|
||||
ShowCurrentNotice();
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.HideUI(UITypes.NoticeConfirmPopupPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type">显示几个按钮</param>
|
||||
/// <param name="info"></param>
|
||||
/// <param name="onClickLeft">左边点击</param>
|
||||
/// <param name="onClickRight">右边点击</param>
|
||||
public void Init(int type, string title, string info, Action onClickLeft = null, Action onClickRight = null, Action onClose = null, string btn_left_text = "", string btn_right_text = "")
|
||||
{
|
||||
var notice = new NoticeInfo()
|
||||
{
|
||||
type = type,
|
||||
title = title,
|
||||
info = info,
|
||||
onClickLeft = onClickLeft,
|
||||
onClickRight = onClickRight,
|
||||
onClose = onClose,
|
||||
btn_left_text = btn_left_text,
|
||||
btn_right_text = btn_right_text
|
||||
};
|
||||
|
||||
lock (noticeQuene)
|
||||
{
|
||||
if (currentNotice == null)
|
||||
{
|
||||
currentNotice = notice;
|
||||
ShowCurrentNotice();
|
||||
}
|
||||
else
|
||||
{
|
||||
noticeQuene.Enqueue(notice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowCurrentNotice()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
text_title.text = currentNotice.title;
|
||||
if (currentNotice.btn_left_text != "")
|
||||
{
|
||||
btn_clickleft_text.text = currentNotice.btn_left_text;
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_clickleft_text.text = LocalizationMgr.GetText("UI_COMMON_confirm");
|
||||
}
|
||||
|
||||
if (currentNotice.btn_right_text != "")
|
||||
{
|
||||
btn_clickright_text.text = currentNotice.btn_right_text;
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_clickright_text.text = LocalizationMgr.GetText("UI_COMMON_cancel");
|
||||
}
|
||||
|
||||
btn_1.SetActive(currentNotice.type == 1);
|
||||
btn_2.SetActive(currentNotice.type == 2);
|
||||
text_info.text = currentNotice.info;
|
||||
onConfirm = currentNotice.onClickLeft;
|
||||
onClickLeft = currentNotice.onClickLeft;
|
||||
onClickRight = currentNotice.onClickRight;
|
||||
onClose = currentNotice.onClose;
|
||||
transform.SetAsLastSibling();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user