PlainTextInspector.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /** @addtogroup Inspectors
  8. * @{
  9. */
  10. /// <summary>
  11. /// Renders an inspector for the <see cref="PlainText"/> resource.
  12. /// </summary>
  13. [CustomInspector(typeof(PlainText))]
  14. internal class PlainTextInspector : Inspector
  15. {
  16. private const int MAX_SHOWN_CHARACTERS = 3000;
  17. private GUILabel textLabel = new GUILabel("", EditorStyles.MultiLineLabel, GUIOption.FixedHeight(500));
  18. private GUITexture textBg = new GUITexture(null, EditorStylesInternal.ScrollAreaBg);
  19. private string shownText = "";
  20. /// <inheritdoc/>
  21. protected internal override void Initialize()
  22. {
  23. LoadResource();
  24. PlainText plainText = InspectedObject as PlainText;
  25. if (plainText == null)
  26. return;
  27. GUIPanel textPanel = Layout.AddPanel();
  28. GUILayout textLayoutY = textPanel.AddLayoutY();
  29. textLayoutY.AddSpace(5);
  30. GUILayout textLayoutX = textLayoutY.AddLayoutX();
  31. textLayoutX.AddSpace(5);
  32. textLayoutX.AddElement(textLabel);
  33. textLayoutX.AddSpace(5);
  34. textLayoutY.AddSpace(5);
  35. GUIPanel textBgPanel = textPanel.AddPanel(1);
  36. textBgPanel.AddElement(textBg);
  37. }
  38. /// <inheritdoc/>
  39. protected internal override InspectableState Refresh()
  40. {
  41. PlainText plainText = InspectedObject as PlainText;
  42. if (plainText == null)
  43. return InspectableState.NotModified;
  44. string newText = plainText.Text;
  45. string newShownText = plainText.Text.Substring(0, MathEx.Min(newText.Length, MAX_SHOWN_CHARACTERS));
  46. if (newShownText != shownText)
  47. {
  48. textLabel.SetContent(newShownText);
  49. shownText = newShownText;
  50. }
  51. return InspectableState.NotModified;
  52. }
  53. }
  54. /** @} */
  55. }