MessageWindow.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class MessageWindow : BaseWindow
  6. {
  7. private readonly MessageWindowManager messageWindowManager;
  8. private readonly TextField nameTextField;
  9. private readonly Slider fontSizeSlider;
  10. private readonly TextArea messageTextArea;
  11. private readonly Button okButton;
  12. public override Rect WindowRect
  13. {
  14. set
  15. {
  16. value.width = Mathf.Clamp(Screen.width * 0.4f, 440, Mathf.Infinity);
  17. value.height = Mathf.Clamp(Screen.height * 0.15f, 150, Mathf.Infinity);
  18. base.WindowRect = value;
  19. }
  20. }
  21. private int fontSize = 25;
  22. private bool showingMessage;
  23. public MessageWindow(MessageWindowManager messageWindowManager)
  24. {
  25. WindowRect = WindowRect;
  26. windowRect.x = MiddlePosition.x;
  27. windowRect.y = Screen.height - WindowRect.height;
  28. this.messageWindowManager = messageWindowManager;
  29. nameTextField = new TextField();
  30. fontSizeSlider = new Slider(MessageWindowManager.fontBounds);
  31. fontSizeSlider.ControlEvent += ChangeFontSize;
  32. messageTextArea = new TextArea();
  33. okButton = new Button("OK");
  34. okButton.ControlEvent += ShowMessage;
  35. }
  36. public void ToggleVisibility()
  37. {
  38. if (showingMessage)
  39. {
  40. messageWindowManager.CloseMessagePanel();
  41. showingMessage = false;
  42. }
  43. else Visible = !Visible;
  44. }
  45. private void ChangeFontSize(object sender, EventArgs args)
  46. {
  47. fontSize = (int)fontSizeSlider.Value;
  48. messageWindowManager.SetFontSize(fontSize);
  49. }
  50. private void ShowMessage(object sender, EventArgs args)
  51. {
  52. Visible = false;
  53. showingMessage = true;
  54. messageWindowManager.ShowMessage(nameTextField.Value, messageTextArea.Value);
  55. }
  56. public override void Update()
  57. {
  58. base.Update();
  59. if (InputManager.GetKeyDown(MpsKey.ToggleMessage)) ToggleVisibility();
  60. }
  61. public override void Draw()
  62. {
  63. GUILayout.BeginHorizontal();
  64. GUILayout.Label("Name", GUILayout.ExpandWidth(false));
  65. nameTextField.Draw(GUILayout.Width(120));
  66. GUILayout.Space(30);
  67. GUILayout.Label("Font Size", GUILayout.ExpandWidth(false));
  68. fontSizeSlider.Draw(GUILayout.Width(120), GUILayout.ExpandWidth(false));
  69. GUILayout.Label($"{fontSize}pt");
  70. GUILayout.EndHorizontal();
  71. messageTextArea.Draw(GUILayout.MinHeight(90));
  72. okButton.Draw(GUILayout.ExpandWidth(false), GUILayout.Width(30));
  73. }
  74. public override void Deactivate()
  75. {
  76. if (showingMessage)
  77. {
  78. messageWindowManager.CloseMessagePanel();
  79. showingMessage = false;
  80. }
  81. Visible = false;
  82. }
  83. }
  84. }