Settings.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. #pragma once
  9. #include <AzCore/Asset/AssetCommon.h>
  10. #include <AzCore/Math/Uuid.h>
  11. #include <AzCore/UserSettings/UserSettings.h>
  12. #include <ScriptCanvas/Core/Core.h>
  13. // qdatastream.h(173): warning C4251: 'QDataStream::d': class 'QScopedPointer<QDataStreamPrivate,QScopedPointerDeleter<T>>' needs to have dll-interface to be used by clients of class 'QDataStream'
  14. // qwidget.h(858): warning C4800: 'uint': forcing value to bool 'true' or 'false' (performance warning)
  15. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
  16. #include <QByteArray>
  17. #include <QMainWindow>
  18. AZ_POP_DISABLE_WARNING
  19. #include <GraphCanvas/Editor/AssetEditorBus.h>
  20. #include <GraphCanvas/Types/ConstructPresets.h>
  21. namespace AZ
  22. {
  23. class ReflectContext;
  24. }
  25. namespace ScriptCanvasEditor
  26. {
  27. namespace EditorSettings
  28. {
  29. class ScriptCanvasConstructPresets
  30. : public GraphCanvas::EditorConstructPresets
  31. {
  32. public:
  33. AZ_RTTI(ScriptCanvasConstructPresets, "{191DCCB3-670F-4243-813E-DF23BE838F45}", GraphCanvas::EditorConstructPresets);
  34. AZ_CLASS_ALLOCATOR(ScriptCanvasConstructPresets, AZ::SystemAllocator);
  35. ScriptCanvasConstructPresets();
  36. ~ScriptCanvasConstructPresets() override = default;
  37. void InitializeConstructType(GraphCanvas::ConstructType constructType) override;
  38. };
  39. class EditorWorkspace
  40. : public AZ::UserSettings
  41. {
  42. public:
  43. struct WorkspaceAssetSaveData
  44. {
  45. AZ_RTTI(WorkspaceAssetSaveData, "{927368CA-096F-4CF1-B2E0-1B9E4A93EA57}");
  46. WorkspaceAssetSaveData();
  47. WorkspaceAssetSaveData(SourceHandle assetId);
  48. virtual ~WorkspaceAssetSaveData() = default;
  49. SourceHandle m_assetId;
  50. };
  51. AZ_RTTI(EditorWorkspace, "{67DACC4D-B92C-4B5A-8884-6AF7C7B74246}", AZ::UserSettings);
  52. AZ_CLASS_ALLOCATOR(EditorWorkspace, AZ::SystemAllocator);
  53. static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& rootDataElementNode);
  54. static void Reflect(AZ::ReflectContext* context);
  55. EditorWorkspace() = default;
  56. void ConfigureActiveAssets(SourceHandle focusedAsset, const AZStd::vector< WorkspaceAssetSaveData >& activeAssetIds);
  57. SourceHandle GetFocusedAssetId() const;
  58. AZStd::vector< WorkspaceAssetSaveData > GetActiveAssetData() const;
  59. void Init(const QByteArray& windowState, const QByteArray& windowGeometry);
  60. void Restore(QMainWindow* window);
  61. void Clear()
  62. {
  63. m_focusedAssetId.Clear();
  64. m_activeAssetData.clear();
  65. }
  66. private:
  67. const AZStd::vector<AZ::u8>& GetWindowState();
  68. AZStd::vector<AZ::u8> m_storedWindowState;
  69. AZStd::vector<AZ::u8> m_windowGeometry;
  70. AZStd::vector<AZ::u8> m_windowState;
  71. SourceHandle m_focusedAssetId;
  72. AZStd::vector< WorkspaceAssetSaveData > m_activeAssetData;
  73. };
  74. // Structure used for Toggleable Configurations
  75. // i.e. something that has a configuration time and the ability to turn it on/off
  76. class ToggleableConfiguration
  77. {
  78. public:
  79. AZ_RTTI(ToggleableConfiguration, "{24E8CAE7-0B5E-4B5E-94CC-08B9148B4AB5}");
  80. AZ_CLASS_ALLOCATOR(ToggleableConfiguration, AZ::SystemAllocator);
  81. ToggleableConfiguration()
  82. : ToggleableConfiguration(false, 1000)
  83. {
  84. }
  85. ToggleableConfiguration(bool enabled, int timeMS)
  86. : m_enabled(enabled)
  87. , m_timeMS(timeMS)
  88. {
  89. }
  90. virtual ~ToggleableConfiguration() = default;
  91. bool m_enabled;
  92. int m_timeMS;
  93. };
  94. class AutoSaveSettings
  95. {
  96. public:
  97. AZ_RTTI(AutoSaveSettings, "{FAB6437B-8BC2-46E1-B364-986DEBD8376A}");
  98. AZ_CLASS_ALLOCATOR(AutoSaveSettings, AZ::SystemAllocator);
  99. AutoSaveSettings(bool enabled = false, int timeSeconds = 10)
  100. : m_enabled(enabled)
  101. , m_timeSeconds(timeSeconds)
  102. {
  103. }
  104. virtual ~AutoSaveSettings() = default;
  105. bool m_enabled;
  106. int m_timeSeconds;
  107. };
  108. class ShakeToDespliceSettings
  109. {
  110. friend class ScriptCanvasEditorSettings;
  111. public:
  112. AZ_RTTI(ShakeToDespliceSettings, "{6401FA20-7A17-407E-81E3-D1389C9C70B7}");
  113. AZ_CLASS_ALLOCATOR(ShakeToDespliceSettings, AZ::SystemAllocator);
  114. ShakeToDespliceSettings()
  115. : m_enabled(true)
  116. , m_shakeCount(3)
  117. , m_maximumShakeTimeMS(1000)
  118. , m_minimumShakeLengthPercent(3)
  119. , m_deadZonePercent(1)
  120. , m_straightnessPercent(65)
  121. {
  122. }
  123. virtual ~ShakeToDespliceSettings() = default;
  124. float GetStraightnessPercent() const
  125. {
  126. return m_straightnessPercent * 0.01f;
  127. }
  128. float GetMinimumShakeLengthPercent() const
  129. {
  130. return m_minimumShakeLengthPercent * 0.01f;
  131. }
  132. float GetDeadZonePercent() const
  133. {
  134. return m_deadZonePercent * 0.01f;
  135. }
  136. bool m_enabled;
  137. int m_shakeCount;
  138. int m_maximumShakeTimeMS;
  139. private:
  140. float m_minimumShakeLengthPercent;
  141. float m_deadZonePercent;
  142. float m_straightnessPercent;
  143. };
  144. class ZoomSettings
  145. {
  146. friend class ScriptCanvasEditorSettings;
  147. public:
  148. AZ_RTTI(ZoomSettings, "{276D3E97-B38C-4A3D-A484-E5A5D0A2D942}");
  149. AZ_CLASS_ALLOCATOR(ZoomSettings, AZ::SystemAllocator);
  150. ZoomSettings()
  151. : m_zoomInSetting(2.0f)
  152. {
  153. }
  154. virtual ~ZoomSettings() = default;
  155. float GetMaxZoom() const
  156. {
  157. return 1.0f * m_zoomInSetting;
  158. }
  159. private:
  160. float m_zoomInSetting;
  161. };
  162. class EdgePanningSettings
  163. {
  164. friend class ScriptCanvasEditorSettings;
  165. public:
  166. AZ_RTTI(EdgePanningSettings, "{38399A9B-8D4B-4198-AAA2-D1E8761F5563}");
  167. AZ_CLASS_ALLOCATOR(EdgePanningSettings, AZ::SystemAllocator);
  168. EdgePanningSettings()
  169. : m_edgeScrollPercent(5.0f)
  170. , m_edgeScrollSpeed(75.0f)
  171. {
  172. }
  173. virtual ~EdgePanningSettings() = default;
  174. float GetEdgeScrollPercent() const
  175. {
  176. return m_edgeScrollPercent * 0.01f;
  177. }
  178. float GetEdgeScrollSpeed() const
  179. {
  180. return m_edgeScrollSpeed;
  181. }
  182. private:
  183. float m_edgeScrollPercent;
  184. float m_edgeScrollSpeed;
  185. };
  186. //! Container object for any experimental features, or in-development features
  187. //! in Script Canvas that we want to make available for users to try, but that may
  188. //! not be complete, working as expected, or covering every use case.
  189. class ExperimentalSettings
  190. {
  191. friend class ScriptCanvasEditorSettings;
  192. public:
  193. AZ_RTTI(ExperimentalSettings, "{13B275AF-A2D4-4D18-8236-CC0D19043C85}");
  194. AZ_CLASS_ALLOCATOR(ExperimentalSettings, AZ::SystemAllocator);
  195. ExperimentalSettings()
  196. : m_showNetworkProperties(false)
  197. {
  198. }
  199. virtual ~ExperimentalSettings() = default;
  200. float GetShowNetworkProperties() const
  201. {
  202. return m_showNetworkProperties;
  203. }
  204. private:
  205. //! Currently variable network properties are experimental and disabled by default
  206. bool m_showNetworkProperties;
  207. };
  208. class StylingSettings
  209. {
  210. public:
  211. AZ_RTTI(StylingSettings, "{2814140B-0679-492F-BE37-F89DA1414E67}");
  212. AZ_CLASS_ALLOCATOR(StylingSettings, AZ::SystemAllocator);
  213. static void Reflect(AZ::ReflectContext* reflectContext);
  214. StylingSettings() = default;
  215. virtual ~StylingSettings() = default;
  216. GraphCanvas::Styling::ConnectionCurveType GetConnectionCurveType() const
  217. {
  218. return m_connectionCurveType;
  219. }
  220. GraphCanvas::Styling::ConnectionCurveType GetDataConnectionCurveType() const
  221. {
  222. return m_dataConnectionCurveType;
  223. }
  224. private:
  225. GraphCanvas::Styling::ConnectionCurveType m_connectionCurveType = GraphCanvas::Styling::ConnectionCurveType::Straight;
  226. GraphCanvas::Styling::ConnectionCurveType m_dataConnectionCurveType = GraphCanvas::Styling::ConnectionCurveType::Straight;
  227. };
  228. class ScriptCanvasEditorSettings
  229. : public AZ::UserSettings
  230. , public GraphCanvas::AssetEditorPresetNotificationBus::Handler
  231. {
  232. public:
  233. AZ_RTTI(ScriptCanvasEditorSettings, "{D8D5453C-BFB8-4C71-BBAF-0F10FDD69B3F}", AZ::UserSettings);
  234. AZ_CLASS_ALLOCATOR(ScriptCanvasEditorSettings, AZ::SystemAllocator);
  235. static void Reflect(AZ::ReflectContext* context);
  236. static bool VersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement);
  237. ScriptCanvasEditorSettings();
  238. // GraphCanvas::AssetEditorPResetNotifications
  239. void OnConstructPresetsChanged(GraphCanvas::ConstructType constructType) override;
  240. ////
  241. double m_snapDistance;
  242. bool m_enableGroupDoubleClickCollapse;
  243. bool m_allowBookmarkViewpointControl;
  244. bool m_allowNodeNudging;
  245. bool m_rememberOpenCanvases;
  246. bool m_showUpgradeDialog;
  247. ToggleableConfiguration m_dragNodeCouplingConfig;
  248. ToggleableConfiguration m_dragNodeSplicingConfig;
  249. ToggleableConfiguration m_dropNodeSplicingConfig;
  250. AutoSaveSettings m_autoSaveConfig;
  251. ShakeToDespliceSettings m_shakeDespliceConfig;
  252. ZoomSettings m_zoomSettings;
  253. EdgePanningSettings m_edgePanningSettings;
  254. ExperimentalSettings m_experimentalSettings;
  255. AZStd::unordered_set<AZ::Uuid> m_pinnedDataTypes;
  256. ScriptCanvasConstructPresets m_constructPresets;
  257. int m_variablePanelSorting;
  258. bool m_showValidationWarnings;
  259. bool m_showValidationErrors;
  260. bool m_saveRawTranslationOuputToFile;
  261. bool m_printAbstractCodeModel;
  262. AZ::u32 m_alignmentTimeMS;
  263. StylingSettings m_stylingSettings;
  264. AZ::u32 m_sceneContextMenuNodePaletteWidth = 300;
  265. };
  266. }
  267. }