HeightfieldMaterialSettingsDialog.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // HeightfieldMaterialSettingsDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "heightfieldmaterialsettingsdialog.h"
  23. #include "heightfieldeditor.h"
  24. #include "terrainmaterial.h"
  25. #include "utils.h"
  26. #include "filemgr.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // HeightfieldMaterialSettingsDialogClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. HeightfieldMaterialSettingsDialogClass::HeightfieldMaterialSettingsDialogClass (CWnd *pParent) :
  38. MaterialIndex (0),
  39. CDialog(HeightfieldMaterialSettingsDialogClass::IDD, pParent)
  40. {
  41. //{{AFX_DATA_INIT(HeightfieldMaterialSettingsDialogClass)
  42. // NOTE: the ClassWizard will add member initialization here
  43. //}}AFX_DATA_INIT
  44. return ;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. //
  48. // DoDataExchange
  49. //
  50. /////////////////////////////////////////////////////////////////////////////
  51. void
  52. HeightfieldMaterialSettingsDialogClass::DoDataExchange (CDataExchange* pDX)
  53. {
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(HeightfieldMaterialSettingsDialogClass)
  56. // NOTE: the ClassWizard will add DDX and DDV calls here
  57. //}}AFX_DATA_MAP
  58. return ;
  59. }
  60. BEGIN_MESSAGE_MAP(HeightfieldMaterialSettingsDialogClass, CDialog)
  61. //{{AFX_MSG_MAP(HeightfieldMaterialSettingsDialogClass)
  62. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. // OnInitDialog
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. BOOL
  71. HeightfieldMaterialSettingsDialogClass::OnInitDialog (void)
  72. {
  73. CDialog::OnInitDialog ();
  74. //
  75. // Lookup the material we're editing
  76. //
  77. TerrainMaterialClass *material = HeightfieldEditorClass::Peek_Material (MaterialIndex);
  78. if (material != NULL) {
  79. //
  80. // Fill in the controls
  81. //
  82. SetDlgItemText (IDC_TEXTURE_FILENAME, material->Get_Texture_Name ());
  83. ::SetDlgItemFloat (m_hWnd, IDC_METERS_PER_TILE_EDIT, material->Get_Meters_Per_Tile ());
  84. CheckDlgButton (IDC_MIRROR_CHECK, material->Are_UVs_Mirrored ());
  85. //
  86. // Select the right surface type
  87. //
  88. SendDlgItemMessage (IDC_SURFACE_TYPE_COMBO, CB_SETCURSEL, material->Get_Surface_Type (), 0L);
  89. } else {
  90. ::SetDlgItemFloat (m_hWnd, IDC_METERS_PER_TILE_EDIT, 10.0F);
  91. }
  92. return TRUE;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. //
  96. // OnOK
  97. //
  98. /////////////////////////////////////////////////////////////////////////////
  99. void
  100. HeightfieldMaterialSettingsDialogClass::OnOK (void)
  101. {
  102. bool is_ok = true;
  103. //
  104. // Get the texture path
  105. //
  106. CString texture_path;
  107. GetDlgItemText (IDC_TEXTURE_FILENAME, texture_path);
  108. //
  109. // Is the texture path valid?
  110. //
  111. bool is_rel_path = ::Is_Path_Relative (texture_path);
  112. if ((is_rel_path == true) || ((is_rel_path == false) && ::Get_File_Mgr ()->Is_Path_Valid (texture_path))) {
  113. float meters_per_tile = ::GetDlgItemFloat (m_hWnd, IDC_METERS_PER_TILE_EDIT);
  114. //
  115. // Get (or create) the material we're editing
  116. //
  117. TerrainMaterialClass *material = HeightfieldEditorClass::Peek_Material (MaterialIndex);
  118. if (material == NULL) {
  119. //
  120. // Create the material and add it to the manager
  121. //
  122. material = new TerrainMaterialClass;
  123. HeightfieldEditorClass::Set_Material (MaterialIndex, material);
  124. material->Release_Ref ();
  125. }
  126. //
  127. // Configure the material
  128. //
  129. material->Set_Texture (texture_path);
  130. material->Set_Meters_Per_Tile (meters_per_tile);
  131. material->Mirror_UVs (IsDlgButtonChecked (IDC_MIRROR_CHECK) == 1);
  132. material->Set_Surface_Type (SendDlgItemMessage (IDC_SURFACE_TYPE_COMBO, CB_GETCURSEL));
  133. } else {
  134. //
  135. // Let the user know this path is invalid
  136. //
  137. CString message;
  138. CString title;
  139. message.Format (IDS_INVALID_MODEL_PATH_MSG, (LPCTSTR)::Get_File_Mgr()->Get_Base_Path ());
  140. title.LoadString (IDS_INVALID_MODEL_PATH_TITLE);
  141. ::MessageBox (m_hWnd, message, title, MB_ICONERROR | MB_OK);
  142. is_ok = false;
  143. }
  144. if (is_ok) {
  145. CDialog::OnOK ();
  146. }
  147. return ;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. //
  151. // OnBrowse
  152. //
  153. /////////////////////////////////////////////////////////////////////////////
  154. void
  155. HeightfieldMaterialSettingsDialogClass::OnBrowse (void)
  156. {
  157. //
  158. // Get the current texture path
  159. //
  160. CString texture_path;
  161. GetDlgItemText (IDC_TEXTURE_FILENAME, texture_path);
  162. CFileDialog dialog (TRUE, ".tga", texture_path,
  163. OFN_HIDEREADONLY | OFN_EXPLORER,
  164. "Texture Files (*.tga)|*.tga||", ::AfxGetMainWnd ());
  165. //
  166. // Ask the user what texture they wish to use
  167. //
  168. if (dialog.DoModal () == IDOK) {
  169. //
  170. // Reset the texture filename as a "relative" path
  171. //
  172. CString full_texture_path = dialog.GetPathName ();
  173. CString rel_texture_path = ::Get_File_Mgr ()->Make_Relative_Path (full_texture_path);
  174. SetDlgItemText (IDC_TEXTURE_FILENAME, rel_texture_path);
  175. }
  176. return ;
  177. }