TerrainLODPage.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. // TerrainLODPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "TerrainLODPage.h"
  23. #include "LODSettingsDialog.H"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Constants
  32. //
  33. /////////////////////////////////////////////////////////////////////////////
  34. static const int COL_NAME = 0;
  35. static const int COL_DISTANCE = 1;
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // TerrainLODPageClass
  39. //
  40. /////////////////////////////////////////////////////////////////////////////
  41. TerrainLODPageClass::TerrainLODPageClass (void)
  42. : m_bFinishedInit (false),
  43. DockableFormClass(TerrainLODPageClass::IDD)
  44. {
  45. //{{AFX_DATA_INIT(TerrainLODPageClass)
  46. // NOTE: the ClassWizard will add member initialization here
  47. //}}AFX_DATA_INIT
  48. return ;
  49. }
  50. /////////////////////////////////////////////////////////////////////////////
  51. //
  52. // ~TerrainLODPageClass
  53. //
  54. /////////////////////////////////////////////////////////////////////////////
  55. TerrainLODPageClass::~TerrainLODPageClass (void)
  56. {
  57. return ;
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. //
  61. // DoDataExchange
  62. //
  63. /////////////////////////////////////////////////////////////////////////////
  64. void
  65. TerrainLODPageClass::DoDataExchange (CDataExchange *pDX)
  66. {
  67. DockableFormClass::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(TerrainLODPageClass)
  69. DDX_Control(pDX, IDC_LOD_LIST, m_LODListCtrl);
  70. DDX_Control(pDX, IDC_LOD_COUNT_SPIN, m_LODCountSpin);
  71. //}}AFX_DATA_MAP
  72. return ;
  73. }
  74. BEGIN_MESSAGE_MAP(TerrainLODPageClass, DockableFormClass)
  75. //{{AFX_MSG_MAP(TerrainLODPageClass)
  76. ON_NOTIFY(NM_DBLCLK, IDC_LOD_LIST, OnDblclkLodList)
  77. ON_EN_UPDATE(IDC_LOD_COUNT_EDIT, OnUpdateLodCountEdit)
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // TerrainLODPageClass message handlers
  82. /////////////////////////////////////////////////////////////////////////////
  83. //
  84. // HandleInitDialog
  85. //
  86. /////////////////////////////////////////////////////////////////////////////
  87. void
  88. TerrainLODPageClass::HandleInitDialog (void)
  89. {
  90. //
  91. // Setup the lod-count controls
  92. //
  93. SetDlgItemInt (IDC_LOD_COUNT_EDIT, 0);
  94. m_LODCountSpin.SetRange (0, 10);
  95. m_LODCountSpin.SetPos (m_SettingsList.Count ());
  96. //
  97. // Setup the list control
  98. //
  99. m_LODListCtrl.InsertColumn (COL_NAME, "Level");
  100. m_LODListCtrl.InsertColumn (COL_DISTANCE, "Switch Distance");
  101. CRect rect;
  102. m_LODListCtrl.GetClientRect (&rect);
  103. m_LODListCtrl.SetColumnWidth (COL_NAME, rect.Width () >> 1);
  104. m_LODListCtrl.SetColumnWidth (COL_DISTANCE, rect.Width () >> 1);
  105. //
  106. // Loop through all the distances and add them to the list control.
  107. //
  108. for (int index = 0; index < m_SettingsList.Count (); index ++) {
  109. unsigned int distance = m_SettingsList[index];
  110. CString text;
  111. text.Format ("LOD %d", index + 1);
  112. int real_index = m_LODListCtrl.InsertItem (index + 1, text);
  113. if (real_index >= 0) {
  114. text.Format ("%d meters", distance);
  115. m_LODListCtrl.SetItemText (real_index, COL_DISTANCE, text);
  116. m_LODListCtrl.SetItemData (real_index, distance);
  117. }
  118. }
  119. m_bFinishedInit = true;
  120. return ;
  121. }
  122. /////////////////////////////////////////////////////////////////////////////
  123. //
  124. // Apply_Changes
  125. //
  126. /////////////////////////////////////////////////////////////////////////////
  127. bool
  128. TerrainLODPageClass::Apply_Changes (void)
  129. {
  130. m_SettingsList.Delete_All ();
  131. //
  132. // Build a list of switching distances (could just be an array, but I'm feeling lazy).
  133. //
  134. for (int index = 0; index < m_LODListCtrl.GetItemCount (); index ++) {
  135. m_SettingsList.Add ((unsigned int)m_LODListCtrl.GetItemData (index));
  136. }
  137. return true;
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. //
  141. // OnDblclkLodList
  142. //
  143. /////////////////////////////////////////////////////////////////////////////
  144. void
  145. TerrainLODPageClass::OnDblclkLodList
  146. (
  147. NMHDR *pNMHDR,
  148. LRESULT *pResult
  149. )
  150. {
  151. (*pResult) = 0;
  152. //
  153. // Get the index of the selected item
  154. //
  155. int index = m_LODListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  156. if (index >= 0) {
  157. unsigned int distance = (unsigned int)m_LODListCtrl.GetItemData (index);
  158. //
  159. // Display the dialog
  160. //
  161. LODSettingsDialogClass dialog (distance);
  162. if (dialog.DoModal () == IDOK) {
  163. distance = dialog.Get_Distance ();
  164. //
  165. // Pass the new distance information onto the list control
  166. //
  167. CString text;
  168. text.Format ("%d meters", distance);
  169. m_LODListCtrl.SetItemText (index, COL_DISTANCE, text);
  170. m_LODListCtrl.SetItemData (index, distance);
  171. }
  172. }
  173. return ;
  174. }
  175. /////////////////////////////////////////////////////////////////////////////
  176. //
  177. // On_Count_Change
  178. //
  179. /////////////////////////////////////////////////////////////////////////////
  180. void
  181. TerrainLODPageClass::On_Count_Change (void)
  182. {
  183. if (m_bFinishedInit) {
  184. //
  185. // Get the new count
  186. //
  187. int new_lod_count = GetDlgItemInt (IDC_LOD_COUNT_EDIT);
  188. new_lod_count = max (0, new_lod_count);
  189. //
  190. // Get the current count
  191. //
  192. int current_count = m_LODListCtrl.GetItemCount ();
  193. //
  194. // Determine if we should add or remove entries
  195. //
  196. if (new_lod_count < current_count) {
  197. //
  198. // Remove the unnecessary entries from the list control
  199. //
  200. for (int index = new_lod_count; index < current_count; index ++) {
  201. m_LODListCtrl.DeleteItem (new_lod_count);
  202. }
  203. } else if (new_lod_count > current_count) {
  204. //
  205. // Add the new entries to the list control
  206. //
  207. for (int index = current_count; index < new_lod_count; index ++) {
  208. CString name;
  209. name.Format ("LOD %d", index + 1);
  210. int real_index = m_LODListCtrl.InsertItem (index + 1, name);
  211. m_LODListCtrl.SetItemText (real_index, COL_DISTANCE, "0 meters");
  212. m_LODListCtrl.SetItemData (real_index, 0);
  213. }
  214. }
  215. }
  216. return ;
  217. }
  218. /////////////////////////////////////////////////////////////////////////////
  219. //
  220. // OnUpdateLodCountEdit
  221. //
  222. /////////////////////////////////////////////////////////////////////////////
  223. void
  224. TerrainLODPageClass::OnUpdateLodCountEdit (void)
  225. {
  226. On_Count_Change ();
  227. return ;
  228. }