PlainTextInspector.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Collections.Generic;
  4. using BansheeEngine;
  5. namespace BansheeEditor
  6. {
  7. /// <summary>
  8. /// Renders an inspector for the <see cref="PlainText"/> resource.
  9. /// </summary>
  10. [CustomInspector(typeof(PlainText))]
  11. internal class PlainTextInspector : Inspector
  12. {
  13. private const int MAX_SHOWN_CHARACTERS = 3000;
  14. private GUILabel textLabel = new GUILabel("", EditorStyles.MultiLineLabel, GUIOption.FixedHeight(500));
  15. private GUITexture textBg = new GUITexture(null, EditorStyles.ScrollAreaBg);
  16. private string shownText = "";
  17. /// <inheritdoc/>
  18. protected internal override void Initialize()
  19. {
  20. PlainText plainText = InspectedObject as PlainText;
  21. if (plainText == null)
  22. return;
  23. GUIPanel textPanel = Layout.AddPanel();
  24. GUILayout textLayoutY = textPanel.AddLayoutY();
  25. textLayoutY.AddSpace(5);
  26. GUILayout textLayoutX = textLayoutY.AddLayoutX();
  27. textLayoutX.AddSpace(5);
  28. textLayoutX.AddElement(textLabel);
  29. textLayoutX.AddSpace(5);
  30. textLayoutY.AddSpace(5);
  31. GUIPanel textBgPanel = textPanel.AddPanel(1);
  32. textBgPanel.AddElement(textBg);
  33. }
  34. /// <inheritdoc/>
  35. protected internal override InspectableState Refresh()
  36. {
  37. PlainText plainText = InspectedObject as PlainText;
  38. if (plainText == null)
  39. return InspectableState.NotModified;
  40. string newText = plainText.Text;
  41. string newShownText = plainText.Text.Substring(0, MathEx.Min(newText.Length, MAX_SHOWN_CHARACTERS));
  42. if (newShownText != shownText)
  43. {
  44. textLabel.SetContent(newShownText);
  45. shownText = newShownText;
  46. }
  47. return InspectableState.NotModified;
  48. }
  49. }
  50. }