UiAnimViewFindDlg.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "EditorDefs.h"
  9. #include "UiAnimViewFindDlg.h"
  10. #include "UiAnimViewDialog.h"
  11. #include "UiAnimViewSequenceManager.h"
  12. #include <LyShine/Animation/IUiAnimation.h>
  13. #include <QtUtilWin.h>
  14. #include <QListWidgetItem>
  15. #include <Editor/Animation/ui_UiAnimViewFindDlg.h>
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CUiAnimViewFindDlg dialog
  18. CUiAnimViewFindDlg::CUiAnimViewFindDlg(const char* title, QWidget* pParent /*=NULL*/)
  19. : QDialog(pParent)
  20. , ui(new Ui::UiAnimViewFindDlg)
  21. {
  22. setWindowTitle(title);
  23. m_tvDlg = 0;
  24. m_numSeqs = 0;
  25. ui->setupUi(this);
  26. ui->LIST->setSelectionMode(QAbstractItemView::SingleSelection);
  27. connect(ui->OK, &QPushButton::clicked, this, &CUiAnimViewFindDlg::OnOK);
  28. connect(ui->CANCEL, &QPushButton::clicked, this, &CUiAnimViewFindDlg::OnCancel);
  29. connect(ui->FILTER, &QLineEdit::textEdited, this, &CUiAnimViewFindDlg::OnFilterChange);
  30. connect(ui->LIST, &QListWidget::itemDoubleClicked, this, &CUiAnimViewFindDlg::OnItemDoubleClicked);
  31. FillData();
  32. }
  33. CUiAnimViewFindDlg::~CUiAnimViewFindDlg()
  34. {
  35. }
  36. void CUiAnimViewFindDlg::FillData()
  37. {
  38. IUiAnimationSystem* animationSystem = nullptr;
  39. UiEditorAnimationBus::BroadcastResult(animationSystem, &UiEditorAnimationBus::Events::GetAnimationSystem);
  40. m_numSeqs = 0;
  41. m_objs.resize(0);
  42. for (int k = 0; k < animationSystem->GetNumSequences(); ++k)
  43. {
  44. IUiAnimSequence* seq = animationSystem->GetSequence(k);
  45. for (int i = 0; i < seq->GetNodeCount(); i++)
  46. {
  47. IUiAnimNode* pNode = seq->GetNode(i);
  48. ObjName obj;
  49. obj.m_objName = QString::fromUtf8(pNode->GetName().c_str());
  50. obj.m_directorName = pNode->HasDirectorAsParent() ? QString::fromUtf8(pNode->HasDirectorAsParent()->GetName().c_str()) : "";
  51. AZStd::string fullname = seq->GetName();
  52. obj.m_seqName = fullname.c_str();
  53. m_objs.push_back(obj);
  54. }
  55. m_numSeqs++;
  56. }
  57. FillList();
  58. }
  59. void CUiAnimViewFindDlg::Init(CUiAnimViewDialog* tvDlg)
  60. {
  61. m_tvDlg = tvDlg;
  62. }
  63. void CUiAnimViewFindDlg::FillList()
  64. {
  65. QString filter = ui->FILTER->text();
  66. ui->LIST->clear();
  67. for (int i = 0; i < m_objs.size(); i++)
  68. {
  69. ObjName pObj = m_objs[i];
  70. if (filter.isEmpty() || pObj.m_objName.contains(filter, Qt::CaseInsensitive))
  71. {
  72. QString text = pObj.m_objName;
  73. if (!pObj.m_directorName.isEmpty())
  74. {
  75. text += " (";
  76. text += pObj.m_directorName;
  77. text += ")";
  78. }
  79. if (m_numSeqs > 1)
  80. {
  81. text += " / ";
  82. text += pObj.m_seqName;
  83. }
  84. ui->LIST->addItem(text);
  85. }
  86. }
  87. ui->LIST->setCurrentRow(0);
  88. }
  89. void CUiAnimViewFindDlg::OnOK()
  90. {
  91. ProcessSel();
  92. accept();
  93. }
  94. void CUiAnimViewFindDlg::OnCancel()
  95. {
  96. reject();
  97. }
  98. void CUiAnimViewFindDlg::OnFilterChange([[maybe_unused]] const QString& text)
  99. {
  100. FillList();
  101. }
  102. void CUiAnimViewFindDlg::ProcessSel()
  103. {
  104. QList<QListWidgetItem*> selection = ui->LIST->selectedItems();
  105. if (selection.size() != 1)
  106. {
  107. return;
  108. }
  109. int index = ui->LIST->row(selection.first());
  110. if (index >= 0 && m_tvDlg)
  111. {
  112. ObjName object = m_objs[index];
  113. const CUiAnimViewSequenceManager* pSequenceManager = CUiAnimViewSequenceManager::GetSequenceManager();
  114. CUiAnimViewSequence* pSequence = pSequenceManager->GetSequenceByName(object.m_seqName);
  115. if (pSequence)
  116. {
  117. CUiAnimationContext* pAnimationContext = nullptr;
  118. UiEditorAnimationBus::BroadcastResult(pAnimationContext, &UiEditorAnimationBus::Events::GetAnimationContext);
  119. pAnimationContext->SetSequence(pSequence, false, false, true);
  120. CUiAnimViewAnimNode* pParentDirector = pSequence;
  121. CUiAnimViewAnimNodeBundle foundDirectorNodes = pSequence->GetAnimNodesByName(object.m_directorName.toUtf8().data());
  122. if (foundDirectorNodes.GetCount() > 0 && foundDirectorNodes.GetNode(0)->GetType() == eUiAnimNodeType_Director)
  123. {
  124. pParentDirector = foundDirectorNodes.GetNode(0);
  125. }
  126. CUiAnimViewAnimNodeBundle foundNodes = pParentDirector->GetAnimNodesByName(object.m_objName.toUtf8().data());
  127. const uint numNodes = foundNodes.GetCount();
  128. for (uint i = 0; i < numNodes; ++i)
  129. {
  130. foundNodes.GetNode(i)->SetSelected(true);
  131. }
  132. }
  133. }
  134. }
  135. void CUiAnimViewFindDlg::OnItemDoubleClicked()
  136. {
  137. ProcessSel();
  138. }
  139. #include <Animation/moc_UiAnimViewFindDlg.cpp>