SExtDependencyNode.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #include "SExtDependencyNode.h"
  3. #include "ExtContentBrowser.h"
  4. #include "EdGraphNode_ExtDependency.h"
  5. #include "ExtAssetThumbnail.h"
  6. #include "ExtContentBrowserSettings.h"
  7. #include "ExtContentBrowserStyle.h"
  8. #include "Widgets/SBoxPanel.h"
  9. #include "Widgets/Layout/SSpacer.h"
  10. #include "Widgets/Images/SImage.h"
  11. #include "Widgets/Layout/SBox.h"
  12. #include "Widgets/Text/SInlineEditableTextBlock.h"
  13. #include "SCommentBubble.h"
  14. #define LOCTEXT_NAMESPACE "ExtDependencyViewer"
  15. void SExtDependencyNode::Construct( const FArguments& InArgs, UEdGraphNode_ExtDependency* InNode )
  16. {
  17. const int32 ThumbnailSize = 128;
  18. ECB_LOG(Display, TEXT("SExtDependencyNode::Construct: %s"), *InNode->GetNodeTitle(ENodeTitleType::FullTitle).ToString());
  19. if (InNode->UsesThumbnail())
  20. {
  21. // Create a thumbnail from the graph's thumbnail pool
  22. TSharedPtr<FExtAssetThumbnailPool> AssetThumbnailPool = InNode->GetDependencyViewerGraph()->GetAssetThumbnailPool();
  23. AssetThumbnail = MakeShareable( new FExtAssetThumbnail( InNode->GetAssetData(), ThumbnailSize, ThumbnailSize, AssetThumbnailPool ) );
  24. }
  25. else if (InNode->IsPackage() || InNode->IsCollapsed())
  26. {
  27. // Just make a generic thumbnail
  28. AssetThumbnail = MakeShareable( new FExtAssetThumbnail( InNode->GetAssetData(), ThumbnailSize, ThumbnailSize, NULL ) );
  29. }
  30. GraphNode = InNode;
  31. SetCursor( EMouseCursor::CardinalCross );
  32. UpdateGraphNode();
  33. }
  34. void SExtDependencyNode::UpdateGraphNode()
  35. {
  36. OutputPins.Empty();
  37. // Reset variables that are going to be exposed, in case we are refreshing an already setup node.
  38. RightNodeBox.Reset();
  39. LeftNodeBox.Reset();
  40. UpdateErrorInfo();
  41. //
  42. // ______________________
  43. // | TITLE AREA |
  44. // +-------+------+-------+
  45. // | (>) L | | R (>) |
  46. // | (>) E | | I (>) |
  47. // | (>) F | | G (>) |
  48. // | (>) T | | H (>) |
  49. // | | | T (>) |
  50. // |_______|______|_______|
  51. //
  52. TSharedPtr<SVerticalBox> MainVerticalBox;
  53. TSharedPtr<SErrorText> ErrorText;
  54. TSharedPtr<SNodeTitle> NodeTitle = SNew(SNodeTitle, GraphNode);
  55. const float LeftRightWidth = 10.f;
  56. TSharedRef<SWidget> ThumbnailWidget = SNullWidget::NullWidget;
  57. if ( AssetThumbnail.IsValid() )
  58. {
  59. UEdGraphNode_ExtDependency* RefGraphNode = CastChecked<UEdGraphNode_ExtDependency>(GraphNode);
  60. FExtAssetThumbnailConfig ThumbnailConfig;
  61. ThumbnailConfig.bAllowFadeIn = RefGraphNode->UsesThumbnail();
  62. ThumbnailConfig.bForceGenericThumbnail = !RefGraphNode->UsesThumbnail();
  63. ThumbnailConfig.bAllowAssetSpecificThumbnailOverlay = false; // Disable asset thumbnail overlay
  64. ThumbnailWidget =
  65. SNew(SBorder)
  66. .BorderImage(FAppStyle::GetBrush("Graph.Node.Body"))
  67. .Padding(0)
  68. [
  69. SNew(SBox)
  70. .WidthOverride(AssetThumbnail->GetSize().X)
  71. .HeightOverride(AssetThumbnail->GetSize().Y)
  72. [
  73. AssetThumbnail->MakeThumbnailWidget(ThumbnailConfig)
  74. ]
  75. ];
  76. }
  77. ContentScale.Bind( this, &SExtDependencyNode::GetContentScale );
  78. GetOrAddSlot( ENodeZone::Center )
  79. .HAlign(HAlign_Center)
  80. .VAlign(VAlign_Center)
  81. [
  82. SNew(SOverlay)
  83. // MainVerticalBox Overlay >>
  84. #if ECB_FOLD
  85. + SOverlay::Slot()
  86. .HAlign(HAlign_Fill)
  87. .VAlign(VAlign_Fill)
  88. [
  89. SAssignNew(MainVerticalBox, SVerticalBox)
  90. +SVerticalBox::Slot()
  91. .AutoHeight()
  92. [
  93. SNew(SBorder)
  94. .BorderImage(FAppStyle::GetBrush( "Graph.Node.Body" ) )
  95. .Padding(0)
  96. [
  97. SNew(SVerticalBox)
  98. . ToolTipText( this, &SExtDependencyNode::GetNodeTooltip )
  99. +SVerticalBox::Slot()
  100. .AutoHeight()
  101. .HAlign(HAlign_Fill)
  102. .VAlign(VAlign_Top)
  103. [
  104. SNew(SOverlay)
  105. // +SOverlay::Slot()
  106. // [
  107. // SNew(SImage)
  108. // .Image( FAppStyle::GetBrush("Graph.Node.TitleGloss") )
  109. // ]
  110. +SOverlay::Slot()
  111. .HAlign(HAlign_Left)
  112. .VAlign(VAlign_Center)
  113. [
  114. SNew(SBorder)
  115. .BorderImage(FAppStyle::GetBrush("Graph.Node.ColorSpill") )
  116. // The extra margin on the right
  117. // is for making the color spill stretch well past the node title
  118. //.Padding( FMargin(10,5,30,3) )
  119. .Padding(FMargin(10, 5, 5, 3))
  120. .BorderBackgroundColor( this, &SExtDependencyNode::GetNodeTitleBackgroundColor)
  121. [
  122. SNew(SVerticalBox)
  123. +SVerticalBox::Slot()
  124. .AutoHeight()
  125. [
  126. SNew(SBox)
  127. .WidthOverride(AssetThumbnail->GetSize().X - 5.f)
  128. [
  129. SAssignNew(InlineEditableText, SInlineEditableTextBlock)
  130. .Style(FAppStyle::Get(), "Graph.Node.NodeTitleInlineEditableText")
  131. .Text(NodeTitle.Get(), &SNodeTitle::GetHeadTitle)
  132. .OnVerifyTextChanged(this, &SExtDependencyNode::OnVerifyNameTextChanged)
  133. .OnTextCommitted(this, &SExtDependencyNode::OnNameTextCommited)
  134. .IsReadOnly(this, &SExtDependencyNode::IsNameReadOnly)
  135. .IsSelected(this, &SExtDependencyNode::IsSelectedExclusively)
  136. ]
  137. ]
  138. +SVerticalBox::Slot()
  139. .AutoHeight()
  140. [
  141. NodeTitle.ToSharedRef()
  142. ]
  143. ]
  144. ]
  145. // +SOverlay::Slot()
  146. // .VAlign(VAlign_Top)
  147. // [
  148. // SNew(SBorder)
  149. // .BorderImage( FAppStyle::GetBrush( "Graph.Node.TitleHighlight" ) )
  150. // .Visibility(EVisibility::HitTestInvisible)
  151. // [
  152. // SNew(SSpacer)
  153. // .Size(FVector2D(20,20))
  154. // ]
  155. // ]
  156. ]
  157. +SVerticalBox::Slot()
  158. .AutoHeight()
  159. .Padding(1.0f)
  160. [
  161. // POPUP ERROR MESSAGE
  162. SAssignNew(ErrorText, SErrorText )
  163. .BackgroundColor( this, &SExtDependencyNode::GetErrorColor )
  164. .ToolTipText( this, &SExtDependencyNode::GetErrorMsgToolTip )
  165. ]
  166. +SVerticalBox::Slot()
  167. .AutoHeight()
  168. .HAlign(HAlign_Fill)
  169. .VAlign(VAlign_Top)
  170. [
  171. // NODE CONTENT AREA
  172. SNew(SBorder)
  173. //.BorderImage( FAppStyle::GetBrush("NoBorder") )
  174. .BorderImage(FAppStyle::GetBrush("WhiteBrush"))
  175. .BorderBackgroundColor(this, &SExtDependencyNode::GetNodeBodyBackgroundColor)
  176. .HAlign(HAlign_Fill)
  177. .VAlign(VAlign_Fill)
  178. .Padding( FMargin(0,3) )
  179. [
  180. SNew(SHorizontalBox)
  181. +SHorizontalBox::Slot()
  182. .AutoWidth()
  183. .VAlign(VAlign_Center)
  184. [
  185. // LEFT
  186. SNew(SBox)
  187. .WidthOverride(LeftRightWidth)
  188. [
  189. SAssignNew(LeftNodeBox, SVerticalBox)
  190. ]
  191. ]
  192. +SHorizontalBox::Slot()
  193. .VAlign(VAlign_Center)
  194. .HAlign(HAlign_Center)
  195. .FillWidth(1.0f)
  196. [
  197. // Thumbnail
  198. ThumbnailWidget
  199. ]
  200. +SHorizontalBox::Slot()
  201. .AutoWidth()
  202. .VAlign(VAlign_Center)
  203. [
  204. // RIGHT
  205. SNew(SBox)
  206. .WidthOverride(LeftRightWidth)
  207. [
  208. SAssignNew(RightNodeBox, SVerticalBox)
  209. ]
  210. ]
  211. ]
  212. ]
  213. ]
  214. ]
  215. ]
  216. #endif // MainVerticalBox Overlay <<
  217. // Tint Overlay >>
  218. #if ECB_WIP_REF_VIEWER_HIGHLIGHT_ERROR
  219. + SOverlay::Slot()
  220. .HAlign(HAlign_Fill)
  221. .VAlign(VAlign_Fill)
  222. [
  223. SNew(SBorder)
  224. .BorderImage(FAppStyle::GetBrush("WhiteBrush"))
  225. .BorderBackgroundColor(this, &SExtDependencyNode::GetNodeOverlayColor)
  226. .Padding(FMargin(4.0f, 0.0f))
  227. //.Visibility(this, &SGraphNode_BehaviorTree::GetDebuggerSearchFailedMarkerVisibility)
  228. [
  229. SNew(SBox)
  230. .HeightOverride(4)
  231. ]
  232. ]
  233. #endif // Tint Overlay >>
  234. ];
  235. #if ECB_LEGACY
  236. // Create comment bubble if comment text is valid
  237. GetNodeObj()->bCommentBubbleVisible = !GetNodeObj()->NodeComment.IsEmpty();
  238. if( GetNodeObj()->bCommentBubbleVisible )
  239. {
  240. TSharedPtr<SCommentBubble> CommentBubble;
  241. SAssignNew( CommentBubble, SCommentBubble )
  242. .GraphNode( GraphNode )
  243. .Text( this, &SGraphNode::GetNodeComment )
  244. .ColorAndOpacity( this, &SExtDependencyNode::GetCommentColor );
  245. GetOrAddSlot( ENodeZone::TopCenter )
  246. .SlotOffset( TAttribute<FVector2D>( CommentBubble.Get(), &SCommentBubble::GetOffset ))
  247. .SlotSize( TAttribute<FVector2D>( CommentBubble.Get(), &SCommentBubble::GetSize ))
  248. .AllowScaling( TAttribute<bool>( CommentBubble.Get(), &SCommentBubble::IsScalingAllowed ))
  249. .VAlign( VAlign_Top )
  250. [
  251. CommentBubble.ToSharedRef()
  252. ];
  253. }
  254. #endif
  255. ErrorReporting = ErrorText;
  256. ErrorReporting->SetError(ErrorMsg);
  257. CreateBelowWidgetControls(MainVerticalBox);
  258. CreatePinWidgets();
  259. }
  260. FSlateColor SExtDependencyNode::GetNodeTitleBackgroundColor() const
  261. {
  262. return FLinearColor(0.3f, 0.3f, 0.3f, 0.8f);
  263. }
  264. FSlateColor SExtDependencyNode::GetNodeOverlayColor() const
  265. {
  266. #if ECB_WIP_REF_VIEWER_HIGHLIGHT_ERROR
  267. if (UEdGraphNode_ExtDependency* RefGraphNode = CastChecked<UEdGraphNode_ExtDependency>(GraphNode))
  268. {
  269. if (!RefGraphNode->IsMissingOrInvalid() && GetDefault<UExtContentBrowserSettings>()->HighlightErrorNodesInDependencyViewer)
  270. {
  271. return FLinearColor(0.f, 0.f, 0.f, 0.5f);
  272. }
  273. }
  274. #endif
  275. return FLinearColor(0.f, 0.f, 0.f, 0.f);
  276. }
  277. FSlateColor SExtDependencyNode::GetNodeBodyBackgroundColor() const
  278. {
  279. if (UEdGraphNode_ExtDependency* RefGraphNode = CastChecked<UEdGraphNode_ExtDependency>(GraphNode))
  280. {
  281. if (RefGraphNode->IsMissingOrInvalid())
  282. {
  283. if (RefGraphNode->GetDependencyPin()->PinType.PinCategory == TEXT("hard")
  284. || RefGraphNode->GetReferencerPin()->PinType.PinCategory == TEXT("hard"))
  285. {
  286. return FExtContentBrowserStyle::Get().GetColor("ErrorReporting.HardReferenceColor.Darker");
  287. }
  288. else
  289. {
  290. return FExtContentBrowserStyle::Get().GetColor("ErrorReporting.SoftReferenceColor.Darker");
  291. }
  292. }
  293. }
  294. return FLinearColor(0.f, 0.f, 0.f, 1.f);
  295. }
  296. TSharedPtr<class SGraphNode> FExtDependencyGraphPanelNodeFactory::CreateNode(UEdGraphNode* Node) const
  297. {
  298. if (UEdGraphNode_ExtDependency* DependencyNode = Cast<UEdGraphNode_ExtDependency>(Node))
  299. {
  300. return SNew(SExtDependencyNode, DependencyNode);
  301. }
  302. return nullptr;
  303. }
  304. #undef LOCTEXT_NAMESPACE