SGenerateSoundBanks.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. /*------------------------------------------------------------------------------------
  16. SGenerateSoundBanks.cpp
  17. ------------------------------------------------------------------------------------*/
  18. #include "SGenerateSoundBanks.h"
  19. #include "AkAudioBankGenerationHelpers.h"
  20. #include "AkAudioDevice.h"
  21. #include "AkSettingsPerUser.h"
  22. #include "WwiseUEFeatures.h"
  23. #include "AssetManagement/AkGenerateSoundBanksTask.h"
  24. #include "AssetRegistry/AssetRegistryModule.h"
  25. #include "Dialogs/Dialogs.h"
  26. #include "Dom/JsonObject.h"
  27. #include "Framework/Application/SlateApplication.h"
  28. #include "GenericPlatform/GenericPlatformFile.h"
  29. #if UE_5_0_OR_LATER
  30. #include "HAL/PlatformFileManager.h"
  31. #else
  32. #include "HAL/PlatformFilemanager.h"
  33. #endif
  34. #include "Interfaces/ITargetPlatform.h"
  35. #include "Interfaces/ITargetPlatformManagerModule.h"
  36. #include "Misc/FileHelper.h"
  37. #include "Misc/MessageDialog.h"
  38. #include "Platforms/AkPlatformInfo.h"
  39. #include "Platforms/AkUEPlatform.h"
  40. #include "Serialization/JsonReader.h"
  41. #include "Serialization/JsonSerializer.h"
  42. #include "Widgets/Input/SButton.h"
  43. #include "Widgets/Input/SCheckBox.h"
  44. #include "AssetManagement/WwiseProjectInfo.h"
  45. #define LOCTEXT_NAMESPACE "AkAudio"
  46. SGenerateSoundBanks::SGenerateSoundBanks()
  47. {
  48. }
  49. void SGenerateSoundBanks::Construct(const FArguments& InArgs)
  50. {
  51. // Generate the list of banks and platforms
  52. PopulateList();
  53. if (PlatformNames.Num() == 0)
  54. {
  55. FMessageDialog::Open(EAppMsgType::Ok, NSLOCTEXT("AkAudio", "Warning_Ak_PlatformSupported", "Unable to generate Sound Data. Please select a valid Wwise supported platform in the 'Project Settings > Project > Supported Platforms' dialog."));
  56. return;
  57. }
  58. bool skipLanguages = false;
  59. if (auto* akSettingsPerUser = GetDefault<UAkSettingsPerUser>())
  60. {
  61. skipLanguages = akSettingsPerUser->SoundDataGenerationSkipLanguage;
  62. }
  63. // Build the form
  64. ChildSlot
  65. [
  66. SNew(SVerticalBox)
  67. +SVerticalBox::Slot()
  68. .Padding(0, 8)
  69. .FillHeight(1.f)
  70. [
  71. SNew(SHorizontalBox)
  72. +SHorizontalBox::Slot()
  73. .Padding(0, 8)
  74. .AutoWidth()
  75. [
  76. SNew(SBorder)
  77. .BorderImage( FAkAppStyle::Get().GetBrush("ToolPanel.GroupBorder") )
  78. [
  79. SAssignNew(PlatformList, SListView<TSharedPtr<FString>>)
  80. .ListItemsSource(&PlatformNames)
  81. .SelectionMode(ESelectionMode::Multi)
  82. .OnGenerateRow(this, &SGenerateSoundBanks::MakePlatformListItemWidget)
  83. .HeaderRow
  84. (
  85. SNew(SHeaderRow)
  86. + SHeaderRow::Column("Available Platforms")
  87. [
  88. SNew(SBorder)
  89. .Padding(5)
  90. .Content()
  91. [
  92. SNew(STextBlock)
  93. .Text(LOCTEXT("AkAvailablePlatforms", "Available Platforms"))
  94. ]
  95. ]
  96. )
  97. ]
  98. ]
  99. + SHorizontalBox::Slot()
  100. .Padding(0, 8)
  101. .AutoWidth()
  102. [
  103. SNew(SBorder)
  104. .BorderImage(FAkAppStyle::Get().GetBrush("ToolPanel.GroupBorder"))
  105. [
  106. SAssignNew(LanguageList, SListView<TSharedPtr<FString>>)
  107. .ListItemsSource(&LanguagesNames)
  108. .SelectionMode(ESelectionMode::Multi)
  109. .OnGenerateRow(this, &SGenerateSoundBanks::MakePlatformListItemWidget)
  110. .HeaderRow
  111. (
  112. SNew(SHeaderRow)
  113. + SHeaderRow::Column("Available Languages")
  114. [
  115. SNew(SBorder)
  116. .Padding(5)
  117. .Content()
  118. [
  119. SNew(STextBlock)
  120. .Text(LOCTEXT("AkAvailableLanguages", "Available Languages"))
  121. ]
  122. ]
  123. )
  124. ]
  125. ]
  126. ]
  127. + SVerticalBox::Slot()
  128. .AutoHeight()
  129. .Padding(0, 4)
  130. .HAlign(HAlign_Left)
  131. [
  132. SAssignNew(SkipLanguagesCheckBox, SCheckBox)
  133. .IsChecked(skipLanguages ? ECheckBoxState::Checked : ECheckBoxState::Unchecked)
  134. .Content()
  135. [
  136. SNew(STextBlock)
  137. .Text(LOCTEXT("AkSkipVOFiles", "Skip generation of localized assets"))
  138. ]
  139. ]
  140. +SVerticalBox::Slot()
  141. .AutoHeight()
  142. .Padding(0, 4)
  143. .HAlign(HAlign_Right)
  144. [
  145. SNew(SButton)
  146. .Text(LOCTEXT("AkGenerate", "Generate"))
  147. .OnClicked(this, &SGenerateSoundBanks::OnGenerateButtonClicked)
  148. ]
  149. ];
  150. // Select all the platforms
  151. for (const auto& platform : PlatformNames)
  152. {
  153. PlatformList->SetItemSelection(platform, true);
  154. }
  155. // Select all the languages
  156. for (const auto& language : LanguagesNames)
  157. {
  158. LanguageList->SetItemSelection(language, true);
  159. }
  160. }
  161. void SGenerateSoundBanks::PopulateList(void)
  162. {
  163. // Get platforms in Wwise project
  164. wwiseProjectInfo.Parse();
  165. PlatformNames.Empty();
  166. for (const auto& WwisePlatform : wwiseProjectInfo.GetSupportedPlatforms())
  167. {
  168. const FString WwisePlatformName = WwisePlatform.Name;
  169. if (!WwisePlatformName.IsEmpty() &&
  170. !PlatformNames.ContainsByPredicate([WwisePlatformName](TSharedPtr<FString> Platform) { return WwisePlatformName == *Platform; }))
  171. {
  172. PlatformNames.Add(MakeShared<FString>(WwisePlatformName));
  173. }
  174. }
  175. LanguagesNames.Empty();
  176. for (const auto& language : wwiseProjectInfo.GetSupportedLanguages())
  177. {
  178. LanguagesNames.Add(MakeShared<FString>(language.Name));
  179. }
  180. }
  181. FReply SGenerateSoundBanks::OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& InKeyboardEvent )
  182. {
  183. if( InKeyboardEvent.GetKey() == EKeys::Enter )
  184. {
  185. return OnGenerateButtonClicked();
  186. }
  187. else if( InKeyboardEvent.GetKey() == EKeys::Escape )
  188. {
  189. TSharedPtr<SWindow> ParentWindow = FSlateApplication::Get().FindWidgetWindow(AsShared());
  190. ParentWindow->RequestDestroyWindow();
  191. return FReply::Handled();
  192. }
  193. return SCompoundWidget::OnKeyDown(MyGeometry, InKeyboardEvent);
  194. }
  195. FReply SGenerateSoundBanks::OnGenerateButtonClicked()
  196. {
  197. TArray< TSharedPtr<FString> > PlatformsToGenerate = PlatformList->GetSelectedItems();
  198. if( PlatformsToGenerate.Num() <= 0 )
  199. {
  200. FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("AkAudio", "Warning_Ak_NoAkPlatformsSelected", "At least one platform must be selected."));
  201. return FReply::Handled();
  202. }
  203. AkSoundBankGenerationManager::FInitParameters InitParameters;
  204. for (auto& platform : PlatformsToGenerate)
  205. {
  206. InitParameters.Platforms.Add(*platform.Get());
  207. }
  208. TArray<TSharedPtr<FString>> languagesToGenerate = LanguageList->GetSelectedItems();
  209. for (auto& selectedLanguage : languagesToGenerate)
  210. {
  211. for (auto& entry : wwiseProjectInfo.GetSupportedLanguages())
  212. {
  213. if (*selectedLanguage == entry.Name)
  214. {
  215. InitParameters.Languages.Add(entry.Name);
  216. break;
  217. }
  218. }
  219. }
  220. InitParameters.SkipLanguages = SkipLanguagesCheckBox->IsChecked();
  221. if (auto* akSettingsPerUser = GetMutableDefault<UAkSettingsPerUser>())
  222. {
  223. akSettingsPerUser->SoundDataGenerationSkipLanguage = InitParameters.SkipLanguages;
  224. akSettingsPerUser->SaveConfig();
  225. }
  226. if (FAkWaapiClient::IsProjectLoaded())
  227. {
  228. InitParameters.GenerationMode = AkSoundBankGenerationManager::ESoundBankGenerationMode::WAAPI;
  229. }
  230. AkGenerateSoundBanksTask::CreateAndExecuteTask(InitParameters);
  231. TSharedPtr<SWindow> ParentWindow = FSlateApplication::Get().FindWidgetWindow(AsShared());
  232. ParentWindow->RequestDestroyWindow();
  233. return FReply::Handled();
  234. }
  235. TSharedRef<ITableRow> SGenerateSoundBanks::MakePlatformListItemWidget(TSharedPtr<FString> Platform, const TSharedRef<STableViewBase>& OwnerTable)
  236. {
  237. return
  238. SNew(STableRow< TSharedPtr<FString> >, OwnerTable)
  239. [
  240. SNew(SBox)
  241. .WidthOverride(300)
  242. [
  243. SNew(STextBlock)
  244. .Text(FText::FromString(*Platform))
  245. ]
  246. ];
  247. }
  248. #undef LOCTEXT_NAMESPACE