TaptapAntiAddictionHealthReminderController.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using UnityEngine.UI;
  3. using TapSDK.UI;
  4. namespace TapTap.AntiAddiction.Internal {
  5. public class TaptapAntiAddictionHealthReminderController : BasePanelController
  6. {
  7. public Text titleText;
  8. public Text contentText;
  9. public Button switchAccountButton;
  10. public Button okButton;
  11. private Action OnOk { get; set; }
  12. private Action OnSwitchAccount { get; set; }
  13. /// <summary>
  14. /// bind ugui components for every panel
  15. /// </summary>
  16. protected override void BindComponents()
  17. {
  18. titleText = transform.Find("Root/TitleText").GetComponent<Text>();
  19. contentText = transform.Find("Root/ContentText").GetComponent<Text>();
  20. switchAccountButton = transform.Find("Root/SwitchAccountButton").GetComponent<Button>();
  21. okButton = transform.Find("Root/OKButton").GetComponent<Button>();
  22. }
  23. protected override void OnLoadSuccess()
  24. {
  25. base.OnLoadSuccess();
  26. switchAccountButton.onClick.AddListener(OnSwitchAccountButtonClicked);
  27. okButton.onClick.AddListener(OnOKButtonClicked);
  28. }
  29. internal void Show(PlayableResult playable, Action onOk, Action onSwitchAccount)
  30. {
  31. OnOk = onOk;
  32. OnSwitchAccount = onSwitchAccount;
  33. titleText.text = playable.Title;
  34. int remainTime = Math.Max(0, playable.RemainTime / 60);
  35. remainTime = Math.Min(PlayableResult.MaxRemainTime, remainTime);
  36. // 替换富文本标签
  37. contentText.text = playable.Content
  38. ?.Replace("<font color=", "<color=")
  39. .Replace("</font>", "</color>")
  40. .Replace("<span color=", "<color=")
  41. .Replace("</span>", "</color>")
  42. .Replace("<br>", "\n")
  43. // 设置剩余时间
  44. .Replace("# ${remaining} #", remainTime.ToString());
  45. switchAccountButton.gameObject.SetActive(onSwitchAccount != null);
  46. var buttonText = okButton.transform.Find("Text").GetComponent<Text>();
  47. var switchButtonText = switchAccountButton.transform.Find("Text").GetComponent<Text>();
  48. if (TapTapAntiAddictionManager.AntiAddictionConfig.region == Region.Vietnam)
  49. {
  50. if (onOk == null && onSwitchAccount != null)
  51. {
  52. buttonText.text =
  53. Config.Current.UIConfig.HealthReminderVietnam.buttonSwitch;
  54. OnOk = onSwitchAccount;
  55. OnSwitchAccount = null;
  56. switchAccountButton.gameObject.SetActive(false);
  57. }
  58. else
  59. {
  60. buttonText.text =
  61. Config.Current.UIConfig.HealthReminderVietnam.buttonExit;
  62. switchButtonText.text =
  63. Config.Current.UIConfig.HealthReminderVietnam.buttonSwitch;
  64. }
  65. }
  66. else
  67. {
  68. buttonText.text = playable.CanPlay
  69. ? TapTapAntiAddictionManager.LocalizationItems.Current.EnterGame
  70. : TapTapAntiAddictionManager.LocalizationItems.Current.ExitGame;
  71. }
  72. }
  73. private void OnOKButtonClicked()
  74. {
  75. OnOk?.Invoke();
  76. Close();
  77. }
  78. private void OnSwitchAccountButtonClicked()
  79. {
  80. OnSwitchAccount?.Invoke();
  81. Close();
  82. }
  83. }
  84. }