MessageWindow.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class MessageWindow : BaseWindow
  6. {
  7. private MessageWindowManager messageWindowManager;
  8. private TextField nameTextField;
  9. private Slider fontSizeSlider;
  10. private TextArea messageTextArea;
  11. private 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 = false;
  23. public MessageWindow(MessageWindowManager messageWindowManager) : base()
  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. Controls.Add(nameTextField);
  31. fontSizeSlider = new Slider(MessageWindowManager.fontBounds);
  32. fontSizeSlider.ControlEvent += ChangeFontSize;
  33. Controls.Add(fontSizeSlider);
  34. messageTextArea = new TextArea();
  35. Controls.Add(messageTextArea);
  36. okButton = new Button("OK");
  37. okButton.ControlEvent += ShowMessage;
  38. Controls.Add(okButton);
  39. }
  40. public void ToggleVisibility()
  41. {
  42. if (showingMessage)
  43. {
  44. messageWindowManager.CloseMessagePanel();
  45. showingMessage = false;
  46. }
  47. else
  48. {
  49. Visible = !Visible;
  50. }
  51. }
  52. private void ChangeFontSize(object sender, EventArgs args)
  53. {
  54. fontSize = (int)fontSizeSlider.Value;
  55. messageWindowManager.SetFontSize(fontSize);
  56. }
  57. private void ShowMessage(object sender, EventArgs args)
  58. {
  59. Visible = false;
  60. showingMessage = true;
  61. messageWindowManager.ShowMessage(nameTextField.Value, messageTextArea.Value);
  62. }
  63. public override void Update()
  64. {
  65. base.Update();
  66. if (InputManager.GetKeyDown(MpsKey.ToggleMessage)) this.ToggleVisibility();
  67. }
  68. public override void Draw()
  69. {
  70. GUILayout.BeginHorizontal();
  71. GUILayout.Label("Name", GUILayout.ExpandWidth(false));
  72. nameTextField.Draw(GUILayout.Width(120));
  73. GUILayout.Space(30);
  74. GUILayout.Label("Font Size", GUILayout.ExpandWidth(false));
  75. fontSizeSlider.Draw(GUILayout.Width(120), GUILayout.ExpandWidth(false));
  76. GUILayout.Label($"{(int)fontSize}pt");
  77. GUILayout.EndHorizontal();
  78. messageTextArea.Draw(GUILayout.MinHeight(90));
  79. okButton.Draw(GUILayout.ExpandWidth(false), GUILayout.Width(30));
  80. }
  81. public override void Deactivate()
  82. {
  83. if (showingMessage)
  84. {
  85. messageWindowManager.CloseMessagePanel();
  86. showingMessage = false;
  87. }
  88. Visible = false;
  89. }
  90. }
  91. }