SettingsManager.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #ifndef CRYINCLUDE_EDITOR_SETTINGSMANAGER_H
  9. #define CRYINCLUDE_EDITOR_SETTINGSMANAGER_H
  10. #pragma once
  11. #include <QString>
  12. class QByteArray;
  13. #define EDITOR_LAYOUT_FILE_PATH "@user@/Editor/EditorLayout.xml"
  14. #define EDITOR_SETTINGS_FILE_PATH "@user@/Editor/EditorSettings.xml"
  15. #define EDITOR_LAYOUT_ROOT_NODE "EditorLayout"
  16. #define EDITOR_SETTINGS_ROOT_NODE "EditorSettings"
  17. #define EDITOR_SETTINGS_CONTENT_NODE "EditorSettingsContent"
  18. #define NEED_SETTINGS_VALID_LOOKUP_PATH "Settings"
  19. #define EDITOR_LAYOUT_NODE "DockingPaneLayouts"
  20. #define EDITOR_SETTINGS_ATTRIB_NAME "value"
  21. #define CVARS_NODE "CVars"
  22. #define CVAR_NODE "CVar"
  23. #define EDITOR_EVENT_LOG_FILE_PATH "@user@/Editor/EditorEventLog.xml"
  24. #define EDITOR_EVENT_LOG_ROOT_NODE "EventRecorder"
  25. #define EVENT_LOG_EVENT_NAME "eventName"
  26. #define EDITOR_EVENT_LOG_ATTRIB_NAME "value"
  27. #define EVENT_LOG_START "start"
  28. #define EVENT_LOG_END "end"
  29. #define LOG_DATETIME_FORMAT "MM/dd/yyyy HH:mm:ss"
  30. #define EVENT_LOG_CALLER_VERSION "callerVersion"
  31. enum EditorSettingsManagerType
  32. {
  33. eSettingsManagerMemoryStorage = 0,
  34. eSettingsManagerLast
  35. };
  36. enum EditorSettingsExportType
  37. {
  38. eSettingsManagerExportSettings = 0,
  39. eSettingsManagerExportLayout
  40. };
  41. typedef std::map<QString, QString> TToolNamesMap;
  42. struct SEventLog;
  43. struct SEventLog
  44. {
  45. SEventLog(QString eventName, QString eventState, QString callerVersion = "")
  46. {
  47. m_eventName = eventName;
  48. m_eventState = eventState;
  49. m_callerVersion = callerVersion;
  50. }
  51. QString m_eventName;
  52. QString m_callerVersion;
  53. QString m_eventState;
  54. };
  55. class CSettingsManager
  56. {
  57. public:
  58. // eMemoryStorage=0
  59. CSettingsManager(EditorSettingsManagerType managerType);
  60. ~CSettingsManager();
  61. // Sandbox Editor events
  62. void RegisterEvent(const SEventLog& event);
  63. void UnregisterEvent(const SEventLog& event);
  64. bool IsEventSafe(const SEventLog& event);
  65. QString GenerateContentHash(XmlNodeRef& node, QString sourceName);
  66. XmlNodeRef LoadLogEventSetting(const QString& path, const QString& attr, QString& val, XmlNodeRef& root);
  67. void SaveLogEventSetting(const QString& path, const QString& attr, const QString& val);
  68. bool CreateDefaultLayoutSettingsFile();
  69. void SaveLayoutSettings(const QByteArray& layout, const QString& toolName);
  70. AZStd::vector<AZStd::string> BuildSettingsList();
  71. void BuildSettingsList_Helper(const XmlNodeRef& nodeList, const AZStd::string_view& previousPath, AZStd::vector<AZStd::string>& result);
  72. void LoadSetting(const QString& path, const QString& attr, bool& val);
  73. void LoadSetting(const QString& path, const QString& attr, int& iVal);
  74. void LoadSetting(const QString& path, const QString& attr, float& fVal);
  75. void LoadSetting(const QString& path, const QString& attr, QColor& color);
  76. XmlNodeRef LoadSetting(const QString& path, const QString& attr, QString& val);
  77. void SaveSetting(const QString& path, const QString& attr, bool val);
  78. void SaveSetting(const QString& path, const QString& attr, float fVal);
  79. void SaveSetting(const QString& path, const QString& attr, int iVal);
  80. void SaveSetting(const QString& path, const QString& attr, QColor color);
  81. void SaveSetting(const QString& path, const QString& attr, const QString& val);
  82. void AddSettingsNode(XmlNodeRef newNode);
  83. void AddToolVersion(const QString& toolName, const QString& toolVersion);
  84. QString& GetToolVersion(const QString& sPaneClassName){ return m_toolVersions[sPaneClassName]; };
  85. void AddToolName(const QString& toolName, const QString& humanReadableName = QString());
  86. TToolNamesMap* GetToolNames() { return &m_toolNames; };
  87. // Test if all tools can be safely opened
  88. bool IsToolsOpenSafe();
  89. void ClearToolNames(){ m_toolNames.clear(); m_toolVersions.clear(); };
  90. void UpdateLayoutNode();
  91. void ImportSettings(QString file);
  92. void ExportSettings(XmlNodeRef exportNode, QString fileName);
  93. void Export();
  94. void GetMatchingLayoutNames(TToolNamesMap& foundTools, XmlNodeRef& resultNode, QString file);
  95. bool NeedSettingsNode(const QString& path);
  96. void SerializeCVars(XmlNodeRef& node, bool bLoad);
  97. void ReadValueStr(XmlNodeRef& sourceNode, const QString& path, const QString& attr, QString& val);
  98. void SetExportFileName(QString exportFilePath) { m_ExportFilePath = exportFilePath; };
  99. private:
  100. // Save settings to memory or file
  101. EditorSettingsManagerType m_managerType;
  102. // Full path of exported file
  103. QString m_ExportFilePath;
  104. // Node created in memory to be used for exporting editor settings, console-set cvars and layout
  105. XmlNodeRef m_pSettingsManagerMemoryNode;
  106. // Registered Tool Names
  107. TToolNamesMap m_toolNames;
  108. TToolNamesMap m_toolVersions;
  109. };
  110. #endif // CRYINCLUDE_EDITOR_SETTINGSMANAGER_H