AnimMixingPage.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // AnimMixingPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "W3dViewDoc.h"
  23. #include "AdvancedAnimSheet.h"
  24. #include "AnimMixingPage.h"
  25. #include "RendObj.h"
  26. #include "HTree.h"
  27. #include "HAnim.h"
  28. #include "Utils.h"
  29. #include "AssetMgr.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CAnimMixingPage property page
  37. IMPLEMENT_DYNCREATE(CAnimMixingPage, CPropertyPage)
  38. CAnimMixingPage::CAnimMixingPage(CAdvancedAnimSheet *sheet)
  39. : CPropertyPage(CAnimMixingPage::IDD),
  40. m_Sheet(sheet)
  41. {
  42. //{{AFX_DATA_INIT(CAnimMixingPage)
  43. // NOTE: the ClassWizard will add member initialization here
  44. //}}AFX_DATA_INIT
  45. }
  46. CAnimMixingPage::~CAnimMixingPage()
  47. {
  48. }
  49. void CAnimMixingPage::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CPropertyPage::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CAnimMixingPage)
  53. DDX_Control(pDX, IDC_ANIMATION_LIST, m_AnimList);
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(CAnimMixingPage, CPropertyPage)
  57. //{{AFX_MSG_MAP(CAnimMixingPage)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CAnimMixingPage message handlers
  62. BOOL CAnimMixingPage::OnInitDialog()
  63. {
  64. CPropertyPage::OnInitDialog();
  65. ASSERT(m_Sheet != NULL);
  66. FillListCtrl();
  67. return TRUE; // return TRUE unless you set the focus to a control
  68. // EXCEPTION: OCX Property Pages should return FALSE
  69. }
  70. void CAnimMixingPage::FillListCtrl (void)
  71. {
  72. // Get the current render object and it's HTree. If it doesn't have
  73. // an HTree, then it's not animating and we're not interested.
  74. RenderObjClass *robj = ::GetCurrentDocument()->GetDisplayedObject();
  75. if (robj == NULL)
  76. return;
  77. const HTreeClass *htree = robj->Get_HTree();
  78. if (htree == NULL)
  79. return;
  80. // Get a sorted array of animations that affect the currently active object.
  81. HAnimClass **anim = m_Sheet->GetAnims();
  82. int anim_count = m_Sheet->GetAnimCount();
  83. // Add an item to the list view for each animation.
  84. int i;
  85. for (i = 0; i < anim_count; i++)
  86. m_AnimList.InsertItem(i, anim[i]->Get_Name());
  87. }
  88. void CAnimMixingPage::OnOK()
  89. {
  90. /*
  91. ** Create a new HAnimCombo class containing the animations selected by the user.
  92. */
  93. int num_selected = m_AnimList.GetSelectedCount();
  94. RenderObjClass *current_obj = ::GetCurrentDocument()->GetDisplayedObject();
  95. const char *obj_name = current_obj->Get_Name();
  96. RenderObjClass *robj = WW3DAssetManager::Get_Instance()->Create_Render_Obj(obj_name);
  97. if (num_selected > 0 && robj != NULL)
  98. {
  99. HAnimClass **anim = m_Sheet->GetAnims();
  100. HAnimComboClass *combo = new HAnimComboClass(num_selected);
  101. ASSERT(combo != NULL);
  102. POSITION pos = m_AnimList.GetFirstSelectedItemPosition();
  103. int array_idx, idx = 0;
  104. while (pos)
  105. {
  106. array_idx = m_AnimList.GetNextSelectedItem(pos);
  107. combo->Set_Motion(idx, anim[array_idx]);
  108. combo->Set_Weight(idx, 1.0f);
  109. combo->Peek_Anim_Combo_Data(idx)->Build_Active_Pivot_Map();
  110. idx++;
  111. }
  112. /*
  113. ** Set this new combo to be used by the doc.
  114. */
  115. ::GetCurrentDocument()->PlayAnimation(robj, combo);
  116. robj->Release_Ref();
  117. }
  118. CPropertyPage::OnOK();
  119. }
  120. BOOL CAnimMixingPage::OnKillActive()
  121. {
  122. /*
  123. ** Update the parent with info on the current selection.
  124. */
  125. m_Sheet->m_SelectedAnims.Clear();
  126. m_Sheet->m_SelectedAnims.Resize(m_AnimList.GetSelectedCount());
  127. int selected_idx, i=0;
  128. POSITION pos = m_AnimList.GetFirstSelectedItemPosition();
  129. while (pos)
  130. {
  131. selected_idx = m_AnimList.GetNextSelectedItem(pos);
  132. if (!m_Sheet->m_SelectedAnims.Add(selected_idx))
  133. {
  134. char buf[128];
  135. sprintf(buf, "Failed to insert item %d! Talk to Andre if "\
  136. "you see this message.", i);
  137. MessageBox(buf);
  138. }
  139. i++;
  140. }
  141. return CPropertyPage::OnKillActive();
  142. }