DlgPgSector.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgPgSector.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgPgSector.h"
  16. #ifdef _DEBUG
  17. #undef new
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgPgSector property page
  24. IMPLEMENT_DYNCREATE(CDlgPgSector, CPropertyPage)
  25. CDlgPgSector::CDlgPgSector() : CPropertyPage(CDlgPgSector::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CDlgPgSector)
  28. m_iBrowseModeRadio = -1;
  29. m_strSectorName = _T("");
  30. m_radioInclude = -1;
  31. //}}AFX_DATA_INIT
  32. if(
  33. CTString( CStringA(theApp.GetProfileString(L"World editor", L"Color browsing mode (info)"))) ==
  34. CTString("RGB"))
  35. {
  36. m_iBrowseModeRadio = 0;
  37. }
  38. else
  39. {
  40. m_iBrowseModeRadio = 1;
  41. }
  42. m_colLastSectorAmbientColor = -1;
  43. m_bLastSectorAmbientColorMixed = FALSE;
  44. m_SectorAmbientColor.SetPickerType( CColoredButton::PT_MFC);
  45. m_ctrlClassificationFlags.SetDialogPtr(this);
  46. m_ctrlVisibilityFlags.SetDialogPtr(this);
  47. m_ctrlClassificationFlags.SetEditableMask(0xFFFF0000);
  48. m_ctrlVisibilityFlags.SetEditableMask(0x0000FFFF);
  49. }
  50. CDlgPgSector::~CDlgPgSector()
  51. {
  52. }
  53. #define MIXED_NAME "Mixed name"
  54. void CDlgPgSector::DoDataExchange(CDataExchange* pDX)
  55. {
  56. if( theApp.m_bDisableDataExchange) return;
  57. CPropertyPage::DoDataExchange(pDX);
  58. // mark that property page has been modified
  59. SetModified( TRUE);
  60. // obtain document
  61. CWorldEditorDoc* pDoc = theApp.GetDocument();
  62. if( pDoc == NULL) return;
  63. // sector mode must be on
  64. if( pDoc->GetEditingMode() != SECTOR_MODE) return;
  65. // if dialog is receiving data and control windows are valid
  66. if( (pDX->m_bSaveAndValidate == FALSE) && IsWindow( m_SectorAmbientColor.m_hWnd) )
  67. {
  68. BOOL bSelectionExists = pDoc->m_selSectorSelection.Count() != 0;
  69. m_comboContentType.ResetContent();
  70. for(INDEX iContentType=0; iContentType<MAX_UBYTE; iContentType++)
  71. {
  72. CTString &strContent = pDoc->m_woWorld.wo_actContentTypes[iContentType].ct_strName;
  73. if( strContent == "") break;
  74. m_comboContentType.AddString( CString(strContent));
  75. }
  76. m_comboEnvironmentType.ResetContent();
  77. for(INDEX iEnvironmentType=0; iEnvironmentType<MAX_UBYTE; iEnvironmentType++)
  78. {
  79. CTString &strEnvironment = pDoc->m_woWorld.wo_aetEnvironmentTypes[iEnvironmentType].et_strName;
  80. if( strEnvironment == "") break;
  81. m_comboEnvironmentType.AddString( CString(strEnvironment));
  82. }
  83. if( bSelectionExists)
  84. {
  85. BOOL bSameForceField = TRUE;
  86. BOOL bSameFog = TRUE;
  87. BOOL bSameHaze = TRUE;
  88. INDEX iFirstForceField;
  89. INDEX iFirstFog;
  90. INDEX iFirstHaze;
  91. m_comboForceField.ResetContent();
  92. m_comboFog.ResetContent();
  93. m_comboHaze.ResetContent();
  94. CBrush3D *pbrBrush = NULL;
  95. INDEX iSector = 0;
  96. // for all sectors
  97. FOREACHINDYNAMICCONTAINER(pDoc->m_selSectorSelection, CBrushSector, itbsc)
  98. {
  99. if( iSector == 0)
  100. {
  101. iFirstForceField = itbsc->GetForceType();
  102. iFirstFog = itbsc->GetFogType();
  103. iFirstHaze = itbsc->GetHazeType();
  104. }
  105. INDEX iForceField = itbsc->GetForceType();
  106. if( iForceField != iFirstForceField) bSameForceField = FALSE;
  107. INDEX iFog = itbsc->GetFogType();
  108. if( iFog != iFirstFog) bSameFog = FALSE;
  109. INDEX iHaze = itbsc->GetHazeType();
  110. if( iHaze != iFirstHaze) bSameHaze = FALSE;
  111. // get sector brush
  112. if( (pbrBrush == NULL) || (pbrBrush == itbsc->bsc_pbmBrushMip->bm_pbrBrush) )
  113. {
  114. if( pbrBrush == NULL)
  115. {
  116. pbrBrush = itbsc->bsc_pbmBrushMip->bm_pbrBrush;
  117. for(INDEX iForceField=0; iForceField<MAX_UBYTE; iForceField++)
  118. {
  119. CTString strForceName = pbrBrush->br_penEntity->GetForceName( iForceField);
  120. if( strForceName == "") break;
  121. m_comboForceField.AddString( CString(strForceName));
  122. }
  123. for(INDEX iFog=0; iFog<MAX_UBYTE; iFog++)
  124. {
  125. CTString strFogName = pbrBrush->br_penEntity->GetFogName( iFog);
  126. if( strFogName == "") break;
  127. m_comboFog.AddString( CString(strFogName));
  128. }
  129. for(INDEX iHaze=0; iHaze<MAX_UBYTE; iHaze++)
  130. {
  131. CTString strHazeName = pbrBrush->br_penEntity->GetHazeName( iHaze);
  132. if( strHazeName == "") break;
  133. m_comboHaze.AddString( CString(strHazeName));
  134. }
  135. }
  136. }
  137. else
  138. {
  139. m_comboForceField.ResetContent();
  140. m_comboFog.ResetContent();
  141. m_comboHaze.ResetContent();
  142. bSameForceField = FALSE;
  143. bSameFog = FALSE;
  144. bSameHaze = FALSE;
  145. GetDlgItem( IDC_STATIC_FORCE_FIELD_T)->EnableWindow( FALSE);
  146. GetDlgItem( IDC_FORCE_FIELD_COMBO)->EnableWindow( FALSE);
  147. GetDlgItem( IDC_STATIC_FOG_T)->EnableWindow( FALSE);
  148. GetDlgItem( IDC_FOG_COMBO)->EnableWindow( FALSE);
  149. GetDlgItem( IDC_STATIC_HAZE_T)->EnableWindow( FALSE);
  150. GetDlgItem( IDC_HAZE_COMBO)->EnableWindow( FALSE);
  151. }
  152. iSector++;
  153. }
  154. if( bSameForceField) m_comboForceField.SetCurSel( iFirstForceField);
  155. if( bSameFog) m_comboFog.SetCurSel( iFirstFog);
  156. if( bSameHaze) m_comboHaze.SetCurSel( iFirstHaze);
  157. }
  158. BOOL bDisableForce = FALSE;
  159. BOOL bDisableFog = FALSE;
  160. BOOL bDisableHaze = FALSE;
  161. if( m_comboForceField.GetCount() == 0) bDisableForce = TRUE;
  162. if( m_comboFog.GetCount() == 0) bDisableFog = TRUE;
  163. if( m_comboHaze.GetCount() == 0) bDisableHaze = TRUE;
  164. GetDlgItem( IDC_STATIC_FORCE_FIELD_T)->EnableWindow( bSelectionExists&&!bDisableForce);
  165. GetDlgItem( IDC_FORCE_FIELD_COMBO)->EnableWindow( bSelectionExists&&!bDisableForce);
  166. GetDlgItem( IDC_STATIC_FOG_T)->EnableWindow( bSelectionExists&&!bDisableFog);
  167. GetDlgItem( IDC_FOG_COMBO)->EnableWindow( bSelectionExists&&!bDisableFog);
  168. GetDlgItem( IDC_STATIC_HAZE_T)->EnableWindow( bSelectionExists&&!bDisableHaze);
  169. GetDlgItem( IDC_HAZE_COMBO)->EnableWindow( bSelectionExists&&!bDisableHaze);
  170. m_ctrlVisibilityFlags.EnableWindow( bSelectionExists);
  171. m_ctrlClassificationFlags.EnableWindow( bSelectionExists);
  172. INDEX iSector = 0;
  173. BOOL bSameContent = TRUE;
  174. INDEX iFirstContent;
  175. BOOL bSameEnvironment = TRUE;
  176. INDEX iFirstEnvironment;
  177. INDEX iInclude=-1;
  178. // for all sectors
  179. FOREACHINDYNAMICCONTAINER(pDoc->m_selSectorSelection, CBrushSector, itbsc)
  180. {
  181. CBrushSector &bsc=*itbsc;
  182. if( iSector == 0)
  183. {
  184. iFirstContent = bsc.GetContentType();
  185. iFirstEnvironment = bsc.GetEnvironmentType();
  186. m_SectorAmbientColor.SetColor( bsc.bsc_colAmbient);
  187. m_strSectorName = bsc.bsc_strName;
  188. m_ctrlVisibilityFlags.SetFlags(bsc.bsc_ulVisFlags);
  189. m_ctrlClassificationFlags.SetFlags(bsc.bsc_ulVisFlags);
  190. iInclude=(bsc.bsc_ulFlags2&BSCF2_VISIBILITYINCLUDE) ? 0 : 1;
  191. }
  192. else
  193. {
  194. if( bsc.GetContentType() != iFirstContent) bSameContent = FALSE;
  195. if( bsc.GetEnvironmentType() != iFirstEnvironment) bSameEnvironment = FALSE;
  196. if(m_SectorAmbientColor.GetColor() != bsc.bsc_colAmbient)
  197. {
  198. m_SectorAmbientColor.SetMixedColor();
  199. }
  200. if( CTString( CStringA(m_strSectorName)) != bsc.bsc_strName)
  201. {
  202. m_strSectorName = MIXED_NAME;
  203. }
  204. m_ctrlVisibilityFlags.MergeFlags(bsc.bsc_ulVisFlags);
  205. m_ctrlClassificationFlags.MergeFlags(bsc.bsc_ulVisFlags);
  206. INDEX iNewInclude=(bsc.bsc_ulFlags2&BSCF2_VISIBILITYINCLUDE) ? 0 : 1;
  207. if( iInclude!=-1 && iNewInclude!=iInclude)
  208. {
  209. iInclude=-1;
  210. }
  211. }
  212. iSector++;
  213. }
  214. m_radioInclude=iInclude;
  215. m_colLastSectorAmbientColor = m_SectorAmbientColor.GetColor();
  216. m_bLastSectorAmbientColorMixed = !m_SectorAmbientColor.IsColorValid();
  217. m_SectorAmbientColor.EnableWindow( bSelectionExists);
  218. m_comboContentType.EnableWindow( bSelectionExists);
  219. m_comboEnvironmentType.EnableWindow( bSelectionExists);
  220. GetDlgItem( IDC_STATIC_CONTENT_TYPE_T)->EnableWindow( bSelectionExists);
  221. GetDlgItem( IDC_STATIC_ENVIRONMENT_TYPE_T)->EnableWindow( bSelectionExists);
  222. GetDlgItem( IDC_STATIC_SECTOR_NAME)->EnableWindow( bSelectionExists);
  223. GetDlgItem( IDC_SECTOR_NAME)->EnableWindow( bSelectionExists);
  224. GetDlgItem( IDC_AMBIENT_COLOR_T)->EnableWindow( bSelectionExists);
  225. GetDlgItem( IDC_SECTOR_INCLUDE)->EnableWindow( bSelectionExists);
  226. GetDlgItem( IDC_SECTOR_EXCLUDE)->EnableWindow( bSelectionExists);
  227. if( bSameContent) m_comboContentType.SetCurSel( iFirstContent);
  228. else m_comboContentType.SetCurSel(-1);
  229. if( bSameEnvironment) m_comboEnvironmentType.SetCurSel( iFirstEnvironment);
  230. else m_comboEnvironmentType.SetCurSel(-1);
  231. m_udSectorsData.MarkUpdated();
  232. }
  233. //{{AFX_DATA_MAP(CDlgPgSector)
  234. DDX_Control(pDX, ID_CLASSIFICATION_FLAGS, m_ctrlClassificationFlags);
  235. DDX_Control(pDX, ID_VISIBILITY_FLAGS, m_ctrlVisibilityFlags);
  236. DDX_Control(pDX, IDC_STATIC_ENVIRONMENT_TYPE, m_comboEnvironmentType);
  237. DDX_Control(pDX, IDC_HAZE_COMBO, m_comboHaze);
  238. DDX_Control(pDX, IDC_FOG_COMBO, m_comboFog);
  239. DDX_Control(pDX, IDC_FORCE_FIELD_COMBO, m_comboForceField);
  240. DDX_Control(pDX, IDC_CONTENT_TYPE_COMBO, m_comboContentType);
  241. DDX_Control(pDX, ID_SECTOR_COLOR, m_SectorAmbientColor);
  242. DDX_Text(pDX, IDC_SECTOR_NAME, m_strSectorName);
  243. DDX_Radio(pDX, IDC_SECTOR_INCLUDE, m_radioInclude);
  244. //}}AFX_DATA_MAP
  245. // if dialog is giving data and control windows are valid
  246. if( (pDX->m_bSaveAndValidate != FALSE) && IsWindow( m_SectorAmbientColor.m_hWnd) )
  247. {
  248. // for all sectors
  249. FOREACHINDYNAMICCONTAINER(pDoc->m_selSectorSelection, CBrushSector, itbsc)
  250. {
  251. CBrushSector &bsc=*itbsc;
  252. INDEX iNewContent = m_comboContentType.GetCurSel();
  253. if( iNewContent!=CB_ERR)
  254. {
  255. bsc.SetContentType( iNewContent);
  256. }
  257. INDEX iNewEnvironment = m_comboEnvironmentType.GetCurSel();
  258. if( iNewEnvironment!=CB_ERR)
  259. {
  260. bsc.SetEnvironmentType( iNewEnvironment);
  261. }
  262. if( m_strSectorName != MIXED_NAME)
  263. {
  264. bsc.bsc_strName = CStringA(m_strSectorName);
  265. }
  266. INDEX iNewForceField = m_comboForceField.GetCurSel();
  267. if( iNewForceField != CB_ERR) bsc.SetForceType( iNewForceField);
  268. INDEX iNewFog = m_comboFog.GetCurSel();
  269. if( iNewFog != CB_ERR) bsc.SetFogType( iNewFog);
  270. INDEX iNewHaze = m_comboHaze.GetCurSel();
  271. if( iNewHaze != CB_ERR) bsc.SetHazeType( iNewHaze);
  272. m_ctrlVisibilityFlags.ApplyChange(bsc.bsc_ulVisFlags);
  273. m_ctrlClassificationFlags.ApplyChange(bsc.bsc_ulVisFlags);
  274. if( m_radioInclude!=-1)
  275. {
  276. if( m_radioInclude==0) bsc.bsc_ulFlags2|=BSCF2_VISIBILITYINCLUDE;
  277. else bsc.bsc_ulFlags2&=~BSCF2_VISIBILITYINCLUDE;
  278. }
  279. }
  280. COLOR colAmbient = m_SectorAmbientColor.GetColor();
  281. BOOL bColorChanged =
  282. (colAmbient != m_colLastSectorAmbientColor) ||
  283. (m_bLastSectorAmbientColorMixed && m_SectorAmbientColor.IsColorValid());
  284. if( bColorChanged)
  285. {
  286. // for all sectors
  287. FOREACHINDYNAMICCONTAINER(pDoc->m_selSectorSelection, CBrushSector, itbsc)
  288. {
  289. // set new color to sectors
  290. itbsc->bsc_colAmbient = colAmbient;
  291. itbsc->UncacheLightMaps();
  292. }
  293. }
  294. m_udSectorsData.MarkUpdated();
  295. pDoc->SetModifiedFlag( TRUE);
  296. pDoc->UpdateAllViews( NULL);
  297. }
  298. }
  299. BEGIN_MESSAGE_MAP(CDlgPgSector, CPropertyPage)
  300. //{{AFX_MSG_MAP(CDlgPgSector)
  301. ON_WM_HSCROLL()
  302. ON_CBN_DROPDOWN(IDC_CONTENT_TYPE_COMBO, OnDropdownContentTypeCombo)
  303. ON_CBN_SELCHANGE(IDC_CONTENT_TYPE_COMBO, OnSelchangeContentTypeCombo)
  304. ON_CBN_SELCHANGE(IDC_FORCE_FIELD_COMBO, OnSelchangeForceFieldCombo)
  305. ON_CBN_DROPDOWN(IDC_FORCE_FIELD_COMBO, OnDropdownForceFieldCombo)
  306. ON_CBN_DROPDOWN(IDC_FOG_COMBO, OnDropdownFogCombo)
  307. ON_CBN_SELCHANGE(IDC_FOG_COMBO, OnSelchangeFogCombo)
  308. ON_CBN_DROPDOWN(IDC_HAZE_COMBO, OnDropdownHazeCombo)
  309. ON_CBN_SELCHANGE(IDC_HAZE_COMBO, OnSelchangeHazeCombo)
  310. ON_CBN_DROPDOWN(IDC_STATIC_ENVIRONMENT_TYPE, OnDropdownStaticEnvironmentType)
  311. ON_CBN_SELCHANGE(IDC_STATIC_ENVIRONMENT_TYPE, OnSelchangeStaticEnvironmentType)
  312. ON_BN_CLICKED(IDC_SECTOR_INCLUDE, OnSectorInclude)
  313. ON_BN_CLICKED(IDC_SECTOR_EXCLUDE, OnSectorExclude)
  314. //}}AFX_MSG_MAP
  315. END_MESSAGE_MAP()
  316. /////////////////////////////////////////////////////////////////////////////
  317. // CDlgPgSector message handlers
  318. BOOL CDlgPgSector::OnIdle(LONG lCount)
  319. {
  320. // obtain document
  321. CWorldEditorDoc* pDoc = theApp.GetDocument();
  322. if( (pDoc == NULL) || !IsWindow(m_hWnd)) return FALSE;
  323. COLOR colSectorAmbientColor = m_SectorAmbientColor.GetColor();
  324. BOOL bColorChanged =
  325. (colSectorAmbientColor != m_colLastSectorAmbientColor) ||
  326. (m_bLastSectorAmbientColorMixed && m_SectorAmbientColor.IsColorValid());
  327. // if color was changed from last idle
  328. if( bColorChanged)
  329. {
  330. // view the color change
  331. UpdateData(TRUE);
  332. GetDlgItem( ID_SECTOR_COLOR)->Invalidate();
  333. // set new sector color
  334. m_colLastSectorAmbientColor = colSectorAmbientColor;
  335. m_bLastSectorAmbientColorMixed = FALSE;
  336. }
  337. // if selections have been changed (they are not up to date)
  338. if( !pDoc->m_chSelections.IsUpToDate( m_udSectorsData))
  339. {
  340. // update dialog data
  341. UpdateData( FALSE);
  342. }
  343. return TRUE;
  344. }
  345. void CDlgPgSector::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  346. {
  347. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  348. UpdateData( TRUE);
  349. m_colLastSectorAmbientColor = m_SectorAmbientColor.GetColor();
  350. m_bLastSectorAmbientColorMixed = FALSE;
  351. // obtain document
  352. CWorldEditorDoc* pDoc = theApp.GetDocument();
  353. if( pDoc == NULL) return;
  354. pDoc->SetModifiedFlag(TRUE);
  355. }
  356. void CDlgPgSector::OnDropdownContentTypeCombo()
  357. {
  358. m_comboContentType.SetDroppedWidth( 256);
  359. }
  360. void CDlgPgSector::OnSelchangeContentTypeCombo()
  361. {
  362. UpdateData( TRUE);
  363. }
  364. void CDlgPgSector::OnSelchangeForceFieldCombo()
  365. {
  366. UpdateData( TRUE);
  367. }
  368. void CDlgPgSector::OnSelchangeFogCombo()
  369. {
  370. UpdateData( TRUE);
  371. }
  372. void CDlgPgSector::OnSelchangeHazeCombo()
  373. {
  374. UpdateData( TRUE);
  375. }
  376. BOOL CDlgPgSector::PreTranslateMessage(MSG* pMsg)
  377. {
  378. if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
  379. {
  380. // move coordinates from page to entity and snap them
  381. UpdateData( TRUE);
  382. // place snapped coordinates back to dialog
  383. UpdateData( FALSE);
  384. // the message is handled
  385. return TRUE;
  386. }
  387. return CPropertyPage::PreTranslateMessage(pMsg);
  388. }
  389. void CDlgPgSector::OnDropdownForceFieldCombo()
  390. {
  391. m_comboForceField.SetDroppedWidth( 256);
  392. }
  393. void CDlgPgSector::OnDropdownFogCombo()
  394. {
  395. m_comboFog.SetDroppedWidth( 256);
  396. }
  397. void CDlgPgSector::OnDropdownHazeCombo()
  398. {
  399. m_comboHaze.SetDroppedWidth( 256);
  400. }
  401. void CDlgPgSector::OnDropdownStaticEnvironmentType()
  402. {
  403. m_comboEnvironmentType.SetDroppedWidth( 256);
  404. }
  405. void CDlgPgSector::OnSelchangeStaticEnvironmentType()
  406. {
  407. UpdateData( TRUE);
  408. }
  409. void CDlgPgSector::OnSectorInclude()
  410. {
  411. UpdateData( TRUE);
  412. }
  413. void CDlgPgSector::OnSectorExclude()
  414. {
  415. UpdateData( TRUE);
  416. }