BackgroundObjectDialog.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. // BackgroundObjectDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "BackgroundObjectDialog.h"
  23. #include "AssetMgr.H"
  24. #include "Utils.H"
  25. #include "W3DViewDoc.H"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////
  32. //
  33. // CBackgroundObjectDialog
  34. //
  35. CBackgroundObjectDialog::CBackgroundObjectDialog (CWnd* pParent /*=NULL*/)
  36. : CDialog(CBackgroundObjectDialog::IDD, pParent)
  37. {
  38. //{{AFX_DATA_INIT(CBackgroundObjectDialog)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. return ;
  42. }
  43. /////////////////////////////////////////////////////////////
  44. //
  45. // DoDataExchange
  46. //
  47. void
  48. CBackgroundObjectDialog::DoDataExchange (CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CBackgroundObjectDialog)
  52. DDX_Control(pDX, IDC_HIERARCHY_LIST, m_heirarchyListCtrl);
  53. //}}AFX_DATA_MAP
  54. return ;
  55. }
  56. BEGIN_MESSAGE_MAP(CBackgroundObjectDialog, CDialog)
  57. //{{AFX_MSG_MAP(CBackgroundObjectDialog)
  58. ON_NOTIFY(LVN_ITEMCHANGED, IDC_HIERARCHY_LIST, OnItemChangedHierarchyList)
  59. ON_BN_CLICKED(IDC_CLEAR, OnClear)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CBackgroundObjectDialog message handlers
  64. /////////////////////////////////////////////////////////////
  65. //
  66. // OnInitDialog
  67. //
  68. BOOL
  69. CBackgroundObjectDialog::OnInitDialog (void)
  70. {
  71. // Allow the base class to process this message
  72. CDialog::OnInitDialog ();
  73. // Center the dialog around the data tree view instead
  74. // of the direct center of the screen
  75. ::CenterDialogAroundTreeView (m_hWnd);
  76. m_heirarchyListCtrl.InsertColumn (0, "Name");
  77. //m_heirarchyListCtrl.InsertColumn (1, "Subobjects");
  78. // Get an iterator from the asset manager that we can
  79. // use to enumerate the currently loaded assets
  80. RenderObjIterator *pObjEnum = WW3DAssetManager::Get_Instance()->Create_Render_Obj_Iterator ();
  81. ASSERT (pObjEnum);
  82. if (pObjEnum)
  83. {
  84. // Loop through all the assets in the manager
  85. for (pObjEnum->First ();
  86. pObjEnum->Is_Done () == FALSE;
  87. pObjEnum->Next ())
  88. {
  89. LPCTSTR pszItemName = pObjEnum->Current_Item_Name ();
  90. // Is this a hierarchy?
  91. if (WW3DAssetManager::Get_Instance()->Render_Obj_Exists (pszItemName) &&
  92. (pObjEnum->Current_Item_Class_ID () == RenderObjClass::CLASSID_HMODEL))
  93. {
  94. // Add this hierarchy to the list
  95. m_heirarchyListCtrl.InsertItem (0, pszItemName);
  96. }
  97. }
  98. // Free the enumerator object we created earlier
  99. delete pObjEnum;
  100. pObjEnum = NULL;
  101. }
  102. // Get a pointer to the doc
  103. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  104. if (pCDoc)
  105. {
  106. // Get the name of the current background object
  107. CString stringCurrObject = pCDoc->GetBackgroundObjectName ();
  108. LV_FINDINFO findInfo = { 0 };
  109. findInfo.flags = LVFI_STRING;
  110. findInfo.psz = (LPCTSTR)stringCurrObject;
  111. // Attempt to find this item in the list control
  112. int iIndex = m_heirarchyListCtrl.FindItem (&findInfo);
  113. if (iIndex != -1)
  114. {
  115. // Select the item in the list control
  116. m_heirarchyListCtrl.SetItemState (iIndex, LVNI_SELECTED, LVNI_SELECTED);
  117. SetDlgItemText (IDC_CURR_OBJ, m_heirarchyListCtrl.GetItemText (iIndex, 0));
  118. }
  119. else
  120. {
  121. // Select the first item in the list control
  122. m_heirarchyListCtrl.SetItemState (0, LVNI_SELECTED, LVNI_SELECTED);
  123. SetDlgItemText (IDC_CURR_OBJ, m_heirarchyListCtrl.GetItemText (0, 0));
  124. }
  125. }
  126. // Size the columns so they are large enough to display their contents
  127. m_heirarchyListCtrl.SetColumnWidth (0, LVSCW_AUTOSIZE);
  128. //m_heirarchyListCtrl.SetColumnWidth (1, LVSCW_AUTOSIZE_USEHEADER);
  129. return TRUE;
  130. }
  131. /////////////////////////////////////////////////////////////
  132. //
  133. // OnInitDialog
  134. //
  135. void
  136. CBackgroundObjectDialog::OnOK (void)
  137. {
  138. // Get a pointer to the doc
  139. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  140. if (pCDoc)
  141. {
  142. // Get the index of the currently selected item.
  143. int iIndex = m_heirarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  144. if (iIndex != -1)
  145. {
  146. // Get the name of the item from the list control
  147. CString stringItemName = m_heirarchyListCtrl.GetItemText (iIndex, 0);
  148. // Ask the doc to load the background object and display it
  149. pCDoc->SetBackgroundObject (stringItemName);
  150. }
  151. else
  152. {
  153. // Ask the doc to clear the background object
  154. pCDoc->SetBackgroundObject (NULL);
  155. }
  156. // Allow the base class to process this message
  157. CDialog::OnOK ();
  158. }
  159. return ;
  160. }
  161. /////////////////////////////////////////////////////////////
  162. //
  163. // OnItemChangedHierarchyList
  164. //
  165. void
  166. CBackgroundObjectDialog::OnItemChangedHierarchyList
  167. (
  168. NMHDR* pNMHDR,
  169. LRESULT* pResult
  170. )
  171. {
  172. // Did the 'state' of the entry change?
  173. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  174. if (pNMListView &&
  175. (pNMListView->uChanged & LVIF_STATE) == LVIF_STATE)
  176. {
  177. // Is the new state a selected state?
  178. if ((pNMListView->uNewState & LVIS_SELECTED) != LVIS_SELECTED)
  179. {
  180. // Is there a selected item in the list control?
  181. if (m_heirarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) == -1)
  182. {
  183. // Clear the text of the current object static text control
  184. SetDlgItemText (IDC_CURR_OBJ, "");
  185. }
  186. }
  187. else
  188. {
  189. // Set the text of the current object static text control
  190. SetDlgItemText (IDC_CURR_OBJ, m_heirarchyListCtrl.GetItemText (pNMListView->iItem, 0));
  191. }
  192. }
  193. *pResult = 0;
  194. return ;
  195. }
  196. /////////////////////////////////////////////////////////////
  197. //
  198. // OnClear
  199. //
  200. void
  201. CBackgroundObjectDialog::OnClear (void)
  202. {
  203. // Get the current selection (if any)
  204. int iIndex = m_heirarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  205. if (iIndex != -1)
  206. {
  207. // Clear the selection state from this entry
  208. m_heirarchyListCtrl.SetItemState (iIndex, 0, LVIS_SELECTED);
  209. }
  210. return ;
  211. }