EditorPreferencesPageGeneral.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 "EditorPreferencesPageGeneral.h"
  10. // Qt
  11. #include <QMessageBox>
  12. // AzToolsFramework
  13. #include <AzToolsFramework/API/SettingsRegistryUtils.h>
  14. #include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
  15. #include <AzToolsFramework/Prefab/PrefabSettings.h>
  16. #include <AzQtComponents/Components/StyleManager.h>
  17. // Editor
  18. #include "MainWindow.h"
  19. #include "Core/QtEditorApplication.h"
  20. #define EDITORPREFS_EVENTNAME "EPGEvent"
  21. #define EDITORPREFS_EVENTVALTOGGLE "operation"
  22. #define UNDOSLICESAVE_VALON "UndoSliceSaveValueOn"
  23. #define UNDOSLICESAVE_VALOFF "UndoSliceSaveValueOff"
  24. void CEditorPreferencesPage_General::Reflect(AZ::SerializeContext& serialize)
  25. {
  26. serialize.Class<GeneralSettings>()
  27. ->Version(3)
  28. ->Field("PreviewPanel", &GeneralSettings::m_previewPanel)
  29. ->Field("EnableSourceControl", &GeneralSettings::m_enableSourceControl)
  30. ->Field("ClearConsole", &GeneralSettings::m_clearConsoleOnGameModeStart)
  31. ->Field("ConsoleBackgroundColorTheme", &GeneralSettings::m_consoleBackgroundColorTheme)
  32. ->Field("AutoloadLastLevel", &GeneralSettings::m_autoLoadLastLevel)
  33. ->Field("ShowTimeInConsole", &GeneralSettings::m_bShowTimeInConsole)
  34. ->Field("ToolbarIconSize", &GeneralSettings::m_toolbarIconSize)
  35. ->Field("StylusMode", &GeneralSettings::m_stylusMode)
  36. ->Field("ShowNews", &GeneralSettings::m_bShowNews)
  37. ->Field("EnableSceneInspector", &GeneralSettings::m_enableSceneInspector)
  38. ->Field("RestoreViewportCamera", &GeneralSettings::m_restoreViewportCamera);
  39. // note, despite this class name being LevelSaveSettings, it is used for general prefab settings
  40. // and the name is retained to avoid breaking things
  41. serialize.Class<LevelSaveSettings>()
  42. ->Version(1)
  43. ->Field("SaveAllPrefabsPreference", &LevelSaveSettings::m_saveAllPrefabsPreference)
  44. ->Field("DetachPrefabRemovesContainer", &LevelSaveSettings::m_bDetachPrefabRemovesContainer);
  45. serialize.Class<Messaging>()
  46. ->Version(2)
  47. ->Field("ShowDashboard", &Messaging::m_showDashboard);
  48. serialize.Class<Undo>()
  49. ->Version(2)
  50. ->Field("UndoLevels", &Undo::m_undoLevels);
  51. serialize.Class<CEditorPreferencesPage_General>()
  52. ->Version(1)
  53. ->Field("General Settings", &CEditorPreferencesPage_General::m_generalSettings)
  54. ->Field("Prefab Save Settings", &CEditorPreferencesPage_General::m_levelSaveSettings)
  55. ->Field("Messaging", &CEditorPreferencesPage_General::m_messaging)
  56. ->Field("Undo", &CEditorPreferencesPage_General::m_undo);
  57. AZ::EditContext* editContext = serialize.GetEditContext();
  58. if (editContext)
  59. {
  60. editContext->Class<GeneralSettings>("General Settings", "General Editor Preferences")
  61. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_previewPanel, "Show Geometry Preview Panel", "Show Geometry Preview Panel")
  62. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_enableSourceControl, "Enable Source Control", "Enable Source Control")
  63. ->DataElement(
  64. AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_clearConsoleOnGameModeStart, "Clear Console at game startup", "Clear Console when game mode starts")
  65. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_consoleBackgroundColorTheme, "Console Background", "Console Background")
  66. ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Light, "Light")
  67. ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Dark, "Dark")
  68. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_autoLoadLastLevel, "Auto-load last level at startup", "Auto-load last level at startup")
  69. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_bShowTimeInConsole, "Show Time In Console", "Show Time In Console")
  70. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_toolbarIconSize, "Toolbar Icon Size", "Toolbar Icon Size")
  71. ->EnumAttribute(AzQtComponents::ToolBar::ToolBarIconSize::IconNormal, "Default")
  72. ->EnumAttribute(AzQtComponents::ToolBar::ToolBarIconSize::IconLarge, "Large")
  73. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_stylusMode, "Stylus Mode", "Stylus Mode for tablets and other pointing devices")
  74. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_restoreViewportCamera, EditorPreferencesGeneralRestoreViewportCameraSettingName, "Keep the original editor viewport transform when exiting game mode.")
  75. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_enableSceneInspector, "Enable Scene Inspector (EXPERIMENTAL)", "Enable the option to inspect the internal data loaded from scene files like .fbx. This is an experimental feature. Restart the Scene Settings if the option is not visible under the Help menu.");
  76. editContext->Class<LevelSaveSettings>("Prefab Save Settings", "")
  77. ->DataElement(
  78. AZ::Edit::UIHandlers::ComboBox, &LevelSaveSettings::m_saveAllPrefabsPreference, "Save All Nested Prefabs",
  79. "This option controls whether nested prefabs should be saved when a prefab is saved.")
  80. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::AskEveryTime, "Ask every time")
  81. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::SaveAll, "Save all")
  82. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::SaveNone, "Save none")
  83. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &LevelSaveSettings::m_bDetachPrefabRemovesContainer, "Detach removes container entity",
  84. "When you choose the 'detach' option on a prefab container, should the container entity be removed also?");
  85. editContext->Class<Messaging>("Messaging", "")
  86. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Messaging::m_showDashboard, "Show Welcome to Open 3D Engine at startup", "Show Welcome to Open 3D Engine at startup");
  87. editContext->Class<Undo>("Undo", "")
  88. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &Undo::m_undoLevels, "Undo Levels", "This field specifies the number of undo levels")
  89. ->Attribute(AZ::Edit::Attributes::Min, 0)
  90. ->Attribute(AZ::Edit::Attributes::Max, 10000);
  91. editContext->Class<CEditorPreferencesPage_General>("General Editor Preferences", "Class for handling General Editor Preferences")
  92. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  93. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC_CE("PropertyVisibility_ShowChildrenOnly"))
  94. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_generalSettings, "General Settings", "General Editor Preferences")
  95. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_levelSaveSettings, "Prefab Settings", "General Prefab Settings")
  96. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_messaging, "Messaging", "Messaging")
  97. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_undo, "Undo", "Undo Preferences");
  98. }
  99. }
  100. CEditorPreferencesPage_General::CEditorPreferencesPage_General()
  101. {
  102. InitializeSettings();
  103. m_icon = QIcon(":/res/Global.svg");
  104. }
  105. const char* CEditorPreferencesPage_General::GetTitle()
  106. {
  107. return "General Settings";
  108. }
  109. QIcon& CEditorPreferencesPage_General::GetIcon()
  110. {
  111. return m_icon;
  112. }
  113. void CEditorPreferencesPage_General::OnApply()
  114. {
  115. using namespace AzToolsFramework::Prefab::Settings;
  116. //general settings
  117. gSettings.bPreviewGeometryWindow = m_generalSettings.m_previewPanel;
  118. gSettings.enableSourceControl = m_generalSettings.m_enableSourceControl;
  119. gSettings.clearConsoleOnGameModeStart = m_generalSettings.m_clearConsoleOnGameModeStart;
  120. gSettings.consoleBackgroundColorTheme = m_generalSettings.m_consoleBackgroundColorTheme;
  121. gSettings.bShowTimeInConsole = m_generalSettings.m_bShowTimeInConsole;
  122. gSettings.bShowDashboardAtStartup = m_messaging.m_showDashboard;
  123. gSettings.bAutoloadLastLevelAtStartup = m_generalSettings.m_autoLoadLastLevel;
  124. gSettings.stylusMode = m_generalSettings.m_stylusMode;
  125. gSettings.restoreViewportCamera = m_generalSettings.m_restoreViewportCamera;
  126. gSettings.enableSceneInspector = m_generalSettings.m_enableSceneInspector;
  127. AzToolsFramework::SetRegistry(AzToolsFramework::Prefab::Settings::DetachPrefabRemovesContainerName, m_levelSaveSettings.m_bDetachPrefabRemovesContainer);
  128. if (static_cast<int>(m_generalSettings.m_toolbarIconSize) != gSettings.gui.nToolbarIconSize)
  129. {
  130. gSettings.gui.nToolbarIconSize = static_cast<int>(m_generalSettings.m_toolbarIconSize);
  131. MainWindow::instance()->AdjustToolBarIconSize(m_generalSettings.m_toolbarIconSize);
  132. }
  133. //prefabs
  134. gSettings.levelSaveSettings.saveAllPrefabsPreference = m_levelSaveSettings.m_saveAllPrefabsPreference;
  135. //undo
  136. gSettings.undoLevels = m_undo.m_undoLevels;
  137. }
  138. void CEditorPreferencesPage_General::InitializeSettings()
  139. {
  140. using namespace AzToolsFramework::Prefab::Settings;
  141. //general settings
  142. m_generalSettings.m_previewPanel = gSettings.bPreviewGeometryWindow;
  143. m_generalSettings.m_enableSourceControl = gSettings.enableSourceControl;
  144. m_generalSettings.m_clearConsoleOnGameModeStart = gSettings.clearConsoleOnGameModeStart;
  145. m_generalSettings.m_consoleBackgroundColorTheme = gSettings.consoleBackgroundColorTheme;
  146. m_generalSettings.m_bShowTimeInConsole = gSettings.bShowTimeInConsole;
  147. m_generalSettings.m_autoLoadLastLevel = gSettings.bAutoloadLastLevelAtStartup;
  148. m_generalSettings.m_stylusMode = gSettings.stylusMode;
  149. m_generalSettings.m_restoreViewportCamera = gSettings.restoreViewportCamera;
  150. m_generalSettings.m_enableSceneInspector = gSettings.enableSceneInspector;
  151. m_generalSettings.m_toolbarIconSize = static_cast<AzQtComponents::ToolBar::ToolBarIconSize>(gSettings.gui.nToolbarIconSize);
  152. //prefabs
  153. m_levelSaveSettings.m_saveAllPrefabsPreference = gSettings.levelSaveSettings.saveAllPrefabsPreference;
  154. m_levelSaveSettings.m_bDetachPrefabRemovesContainer = AzToolsFramework::GetRegistry(DetachPrefabRemovesContainerName, DetachPrefabRemovesContainerDefault);
  155. //Messaging
  156. m_messaging.m_showDashboard = gSettings.bShowDashboardAtStartup;
  157. //undo
  158. m_undo.m_undoLevels = gSettings.undoLevels;
  159. }