Variable.h 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  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_UTIL_VARIABLE_H
  9. #define CRYINCLUDE_EDITOR_UTIL_VARIABLE_H
  10. #pragma once
  11. #include "RefCountBase.h"
  12. #include "Include/EditorCoreAPI.h"
  13. #include <QObject>
  14. AZ_PUSH_DISABLE_WARNING(4458, "-Wunknown-warning-option")
  15. #include <QtUtilWin.h>
  16. AZ_POP_DISABLE_WARNING
  17. #include <QVariant>
  18. #include <StlUtils.h>
  19. inline const char* to_c_str(const char* str) { return str; }
  20. #define MAX_VAR_STRING_LENGTH 4096
  21. struct IVarEnumList;
  22. struct ISplineInterpolator;
  23. class CUsedResources;
  24. struct IVariable;
  25. namespace
  26. {
  27. template<typename T>
  28. T nextNiceNumberBelow(T number);
  29. template<typename T>
  30. T nextNiceNumberAbove(T number)
  31. {
  32. if (number == 0)
  33. {
  34. return 0;
  35. }
  36. if (number < 0)
  37. {
  38. return -nextNiceNumberBelow(-number);
  39. }
  40. // number = 8000
  41. auto l = log10(number); // 3.90
  42. AZ::s64 i = aznumeric_cast<AZ::s64>(l); // 3
  43. int f = aznumeric_cast<int>(pow(10, l - i)); // 10^0.9 = 8
  44. f = f < 2 ? 2 : f < 5 ? 5 : 10; // f -> 10
  45. return aznumeric_cast<T>(pow(10, i) * f);
  46. }
  47. template<typename T>
  48. T nextNiceNumberBelow(T number)
  49. {
  50. if (number == 0)
  51. {
  52. return 0;
  53. }
  54. if (number < 0)
  55. {
  56. return -nextNiceNumberAbove(-number);
  57. }
  58. // number = 8000
  59. auto l = log10(number); // 3.90
  60. AZ::s64 i = aznumeric_cast<AZ::s64>(l); // 3
  61. int f = aznumeric_cast<int>(pow(10, l - i)); // 10^0.9 = 8
  62. f = f > 5 ? 5 : f > 2 ? 2 : 1; // f -> 5
  63. return aznumeric_cast<T>(pow(10, i) * f);
  64. }
  65. }
  66. /** IVariableContainer
  67. * Interface for all classes that hold child variables
  68. */
  69. struct IVariableContainer
  70. : public CRefCountBase
  71. {
  72. //! Add child variable
  73. virtual void AddVariable(IVariable* var) = 0;
  74. //! Delete specific variable
  75. virtual bool DeleteVariable(IVariable* var, bool recursive = false) = 0;
  76. //! Delete all variables
  77. virtual void DeleteAllVariables() = 0;
  78. //! Gets number of variables
  79. virtual int GetNumVariables() const = 0;
  80. //! Get variable at index
  81. virtual IVariable* GetVariable(int index) const = 0;
  82. //! Returns true if var block contains specified variable.
  83. virtual bool IsContainsVariable(IVariable* pVar, bool bRecursive = false) const = 0;
  84. //! Find variable by name.
  85. virtual IVariable* FindVariable(const char* name, bool bRecursive = false, bool bHumanName = false) const = 0;
  86. //! Return true if variable block is empty (Does not have any vars).
  87. virtual bool IsEmpty() const = 0;
  88. };
  89. //////////////////////////////////////////////////////////////////////////
  90. //////////////////////////////////////////////////////////////////////////
  91. /** IVariable is the variant variable interface.
  92. */
  93. struct IVariable
  94. : public IVariableContainer
  95. {
  96. /** Type of data stored in variable.
  97. */
  98. enum EType
  99. {
  100. UNKNOWN, //!< Unknown parameter type.
  101. INT, //!< Integer property.
  102. BOOL, //!< Boolean property.
  103. FLOAT, //!< Float property.
  104. VECTOR2, //!< Vector property.
  105. VECTOR, //!< Vector property.
  106. VECTOR4, //!< Vector property.
  107. QUAT, //!< Quaternion property.
  108. STRING, //!< String property.
  109. ARRAY, //!< Array of parameters.
  110. FLOW_CUSTOM_DATA, //!< FLow graph custom data
  111. DOUBLE //!< Double property.
  112. };
  113. //! Type of data hold by variable.
  114. enum EDataType
  115. {
  116. DT_SIMPLE = 0, //!< Standard param type.
  117. DT_BOOLEAN,
  118. DT_PERCENT, //!< Percent data type, (Same as simple but value is from 0-1 and UI will be from 0-100).
  119. DT_COLOR,
  120. DT_ANGLE,
  121. DT_TEXTURE,
  122. DT_SHADER,
  123. DT_LOCAL_STRING,
  124. DT_EQUIP,
  125. DT_MATERIALLOOKUP,
  126. DT_EXTARRAY, // Extendable Array
  127. DT_SEQUENCE, // Movie Sequence (DEPRECATED, use DT_SEQUENCE_ID, instead.)
  128. DT_MISSIONOBJ, // Mission Objective
  129. DT_USERITEMCB, // Use a callback GetItemsCallback in user data of variable
  130. DT_UIENUM, // DEPRECATED
  131. DT_SEQUENCE_ID, // Movie Sequence
  132. DT_LIGHT_ANIMATION, // Light Animation Node in the global Light Animation Set
  133. DT_PARTICLE_EFFECT,
  134. DT_DEPRECATED, // formerly DT_FLARE
  135. DT_AUDIO_TRIGGER,
  136. DT_AUDIO_SWITCH,
  137. DT_AUDIO_SWITCH_STATE,
  138. DT_AUDIO_RTPC,
  139. DT_AUDIO_ENVIRONMENT,
  140. DT_AUDIO_PRELOAD_REQUEST,
  141. DT_UI_ELEMENT,
  142. DT_COLORA, // DT_COLOR with alpha channel
  143. DT_MOTION, // Motion animation asset
  144. DT_CURVE = BIT(7), // Combined with other types
  145. };
  146. // Flags that can used with variables.
  147. enum EFlags
  148. {
  149. // User interface related flags.
  150. UI_DISABLED = BIT(0), //!< This variable will be disabled in UI.
  151. UI_BOLD = BIT(1), //!< Variable name in properties will be bold.
  152. UI_SHOW_CHILDREN = BIT(2), //!< Display children in parent field.
  153. UI_USE_GLOBAL_ENUMS = BIT(3), //!< Use CUIEnumsDatabase to fetch enums for this variable name.
  154. UI_INVISIBLE = BIT(4), //!< This variable will not be displayed in the UI
  155. UI_ROLLUP2 = BIT(5), //!< Prefer right roll-up bar for extended property control.
  156. UI_COLLAPSED = BIT(6), //!< Category collapsed by default.
  157. UI_UNSORTED = BIT(7), //!< Do not sort list-box alphabetically.
  158. UI_EXPLICIT_STEP = BIT(8), //!< Use the step size set in the variable for the UI directly.
  159. UI_NOT_DISPLAY_VALUE = BIT(9), //!< The UI will display an empty string where it would normally draw the variable value.
  160. UI_HIGHLIGHT_EDITED = BIT(10), //!< Edited (non-default value) properties show highlight color.
  161. UI_AUTO_EXPAND = BIT(11), //!< Category expanded by default. to auto-expand child in ReflectedPropertyCtrl.
  162. UI_CREATE_SPLINE = BIT(12), //!< To indicate the spline need to be re-created. This is usually because the data was changed directly through the data address
  163. };
  164. typedef AZStd::function<void(IVariable*)> OnSetCallback;
  165. using OnSetEnumCallback = OnSetCallback;
  166. // Store IGetCustomItems into IVariable's UserData and set datatype to
  167. // DT_USERITEMCB
  168. // RefCounting is NOT handled by IVariable!
  169. struct IGetCustomItems
  170. : public CRefCountBase
  171. {
  172. struct SItem
  173. {
  174. SItem() {}
  175. SItem(const QString& name, const QString& desc = QString())
  176. : name(name)
  177. , desc(desc) {}
  178. SItem(const char* name, const char* desc = "")
  179. : name(name)
  180. , desc(desc) {}
  181. QString name;
  182. QString desc;
  183. };
  184. virtual bool GetItems (IVariable* /* pVar */, std::vector<SItem>& /* items */, QString& /* outDialogTitle */) = 0;
  185. virtual bool UseTree() = 0;
  186. virtual const char* GetTreeSeparator() = 0;
  187. };
  188. //! Get name of parameter.
  189. virtual QString GetName() const = 0;
  190. //! Set name of parameter.
  191. virtual void SetName(const QString& name) = 0;
  192. //! Get human readable name of parameter (Normally same as name).
  193. virtual QString GetHumanName() const = 0;
  194. //! Set human readable name of parameter (name without prefix).
  195. virtual void SetHumanName(const QString& name) = 0;
  196. //! Get variable description.
  197. virtual QString GetDescription() const = 0;
  198. //! Set variable description.
  199. virtual void SetDescription(const char* desc) = 0;
  200. //! Set variable description.
  201. virtual void SetDescription(const QString& desc) = 0;
  202. //! Get parameter type.
  203. virtual EType GetType() const = 0;
  204. //! Get size of parameter.
  205. virtual int GetSize() const = 0;
  206. //! Type of data stored in this variable.
  207. virtual unsigned char GetDataType() const = 0;
  208. virtual void SetDataType(unsigned char dataType) = 0;
  209. virtual void SetUserData(const QVariant &data) = 0;
  210. virtual QVariant GetUserData() const = 0;
  211. //////////////////////////////////////////////////////////////////////////
  212. // Flags
  213. //////////////////////////////////////////////////////////////////////////
  214. //! Set variable flags, (Limited to 16 flags).
  215. virtual void SetFlags(int flags) = 0;
  216. virtual int GetFlags() const = 0;
  217. virtual void SetFlagRecursive(EFlags flag) = 0;
  218. /////////////////////////////////////////////////////////////////////////////
  219. // Set methods.
  220. /////////////////////////////////////////////////////////////////////////////
  221. virtual void Set(int value) = 0;
  222. virtual void Set(bool value) = 0;
  223. virtual void Set(float value) = 0;
  224. virtual void Set(double value) = 0;
  225. virtual void Set(const Vec2& value) = 0;
  226. virtual void Set(const Vec3& value) = 0;
  227. virtual void Set(const Vec4& value) = 0;
  228. virtual void Set(const Ang3& value) = 0;
  229. virtual void Set(const Quat& value) = 0;
  230. virtual void Set(const QString& value) = 0;
  231. virtual void Set(const char* value) = 0;
  232. virtual void SetDisplayValue(const QString& value) = 0;
  233. // Called when value updated by any means (including internally).
  234. virtual void OnSetValue(bool bRecursive) = 0;
  235. /////////////////////////////////////////////////////////////////////////////
  236. // Get methods.
  237. /////////////////////////////////////////////////////////////////////////////
  238. virtual void Get(int& value) const = 0;
  239. virtual void Get(bool& value) const = 0;
  240. virtual void Get(float& value) const = 0;
  241. virtual void Get(double& value) const = 0;
  242. virtual void Get(Vec2& value) const = 0;
  243. virtual void Get(Vec3& value) const = 0;
  244. virtual void Get(Vec4& value) const = 0;
  245. virtual void Get(Ang3& value) const = 0;
  246. virtual void Get(Quat& value) const = 0;
  247. virtual void Get(QString& value) const = 0;
  248. virtual QString GetDisplayValue() const = 0;
  249. virtual bool HasDefaultValue() const = 0;
  250. //! reset value to default value
  251. virtual void ResetToDefault() = 0;
  252. //! Return cloned value of variable.
  253. virtual IVariable* Clone(bool bRecursive) const = 0;
  254. //! Copy variable value from specified variable.
  255. //! This method executed always recursively on all sub hierarchy of variables,
  256. //! In Array vars, will never create new variables, only copy values of corresponding childs.
  257. //! @param fromVar Source variable to copy value from.
  258. virtual void CopyValue(IVariable* fromVar) = 0;
  259. //////////////////////////////////////////////////////////////////////////
  260. // Value Limits.
  261. //////////////////////////////////////////////////////////////////////////
  262. //! Set value limits.
  263. virtual void SetLimits([[maybe_unused]] float fMin, [[maybe_unused]] float fMax, [[maybe_unused]] float fStep = 0.f, [[maybe_unused]] bool bHardMin = true, [[maybe_unused]] bool bHardMax = true) {}
  264. //! Get value limits.
  265. virtual void GetLimits([[maybe_unused]] float& fMin, [[maybe_unused]] float& fMax, [[maybe_unused]] float& fStep, [[maybe_unused]] bool& bHardMin, [[maybe_unused]] bool& bHardMax) {}
  266. void GetLimits(float& fMin, float& fMax)
  267. {
  268. float f;
  269. bool b;
  270. GetLimits(fMin, fMax, f, b, b);
  271. }
  272. virtual bool HasCustomLimits() { return false; }
  273. virtual void EnableNotifyWithoutValueChange([[maybe_unused]] bool bFlag){}
  274. //////////////////////////////////////////////////////////////////////////
  275. // Wire/Unwire variables.
  276. //////////////////////////////////////////////////////////////////////////
  277. //! Wire variable, wired variable will be changed when this var changes.
  278. virtual void Wire(IVariable* targetVar) = 0;
  279. //! Unwire variable.
  280. virtual void Unwire(IVariable* targetVar) = 0;
  281. //////////////////////////////////////////////////////////////////////////
  282. // Assign on set callback.
  283. //////////////////////////////////////////////////////////////////////////
  284. virtual void AddOnSetCallback(OnSetCallback* func) = 0;
  285. virtual void RemoveOnSetCallback(OnSetCallback* func) = 0;
  286. virtual void ClearOnSetCallbacks() {}
  287. //////////////////////////////////////////////////////////////////////////
  288. // Assign callback triggered when enums change.
  289. //////////////////////////////////////////////////////////////////////////
  290. virtual void AddOnSetEnumCallback(OnSetEnumCallback* func) = 0;
  291. virtual void RemoveOnSetEnumCallback(OnSetCallback* func) = 0;
  292. virtual void ClearOnSetEnumCallbacks() {}
  293. //////////////////////////////////////////////////////////////////////////
  294. //! Retrieve pointer to selection list used by variable.
  295. virtual IVarEnumList* GetEnumList() const { return 0; }
  296. virtual ISplineInterpolator* GetSpline() { return 0; }
  297. //////////////////////////////////////////////////////////////////////////
  298. //! Serialize variable to XML.
  299. //////////////////////////////////////////////////////////////////////////
  300. virtual void Serialize(XmlNodeRef node, bool load) = 0;
  301. // From CObject, (not implemented)
  302. virtual void Serialize([[maybe_unused]] CArchive& ar) {}
  303. //////////////////////////////////////////////////////////////////////////
  304. // Disables the update callbacks for certain operations in order to avoid
  305. // too many function calls when not needed.
  306. //////////////////////////////////////////////////////////////////////////
  307. virtual void EnableUpdateCallbacks(bool boEnable) = 0;
  308. // Setup to true to force save Undo in case the value the same.
  309. virtual void SetForceModified([[maybe_unused]] bool bForceModified) {}
  310. };
  311. // Smart pointer to this parameter.
  312. typedef _smart_ptr<IVariable> IVariablePtr;
  313. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  314. /**
  315. **************************************************************************************
  316. * CVariableBase implements IVariable interface and provide default implementation
  317. * for basic IVariable functionality (Name, Flags, etc...)
  318. * CVariableBase cannot be instantiated directly and should be used as the base class for
  319. * actual Variant implementation classes.
  320. ***************************************************************************************
  321. */
  322. class EDITOR_CORE_API CVariableBase
  323. : public IVariable
  324. {
  325. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  326. public:
  327. virtual ~CVariableBase() {}
  328. void SetName(const QString& name) override { m_name = name; };
  329. //! Get name of parameter.
  330. QString GetName() const override { return m_name; };
  331. QString GetHumanName() const override
  332. {
  333. if (!m_humanName.isEmpty())
  334. {
  335. return m_humanName;
  336. }
  337. return m_name;
  338. }
  339. void SetHumanName(const QString& name) override { m_humanName = name; }
  340. void SetDescription(const char* desc) override { m_description = desc; };
  341. void SetDescription(const QString& desc) override { m_description = desc; };
  342. //! Get name of parameter.
  343. QString GetDescription() const override { return m_description; };
  344. EType GetType() const override { return IVariable::UNKNOWN; };
  345. int GetSize() const override { return sizeof(*this); };
  346. unsigned char GetDataType() const override { return m_dataType; };
  347. void SetDataType(unsigned char dataType) override { m_dataType = dataType; }
  348. void SetFlags(int flags) override { m_flags = static_cast<uint16>(flags); }
  349. int GetFlags() const override { return m_flags; }
  350. void SetFlagRecursive(EFlags flag) override { m_flags |= flag; }
  351. void SetUserData(const QVariant &data) override { m_userData = data; };
  352. QVariant GetUserData() const override { return m_userData; }
  353. //////////////////////////////////////////////////////////////////////////
  354. // Set methods.
  355. //////////////////////////////////////////////////////////////////////////
  356. void Set([[maybe_unused]] int value) override { assert(0); }
  357. void Set([[maybe_unused]] bool value) override { assert(0); }
  358. void Set([[maybe_unused]] float value) override { assert(0); }
  359. void Set([[maybe_unused]] double value) override { assert(0); }
  360. void Set([[maybe_unused]] const Vec2& value) override { assert(0); }
  361. void Set([[maybe_unused]] const Vec3& value) override { assert(0); }
  362. void Set([[maybe_unused]] const Vec4& value) override { assert(0); }
  363. void Set([[maybe_unused]] const Ang3& value) override { assert(0); }
  364. void Set([[maybe_unused]] const Quat& value) override { assert(0); }
  365. void Set([[maybe_unused]] const QString& value) override { assert(0); }
  366. void Set([[maybe_unused]] const char* value) override { assert(0); }
  367. void SetDisplayValue(const QString& value) override { Set(value); }
  368. //////////////////////////////////////////////////////////////////////////
  369. // Get methods.
  370. //////////////////////////////////////////////////////////////////////////
  371. void Get([[maybe_unused]] int& value) const override { assert(0); }
  372. void Get([[maybe_unused]] bool& value) const override { assert(0); }
  373. void Get([[maybe_unused]] float& value) const override { assert(0); }
  374. void Get([[maybe_unused]] double& value) const override { assert(0); }
  375. void Get([[maybe_unused]] Vec2& value) const override { assert(0); }
  376. void Get([[maybe_unused]] Vec3& value) const override { assert(0); }
  377. void Get([[maybe_unused]] Vec4& value) const override { assert(0); }
  378. void Get([[maybe_unused]] Ang3& value) const override { assert(0); }
  379. void Get([[maybe_unused]] Quat& value) const override { assert(0); }
  380. void Get([[maybe_unused]] QString& value) const override { assert(0); }
  381. QString GetDisplayValue() const override { QString val; Get(val); return val; }
  382. //////////////////////////////////////////////////////////////////////////
  383. // IVariableContainer functions
  384. //////////////////////////////////////////////////////////////////////////
  385. void AddVariable([[maybe_unused]] IVariable* var) override { assert(0); }
  386. bool DeleteVariable([[maybe_unused]] IVariable* var, [[maybe_unused]] bool recursive = false) override { return false; }
  387. void DeleteAllVariables() override {}
  388. int GetNumVariables() const override { return 0; }
  389. IVariable* GetVariable([[maybe_unused]] int index) const override { return nullptr; }
  390. bool IsContainsVariable([[maybe_unused]] IVariable* pVar, [[maybe_unused]] bool bRecursive = false) const override { return false; }
  391. IVariable* FindVariable([[maybe_unused]] const char* name, [[maybe_unused]] bool bRecursive = false, [[maybe_unused]] bool bHumanName = false) const override { return nullptr; }
  392. bool IsEmpty() const override { return true; }
  393. //////////////////////////////////////////////////////////////////////////
  394. void Wire(IVariable* var) override
  395. {
  396. m_wiredVars.push_back(var);
  397. }
  398. //////////////////////////////////////////////////////////////////////////
  399. void Unwire(IVariable* var) override
  400. {
  401. if (!var)
  402. {
  403. // Unwire all.
  404. m_wiredVars.clear();
  405. }
  406. else
  407. {
  408. stl::find_and_erase(m_wiredVars, var);
  409. }
  410. }
  411. //////////////////////////////////////////////////////////////////////////
  412. void AddOnSetCallback(OnSetCallback* func) override
  413. {
  414. if (!stl::find(m_onSetFuncs, func))
  415. {
  416. m_onSetFuncs.push_back(func);
  417. }
  418. }
  419. //////////////////////////////////////////////////////////////////////////
  420. void RemoveOnSetCallback(OnSetCallback* func) override
  421. {
  422. stl::find_and_erase(m_onSetFuncs, func);
  423. }
  424. //////////////////////////////////////////////////////////////////////////
  425. void ClearOnSetCallbacks() override
  426. {
  427. m_onSetFuncs.clear();
  428. }
  429. void AddOnSetEnumCallback(OnSetEnumCallback* func) override
  430. {
  431. if (!stl::find(m_onSetEnumFuncs, func))
  432. {
  433. m_onSetEnumFuncs.push_back(func);
  434. }
  435. }
  436. //////////////////////////////////////////////////////////////////////////
  437. void RemoveOnSetEnumCallback(OnSetCallback* func) override
  438. {
  439. stl::find_and_erase(m_onSetEnumFuncs, func);
  440. }
  441. void ClearOnSetEnumCallbacks() override
  442. {
  443. m_onSetEnumFuncs.clear();
  444. }
  445. void OnSetValue([[maybe_unused]] bool bRecursive) override
  446. {
  447. // If have wired variables or OnSet callback, process them.
  448. // Send value to wired variable.
  449. for (CVariableBase::WiredList::iterator it = m_wiredVars.begin(); it != m_wiredVars.end(); ++it)
  450. {
  451. if (m_bForceModified)
  452. {
  453. (*it)->SetForceModified(true);
  454. }
  455. // Copy value to wired vars.
  456. (*it)->CopyValue(this);
  457. }
  458. if (!m_boUpdateCallbacksEnabled)
  459. {
  460. return;
  461. }
  462. // Call on set callback.
  463. for (auto it = m_onSetFuncs.begin(); it != m_onSetFuncs.end(); ++it)
  464. {
  465. // Call on set callback.
  466. (*it)->operator()(this);
  467. }
  468. }
  469. //////////////////////////////////////////////////////////////////////////
  470. using IVariable::Serialize;
  471. void Serialize(XmlNodeRef node, bool load) override
  472. {
  473. if (load)
  474. {
  475. if (node->haveAttr(m_name.toUtf8().data()))
  476. {
  477. Set(node->getAttr(m_name.toUtf8().data()));
  478. }
  479. }
  480. else
  481. {
  482. // Saving.
  483. QString str;
  484. Get(str);
  485. node->setAttr(m_name.toUtf8().data(), str.toUtf8().data());
  486. }
  487. }
  488. void EnableUpdateCallbacks(bool boEnable) override{m_boUpdateCallbacksEnabled = boEnable; };
  489. void SetForceModified(bool bForceModified) override { m_bForceModified = bForceModified; }
  490. protected:
  491. // Constructor.
  492. CVariableBase()
  493. : m_dataType(DT_SIMPLE)
  494. , m_flags(0)
  495. , m_boUpdateCallbacksEnabled(true)
  496. , m_bForceModified(false)
  497. {
  498. }
  499. // Copy constructor.
  500. CVariableBase(const CVariableBase& var)
  501. {
  502. m_name = var.m_name;
  503. m_humanName = var.m_humanName;
  504. m_description = var.m_description;
  505. m_flags = var.m_flags;
  506. m_dataType = var.m_dataType;
  507. m_userData = var.m_userData;
  508. m_boUpdateCallbacksEnabled = true;
  509. m_bForceModified = var.m_bForceModified;
  510. // Never copy callback function or wired variables they are private to specific variable,
  511. }
  512. // Not allow.
  513. CVariableBase& operator=([[maybe_unused]] const CVariableBase& var)
  514. {
  515. return *this;
  516. }
  517. //////////////////////////////////////////////////////////////////////////
  518. // Variables.
  519. //////////////////////////////////////////////////////////////////////////
  520. typedef std::vector<OnSetCallback*> OnSetCallbackList;
  521. typedef std::vector<IVariablePtr> WiredList;
  522. using OnSetEnumCallbackList = std::vector<OnSetEnumCallback*>;
  523. QString m_name;
  524. QString m_humanName;
  525. QString m_description;
  526. //! Optional userdata pointer
  527. QVariant m_userData;
  528. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  529. //! Extended data (Extended data is never copied, it's always private to this variable).
  530. WiredList m_wiredVars;
  531. OnSetCallbackList m_onSetFuncs;
  532. OnSetEnumCallbackList m_onSetEnumFuncs;
  533. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  534. uint16 m_flags;
  535. //! Limited to 8 flags.
  536. unsigned char m_dataType;
  537. bool m_boUpdateCallbacksEnabled;
  538. bool m_bForceModified;
  539. };
  540. /**
  541. **************************************************************************************
  542. * CVariableArray implements variable of type array of IVariables.
  543. ***************************************************************************************
  544. */
  545. class EDITOR_CORE_API CVariableArray
  546. : public CVariableBase
  547. {
  548. public:
  549. CVariableArray(){}
  550. //! Get name of parameter.
  551. EType GetType() const override { return IVariable::ARRAY; };
  552. int GetSize() const override { return sizeof(CVariableArray); };
  553. //////////////////////////////////////////////////////////////////////////
  554. // Set methods.
  555. //////////////////////////////////////////////////////////////////////////
  556. void Set(const QString& value) override
  557. {
  558. if (m_strValue != value)
  559. {
  560. m_strValue = value;
  561. OnSetValue(false);
  562. }
  563. }
  564. void OnSetValue(bool bRecursive) override
  565. {
  566. CVariableBase::OnSetValue(bRecursive);
  567. if (bRecursive)
  568. {
  569. for (Variables::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  570. {
  571. (*it)->OnSetValue(true);
  572. }
  573. }
  574. }
  575. void SetFlagRecursive(EFlags flag) override
  576. {
  577. CVariableBase::SetFlagRecursive(flag);
  578. for (Variables::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  579. {
  580. (*it)->SetFlagRecursive(flag);
  581. }
  582. }
  583. //////////////////////////////////////////////////////////////////////////
  584. // Get methods.
  585. //////////////////////////////////////////////////////////////////////////
  586. void Get(QString& value) const override { value = m_strValue; }
  587. bool HasDefaultValue() const override
  588. {
  589. for (Variables::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  590. {
  591. if (!(*it)->HasDefaultValue())
  592. {
  593. return false;
  594. }
  595. }
  596. return true;
  597. }
  598. void ResetToDefault() override
  599. {
  600. for (Variables::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  601. {
  602. (*it)->ResetToDefault();
  603. }
  604. }
  605. //////////////////////////////////////////////////////////////////////////
  606. IVariable* Clone(bool bRecursive) const override
  607. {
  608. CVariableArray* var = new CVariableArray(*this);
  609. // m_vars was shallow-duplicated, clone elements.
  610. for (int i = 0; i < m_vars.size(); i++)
  611. {
  612. var->m_vars[i] = m_vars[i]->Clone(bRecursive);
  613. }
  614. return var;
  615. }
  616. //////////////////////////////////////////////////////////////////////////
  617. void CopyValue(IVariable* fromVar) override
  618. {
  619. assert(fromVar);
  620. if (fromVar->GetType() != IVariable::ARRAY)
  621. {
  622. return;
  623. }
  624. int numSrc = fromVar->GetNumVariables();
  625. int numTrg = static_cast<int>(m_vars.size());
  626. for (int i = 0; i < numSrc && i < numTrg; i++)
  627. {
  628. // Copy Every child variable.
  629. m_vars[i]->CopyValue(fromVar->GetVariable(i));
  630. }
  631. QString strValue;
  632. fromVar->Get(strValue);
  633. Set(strValue);
  634. }
  635. //////////////////////////////////////////////////////////////////////////
  636. int GetNumVariables() const override { return static_cast<int>(m_vars.size()); }
  637. IVariable* GetVariable(int index) const override
  638. {
  639. assert(index >= 0 && index < (int)m_vars.size());
  640. return m_vars[index];
  641. }
  642. void AddVariable(IVariable* var) override
  643. {
  644. m_vars.push_back(var);
  645. }
  646. bool DeleteVariable(IVariable* var, bool recursive /*=false*/) override
  647. {
  648. bool found = stl::find_and_erase(m_vars, var);
  649. if (!found && recursive)
  650. {
  651. for (Variables::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  652. {
  653. if ((*it)->DeleteVariable(var, recursive))
  654. {
  655. return true;
  656. }
  657. }
  658. }
  659. return found;
  660. }
  661. void DeleteAllVariables() override
  662. {
  663. m_vars.clear();
  664. }
  665. bool IsContainsVariable(IVariable* pVar, bool bRecursive) const override
  666. {
  667. for (Variables::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  668. {
  669. if (*it == pVar)
  670. {
  671. return true;
  672. }
  673. }
  674. // If not found search childs.
  675. if (bRecursive)
  676. {
  677. // Search all top level variables.
  678. for (Variables::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  679. {
  680. if ((*it)->IsContainsVariable(pVar))
  681. {
  682. return true;
  683. }
  684. }
  685. }
  686. return false;
  687. }
  688. IVariable* FindVariable(const char* name, bool bRecursive, bool bHumanName) const override;
  689. bool IsEmpty() const override
  690. {
  691. return m_vars.empty();
  692. }
  693. using IVariable::Serialize;
  694. void Serialize(XmlNodeRef node, bool load) override
  695. {
  696. if (load)
  697. {
  698. // Loading.
  699. QString name;
  700. for (Variables::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  701. {
  702. IVariable* var = *it;
  703. if (var->GetNumVariables())
  704. {
  705. XmlNodeRef child = node->findChild(var->GetName().toUtf8().data());
  706. if (child)
  707. {
  708. var->Serialize(child, load);
  709. }
  710. }
  711. else
  712. {
  713. var->Serialize(node, load);
  714. }
  715. }
  716. }
  717. else
  718. {
  719. // Saving.
  720. for (Variables::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  721. {
  722. IVariable* var = *it;
  723. if (var->GetNumVariables())
  724. {
  725. XmlNodeRef child = node->newChild(var->GetName().toUtf8().data());
  726. var->Serialize(child, load);
  727. }
  728. else
  729. {
  730. var->Serialize(node, load);
  731. }
  732. }
  733. }
  734. }
  735. protected:
  736. typedef std::vector<IVariablePtr> Variables;
  737. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  738. Variables m_vars;
  739. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  740. //! Any string value displayed in properties.
  741. QString m_strValue;
  742. };
  743. /** var_type namespace includes type definitions needed for CVariable implementaton.
  744. */
  745. namespace var_type
  746. {
  747. //////////////////////////////////////////////////////////////////////////
  748. template <int TypeID, bool IsStandart, bool IsInteger, bool IsSigned, bool SupportsRange>
  749. struct type_traits_base
  750. {
  751. static int type() { return TypeID; };
  752. //! Return true if standard C++ type.
  753. static bool is_standart() { return IsStandart; };
  754. static bool is_integer() { return IsInteger; };
  755. static bool is_signed() { return IsSigned; };
  756. static bool supports_range() { return SupportsRange; };
  757. };
  758. template <class Type>
  759. struct type_traits
  760. : public type_traits_base<IVariable::UNKNOWN, false, false, false, false> {};
  761. // Types specialization.
  762. template<>
  763. struct type_traits<int>
  764. : public type_traits_base<IVariable::INT, true, true, true, true> {};
  765. template<>
  766. struct type_traits<bool>
  767. : public type_traits_base<IVariable::BOOL, true, true, false, true> {};
  768. template<>
  769. struct type_traits<float>
  770. : public type_traits_base<IVariable::FLOAT, true, false, false, true> {};
  771. template<>
  772. struct type_traits<double>
  773. : public type_traits_base<IVariable::DOUBLE, true, false, false, true>{};
  774. template<>
  775. struct type_traits<Vec2>
  776. : public type_traits_base<IVariable::VECTOR2, false, false, false, false> {};
  777. template<>
  778. struct type_traits<Vec3>
  779. : public type_traits_base<IVariable::VECTOR, false, false, false, false> {};
  780. template<>
  781. struct type_traits<Vec4>
  782. : public type_traits_base<IVariable::VECTOR4, false, false, false, false> {};
  783. template<>
  784. struct type_traits<Quat>
  785. : public type_traits_base<IVariable::QUAT, false, false, false, false> {};
  786. template<>
  787. struct type_traits<QString>
  788. : public type_traits_base<IVariable::STRING, false, false, false, false> {};
  789. //////////////////////////////////////////////////////////////////////////
  790. //////////////////////////////////////////////////////////////////////////
  791. // General one type to another type convertor class.
  792. //////////////////////////////////////////////////////////////////////////
  793. struct type_convertor
  794. {
  795. template <class From, class To>
  796. void operator()([[maybe_unused]] const From& from, [[maybe_unused]] To& to) const { assert(0); }
  797. void operator()(const int& from, int& to) const { to = from; }
  798. void operator()(const int& from, bool& to) const { to = from != 0; }
  799. void operator()(const int& from, float& to) const { to = (float)from; }
  800. //////////////////////////////////////////////////////////////////////////
  801. void operator()(const bool& from, int& to) const { to = from; }
  802. void operator()(const bool& from, bool& to) const { to = from; }
  803. void operator()(const bool& from, float& to) const { to = from; }
  804. //////////////////////////////////////////////////////////////////////////
  805. void operator()(const float& from, int& to) const { to = (int)from; }
  806. void operator()(const float& from, bool& to) const { to = from != 0; }
  807. void operator()(const float& from, float& to) const { to = from; }
  808. void operator()(const double& from, int& to) const { to = (int)from; }
  809. void operator()(const double& from, bool& to) const { to = from != 0; }
  810. void operator()(const double& from, float& to) const { to = aznumeric_cast<float>(from); }
  811. void operator()(const Vec2& from, Vec2& to) const { to = from; }
  812. void operator()(const Vec3& from, Vec3& to) const { to = from; }
  813. void operator()(const Vec4& from, Vec4& to) const { to = from; }
  814. void operator()(const Quat& from, Quat& to) const { to = from; }
  815. void operator()(const QString& from, QString& to) const { to = from; }
  816. void operator()(bool value, QString& to) const { to = QString::number((value) ? (int)1 : (int)0); }
  817. void operator()(int value, QString& to) const { to = QString::number(value); }
  818. void operator()(float value, QString& to) const { to = QString::number(value); };
  819. void operator()(double value, QString& to) const { to = QString::number(value); };
  820. void operator()(const Vec2& value, QString& to) const { to = QString::fromLatin1("%1,%2").arg(value.x).arg(value.y); }
  821. void operator()(const Vec3& value, QString& to) const { to = QString::fromLatin1("%1,%2,%3").arg(value.x).arg(value.y).arg(value.z); }
  822. void operator()(const Vec4& value, QString& to) const { to = QString::fromLatin1("%1,%2,%3,%4").arg(value.x).arg(value.y).arg(value.z).arg(value.w); }
  823. void operator()(const Ang3& value, QString& to) const { to = QString::fromLatin1("%1,%2,%3").arg(value.x).arg(value.y).arg(value.z); }
  824. void operator()(const Quat& value, QString& to) const { to = QString::fromLatin1("%1,%2,%3,%4").arg(value.w).arg(value.v.x).arg(value.v.y).arg(value.v.z); }
  825. void operator()(const QString& from, int& value) const { value = from.toInt(); }
  826. void operator()(const QString& from, bool& value) const { value = from.toInt() != 0; }
  827. void operator()(const QString& from, float& value) const { value = from.toFloat(); }
  828. void operator()(const QString& from, Vec2& value) const
  829. {
  830. QStringList parts = from.split(QStringLiteral(","));
  831. while (parts.size() < 2)
  832. {
  833. parts.push_back(QString());
  834. }
  835. value.x = parts[0].toFloat();
  836. value.y = parts[1].toFloat();
  837. };
  838. void operator()(const QString& from, Vec3& value) const
  839. {
  840. QStringList parts = from.split(QStringLiteral(","));
  841. while (parts.size() < 3)
  842. {
  843. parts.push_back(QString());
  844. }
  845. value.x = parts[0].toFloat();
  846. value.y = parts[1].toFloat();
  847. value.z = parts[2].toFloat();
  848. };
  849. void operator()(const QString& from, Vec4& value) const
  850. {
  851. QStringList parts = from.split(QStringLiteral(","));
  852. while (parts.size() < 4)
  853. {
  854. parts.push_back(QString());
  855. }
  856. value.x = parts[0].toFloat();
  857. value.y = parts[1].toFloat();
  858. value.z = parts[2].toFloat();
  859. value.w = parts[3].toFloat();
  860. };
  861. void operator()(const QString& from, Ang3& value) const
  862. {
  863. QStringList parts = from.split(QStringLiteral(","));
  864. while (parts.size() < 3)
  865. {
  866. parts.push_back(QString());
  867. }
  868. value.x = parts[0].toFloat();
  869. value.y = parts[1].toFloat();
  870. value.z = parts[2].toFloat();
  871. };
  872. void operator()(const QString& from, Quat& value) const
  873. {
  874. QStringList parts = from.split(QStringLiteral(","));
  875. while (parts.size() < 4)
  876. {
  877. parts.push_back(QString());
  878. }
  879. value.w = parts[0].toFloat();
  880. value.v.x = parts[1].toFloat();
  881. value.v.y = parts[2].toFloat();
  882. value.v.z = parts[3].toFloat();
  883. };
  884. };
  885. //////////////////////////////////////////////////////////////////////////
  886. // Custom comparison functions for different variable type's values,.
  887. //////////////////////////////////////////////////////////////////////////
  888. template <class Type>
  889. inline bool compare(const Type& arg1, const Type& arg2)
  890. {
  891. return arg1 == arg2;
  892. };
  893. inline bool compare(const Vec2& v1, const Vec2& v2)
  894. {
  895. return v1.x == v2.x && v1.y == v2.y;
  896. }
  897. inline bool compare(const Vec3& v1, const Vec3& v2)
  898. {
  899. return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
  900. }
  901. inline bool compare(const Vec4& v1, const Vec4& v2)
  902. {
  903. return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w;
  904. }
  905. inline bool compare(const Ang3& v1, const Ang3& v2)
  906. {
  907. return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
  908. }
  909. inline bool compare(const Quat& q1, const Quat& q2)
  910. {
  911. return q1.v.x == q2.v.x && q1.v.y == q2.v.y && q1.v.z == q2.v.z && q1.w == q2.w;
  912. }
  913. inline bool compare(const char* s1, const char* s2)
  914. {
  915. return strcmp(s1, s2) == 0;
  916. }
  917. //////////////////////////////////////////////////////////////////////////
  918. //////////////////////////////////////////////////////////////////////////
  919. // Custom Initialization functions for different variable type's values,.
  920. //////////////////////////////////////////////////////////////////////////
  921. template <class Type>
  922. inline void init(Type& val)
  923. {
  924. val = 0;
  925. };
  926. inline void init(Vec2& val) { val.x = 0; val.y = 0; };
  927. inline void init(Vec3& val) { val.x = 0; val.y = 0; val.z = 0; };
  928. inline void init(Vec4& val) { val.x = 0; val.y = 0; val.z = 0; val.w = 0; };
  929. inline void init(Ang3& val) { val.x = 0; val.y = 0; val.z = 0; };
  930. inline void init(Quat& val)
  931. {
  932. val.v.x = 0;
  933. val.v.y = 0;
  934. val.v.z = 0;
  935. val.w = 0;
  936. };
  937. inline void init(const char*& val)
  938. {
  939. val = "";
  940. };
  941. inline void init([[maybe_unused]] QString& val)
  942. {
  943. // self initializing.
  944. }
  945. //////////////////////////////////////////////////////////////////////////
  946. };
  947. //////////////////////////////////////////////////////////////////////////
  948. // Void variable does not contain any value.
  949. //////////////////////////////////////////////////////////////////////////
  950. class CVariableVoid
  951. : public CVariableBase
  952. {
  953. public:
  954. CVariableVoid(){};
  955. EType GetType() const override { return IVariable::UNKNOWN; };
  956. IVariable* Clone([[maybe_unused]] bool bRecursive) const override { return new CVariableVoid(*this); }
  957. void CopyValue([[maybe_unused]] IVariable* fromVar) override {};
  958. bool HasDefaultValue() const override { return true; }
  959. void ResetToDefault() override {};
  960. protected:
  961. CVariableVoid(const CVariableVoid& v)
  962. : CVariableBase(v) {};
  963. };
  964. //////////////////////////////////////////////////////////////////////////
  965. template <class T>
  966. class CVariable
  967. : public CVariableBase
  968. {
  969. typedef CVariable<T> Self;
  970. public:
  971. // Constructor.
  972. CVariable()
  973. : m_valueMin(0.0f)
  974. , m_valueMax(100.0f)
  975. , m_valueStep(0.0f)
  976. , m_bHardMin(false)
  977. , m_bHardMax(false)
  978. , m_customLimits(false)
  979. {
  980. // Initialize value to zero or empty string.
  981. var_type::init(m_valueDef);
  982. }
  983. explicit CVariable(const T& set)
  984. : CVariable()
  985. {
  986. var_type::init(m_valueDef); // Update F32NAN values in Debud mode
  987. SetValue(set);
  988. }
  989. //! Get name of parameter.
  990. EType GetType() const override { return (EType)var_type::type_traits<T>::type(); };
  991. int GetSize() const override { return sizeof(T); };
  992. //////////////////////////////////////////////////////////////////////////
  993. // Set methods.
  994. //////////////////////////////////////////////////////////////////////////
  995. void Set(int value) override { SetValue(value); }
  996. void Set(bool value) override { SetValue(value); }
  997. void Set(float value) override { SetValue(value); }
  998. void Set(double value) override { SetValue(value); }
  999. void Set(const Vec2& value) override { SetValue(value); }
  1000. void Set(const Vec3& value) override { SetValue(value); }
  1001. void Set(const Vec4& value) override { SetValue(value); }
  1002. void Set(const Ang3& value) override { SetValue(value); }
  1003. void Set(const Quat& value) override { SetValue(value); }
  1004. void Set(const QString& value) override { SetValue(value); }
  1005. void Set(const char* value) override { SetValue(QString(value)); }
  1006. //////////////////////////////////////////////////////////////////////////
  1007. // Get methods.
  1008. //////////////////////////////////////////////////////////////////////////
  1009. void Get(int& value) const override { GetValue(value); }
  1010. void Get(bool& value) const override { GetValue(value); }
  1011. void Get(float& value) const override { GetValue(value); }
  1012. void Get(double& value) const override { GetValue(value); }
  1013. void Get(Vec2& value) const override { GetValue(value); }
  1014. void Get(Vec3& value) const override { GetValue(value); }
  1015. void Get(Vec4& value) const override { GetValue(value); }
  1016. void Get(Quat& value) const override { GetValue(value); }
  1017. void Get(QString& value) const override { GetValue(value); }
  1018. bool HasDefaultValue() const override
  1019. {
  1020. T defval;
  1021. var_type::init(defval);
  1022. return m_valueDef == defval;
  1023. }
  1024. void ResetToDefault() override
  1025. {
  1026. T defval;
  1027. var_type::init(defval);
  1028. SetValue(defval);
  1029. }
  1030. //////////////////////////////////////////////////////////////////////////
  1031. // Limits.
  1032. //////////////////////////////////////////////////////////////////////////
  1033. void SetLimits(float fMin, float fMax, float fStep = 0.f, bool bHardMin = true, bool bHardMax = true) override
  1034. {
  1035. m_valueMin = fMin;
  1036. m_valueMax = fMax;
  1037. m_valueStep = fStep;
  1038. m_bHardMin = bHardMin;
  1039. m_bHardMax = bHardMax;
  1040. // Flag to determine when this variable has custom limits set
  1041. m_customLimits = true;
  1042. }
  1043. void GetLimits(float& fMin, float& fMax, float& fStep, bool& bHardMin, bool& bHardMax) override
  1044. {
  1045. if (!m_customLimits && var_type::type_traits<T>::supports_range())
  1046. {
  1047. float value;
  1048. GetValue(value);
  1049. if (value > m_valueMax && !m_bHardMax)
  1050. {
  1051. SetLimits(m_valueMin, nextNiceNumberAbove(value), 0.0, false, false);
  1052. }
  1053. if (value < m_valueMin && !m_bHardMin)
  1054. {
  1055. SetLimits(nextNiceNumberBelow(value), m_valueMax, 0.0, false, false);
  1056. }
  1057. }
  1058. fMin = m_valueMin;
  1059. fMax = m_valueMax;
  1060. fStep = m_valueStep;
  1061. bHardMin = m_bHardMin;
  1062. bHardMax = m_bHardMax;
  1063. }
  1064. void ClearLimits()
  1065. {
  1066. SetLimits(0.0f, 0.0f, 0.0f, false, false);
  1067. m_customLimits = false;
  1068. }
  1069. bool HasCustomLimits() override
  1070. {
  1071. return m_customLimits;
  1072. }
  1073. //////////////////////////////////////////////////////////////////////////
  1074. // Access operators.
  1075. //////////////////////////////////////////////////////////////////////////
  1076. //! Cast to held type.
  1077. operator T const& () const {
  1078. return m_valueDef;
  1079. }
  1080. //! Assign operator for variable.
  1081. void operator=(const T& value) { SetValue(value); }
  1082. //////////////////////////////////////////////////////////////////////////
  1083. IVariable* Clone([[maybe_unused]] bool bRecursive) const override
  1084. {
  1085. Self* var = new Self(*this);
  1086. return var;
  1087. }
  1088. //////////////////////////////////////////////////////////////////////////
  1089. void CopyValue(IVariable* fromVar) override
  1090. {
  1091. assert(fromVar);
  1092. T val;
  1093. fromVar->Get(val);
  1094. SetValue(val);
  1095. }
  1096. protected:
  1097. //////////////////////////////////////////////////////////////////////////
  1098. template <class P>
  1099. void SetValue(const P& value)
  1100. {
  1101. T newValue = T();
  1102. //var_type::type_convertor<P,T> convertor;
  1103. var_type::type_convertor convertor;
  1104. convertor(value, newValue);
  1105. // compare old and new values.
  1106. if (m_bForceModified || !var_type::compare(m_valueDef, newValue))
  1107. {
  1108. m_valueDef = newValue;
  1109. m_bForceModified = false;
  1110. OnSetValue(false);
  1111. }
  1112. }
  1113. //////////////////////////////////////////////////////////////////////////
  1114. template <class P>
  1115. void GetValue(P& value) const
  1116. {
  1117. var_type::type_convertor convertor;
  1118. convertor(m_valueDef, value);
  1119. }
  1120. protected:
  1121. T m_valueDef;
  1122. bool m_customLimits;
  1123. bool m_bResolving;
  1124. unsigned char m_bHardMin : 1;
  1125. unsigned char m_bHardMax : 1;
  1126. // Min/Max value.
  1127. float m_valueMin, m_valueMax, m_valueStep;
  1128. };
  1129. //////////////////////////////////////////////////////////////////////////
  1130. /**
  1131. **************************************************************************************
  1132. * CVariableArray implements variable of type array of IVariables.
  1133. ***************************************************************************************
  1134. */
  1135. template <class T>
  1136. class TVariableArray
  1137. : public CVariable<T>
  1138. {
  1139. typedef TVariableArray<T> Self;
  1140. public:
  1141. using CVariable<T>::GetType;
  1142. TVariableArray()
  1143. : CVariable<T>() {};
  1144. // Copy Constructor.
  1145. TVariableArray(const Self& var)
  1146. : CVariable<T>(var)
  1147. {}
  1148. //! Get name of parameter.
  1149. virtual int GetSize() const { return sizeof(Self); };
  1150. virtual bool HasDefaultValue() const
  1151. {
  1152. for (Vars::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  1153. {
  1154. if (!(*it)->HasDefaultValue())
  1155. {
  1156. return false;
  1157. }
  1158. }
  1159. return true;
  1160. }
  1161. virtual void ResetToDefault()
  1162. {
  1163. for (Vars::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  1164. {
  1165. (*it)->ResetToDefault();
  1166. }
  1167. }
  1168. //////////////////////////////////////////////////////////////////////////
  1169. IVariable* Clone(bool bRecursive) const
  1170. {
  1171. Self* var = new Self(*this);
  1172. for (Vars::const_iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  1173. {
  1174. var->m_vars.push_back((*it)->Clone(bRecursive));
  1175. }
  1176. return var;
  1177. }
  1178. //////////////////////////////////////////////////////////////////////////
  1179. void CopyValue(IVariable* fromVar)
  1180. {
  1181. assert(fromVar);
  1182. if (fromVar->GetType() != GetType())
  1183. {
  1184. return;
  1185. }
  1186. CVariable<T>::CopyValue(fromVar);
  1187. int numSrc = fromVar->GetNumVariables();
  1188. int numTrg = m_vars.size();
  1189. for (int i = 0; i < numSrc && i < numTrg; i++)
  1190. {
  1191. // Copy Every child variable.
  1192. m_vars[i]->CopyValue(fromVar->GetVariable(i));
  1193. }
  1194. }
  1195. //////////////////////////////////////////////////////////////////////////
  1196. int GetNumVariables() const { return m_vars.size(); }
  1197. IVariable* GetVariable(int index) const
  1198. {
  1199. assert(index >= 0 && index < (int)m_vars.size());
  1200. return m_vars[index];
  1201. }
  1202. void AddVariable(IVariable* var) { m_vars.push_back(var); }
  1203. void DeleteAllVariables() { m_vars.clear(); }
  1204. //////////////////////////////////////////////////////////////////////////
  1205. void Serialize(XmlNodeRef node, bool load)
  1206. {
  1207. CVariable<T>::Serialize(node, load);
  1208. if (load)
  1209. {
  1210. // Loading.
  1211. QString name;
  1212. for (Vars::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  1213. {
  1214. IVariable* var = *it;
  1215. if (var->GetNumVariables())
  1216. {
  1217. XmlNodeRef child = node->findChild(var->GetName().toUtf8().data());
  1218. if (child)
  1219. {
  1220. var->Serialize(child, load);
  1221. }
  1222. }
  1223. else
  1224. {
  1225. var->Serialize(node, load);
  1226. }
  1227. }
  1228. }
  1229. else
  1230. {
  1231. // Saving.
  1232. for (Vars::iterator it = m_vars.begin(); it != m_vars.end(); ++it)
  1233. {
  1234. IVariable* var = *it;
  1235. if (var->GetNumVariables())
  1236. {
  1237. XmlNodeRef child = node->newChild(var->GetName().toUtf8().data());
  1238. var->Serialize(child, load);
  1239. }
  1240. else
  1241. {
  1242. var->Serialize(node, load);
  1243. }
  1244. }
  1245. }
  1246. }
  1247. protected:
  1248. typedef std::vector<IVariablePtr> Vars;
  1249. Vars m_vars;
  1250. };
  1251. //////////////////////////////////////////////////////////////////////////
  1252. //////////////////////////////////////////////////////////////////////////
  1253. //! Selection list shown in combo box, for enumerated variable.
  1254. struct IVarEnumList
  1255. : public CRefCountBase
  1256. {
  1257. //! Get the name of specified value in enumeration, or empty string if out of range.
  1258. virtual QString GetItemName(uint index) = 0;
  1259. };
  1260. typedef _smart_ptr<IVarEnumList> IVarEnumListPtr;
  1261. //////////////////////////////////////////////////////////////////////////
  1262. //////////////////////////////////////////////////////////////////////////
  1263. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING;
  1264. //! Selection list shown in combo box, for enumerated variable.
  1265. template <class T>
  1266. class CVarEnumListBase
  1267. : public IVarEnumList
  1268. {
  1269. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  1270. public:
  1271. CVarEnumListBase(){}
  1272. //////////////////////////////////////////////////////////////////////////
  1273. virtual T NameToValue(const QString& name) = 0;
  1274. //////////////////////////////////////////////////////////////////////////
  1275. virtual QString ValueToName(T const& value) = 0;
  1276. //! Add new item to the selection.
  1277. virtual void AddItem(const QString& name, const T& value) = 0;
  1278. template <class TVal>
  1279. static bool IsValueEqual(const TVal& v1, const TVal& v2)
  1280. {
  1281. return v1 == v2;
  1282. }
  1283. static bool IsValueEqual(const QString& v1, const QString& v2)
  1284. {
  1285. // Case insensitive compare.
  1286. return QString::compare(v1, v2, Qt::CaseInsensitive) == 0;
  1287. }
  1288. protected:
  1289. virtual ~CVarEnumListBase() {};
  1290. friend class _smart_ptr<CVarEnumListBase<T> >;
  1291. };
  1292. //////////////////////////////////////////////////////////////////////////
  1293. //////////////////////////////////////////////////////////////////////////
  1294. //! Selection list shown in combo box, for enumerated variable.
  1295. template <class T>
  1296. class CVarEnumList
  1297. : public CVarEnumListBase<T>
  1298. {
  1299. public:
  1300. using CVarEnumListBase<T>::IsValueEqual;
  1301. CVarEnumList(){}
  1302. struct Item
  1303. {
  1304. QString name;
  1305. T value;
  1306. };
  1307. QString GetItemName(uint index)
  1308. {
  1309. if (index >= m_items.size())
  1310. {
  1311. return QString();
  1312. }
  1313. return m_items[index].name;
  1314. };
  1315. //////////////////////////////////////////////////////////////////////////
  1316. T NameToValue(const QString& name)
  1317. {
  1318. for (int i = 0; i < m_items.size(); i++)
  1319. {
  1320. if (name == m_items[i].name)
  1321. {
  1322. return m_items[i].value;
  1323. }
  1324. }
  1325. return T();
  1326. }
  1327. //////////////////////////////////////////////////////////////////////////
  1328. QString ValueToName(T const& value)
  1329. {
  1330. for (int i = 0; i < m_items.size(); i++)
  1331. {
  1332. if (CVarEnumListBase<T>::IsValueEqual(value, m_items[i].value))
  1333. {
  1334. return m_items[i].name;
  1335. }
  1336. }
  1337. return "";
  1338. }
  1339. //! Add new item to the selection.
  1340. void AddItem(const QString& name, const T& value)
  1341. {
  1342. Item item;
  1343. item.name = name;
  1344. item.value = value;
  1345. m_items.push_back(item);
  1346. };
  1347. protected:
  1348. ~CVarEnumList() {};
  1349. private:
  1350. std::vector<Item> m_items;
  1351. };
  1352. //////////////////////////////////////////////////////////////////////////////////
  1353. // CVariableEnum is the same as CVariable but it display enumerated values in UI
  1354. //////////////////////////////////////////////////////////////////////////////////
  1355. template <class T>
  1356. class CVariableEnum
  1357. : public CVariable<T>
  1358. {
  1359. public:
  1360. using CVariable<T>::SetValue;
  1361. using CVariable<T>::GetFlags;
  1362. using CVariable<T>::OnSetValue;
  1363. using CVariable<T>::Set;
  1364. using CVariable<T>::m_valueDef;
  1365. using CVariable<T>::m_onSetEnumFuncs;
  1366. //////////////////////////////////////////////////////////////////////////
  1367. CVariableEnum(){}
  1368. //! Assign operator for variable.
  1369. void operator=(const T& value) { CVariable<T>::SetValue(value); }
  1370. //! Add new item to the enumeration.
  1371. void AddEnumItem(const char* name, const T& value)
  1372. {
  1373. AddEnumItem(QString(name), value);
  1374. };
  1375. //! Add new item to the enumeration.
  1376. void AddEnumItem(const QString& name, const T& value)
  1377. {
  1378. if (GetFlags() & IVariable::UI_USE_GLOBAL_ENUMS) // don't think adding makes sense
  1379. {
  1380. return;
  1381. }
  1382. if (!m_enum)
  1383. {
  1384. m_enum = new CVarEnumList<T>();
  1385. }
  1386. m_enum->AddItem(name, value);
  1387. OnEnumsChanged();
  1388. };
  1389. void SetEnumList(CVarEnumListBase<T>* enumList)
  1390. {
  1391. m_enum = enumList;
  1392. OnSetValue(false);
  1393. OnEnumsChanged();
  1394. }
  1395. IVarEnumList* GetEnumList() const
  1396. {
  1397. return m_enum;
  1398. }
  1399. //////////////////////////////////////////////////////////////////////////
  1400. IVariable* Clone([[maybe_unused]] bool bRecursive) const
  1401. {
  1402. CVariableEnum<T>* var = new CVariableEnum<T>(*this);
  1403. return var;
  1404. }
  1405. virtual QString GetDisplayValue() const
  1406. {
  1407. if (m_enum)
  1408. {
  1409. return m_enum->ValueToName(m_valueDef);
  1410. }
  1411. else
  1412. {
  1413. return CVariable<T>::GetDisplayValue();
  1414. }
  1415. }
  1416. virtual void SetDisplayValue(const QString& value)
  1417. {
  1418. if (m_enum)
  1419. {
  1420. Set(m_enum->NameToValue(value));
  1421. }
  1422. else
  1423. {
  1424. Set(value);
  1425. }
  1426. }
  1427. protected:
  1428. void OnEnumsChanged()
  1429. {
  1430. // Call on set callback.
  1431. for (auto it = m_onSetEnumFuncs.begin(); it != m_onSetEnumFuncs.end(); ++it)
  1432. {
  1433. // Call on set callback.
  1434. (*it)->operator()(this);
  1435. }
  1436. }
  1437. // Copy Constructor.
  1438. CVariableEnum(const CVariableEnum<T>& var)
  1439. : CVariable<T>(var)
  1440. {
  1441. m_enum = var.m_enum;
  1442. }
  1443. private:
  1444. _smart_ptr<CVarEnumListBase<T> > m_enum;
  1445. };
  1446. //////////////////////////////////////////////////////////////////////////
  1447. // Smart pointers to variables.
  1448. //////////////////////////////////////////////////////////////////////////
  1449. //////////////////////////////////////////////////////////////////////////
  1450. template <class T, class TVar>
  1451. struct CSmartVariableBase
  1452. {
  1453. typedef TVar VarType;
  1454. CSmartVariableBase() { pVar = new VarType(); }
  1455. operator T const& () const {
  1456. VarType* pV = pVar;
  1457. return *pV;
  1458. }
  1459. //void operator=( const T& value ) { VarType *pV = pVar; *pV = value; }
  1460. // Compare with pointer to variable.
  1461. bool operator==(IVariable* pV) { return pVar == pV; }
  1462. bool operator!=(IVariable* pV) { return pVar != pV; }
  1463. operator VarType&() {
  1464. VarType* pV = pVar;
  1465. return *pV;
  1466. } // Cast to CVariableBase&
  1467. VarType& operator*() const { return *pVar; }
  1468. VarType* operator->() const { return pVar; }
  1469. VarType* GetVar() const { return pVar; };
  1470. protected:
  1471. _smart_ptr<VarType> pVar;
  1472. };
  1473. //////////////////////////////////////////////////////////////////////////
  1474. template <class T>
  1475. struct CSmartVariable
  1476. : public CSmartVariableBase<T, CVariable<T> >
  1477. {
  1478. using CSmartVariableBase<T, CVariable<T> >::pVar;
  1479. void operator=(const T& value) { CVariable<T>* pV = pVar; *pV = value; }
  1480. };
  1481. //////////////////////////////////////////////////////////////////////////
  1482. template <class T>
  1483. struct CSmartVariableArrayT
  1484. : public CSmartVariableBase<T, TVariableArray<T> >
  1485. {
  1486. using CSmartVariableBase<T, TVariableArray<T> >::pVar;
  1487. void operator=(const T& value) { TVariableArray<T>* pV = pVar; *pV = value; }
  1488. };
  1489. //////////////////////////////////////////////////////////////////////////
  1490. template <class T>
  1491. struct CSmartVariableEnum
  1492. : public CSmartVariableBase<T, CVariableEnum<T> >
  1493. {
  1494. using CSmartVariableBase<T, CVariableEnum<T> >::pVar;
  1495. CSmartVariableEnum(){}
  1496. void operator=(const T& value) { CVariableEnum<T>* pV = pVar; *pV = value; }
  1497. void AddEnumItem(const QString& name, const T& value)
  1498. {
  1499. pVar->AddEnumItem(name, value);
  1500. };
  1501. void SetEnumList(CVarEnumListBase<T>* enumList)
  1502. {
  1503. pVar->EnableUpdateCallbacks(false);
  1504. pVar->SetEnumList(enumList);
  1505. pVar->EnableUpdateCallbacks(true);
  1506. }
  1507. };
  1508. //////////////////////////////////////////////////////////////////////////
  1509. struct CSmartVariableArray
  1510. {
  1511. typedef CVariableArray VarType;
  1512. CSmartVariableArray() { pVar = new VarType(); }
  1513. //////////////////////////////////////////////////////////////////////////
  1514. // Access operators.
  1515. //////////////////////////////////////////////////////////////////////////
  1516. operator VarType&() {
  1517. VarType* pV = pVar;
  1518. return *pV;
  1519. }
  1520. VarType& operator*() const { return *pVar; }
  1521. VarType* operator->() const { return pVar; }
  1522. VarType* GetVar() const { return pVar; };
  1523. private:
  1524. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1525. _smart_ptr<VarType> pVar;
  1526. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1527. };
  1528. //////////////////////////////////////////////////////////////////////////
  1529. //////////////////////////////////////////////////////////////////////////
  1530. AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  1531. class EDITOR_CORE_API CVarBlock
  1532. : public IVariableContainer
  1533. {
  1534. AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
  1535. public:
  1536. // Dtor.
  1537. virtual ~CVarBlock() {}
  1538. //! Add variable to block.
  1539. void AddVariable(IVariable* var) override;
  1540. //! Remove variable from block
  1541. bool DeleteVariable(IVariable* var, bool bRecursive = false) override;
  1542. void AddVariable(IVariable* pVar, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE);
  1543. // This used from smart variable pointer.
  1544. void AddVariable(CVariableBase& var, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE);
  1545. //! Returns number of variables in block.
  1546. int GetNumVariables() const override { return static_cast<int>(m_vars.size()); }
  1547. //! Get pointer to stored variable by index.
  1548. IVariable* GetVariable(int index) const override
  1549. {
  1550. assert(index >= 0 && index < m_vars.size());
  1551. return m_vars[index];
  1552. }
  1553. // Clear all vars from VarBlock.
  1554. void DeleteAllVariables() override { m_vars.clear(); };
  1555. //! Return true if variable block is empty (Does not have any vars).
  1556. bool IsEmpty() const override { return m_vars.empty(); }
  1557. // Returns true if var block contains specified variable.
  1558. bool IsContainsVariable(IVariable* pVar, bool bRecursive = true) const override;
  1559. //! Find variable by name.
  1560. IVariable* FindVariable(const char* name, bool bRecursive = true, bool bHumanName = false) const override;
  1561. //////////////////////////////////////////////////////////////////////////
  1562. //! Clone var block.
  1563. CVarBlock* Clone(bool bRecursive) const;
  1564. //////////////////////////////////////////////////////////////////////////
  1565. //! Copy variable values from specified var block.
  1566. //! Do not create new variables, only copy values of existing ones.
  1567. //! Should only be used to copy identical var blocks (eg. not Array type var copied to String type var)
  1568. //! @param fromVarBlock Source variable block that contain copied values, must be identical to this var block.
  1569. void CopyValues(const CVarBlock* fromVarBlock);
  1570. //////////////////////////////////////////////////////////////////////////
  1571. //! Copy variable values from specified var block.
  1572. //! Do not create new variables, only copy values of existing ones.
  1573. //! Can be used to copy slightly different var blocks, matching performed by variable name.
  1574. //! @param fromVarBlock Source variable block that contain copied values.
  1575. void CopyValuesByName(CVarBlock* fromVarBlock);
  1576. void OnSetValues();
  1577. //////////////////////////////////////////////////////////////////////////
  1578. //! Set UI_CREATE_SPLINE flags for all the varialbes in this Var Block.
  1579. //! This is because when the data was changed for a spline variable, the spline need to be recreated to reflect the change.
  1580. //! Set the flag to notify the spline variable.
  1581. void SetRecreateSplines();
  1582. //////////////////////////////////////////////////////////////////////////
  1583. // Wire/Unwire other variable blocks.
  1584. //////////////////////////////////////////////////////////////////////////
  1585. //! Wire to other variable block.
  1586. //! Only equivalent VarBlocks can be wired (same number of variables with same type).
  1587. //! Recursive wiring of array variables is supported.
  1588. void Wire(CVarBlock* toVarBlock);
  1589. //! Unwire var block.
  1590. void Unwire(CVarBlock* varBlock);
  1591. //! Add this callback to every variable in block (recursively).
  1592. void AddOnSetCallback(IVariable::OnSetCallback* func);
  1593. //! Remove this callback from every variable in block (recursively).
  1594. void RemoveOnSetCallback(IVariable::OnSetCallback* func);
  1595. //////////////////////////////////////////////////////////////////////////
  1596. void Serialize(XmlNodeRef vbNode, bool load);
  1597. void ReserveNumVariables(int numVars);
  1598. //////////////////////////////////////////////////////////////////////////
  1599. //! Gather resources in this variable block.
  1600. virtual void GatherUsedResources(CUsedResources& resources);
  1601. void EnableUpdateCallbacks(bool boEnable);
  1602. IVariable* FindChildVar(const char* name, IVariable* pParentVar) const;
  1603. void Sort();
  1604. protected:
  1605. void SetCallbackToVar(IVariable::OnSetCallback* func, IVariable* pVar, bool bAdd);
  1606. void WireVar(IVariable* src, IVariable* trg, bool bWire);
  1607. void GatherUsedResourcesInVar(IVariable* pVar, CUsedResources& resources);
  1608. typedef std::vector<IVariablePtr> Variables;
  1609. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1610. Variables m_vars;
  1611. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1612. };
  1613. typedef _smart_ptr<CVarBlock> CVarBlockPtr;
  1614. //////////////////////////////////////////////////////////////////////////
  1615. class EDITOR_CORE_API CVarObject
  1616. : public QObject
  1617. , public CRefCountBase
  1618. {
  1619. public:
  1620. typedef IVariable::OnSetCallback VarOnSetCallback;
  1621. CVarObject();
  1622. ~CVarObject();
  1623. void Serialize(XmlNodeRef node, bool load);
  1624. CVarBlock* GetVarBlock() const { return m_vars; };
  1625. void AddVariable(CVariableBase& var, const QString& varName, VarOnSetCallback* cb = nullptr, unsigned char dataType = IVariable::DT_SIMPLE);
  1626. void AddVariable(CVariableBase& var, const QString& varName, const QString& varHumanName, VarOnSetCallback* cb = nullptr, unsigned char dataType = IVariable::DT_SIMPLE);
  1627. void AddVariable(CVariableArray& table, CVariableBase& var, const QString& varName, const QString& varHumanName, VarOnSetCallback* cb = nullptr, unsigned char dataType = IVariable::DT_SIMPLE);
  1628. void ReserveNumVariables(int numVars);
  1629. void RemoveVariable(IVariable* var);
  1630. void EnableUpdateCallbacks(bool boEnable);
  1631. void OnSetValues();
  1632. protected:
  1633. //! Copy values of variables from other VarObject.
  1634. //! Source object must be of same type.
  1635. void CopyVariableValues(CVarObject* sourceObject);
  1636. private:
  1637. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1638. CVarBlockPtr m_vars;
  1639. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  1640. };
  1641. Q_DECLARE_METATYPE(IVariable *);
  1642. #endif // CRYINCLUDE_EDITOR_UTIL_VARIABLE_H