DlgWorldSettings.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. // DlgWorldSettings.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "DlgWorldSettings.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. // CDlgWorldSettings dialog
  24. CDlgWorldSettings::CDlgWorldSettings(CWnd* pParent /*=NULL*/)
  25. : CDialog(CDlgWorldSettings::IDD, pParent)
  26. {
  27. //{{AFX_DATA_INIT(CDlgWorldSettings)
  28. m_fnBackgroundPicture = _T("");
  29. m_strMissionDescription = _T("");
  30. m_fFrontViewCenterX = 0.0f;
  31. m_fFrontViewCenterY = 0.0f;
  32. m_fFrontViewHeight = 0.0f;
  33. m_strFrontViewPicture = _T("");
  34. m_fFrontViewWidth = 0.0f;
  35. m_fRightViewCenterX = 0.0f;
  36. m_fRightViewCenterY = 0.0f;
  37. m_fRightViewHeight = 0.0f;
  38. m_strRightViewPicture = _T("");
  39. m_fRightViewWidth = 0.0f;
  40. m_fTopViewCenterX = 0.0f;
  41. m_fTopViewCenterY = 0.0f;
  42. m_fTopViewHeight = 0.0f;
  43. m_strTopViewPicture = _T("");
  44. m_fTopViewWidth = 0.0f;
  45. m_strBackdropObject = _T("");
  46. m_strLevelName = _T("");
  47. //}}AFX_DATA_INIT
  48. }
  49. #define DDX_SPAWN_FLAG_GET(mask, ctrl) \
  50. if( ulSpawnFlags & (mask)) {\
  51. ((CButton *)GetDlgItem( ctrl))->SetCheck( TRUE);\
  52. } else {\
  53. ((CButton *)GetDlgItem( ctrl))->SetCheck( FALSE);}
  54. #define DDX_SPAWN_FLAG_SET(mask, ctrl) \
  55. if( ((CButton *)GetDlgItem( ctrl) )->GetCheck() == 1) {\
  56. ulSpawnFlags |= (mask);\
  57. } else {\
  58. ulSpawnFlags &= ~(mask);\
  59. }
  60. void CDlgWorldSettings::DoDataExchange(CDataExchange* pDX)
  61. {
  62. // if dialog is recieving data
  63. if( pDX->m_bSaveAndValidate == FALSE)
  64. {
  65. if( m_fnBackgroundPicture == "")
  66. {
  67. // disable ok button
  68. //GetDlgItem( IDOK)->EnableWindow( FALSE);
  69. }
  70. CWorldEditorDoc *pDoc = theApp.GetDocument();
  71. // obtain data for pictures used as view background
  72. m_strTopViewPicture = pDoc->m_woWorld.wo_strBackdropUp;
  73. m_fTopViewWidth = pDoc->m_woWorld.wo_fUpW;
  74. m_fTopViewHeight = pDoc->m_woWorld.wo_fUpL;
  75. m_fTopViewCenterX = pDoc->m_woWorld.wo_fUpCX;
  76. m_fTopViewCenterY = pDoc->m_woWorld.wo_fUpCZ;
  77. m_strFrontViewPicture = pDoc->m_woWorld.wo_strBackdropFt;
  78. m_fFrontViewWidth = pDoc->m_woWorld.wo_fFtW;
  79. m_fFrontViewHeight = pDoc->m_woWorld.wo_fFtH;
  80. m_fFrontViewCenterX = pDoc->m_woWorld.wo_fFtCX;
  81. m_fFrontViewCenterY = pDoc->m_woWorld.wo_fFtCY;
  82. m_strRightViewPicture = pDoc->m_woWorld.wo_strBackdropRt;
  83. m_fRightViewWidth = pDoc->m_woWorld.wo_fRtL;
  84. m_fRightViewHeight = pDoc->m_woWorld.wo_fRtH;
  85. m_fRightViewCenterX = pDoc->m_woWorld.wo_fRtCZ;
  86. m_fRightViewCenterY = pDoc->m_woWorld.wo_fRtCY;
  87. m_strBackdropObject = pDoc->m_woWorld.wo_strBackdropObject;
  88. m_strLevelName = pDoc->m_woWorld.GetName();
  89. // get spawn flags
  90. ULONG ulSpawnFlags = pDoc->m_woWorld.GetSpawnFlags();
  91. DDX_SPAWN_FLAG_GET( SPF_EASY, IDC_EASY);
  92. DDX_SPAWN_FLAG_GET( SPF_NORMAL, IDC_NORMAL);
  93. DDX_SPAWN_FLAG_GET( SPF_HARD, IDC_HARD);
  94. DDX_SPAWN_FLAG_GET( SPF_EXTREME, IDC_EXTREME);
  95. DDX_SPAWN_FLAG_GET( SPF_EXTREME<<1, IDC_DIFFICULTY_1B);
  96. DDX_SPAWN_FLAG_GET( SPF_EXTREME<<2, IDC_DIFFICULTY_2B);
  97. DDX_SPAWN_FLAG_GET( SPF_EXTREME<<3, IDC_DIFFICULTY_3B);
  98. DDX_SPAWN_FLAG_GET( SPF_EXTREME<<4, IDC_DIFFICULTY_4B);
  99. DDX_SPAWN_FLAG_GET( SPF_EXTREME<<5, IDC_DIFFICULTY_5B);
  100. DDX_SPAWN_FLAG_GET( SPF_SINGLEPLAYER, IDC_SINGLE);
  101. DDX_SPAWN_FLAG_GET( SPF_DEATHMATCH, IDC_DEATHMATCH);
  102. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE, IDC_COOPERATIVE);
  103. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<1, IDC_GAME_MODE_1B);
  104. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<2, IDC_GAME_MODE_2B);
  105. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<3, IDC_GAME_MODE_3B);
  106. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<4, IDC_GAME_MODE_4B);
  107. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<5, IDC_GAME_MODE_5B);
  108. DDX_SPAWN_FLAG_GET( SPF_COOPERATIVE<<6, IDC_GAME_MODE_6B);
  109. }
  110. CDialog::DoDataExchange(pDX);
  111. //{{AFX_DATA_MAP(CDlgWorldSettings)
  112. DDX_Control(pDX, IDC_BACKGROUND_COLOR, m_BackgroundColor);
  113. DDX_Text(pDX, IDC_PICTURE_FILE_T, m_fnBackgroundPicture);
  114. DDX_Text(pDX, IDC_MISSION_DESCRIPTION, m_strMissionDescription);
  115. DDX_Text(pDX, IDC_FRONT_VIEW_CENTER_X, m_fFrontViewCenterX);
  116. DDX_Text(pDX, IDC_FRONT_VIEW_CENTER_Y, m_fFrontViewCenterY);
  117. DDX_Text(pDX, IDC_FRONT_VIEW_HEIGHT, m_fFrontViewHeight);
  118. DDX_Text(pDX, IDC_FRONT_VIEW_PICTURE_T, m_strFrontViewPicture);
  119. DDX_Text(pDX, IDC_FRONT_VIEW_WIDTH, m_fFrontViewWidth);
  120. DDX_Text(pDX, IDC_RIGHT_VIEW_CENTER_X, m_fRightViewCenterX);
  121. DDX_Text(pDX, IDC_RIGHT_VIEW_CENTER_Y, m_fRightViewCenterY);
  122. DDX_Text(pDX, IDC_RIGHT_VIEW_HEIGHT, m_fRightViewHeight);
  123. DDX_Text(pDX, IDC_RIGHT_VIEW_PICTURE_T, m_strRightViewPicture);
  124. DDX_Text(pDX, IDC_RIGHT_VIEW_WIDTH, m_fRightViewWidth);
  125. DDX_Text(pDX, IDC_TOP_VIEW_CENTER_X, m_fTopViewCenterX);
  126. DDX_Text(pDX, IDC_TOP_VIEW_CENTER_Y, m_fTopViewCenterY);
  127. DDX_Text(pDX, IDC_TOP_VIEW_HEIGHT, m_fTopViewHeight);
  128. DDX_Text(pDX, IDC_TOP_VIEW_PICTURE_T, m_strTopViewPicture);
  129. DDX_Text(pDX, IDC_TOP_VIEW_WIDTH, m_fTopViewWidth);
  130. DDX_Text(pDX, IDC_BACKDROP_OBJECT_T, m_strBackdropObject);
  131. DDX_Text(pDX, IDC_EDIT_LEVEL_NAME, m_strLevelName);
  132. //}}AFX_DATA_MAP
  133. // if dialog is giving data
  134. if( pDX->m_bSaveAndValidate != FALSE)
  135. {
  136. CWorldEditorDoc *pDoc = theApp.GetDocument();
  137. pDoc->m_woWorld.wo_strBackdropUp = CStringA(m_strTopViewPicture);
  138. pDoc->m_woWorld.wo_fUpW = m_fTopViewWidth;
  139. pDoc->m_woWorld.wo_fUpL = m_fTopViewHeight;
  140. pDoc->m_woWorld.wo_fUpCX = m_fTopViewCenterX;
  141. pDoc->m_woWorld.wo_fUpCZ = m_fTopViewCenterY;
  142. pDoc->m_woWorld.wo_strBackdropFt = CStringA(m_strFrontViewPicture);
  143. pDoc->m_woWorld.wo_fFtW = m_fFrontViewWidth;
  144. pDoc->m_woWorld.wo_fFtH = m_fFrontViewHeight;
  145. pDoc->m_woWorld.wo_fFtCX = m_fFrontViewCenterX;
  146. pDoc->m_woWorld.wo_fFtCY = m_fFrontViewCenterY;
  147. pDoc->m_woWorld.wo_strBackdropRt = CStringA(m_strRightViewPicture);
  148. pDoc->m_woWorld.wo_fRtL = m_fRightViewWidth;
  149. pDoc->m_woWorld.wo_fRtH = m_fRightViewHeight;
  150. pDoc->m_woWorld.wo_fRtCZ = m_fRightViewCenterX;
  151. pDoc->m_woWorld.wo_fRtCY = m_fRightViewCenterY;
  152. pDoc->m_woWorld.wo_strBackdropObject = CStringA(m_strBackdropObject);
  153. // try to load object for backdrops
  154. if( pDoc->m_woWorld.wo_strBackdropObject != "")
  155. {
  156. // try to
  157. try
  158. {
  159. pDoc->m_o3dBackdropObject.Clear();
  160. // load 3D object
  161. FLOATmatrix3D mStretch;
  162. mStretch.Diagonal(1.0f);
  163. pDoc->m_o3dBackdropObject.LoadAny3DFormat_t( pDoc->m_woWorld.wo_strBackdropObject, mStretch);
  164. }
  165. // catch and
  166. catch( char *strError)
  167. {
  168. // report errors
  169. AfxMessageBox( CString(strError));
  170. return;
  171. }
  172. }
  173. if( m_fnBackgroundPicture != "")
  174. {
  175. theApp.WriteProfileString( L"World editor prefs", L"Default background picture",
  176. m_fnBackgroundPicture);
  177. }
  178. char chrColor[ 16];
  179. sprintf( chrColor, "0x%08x", m_BackgroundColor.GetColor());
  180. _strupr( chrColor);
  181. theApp.WriteProfileString( L"World editor prefs", L"Default background color", CString(chrColor));
  182. pDoc->m_woWorld.SetName( CTString(CStringA(m_strLevelName)));
  183. // apply new spawn flags
  184. ULONG ulSpawnFlags = 0;
  185. DDX_SPAWN_FLAG_SET( SPF_EASY, IDC_EASY);
  186. DDX_SPAWN_FLAG_SET( SPF_NORMAL, IDC_NORMAL);
  187. DDX_SPAWN_FLAG_SET( SPF_HARD, IDC_HARD);
  188. DDX_SPAWN_FLAG_SET( SPF_EXTREME, IDC_EXTREME);
  189. DDX_SPAWN_FLAG_SET( SPF_EXTREME<<1, IDC_DIFFICULTY_1B);
  190. DDX_SPAWN_FLAG_SET( SPF_EXTREME<<2, IDC_DIFFICULTY_2B);
  191. DDX_SPAWN_FLAG_SET( SPF_EXTREME<<3, IDC_DIFFICULTY_3B);
  192. DDX_SPAWN_FLAG_SET( SPF_EXTREME<<4, IDC_DIFFICULTY_4B);
  193. DDX_SPAWN_FLAG_SET( SPF_EXTREME<<5, IDC_DIFFICULTY_5B);
  194. DDX_SPAWN_FLAG_SET( SPF_SINGLEPLAYER, IDC_SINGLE);
  195. DDX_SPAWN_FLAG_SET( SPF_DEATHMATCH, IDC_DEATHMATCH);
  196. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE, IDC_COOPERATIVE);
  197. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<1, IDC_GAME_MODE_1B);
  198. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<2, IDC_GAME_MODE_2B);
  199. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<3, IDC_GAME_MODE_3B);
  200. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<4, IDC_GAME_MODE_4B);
  201. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<5, IDC_GAME_MODE_5B);
  202. DDX_SPAWN_FLAG_SET( SPF_COOPERATIVE<<6, IDC_GAME_MODE_6B);
  203. pDoc->m_woWorld.SetSpawnFlags(ulSpawnFlags);
  204. }
  205. }
  206. BEGIN_MESSAGE_MAP(CDlgWorldSettings, CDialog)
  207. //{{AFX_MSG_MAP(CDlgWorldSettings)
  208. ON_BN_CLICKED(IDC_BROWSE_BACKGROUND_PICTURE, OnBrowseBackgroundPicture)
  209. ON_BN_CLICKED(IDC_BROWSE_FRONT_VIEW_PICTURE, OnBrowseFrontViewPicture)
  210. ON_BN_CLICKED(IDC_BROWSE_RIGHT_VIEW_PICTURE, OnBrowseRightViewPicture)
  211. ON_BN_CLICKED(IDC_BROWSE_TOP_VIEW_PICTURE, OnBrowseTopViewPicture)
  212. ON_BN_CLICKED(IDC_BROWSE_BACKDROP_OBJECT, OnBrowseBackdropObject)
  213. ON_BN_CLICKED(ID_APPLY, OnApply)
  214. //}}AFX_MSG_MAP
  215. END_MESSAGE_MAP()
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CDlgWorldSettings message handlers
  218. void CDlgWorldSettings::OnBrowseBackgroundPicture()
  219. {
  220. CTFileName fnChoosedFile = _EngineGUI.FileRequester( "Select background texture",
  221. FILTER_TEX FILTER_ALL FILTER_END, KEY_NAME_BACKGROUND_TEXTURE_DIR, "Textures\\Background");
  222. if( fnChoosedFile == "") return;
  223. // substract last two letters of background's file name
  224. char achrShortenedBcgName[ PATH_MAX];
  225. strcpy( achrShortenedBcgName, fnChoosedFile.FileDir()+fnChoosedFile.FileName());
  226. // there must be at least two letters in selected texture name
  227. if( strlen( achrShortenedBcgName) > 2)
  228. {
  229. // shorten file name for two letters
  230. achrShortenedBcgName[ strlen( achrShortenedBcgName)-2] = 0;
  231. // assign new background texture name
  232. m_fnBackgroundPicture = CTString(achrShortenedBcgName)+fnChoosedFile.FileExt();
  233. }
  234. // enable ok button
  235. //GetDlgItem( IDOK)->EnableWindow( TRUE);
  236. UpdateData( FALSE);
  237. }
  238. // setups background settings dialog
  239. void CDlgWorldSettings::SetupBcgSettings( BOOL bOnNewDocument)
  240. {
  241. char chrColor[ 16];
  242. COLOR colBackground;
  243. // if change bcg settings dialog was called on new document
  244. if( bOnNewDocument)
  245. {
  246. // obtain background color form INI file
  247. strcpy( chrColor, CStringA(theApp.GetProfileString( L"World editor prefs",
  248. L"Default background color", L"0XFF000000")));
  249. sscanf( chrColor, "0X%08x", &colBackground);
  250. // set background color to color button
  251. m_BackgroundColor.SetColor( colBackground);
  252. // set default texture for background
  253. m_fnBackgroundPicture = "Textures\\Editor\\Default.tex";
  254. // set default mission description
  255. m_strMissionDescription = "No mission description";
  256. }
  257. else
  258. {
  259. CWorldEditorDoc *pDoc = theApp.GetDocument();
  260. // obtain picture used for background from world
  261. m_fnBackgroundPicture = CTString(); //!!!!pDoc->m_woWorld.GetBackgroundTexture();
  262. // set world's background color to color button
  263. m_BackgroundColor.SetColor( pDoc->m_woWorld.GetBackgroundColor());
  264. // pick-up mission description from world
  265. m_strMissionDescription = pDoc->m_woWorld.GetDescription();
  266. }
  267. }
  268. BOOL CDlgWorldSettings::OnInitDialog()
  269. {
  270. CDialog::OnInitDialog();
  271. // call MFC color picker (windows)
  272. m_BackgroundColor.SetPickerType( CColoredButton::PT_MFC);
  273. return TRUE; // return TRUE unless you set the focus to a control
  274. // EXCEPTION: OCX Property Pages should return FALSE
  275. }
  276. void CDlgWorldSettings::OnBrowseTopViewPicture()
  277. {
  278. CTFileName fnPicture = _EngineGUI.FileRequester( "Picture for top view",
  279. FILTER_PICTURES FILTER_ALL FILTER_END, "Picture for view directory", "");
  280. if( fnPicture == "") return;
  281. GetDlgItem( IDC_TOP_VIEW_PICTURE_T)->SetWindowText( CString(fnPicture));
  282. m_strTopViewPicture = fnPicture;
  283. CWorldEditorDoc *pDoc = theApp.GetDocument();
  284. pDoc->SetupBackdropTextureObject( CTString(CStringA(m_strTopViewPicture)), pDoc->m_toBackdropUp);
  285. }
  286. void CDlgWorldSettings::OnBrowseFrontViewPicture()
  287. {
  288. CTFileName fnPicture = _EngineGUI.FileRequester( "Picture for front view",
  289. FILTER_PICTURES FILTER_ALL FILTER_END, "Picture for view directory", "");
  290. if( fnPicture == "") return;
  291. GetDlgItem( IDC_FRONT_VIEW_PICTURE_T)->SetWindowText( CString(fnPicture));
  292. m_strFrontViewPicture = fnPicture;
  293. CWorldEditorDoc *pDoc = theApp.GetDocument();
  294. pDoc->SetupBackdropTextureObject( CTString(CStringA(m_strFrontViewPicture)), pDoc->m_toBackdropFt);
  295. }
  296. void CDlgWorldSettings::OnBrowseRightViewPicture()
  297. {
  298. CTFileName fnPicture = _EngineGUI.FileRequester( "Picture for right view",
  299. FILTER_PICTURES FILTER_ALL FILTER_END, "Picture for view directory", "");
  300. if( fnPicture == "") return;
  301. GetDlgItem( IDC_RIGHT_VIEW_PICTURE_T)->SetWindowText( CString(fnPicture));
  302. m_strRightViewPicture = fnPicture;
  303. CWorldEditorDoc *pDoc = theApp.GetDocument();
  304. pDoc->SetupBackdropTextureObject( CTString(CStringA(m_strRightViewPicture)), pDoc->m_toBackdropRt);
  305. }
  306. void CDlgWorldSettings::OnBrowseBackdropObject()
  307. {
  308. CTFileName fnObject = _EngineGUI.FileRequester( "Select background object",
  309. FILTER_3DOBJ FILTER_LWO FILTER_OBJ FILTER_3DS FILTER_ALL FILTER_END, "Backdrop object directory", "");
  310. if( fnObject == "") return;
  311. GetDlgItem( IDC_BACKDROP_OBJECT_T)->SetWindowText( CString(fnObject));
  312. m_strBackdropObject = fnObject;
  313. }
  314. void CDlgWorldSettings::OnOK()
  315. {
  316. }
  317. void CDlgWorldSettings::OnApply()
  318. {
  319. CDialog::OnOK();
  320. }