Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HelpPanel.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using Unity.PlasticSCM.Editor.UI;
  5. namespace Unity.PlasticSCM.Editor.Help
  6. {
  7. internal class HelpPanel
  8. {
  9. internal Vector2 TextScroll;
  10. internal bool Visible { get; private set; }
  11. internal PlasticGui.Help.HelpImage Image
  12. {
  13. get { return mHelpImage; }
  14. }
  15. internal HelpData Data
  16. {
  17. get { return mHelpData; }
  18. }
  19. internal GUIContent GUIContent
  20. {
  21. get { return mHelpGUIContent; }
  22. }
  23. internal HelpPanel(EditorWindow window)
  24. {
  25. mWindow = window;
  26. }
  27. internal void Show(PlasticGui.Help.HelpImage helpImage, HelpData helpData)
  28. {
  29. ClearData();
  30. UpdateData(helpImage, helpData);
  31. Visible = true;
  32. mWindow.Repaint();
  33. }
  34. internal void Hide()
  35. {
  36. ClearData();
  37. Visible = false;
  38. mWindow.Repaint();
  39. }
  40. internal bool TryGetLinkAtChar(
  41. int charIndex,
  42. out HelpLink link)
  43. {
  44. link = null;
  45. FormattedHelpLink formattedLink = GetFormattedLinkAtChar(
  46. mFormattedLinks, charIndex);
  47. if (formattedLink == null)
  48. return false;
  49. link = formattedLink.Source;
  50. return !BuildFormattedHelp.IsLinkMetaChar(formattedLink, charIndex);
  51. }
  52. void ClearData()
  53. {
  54. mHelpImage = PlasticGui.Help.HelpImage.GenericBuho;
  55. mHelpData = null;
  56. mHelpGUIContent = null;
  57. mFormattedLinks = null;
  58. }
  59. void UpdateData(PlasticGui.Help.HelpImage helpImage, HelpData helpData)
  60. {
  61. mHelpImage = helpImage;
  62. mHelpData = helpData;
  63. string formattedHelpText;
  64. BuildFormattedHelp.ForData(
  65. mHelpData.CleanText,
  66. mHelpData.FormattedBlocks.ToArray(),
  67. mHelpData.Links.ToArray(),
  68. out formattedHelpText,
  69. out mFormattedLinks);
  70. mHelpGUIContent = new GUIContent(formattedHelpText);
  71. }
  72. static FormattedHelpLink GetFormattedLinkAtChar(
  73. List<FormattedHelpLink> formattedLinks, int charIndex)
  74. {
  75. for(int i = 0; i < formattedLinks.Count; i++)
  76. {
  77. FormattedHelpLink link = formattedLinks[i];
  78. if (link.Position <= charIndex &&
  79. charIndex < link.Position + link.Length)
  80. return link;
  81. if (charIndex <= link.Position + link.Length)
  82. return null;
  83. }
  84. return null;
  85. }
  86. PlasticGui.Help.HelpImage mHelpImage;
  87. HelpData mHelpData;
  88. GUIContent mHelpGUIContent;
  89. List<FormattedHelpLink> mFormattedLinks;
  90. EditorWindow mWindow;
  91. }
  92. }