Files
MinFt/Client/Assets/Scripts/UI/Home/NoticeConfirmPopupPanel.cs
2026-04-27 12:07:32 +08:00

232 lines
6.6 KiB
C#

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;
Button btn_red;
TMP_Text btn_clickright_text;
TMP_Text btn_clickright_text_red;
Button btn_close;
Action onConfirm;
Action onClickLeft;
Action onClickRight;
Action onClose;
Animation 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 = "";
public bool RightBtnRed = false;
}
private static Queue<NoticeInfo> noticeQuene = new Queue<NoticeInfo>();
private static NoticeInfo currentNotice = null;
//private string defaultLBtnText;
//private string defaultRBtnText;
private void Awake()
{
ResetUI();
}
private void ResetUI()
{
animator = GetComponent<Animation>();
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_red = transform.Find("root/btn_2/btn_confrim/btn_red").GetComponent<Button>();
btn_clickright_text = transform.Find("root/btn_2/btn_confrim/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
btn_clickright_text_red = transform.Find("root/btn_2/btn_confrim/btn_red/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_red.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");
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 = "", bool RightBtnRed = false)
{
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,
RightBtnRed = RightBtnRed
};
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.title != "")
{
text_title.text = currentNotice.title;
}
else
{
text_title.text = LocalizationMgr.GetText("UI_FishingNoticePopupPanel_101001");
}
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_clickright_text_red.text = btn_clickright_text.text;
if (currentNotice.type == 2)
{
btn_click2.gameObject.SetActive(!currentNotice.RightBtnRed);
btn_red.gameObject.SetActive(currentNotice.RightBtnRed);
}
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();
}
}