Settings.cpp 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "EditorDefs.h"
  9. #include "Settings.h"
  10. #include "EditorViewportSettings.h"
  11. // Qt
  12. #include <QGuiApplication>
  13. #include <QOperatingSystemVersion>
  14. #include <QScreen>
  15. // AzCore
  16. #include <AzCore/IO/Path/Path.h>
  17. #include <AzCore/Settings/SettingsRegistry.h>
  18. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  19. #include <AzCore/StringFunc/StringFunc.h>
  20. #include <AzCore/Utils/Utils.h>
  21. // AzFramework
  22. #include <AzFramework/API/ApplicationAPI.h>
  23. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  24. // AzToolsFramework
  25. #include <AzToolsFramework/SourceControl/SourceControlAPI.h>
  26. // Editor
  27. #include "CryEdit.h"
  28. #include "MainWindow.h"
  29. //////////////////////////////////////////////////////////////////////////
  30. // Global Instance of Editor settings.
  31. //////////////////////////////////////////////////////////////////////////
  32. SANDBOX_API SEditorSettings gSettings;
  33. Q_GLOBAL_STATIC(QSettings, s_editorSettings);
  34. const QString kDefaultColumnsForAssetBrowserList = "Filename,Path,LODs,Triangles,Submeshes,Filesize,Textures,Materials,Tags";
  35. const int EditorSettingsVersion = 2; // bump this up on every substantial settings change
  36. void KeepEditorActiveChanged(ICVar* keepEditorActive)
  37. {
  38. const int iCVarKeepEditorActive = keepEditorActive->GetIVal();
  39. CCryEditApp::instance()->KeepEditorActive(iCVarKeepEditorActive);
  40. }
  41. void ToolbarIconSizeChanged(ICVar* toolbarIconSize)
  42. {
  43. MainWindow::instance()->AdjustToolBarIconSize(static_cast<AzQtComponents::ToolBar::ToolBarIconSize>(toolbarIconSize->GetIVal()));
  44. }
  45. class SettingsGroup
  46. {
  47. public:
  48. explicit SettingsGroup(const QString& group)
  49. : m_group(group)
  50. {
  51. for (auto g : m_group.split('\\'))
  52. {
  53. s_editorSettings()->beginGroup(g);
  54. }
  55. }
  56. ~SettingsGroup()
  57. {
  58. for (auto g : m_group.split('\\'))
  59. {
  60. s_editorSettings()->endGroup();
  61. }
  62. }
  63. private:
  64. const QString m_group;
  65. };
  66. namespace
  67. {
  68. class QtApplicationListener
  69. : public AzToolsFramework::EditorEvents::Bus::Handler
  70. {
  71. public:
  72. QtApplicationListener()
  73. {
  74. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  75. }
  76. void NotifyQtApplicationAvailable(QApplication* application) override
  77. {
  78. gSettings.viewports.nDragSquareSize = application->startDragDistance();
  79. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  80. delete this;
  81. }
  82. };
  83. }
  84. //////////////////////////////////////////////////////////////////////////
  85. SEditorSettings::SEditorSettings()
  86. {
  87. bSettingsManagerMode = false;
  88. undoLevels = 50;
  89. bShowDashboardAtStartup = true;
  90. bAutoloadLastLevelAtStartup = false;
  91. bMuteAudio = false;
  92. objectHideMask = 0;
  93. objectSelectMask = 0xFFFFFFFF; // Initially all selectable.
  94. autoBackupEnabled = false;
  95. autoBackupTime = 10;
  96. autoBackupMaxCount = 3;
  97. autoRemindTime = 0;
  98. bNavigationContinuousUpdate = false;
  99. bNavigationShowAreas = true;
  100. bNavigationDebugDisplay = false;
  101. bVisualizeNavigationAccessibility = false;
  102. navigationDebugAgentType = 0;
  103. viewports.bAlwaysShowRadiuses = false;
  104. viewports.bSync2DViews = false;
  105. viewports.fDefaultAspectRatio = 800.0f / 600.0f;
  106. viewports.bHighlightSelectedGeometry = false;
  107. viewports.bHighlightSelectedVegetation = true;
  108. viewports.bHighlightMouseOverGeometry = true;
  109. viewports.bShowMeshStatsOnMouseOver = false;
  110. viewports.bDrawEntityLabels = false;
  111. viewports.bShowTriggerBounds = false;
  112. viewports.nShowFrozenHelpers = true;
  113. viewports.bFillSelectedShapes = false;
  114. viewports.nTopMapTextureResolution = 512;
  115. viewports.bTopMapSwapXY = false;
  116. viewports.bShowGridGuide = true;
  117. viewports.bHideMouseCursorWhenCaptured = true;
  118. viewports.nDragSquareSize = 0; // We must initialize this after the Qt application object is available; see QtApplicationListener
  119. viewports.bEnableContextMenu = true;
  120. viewports.fWarningIconsDrawDistance = 50.0f;
  121. viewports.bShowScaleWarnings = false;
  122. viewports.bShowRotationWarnings = false;
  123. cameraMoveSpeed = 1;
  124. cameraRotateSpeed = 1;
  125. cameraFastMoveSpeed = 2;
  126. stylusMode = false;
  127. restoreViewportCamera = true;
  128. wheelZoomSpeed = 1;
  129. invertYRotation = false;
  130. invertPan = false;
  131. bPreviewGeometryWindow = true;
  132. bBackupOnSave = true;
  133. backupOnSaveMaxCount = 3;
  134. showErrorDialogOnLoad = 1;
  135. consoleBackgroundColorTheme = AzToolsFramework::ConsoleColorTheme::Dark;
  136. bShowTimeInConsole = false;
  137. clearConsoleOnGameModeStart = false;
  138. enableSceneInspector = false;
  139. strStandardTempDirectory = "Temp";
  140. // Init source safe params.
  141. enableSourceControl = false;
  142. #if AZ_TRAIT_OS_PLATFORM_APPLE
  143. textEditorForScript = "TextEdit";
  144. textEditorForShaders = "TextEdit";
  145. textEditorForBspaces = "TextEdit";
  146. textureEditor = "Photoshop";
  147. #elif defined(AZ_PLATFORM_WINDOWS)
  148. textEditorForScript = "notepad++.exe";
  149. textEditorForShaders = "notepad++.exe";
  150. textEditorForBspaces = "notepad++.exe";
  151. textureEditor = "Photoshop.exe";
  152. #else
  153. textEditorForScript = "";
  154. textEditorForShaders = "";
  155. textEditorForBspaces = "";
  156. textureEditor = "";
  157. #endif
  158. animEditor = "";
  159. sTextureBrowserSettings.nCellSize = 128;
  160. // Experimental features settings
  161. sExperimentalFeaturesSettings.bTotalIlluminationEnabled = false;
  162. //
  163. // Asset Browser settings init
  164. //
  165. sAssetBrowserSettings.nThumbSize = 128;
  166. sAssetBrowserSettings.bShowLoadedInLevel = false;
  167. sAssetBrowserSettings.bShowUsedInLevel = false;
  168. sAssetBrowserSettings.bAutoSaveFilterPreset = true;
  169. sAssetBrowserSettings.bShowFavorites = false;
  170. sAssetBrowserSettings.bHideLods = false;
  171. sAssetBrowserSettings.bAutoChangeViewportSelection = false;
  172. sAssetBrowserSettings.bAutoFilterFromViewportSelection = false;
  173. smartOpenSettings.rect = QRect();
  174. //////////////////////////////////////////////////////////////////////////
  175. // Initialize GUI settings.
  176. //////////////////////////////////////////////////////////////////////////
  177. gui.nToolbarIconSize = static_cast<int>(AzQtComponents::ToolBar::ToolBarIconSize::Default);
  178. backgroundUpdatePeriod = 0;
  179. g_TemporaryLevelName = nullptr;
  180. levelSaveSettings.saveAllPrefabsPreference = AzToolsFramework::Prefab::SaveAllPrefabsPreference::AskEveryTime;
  181. }
  182. void SEditorSettings::Connect()
  183. {
  184. new QtApplicationListener(); // Deletes itself when it's done.
  185. AzToolsFramework::EditorSettingsAPIBus::Handler::BusConnect();
  186. }
  187. void SEditorSettings::Disconnect()
  188. {
  189. AzToolsFramework::EditorSettingsAPIBus::Handler::BusDisconnect();
  190. }
  191. //////////////////////////////////////////////////////////////////////////
  192. void SEditorSettings::SaveValue(const char* sSection, const char* sKey, int value)
  193. {
  194. const SettingsGroup sg(sSection);
  195. s_editorSettings()->setValue(sKey, value);
  196. if (!bSettingsManagerMode)
  197. {
  198. if (GetIEditor()->GetSettingsManager())
  199. {
  200. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  201. }
  202. }
  203. }
  204. //////////////////////////////////////////////////////////////////////////
  205. void SEditorSettings::SaveValue(const char* sSection, const char* sKey, const QColor& value)
  206. {
  207. const SettingsGroup sg(sSection);
  208. s_editorSettings()->setValue(sKey, QVariant::fromValue<int>(RGB(value.red(), value.green(), value.blue())));
  209. if (!bSettingsManagerMode)
  210. {
  211. if (GetIEditor()->GetSettingsManager())
  212. {
  213. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  214. }
  215. }
  216. }
  217. //////////////////////////////////////////////////////////////////////////
  218. void SEditorSettings::SaveValue(const char* sSection, const char* sKey, float value)
  219. {
  220. const SettingsGroup sg(sSection);
  221. s_editorSettings()->setValue(sKey, QString::number(value));
  222. if (!bSettingsManagerMode)
  223. {
  224. if (GetIEditor()->GetSettingsManager())
  225. {
  226. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  227. }
  228. }
  229. }
  230. //////////////////////////////////////////////////////////////////////////
  231. void SEditorSettings::SaveValue(const char* sSection, const char* sKey, const QString& value)
  232. {
  233. const SettingsGroup sg(sSection);
  234. s_editorSettings()->setValue(sKey, value);
  235. if (!bSettingsManagerMode)
  236. {
  237. if (GetIEditor()->GetSettingsManager())
  238. {
  239. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  240. }
  241. }
  242. }
  243. //////////////////////////////////////////////////////////////////////////
  244. void SEditorSettings::LoadValue(const char* sSection, const char* sKey, int& value)
  245. {
  246. if (bSettingsManagerMode)
  247. {
  248. if (GetIEditor()->GetSettingsManager())
  249. {
  250. GetIEditor()->GetSettingsManager()->LoadSetting(sSection, sKey, value);
  251. }
  252. SaveValue(sSection, sKey, value);
  253. }
  254. else
  255. {
  256. const SettingsGroup sg(sSection);
  257. value = s_editorSettings()->value(sKey, value).toInt();
  258. if (GetIEditor()->GetSettingsManager())
  259. {
  260. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  261. }
  262. }
  263. }
  264. //////////////////////////////////////////////////////////////////////////
  265. void SEditorSettings::LoadValue(const char* sSection, const char* sKey, QColor& value)
  266. {
  267. if (bSettingsManagerMode)
  268. {
  269. if (GetIEditor()->GetSettingsManager())
  270. {
  271. GetIEditor()->GetSettingsManager()->LoadSetting(sSection, sKey, value);
  272. }
  273. SaveValue(sSection, sKey, value);
  274. }
  275. else
  276. {
  277. const SettingsGroup sg(sSection);
  278. int defaultValue = RGB(value.red(), value.green(), value.blue());
  279. int v = s_editorSettings()->value(sKey, QVariant::fromValue<int>(defaultValue)).toInt();
  280. value = QColor(GetRValue(v), GetGValue(v), GetBValue(v));
  281. if (GetIEditor()->GetSettingsManager())
  282. {
  283. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  284. }
  285. }
  286. }
  287. //////////////////////////////////////////////////////////////////////////
  288. void SEditorSettings::LoadValue(const char* sSection, const char* sKey, float& value)
  289. {
  290. if (bSettingsManagerMode)
  291. {
  292. if (GetIEditor()->GetSettingsManager())
  293. {
  294. GetIEditor()->GetSettingsManager()->LoadSetting(sSection, sKey, value);
  295. }
  296. SaveValue(sSection, sKey, value);
  297. }
  298. else
  299. {
  300. const SettingsGroup sg(sSection);
  301. const QString defaultVal = s_editorSettings()->value(sKey, QString::number(value)).toString();
  302. value = defaultVal.toFloat();
  303. if (GetIEditor()->GetSettingsManager())
  304. {
  305. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  306. }
  307. }
  308. }
  309. //////////////////////////////////////////////////////////////////////////
  310. void SEditorSettings::LoadValue(const char* sSection, const char* sKey, bool& value)
  311. {
  312. if (bSettingsManagerMode)
  313. {
  314. if (GetIEditor()->GetSettingsManager())
  315. {
  316. GetIEditor()->GetSettingsManager()->LoadSetting(sSection, sKey, value);
  317. }
  318. SaveValue(sSection, sKey, value);
  319. }
  320. else
  321. {
  322. const SettingsGroup sg(sSection);
  323. value = s_editorSettings()->value(sKey, value).toInt();
  324. if (GetIEditor()->GetSettingsManager())
  325. {
  326. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  327. }
  328. }
  329. }
  330. //////////////////////////////////////////////////////////////////////////
  331. void SEditorSettings::LoadValue(const char* sSection, const char* sKey, QString& value)
  332. {
  333. if (bSettingsManagerMode)
  334. {
  335. if (GetIEditor()->GetSettingsManager())
  336. {
  337. GetIEditor()->GetSettingsManager()->LoadSetting(sSection, sKey, value);
  338. }
  339. SaveValue(sSection, sKey, value);
  340. }
  341. else
  342. {
  343. const SettingsGroup sg(sSection);
  344. value = s_editorSettings()->value(sKey, value).toString();
  345. if (GetIEditor()->GetSettingsManager())
  346. {
  347. GetIEditor()->GetSettingsManager()->SaveSetting(sSection, sKey, value);
  348. }
  349. }
  350. }
  351. //////////////////////////////////////////////////////////////////////////
  352. void SEditorSettings::Save(bool isEditorClosing)
  353. {
  354. QString strStringPlaceholder;
  355. // Save settings to registry.
  356. SaveValue("Settings", "UndoLevels", undoLevels);
  357. SaveValue("Settings", "ShowWelcomeScreenAtStartup", bShowDashboardAtStartup);
  358. SaveValue("Settings", "LoadLastLevelAtStartup", bAutoloadLastLevelAtStartup);
  359. SaveValue("Settings", "MuteAudio", bMuteAudio);
  360. SaveValue("Settings", "AutoBackup", autoBackupEnabled);
  361. SaveValue("Settings", "AutoBackupTime", autoBackupTime);
  362. SaveValue("Settings", "AutoBackupMaxCount", autoBackupMaxCount);
  363. SaveValue("Settings", "AutoRemindTime", autoRemindTime);
  364. SaveValue("Settings", "CameraMoveSpeed", cameraMoveSpeed);
  365. SaveValue("Settings", "CameraRotateSpeed", cameraRotateSpeed);
  366. SaveValue("Settings", "StylusMode", stylusMode);
  367. SaveValue("Settings", "RestoreViewportCamera", restoreViewportCamera);
  368. SaveValue("Settings", "WheelZoomSpeed", wheelZoomSpeed);
  369. SaveValue("Settings", "InvertYRotation", invertYRotation);
  370. SaveValue("Settings", "InvertPan", invertPan);
  371. SaveValue("Settings", "CameraFastMoveSpeed", cameraFastMoveSpeed);
  372. SaveValue("Settings", "PreviewGeometryWindow", bPreviewGeometryWindow);
  373. SaveValue("Settings\\Navigation", "NavigationContinuousUpdate", bNavigationContinuousUpdate);
  374. SaveValue("Settings\\Navigation", "NavigationShowAreas", bNavigationShowAreas);
  375. SaveValue("Settings\\Navigation", "NavigationDebugDisplay", bNavigationDebugDisplay);
  376. SaveValue("Settings\\Navigation", "NavigationDebugAgentType", navigationDebugAgentType);
  377. SaveValue("Settings\\Navigation", "VisualizeNavigationAccessibility", bVisualizeNavigationAccessibility);
  378. SaveValue("Settings", "BackupOnSave", bBackupOnSave);
  379. SaveValue("Settings", "SaveBackupMaxCount", backupOnSaveMaxCount);
  380. SaveValue("Settings", "TemporaryDirectory", strStandardTempDirectory);
  381. SaveValue("Settings", "ConsoleBackgroundColorThemeV2", (int)consoleBackgroundColorTheme);
  382. SaveValue("Settings", "ClearConsoleOnGameModeStart", clearConsoleOnGameModeStart);
  383. SaveValue("Settings", "ShowTimeInConsole", bShowTimeInConsole);
  384. SaveValue("Settings", "EnableSceneInspector", enableSceneInspector);
  385. //////////////////////////////////////////////////////////////////////////
  386. // Viewport settings.
  387. //////////////////////////////////////////////////////////////////////////
  388. SaveValue("Settings", "AlwaysShowRadiuses", viewports.bAlwaysShowRadiuses);
  389. SaveValue("Settings", "Sync2DViews", viewports.bSync2DViews);
  390. SaveValue("Settings", "AspectRatio", viewports.fDefaultAspectRatio);
  391. SaveValue("Settings", "HighlightSelectedGeometry", viewports.bHighlightSelectedGeometry);
  392. SaveValue("Settings", "HighlightSelectedVegetation", viewports.bHighlightSelectedVegetation);
  393. SaveValue("Settings", "HighlightMouseOverGeometry", viewports.bHighlightMouseOverGeometry);
  394. SaveValue("Settings", "ShowMeshStatsOnMouseOver", viewports.bShowMeshStatsOnMouseOver);
  395. SaveValue("Settings", "DrawEntityLabels", viewports.bDrawEntityLabels);
  396. SaveValue("Settings", "ShowTriggerBounds", viewports.bShowTriggerBounds);
  397. SaveValue("Settings", "ShowFrozenHelpers", viewports.nShowFrozenHelpers);
  398. SaveValue("Settings", "FillSelectedShapes", viewports.bFillSelectedShapes);
  399. SaveValue("Settings", "MapTextureResolution", viewports.nTopMapTextureResolution);
  400. SaveValue("Settings", "MapSwapXY", viewports.bTopMapSwapXY);
  401. SaveValue("Settings", "ShowGridGuide", viewports.bShowGridGuide);
  402. SaveValue("Settings", "HideMouseCursorOnCapture", viewports.bHideMouseCursorWhenCaptured);
  403. SaveValue("Settings", "DragSquareSize", viewports.nDragSquareSize);
  404. SaveValue("Settings", "EnableContextMenu", viewports.bEnableContextMenu);
  405. SaveValue("Settings", "ToolbarIconSizeV2", gui.nToolbarIconSize);
  406. SaveValue("Settings", "WarningIconsDrawDistance", viewports.fWarningIconsDrawDistance);
  407. SaveValue("Settings", "ShowScaleWarnings", viewports.bShowScaleWarnings);
  408. SaveValue("Settings", "ShowRotationWarnings", viewports.bShowRotationWarnings);
  409. SaveValue("Settings", "TextEditorScript", textEditorForScript);
  410. SaveValue("Settings", "TextEditorShaders", textEditorForShaders);
  411. SaveValue("Settings", "TextEditorBSpaces", textEditorForBspaces);
  412. SaveValue("Settings", "TextureEditor", textureEditor);
  413. SaveValue("Settings", "AnimationEditor", animEditor);
  414. SaveEnableSourceControlFlag(true);
  415. //////////////////////////////////////////////////////////////////////////
  416. // Snapping Settings.
  417. SaveValue("Settings\\Snap", "ConstructPlaneSize", snap.constructPlaneSize);
  418. SaveValue("Settings\\Snap", "ConstructPlaneDisplay", snap.constructPlaneDisplay);
  419. SaveValue("Settings\\Snap", "SnapMarkerDisplay", snap.markerDisplay);
  420. SaveValue("Settings\\Snap", "SnapMarkerColor", snap.markerColor);
  421. SaveValue("Settings\\Snap", "SnapMarkerSize", snap.markerSize);
  422. SaveValue("Settings\\Snap", "GridUserDefined", snap.bGridUserDefined);
  423. SaveValue("Settings\\Snap", "GridGetFromSelected", snap.bGridGetFromSelected);
  424. //////////////////////////////////////////////////////////////////////////
  425. //////////////////////////////////////////////////////////////////////////
  426. // Texture browser settings
  427. //////////////////////////////////////////////////////////////////////////
  428. SaveValue("Settings\\TextureBrowser", "Cell Size", sTextureBrowserSettings.nCellSize);
  429. //////////////////////////////////////////////////////////////////////////
  430. // Experimental features settings
  431. //////////////////////////////////////////////////////////////////////////
  432. SaveValue("Settings\\ExperimentalFeatures", "TotalIlluminationEnabled", sExperimentalFeaturesSettings.bTotalIlluminationEnabled);
  433. ///////////////////////////////////////////////////////////////////////////
  434. SaveValue("Settings\\SelectObjectDialog", "Columns", selectObjectDialog.columns);
  435. SaveValue("Settings\\SelectObjectDialog", "LastColumnSortDirection", selectObjectDialog.nLastColumnSortDirection);
  436. //////////////////////////////////////////////////////////////////////////
  437. // Asset browser settings
  438. //////////////////////////////////////////////////////////////////////////
  439. SaveValue("Settings\\AssetBrowser", "ThumbSize", sAssetBrowserSettings.nThumbSize);
  440. SaveValue("Settings\\AssetBrowser", "ShowLoadedInLevel", sAssetBrowserSettings.bShowLoadedInLevel);
  441. SaveValue("Settings\\AssetBrowser", "ShowUsedInLevel", sAssetBrowserSettings.bShowUsedInLevel);
  442. SaveValue("Settings\\AssetBrowser", "FilenameSearch", sAssetBrowserSettings.sFilenameSearch);
  443. SaveValue("Settings\\AssetBrowser", "PresetName", sAssetBrowserSettings.sPresetName);
  444. SaveValue("Settings\\AssetBrowser", "ShowDatabases", sAssetBrowserSettings.sVisibleDatabaseNames);
  445. SaveValue("Settings\\AssetBrowser", "ShowFavorites", sAssetBrowserSettings.bShowFavorites);
  446. SaveValue("Settings\\AssetBrowser", "HideLods", sAssetBrowserSettings.bHideLods);
  447. SaveValue("Settings\\AssetBrowser", "AutoSaveFilterPreset", sAssetBrowserSettings.bAutoSaveFilterPreset);
  448. SaveValue("Settings\\AssetBrowser", "AutoChangeViewportSelection", sAssetBrowserSettings.bAutoChangeViewportSelection);
  449. SaveValue("Settings\\AssetBrowser", "AutoFilterFromViewportSelection", sAssetBrowserSettings.bAutoFilterFromViewportSelection);
  450. SaveValue("Settings\\AssetBrowser", "VisibleColumnNames", sAssetBrowserSettings.sVisibleColumnNames);
  451. SaveValue("Settings\\AssetBrowser", "ColumnNames", sAssetBrowserSettings.sColumnNames);
  452. //////////////////////////////////////////////////////////////////////////
  453. // Deep Selection Settings
  454. //////////////////////////////////////////////////////////////////////////
  455. SaveValue("Settings", "DeepSelectionNearness", deepSelectionSettings.fRange);
  456. SaveValue("Settings", "StickDuplicate", deepSelectionSettings.bStickDuplicate);
  457. //////////////////////////////////////////////////////////////////////////
  458. // Object Highlight Colors
  459. //////////////////////////////////////////////////////////////////////////
  460. SaveValue("Settings\\ObjectColors", "groupHighlight", objectColorSettings.groupHighlight);
  461. SaveValue("Settings\\ObjectColors", "entityHighlight", objectColorSettings.entityHighlight);
  462. SaveValue("Settings\\ObjectColors", "BBoxAlpha", objectColorSettings.fBBoxAlpha);
  463. SaveValue("Settings\\ObjectColors", "GeometryHighlightColor", objectColorSettings.geometryHighlightColor);
  464. SaveValue("Settings\\ObjectColors", "SolidBrushGeometryHighlightColor", objectColorSettings.solidBrushGeometryColor);
  465. SaveValue("Settings\\ObjectColors", "GeometryAlpha", objectColorSettings.fGeomAlpha);
  466. SaveValue("Settings\\ObjectColors", "ChildGeometryAlpha", objectColorSettings.fChildGeomAlpha);
  467. //////////////////////////////////////////////////////////////////////////
  468. // Smart file open settings
  469. //////////////////////////////////////////////////////////////////////////
  470. SaveValue("Settings\\SmartFileOpen", "LastSearchTerm", smartOpenSettings.lastSearchTerm);
  471. SaveValue("Settings\\SmartFileOpen", "DlgRect.Left", smartOpenSettings.rect.left());
  472. SaveValue("Settings\\SmartFileOpen", "DlgRect.Top", smartOpenSettings.rect.top());
  473. SaveValue("Settings\\SmartFileOpen", "DlgRect.Right", smartOpenSettings.rect.right());
  474. SaveValue("Settings\\SmartFileOpen", "DlgRect.Bottom", smartOpenSettings.rect.bottom());
  475. s_editorSettings()->sync();
  476. // --- Settings Registry values
  477. AzToolsFramework::Prefab::PrefabLoaderInterface* prefabLoaderInterface =
  478. AZ::Interface<AzToolsFramework::Prefab::PrefabLoaderInterface>::Get();
  479. prefabLoaderInterface->SetSaveAllPrefabsPreference(levelSaveSettings.saveAllPrefabsPreference);
  480. if (!isEditorClosing)
  481. {
  482. SaveSettingsRegistryFile();
  483. }
  484. }
  485. //////////////////////////////////////////////////////////////////////////
  486. void SEditorSettings::Load()
  487. {
  488. AzToolsFramework::Prefab::PrefabLoaderInterface* prefabLoaderInterface =
  489. AZ::Interface<AzToolsFramework::Prefab::PrefabLoaderInterface>::Get();
  490. levelSaveSettings.saveAllPrefabsPreference = prefabLoaderInterface->GetSaveAllPrefabsPreference();
  491. const int settingsVersion = s_editorSettings()->value(QStringLiteral("Settings/EditorSettingsVersion"), 0).toInt();
  492. if (settingsVersion != EditorSettingsVersion)
  493. {
  494. s_editorSettings()->setValue(QStringLiteral("Settings/EditorSettingsVersion"), EditorSettingsVersion);
  495. Save();
  496. return;
  497. }
  498. QString strPlaceholderString;
  499. // Load settings from registry.
  500. LoadValue("Settings", "UndoLevels", undoLevels);
  501. LoadValue("Settings", "ShowWelcomeScreenAtStartup", bShowDashboardAtStartup);
  502. LoadValue("Settings", "LoadLastLevelAtStartup", bAutoloadLastLevelAtStartup);
  503. LoadValue("Settings", "MuteAudio", bMuteAudio);
  504. LoadValue("Settings", "AutoBackup", autoBackupEnabled);
  505. LoadValue("Settings", "AutoBackupTime", autoBackupTime);
  506. LoadValue("Settings", "AutoBackupMaxCount", autoBackupMaxCount);
  507. LoadValue("Settings", "AutoRemindTime", autoRemindTime);
  508. LoadValue("Settings", "CameraMoveSpeed", cameraMoveSpeed);
  509. LoadValue("Settings", "CameraRotateSpeed", cameraRotateSpeed);
  510. LoadValue("Settings", "StylusMode", stylusMode);
  511. LoadValue("Settings", "RestoreViewportCamera", restoreViewportCamera);
  512. LoadValue("Settings", "WheelZoomSpeed", wheelZoomSpeed);
  513. LoadValue("Settings", "InvertYRotation", invertYRotation);
  514. LoadValue("Settings", "InvertPan", invertPan);
  515. LoadValue("Settings", "CameraFastMoveSpeed", cameraFastMoveSpeed);
  516. LoadValue("Settings", "PreviewGeometryWindow", bPreviewGeometryWindow);
  517. LoadValue("Settings\\Navigation", "NavigationContinuousUpdate", bNavigationContinuousUpdate);
  518. LoadValue("Settings\\Navigation", "NavigationShowAreas", bNavigationShowAreas);
  519. LoadValue("Settings\\Navigation", "NavigationDebugDisplay", bNavigationDebugDisplay);
  520. LoadValue("Settings\\Navigation", "NavigationDebugAgentType", navigationDebugAgentType);
  521. LoadValue("Settings\\Navigation", "VisualizeNavigationAccessibility", bVisualizeNavigationAccessibility);
  522. LoadValue("Settings", "BackupOnSave", bBackupOnSave);
  523. LoadValue("Settings", "SaveBackupMaxCount", backupOnSaveMaxCount);
  524. LoadValue("Settings", "TemporaryDirectory", strStandardTempDirectory);
  525. int consoleBackgroundColorThemeInt = (int)consoleBackgroundColorTheme;
  526. LoadValue("Settings", "ConsoleBackgroundColorThemeV2", consoleBackgroundColorThemeInt);
  527. consoleBackgroundColorTheme = static_cast<AzToolsFramework::ConsoleColorTheme>(consoleBackgroundColorThemeInt);
  528. if (consoleBackgroundColorTheme != AzToolsFramework::ConsoleColorTheme::Dark && consoleBackgroundColorTheme != AzToolsFramework::ConsoleColorTheme::Light)
  529. {
  530. consoleBackgroundColorTheme = AzToolsFramework::ConsoleColorTheme::Dark;
  531. }
  532. LoadValue("Settings", "ClearConsoleOnGameModeStart", clearConsoleOnGameModeStart);
  533. LoadValue("Settings", "ShowTimeInConsole", bShowTimeInConsole);
  534. LoadValue("Settings", "EnableSceneInspector", enableSceneInspector);
  535. //////////////////////////////////////////////////////////////////////////
  536. // Viewport Settings.
  537. //////////////////////////////////////////////////////////////////////////
  538. LoadValue("Settings", "AlwaysShowRadiuses", viewports.bAlwaysShowRadiuses);
  539. LoadValue("Settings", "Sync2DViews", viewports.bSync2DViews);
  540. LoadValue("Settings", "AspectRatio", viewports.fDefaultAspectRatio);
  541. LoadValue("Settings", "HighlightSelectedGeometry", viewports.bHighlightSelectedGeometry);
  542. LoadValue("Settings", "HighlightSelectedVegetation", viewports.bHighlightSelectedVegetation);
  543. LoadValue("Settings", "HighlightMouseOverGeometry", viewports.bHighlightMouseOverGeometry);
  544. LoadValue("Settings", "ShowMeshStatsOnMouseOver", viewports.bShowMeshStatsOnMouseOver);
  545. LoadValue("Settings", "DrawEntityLabels", viewports.bDrawEntityLabels);
  546. LoadValue("Settings", "ShowTriggerBounds", viewports.bShowTriggerBounds);
  547. LoadValue("Settings", "ShowFrozenHelpers", viewports.nShowFrozenHelpers);
  548. LoadValue("Settings", "FillSelectedShapes", viewports.bFillSelectedShapes);
  549. LoadValue("Settings", "MapTextureResolution", viewports.nTopMapTextureResolution);
  550. LoadValue("Settings", "MapSwapXY", viewports.bTopMapSwapXY);
  551. LoadValue("Settings", "ShowGridGuide", viewports.bShowGridGuide);
  552. LoadValue("Settings", "HideMouseCursorOnCapture", viewports.bHideMouseCursorWhenCaptured);
  553. LoadValue("Settings", "DragSquareSize", viewports.nDragSquareSize);
  554. LoadValue("Settings", "EnableContextMenu", viewports.bEnableContextMenu);
  555. LoadValue("Settings", "ToolbarIconSizeV2", gui.nToolbarIconSize);
  556. LoadValue("Settings", "WarningIconsDrawDistance", viewports.fWarningIconsDrawDistance);
  557. LoadValue("Settings", "ShowScaleWarnings", viewports.bShowScaleWarnings);
  558. LoadValue("Settings", "ShowRotationWarnings", viewports.bShowRotationWarnings);
  559. LoadValue("Settings", "TextEditorScript", textEditorForScript);
  560. LoadValue("Settings", "TextEditorShaders", textEditorForShaders);
  561. LoadValue("Settings", "TextEditorBSpaces", textEditorForBspaces);
  562. LoadValue("Settings", "TextureEditor", textureEditor);
  563. LoadValue("Settings", "AnimationEditor", animEditor);
  564. LoadEnableSourceControlFlag();
  565. //////////////////////////////////////////////////////////////////////////
  566. // Snapping Settings.
  567. LoadValue("Settings\\Snap", "ConstructPlaneSize", snap.constructPlaneSize);
  568. LoadValue("Settings\\Snap", "ConstructPlaneDisplay", snap.constructPlaneDisplay);
  569. LoadValue("Settings\\Snap", "SnapMarkerDisplay", snap.markerDisplay);
  570. LoadValue("Settings\\Snap", "SnapMarkerColor", snap.markerColor);
  571. LoadValue("Settings\\Snap", "SnapMarkerSize", snap.markerSize);
  572. LoadValue("Settings\\Snap", "GridUserDefined", snap.bGridUserDefined);
  573. LoadValue("Settings\\Snap", "GridGetFromSelected", snap.bGridGetFromSelected);
  574. //////////////////////////////////////////////////////////////////////////
  575. //////////////////////////////////////////////////////////////////////////
  576. // Texture browser settings
  577. //////////////////////////////////////////////////////////////////////////
  578. LoadValue("Settings\\TextureBrowser", "Cell Size", sTextureBrowserSettings.nCellSize);
  579. //////////////////////////////////////////////////////////////////////////
  580. // Experimental features settings
  581. //////////////////////////////////////////////////////////////////////////
  582. LoadValue("Settings\\ExperimentalFeatures", "TotalIlluminationEnabled", sExperimentalFeaturesSettings.bTotalIlluminationEnabled);
  583. //////////////////////////////////////////////////////////////////////////
  584. LoadValue("Settings\\SelectObjectDialog", "Columns", selectObjectDialog.columns);
  585. LoadValue("Settings\\SelectObjectDialog", "LastColumnSortDirection", selectObjectDialog.nLastColumnSortDirection);
  586. //////////////////////////////////////////////////////////////////////////
  587. // Asset browser settings
  588. //////////////////////////////////////////////////////////////////////////
  589. LoadValue("Settings\\AssetBrowser", "ThumbSize", sAssetBrowserSettings.nThumbSize);
  590. LoadValue("Settings\\AssetBrowser", "ShowLoadedInLevel", sAssetBrowserSettings.bShowLoadedInLevel);
  591. LoadValue("Settings\\AssetBrowser", "ShowUsedInLevel", sAssetBrowserSettings.bShowUsedInLevel);
  592. LoadValue("Settings\\AssetBrowser", "FilenameSearch", sAssetBrowserSettings.sFilenameSearch);
  593. LoadValue("Settings\\AssetBrowser", "PresetName", sAssetBrowserSettings.sPresetName);
  594. LoadValue("Settings\\AssetBrowser", "ShowDatabases", sAssetBrowserSettings.sVisibleDatabaseNames);
  595. LoadValue("Settings\\AssetBrowser", "ShowFavorites", sAssetBrowserSettings.bShowFavorites);
  596. LoadValue("Settings\\AssetBrowser", "HideLods", sAssetBrowserSettings.bHideLods);
  597. LoadValue("Settings\\AssetBrowser", "AutoSaveFilterPreset", sAssetBrowserSettings.bAutoSaveFilterPreset);
  598. LoadValue("Settings\\AssetBrowser", "AutoChangeViewportSelection", sAssetBrowserSettings.bAutoChangeViewportSelection);
  599. LoadValue("Settings\\AssetBrowser", "AutoFilterFromViewportSelection", sAssetBrowserSettings.bAutoFilterFromViewportSelection);
  600. LoadValue("Settings\\AssetBrowser", "VisibleColumnNames", sAssetBrowserSettings.sVisibleColumnNames);
  601. LoadValue("Settings\\AssetBrowser", "ColumnNames", sAssetBrowserSettings.sColumnNames);
  602. if (sAssetBrowserSettings.sVisibleColumnNames == ""
  603. || sAssetBrowserSettings.sColumnNames == "")
  604. {
  605. sAssetBrowserSettings.sColumnNames =
  606. sAssetBrowserSettings.sVisibleColumnNames = kDefaultColumnsForAssetBrowserList;
  607. }
  608. //////////////////////////////////////////////////////////////////////////
  609. // Deep Selection Settings
  610. //////////////////////////////////////////////////////////////////////////
  611. LoadValue("Settings", "DeepSelectionNearness", deepSelectionSettings.fRange);
  612. LoadValue("Settings", "StickDuplicate", deepSelectionSettings.bStickDuplicate);
  613. //////////////////////////////////////////////////////////////////////////
  614. // Object Highlight Colors
  615. //////////////////////////////////////////////////////////////////////////
  616. LoadValue("Settings\\ObjectColors", "GroupHighlight", objectColorSettings.groupHighlight);
  617. LoadValue("Settings\\ObjectColors", "EntityHighlight", objectColorSettings.entityHighlight);
  618. LoadValue("Settings\\ObjectColors", "BBoxAlpha", objectColorSettings.fBBoxAlpha);
  619. LoadValue("Settings\\ObjectColors", "GeometryHighlightColor", objectColorSettings.geometryHighlightColor);
  620. LoadValue("Settings\\ObjectColors", "SolidBrushGeometryHighlightColor", objectColorSettings.solidBrushGeometryColor);
  621. LoadValue("Settings\\ObjectColors", "GeometryAlpha", objectColorSettings.fGeomAlpha);
  622. LoadValue("Settings\\ObjectColors", "ChildGeometryAlpha", objectColorSettings.fChildGeomAlpha);
  623. //////////////////////////////////////////////////////////////////////////
  624. // Smart file open settings
  625. //////////////////////////////////////////////////////////////////////////
  626. int soRcLeft = 0;
  627. int soRcRight = 0;
  628. int soRcTop = 0;
  629. int soRcBottom = 0;
  630. LoadValue("Settings\\SmartFileOpen", "LastSearchTerm", smartOpenSettings.lastSearchTerm);
  631. LoadValue("Settings\\SmartFileOpen", "DlgRect.Left", soRcLeft);
  632. LoadValue("Settings\\SmartFileOpen", "DlgRect.Top", soRcTop);
  633. LoadValue("Settings\\SmartFileOpen", "DlgRect.Right", soRcRight);
  634. LoadValue("Settings\\SmartFileOpen", "DlgRect.Bottom", soRcBottom);
  635. // check for bad values
  636. QRect screenRc = QGuiApplication::primaryScreen()->availableGeometry();
  637. if (screenRc.contains(QPoint(soRcLeft, soRcTop))
  638. && screenRc.contains(QPoint(soRcRight, soRcBottom)))
  639. {
  640. smartOpenSettings.rect.setLeft(soRcLeft);
  641. smartOpenSettings.rect.setTop(soRcTop);
  642. smartOpenSettings.rect.setRight(soRcRight);
  643. smartOpenSettings.rect.setBottom(soRcBottom);
  644. }
  645. //////////////////////////////////////////////////////////////////////////
  646. // Load paths.
  647. //////////////////////////////////////////////////////////////////////////
  648. for (int id = 0; id < EDITOR_PATH_LAST; id++)
  649. {
  650. if (id == EDITOR_PATH_UI_ICONS) // Skip UI icons path, not load it.
  651. {
  652. continue;
  653. }
  654. int i = 0;
  655. searchPaths[id].clear();
  656. while (true)
  657. {
  658. const QString key = QStringLiteral("Path_%1_%2").arg(id, 2, 10, QLatin1Char('.')).arg(i, 2, 10, QLatin1Char('.'));
  659. QString path;
  660. LoadValue("Paths", key.toUtf8().data(), path);
  661. if (path.isEmpty())
  662. {
  663. break;
  664. }
  665. searchPaths[id].push_back(path);
  666. }
  667. }
  668. }
  669. //////////////////////////////////////////////////////////////////////////
  670. AZ_CVAR(bool, ed_previewGameInFullscreen_once, false, nullptr, AZ::ConsoleFunctorFlags::IsInvisible, "Preview the game (Ctrl+G, \"Play Game\", etc.) in fullscreen once");
  671. AZ_CVAR(bool, ed_lowercasepaths, false, nullptr, AZ::ConsoleFunctorFlags::Null, "Convert CCryFile paths to lowercase on Open");
  672. AZ_CVAR(int64_t, ed_backgroundSystemTickCap, 33, nullptr, AZ::ConsoleFunctorFlags::Null,"Delay between frame updates (ms) when window is out of focus but not minimized AND background update is disabled.");
  673. void SEditorSettings::PostInitApply()
  674. {
  675. if (!gEnv || !gEnv->pConsole)
  676. {
  677. return;
  678. }
  679. // Create CVars.
  680. REGISTER_CVAR2("ed_highlightGeometry", &viewports.bHighlightMouseOverGeometry, viewports.bHighlightMouseOverGeometry, 0, "Highlight geometry when mouse over it");
  681. REGISTER_CVAR2("ed_showFrozenHelpers", &viewports.nShowFrozenHelpers, viewports.nShowFrozenHelpers, 0, "Show helpers of frozen objects");
  682. gEnv->pConsole->RegisterInt("fe_fbx_savetempfile", 0, 0, "When importing an FBX file into Facial Editor, this will save out a conversion FSQ to the Animations/temp folder for trouble shooting");
  683. REGISTER_CVAR2_CB("ed_toolbarIconSize", &gui.nToolbarIconSize, gui.nToolbarIconSize, VF_NULL, "Override size of the toolbar icons 0-default, 16,32,...", ToolbarIconSizeChanged);
  684. REGISTER_CVAR2("ed_backgroundUpdatePeriod", &backgroundUpdatePeriod, backgroundUpdatePeriod, 0, "Delay between frame updates (ms) when window is out of focus but not minimized. 0 = disable background update. -1 = update with no delay.");
  685. REGISTER_CVAR2("ed_showErrorDialogOnLoad", &showErrorDialogOnLoad, showErrorDialogOnLoad, 0, "Show error dialog on level load");
  686. REGISTER_CVAR2_CB("ed_keepEditorActive", &keepEditorActive, 0, VF_NULL, "Keep the editor active, even if no focus is set", KeepEditorActiveChanged);
  687. REGISTER_CVAR2("g_TemporaryLevelName", &g_TemporaryLevelName, "temp_level", VF_NULL, "Temporary level named used for experimental levels.");
  688. CCryEditApp::instance()->KeepEditorActive(keepEditorActive > 0);
  689. }
  690. //////////////////////////////////////////////////////////////////////////
  691. // needs to be called after crysystem has been loaded
  692. void SEditorSettings::LoadDefaultGamePaths()
  693. {
  694. //////////////////////////////////////////////////////////////////////////
  695. // Default paths.
  696. //////////////////////////////////////////////////////////////////////////
  697. if (searchPaths[EDITOR_PATH_OBJECTS].empty())
  698. {
  699. searchPaths[EDITOR_PATH_OBJECTS].push_back((Path::GetEditingGameDataFolder() + "/Objects").c_str());
  700. }
  701. if (searchPaths[EDITOR_PATH_TEXTURES].empty())
  702. {
  703. searchPaths[EDITOR_PATH_TEXTURES].push_back((Path::GetEditingGameDataFolder() + "/Textures").c_str());
  704. }
  705. if (searchPaths[EDITOR_PATH_SOUNDS].empty())
  706. {
  707. searchPaths[EDITOR_PATH_SOUNDS].push_back((Path::GetEditingGameDataFolder() + "/Sounds").c_str());
  708. }
  709. if (searchPaths[EDITOR_PATH_MATERIALS].empty())
  710. {
  711. searchPaths[EDITOR_PATH_MATERIALS].push_back((Path::GetEditingGameDataFolder() + "/Materials").c_str());
  712. }
  713. auto iconsPath = AZ::IO::Path(AZ::Utils::GetEnginePath()) / "Assets";
  714. iconsPath /= "Editor/UI/Icons";
  715. iconsPath.MakePreferred();
  716. searchPaths[EDITOR_PATH_UI_ICONS].push_back(iconsPath.c_str());
  717. }
  718. void EnableSourceControl(bool enable)
  719. {
  720. // Source control component
  721. using SCRequestBus = AzToolsFramework::SourceControlConnectionRequestBus;
  722. SCRequestBus::Broadcast(&SCRequestBus::Events::EnableSourceControl, enable);
  723. }
  724. void SEditorSettings::SaveEnableSourceControlFlag(bool triggerUpdate /*= false*/)
  725. {
  726. constexpr AZStd::string_view enableSourceControlKey = "/Amazon/Settings/EnableSourceControl";
  727. if (auto* registry = AZ::SettingsRegistry::Get())
  728. {
  729. // Track the original source control value
  730. bool originalSourceControlFlag;
  731. registry->Get(originalSourceControlFlag, enableSourceControlKey);
  732. // Update only on change
  733. if (originalSourceControlFlag != enableSourceControl)
  734. {
  735. registry->Set(enableSourceControlKey, enableSourceControl);
  736. }
  737. // If we are triggering any update for the source control flag, then set the control state
  738. if (triggerUpdate)
  739. {
  740. EnableSourceControl(enableSourceControl);
  741. }
  742. }
  743. }
  744. void SEditorSettings::LoadEnableSourceControlFlag()
  745. {
  746. constexpr AZStd::string_view enableSourceControlKey = "/Amazon/Settings/EnableSourceControl";
  747. if (const auto* registry = AZ::SettingsRegistry::Get())
  748. {
  749. bool potentialValue;
  750. if (registry->Get(potentialValue, enableSourceControlKey))
  751. {
  752. enableSourceControl = AZStd::move(potentialValue);
  753. }
  754. }
  755. EnableSourceControl(enableSourceControl);
  756. }
  757. AZStd::vector<AZStd::string> SEditorSettings::BuildSettingsList()
  758. {
  759. if (GetIEditor()->GetSettingsManager())
  760. {
  761. // Will need to save the settings at least once to populate the list
  762. // This will not affect the level nor prompt dialogs
  763. Save();
  764. return GetIEditor()->GetSettingsManager()->BuildSettingsList();
  765. }
  766. return AZStd::vector<AZStd::string>();
  767. }
  768. void SEditorSettings::ConvertPath(const AZStd::string_view sourcePath, AZStd::string& category, AZStd::string& attribute)
  769. {
  770. // This API accepts pipe-separated paths like "Category1|Category2|AttributeName"
  771. // But the SettingsManager requires 2 arguments, a Category like "Category1\Category2" and an attribute "AttributeName"
  772. // The reason for the difference is to have this API be consistent with the path syntax in Open 3D Engine Python APIs.
  773. // Find the last pipe separator ("|") in the path
  774. size_t lastSeparator = sourcePath.find_last_of("|");
  775. // Everything before the last separator is the category (since only the category is hierarchical)
  776. category = sourcePath.substr(0, lastSeparator);
  777. // Everything after the last separator is the attribute
  778. attribute = sourcePath.substr(lastSeparator + 1, sourcePath.length());
  779. // Replace pipes with backspaces in the category
  780. AZStd::replace(category.begin(), category.end(), '|', '\\');
  781. }
  782. AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome SEditorSettings::GetValue(const AZStd::string_view path)
  783. {
  784. if (path.find("|") == AZStd::string_view::npos)
  785. {
  786. return AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome{ AZStd::unexpect,
  787. AZStd::string("Invalid Path - could not find separator \"|\"") };
  788. }
  789. AZStd::string category, attribute;
  790. ConvertPath(path, category, attribute);
  791. QString result;
  792. LoadValue(category.c_str(), attribute.c_str(), result);
  793. AZStd::string actualResult = result.toUtf8().data();
  794. return { AZStd::any(actualResult) };
  795. }
  796. AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome SEditorSettings::SetValue(const AZStd::string_view path, const AZStd::any& value)
  797. {
  798. if (path.find("|") == AZStd::string_view::npos)
  799. {
  800. return AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome{ AZStd::unexpect,
  801. AZStd::string("Invalid Path - could not find separator \"|\"") };
  802. }
  803. AZStd::string category, attribute;
  804. ConvertPath(path, category, attribute);
  805. if (value.type() == azrtti_typeid<bool>())
  806. {
  807. bool val = AZStd::any_cast<bool>(value);
  808. SaveValue(category.c_str(), attribute.c_str(), val);
  809. }
  810. else if (value.type() == azrtti_typeid<double>())
  811. {
  812. SaveValue(category.c_str(), attribute.c_str(), aznumeric_cast<float>(AZStd::any_cast<double>(value)));
  813. }
  814. else if (value.type() == azrtti_typeid<AZ::s64>())
  815. {
  816. SaveValue(category.c_str(), attribute.c_str(), aznumeric_cast<int>(AZStd::any_cast<AZ::s64>(value)));
  817. }
  818. else if (value.type() == azrtti_typeid<AZStd::string>())
  819. {
  820. SaveValue(category.c_str(), attribute.c_str(), QString(AZStd::any_cast<AZStd::string>(value).c_str()));
  821. }
  822. else if (value.type() == azrtti_typeid<AZStd::string_view>())
  823. {
  824. SaveValue(category.c_str(), attribute.c_str(), QString(AZStd::any_cast<AZStd::string_view>(value).data()));
  825. }
  826. else
  827. {
  828. return AzToolsFramework::EditorSettingsAPIRequests::SettingOutcome{ AZStd::unexpect,
  829. AZStd::string("Invalid Value Type - supported types: string, bool, int, float") };
  830. }
  831. // Reload the changes in the Settings object used in the Editor
  832. Load();
  833. return { value };
  834. }
  835. void SEditorSettings::SaveSettingsRegistryFile()
  836. {
  837. auto registry = AZ::SettingsRegistry::Get();
  838. if (registry == nullptr)
  839. {
  840. AZ_Warning("SEditorSettings", false, "Unable to access global settings registry. Editor Preferences cannot be saved");
  841. return;
  842. }
  843. // Resolve path to editorpreferences.setreg
  844. AZ::IO::FixedMaxPath editorPreferencesFilePath = AZ::Utils::GetProjectPath();
  845. editorPreferencesFilePath /= "user/Registry/editorpreferences.setreg";
  846. AZ::SettingsRegistryMergeUtils::DumperSettings dumperSettings;
  847. dumperSettings.m_prettifyOutput = true;
  848. dumperSettings.m_includeFilter = [](AZStd::string_view path)
  849. {
  850. AZStd::string_view amazonSettingsPrefixPath("/Amazon/Settings");
  851. AZStd::string_view amazonPrefixPath("/Amazon/Preferences");
  852. AZStd::string_view o3dePrefixPath("/O3DE/Preferences");
  853. return amazonSettingsPrefixPath.starts_with(path.substr(0, amazonSettingsPrefixPath.size())) ||
  854. amazonPrefixPath.starts_with(path.substr(0, amazonPrefixPath.size())) ||
  855. o3dePrefixPath.starts_with(path.substr(0, o3dePrefixPath.size()));
  856. };
  857. AZStd::string stringBuffer;
  858. AZ::IO::ByteContainerStream stringStream(&stringBuffer);
  859. if (!AZ::SettingsRegistryMergeUtils::DumpSettingsRegistryToStream(*registry, "", stringStream, dumperSettings))
  860. {
  861. AZ_Warning("SEditorSettings", false, R"(Unable to save changes to the Editor Preferences registry file at "%s"\n)",
  862. editorPreferencesFilePath.c_str());
  863. return;
  864. }
  865. [[maybe_unused]] bool saved = false;
  866. constexpr auto configurationMode = AZ::IO::SystemFile::SF_OPEN_CREATE
  867. | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH
  868. | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY;
  869. if (AZ::IO::SystemFile outputFile; outputFile.Open(editorPreferencesFilePath.c_str(), configurationMode))
  870. {
  871. saved = outputFile.Write(stringBuffer.data(), stringBuffer.size()) == stringBuffer.size();
  872. }
  873. AZ_Warning("SEditorSettings", saved, R"(Unable to save Editor Preferences registry file to path "%s"\n)",
  874. editorPreferencesFilePath.c_str());
  875. }
  876. AzToolsFramework::ConsoleColorTheme SEditorSettings::GetConsoleColorTheme() const
  877. {
  878. return consoleBackgroundColorTheme;
  879. }
  880. AZ::u64 SEditorSettings::GetMaxNumberOfItemsShownInSearchView() const
  881. {
  882. return SandboxEditor::MaxItemsShownInAssetBrowserSearch();
  883. }