MessageWindowManager.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class MessageWindowManager : IManager, ISerializable
  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. private string messageName;
  16. private string messageText;
  17. static MessageWindowManager()
  18. {
  19. InputManager.Register(MpsKey.ToggleMessage, KeyCode.M, "Show/hide message box");
  20. }
  21. public MessageWindowManager()
  22. {
  23. sysRoot = GameObject.Find("__GameMain__/SystemUI Root");
  24. msgWnd = GameMain.Instance.MsgWnd;
  25. msgGameObject = sysRoot.transform.Find("MessageWindowPanel").gameObject;
  26. msgClass = new MessageClass(msgGameObject, msgWnd);
  27. nameLabel = UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/SpeakerName/Name", false)
  28. .GetComponent<UILabel>();
  29. msgLabel = UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/Message", false)
  30. .GetComponent<UILabel>();
  31. Utility.SetFieldValue(msgClass, "message_label_", msgLabel);
  32. Utility.SetFieldValue(msgClass, "name_label_", nameLabel);
  33. Activate();
  34. }
  35. public void Activate() => SetPhotoMessageWindowActive(true);
  36. public void Deactivate()
  37. {
  38. msgWnd.CloseMessageWindowPanel();
  39. SetPhotoMessageWindowActive(false);
  40. }
  41. public void Serialize(System.IO.BinaryWriter binaryWriter)
  42. {
  43. binaryWriter.Write(header);
  44. binaryWriter.Write(ShowingMessage);
  45. binaryWriter.Write(msgLabel.fontSize);
  46. binaryWriter.WriteNullableString(messageName);
  47. binaryWriter.WriteNullableString(messageText);
  48. }
  49. public void Deserialize(System.IO.BinaryReader binaryReader)
  50. {
  51. CloseMessagePanel();
  52. bool showingMessage = binaryReader.ReadBoolean();
  53. msgLabel.fontSize = binaryReader.ReadInt32();
  54. messageName = binaryReader.ReadNullableString();
  55. messageText = binaryReader.ReadNullableString();
  56. if (showingMessage) ShowMessage(messageName, messageText);
  57. }
  58. public void Update() { }
  59. private void SetPhotoMessageWindowActive(bool active)
  60. {
  61. UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/MessageBox", false)
  62. .SetActive(active);
  63. UTY.GetChildObject(msgGameObject, "MessageViewer/MsgParent/Hitret", false)
  64. .GetComponent<UISprite>().enabled = !active;
  65. nameLabel.gameObject.SetActive(active);
  66. msgLabel.gameObject.SetActive(active);
  67. Transform transform = sysRoot.transform.Find("MessageWindowPanel/MessageViewer/MsgParent/Buttons");
  68. MessageWindowMgr.MessageWindowUnderButton[] msgButtons = new[]
  69. {
  70. MessageWindowMgr.MessageWindowUnderButton.Skip,
  71. MessageWindowMgr.MessageWindowUnderButton.Auto,
  72. MessageWindowMgr.MessageWindowUnderButton.Voice,
  73. MessageWindowMgr.MessageWindowUnderButton.BackLog,
  74. MessageWindowMgr.MessageWindowUnderButton.Config
  75. };
  76. foreach (MessageWindowMgr.MessageWindowUnderButton msgButton in msgButtons)
  77. {
  78. transform.Find(msgButton.ToString()).gameObject.SetActive(!active);
  79. }
  80. if (msgClass.subtitles_manager_ != null)
  81. {
  82. msgClass.subtitles_manager_.visible = false;
  83. msgClass.subtitles_manager_ = null;
  84. }
  85. }
  86. public void ShowMessage(string name, string message)
  87. {
  88. messageName = name;
  89. messageText = message;
  90. ShowingMessage = true;
  91. msgWnd.OpenMessageWindowPanel();
  92. msgLabel.ProcessText();
  93. msgClass.SetText(name, message, "", 0, AudioSourceMgr.Type.System);
  94. msgClass.FinishChAnime();
  95. }
  96. public void SetFontSize(int fontSize) => msgLabel.fontSize = fontSize;
  97. public void CloseMessagePanel()
  98. {
  99. ShowingMessage = false;
  100. msgWnd.CloseMessageWindowPanel();
  101. }
  102. }
  103. }