EditorPreferencesPageGeneral.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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/UI/UICore/WidgetHelpers.h>
  14. #include <AzQtComponents/Components/StyleManager.h>
  15. // Editor
  16. #include "MainWindow.h"
  17. #include "Core/QtEditorApplication.h"
  18. #define EDITORPREFS_EVENTNAME "EPGEvent"
  19. #define EDITORPREFS_EVENTVALTOGGLE "operation"
  20. #define UNDOSLICESAVE_VALON "UndoSliceSaveValueOn"
  21. #define UNDOSLICESAVE_VALOFF "UndoSliceSaveValueOff"
  22. void CEditorPreferencesPage_General::Reflect(AZ::SerializeContext& serialize)
  23. {
  24. serialize.Class<GeneralSettings>()
  25. ->Version(3)
  26. ->Field("PreviewPanel", &GeneralSettings::m_previewPanel)
  27. ->Field("EnableSourceControl", &GeneralSettings::m_enableSourceControl)
  28. ->Field("ClearConsole", &GeneralSettings::m_clearConsoleOnGameModeStart)
  29. ->Field("ConsoleBackgroundColorTheme", &GeneralSettings::m_consoleBackgroundColorTheme)
  30. ->Field("AutoloadLastLevel", &GeneralSettings::m_autoLoadLastLevel)
  31. ->Field("ShowTimeInConsole", &GeneralSettings::m_bShowTimeInConsole)
  32. ->Field("ToolbarIconSize", &GeneralSettings::m_toolbarIconSize)
  33. ->Field("StylusMode", &GeneralSettings::m_stylusMode)
  34. ->Field("ShowNews", &GeneralSettings::m_bShowNews)
  35. ->Field("EnableSceneInspector", &GeneralSettings::m_enableSceneInspector)
  36. ->Field("RestoreViewportCamera", &GeneralSettings::m_restoreViewportCamera);
  37. serialize.Class<LevelSaveSettings>()
  38. ->Version(1)
  39. ->Field("SaveAllPrefabsPreference", &LevelSaveSettings::m_saveAllPrefabsPreference);
  40. serialize.Class<Messaging>()
  41. ->Version(2)
  42. ->Field("ShowDashboard", &Messaging::m_showDashboard)
  43. ->Field("ShowCircularDependencyError", &Messaging::m_showCircularDependencyError);
  44. serialize.Class<Undo>()
  45. ->Version(2)
  46. ->Field("UndoLevels", &Undo::m_undoLevels)
  47. ->Field("UndoSliceOverrideSaves", &Undo::m_undoSliceOverrideSaveValue);;
  48. serialize.Class<DeepSelection>()
  49. ->Version(2)
  50. ->Field("DeepSelectionRange", &DeepSelection::m_deepSelectionRange)
  51. ->Field("StickDuplicate", &DeepSelection::m_stickDuplicate);
  52. serialize.Class<SliceSettings>()
  53. ->Version(1)
  54. ->Field("DynamicByDefault", &SliceSettings::m_slicesDynamicByDefault);
  55. serialize.Class<CEditorPreferencesPage_General>()
  56. ->Version(1)
  57. ->Field("General Settings", &CEditorPreferencesPage_General::m_generalSettings)
  58. ->Field("Prefab Save Settings", &CEditorPreferencesPage_General::m_levelSaveSettings)
  59. ->Field("Messaging", &CEditorPreferencesPage_General::m_messaging)
  60. ->Field("Undo", &CEditorPreferencesPage_General::m_undo)
  61. ->Field("Deep Selection", &CEditorPreferencesPage_General::m_deepSelection)
  62. ->Field("Slice Settings", &CEditorPreferencesPage_General::m_sliceSettings);
  63. AZ::EditContext* editContext = serialize.GetEditContext();
  64. if (editContext)
  65. {
  66. editContext->Class<GeneralSettings>("General Settings", "General Editor Preferences")
  67. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_previewPanel, "Show Geometry Preview Panel", "Show Geometry Preview Panel")
  68. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_enableSourceControl, "Enable Source Control", "Enable Source Control")
  69. ->DataElement(
  70. AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_clearConsoleOnGameModeStart, "Clear Console at game startup", "Clear Console when game mode starts")
  71. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_consoleBackgroundColorTheme, "Console Background", "Console Background")
  72. ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Light, "Light")
  73. ->EnumAttribute(AzToolsFramework::ConsoleColorTheme::Dark, "Dark")
  74. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_autoLoadLastLevel, "Auto-load last level at startup", "Auto-load last level at startup")
  75. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_bShowTimeInConsole, "Show Time In Console", "Show Time In Console")
  76. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GeneralSettings::m_toolbarIconSize, "Toolbar Icon Size", "Toolbar Icon Size")
  77. ->EnumAttribute(AzQtComponents::ToolBar::ToolBarIconSize::IconNormal, "Default")
  78. ->EnumAttribute(AzQtComponents::ToolBar::ToolBarIconSize::IconLarge, "Large")
  79. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_stylusMode, "Stylus Mode", "Stylus Mode for tablets and other pointing devices")
  80. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &GeneralSettings::m_restoreViewportCamera, EditorPreferencesGeneralRestoreViewportCameraSettingName, "Keep the original editor viewport transform when exiting game mode.")
  81. ->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.");
  82. editContext->Class<LevelSaveSettings>("Prefab Save Settings", "")
  83. ->DataElement(
  84. AZ::Edit::UIHandlers::ComboBox, &LevelSaveSettings::m_saveAllPrefabsPreference, "Save All Nested Prefabs",
  85. "This option controls whether nested prefabs should be saved when a prefab is saved.")
  86. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::AskEveryTime, "Ask every time")
  87. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::SaveAll, "Save all")
  88. ->EnumAttribute(AzToolsFramework::Prefab::SaveAllPrefabsPreference::SaveNone, "Save none");
  89. editContext->Class<Messaging>("Messaging", "")
  90. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Messaging::m_showDashboard, "Show Welcome to Open 3D Engine at startup", "Show Welcome to Open 3D Engine at startup")
  91. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Messaging::m_showCircularDependencyError, "Show Error: Circular dependency", "Show an error message when adding a slice instance to the target slice would create a cyclic asset dependency. All other valid overrides will be saved even if this is turned off.");
  92. editContext->Class<Undo>("Undo", "")
  93. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &Undo::m_undoLevels, "Undo Levels", "This field specifies the number of undo levels")
  94. ->Attribute(AZ::Edit::Attributes::Min, 0)
  95. ->Attribute(AZ::Edit::Attributes::Max, 10000)
  96. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &Undo::m_undoSliceOverrideSaveValue, "Undo Slice Override Saves", "Allow slice saves to be undone");
  97. editContext->Class<DeepSelection>("Selection", "")
  98. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &DeepSelection::m_stickDuplicate, "Stick duplicate to cursor", "Stick duplicate to cursor")
  99. ->DataElement(AZ::Edit::UIHandlers::SpinBox, &DeepSelection::m_deepSelectionRange, "Deep selection range", "Deep Selection Range")
  100. ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
  101. ->Attribute(AZ::Edit::Attributes::Max, 1000.0f);
  102. editContext->Class<SliceSettings>("Slices", "")
  103. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &SliceSettings::m_slicesDynamicByDefault, "New Slices Dynamic By Default", "When creating slices, they will be set to dynamic by default");
  104. editContext->Class<CEditorPreferencesPage_General>("General Editor Preferences", "Class for handling General Editor Preferences")
  105. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  106. ->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC("PropertyVisibility_ShowChildrenOnly", 0xef428f20))
  107. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_generalSettings, "General Settings", "General Editor Preferences")
  108. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_levelSaveSettings, "Prefab Save Settings", "File>Save")
  109. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_messaging, "Messaging", "Messaging")
  110. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_undo, "Undo", "Undo Preferences")
  111. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_deepSelection, "Selection", "Selection")
  112. ->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_General::m_sliceSettings, "Slices", "Slice Settings");
  113. }
  114. }
  115. CEditorPreferencesPage_General::CEditorPreferencesPage_General()
  116. {
  117. InitializeSettings();
  118. m_icon = QIcon(":/res/Global.svg");
  119. }
  120. const char* CEditorPreferencesPage_General::GetTitle()
  121. {
  122. return "General Settings";
  123. }
  124. QIcon& CEditorPreferencesPage_General::GetIcon()
  125. {
  126. return m_icon;
  127. }
  128. void CEditorPreferencesPage_General::OnApply()
  129. {
  130. //general settings
  131. gSettings.bPreviewGeometryWindow = m_generalSettings.m_previewPanel;
  132. gSettings.enableSourceControl = m_generalSettings.m_enableSourceControl;
  133. gSettings.clearConsoleOnGameModeStart = m_generalSettings.m_clearConsoleOnGameModeStart;
  134. gSettings.consoleBackgroundColorTheme = m_generalSettings.m_consoleBackgroundColorTheme;
  135. gSettings.bShowTimeInConsole = m_generalSettings.m_bShowTimeInConsole;
  136. gSettings.bShowDashboardAtStartup = m_messaging.m_showDashboard;
  137. gSettings.m_showCircularDependencyError = m_messaging.m_showCircularDependencyError;
  138. gSettings.bAutoloadLastLevelAtStartup = m_generalSettings.m_autoLoadLastLevel;
  139. gSettings.stylusMode = m_generalSettings.m_stylusMode;
  140. gSettings.restoreViewportCamera = m_generalSettings.m_restoreViewportCamera;
  141. gSettings.enableSceneInspector = m_generalSettings.m_enableSceneInspector;
  142. if (static_cast<int>(m_generalSettings.m_toolbarIconSize) != gSettings.gui.nToolbarIconSize)
  143. {
  144. gSettings.gui.nToolbarIconSize = static_cast<int>(m_generalSettings.m_toolbarIconSize);
  145. MainWindow::instance()->AdjustToolBarIconSize(m_generalSettings.m_toolbarIconSize);
  146. }
  147. //prefabs
  148. gSettings.levelSaveSettings.saveAllPrefabsPreference = m_levelSaveSettings.m_saveAllPrefabsPreference;
  149. //undo
  150. gSettings.undoLevels = m_undo.m_undoLevels;
  151. gSettings.m_undoSliceOverrideSaveValue = m_undo.m_undoSliceOverrideSaveValue;
  152. //deep selection
  153. gSettings.deepSelectionSettings.fRange = m_deepSelection.m_deepSelectionRange;
  154. gSettings.deepSelectionSettings.bStickDuplicate = m_deepSelection.m_stickDuplicate;
  155. //slices
  156. gSettings.sliceSettings.dynamicByDefault = m_sliceSettings.m_slicesDynamicByDefault;
  157. }
  158. void CEditorPreferencesPage_General::InitializeSettings()
  159. {
  160. //general settings
  161. m_generalSettings.m_previewPanel = gSettings.bPreviewGeometryWindow;
  162. m_generalSettings.m_enableSourceControl = gSettings.enableSourceControl;
  163. m_generalSettings.m_clearConsoleOnGameModeStart = gSettings.clearConsoleOnGameModeStart;
  164. m_generalSettings.m_consoleBackgroundColorTheme = gSettings.consoleBackgroundColorTheme;
  165. m_generalSettings.m_bShowTimeInConsole = gSettings.bShowTimeInConsole;
  166. m_generalSettings.m_autoLoadLastLevel = gSettings.bAutoloadLastLevelAtStartup;
  167. m_generalSettings.m_stylusMode = gSettings.stylusMode;
  168. m_generalSettings.m_restoreViewportCamera = gSettings.restoreViewportCamera;
  169. m_generalSettings.m_enableSceneInspector = gSettings.enableSceneInspector;
  170. m_generalSettings.m_toolbarIconSize = static_cast<AzQtComponents::ToolBar::ToolBarIconSize>(gSettings.gui.nToolbarIconSize);
  171. //prefabs
  172. m_levelSaveSettings.m_saveAllPrefabsPreference = gSettings.levelSaveSettings.saveAllPrefabsPreference;
  173. //Messaging
  174. m_messaging.m_showDashboard = gSettings.bShowDashboardAtStartup;
  175. m_messaging.m_showCircularDependencyError = gSettings.m_showCircularDependencyError;
  176. //undo
  177. m_undo.m_undoLevels = gSettings.undoLevels;
  178. m_undo.m_undoSliceOverrideSaveValue = gSettings.m_undoSliceOverrideSaveValue;
  179. //deep selection
  180. m_deepSelection.m_deepSelectionRange = gSettings.deepSelectionSettings.fRange;
  181. m_deepSelection.m_stickDuplicate = gSettings.deepSelectionSettings.bStickDuplicate;
  182. //slices
  183. m_sliceSettings.m_slicesDynamicByDefault = gSettings.sliceSettings.dynamicByDefault;
  184. }