/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Editor/EditorFramework/Preferences/Preferences.h
100 строк
4 KB
C-Core
Array usage cleanup (#1864)
11 мар 2026, 23:44
Не верифицирован
11 мар 2026, 23:44
f7cb730
Код
Авторство
О чём код?
#pragma once #include <EditorFramework/EditorFrameworkDLL.h> #include <Foundation/Reflection/Reflection.h> class ezDocument; /// \brief Base class for all preferences. /// /// Derive from this to implement a custom class containing preferences. /// All properties in such a class are exposed in the preferences UI and are automatically stored and restored. /// /// Pass the 'Domain' and 'Visibility' to the constructor to configure whether the preference class /// is per application, per project or per document, and whether the data is shared among all users /// or custom for every user. class EZ_EDITORFRAMEWORK_DLL ezPreferences : public ezReflectedClass { EZ_ADD_DYNAMIC_REFLECTION(ezPreferences, ezReflectedClass); public: enum class Domain { Application, Project, Document }; /// \brief Static function to query a preferences object of the given type. /// If the instance does not exist yet, it is created and the data is restored from file. template <typename TYPE> static TYPE* QueryPreferences(const ezDocument* pDocument = nullptr) { static_assert((std::is_base_of<ezPreferences, TYPE>::value == true), "All preferences objects must be derived from ezPreferences"); return static_cast<TYPE*>(QueryPreferences(ezGetStaticRTTI<TYPE>(), pDocument)); } /// \brief Static function to query a preferences object of the given type. /// If the instance does not exist yet, it is created and the data is restored from file. static ezPreferences* QueryPreferences(const ezRTTI* pRtti, const ezDocument* pDocument = nullptr); /// \brief Saves all preferences that are tied to the given document static void SaveDocumentPreferences(const ezDocument* pDocument); /// \brief Removes all preferences for the given document. Does not save them. /// Afterwards the preferences will not appear in the UI any further. static void ClearDocumentPreferences(const ezDocument* pDocument); /// \brief Saves all project specific preferences. static void SaveProjectPreferences(); /// \brief Removes all project specific preferences. Does not save them. /// Afterwards the preferences will not appear in the UI any further. static void ClearProjectPreferences(); /// \brief Saves all application specific preferences. static void SaveApplicationPreferences(); /// \brief Removes all application specific preferences. Does not save them. /// Afterwards the preferences will not appear in the UI any further. static void ClearApplicationPreferences(); //// \brief Fills the list with all currently known preferences static void GatherAllPreferences(ezDynamicArray<ezPreferences*>& out_allPreferences); /// \brief Whether the preferences are app, project or document specific Domain GetDomain() const { return m_Domain; } /// \brief Within the same domain and visibility the name must be unique, but across those it can be reused. ezString GetName() const; /// \brief If these preferences are per document, the pointer is valid, otherwise nullptr. const ezDocument* GetDocumentAssociation() const { return m_pDocument; } /// A simple event that can be fired when any preference property changes. No specific change details are given. ezEvent<ezPreferences*> m_ChangedEvent; /// Call this to broadcast that this preference object was modified. void TriggerPreferencesChangedEvent() { m_ChangedEvent.Broadcast(this); } protected: ezPreferences(Domain domain, const char* szUniqueName); ezString GetFilePath() const; private: static void SavePreferences(const ezDocument* pDocument, Domain domain); static void ClearPreferences(const ezDocument* pDocument, Domain domain); void Load(); void Save() const; private: Domain m_Domain; ezString m_sUniqueName; const ezDocument* m_pDocument; static ezMap<const ezDocument*, ezMap<const ezRTTI*, ezPreferences*>> s_Preferences; };