| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- [DisallowMultipleComponent]
- public class PopViewScreenView : MonoBehaviour
- {
- TMP_Text titleText;
- TMP_Text badgeText;
- TMP_Text bodyText;
- TMP_Text confirmLabel;
- TMP_Text cancelLabel;
- Transform badgeRoot;
- Button confirmButton;
- Button cancelButton;
- Action onConfirm;
- Action onCancel;
- bool wired;
- public void Show(PopViewContent content, Action confirm, Action cancel)
- {
- CacheReferences();
- WireButtons();
- onConfirm = confirm;
- onCancel = cancel;
- if (titleText != null)
- titleText.text = content.Title ?? "";
- if (badgeRoot != null)
- badgeRoot.gameObject.SetActive(!string.IsNullOrEmpty(content.Badge));
- if (badgeText != null)
- badgeText.text = content.Badge ?? "";
- if (bodyText != null)
- bodyText.text = content.Body ?? "";
- if (confirmLabel != null)
- confirmLabel.text = content.ConfirmText ?? L.Get("common.ok");
- if (cancelLabel != null)
- cancelLabel.text = content.CancelText ?? L.Get("common.cancel");
- transform.SetAsLastSibling();
- gameObject.SetActive(true);
- }
- public void Hide()
- {
- onConfirm = null;
- onCancel = null;
- gameObject.SetActive(false);
- }
- public void Cancel()
- {
- var callback = onCancel;
- Hide();
- callback?.Invoke();
- }
- void CacheReferences()
- {
- if (titleText == null)
- titleText = UIViewUtility.Text(transform, "IMG_BG/GRP_Title/IMG_DailyCheckInTitle/TMP_Title");
- if (badgeRoot == null)
- badgeRoot = UIViewUtility.Find(transform, "IMG_BG/GRP_Title/IMG_DailyCheckInTitle/IMG_PauseModeBadge");
- if (badgeText == null)
- badgeText = UIViewUtility.Text(transform, "IMG_BG/GRP_Title/IMG_DailyCheckInTitle/IMG_PauseModeBadge/TMP_Des");
- if (bodyText == null)
- bodyText = UIViewUtility.Text(transform, "IMG_BG/TMP_Content");
- if (confirmButton == null)
- confirmButton = UIViewUtility.Button(transform, "IMG_BG/GRP_Btns/BTN_Confirm");
- if (cancelButton == null)
- cancelButton = UIViewUtility.Button(transform, "IMG_BG/GRP_Btns/BTN_Cancel");
- if (confirmLabel == null)
- confirmLabel = UIViewUtility.Text(transform, "IMG_BG/GRP_Btns/BTN_Confirm/Text (TMP)");
- if (cancelLabel == null)
- cancelLabel = UIViewUtility.Text(transform, "IMG_BG/GRP_Btns/BTN_Cancel/Text (TMP)");
- }
- void WireButtons()
- {
- if (wired)
- return;
- bool any = false;
- if (confirmButton != null)
- {
- UIViewUtility.Bind(confirmButton, HandleConfirm);
- any = true;
- }
- if (cancelButton != null)
- {
- UIViewUtility.Bind(cancelButton, HandleCancel);
- any = true;
- }
- wired = any;
- }
- void HandleConfirm()
- {
- var callback = onConfirm;
- Hide();
- callback?.Invoke();
- }
- void HandleCancel()
- {
- Cancel();
- }
- }
- public struct PopViewContent
- {
- public string Title;
- public string Badge;
- public string Body;
- public string ConfirmText;
- public string CancelText;
- }
|