TrackViewKeyPropertiesDlg.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_TRACKVIEW_TRACKVIEWKEYPROPERTIESDLG_H
  9. #define CRYINCLUDE_EDITOR_TRACKVIEW_TRACKVIEWKEYPROPERTIESDLG_H
  10. #pragma once
  11. #if !defined(Q_MOC_RUN)
  12. #include "TrackViewSequence.h"
  13. #include "TrackViewNode.h"
  14. #include "TrackViewDopeSheetBase.h"
  15. #include <QScopedPointer>
  16. #include <QDockWidget>
  17. #include "Util/Variable.h"
  18. #endif
  19. namespace Ui {
  20. class CTrackViewTrackPropsDlg;
  21. class CTrackViewKeyPropertiesDlg;
  22. }
  23. class ReflectedPropertyControl;
  24. class CTrackViewKeyPropertiesDlg;
  25. //////////////////////////////////////////////////////////////////////////
  26. class CTrackViewKeyUIControls
  27. : public QObject
  28. , public _i_reference_target_t
  29. {
  30. Q_OBJECT
  31. public:
  32. CTrackViewKeyUIControls()
  33. {
  34. m_pVarBlock = new CVarBlock;
  35. m_onSetCallback = AZStd::bind(&CTrackViewKeyUIControls::OnInternalVariableChange, this, AZStd::placeholders::_1);
  36. };
  37. void SetKeyPropertiesDlg(CTrackViewKeyPropertiesDlg* pDlg) { m_pKeyPropertiesDlg = pDlg; }
  38. // Return internal variable block.
  39. CVarBlock* GetVarBlock() const { return m_pVarBlock; }
  40. //////////////////////////////////////////////////////////////////////////
  41. // Callbacks that must be implemented in derived class
  42. //////////////////////////////////////////////////////////////////////////
  43. // Returns true if specified animation track type is supported by this UI.
  44. virtual bool SupportTrackType(const CAnimParamType& paramType, EAnimCurveType trackType, AnimValueType valueType) const = 0;
  45. // Called when UI variable changes.
  46. virtual void OnCreateVars() = 0;
  47. // Called when user changes selected keys.
  48. // Return true if control update UI values
  49. virtual bool OnKeySelectionChange(const CTrackViewKeyBundle& keys) = 0;
  50. // Called when UI variable changes.
  51. virtual void OnUIChange(IVariable* pVar, CTrackViewKeyBundle& keys) = 0;
  52. // Get priority of key UI control, so that specializations can have precedence
  53. virtual unsigned int GetPriority() const = 0;
  54. protected:
  55. //////////////////////////////////////////////////////////////////////////
  56. // Helper functions.
  57. //////////////////////////////////////////////////////////////////////////
  58. template <class T>
  59. void SyncValue(CSmartVariable<T>& var, T& value, bool bCopyToUI, IVariable* pSrcVar = nullptr)
  60. {
  61. if (bCopyToUI)
  62. {
  63. var = value;
  64. }
  65. else
  66. {
  67. if (!pSrcVar || pSrcVar == var.GetVar())
  68. {
  69. value = var;
  70. }
  71. }
  72. }
  73. void AddVariable(CVariableBase& varArray, CVariableBase& var, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE)
  74. {
  75. if (varName)
  76. {
  77. var.SetName(varName);
  78. }
  79. var.SetDataType(dataType);
  80. var.AddOnSetCallback(&m_onSetCallback);
  81. varArray.AddVariable(&var);
  82. m_registeredVariables.push_back(&var);
  83. }
  84. //////////////////////////////////////////////////////////////////////////
  85. void AddVariable(CVariableBase& var, const char* varName, unsigned char dataType = IVariable::DT_SIMPLE)
  86. {
  87. if (varName)
  88. {
  89. var.SetName(varName);
  90. }
  91. var.SetDataType(dataType);
  92. var.AddOnSetCallback(&m_onSetCallback);
  93. m_pVarBlock->AddVariable(&var);
  94. m_registeredVariables.push_back(&var);
  95. }
  96. void OnInternalVariableChange(IVariable* pVar);
  97. protected:
  98. _smart_ptr<CVarBlock> m_pVarBlock;
  99. std::vector<_smart_ptr<IVariable> > m_registeredVariables;
  100. CTrackViewKeyPropertiesDlg* m_pKeyPropertiesDlg;
  101. IVariable::OnSetCallback m_onSetCallback;
  102. };
  103. //////////////////////////////////////////////////////////////////////////
  104. class CTrackViewTrackPropsDlg
  105. : public QWidget
  106. {
  107. Q_OBJECT
  108. public:
  109. CTrackViewTrackPropsDlg(QWidget* parent = 0);
  110. ~CTrackViewTrackPropsDlg();
  111. void OnSequenceChanged();
  112. bool OnKeySelectionChange(const CTrackViewKeyBundle& keys);
  113. protected slots:
  114. void OnUpdateTime();
  115. protected:
  116. CTrackViewKeyHandle m_keyHandle;
  117. QScopedPointer<Ui::CTrackViewTrackPropsDlg> ui;
  118. };
  119. //////////////////////////////////////////////////////////////////////////
  120. class TrackViewKeys;
  121. class CTrackViewKeyPropertiesDlg
  122. : public QWidget
  123. , public ITrackViewSequenceListener
  124. {
  125. public:
  126. CTrackViewKeyPropertiesDlg(QWidget* hParentWnd);
  127. void SetKeysCtrl(CTrackViewDopeSheetBase* pKeysCtrl)
  128. {
  129. m_keysCtrl = pKeysCtrl;
  130. if (m_keysCtrl)
  131. {
  132. m_keysCtrl->SetKeyPropertiesDlg(this);
  133. }
  134. }
  135. void OnSequenceChanged(CTrackViewSequence* sequence);
  136. void PopulateVariables();
  137. void PopulateVariables(ReflectedPropertyControl* propCtrl);
  138. // ITrackViewSequenceListener
  139. void OnKeysChanged(CTrackViewSequence* pSequence) override;
  140. void OnKeySelectionChanged(CTrackViewSequence* pSequence) override;
  141. protected:
  142. //////////////////////////////////////////////////////////////////////////
  143. void OnVarChange(IVariable* pVar);
  144. void CreateAllVars();
  145. void AddVars(CTrackViewKeyUIControls* pUI);
  146. void ReloadValues();
  147. protected:
  148. std::vector< _smart_ptr<CTrackViewKeyUIControls> > m_keyControls;
  149. _smart_ptr<CVarBlock> m_pVarBlock;
  150. ReflectedPropertyControl* m_wndProps;
  151. CTrackViewTrackPropsDlg* m_wndTrackProps;
  152. CTrackViewDopeSheetBase* m_keysCtrl;
  153. CTrackViewTrack* m_pLastTrackSelected;
  154. CTrackViewSequence* m_sequence;
  155. };
  156. #endif // CRYINCLUDE_EDITOR_TRACKVIEW_TRACKVIEWKEYPROPERTIESDLG_H