ExtDependencyViewerSchema.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #include "ExtDependencyViewerSchema.h"
  3. #include "ExtContentBrowser.h"
  4. #include "ExtContentBrowserStyle.h"
  5. #include "ExtContentBrowserSettings.h"
  6. #include "ExtDependencyViewerCommands.h"
  7. #include "Textures/SlateIcon.h"
  8. #include "Misc/Attribute.h"
  9. #include "ToolMenus.h"
  10. #include "EdGraph/EdGraph.h"
  11. #include "EditorStyleSet.h"
  12. #include "CollectionManagerTypes.h"
  13. #include "Toolkits/GlobalEditorCommonCommands.h"
  14. #include "ConnectionDrawingPolicy.h"
  15. static const FLinearColor RiceFlower = FLinearColor(FColor(236, 252, 227));
  16. static const FLinearColor CannonPink = FLinearColor(FColor(145, 66, 117));
  17. static const FLinearColor CannonPinkRed = FLinearColor(FColor(245, 66, 11));
  18. // Overridden connection drawing policy to use less curvy lines between nodes
  19. class FExtDependencyViewerConnectionDrawingPolicy : public FConnectionDrawingPolicy
  20. {
  21. public:
  22. FExtDependencyViewerConnectionDrawingPolicy(int32 InBackLayerID, int32 InFrontLayerID, float InZoomFactor, const FSlateRect& InClippingRect, FSlateWindowElementList& InDrawElements)
  23. : FConnectionDrawingPolicy(InBackLayerID, InFrontLayerID, InZoomFactor, InClippingRect, InDrawElements)
  24. {
  25. }
  26. virtual FVector2D ComputeSplineTangent(const FVector2D& Start, const FVector2D& End) const override
  27. {
  28. const UExtContentBrowserSettings* ExtContentBrowserSetting = GetDefault<UExtContentBrowserSettings>();
  29. const bool bSpline = !ExtContentBrowserSetting->UseStraightLineInDependencyViewer;
  30. if (bSpline)
  31. {
  32. const int32 Tension = FMath::Abs<int32>(Start.X - End.X);
  33. return Tension * FVector2D(1.0f, 0);
  34. }
  35. else
  36. {
  37. const FVector2D Delta = End - Start;
  38. const FVector2D NormDelta = Delta.GetSafeNormal();
  39. return NormDelta;
  40. }
  41. }
  42. virtual void DetermineWiringStyle(UEdGraphPin* OutputPin, UEdGraphPin* InputPin, /*inout*/ FConnectionParams& Params) override
  43. {
  44. const bool bHardRefernce = OutputPin->PinType.PinCategory == TEXT("hard") || InputPin->PinType.PinCategory == TEXT("hard");
  45. const bool bInvalid = OutputPin->PinType.PinSubCategory == TEXT("invalid") || InputPin->PinType.PinSubCategory == TEXT("invalid");
  46. if (bHardRefernce)
  47. {
  48. if (bInvalid)
  49. {
  50. Params.WireColor = FExtContentBrowserStyle::Get().GetColor("ErrorReporting.HardReferenceColor");
  51. }
  52. else
  53. {
  54. Params.WireColor = RiceFlower;
  55. }
  56. }
  57. else
  58. {
  59. if (bInvalid)
  60. {
  61. Params.WireColor = FExtContentBrowserStyle::Get().GetColor("ErrorReporting.SoftReferenceColor");
  62. }
  63. else
  64. {
  65. Params.WireColor = CannonPink;
  66. }
  67. }
  68. }
  69. };
  70. //////////////////////////////////////////////////////////////////////////
  71. // UExtDependencyViewerSchema
  72. UExtDependencyViewerSchema::UExtDependencyViewerSchema(const FObjectInitializer& ObjectInitializer)
  73. : Super(ObjectInitializer)
  74. {
  75. }
  76. void UExtDependencyViewerSchema::GetContextMenuActions(UToolMenu* Menu, UGraphNodeContextMenuContext* Context) const
  77. {
  78. {
  79. FToolMenuSection& Section = Menu->AddSection(TEXT("Fit"), NSLOCTEXT("ReferenceViewerSchema", "FitSectionLabel", "Fit"));
  80. Section.AddMenuEntry(FExtDependencyViewerCommands::Get().ZoomToFitSelected);
  81. }
  82. #if ECB_LEGACY
  83. {
  84. FToolMenuSection& Section = Menu->AddSection(TEXT("Asset"), NSLOCTEXT("ReferenceViewerSchema", "AssetSectionLabel", "Asset"));
  85. Section.AddMenuEntry(FGlobalEditorCommonCommands::Get().FindInContentBrowser);
  86. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().OpenSelectedInAssetEditor);
  87. }
  88. {
  89. FToolMenuSection& Section = Menu->AddSection(TEXT("Misc"), NSLOCTEXT("ReferenceViewerSchema", "MiscSectionLabel", "Misc"));
  90. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ZoomToFit);
  91. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ReCenterGraph);
  92. Section.AddSubMenu(
  93. "MakeCollectionWith",
  94. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithTitle", "Make Collection with"),
  95. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithTooltip", "Makes a collection with either the referencers or dependencies of the selected nodes."),
  96. FNewToolMenuDelegate::CreateUObject(const_cast<UReferenceViewerSchema*>(this), &UReferenceViewerSchema::GetMakeCollectionWithSubMenu)
  97. );
  98. }
  99. {
  100. FToolMenuSection& Section = Menu->AddSection(TEXT("References"), NSLOCTEXT("ReferenceViewerSchema", "ReferencesSectionLabel", "References"));
  101. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().CopyReferencedObjects);
  102. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().CopyReferencingObjects);
  103. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ShowReferencedObjects);
  104. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ShowReferencingObjects);
  105. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ShowReferenceTree);
  106. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().ViewSizeMap);
  107. FToolMenuEntry ViewAssetAuditEntry = FToolMenuEntry::InitMenuEntry(FAssetManagerEditorCommands::Get().ViewAssetAudit);
  108. ViewAssetAuditEntry.Name = TEXT("ContextMenu");
  109. Section.AddEntry(ViewAssetAuditEntry);
  110. }
  111. #endif
  112. }
  113. FLinearColor UExtDependencyViewerSchema::GetPinTypeColor(const FEdGraphPinType& PinType) const
  114. {
  115. if (PinType.PinCategory == TEXT("hard"))
  116. {
  117. return RiceFlower;
  118. }
  119. else
  120. {
  121. return CannonPink;
  122. }
  123. }
  124. void UExtDependencyViewerSchema::BreakPinLinks(UEdGraphPin& TargetPin, bool bSendsNodeNotifcation) const
  125. {
  126. // Don't allow breaking any links
  127. }
  128. void UExtDependencyViewerSchema::BreakSinglePinLink(UEdGraphPin* SourcePin, UEdGraphPin* TargetPin) const
  129. {
  130. // Don't allow breaking any links
  131. }
  132. FPinConnectionResponse UExtDependencyViewerSchema::MovePinLinks(UEdGraphPin& MoveFromPin, UEdGraphPin& MoveToPin, bool bIsIntermediateMove, bool bNotifyLinkedNodes) const
  133. {
  134. // Don't allow moving any links
  135. return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, FString());
  136. }
  137. FPinConnectionResponse UExtDependencyViewerSchema::CopyPinLinks(UEdGraphPin& CopyFromPin, UEdGraphPin& CopyToPin, bool bIsIntermediateCopy) const
  138. {
  139. // Don't allow copying any links
  140. return FPinConnectionResponse(CONNECT_RESPONSE_DISALLOW, FString());
  141. }
  142. FConnectionDrawingPolicy* UExtDependencyViewerSchema::CreateConnectionDrawingPolicy(int32 InBackLayerID, int32 InFrontLayerID, float InZoomFactor, const FSlateRect& InClippingRect, class FSlateWindowElementList& InDrawElements, class UEdGraph* InGraphObj) const
  143. {
  144. return new FExtDependencyViewerConnectionDrawingPolicy(InBackLayerID, InFrontLayerID, InZoomFactor, InClippingRect, InDrawElements);
  145. }
  146. void UExtDependencyViewerSchema::GetAssetsGraphHoverMessage(const TArray<FAssetData>& Assets, const UEdGraph* HoverGraph, FString& OutTooltipText, bool& OutOkIcon) const
  147. {
  148. OutOkIcon = true;
  149. }
  150. void UExtDependencyViewerSchema::GetMakeCollectionWithSubMenu(UToolMenu* Menu)
  151. {
  152. #if ECB_LEGACY
  153. FToolMenuSection& Section = Menu->AddSection("Section");
  154. Section.AddSubMenu(
  155. "MakeCollectionWithReferencers",
  156. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithReferencersTitle", "Referencers <-"),
  157. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithReferencersTooltip", "Makes a collection with assets one connection to the left of selected nodes."),
  158. FNewToolMenuDelegate::CreateUObject(this, &UReferenceViewerSchema::GetMakeCollectionWithReferencersOrDependenciesSubMenu, true)
  159. );
  160. Section.AddSubMenu(
  161. "MakeCollectionWithDependencies",
  162. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithDependenciesTitle", "Dependencies ->"),
  163. NSLOCTEXT("ReferenceViewerSchema", "MakeCollectionWithDependenciesTooltip", "Makes a collection with assets one connection to the right of selected nodes."),
  164. FNewToolMenuDelegate::CreateUObject(this, &UReferenceViewerSchema::GetMakeCollectionWithReferencersOrDependenciesSubMenu, false)
  165. );
  166. #endif
  167. }
  168. void UExtDependencyViewerSchema::GetMakeCollectionWithReferencersOrDependenciesSubMenu(UToolMenu* Menu, bool bReferencers)
  169. {
  170. #if ECB_LEGACY
  171. FToolMenuSection& Section = Menu->AddSection("Section");
  172. if (bReferencers)
  173. {
  174. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakeLocalCollectionWithReferencers,
  175. TAttribute<FText>(),
  176. ECollectionShareType::GetDescription(ECollectionShareType::CST_Local),
  177. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Local))
  178. );
  179. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakePrivateCollectionWithReferencers,
  180. TAttribute<FText>(),
  181. ECollectionShareType::GetDescription(ECollectionShareType::CST_Private),
  182. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Private))
  183. );
  184. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakeSharedCollectionWithReferencers,
  185. TAttribute<FText>(),
  186. ECollectionShareType::GetDescription(ECollectionShareType::CST_Shared),
  187. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Shared))
  188. );
  189. }
  190. else
  191. {
  192. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakeLocalCollectionWithDependencies,
  193. TAttribute<FText>(),
  194. ECollectionShareType::GetDescription(ECollectionShareType::CST_Local),
  195. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Local))
  196. );
  197. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakePrivateCollectionWithDependencies,
  198. TAttribute<FText>(),
  199. ECollectionShareType::GetDescription(ECollectionShareType::CST_Private),
  200. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Private))
  201. );
  202. Section.AddMenuEntry(FAssetManagerEditorCommands::Get().MakeSharedCollectionWithDependencies,
  203. TAttribute<FText>(),
  204. ECollectionShareType::GetDescription(ECollectionShareType::CST_Shared),
  205. FSlateIcon(FAppStyle::GetStyleSetName(), ECollectionShareType::GetIconStyleName(ECollectionShareType::CST_Shared))
  206. );
  207. }
  208. #endif
  209. }