MessageWindowManager.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin;
  3. public class MessageWindowManager : IManager
  4. {
  5. public const string Header = "TEXTBOX";
  6. public static readonly SliderProp FontBounds = new(25f, 60f);
  7. private readonly MessageWindowMgr messageWindowMgr;
  8. private readonly GameObject subtitlesDisplayPanel;
  9. private readonly GameObject hitRetSprite;
  10. private readonly GameObject messageBox;
  11. private readonly GameObject messageButtons;
  12. private readonly UILabel messageLabel;
  13. private readonly UILabel speakerLabel;
  14. static MessageWindowManager() =>
  15. InputManager.Register(MpsKey.ToggleMessage, KeyCode.M, "Show/hide message box");
  16. public MessageWindowManager()
  17. {
  18. messageWindowMgr = GameMain.Instance.MsgWnd;
  19. var messageWindowPanel =
  20. Utility.GetFieldValue<MessageWindowMgr, GameObject>(messageWindowMgr, "m_goMessageWindowPanel");
  21. var msgParent = UTY.GetChildObject(messageWindowPanel, "MessageViewer/MsgParent");
  22. messageButtons = UTY.GetChildObject(msgParent, "Buttons");
  23. hitRetSprite = UTY.GetChildObject(msgParent, "Hitret");
  24. subtitlesDisplayPanel = UTY.GetChildObject(msgParent, "SubtitlesDisplayPanel");
  25. messageBox = UTY.GetChildObject(msgParent, "MessageBox");
  26. speakerLabel = UTY.GetChildObject(msgParent, "SpeakerName/Name").GetComponent<UILabel>();
  27. messageLabel = UTY.GetChildObject(msgParent, "Message").GetComponent<UILabel>();
  28. }
  29. public bool ShowingMessage
  30. {
  31. get => messageWindowMgr.IsVisibleMessageViewer;
  32. private set
  33. {
  34. if (value)
  35. messageWindowMgr.OpenMessageWindowPanel();
  36. else
  37. messageWindowMgr.CloseMessageWindowPanel();
  38. }
  39. }
  40. public string MessageName
  41. {
  42. get => speakerLabel.text;
  43. private set => speakerLabel.text = value;
  44. }
  45. public string MessageText
  46. {
  47. get => messageLabel.text;
  48. private set => messageLabel.text = value;
  49. }
  50. public int FontSize
  51. {
  52. get => messageLabel.fontSize;
  53. set => messageLabel.fontSize = (int)Mathf.Clamp(value, FontBounds.Left, FontBounds.Right);
  54. }
  55. public void Update()
  56. {
  57. }
  58. public void Activate()
  59. {
  60. if (Product.supportMultiLanguage)
  61. subtitlesDisplayPanel.SetActive(false);
  62. ResetMessageBoxProperties();
  63. SetMessageBoxActive(true);
  64. SetMessageBoxExtrasActive(false);
  65. CloseMessagePanel();
  66. }
  67. public void Deactivate()
  68. {
  69. if (Product.supportMultiLanguage)
  70. {
  71. subtitlesDisplayPanel.SetActive(true);
  72. SetMessageBoxActive(false);
  73. }
  74. ResetMessageBoxProperties();
  75. SetMessageBoxExtrasActive(true);
  76. CloseMessagePanel();
  77. }
  78. public void ShowMessage(string name, string message)
  79. {
  80. MessageName = name;
  81. MessageText = message;
  82. ShowingMessage = true;
  83. }
  84. public void CloseMessagePanel()
  85. {
  86. if (!ShowingMessage)
  87. return;
  88. ShowingMessage = false;
  89. }
  90. private void SetMessageBoxActive(bool active)
  91. {
  92. messageBox.SetActive(active);
  93. messageLabel.gameObject.SetActive(active);
  94. speakerLabel.gameObject.SetActive(active);
  95. }
  96. private void SetMessageBoxExtrasActive(bool active)
  97. {
  98. messageButtons.SetActive(active);
  99. hitRetSprite.SetActive(active);
  100. }
  101. private void ResetMessageBoxProperties()
  102. {
  103. FontSize = 25;
  104. MessageName = string.Empty;
  105. MessageText = string.Empty;
  106. }
  107. }