ForestDlg.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // ForestDlg.cpp : implementation file
  5. //
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "ForestDlg.h"
  9. #include "Terrain.h"
  10. #include "mclib.h"
  11. #include "EditorObjectMgr.h"
  12. #include "mclib.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // ForestDlg dialog
  15. static char szFITFilter[] = "FIT Files (*.FIT)|*.fit||";
  16. ForestDlg::ForestDlg(CWnd* pParent /*=NULL*/)
  17. : CDialog(ForestDlg::IDD, pParent), forest( -1 )
  18. {
  19. //{{AFX_DATA_INIT(ForestDlg)
  20. m_maxDensity = 10.0f;
  21. m_minDensity = 2.0f;
  22. m_maxHeight = 1.0f;
  23. m_minHeight = 1.0f;
  24. m_randomPlacement = TRUE;
  25. m_xLoc = 0.0f;
  26. m_yLoc = 0.0f;
  27. m_radius = 0.0f;
  28. m_Name = _T("");
  29. m_1 = 0;
  30. m_2 = 0;
  31. m_3 = 0;
  32. m_4 = 0;
  33. m_5 = 0;
  34. m_6 = 0;
  35. m_7 = 0;
  36. m_8 = 0;
  37. m_9 = 0;
  38. m_10 = 0;
  39. m_12 = 0;
  40. m_13 = 0;
  41. m_14 = 0;
  42. m_15 = 0;
  43. //}}AFX_DATA_INIT
  44. }
  45. void ForestDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47. float min = -land->mapTopLeft3d.y;
  48. float max = land->mapTopLeft3d.y;
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(ForestDlg)
  51. DDX_Text(pDX, IDC_DENSITY_MAX, m_maxDensity);
  52. DDV_MinMaxFloat(pDX, m_maxDensity, 0.f, 10.f);
  53. DDX_Text(pDX, IDC_DENSITY_MIN, m_minDensity);
  54. DDV_MinMaxFloat(pDX, m_minDensity, 0.f, 10.f);
  55. DDX_Text(pDX, IDC_HEIGHT_MAX, m_maxHeight);
  56. DDV_MinMaxFloat(pDX, m_maxHeight, 0.5f, 1.5f);
  57. DDX_Text(pDX, IDC_HEIGHT_MIN, m_minHeight);
  58. DDV_MinMaxFloat(pDX, m_minHeight, 0.5f, 1.5f);
  59. DDX_Check(pDX, IDC_RANDOM, m_randomPlacement);
  60. DDX_Text(pDX, IDC_XLOC, m_xLoc);
  61. DDX_Text(pDX, IDC_YLOC, m_yLoc);
  62. DDX_Text(pDX, IDC_RADIUS, m_radius);
  63. DDX_Text(pDX, IDC_NAME_EDIT, m_Name);
  64. DDX_Text(pDX, IDC_FOREST_EDIT1, m_1);
  65. DDV_MinMaxInt(pDX, m_1, 0, 100);
  66. DDX_Text(pDX, IDC_FOREST_EDIT2, m_2);
  67. DDV_MinMaxInt(pDX, m_2, 0, 100);
  68. DDX_Text(pDX, IDC_FOREST_EDIT3, m_3);
  69. DDV_MinMaxInt(pDX, m_3, 0, 100);
  70. DDX_Text(pDX, IDC_FOREST_EDIT4, m_4);
  71. DDV_MinMaxInt(pDX, m_4, 0, 100);
  72. DDX_Text(pDX, IDC_FOREST_EDIT5, m_5);
  73. DDV_MinMaxInt(pDX, m_5, 0, 100);
  74. DDX_Text(pDX, IDC_FOREST_EDIT6, m_6);
  75. DDV_MinMaxInt(pDX, m_6, 0, 100);
  76. DDX_Text(pDX, IDC_FOREST_EDIT7, m_7);
  77. DDV_MinMaxInt(pDX, m_7, 0, 100);
  78. DDX_Text(pDX, IDC_FOREST_EDIT8, m_8);
  79. DDV_MinMaxInt(pDX, m_8, 0, 100);
  80. DDX_Text(pDX, IDC_FOREST_EDIT9, m_9);
  81. DDV_MinMaxInt(pDX, m_9, 0, 100);
  82. DDX_Text(pDX, IDC_FOREST_EDIT10, m_10);
  83. DDV_MinMaxInt(pDX, m_10, 0, 100);
  84. DDX_Text(pDX, IDC_FOREST_EDIT12, m_12);
  85. DDV_MinMaxInt(pDX, m_12, 0, 100);
  86. DDX_Text(pDX, IDC_FOREST_EDIT13, m_13);
  87. DDV_MinMaxInt(pDX, m_13, 0, 100);
  88. DDX_Text(pDX, IDC_FOREST_EDIT14, m_14);
  89. DDV_MinMaxInt(pDX, m_14, 0, 100);
  90. DDX_Text(pDX, IDC_FOREST_EDIT15, m_15);
  91. DDV_MinMaxInt(pDX, m_15, 0, 100);
  92. //}}AFX_DATA_MAP
  93. // DDV_MinMaxFloat(pDX, m_xLoc, land->mapTopLeft3d.x, -land->mapTopLeft3d.x);
  94. DDV_MinMaxFloat(pDX, m_yLoc, min, max);
  95. }
  96. BEGIN_MESSAGE_MAP(ForestDlg, CDialog)
  97. //{{AFX_MSG_MAP(ForestDlg)
  98. ON_BN_CLICKED(IDSAVE, OnSave)
  99. ON_BN_CLICKED(IDLOAD, OnLoad)
  100. //}}AFX_MSG_MAP
  101. ON_CONTROL_RANGE( EN_CHANGE, IDC_FOREST_EDIT1, IDC_FOREST_EDIT15, OnEditChanged )
  102. ON_NOTIFY_RANGE( NM_RELEASEDCAPTURE, IDC_SLIDER1, IDC_SLIDER15, OnSliderChanged )
  103. END_MESSAGE_MAP()
  104. /////////////////////////////////////////////////////////////////////////////
  105. // ForestDlg message handlers
  106. void ForestDlg::OnSave()
  107. {
  108. BOOL bRes = UpdateData(TRUE);
  109. if (!bRes)
  110. {
  111. return;
  112. }
  113. CFileDialog dlg( 0, "fit", NULL, OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR, szFITFilter, this );
  114. dlg.m_ofn.lpstrInitialDir = terrainPath;
  115. int retVal = dlg.DoModal();
  116. if ( IDOK == retVal )
  117. {
  118. for ( int i = IDC_FOREST_EDIT1; i < IDC_FOREST_EDIT15+1; i+= 2 )
  119. {
  120. CWnd* pWnd = GetDlgItem( i );
  121. CEdit* pEdit = (CEdit*)( pWnd );
  122. if ( pEdit )
  123. {
  124. CString str;
  125. pEdit->GetWindowText( str );
  126. forest.percentages[(i-IDC_FOREST_EDIT1)/2] = atof( str );
  127. }
  128. }
  129. forest.minDensity = m_minDensity;
  130. forest.maxDensity = m_maxDensity;
  131. forest.minHeight = m_minHeight;
  132. forest.maxHeight = m_maxHeight;
  133. forest.bRandom = m_randomPlacement;
  134. forest.centerX = m_xLoc;
  135. forest.centerY = m_yLoc;
  136. forest.radius = m_radius;
  137. forest.setFileName( dlg.m_ofn.lpstrFile );
  138. forest.save();
  139. OnInitDialog();
  140. }
  141. }
  142. void ForestDlg::OnOK()
  143. {
  144. BOOL bRes = UpdateData(TRUE);
  145. if (!bRes)
  146. {
  147. return;
  148. }
  149. for ( int i = IDC_FOREST_EDIT1; i < IDC_FOREST_EDIT15+1; i+= 2 )
  150. {
  151. CWnd* pWnd = GetDlgItem( i );
  152. CEdit* pEdit = (CEdit*)( pWnd );
  153. if ( pEdit )
  154. {
  155. CString str;
  156. pEdit->GetWindowText( str );
  157. forest.percentages[(i-IDC_FOREST_EDIT1)/2] = atof( str );
  158. }
  159. }
  160. forest.minDensity = m_minDensity;
  161. forest.maxDensity = m_maxDensity;
  162. forest.minHeight = m_minHeight;
  163. forest.maxHeight = m_maxHeight;
  164. forest.bRandom = m_randomPlacement;
  165. forest.centerX = m_xLoc;
  166. forest.centerY = m_yLoc;
  167. forest.radius = m_radius;
  168. forest.name = m_Name;
  169. CDialog::OnOK();
  170. }
  171. void ForestDlg::OnCancel()
  172. {
  173. // TODO: Add extra cleanup here
  174. CDialog::OnCancel();
  175. }
  176. void ForestDlg::OnEditChanged( UINT nID )
  177. {
  178. CWnd* pWnd = GetDlgItem( nID );
  179. CEdit* pEdit = (CEdit*)( pWnd );
  180. if ( pEdit )
  181. {
  182. CString text;
  183. pEdit->GetWindowText( text );
  184. double val = atof( text );
  185. CSliderCtrl* pSlider = (CSliderCtrl*)( GetDlgItem( nID - 1 ) );
  186. if ( pSlider )
  187. {
  188. pSlider->SetRange( 0, 100 );
  189. pSlider->SetPos( val );
  190. }
  191. }
  192. }
  193. void ForestDlg::OnSliderChanged( UINT id, NMHDR * pNotifyStruct, LRESULT * result )
  194. {
  195. CWnd* pWnd = GetDlgItem( id );
  196. CSliderCtrl* pSlider = (CSliderCtrl*)( pWnd );
  197. if ( pSlider )
  198. {
  199. int Val = pSlider->GetPos();
  200. CEdit* pEdit = (CEdit*)( GetDlgItem( id + 1 ) );
  201. if ( pEdit )
  202. {
  203. CString text;
  204. text.Format( "%ld", Val );
  205. pEdit->SetWindowText( text );
  206. }
  207. }
  208. }
  209. BOOL ForestDlg::OnInitDialog()
  210. {
  211. CDialog::OnInitDialog();
  212. m_minDensity = forest.minDensity;
  213. m_maxDensity = forest.maxDensity;
  214. m_minHeight = forest.minHeight;
  215. m_maxHeight = forest.maxHeight;
  216. m_randomPlacement = forest.bRandom;
  217. m_Name = forest.name;
  218. if ( !m_xLoc )
  219. {
  220. m_xLoc = forest.centerX;
  221. m_yLoc = forest.centerY;
  222. m_radius = forest.radius;
  223. }
  224. UpdateData( 0 );
  225. for ( int i = IDC_SLIDER1; i < IDC_SLIDER15; i+= 2 )
  226. {
  227. CWnd* pWnd = GetDlgItem( i );
  228. CSliderCtrl* pSlider = (CSliderCtrl*)( pWnd );
  229. if ( pSlider )
  230. {
  231. pSlider->SetRange( 0, 100 );
  232. }
  233. }
  234. for ( i = IDC_FOREST_EDIT1; i < IDC_FOREST_EDIT15+1; i+= 2 )
  235. {
  236. CWnd* pWnd = GetDlgItem( i );
  237. CEdit* pEdit = (CEdit*)( pWnd );
  238. if ( pEdit )
  239. {
  240. CString str;
  241. str.Format( "%ld", (long)forest.percentages[(i-IDC_FOREST_EDIT1)/2] );
  242. pEdit->SetWindowText( str );
  243. }
  244. CSliderCtrl* pSlider = (CSliderCtrl*)( GetDlgItem( i - 1 ) );
  245. if ( pSlider )
  246. {
  247. pSlider->SetRange( 0, 100 );
  248. pSlider->SetPos( forest.percentages[(i-IDC_FOREST_EDIT1)/2] );
  249. }
  250. }
  251. char tmp[256];
  252. _splitpath( forest.getFileName(), NULL, NULL, tmp, 0 );
  253. if (0 != strcmp("", tmp))
  254. {
  255. SetWindowText( tmp );
  256. }
  257. return TRUE; // return TRUE unless you set the focus to a control
  258. // EXCEPTION: OCX Property Pages should return FALSE
  259. }
  260. void ForestDlg::OnLoad()
  261. {
  262. CFileDialog dlg( TRUE, "fit", NULL, OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST, szFITFilter, this );
  263. dlg.m_ofn.lpstrInitialDir = terrainPath;
  264. if ( IDOK == dlg.DoModal() )
  265. {
  266. CString str = dlg.GetFileName();
  267. // Forest tmp( -1 );
  268. // tmp.setFileName( dlg.m_ofn.lpstrFile );
  269. // tmp.init();
  270. EditorObjectMgr::instance()->unselectAll();
  271. // int ID = EditorObjectMgr::instance()->createForest( tmp );
  272. forest.setFileName( dlg.m_ofn.lpstrFile );
  273. forest.init();
  274. //forest = tmp;
  275. OnInitDialog();
  276. }
  277. }