MessageWindowManager.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System.Reflection;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class MessageWindowManager : IManager, ISerializable
  6. {
  7. public const string header = "TEXTBOX";
  8. public static readonly SliderProp fontBounds = new SliderProp(25f, 60f);
  9. private static GameObject sysRoot;
  10. private MessageClass msgClass;
  11. private MessageWindowMgr msgWnd;
  12. private UILabel msgLabel;
  13. private UILabel nameLabel;
  14. private GameObject msgGameObject;
  15. public bool ShowingMessage { get; private set; }
  16. private string messageName;
  17. private string messageText;
  18. static MessageWindowManager() => InputManager.Register(MpsKey.ToggleMessage, KeyCode.M, "Show/hide message box");
  19. public MessageWindowManager()
  20. {
  21. sysRoot = GameObject.Find("__GameMain__/SystemUI Root");
  22. this.msgWnd = GameMain.Instance.MsgWnd;
  23. this.msgGameObject = sysRoot.transform.Find("MessageWindowPanel").gameObject;
  24. this.msgClass = new MessageClass(this.msgGameObject, this.msgWnd);
  25. this.nameLabel = UTY.GetChildObject(this.msgGameObject, "MessageViewer/MsgParent/SpeakerName/Name", false)
  26. .GetComponent<UILabel>();
  27. this.msgLabel = UTY.GetChildObject(this.msgGameObject, "MessageViewer/MsgParent/Message", false)
  28. .GetComponent<UILabel>();
  29. Utility.SetFieldValue<MessageClass, UILabel>(this.msgClass, "message_label_", this.msgLabel);
  30. Utility.SetFieldValue<MessageClass, UILabel>(this.msgClass, "name_label_", this.nameLabel);
  31. }
  32. public void Activate()
  33. {
  34. SetPhotoMessageWindowActive(true);
  35. }
  36. public void Deactivate()
  37. {
  38. this.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(this.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. this.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(this.msgGameObject, "MessageViewer/MsgParent/MessageBox", false)
  62. .SetActive(active);
  63. UTY.GetChildObject(this.msgGameObject, "MessageViewer/MsgParent/Hitret", false)
  64. .GetComponent<UISprite>().enabled = !active;
  65. this.nameLabel.gameObject.SetActive(active);
  66. this.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 (var msgButton in msgButtons)
  77. {
  78. transform.Find(msgButton.ToString()).gameObject.SetActive(!active);
  79. }
  80. if (this.msgClass.subtitles_manager_ != null)
  81. {
  82. this.msgClass.subtitles_manager_.visible = false;
  83. this.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. this.msgWnd.OpenMessageWindowPanel();
  92. this.msgLabel.ProcessText();
  93. this.msgClass.SetText(name, message, "", 0, AudioSourceMgr.Type.System);
  94. this.msgClass.FinishChAnime();
  95. }
  96. public void SetFontSize(int fontSize)
  97. {
  98. this.msgLabel.fontSize = fontSize;
  99. }
  100. public void CloseMessagePanel()
  101. {
  102. ShowingMessage = false;
  103. this.msgWnd.CloseMessageWindowPanel();
  104. }
  105. }
  106. }