GraphViewSettings.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <AtomToolsFramework/Graph/GraphViewSettings.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. namespace AtomToolsFramework
  13. {
  14. void GraphViewSettings::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serialize->Class<GraphViewSettings>()
  19. ->Version(0)
  20. ->Field("snapDistance", &GraphViewSettings::m_snapDistance)
  21. ->Field("alignmentTime", &GraphViewSettings::m_alignmentTime)
  22. ->Field("maxZoom", &GraphViewSettings::m_maxZoom)
  23. ->Field("edgePanningPercentage", &GraphViewSettings::m_edgePanningPercentage)
  24. ->Field("edgePanningScrollSpeed", &GraphViewSettings::m_edgePanningScrollSpeed)
  25. ->Field("dragNodeCouplingEnabled", &GraphViewSettings::m_dragNodeCouplingEnabled)
  26. ->Field("dragCouplingTime", &GraphViewSettings::m_dragCouplingTime)
  27. ->Field("dragConnectionSpliceEnabled", &GraphViewSettings::m_dragConnectionSpliceEnabled)
  28. ->Field("dragConnectionSpliceTime", &GraphViewSettings::m_dragConnectionSpliceTime)
  29. ->Field("dropConnectionSpliceEnabled", &GraphViewSettings::m_dropConnectionSpliceEnabled)
  30. ->Field("dropConnectionSpliceTime", &GraphViewSettings::m_dropConnectionSpliceTime)
  31. ->Field("shakeToDespliceEnabled", &GraphViewSettings::m_shakeToDespliceEnabled)
  32. ->Field("shakesToDesplice", &GraphViewSettings::m_shakesToDesplice)
  33. ->Field("minimumShakePercent", &GraphViewSettings::m_minimumShakePercent)
  34. ->Field("shakeDeadZonePercent", &GraphViewSettings::m_shakeDeadZonePercent)
  35. ->Field("shakeStraightnessPercent", &GraphViewSettings::m_shakeStraightnessPercent)
  36. ->Field("maximumShakeDuration", &GraphViewSettings::m_maximumShakeDuration)
  37. ->Field("splicedNodeNudgingEnabled", &GraphViewSettings::m_splicedNodeNudgingEnabled)
  38. ->Field("nodeNudgingEnabled", &GraphViewSettings::m_nodeNudgingEnabled)
  39. ->Field("connectionCurveType", &GraphViewSettings::m_connectionCurveType)
  40. ->Field("dataConnectionCurveType", &GraphViewSettings::m_dataConnectionCurveType)
  41. ->Field("groupDoubleClickCollapseEnabled", &GraphViewSettings::m_groupDoubleClickCollapseEnabled)
  42. ->Field("bookmarkViewportControlEnabled", &GraphViewSettings::m_bookmarkViewportControlEnabled)
  43. ->Field("allowNodeDisabling", &GraphViewSettings::m_allowNodeDisabling)
  44. ->Field("allowDataReferenceSlots", &GraphViewSettings::m_allowDataReferenceSlots)
  45. ->Field("constructPresets", &GraphViewSettings::m_constructPresets)
  46. ;
  47. serialize->RegisterGenericType<GraphViewSettingsPtr>();
  48. if (auto editContext = serialize->GetEditContext())
  49. {
  50. editContext->Class<GraphViewSettingsPtr>("GraphViewSettingsPtr", "")
  51. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  52. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  53. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  54. ;
  55. editContext->Class<GraphViewSettings>("Graph View Config", "")
  56. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  57. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  58. ->ClassElement(AZ::Edit::ClassElements::Group, "Basic Interactions")
  59. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  60. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_snapDistance, "Snap Distance", "The distance at which connections will snap to a nearby slot.")
  61. ->Attribute(AZ::Edit::Attributes::Min, 10.0)
  62. ->Attribute(AZ::Edit::Attributes::Max, 100.0)
  63. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_maxZoom, "Max Zoom", "Controls the maximum magnification for zooming in")
  64. ->Attribute(AZ::Edit::Attributes::Min, 1.0)
  65. ->Attribute(AZ::Edit::Attributes::Max, 5.0)
  66. ->Attribute(AZ::Edit::Attributes::Step, 0.1)
  67. ->Attribute(AZ::Edit::Attributes::Suffix, "X")
  68. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_edgePanningPercentage, "Edge Panning Percentage", "The percentage of the visible area to start scrolling when the mouse cursor is dragged into")
  69. ->Attribute(AZ::Edit::Attributes::Min, 0.0)
  70. ->Attribute(AZ::Edit::Attributes::Max, 50.0)
  71. ->Attribute(AZ::Edit::Attributes::Step, 1.0)
  72. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_edgePanningScrollSpeed, "Edge Panning Scroll Speed", "How fast the scene will scroll when scrolling")
  73. ->Attribute(AZ::Edit::Attributes::Min, 1.0)
  74. ->Attribute(AZ::Edit::Attributes::Max, 1000.0)
  75. ->ClassElement(AZ::Edit::ClassElements::Group, "Coupling")
  76. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  77. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_dragNodeCouplingEnabled, "Drag Node Coupling Enabled", "Allow automatic connections to be created between nodes when dragging them on top of each other")
  78. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_dragCouplingTime, "Drag Coupling Time", "Amount of time nodes must be overlapping before automatic coupling is activated")
  79. ->Attribute(AZ::Edit::Attributes::Suffix, "ms")
  80. ->Attribute(AZ::Edit::Attributes::Min, 1)
  81. ->Attribute(AZ::Edit::Attributes::Max, 1000)
  82. ->ClassElement(AZ::Edit::ClassElements::Group, "Splicing")
  83. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  84. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_dragConnectionSpliceEnabled, "Drag Connection Splice Enabled", "Allow automatic splicing when dragging nodes on top of existing graph connections")
  85. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_dragConnectionSpliceTime, "Drag Connection Splice Time", "Amount of time a node must be overlapping an existing connection before automatic splicing occurs")
  86. ->Attribute(AZ::Edit::Attributes::Suffix, "ms")
  87. ->Attribute(AZ::Edit::Attributes::Min, 1)
  88. ->Attribute(AZ::Edit::Attributes::Max, 1000)
  89. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_dropConnectionSpliceEnabled, "Drop Connection Splice Enabled", "Allow automatic splicing when dropping nodes onto existing graph connections")
  90. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_dropConnectionSpliceTime, "Drop Connection Splice Time", "Amount of time a node must be overlapping an existing connection before automatic splicing occurs")
  91. ->Attribute(AZ::Edit::Attributes::Suffix, "ms")
  92. ->Attribute(AZ::Edit::Attributes::Min, 1)
  93. ->Attribute(AZ::Edit::Attributes::Max, 1000)
  94. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_splicedNodeNudgingEnabled, "Spliced Node Nudging Enabled", "Allow splicing actions to nudge other nodes out of the way")
  95. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_shakeToDespliceEnabled, "Shake To Desplice Enabled", "Allow shaking a node to break connections from the nodes")
  96. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_shakesToDesplice, "Shakes To Desplice", "The number of shades required to break connections between nodes")
  97. ->Attribute(AZ::Edit::Attributes::Min, 1)
  98. ->Attribute(AZ::Edit::Attributes::Max, 10)
  99. ->ClassElement(AZ::Edit::ClassElements::Group, "Nudging")
  100. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  101. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_nodeNudgingEnabled, "Node Nudging Enabled", "Controls if nodes will attempt to nudge each other out of the way during different operations")
  102. ->ClassElement(AZ::Edit::ClassElements::Group, "Shaking")
  103. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  104. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_minimumShakePercent, "Minimum Shake Percent", "Controls how long each motion must be in order to be registered as a shake")
  105. ->Attribute(AZ::Edit::Attributes::Min, 0.0)
  106. ->Attribute(AZ::Edit::Attributes::Max, 100.0)
  107. ->Attribute(AZ::Edit::Attributes::Step, 1.0)
  108. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_shakeDeadZonePercent, "Shake Dead Zone Percent", "Controls how far the cursor must move before a check is initiated")
  109. ->Attribute(AZ::Edit::Attributes::Min, 0.0)
  110. ->Attribute(AZ::Edit::Attributes::Max, 100.0)
  111. ->Attribute(AZ::Edit::Attributes::Step, 1.0)
  112. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_shakeStraightnessPercent, "Shake Straightness Percent", "Controls how aligned the individual motions must be in order to qualify as a shake")
  113. ->Attribute(AZ::Edit::Attributes::Min, 0.0)
  114. ->Attribute(AZ::Edit::Attributes::Max, 100.0)
  115. ->Attribute(AZ::Edit::Attributes::Step, 1.0)
  116. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_maximumShakeDuration, "Maximum Shake Duration", "Sets a cap on how long it consider a series of actions as a single shake gesture")
  117. ->Attribute(AZ::Edit::Attributes::Suffix, "ms")
  118. ->Attribute(AZ::Edit::Attributes::Min, 1)
  119. ->Attribute(AZ::Edit::Attributes::Max, 1000)
  120. ->ClassElement(AZ::Edit::ClassElements::Group, "Aligning")
  121. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  122. ->DataElement(AZ::Edit::UIHandlers::Slider, &GraphViewSettings::m_alignmentTime, "Alignment Time", "Controls the amount of time nodes will take to slide into place when performing alignment commands")
  123. ->Attribute(AZ::Edit::Attributes::Suffix, "ms")
  124. ->Attribute(AZ::Edit::Attributes::Min, 0)
  125. ->Attribute(AZ::Edit::Attributes::Max, 5)
  126. ->ClassElement(AZ::Edit::ClassElements::Group, "Connections")
  127. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  128. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GraphViewSettings::m_connectionCurveType, "Connection Curve Type", "Style used for drawing lines between non-data connections")
  129. ->EnumAttribute(GraphCanvas::Styling::ConnectionCurveType::Straight, "Straight")
  130. ->EnumAttribute(GraphCanvas::Styling::ConnectionCurveType::Curved, "Curved")
  131. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &GraphViewSettings::m_dataConnectionCurveType, "Data Connection Curve Type", "Style used for drawing lines between data connections")
  132. ->EnumAttribute(GraphCanvas::Styling::ConnectionCurveType::Straight, "Straight")
  133. ->EnumAttribute(GraphCanvas::Styling::ConnectionCurveType::Curved, "Curved")
  134. ->ClassElement(AZ::Edit::ClassElements::Group, "Misc")
  135. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  136. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_groupDoubleClickCollapseEnabled, "Group Double Click Collapse Enabled", "Toggle if groups can be expanded or collapsed by double clicking")
  137. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_bookmarkViewportControlEnabled, "Bookmark Viewport Control Enabled", "Will cause the bookmarks to force the viewport into the state determined by the bookmark type\nBookmark Anchors - The viewport that exists when the bookmark is created.\nNode Groups - The area the Node Group covers")
  138. ->DataElement(AZ::Edit::UIHandlers::Default, &GraphViewSettings::m_allowDataReferenceSlots, "Allow Data Reference Slots", "")
  139. ;
  140. }
  141. }
  142. }
  143. GraphViewSettings::~GraphViewSettings()
  144. {
  145. GraphCanvas::AssetEditorSettingsRequestBus::Handler::BusDisconnect();
  146. }
  147. void GraphViewSettings::Initialize(const AZ::Crc32& toolId, const AZStd::map<AZStd::string, AZ::Color>& defaultGroupPresets)
  148. {
  149. m_toolId = toolId;
  150. m_constructPresets.SetDefaultGroupPresets(defaultGroupPresets);
  151. m_constructPresets.SetEditorId(m_toolId);
  152. GraphCanvas::AssetEditorSettingsRequestBus::Handler::BusConnect(m_toolId);
  153. }
  154. double GraphViewSettings::GetSnapDistance() const
  155. {
  156. return m_snapDistance;
  157. }
  158. bool GraphViewSettings::IsGroupDoubleClickCollapseEnabled() const
  159. {
  160. return m_groupDoubleClickCollapseEnabled;
  161. }
  162. bool GraphViewSettings::IsBookmarkViewportControlEnabled() const
  163. {
  164. return m_bookmarkViewportControlEnabled;
  165. }
  166. bool GraphViewSettings::IsDragNodeCouplingEnabled() const
  167. {
  168. return m_dragNodeCouplingEnabled;
  169. }
  170. AZStd::chrono::milliseconds GraphViewSettings::GetDragCouplingTime() const
  171. {
  172. return AZStd::chrono::milliseconds(m_dragCouplingTime);
  173. }
  174. bool GraphViewSettings::IsDragConnectionSpliceEnabled() const
  175. {
  176. return m_dragConnectionSpliceEnabled;
  177. }
  178. AZStd::chrono::milliseconds GraphViewSettings::GetDragConnectionSpliceTime() const
  179. {
  180. return AZStd::chrono::milliseconds(m_dropConnectionSpliceTime);
  181. }
  182. bool GraphViewSettings::IsDropConnectionSpliceEnabled() const
  183. {
  184. return m_dropConnectionSpliceEnabled;
  185. }
  186. AZStd::chrono::milliseconds GraphViewSettings::GetDropConnectionSpliceTime() const
  187. {
  188. return AZStd::chrono::milliseconds(m_dropConnectionSpliceTime);
  189. }
  190. bool GraphViewSettings::IsSplicedNodeNudgingEnabled() const
  191. {
  192. return m_splicedNodeNudgingEnabled;
  193. }
  194. bool GraphViewSettings::IsNodeNudgingEnabled() const
  195. {
  196. return m_nodeNudgingEnabled;
  197. }
  198. bool GraphViewSettings::IsShakeToDespliceEnabled() const
  199. {
  200. return m_shakeToDespliceEnabled;
  201. }
  202. int GraphViewSettings::GetShakesToDesplice() const
  203. {
  204. return m_shakesToDesplice;
  205. }
  206. float GraphViewSettings::GetMinimumShakePercent() const
  207. {
  208. return m_minimumShakePercent;
  209. }
  210. float GraphViewSettings::GetShakeDeadZonePercent() const
  211. {
  212. return m_shakeDeadZonePercent;
  213. }
  214. float GraphViewSettings::GetShakeStraightnessPercent() const
  215. {
  216. return m_shakeStraightnessPercent;
  217. }
  218. AZStd::chrono::milliseconds GraphViewSettings::GetMaximumShakeDuration() const
  219. {
  220. return AZStd::chrono::milliseconds(m_maximumShakeDuration);
  221. }
  222. AZStd::chrono::milliseconds GraphViewSettings::GetAlignmentTime() const
  223. {
  224. return AZStd::chrono::milliseconds(m_alignmentTime);
  225. }
  226. float GraphViewSettings::GetMaxZoom() const
  227. {
  228. return m_maxZoom;
  229. }
  230. float GraphViewSettings::GetEdgePanningPercentage() const
  231. {
  232. return m_edgePanningPercentage;
  233. }
  234. float GraphViewSettings::GetEdgePanningScrollSpeed() const
  235. {
  236. return m_edgePanningScrollSpeed;
  237. }
  238. GraphCanvas::EditorConstructPresets* GraphViewSettings::GetConstructPresets() const
  239. {
  240. return &m_constructPresets;
  241. }
  242. const GraphCanvas::ConstructTypePresetBucket* GraphViewSettings::GetConstructTypePresetBucket(GraphCanvas::ConstructType constructType) const
  243. {
  244. return m_constructPresets.FindPresetBucket(constructType);
  245. }
  246. GraphCanvas::Styling::ConnectionCurveType GraphViewSettings::GetConnectionCurveType() const
  247. {
  248. return m_connectionCurveType;
  249. }
  250. GraphCanvas::Styling::ConnectionCurveType GraphViewSettings::GetDataConnectionCurveType() const
  251. {
  252. return m_dataConnectionCurveType;
  253. }
  254. bool GraphViewSettings::AllowNodeDisabling() const
  255. {
  256. return m_allowNodeDisabling;
  257. }
  258. bool GraphViewSettings::AllowDataReferenceSlots() const
  259. {
  260. return m_allowDataReferenceSlots;
  261. }
  262. } // namespace AtomToolsFramework