UiAVSequenceProps.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "UiAVSequenceProps.h"
  9. #include <LyShine/Animation/IUiAnimation.h>
  10. #include "UiEditorAnimationBus.h"
  11. #include "UiAnimViewUndo.h"
  12. #include "UiAnimViewSequence.h"
  13. #include "Animation/AnimationContext.h"
  14. #include "Objects/BaseObject.h"
  15. #include "QtUtilWin.h"
  16. #include <Editor/Animation/ui_UiAVSequenceProps.h>
  17. #include <QMessageBox>
  18. CUiAVSequenceProps::CUiAVSequenceProps(CUiAnimViewSequence* pSequence, float fps, QWidget* pParent)
  19. : QDialog(pParent)
  20. , m_FPS(fps)
  21. , m_outOfRange(0)
  22. , m_timeUnit(0)
  23. , ui(new Ui::CUiAVSequenceProps)
  24. {
  25. ui->setupUi(this);
  26. assert(pSequence);
  27. m_pSequence = pSequence;
  28. connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &CUiAVSequenceProps::OnOK);
  29. connect(ui->TU_SECONDS, &QRadioButton::toggled, this, &CUiAVSequenceProps::OnBnClickedTuSeconds);
  30. connect(ui->TU_FRAMES, &QRadioButton::toggled, this, &CUiAVSequenceProps::OnBnClickedTuFrames);
  31. OnInitDialog();
  32. }
  33. CUiAVSequenceProps::~CUiAVSequenceProps()
  34. {
  35. }
  36. // CUiAVSequenceProps message handlers
  37. bool CUiAVSequenceProps::OnInitDialog()
  38. {
  39. QString name = QString::fromUtf8(m_pSequence->GetName().c_str());
  40. ui->NAME->setText(name);
  41. ui->MOVE_SCALE_KEYS->setChecked(false);
  42. ui->START_TIME->setRange(0.0, (1e+5));
  43. ui->END_TIME->setRange(0.0, (1e+5));
  44. Range timeRange = m_pSequence->GetTimeRange();
  45. m_timeUnit = 0;
  46. ui->START_TIME->setValue(timeRange.start);
  47. ui->END_TIME->setValue(timeRange.end);
  48. m_outOfRange = 0;
  49. if (m_pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_OutOfRangeConstant)
  50. {
  51. m_outOfRange = 1;
  52. ui->ORT_CONSTANT->setChecked(true);
  53. }
  54. else if (m_pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_OutOfRangeLoop)
  55. {
  56. m_outOfRange = 2;
  57. ui->ORT_LOOP->setChecked(true);
  58. }
  59. else
  60. {
  61. ui->ORT_ONCE->setChecked(true);
  62. }
  63. return true; // return TRUE unless you set the focus to a control
  64. // EXCEPTION: OCX Property Pages should return FALSE
  65. }
  66. void CUiAVSequenceProps::MoveScaleKeys()
  67. {
  68. // Move/Rescale the sequence to a new time range.
  69. Range timeRangeOld = m_pSequence->GetTimeRange();
  70. Range timeRangeNew;
  71. timeRangeNew.start = aznumeric_cast<float>(ui->START_TIME->value());
  72. timeRangeNew.end = aznumeric_cast<float>(ui->END_TIME->value());
  73. if (!(timeRangeNew == timeRangeOld))
  74. {
  75. m_pSequence->AdjustKeysToTimeRange(timeRangeNew);
  76. }
  77. }
  78. void CUiAVSequenceProps::OnOK()
  79. {
  80. QString name = ui->NAME->text();
  81. if (name.isEmpty())
  82. {
  83. QMessageBox::warning(this, "Sequence Properties", "A sequence name cannot be empty!");
  84. return;
  85. }
  86. else if (name.contains('/'))
  87. {
  88. QMessageBox::warning(this, "Sequence Properties", "A sequence name cannot contain a '/' character!");
  89. return;
  90. }
  91. UiAnimUndo undo("Change Animation Sequence Settings");
  92. UiAnimUndo::Record(new CUndoSequenceSettings(m_pSequence));
  93. if (ui->MOVE_SCALE_KEYS->isChecked())
  94. {
  95. MoveScaleKeys();
  96. }
  97. Range timeRange;
  98. timeRange.start = aznumeric_cast<float>(ui->START_TIME->value());
  99. timeRange.end = aznumeric_cast<float>(ui->END_TIME->value());
  100. if (m_timeUnit == 1)
  101. {
  102. float invFPS = 1.0f / m_FPS;
  103. timeRange.start = aznumeric_cast<float>(ui->START_TIME->value() * invFPS);
  104. timeRange.end = aznumeric_cast<float>(ui->END_TIME->value() * invFPS);
  105. }
  106. m_pSequence->SetTimeRange(timeRange);
  107. CUiAnimationContext* ac = nullptr;
  108. UiEditorAnimationBus::BroadcastResult(ac, &UiEditorAnimationBus::Events::GetAnimationContext);
  109. if (ac)
  110. {
  111. ac->UpdateTimeRange();
  112. }
  113. QString seqName = QString::fromUtf8(m_pSequence->GetName().c_str());
  114. if (name != seqName)
  115. {
  116. // Rename sequence.
  117. m_pSequence->SetName(name.toUtf8().data());
  118. }
  119. int seqFlags = m_pSequence->GetFlags();
  120. seqFlags &= ~(IUiAnimSequence::eSeqFlags_OutOfRangeConstant | IUiAnimSequence::eSeqFlags_OutOfRangeLoop);
  121. if (ui->ORT_CONSTANT->isChecked())
  122. {
  123. seqFlags |= IUiAnimSequence::eSeqFlags_OutOfRangeConstant;
  124. }
  125. else if (ui->ORT_LOOP->isChecked())
  126. {
  127. seqFlags |= IUiAnimSequence::eSeqFlags_OutOfRangeLoop;
  128. }
  129. m_pSequence->SetFlags((IUiAnimSequence::EUiAnimSequenceFlags)seqFlags);
  130. accept();
  131. }
  132. void CUiAVSequenceProps::OnBnClickedTuFrames(bool v)
  133. {
  134. if (!v)
  135. {
  136. return;
  137. }
  138. ui->START_TIME->setSingleStep(1.0f);
  139. ui->END_TIME->setSingleStep(1.0f);
  140. ui->START_TIME->setValue(double(int(ui->START_TIME->value() * m_FPS)));
  141. ui->END_TIME->setValue(double(int(ui->END_TIME->value() * m_FPS)));
  142. m_timeUnit = 1;
  143. }
  144. void CUiAVSequenceProps::OnBnClickedTuSeconds(bool v)
  145. {
  146. if (!v)
  147. {
  148. return;
  149. }
  150. ui->START_TIME->setSingleStep(0.01f);
  151. ui->END_TIME->setSingleStep(0.01f);
  152. float fInvFPS = 1.0f / m_FPS;
  153. ui->START_TIME->setValue(ui->START_TIME->value() * fInvFPS);
  154. ui->END_TIME->setValue(ui->END_TIME->value() * fInvFPS);
  155. m_timeUnit = 0;
  156. }
  157. #include <Animation/moc_UiAVSequenceProps.cpp>