MessageWindowManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class MessageWindowManager : IManager
  5. {
  6. public const string header = "TEXTBOX";
  7. public static readonly SliderProp fontBounds = new SliderProp(25f, 60f);
  8. private static GameObject sysRoot;
  9. private readonly MessageClass msgClass;
  10. private readonly MessageWindowMgr msgWnd;
  11. private readonly UILabel msgLabel;
  12. private readonly UILabel nameLabel;
  13. private readonly GameObject msgGameObject;
  14. public bool ShowingMessage { get; private set; }
  15. public string MessageName { get; private set; } = string.Empty;
  16. public string MessageText { get; private set; } = string.Empty;
  17. public int FontSize
  18. {
  19. get => msgLabel.fontSize;
  20. set => msgLabel.fontSize = (int)Mathf.Clamp(value, fontBounds.Left, fontBounds.Right);
  21. }
  22. static MessageWindowManager()
  23. {
  24. InputManager.Register(MpsKey.ToggleMessage, KeyCode.M, "Show/hide message box");
  25. }
  26. public MessageWindowManager()
  27. {
  28. sysRoot = GameObject.Find("__GameMain__/SystemUI Root");
  29. msgWnd = GameMain.Instance.MsgWnd;
  30. msgGameObject = sysRoot.transform.Find("MessageWindowPanel").gameObject;
  31. msgClass = new MessageClass(msgGameObject, msgWnd);
  32. nameLabel = UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/SpeakerName/Name")
  33. .GetComponent<UILabel>();
  34. msgLabel = UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/Message")
  35. .GetComponent<UILabel>();
  36. Utility.SetFieldValue(msgClass, "message_label_", msgLabel);
  37. Utility.SetFieldValue(msgClass, "name_label_", nameLabel);
  38. Activate();
  39. }
  40. public void Activate() => SetPhotoMessageWindowActive(true);
  41. public void Deactivate()
  42. {
  43. msgWnd.CloseMessageWindowPanel();
  44. SetPhotoMessageWindowActive(false);
  45. }
  46. public void Update() { }
  47. private void SetPhotoMessageWindowActive(bool active)
  48. {
  49. UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/MessageBox").SetActive(active);
  50. UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/Hitret")
  51. .GetComponent<UISprite>().enabled = !active;
  52. nameLabel.gameObject.SetActive(active);
  53. msgLabel.gameObject.SetActive(active);
  54. Transform transform = sysRoot.transform.Find("MessageWindowPanel/MessageViewer/MsgParent/Buttons");
  55. var msgButtons = new[]
  56. {
  57. MessageWindowMgr.MessageWindowUnderButton.Skip,
  58. MessageWindowMgr.MessageWindowUnderButton.Auto,
  59. MessageWindowMgr.MessageWindowUnderButton.Voice,
  60. MessageWindowMgr.MessageWindowUnderButton.BackLog,
  61. MessageWindowMgr.MessageWindowUnderButton.Config
  62. };
  63. foreach (MessageWindowMgr.MessageWindowUnderButton msgButton in msgButtons)
  64. {
  65. transform.Find(msgButton.ToString()).gameObject.SetActive(!active);
  66. }
  67. if (!msgClass.subtitles_manager_) return;
  68. msgClass.subtitles_manager_.visible = false;
  69. msgClass.subtitles_manager_ = null;
  70. }
  71. public void ShowMessage(string name, string message)
  72. {
  73. MessageName = name;
  74. MessageText = message;
  75. ShowingMessage = true;
  76. msgWnd.OpenMessageWindowPanel();
  77. msgLabel.ProcessText();
  78. msgClass.SetText(name, message, "", 0, AudioSourceMgr.Type.System);
  79. msgClass.FinishChAnime();
  80. }
  81. public void CloseMessagePanel()
  82. {
  83. ShowingMessage = false;
  84. msgWnd.CloseMessageWindowPanel();
  85. }
  86. }
  87. }