heightfieldpage.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : leveledit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/heightfieldpage.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/28/02 4:40p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "leveledit.h"
  37. #include "heightfieldpage.h"
  38. #include "nodemgr.h"
  39. #include "node.h"
  40. #include "utils.h"
  41. #include "cameramgr.h"
  42. #include "gotoobjectdialog.h"
  43. #include "sceneeditor.h"
  44. #include "icons.h"
  45. #include "nodecategories.h"
  46. #include "definition.h"
  47. #include "definitionfactory.h"
  48. #include "definitionfactorymgr.h"
  49. #include "preset.h"
  50. #include "editableheightfield.h"
  51. #include "staticphys.h"
  52. #include "heightfieldeditor.h"
  53. #include "heightfieldmgr.h"
  54. #include "terrainmaterial.h"
  55. #include "heightfieldmaterialsettingsdialog.h"
  56. #include "newheightfielddialog.h"
  57. #ifdef _DEBUG
  58. #define new DEBUG_NEW
  59. #undef THIS_FILE
  60. static char THIS_FILE[] = __FILE__;
  61. #endif
  62. ///////////////////////////////////////////////////////////////////////
  63. // Static member initialization
  64. ///////////////////////////////////////////////////////////////////////
  65. HeightfieldPageClass * HeightfieldPageClass::_TheInstance = NULL;
  66. /////////////////////////////////////////////////////////////////////////////
  67. //
  68. // HeightfieldPageClass
  69. //
  70. /////////////////////////////////////////////////////////////////////////////
  71. HeightfieldPageClass::HeightfieldPageClass (CWnd *parent_wnd) :
  72. IsInitialized (false),
  73. CDialog (HeightfieldPageClass::IDD)
  74. {
  75. //{{AFX_DATA_INIT(HeightfieldPageClass)
  76. //}}AFX_DATA_INIT
  77. Create (HeightfieldPageClass::IDD, parent_wnd);
  78. _TheInstance = this;
  79. return ;
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. //
  83. // ~HeightfieldPageClass
  84. //
  85. /////////////////////////////////////////////////////////////////////////////
  86. HeightfieldPageClass::~HeightfieldPageClass (void)
  87. {
  88. _TheInstance = NULL;
  89. return ;
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. //
  93. // DoDataExchange
  94. //
  95. /////////////////////////////////////////////////////////////////////////////
  96. void
  97. HeightfieldPageClass::DoDataExchange (CDataExchange* pDX)
  98. {
  99. CDialog::DoDataExchange(pDX);
  100. //{{AFX_DATA_MAP(HeightfieldPageClass)
  101. //}}AFX_DATA_MAP
  102. return ;
  103. }
  104. BEGIN_MESSAGE_MAP(HeightfieldPageClass, CDialog)
  105. //{{AFX_MSG_MAP(HeightfieldPageClass)
  106. ON_WM_SIZE()
  107. ON_WM_DESTROY()
  108. ON_BN_CLICKED(IDC_CREATE_NEW_BUTTON, OnCreateNewButton)
  109. ON_BN_CLICKED(IDC_MATERIAL_SETTINGS_BUTTON, OnMaterialSettingsButton)
  110. //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112. #ifdef _DEBUG
  113. void HeightfieldPageClass::AssertValid() const
  114. {
  115. CDialog::AssertValid();
  116. }
  117. void HeightfieldPageClass::Dump(CDumpContext& dc) const
  118. {
  119. CDialog::Dump(dc);
  120. }
  121. #endif //_DEBUG
  122. /////////////////////////////////////////////////////////////////////////////
  123. //
  124. // OnSize
  125. //
  126. /////////////////////////////////////////////////////////////////////////////
  127. void
  128. HeightfieldPageClass::OnSize
  129. (
  130. UINT nType,
  131. int cx,
  132. int cy
  133. )
  134. {
  135. CDialog::OnSize (nType, cx, cy);
  136. /*if (::IsWindow (m_ListCtrl) && (cx > 0) && (cy > 0)) {
  137. }*/
  138. return ;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. //
  142. // OnDestroy
  143. //
  144. /////////////////////////////////////////////////////////////////////////////
  145. void
  146. HeightfieldPageClass::OnDestroy (void)
  147. {
  148. ::RemoveProp (m_hWnd, "TRANS_ACCS");
  149. CDialog::OnDestroy ();
  150. return ;
  151. }
  152. ////////////////////////////////////////////////////////////////////////////
  153. //
  154. // OnInitDialog
  155. //
  156. ////////////////////////////////////////////////////////////////////////////
  157. BOOL
  158. HeightfieldPageClass::OnInitDialog (void)
  159. {
  160. CDialog::OnInitDialog ();
  161. //
  162. // Set the default parameters
  163. //
  164. ::SetDlgItemFloat (m_hWnd, IDC_BRUSH_INNER_RADIUS_EDIT, HeightfieldEditorClass::Get_Brush_Inner_Radius ());
  165. ::SetDlgItemFloat (m_hWnd, IDC_BRUSH_OUTTER_RADIUS_EDIT, HeightfieldEditorClass::Get_Brush_Outter_Radius ());
  166. ::SetDlgItemFloat (m_hWnd, IDC_BRUSH_AMOUNT_EDIT, HeightfieldEditorClass::Get_Brush_Amount ());
  167. //
  168. // Select the first brush by default
  169. //
  170. SendDlgItemMessage (IDC_BRUSH_TYPE_COMBO, CB_SETCURSEL, 0);
  171. //
  172. // Select the current default texture...
  173. //
  174. int curr_texture = HeightfieldEditorClass::Get_Current_Texture ();
  175. SendDlgItemMessage (IDC_TEXTURE0_BUTTON + curr_texture, BM_SETCHECK, TRUE);
  176. SetProp (m_hWnd, "TRANS_ACCS", (HANDLE)1);
  177. IsInitialized = true;
  178. return TRUE;
  179. }
  180. ////////////////////////////////////////////////////////////////////////////
  181. //
  182. // OnCreateNewButton
  183. //
  184. ////////////////////////////////////////////////////////////////////////////
  185. void
  186. HeightfieldPageClass::OnCreateNewButton (void)
  187. {
  188. NewHeightfieldDialogClass dialog (this);
  189. dialog.DoModal ();
  190. return ;
  191. }
  192. ////////////////////////////////////////////////////////////////////////////
  193. //
  194. // OnCommand
  195. //
  196. ////////////////////////////////////////////////////////////////////////////
  197. BOOL
  198. HeightfieldPageClass::OnCommand (WPARAM wParam, LPARAM lParam)
  199. {
  200. if (IsInitialized) {
  201. int ctrl_id = LOWORD (wParam);
  202. switch (ctrl_id)
  203. {
  204. case IDC_TEXTURE0_BUTTON:
  205. case IDC_TEXTURE1_BUTTON:
  206. case IDC_TEXTURE2_BUTTON:
  207. case IDC_TEXTURE3_BUTTON:
  208. case IDC_TEXTURE4_BUTTON:
  209. case IDC_TEXTURE5_BUTTON:
  210. case IDC_TEXTURE6_BUTTON:
  211. case IDC_TEXTURE7_BUTTON:
  212. case IDC_TEXTURE8_BUTTON:
  213. {
  214. if (HIWORD (wParam) == BN_CLICKED) {
  215. int curr_texture = ctrl_id - IDC_TEXTURE0_BUTTON;
  216. HeightfieldEditorClass::Set_Current_Texture (curr_texture);
  217. }
  218. break;
  219. }
  220. case IDC_BRUSH_INNER_RADIUS_EDIT:
  221. //
  222. // Update the heightfield editor with the new values
  223. //
  224. if (HIWORD (wParam) == EN_CHANGE) {
  225. float inner = ::GetDlgItemFloat (m_hWnd, IDC_BRUSH_INNER_RADIUS_EDIT, false);
  226. float outter = ::GetDlgItemFloat (m_hWnd, IDC_BRUSH_OUTTER_RADIUS_EDIT, false);
  227. HeightfieldEditorClass::Set_Brush_Radii (inner, outter);
  228. }
  229. break;
  230. case IDC_BRUSH_OUTTER_RADIUS_EDIT:
  231. //
  232. // Update the heightfield editor with the new values
  233. //
  234. if (HIWORD (wParam) == EN_CHANGE) {
  235. float inner = ::GetDlgItemFloat (m_hWnd, IDC_BRUSH_INNER_RADIUS_EDIT, false);
  236. float outter = ::GetDlgItemFloat (m_hWnd, IDC_BRUSH_OUTTER_RADIUS_EDIT, false);
  237. HeightfieldEditorClass::Set_Brush_Radii (inner, outter);
  238. }
  239. break;
  240. case IDC_BRUSH_AMOUNT_EDIT:
  241. //
  242. // Update the heightfield editor with the new values
  243. //
  244. if (HIWORD (wParam) == EN_CHANGE) {
  245. float amount = ::GetDlgItemFloat (m_hWnd, IDC_BRUSH_AMOUNT_EDIT, false);
  246. HeightfieldEditorClass::Set_Brush_Amount (amount);
  247. }
  248. break;
  249. case IDC_BRUSH_TYPE_COMBO:
  250. {
  251. int curr_sel = SendDlgItemMessage (IDC_BRUSH_TYPE_COMBO, CB_GETCURSEL);
  252. HeightfieldEditorClass::Set_Mode ((HeightfieldEditorClass::EDITING_MODE)curr_sel);
  253. break;
  254. }
  255. }
  256. }
  257. return CDialog::OnCommand (wParam, lParam);
  258. }
  259. ////////////////////////////////////////////////////////////////////////////
  260. //
  261. // Update_Material_Button
  262. //
  263. ////////////////////////////////////////////////////////////////////////////
  264. void
  265. HeightfieldPageClass::Update_Material_Button (int index)
  266. {
  267. if (index < 0 || index > 9) {
  268. return ;
  269. }
  270. //
  271. // Get the button in question
  272. //
  273. int ctrl_id = IDC_TEXTURE0_BUTTON + index;
  274. HWND button_wnd = ::GetDlgItem (m_hWnd, ctrl_id);
  275. if (button_wnd != NULL) {
  276. HBITMAP thumbnail = NULL;
  277. //
  278. // Get the material for this slot
  279. //
  280. TerrainMaterialClass *material = HeightfieldEditorClass::Get_Material (index);
  281. if (material != NULL) {
  282. //
  283. // Create a bitmap from this material
  284. //
  285. thumbnail = HeightfieldEditorClass::Create_Texture_Thumbnail (material->Get_Texture_Name (), 48, 48);
  286. }
  287. //
  288. // Put the bitmap into the button
  289. //
  290. HBITMAP old_bmp = (HBITMAP)::SendMessage (button_wnd, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)thumbnail);
  291. if (old_bmp != NULL) {
  292. //
  293. // Free the old button bitmap
  294. //
  295. ::DeleteObject (old_bmp);
  296. old_bmp = NULL;
  297. }
  298. }
  299. return ;
  300. }
  301. ////////////////////////////////////////////////////////////////////////////
  302. //
  303. // OnMaterialSettingsButton
  304. //
  305. ////////////////////////////////////////////////////////////////////////////
  306. void
  307. HeightfieldPageClass::OnMaterialSettingsButton (void)
  308. {
  309. int material_index = HeightfieldEditorClass::Get_Current_Texture ();
  310. //
  311. // Display a dialog that allows the user to edit the settings for this
  312. // material.
  313. //
  314. HeightfieldMaterialSettingsDialogClass dialog (this);
  315. dialog.Set_Material (material_index);
  316. if (dialog.DoModal () == IDOK) {
  317. //
  318. // Let the system know that this material has changed
  319. //
  320. HeightfieldEditorClass::On_Material_Changed (material_index);
  321. }
  322. return ;
  323. }