AkSurfaceReflectorSetDetailsCustomization.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "AkSurfaceReflectorSetDetailsCustomization.h"
  16. #include "AkComponent.h"
  17. #include "AkSurfaceReflectorSetComponent.h"
  18. #include "DetailCategoryBuilder.h"
  19. #include "DetailLayoutBuilder.h"
  20. #include "DetailWidgetRow.h"
  21. #include "EditorModeManager.h"
  22. #include "EditorSupportDelegates.h"
  23. #include "IPropertyUtilities.h"
  24. #include "LevelEditorActions.h"
  25. #include "Model.h"
  26. #include "GameFramework/Volume.h"
  27. #include "UI/SAcousticSurfacesController.h"
  28. #include "Widgets/Input/SButton.h"
  29. #include "Widgets/Layout/SBox.h"
  30. #include "Widgets/Text/STextBlock.h"
  31. #include "Builders/ConeBuilder.h"
  32. #include "Builders/CubeBuilder.h"
  33. #include "Builders/CurvedStairBuilder.h"
  34. #include "Builders/CylinderBuilder.h"
  35. #include "Builders/LinearStairBuilder.h"
  36. #include "Builders/SpiralStairBuilder.h"
  37. #include "Builders/TetrahedronBuilder.h"
  38. #define LOCTEXT_NAMESPACE "AudiokineticTools"
  39. //////////////////////////////////////////////////////////////////////////
  40. // FAkSurfaceReflectorSetDetailsCustomization
  41. FAkSurfaceReflectorSetDetailsCustomization::FAkSurfaceReflectorSetDetailsCustomization()
  42. {
  43. ReflectorSetBeingCustomized = nullptr;
  44. FCoreUObjectDelegates::OnObjectModified.AddRaw(this, &FAkSurfaceReflectorSetDetailsCustomization::OnObjectModified);
  45. FEditorSupportDelegates::RedrawAllViewports.AddRaw(this, &FAkSurfaceReflectorSetDetailsCustomization::OnRedrawViewports);
  46. }
  47. FAkSurfaceReflectorSetDetailsCustomization::~FAkSurfaceReflectorSetDetailsCustomization()
  48. {
  49. FCoreUObjectDelegates::OnObjectModified.RemoveAll(this);
  50. FEditorSupportDelegates::RedrawAllViewports.RemoveAll(this);
  51. if (ReflectorSetBeingCustomized.IsValid() && ReflectorSetBeingCustomized->GetOnRefreshDetails())
  52. {
  53. if (ReflectorSetBeingCustomized->GetOnRefreshDetails()->IsBoundToObject(this))
  54. {
  55. ReflectorSetBeingCustomized->ClearOnRefreshDetails();
  56. }
  57. }
  58. ReflectorSetBeingCustomized.Reset();
  59. }
  60. FReply FAkSurfaceReflectorSetDetailsCustomization::OnEnableEditModeClicked()
  61. {
  62. FLevelEditorActionCallbacks::OnShowOnlySelectedActors();
  63. GLevelEditorModeTools().ActivateMode(FEditorModeID(TEXT("EM_Geometry")), false);
  64. return FReply::Handled();
  65. }
  66. FReply FAkSurfaceReflectorSetDetailsCustomization::OnDisableEditModeClicked()
  67. {
  68. GLevelEditorModeTools().DeactivateMode(FEditorModeID(TEXT("EM_Geometry")));
  69. FLevelEditorActionCallbacks::ExecuteExecCommand(FString(TEXT("ACTOR UNHIDE ALL")));
  70. return FReply::Handled();
  71. }
  72. void FAkSurfaceReflectorSetDetailsCustomization::OnObjectModified(UObject* Object)
  73. {
  74. if (!SelectedObjectModifiedThisFrame)
  75. {
  76. for (TWeakObjectPtr<UObject> UObjectPtr : ObjectsBeingCustomized)
  77. {
  78. if (Object == UObjectPtr.Get())
  79. {
  80. SelectedObjectModifiedThisFrame = true;
  81. return;
  82. }
  83. }
  84. }
  85. }
  86. void FAkSurfaceReflectorSetDetailsCustomization::OnRedrawViewports()
  87. {
  88. if (SelectedObjectModifiedThisFrame && DetailBuilder.IsValid())
  89. {
  90. // If there is any user interaction going on, we don't want to refresh the details panel.
  91. // (This would interrupt the interaction and make sliders unusable)
  92. for (TWeakObjectPtr<UObject> UObjectPtr : ObjectsBeingCustomized)
  93. {
  94. if (UAkSurfaceReflectorSetComponent* reflectorSet = Cast<UAkSurfaceReflectorSetComponent>(UObjectPtr.Get()))
  95. {
  96. if (reflectorSet->UserInteractionInProgress)
  97. {
  98. return;
  99. }
  100. }
  101. }
  102. IDetailLayoutBuilder* Layout = nullptr;
  103. if (auto LockedDetailBuilder = DetailBuilder.Pin())
  104. {
  105. Layout = LockedDetailBuilder.Get();
  106. }
  107. if (LIKELY(Layout))
  108. {
  109. Layout->ForceRefreshDetails();
  110. }
  111. SelectedObjectModifiedThisFrame = false;
  112. }
  113. }
  114. TSharedRef<IDetailCustomization> FAkSurfaceReflectorSetDetailsCustomization::MakeInstance()
  115. {
  116. return MakeShareable(new FAkSurfaceReflectorSetDetailsCustomization());
  117. }
  118. void FAkSurfaceReflectorSetDetailsCustomization::CustomizeDetails(const TSharedPtr<IDetailLayoutBuilder>& InDetailBuilder)
  119. {
  120. InDetailBuilder->EditCategory("EnableComponent", FText::GetEmpty(), ECategoryPriority::Important);
  121. InDetailBuilder->EditCategory("SurfaceReflectorSet", FText::GetEmpty(), ECategoryPriority::TypeSpecific);
  122. DetailBuilder = InDetailBuilder;
  123. CustomizeDetails(*InDetailBuilder);
  124. }
  125. void FAkSurfaceReflectorSetDetailsCustomization::CustomizeDetails(IDetailLayoutBuilder& InDetailBuilder)
  126. {
  127. InDetailBuilder.GetObjectsBeingCustomized(ObjectsBeingCustomized);
  128. auto AcousticPolysPropHandle = InDetailBuilder.GetProperty("AcousticPolys");
  129. InDetailBuilder.HideProperty("AcousticPolys");
  130. bool showGeometrySettings = false;
  131. for (int i = 0; i < ObjectsBeingCustomized.Num(); ++i)
  132. {
  133. auto Component = Cast<UAkSurfaceReflectorSetComponent>(ObjectsBeingCustomized[i].Get());
  134. if (Component)
  135. {
  136. ReflectorSetBeingCustomized = TWeakObjectPtr<UAkSurfaceReflectorSetComponent>(Component);
  137. if (ReflectorSetBeingCustomized->bEnableSurfaceReflectors)
  138. {
  139. showGeometrySettings = true;
  140. break;
  141. }
  142. }
  143. }
  144. if (!showGeometrySettings)
  145. InDetailBuilder.HideCategory("SurfaceReflectorSet");
  146. IDetailCategoryBuilder& CategoryBuilder = InDetailBuilder.EditCategory("Surface Properties", FText::GetEmpty(), ECategoryPriority::TypeSpecific);
  147. FString enableEditSurfacesTooltip(FString("Enable ") + GEOMETRY_EDIT_DISPLAY_NAME + " and show only selected actors");
  148. FString disableEditSurfacesTooltip(FString("Disable ") + GEOMETRY_EDIT_DISPLAY_NAME + " and show all actors");
  149. CategoryBuilder.HeaderContent
  150. (
  151. SNew(SHorizontalBox)
  152. + SHorizontalBox::Slot()
  153. .HAlign(HAlign_Left)
  154. .VAlign(VAlign_Center)
  155. .AutoWidth()
  156. [
  157. SAssignNew(SelectionInfoLabel, STextBlock)
  158. // SelectionInfoLabel is passed in to a SAcousticSurfacesController below, and the selection text is set during its construction.
  159. .Text(FText::FromString(""))
  160. ]
  161. + SHorizontalBox::Slot()
  162. .AutoWidth()
  163. .HAlign(HAlign_Left)
  164. .VAlign(VAlign_Center)
  165. [
  166. SNew(SButton)
  167. .Text(FText::FromString("Enable Edit Surfaces "))
  168. .ToolTipText(FText::FromString(enableEditSurfacesTooltip))
  169. .OnClicked(this, &FAkSurfaceReflectorSetDetailsCustomization::OnEnableEditModeClicked)
  170. ]
  171. + SHorizontalBox::Slot()
  172. .AutoWidth()
  173. .HAlign(HAlign_Left)
  174. .VAlign(VAlign_Center)
  175. [
  176. SNew(SButton)
  177. .Text(FText::FromString("Disable Edit Surfaces"))
  178. .ToolTipText(FText::FromString(disableEditSurfacesTooltip))
  179. .OnClicked(this, &FAkSurfaceReflectorSetDetailsCustomization::OnDisableEditModeClicked)
  180. ]
  181. );
  182. // Assume Transmission Loss controls will be hidden
  183. int surfacePropertiesControlsHeight = 48;
  184. for (TWeakObjectPtr<UObject> ObjectBeingCustomized : ObjectsBeingCustomized)
  185. {
  186. UAkSurfaceReflectorSetComponent* reflectorSetComponent = Cast<UAkSurfaceReflectorSetComponent>(ObjectBeingCustomized.Get());
  187. if (reflectorSetComponent && reflectorSetComponent->bEnableSurfaceReflectors)
  188. {
  189. // There is a surface reflector set with bEnableSurfaceReflectors enabled - add room for Transmission Loss controls.
  190. surfacePropertiesControlsHeight = 72;
  191. break;
  192. }
  193. }
  194. if (auto LockedDetailBuilder = DetailBuilder.Pin())
  195. {
  196. FDetailWidgetRow& acousticSurfacesRow = CategoryBuilder.AddCustomRow(AcousticPolysPropHandle->GetPropertyDisplayName());
  197. acousticSurfacesRow.NameContent()
  198. [
  199. SNew(SBox)
  200. .HeightOverride(surfacePropertiesControlsHeight)
  201. [
  202. SNew(SAcousticSurfacesLabels, ObjectsBeingCustomized)
  203. ]
  204. ];
  205. acousticSurfacesRow.ValueContent()
  206. [
  207. SNew(SBox)
  208. .HeightOverride(surfacePropertiesControlsHeight)
  209. [
  210. SNew(SAcousticSurfacesController, ObjectsBeingCustomized, LockedDetailBuilder)
  211. ]
  212. ];
  213. }
  214. if (ObjectsBeingCustomized.Num() == 1)
  215. {
  216. auto Component = Cast<UAkSurfaceReflectorSetComponent>(ObjectsBeingCustomized[0].Get());
  217. if (Component)
  218. {
  219. ReflectorSetBeingCustomized = TWeakObjectPtr<UAkSurfaceReflectorSetComponent>(Component);
  220. SetupGeometryModificationHandlers();
  221. }
  222. else
  223. {
  224. ReflectorSetBeingCustomized.Reset();
  225. UE_LOG(LogAkAudio, Log, TEXT("FAkSurfaceReflectorSetDetailsCustomization::CustomizeDetails: Could not get ObjectsBeingCustomized."));
  226. }
  227. }
  228. }
  229. #define REGISTER_PROPERTY_CHANGED(Class, Property, LockedDetailBuilder) \
  230. auto Property ## Handle = LockedDetailBuilder->GetProperty(GET_MEMBER_NAME_CHECKED(Class, Property), Class::StaticClass(), BrushBuilderName); \
  231. if (Property ## Handle->IsValidHandle()) Property ## Handle->SetOnPropertyValueChanged(FSimpleDelegate::CreateSP(this, &FAkSurfaceReflectorSetDetailsCustomization::OnGeometryChanged))
  232. void FAkSurfaceReflectorSetDetailsCustomization::SetupGeometryModificationHandlers()
  233. {
  234. if (!ReflectorSetBeingCustomized.IsValid())
  235. {
  236. return;
  237. }
  238. static const FName BrushBuilderName(TEXT("BrushBuilder"));
  239. auto ParentBrush = ReflectorSetBeingCustomized->ParentBrush;
  240. if(!ParentBrush)
  241. return;
  242. if (auto LockedDetailBuilder = DetailBuilder.Pin())
  243. {
  244. auto EnableHandle = LockedDetailBuilder->GetProperty("bEnableSurfaceReflectors");
  245. EnableHandle->SetOnPropertyValueChanged(FSimpleDelegate::CreateSP(this, &FAkSurfaceReflectorSetDetailsCustomization::OnEnableValueChanged));
  246. // This is to detect if the BrushBuilder changed.
  247. if (ReflectorSetBeingCustomized->AcousticPolys.Num() != ParentBrush->Nodes.Num())
  248. LockedDetailBuilder->GetPropertyUtilities()->EnqueueDeferredAction(FSimpleDelegate::CreateSP(this, &FAkSurfaceReflectorSetDetailsCustomization::OnGeometryChanged));
  249. }
  250. // Need to register to a LOT of different properties, because some change the geometry but don't force a refresh of the details panel
  251. AVolume* ParentVolume = Cast<AVolume>(ReflectorSetBeingCustomized->GetOwner());
  252. UClass* BrushBuilderClass = nullptr;
  253. if (ParentVolume && ParentVolume->BrushBuilder)
  254. {
  255. BrushBuilderClass = ParentVolume->BrushBuilder->GetClass();
  256. if (BrushBuilderClass == nullptr)
  257. {
  258. return;
  259. }
  260. }
  261. if (auto LockedDetailBuilder = DetailBuilder.Pin())
  262. {
  263. if (BrushBuilderClass == UConeBuilder::StaticClass())
  264. {
  265. REGISTER_PROPERTY_CHANGED(UConeBuilder, Sides, LockedDetailBuilder);
  266. REGISTER_PROPERTY_CHANGED(UConeBuilder, Hollow, LockedDetailBuilder);
  267. }
  268. else if (BrushBuilderClass == UCubeBuilder::StaticClass())
  269. {
  270. REGISTER_PROPERTY_CHANGED(UCubeBuilder, Hollow, LockedDetailBuilder);
  271. REGISTER_PROPERTY_CHANGED(UCubeBuilder, Tessellated, LockedDetailBuilder);
  272. }
  273. else if (BrushBuilderClass == UCurvedStairBuilder::StaticClass())
  274. {
  275. REGISTER_PROPERTY_CHANGED(UCurvedStairBuilder, NumSteps, LockedDetailBuilder);
  276. }
  277. else if (BrushBuilderClass == UCylinderBuilder::StaticClass())
  278. {
  279. REGISTER_PROPERTY_CHANGED(UCylinderBuilder, Sides, LockedDetailBuilder);
  280. REGISTER_PROPERTY_CHANGED(UCylinderBuilder, Hollow, LockedDetailBuilder);
  281. }
  282. else if (BrushBuilderClass == ULinearStairBuilder::StaticClass())
  283. {
  284. REGISTER_PROPERTY_CHANGED(ULinearStairBuilder, NumSteps, LockedDetailBuilder);
  285. }
  286. else if (BrushBuilderClass == USpiralStairBuilder::StaticClass())
  287. {
  288. REGISTER_PROPERTY_CHANGED(USpiralStairBuilder, NumSteps, LockedDetailBuilder);
  289. }
  290. else if (BrushBuilderClass == UTetrahedronBuilder::StaticClass())
  291. {
  292. REGISTER_PROPERTY_CHANGED(UTetrahedronBuilder, SphereExtrapolation, LockedDetailBuilder);
  293. }
  294. }
  295. FOnRefreshDetails DetailsChanged = FOnRefreshDetails::CreateRaw(this, &FAkSurfaceReflectorSetDetailsCustomization::OnEnableValueChanged);
  296. ReflectorSetBeingCustomized->SetOnRefreshDetails(DetailsChanged);
  297. }
  298. void FAkSurfaceReflectorSetDetailsCustomization::OnEnableValueChanged()
  299. {
  300. if (ReflectorSetBeingCustomized.IsValid())
  301. {
  302. ReflectorSetBeingCustomized->ClearOnRefreshDetails();
  303. }
  304. }
  305. void FAkSurfaceReflectorSetDetailsCustomization::OnGeometryChanged()
  306. {
  307. if (ReflectorSetBeingCustomized.IsValid())
  308. {
  309. ReflectorSetBeingCustomized->UpdatePolys();
  310. ReflectorSetBeingCustomized->ClearOnRefreshDetails();
  311. }
  312. }
  313. //////////////////////////////////////////////////////////////////////////
  314. #undef LOCTEXT_NAMESPACE