GraphViewConstructPresets.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/GraphViewConstructPresets.h>
  9. #include <GraphCanvas/Components/Nodes/Comment/CommentBus.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. namespace AtomToolsFramework
  12. {
  13. void GraphViewConstructPresets::Reflect(AZ::ReflectContext* context)
  14. {
  15. if (auto serialize = azrtti_cast<AZ::SerializeContext*>(context))
  16. {
  17. serialize->Class<GraphViewConstructPresets, GraphCanvas::EditorConstructPresets>()
  18. ->Version(0);
  19. if (auto editContext = serialize->GetEditContext())
  20. {
  21. editContext->Class<GraphViewConstructPresets>("GraphViewConstructPresets", "")
  22. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  23. ->Attribute(AZ::Edit::Attributes::AutoExpand, true);
  24. }
  25. }
  26. }
  27. void GraphViewConstructPresets::InitializeConstructType(GraphCanvas::ConstructType constructType)
  28. {
  29. if (constructType == GraphCanvas::ConstructType::NodeGroup)
  30. {
  31. auto presetBucket = static_cast<GraphCanvas::NodeGroupPresetBucket*>(ModPresetBucket(GraphCanvas::ConstructType::NodeGroup));
  32. if (presetBucket)
  33. {
  34. presetBucket->ClearPresets();
  35. // Create all of the initial node group presets using the default names and colors
  36. for (const auto& defaultGroupPresetPair : m_defaultGroupPresets)
  37. {
  38. if (auto preset = presetBucket->CreateNewPreset(defaultGroupPresetPair.first))
  39. {
  40. const auto& presetSaveData = preset->GetPresetData();
  41. if (auto saveData = presetSaveData.FindSaveDataAs<GraphCanvas::CommentNodeTextSaveData>())
  42. {
  43. saveData->m_backgroundColor = defaultGroupPresetPair.second;
  44. }
  45. }
  46. }
  47. }
  48. }
  49. else if (constructType == GraphCanvas::ConstructType::CommentNode)
  50. {
  51. auto presetBucket = static_cast<GraphCanvas::CommentPresetBucket*>(ModPresetBucket(GraphCanvas::ConstructType::CommentNode));
  52. if (presetBucket)
  53. {
  54. presetBucket->ClearPresets();
  55. }
  56. }
  57. }
  58. void GraphViewConstructPresets::SetDefaultGroupPresets(const AZStd::map<AZStd::string, AZ::Color>& defaultGroupPresets)
  59. {
  60. m_defaultGroupPresets = defaultGroupPresets;
  61. }
  62. } // namespace AtomToolsFramework