Нема описа
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.

DrawAssetOverlay.cs 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using PlasticGui;
  5. using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
  6. using Unity.PlasticSCM.Editor.AssetUtils;
  7. using Unity.PlasticSCM.Editor.UI;
  8. namespace Unity.PlasticSCM.Editor.AssetsOverlays
  9. {
  10. internal static class DrawAssetOverlay
  11. {
  12. internal static void Enable(
  13. string wkPath,
  14. IAssetStatusCache assetStatusCache)
  15. {
  16. if (mIsEnabled)
  17. return;
  18. mWkPath = wkPath;
  19. mAssetStatusCache = assetStatusCache;
  20. mIsEnabled = true;
  21. mRepaintProjectWindow = ProjectWindow.Repaint;
  22. EditorApplication.projectWindowItemOnGUI += OnProjectWindowItemGUI;
  23. mRepaintProjectWindow();
  24. }
  25. internal static void Disable()
  26. {
  27. mIsEnabled = false;
  28. EditorApplication.projectWindowItemOnGUI -= OnProjectWindowItemGUI;
  29. mRepaintProjectWindow();
  30. mWkPath = null;
  31. mAssetStatusCache = null;
  32. }
  33. internal static string GetStatusString(AssetStatus assetStatus)
  34. {
  35. if (ClassifyAssetStatus.IsPrivate(assetStatus))
  36. return PlasticLocalization.GetString(
  37. PlasticLocalization.Name.Private);
  38. if (ClassifyAssetStatus.IsIgnored(assetStatus))
  39. return PlasticLocalization.GetString(
  40. PlasticLocalization.Name.StatusIgnored);
  41. if (ClassifyAssetStatus.IsAdded(assetStatus))
  42. return PlasticLocalization.GetString(
  43. PlasticLocalization.Name.StatusAdded);
  44. if (ClassifyAssetStatus.IsConflicted(assetStatus))
  45. return PlasticLocalization.GetString(
  46. PlasticLocalization.Name.StatusConflicted);
  47. if (ClassifyAssetStatus.IsDeletedOnServer(assetStatus))
  48. return PlasticLocalization.GetString(
  49. PlasticLocalization.Name.StatusDeletedOnServer);
  50. if (ClassifyAssetStatus.IsLockedRemote(assetStatus))
  51. return PlasticLocalization.GetString(
  52. PlasticLocalization.Name.StatusLockedRemote);
  53. if (ClassifyAssetStatus.IsOutOfDate(assetStatus))
  54. return PlasticLocalization.GetString(
  55. PlasticLocalization.Name.StatusOutOfDate);
  56. if (ClassifyAssetStatus.IsLocked(assetStatus))
  57. return PlasticLocalization.GetString(
  58. PlasticLocalization.Name.StatusLockedByMe);
  59. if (ClassifyAssetStatus.IsRetained(assetStatus))
  60. return PlasticLocalization.GetString(
  61. PlasticLocalization.Name.StatusRetained);
  62. if (ClassifyAssetStatus.IsCheckedOut(assetStatus))
  63. return PlasticLocalization.GetString(
  64. PlasticLocalization.Name.StatusCheckout);
  65. return string.Empty;
  66. }
  67. internal static string GetTooltipText(
  68. AssetStatus statusValue,
  69. LockStatusData lockStatusData)
  70. {
  71. string statusText = GetStatusString(statusValue);
  72. if (lockStatusData == null)
  73. return statusText;
  74. // example:
  75. // Changed by:
  76. // * dani_pen@hotmail.com
  77. // * workspace wkLocal"
  78. char bulletCharacter = '\u25cf';
  79. string line1 = ClassifyAssetStatus.IsLocked(statusValue) ?
  80. statusText + ":" :
  81. PlasticLocalization.GetString(
  82. PlasticLocalization.Name.AssetOverlayTooltipStatus,
  83. statusText);
  84. string line2 = string.Format("{0} {1}",
  85. bulletCharacter,
  86. lockStatusData.LockedBy);
  87. string line3 = string.Format("{0} {1}",
  88. bulletCharacter,
  89. PlasticLocalization.GetString(
  90. PlasticLocalization.Name.AssetOverlayTooltipOn,
  91. lockStatusData.HolderBranchName));
  92. return string.Format(
  93. "{0}" + Environment.NewLine +
  94. "{1}" + Environment.NewLine +
  95. "{2}",
  96. line1,
  97. line2,
  98. line3);
  99. }
  100. static void OnProjectWindowItemGUI(string guid, Rect selectionRect)
  101. {
  102. if (string.IsNullOrEmpty(guid))
  103. return;
  104. if (Event.current.type != EventType.Repaint)
  105. return;
  106. string fullPath = AssetsPath.GetFullPathUnderWorkspace.
  107. ForGuid(mWkPath, guid);
  108. if (fullPath == null)
  109. return;
  110. AssetStatus assetStatus = mAssetStatusCache.GetStatus(fullPath);
  111. string tooltipText = GetTooltipText(
  112. assetStatus,
  113. mAssetStatusCache.GetLockStatusData(fullPath));
  114. DrawOverlayIcon.ForStatus(
  115. selectionRect,
  116. assetStatus,
  117. tooltipText);
  118. }
  119. internal static class DrawOverlayIcon
  120. {
  121. internal static void ForStatus(
  122. Rect selectionRect,
  123. AssetStatus status,
  124. string tooltipText)
  125. {
  126. Texture overlayIcon = GetOverlayIcon(status);
  127. if (overlayIcon == null)
  128. return;
  129. Rect overlayRect = OverlayRect.GetOverlayRect(
  130. selectionRect,
  131. OVERLAY_ICON_OFFSET);
  132. GUI.DrawTexture(
  133. overlayRect, overlayIcon, ScaleMode.ScaleToFit);
  134. Rect tooltipRect = GetTooltipRect(selectionRect, overlayRect);
  135. GUI.Label(tooltipRect, new GUIContent(string.Empty, tooltipText));
  136. }
  137. internal static Texture GetOverlayIcon(AssetStatus assetStatus)
  138. {
  139. if (ClassifyAssetStatus.IsPrivate(assetStatus))
  140. return Images.GetPrivatedOverlayIcon();
  141. if (ClassifyAssetStatus.IsIgnored(assetStatus))
  142. return Images.GetIgnoredOverlayIcon();
  143. if (ClassifyAssetStatus.IsAdded(assetStatus))
  144. return Images.GetAddedOverlayIcon();
  145. if (ClassifyAssetStatus.IsConflicted(assetStatus))
  146. return Images.GetConflictedOverlayIcon();
  147. if (ClassifyAssetStatus.IsDeletedOnServer(assetStatus))
  148. return Images.GetDeletedRemoteOverlayIcon();
  149. if (ClassifyAssetStatus.IsLockedRemote(assetStatus))
  150. return Images.GetLockedRemoteOverlayIcon();
  151. if (ClassifyAssetStatus.IsOutOfDate(assetStatus))
  152. return Images.GetOutOfSyncOverlayIcon();
  153. if (ClassifyAssetStatus.IsLocked(assetStatus))
  154. return Images.GetLockedLocalOverlayIcon();
  155. if (ClassifyAssetStatus.IsRetained(assetStatus))
  156. return Images.GetRetainedOverlayIcon();
  157. if (ClassifyAssetStatus.IsCheckedOut(assetStatus))
  158. return Images.GetCheckedOutOverlayIcon();
  159. return null;
  160. }
  161. static Rect Inflate(Rect rect, float width, float height)
  162. {
  163. return new Rect(
  164. rect.x - width,
  165. rect.y - height,
  166. rect.width + 2f * width,
  167. rect.height + 2f * height);
  168. }
  169. static Rect GetTooltipRect(
  170. Rect selectionRect,
  171. Rect overlayRect)
  172. {
  173. if (selectionRect.width > selectionRect.height)
  174. {
  175. return overlayRect;
  176. }
  177. return Inflate(overlayRect, 3f, 3f);
  178. }
  179. }
  180. static Action mRepaintProjectWindow;
  181. static bool mIsEnabled;
  182. static IAssetStatusCache mAssetStatusCache;
  183. static string mWkPath;
  184. const float OVERLAY_ICON_OFFSET = 20f;
  185. }
  186. }