DataView.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. // DataView.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "phystest.h"
  22. #include "DataView.h"
  23. #include "PhysTestDoc.h"
  24. #include "assetmgr.h"
  25. #include "rendobj.h"
  26. #include "pscene.h"
  27. #include "phys.h"
  28. #include "physlist.h"
  29. #include "mainfrm.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CDataView
  37. IMPLEMENT_DYNCREATE(CDataView, CTreeView)
  38. CDataView::CDataView() :
  39. ModelsRoot(NULL),
  40. InstancesRoot(NULL)
  41. {
  42. }
  43. CDataView::~CDataView()
  44. {
  45. }
  46. void CDataView::Rebuild_Tree(void)
  47. {
  48. // Turn off repainting
  49. GetTreeCtrl ().SetRedraw (FALSE);
  50. // wipe clean
  51. GetTreeCtrl().DeleteItem(ModelsRoot);
  52. GetTreeCtrl().DeleteItem(InstancesRoot);
  53. ModelsRoot = GetTreeCtrl().InsertItem("Models", NULL, NULL);
  54. InstancesRoot = GetTreeCtrl().InsertItem ("Physics Object Instances", NULL, NULL);
  55. // MODELS
  56. // Get an iterator from the asset manager that we can
  57. // use to enumerate the currently loaded assets
  58. RenderObjIterator * obj_iterator = WW3DAssetManager::Get_Instance()->Create_Render_Obj_Iterator();
  59. ASSERT(obj_iterator);
  60. if (obj_iterator) {
  61. // Loop through all the assets in the manager
  62. for (obj_iterator->First (); !obj_iterator->Is_Done(); obj_iterator->Next()) {
  63. // If the asset is an HLOD, add it to our possible model list
  64. if (obj_iterator->Current_Item_Class_ID() == RenderObjClass::CLASSID_HLOD) {
  65. const char * model_name = obj_iterator->Current_Item_Name();
  66. // Add this entry to the tree
  67. HTREEITEM hItem = GetTreeCtrl().InsertItem(model_name,NULL,0,ModelsRoot,TVI_SORT);
  68. ASSERT (hItem != NULL);
  69. ItemInfoClass * item_info = new ItemInfoClass(model_name,ItemInfoClass::MODEL);
  70. GetTreeCtrl().SetItemData(hItem, (ULONG)item_info);
  71. }
  72. }
  73. // Free the enumerator object we created earlier
  74. WW3DAssetManager::Get_Instance()->Release_Render_Obj_Iterator(obj_iterator);
  75. }
  76. // PHYSICS OBJECT INSTANCES
  77. CPhysTestDoc * doc = (CPhysTestDoc *)GetDocument();
  78. RefPhysListIterator phys_iterator = PhysicsSceneClass::Get_Instance()->Get_Dynamic_Object_Iterator();
  79. for (phys_iterator.First();!phys_iterator.Is_Done();phys_iterator.Next()) {
  80. const char * instance_name = phys_iterator.Peek_Obj()->Get_Name();
  81. if (instance_name != NULL) {
  82. // Add this entry to the tree
  83. HTREEITEM hItem = GetTreeCtrl().InsertItem(instance_name,NULL,0,InstancesRoot,TVI_SORT);
  84. ASSERT (hItem != NULL);
  85. ItemInfoClass * item_info = new ItemInfoClass(instance_name,ItemInfoClass::INSTANCE);
  86. item_info->Instance = phys_iterator.Peek_Obj();
  87. GetTreeCtrl().SetItemData(hItem, (ULONG)item_info);
  88. }
  89. }
  90. // Turn;repainting back on and force a redraw
  91. GetTreeCtrl().SetRedraw (TRUE);
  92. Invalidate(FALSE);
  93. UpdateWindow();
  94. }
  95. ItemInfoClass * CDataView::Get_Selected_Item(void)
  96. {
  97. ItemInfoClass * item_info = NULL;
  98. // Get the currently selected node from the tree control
  99. HTREEITEM htree_item = GetTreeCtrl ().GetSelectedItem ();
  100. if (htree_item != NULL) {
  101. // Get the data associated with this item
  102. item_info = (ItemInfoClass *)GetTreeCtrl().GetItemData(htree_item);
  103. }
  104. // Return the asset information associated with the current item
  105. return item_info;
  106. }
  107. void CDataView::Save(ChunkSaveClass & csave)
  108. {
  109. }
  110. void CDataView::Load(ChunkLoadClass & cload)
  111. {
  112. }
  113. BEGIN_MESSAGE_MAP(CDataView, CTreeView)
  114. //{{AFX_MSG_MAP(CDataView)
  115. ON_WM_CREATE()
  116. ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteitem)
  117. ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
  118. //}}AFX_MSG_MAP
  119. END_MESSAGE_MAP()
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CDataView drawing
  122. void CDataView::OnDraw(CDC* pDC)
  123. {
  124. CDocument* pDoc = GetDocument();
  125. // TODO: add draw code here
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CDataView diagnostics
  129. #ifdef _DEBUG
  130. void CDataView::AssertValid() const
  131. {
  132. CTreeView::AssertValid();
  133. }
  134. void CDataView::Dump(CDumpContext& dc) const
  135. {
  136. CTreeView::Dump(dc);
  137. }
  138. #endif //_DEBUG
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CDataView message handlers
  141. BOOL CDataView::PreCreateWindow(CREATESTRUCT& cs)
  142. {
  143. // Modify the style bits for the window so it will
  144. // have buttons and lines between nodes.
  145. cs.style |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS;
  146. return CTreeView::PreCreateWindow(cs);
  147. }
  148. int CDataView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  149. {
  150. if (CTreeView::OnCreate(lpCreateStruct) == -1)
  151. return -1;
  152. ModelsRoot = GetTreeCtrl().InsertItem("Models", NULL, NULL);
  153. InstancesRoot = GetTreeCtrl().InsertItem ("Physics Object Instances", NULL, NULL);
  154. return 0;
  155. }
  156. void CDataView::OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult)
  157. {
  158. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  159. ItemInfoClass * item_info = (ItemInfoClass *)pNMTreeView->itemOld.lParam;
  160. // Free the asset information object
  161. if (item_info != NULL) {
  162. delete item_info;
  163. }
  164. // Reset the data associated with this entry
  165. GetTreeCtrl().SetItemData(pNMTreeView->itemOld.hItem, NULL);
  166. *pResult = 0;
  167. }
  168. void CDataView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
  169. {
  170. // just tell the main window that the selection changed so it
  171. // can link/unlink the virtual joystick.
  172. ((CMainFrame *)::AfxGetMainWnd())->Notify_Selection_Changed();
  173. *pResult = 0;
  174. }