EditLODDialog.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. // EditLODDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "W3DView.h"
  22. #include "EditLODDialog.h"
  23. #include "DistLod.H"
  24. #include "Utils.H"
  25. #include "RendObj.H"
  26. #include "W3DViewDoc.H"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////
  33. //
  34. // Local Constants
  35. //
  36. const int COL_NAME = 0;
  37. const int COL_SWITCH_UP = 1;
  38. const int COL_SWITCH_DN = 2;
  39. /////////////////////////////////////////////////////////////
  40. //
  41. // CEditLODDialog
  42. //
  43. CEditLODDialog::CEditLODDialog(CWnd* pParent /*=NULL*/)
  44. : m_spinIncrement (0.5F),
  45. CDialog(CEditLODDialog::IDD, pParent)
  46. {
  47. //{{AFX_DATA_INIT(CEditLODDialog)
  48. //}}AFX_DATA_INIT
  49. return ;
  50. }
  51. /////////////////////////////////////////////////////////////
  52. //
  53. // DoDataExchange
  54. //
  55. void
  56. CEditLODDialog::DoDataExchange (CDataExchange* pDX)
  57. {
  58. // Allow the base class to process this message
  59. CDialog::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CEditLODDialog)
  61. DDX_Control(pDX, IDC_SWITCH_UP_SPIN, m_switchUpSpin);
  62. DDX_Control(pDX, IDC_SWITCH_DN_SPIN, m_switchDownSpin);
  63. DDX_Control(pDX, IDC_HIERARCHY_LIST, m_hierarchyListCtrl);
  64. //}}AFX_DATA_MAP
  65. return ;
  66. }
  67. BEGIN_MESSAGE_MAP(CEditLODDialog, CDialog)
  68. //{{AFX_MSG_MAP(CEditLODDialog)
  69. ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_UP_SPIN, OnDeltaposSwitchUpSpin)
  70. ON_NOTIFY(UDN_DELTAPOS, IDC_SWITCH_DN_SPIN, OnDeltaposSwitchDnSpin)
  71. ON_NOTIFY(LVN_ITEMCHANGED, IDC_HIERARCHY_LIST, OnItemChangedHierarchyList)
  72. ON_EN_UPDATE(IDC_SWITCH_DN_EDIT, OnUpdateSwitchDnEdit)
  73. ON_EN_UPDATE(IDC_SWITCH_UP_EDIT, OnUpdateSwitchUpEdit)
  74. ON_BN_CLICKED(IDC_RECALC, OnRecalc)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////
  78. //
  79. // OnInitDialog
  80. //
  81. BOOL
  82. CEditLODDialog::OnInitDialog (void)
  83. {
  84. // Allow the base class to process this message
  85. CDialog::OnInitDialog ();
  86. // Center the dialog around the data tree view instead
  87. // of the direct center of the screen
  88. ::CenterDialogAroundTreeView (m_hWnd);
  89. // Get a pointer to the doc
  90. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  91. if (pCDoc)
  92. {
  93. // Get the current LOD from the doc
  94. DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
  95. ASSERT (pLOD);
  96. if (pLOD)
  97. {
  98. int iSubObjects = pLOD->Get_Num_Sub_Objects ();
  99. // Add the columns to the list control
  100. m_hierarchyListCtrl.InsertColumn (COL_NAME, "Name");
  101. m_hierarchyListCtrl.InsertColumn (COL_SWITCH_UP, "Switch Up");
  102. m_hierarchyListCtrl.InsertColumn (COL_SWITCH_DN, "Switch Down");
  103. RenderObjClass *pfirst_subobj = pLOD->Get_Sub_Object (0);
  104. if (pfirst_subobj != NULL) {
  105. m_spinIncrement = pfirst_subobj->Get_Bounding_Sphere ().Radius / 5.0F;
  106. MEMBER_RELEASE (pfirst_subobj);
  107. }
  108. // Loop through all the subobjects
  109. for (int iObject = 0;
  110. (iObject < iSubObjects);
  111. iObject ++)
  112. {
  113. // Get this subobject
  114. RenderObjClass *pCSubObject = pLOD->Get_Sub_Object (iObject);
  115. if (pCSubObject)
  116. {
  117. // Add this object to the list
  118. int iIndex = m_hierarchyListCtrl.InsertItem (COL_NAME, pCSubObject->Get_Name ());
  119. CString stringTemp;
  120. stringTemp.Format ("%.2f", pLOD->Get_Switch_Up_Dist (iObject));
  121. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
  122. stringTemp.Format ("%.2f", pLOD->Get_Switch_Down_Dist (iObject));
  123. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
  124. // Free this object
  125. MEMBER_RELEASE (pCSubObject);
  126. }
  127. }
  128. m_switchUpSpin.SetRange (-20, UD_MAXVAL-20);
  129. m_switchDownSpin.SetRange (-20, UD_MAXVAL-20);
  130. // Resize the columns so they are wide enough to display the largest string
  131. m_hierarchyListCtrl.SetColumnWidth (COL_NAME, LVSCW_AUTOSIZE);
  132. m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_UP, LVSCW_AUTOSIZE_USEHEADER);
  133. m_hierarchyListCtrl.SetColumnWidth (COL_SWITCH_DN, LVSCW_AUTOSIZE_USEHEADER);
  134. // Select the first item in the list
  135. m_hierarchyListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
  136. }
  137. }
  138. return TRUE;
  139. }
  140. /////////////////////////////////////////////////////////////
  141. //
  142. // OnOK
  143. //
  144. void
  145. CEditLODDialog::OnOK (void)
  146. {
  147. // Get a pointer to the doc
  148. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  149. if (pCDoc)
  150. {
  151. // Get the current LOD from the doc
  152. DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
  153. ASSERT (pLOD);
  154. if (pLOD)
  155. {
  156. int iSubObjects = pLOD->Get_Num_Sub_Objects ();
  157. // Loop through all the subobjects and add them to the list control
  158. for (int iObject = 0;
  159. (iObject < iSubObjects);
  160. iObject ++)
  161. {
  162. // Get the switch up distance from the list control
  163. CString stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_UP);
  164. // Convert the string to a float and pass this value
  165. // onto the LOD manager
  166. float switchDistance = ::atof (stringTemp);
  167. pLOD->Set_Switch_Up_Dist (iObject, switchDistance);
  168. // Get the switch down distance from the list control
  169. stringTemp = m_hierarchyListCtrl.GetItemText (iObject, COL_SWITCH_DN);
  170. // Convert the string to a float and pass this value
  171. // onto the LOD manager
  172. switchDistance = ::atof (stringTemp);
  173. pLOD->Set_Switch_Down_Dist (iObject, switchDistance);
  174. }
  175. }
  176. }
  177. // Allow the base class to process this message
  178. CDialog::OnOK ();
  179. return ;
  180. }
  181. /////////////////////////////////////////////////////////////
  182. //
  183. // OnCancel
  184. //
  185. void
  186. CEditLODDialog::OnCancel (void)
  187. {
  188. // Allow the base class to process this message
  189. CDialog::OnCancel ();
  190. return ;
  191. }
  192. /////////////////////////////////////////////////////////////
  193. //
  194. // OnDeltaposSwitchUpSpin
  195. //
  196. void
  197. CEditLODDialog::OnDeltaposSwitchUpSpin
  198. (
  199. NMHDR* pNMHDR,
  200. LRESULT* pResult
  201. )
  202. {
  203. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  204. if (pNMUpDown)
  205. {
  206. float newVal = float(pNMUpDown->iPos) / 10.00F;
  207. // Change the switching distance in the edit control
  208. CString stringTemp;
  209. stringTemp.Format ("%.2f", newVal);
  210. SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
  211. // Find the selected item in the list control
  212. int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  213. if (iIndex != -1)
  214. {
  215. // Change the switching distance in the list control
  216. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
  217. }
  218. }
  219. *pResult = 0;
  220. return ;
  221. }
  222. /////////////////////////////////////////////////////////////
  223. //
  224. // OnDeltaposSwitchDnSpin
  225. //
  226. void
  227. CEditLODDialog::OnDeltaposSwitchDnSpin
  228. (
  229. NMHDR* pNMHDR,
  230. LRESULT* pResult
  231. )
  232. {
  233. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  234. if (pNMUpDown)
  235. {
  236. float newVal = float(pNMUpDown->iPos) / 10.00F;
  237. // Change the switching distance in the edit control
  238. CString stringTemp;
  239. stringTemp.Format ("%.2f", newVal);
  240. SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
  241. // Find the selected item in the list control
  242. int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  243. if (iIndex != -1)
  244. {
  245. // Change the switching distance in the list control
  246. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
  247. }
  248. }
  249. *pResult = 0;
  250. return ;
  251. }
  252. /////////////////////////////////////////////////////////////
  253. //
  254. // OnItemChangedHierarchyList
  255. //
  256. void
  257. CEditLODDialog::OnItemChangedHierarchyList
  258. (
  259. NMHDR* pNMHDR,
  260. LRESULT* pResult
  261. )
  262. {
  263. // Did the 'state' of the entry change?
  264. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  265. if (pNMListView &&
  266. (pNMListView->uChanged & LVIF_STATE) == LVIF_STATE)
  267. {
  268. if ((pNMListView->uNewState & LVIS_SELECTED) != LVIS_SELECTED)
  269. {
  270. // Is there a selected item in the list control?
  271. if (m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) == -1)
  272. {
  273. // Disabled the edit and spin controls
  274. EnableControls (FALSE);
  275. }
  276. }
  277. else
  278. {
  279. // Enable the edit and spin controls
  280. EnableControls (TRUE);
  281. // Load the control with data for the selected item.
  282. ResetControls (pNMListView->iItem);
  283. }
  284. }
  285. *pResult = 0;
  286. return ;
  287. }
  288. /////////////////////////////////////////////////////////////
  289. //
  290. // ResetControls
  291. //
  292. void
  293. CEditLODDialog::ResetControls (int iIndex)
  294. {
  295. //
  296. // Set the text of the group box
  297. //
  298. CString stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_NAME);
  299. // Set the text of the group box
  300. CString stringTitle;
  301. stringTitle.Format ("Settings (%s)", (LPCTSTR)stringTemp);
  302. SetDlgItemText (IDC_SETTINGS_GROUP, stringTitle);
  303. //
  304. // Reset the switch up controls
  305. //
  306. // Get the switch up distance from the list control
  307. stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_UP);
  308. // Set the text of the edit control to reflect the switching distance
  309. SetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
  310. // Set the current position of the spin control
  311. float switchDistance = ::atof (stringTemp);
  312. m_switchUpSpin.SetPos (int(switchDistance * 10.00F));
  313. //
  314. // Reset the switch down controls
  315. //
  316. // Get the switch down distance from the list control
  317. stringTemp = m_hierarchyListCtrl.GetItemText (iIndex, COL_SWITCH_DN);
  318. // Set the text of the edit control to reflect the switching distance
  319. SetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
  320. // Set the current position of the spin control
  321. switchDistance = ::atof (stringTemp);
  322. m_switchDownSpin.SetPos (int(switchDistance * 10.00F));
  323. return ;
  324. }
  325. /////////////////////////////////////////////////////////////
  326. //
  327. // EnableControls
  328. //
  329. void
  330. CEditLODDialog::EnableControls (BOOL bEnable)
  331. {
  332. // Enable or disable the windows
  333. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SETTINGS_GROUP), bEnable);
  334. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_SPIN), bEnable);
  335. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_UP_EDIT), bEnable);
  336. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_SPIN), bEnable);
  337. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SWITCH_DN_EDIT), bEnable);
  338. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_RECALC), bEnable);
  339. return ;
  340. }
  341. /////////////////////////////////////////////////////////////
  342. //
  343. // OnUpdateSwitchDnEdit
  344. //
  345. void
  346. CEditLODDialog::OnUpdateSwitchDnEdit (void)
  347. {
  348. // Get the switching distance from the edit control
  349. CString stringTemp;
  350. GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
  351. float newVal = ::atof (stringTemp);
  352. // Change the switching distance in the spin control
  353. m_switchDownSpin.SetPos (int(newVal * 10.00F));
  354. // Find the selected item in the list control
  355. int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  356. if (iIndex != -1)
  357. {
  358. // Change the switching distance in the list control
  359. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_DN, stringTemp);
  360. }
  361. return ;
  362. }
  363. /////////////////////////////////////////////////////////////
  364. //
  365. // OnUpdateSwitchUpEdit
  366. //
  367. void CEditLODDialog::OnUpdateSwitchUpEdit (void)
  368. {
  369. // Get the switching distance from the edit control
  370. CString stringTemp;
  371. GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
  372. float newVal = ::atof (stringTemp);
  373. // Change the switching distance in the spin control
  374. m_switchUpSpin.SetPos (int(newVal * 10.00F));
  375. // Find the selected item in the list control
  376. int iIndex = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  377. if (iIndex != -1)
  378. {
  379. // Change the switching distance in the list control
  380. m_hierarchyListCtrl.SetItemText (iIndex, COL_SWITCH_UP, stringTemp);
  381. }
  382. return ;
  383. }
  384. /////////////////////////////////////////////////////////////
  385. //
  386. // OnRecalc
  387. //
  388. void CEditLODDialog::OnRecalc (void)
  389. {
  390. // Get the up switching distance from the edit control
  391. CString stringTemp;
  392. GetDlgItemText (IDC_SWITCH_UP_EDIT, stringTemp);
  393. float switchUp = ::atof (stringTemp);
  394. // Get the down switching distance from the edit control
  395. stringTemp;
  396. GetDlgItemText (IDC_SWITCH_DN_EDIT, stringTemp);
  397. float switchDown = ::atof (stringTemp);
  398. if (switchUp < switchDown)
  399. {
  400. // Calculate the current range
  401. float switchDelta = switchDown - switchUp;
  402. float switchOverlap = switchDelta * 0.1F;
  403. // Get a pointer to the doc
  404. CW3DViewDoc *pCDoc = ::GetCurrentDocument ();
  405. if (pCDoc)
  406. {
  407. // Get the current LOD from the doc
  408. DistLODClass *pLOD = (DistLODClass *)pCDoc->GetDisplayedObject ();
  409. ASSERT (pLOD);
  410. if (pLOD)
  411. {
  412. int iSubObjects = pLOD->Get_Num_Sub_Objects ();
  413. switchUp = switchDown - switchOverlap;
  414. // Loop through all the subobjects (following the highlighted one)
  415. for (int iObject = m_hierarchyListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED) + 1;
  416. (iObject < iSubObjects);
  417. iObject ++)
  418. {
  419. // Set the text of the switch up column
  420. CString stringTemp;
  421. stringTemp.Format ("%.2f", switchUp);
  422. m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_UP, stringTemp);
  423. // Set the text of the switch dn column
  424. stringTemp.Format ("%.2f", switchUp+switchDelta);
  425. m_hierarchyListCtrl.SetItemText (iObject, COL_SWITCH_DN, stringTemp);
  426. // Add the range to the switch up distance
  427. switchUp += switchDelta-switchOverlap;
  428. }
  429. }
  430. }
  431. }
  432. return ;
  433. }