MessageWindow.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public MessageWindow(MessageWindowManager messageWindowManager)
  23. {
  24. WindowRect = WindowRect;
  25. windowRect.x = MiddlePosition.x;
  26. windowRect.y = Screen.height - WindowRect.height;
  27. this.messageWindowManager = messageWindowManager;
  28. nameTextField = new TextField();
  29. fontSizeSlider = new Slider(MessageWindowManager.fontBounds);
  30. fontSizeSlider.ControlEvent += ChangeFontSize;
  31. messageTextArea = new TextArea();
  32. okButton = new Button("OK");
  33. okButton.ControlEvent += ShowMessage;
  34. }
  35. private void ToggleVisibility()
  36. {
  37. if (messageWindowManager.ShowingMessage) messageWindowManager.CloseMessagePanel();
  38. else Visible = !Visible;
  39. }
  40. private void ChangeFontSize(object sender, EventArgs args)
  41. {
  42. fontSize = (int)fontSizeSlider.Value;
  43. messageWindowManager.FontSize = fontSize;
  44. }
  45. private void ShowMessage(object sender, EventArgs args)
  46. {
  47. Visible = false;
  48. messageWindowManager.ShowMessage(nameTextField.Value, messageTextArea.Value);
  49. }
  50. public override void Update()
  51. {
  52. base.Update();
  53. if (InputManager.GetKeyDown(MpsKey.ToggleMessage)) ToggleVisibility();
  54. }
  55. public override void Draw()
  56. {
  57. GUILayout.BeginHorizontal();
  58. GUILayout.Label("Name", GUILayout.ExpandWidth(false));
  59. nameTextField.Draw(GUILayout.Width(120));
  60. GUILayout.Space(30);
  61. GUILayout.Label("Font Size", GUILayout.ExpandWidth(false));
  62. fontSizeSlider.Draw(GUILayout.Width(120), GUILayout.ExpandWidth(false));
  63. GUILayout.Label($"{fontSize}pt");
  64. GUILayout.EndHorizontal();
  65. messageTextArea.Draw(GUILayout.MinHeight(90));
  66. okButton.Draw(GUILayout.ExpandWidth(false), GUILayout.Width(30));
  67. }
  68. public override void Deactivate()
  69. {
  70. messageWindowManager.CloseMessagePanel();
  71. Visible = false;
  72. }
  73. }
  74. }