MessageWindowManager.cs 4.0 KB

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