EmitterGeneralPropPage.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. // EmitterGeneralPropPage.cpp : implementation file
  19. //
  20. #include "StdAfx.H"
  21. #include "W3DView.H"
  22. #include "EmitterGeneralPropPage.H"
  23. #include "EmitterPropertySheet.H"
  24. #include "Part_Emt.H"
  25. #include "Utils.H"
  26. #include "texture.h"
  27. #include "Shader.H"
  28. #include "EmitterInstanceList.H"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. /////////////////////////////////////////////////////////////////////////////
  35. // EmitterGeneralPropPageClass property page
  36. IMPLEMENT_DYNCREATE(EmitterGeneralPropPageClass, CPropertyPage)
  37. /////////////////////////////////////////////////////////////
  38. //
  39. // EmitterGeneralPropPageClass
  40. //
  41. EmitterGeneralPropPageClass::EmitterGeneralPropPageClass (EmitterInstanceListClass *pemitter)
  42. : m_pEmitterList (NULL),
  43. m_Parent (NULL),
  44. m_bValid (true),
  45. m_Lifetime (0),
  46. CPropertyPage(EmitterGeneralPropPageClass::IDD)
  47. {
  48. //{{AFX_DATA_INIT(EmitterGeneralPropPageClass)
  49. //}}AFX_DATA_INIT
  50. Initialize ();
  51. return ;
  52. }
  53. /////////////////////////////////////////////////////////////
  54. //
  55. // ~EmitterGeneralPropPageClass
  56. //
  57. EmitterGeneralPropPageClass::~EmitterGeneralPropPageClass (void)
  58. {
  59. return;
  60. }
  61. /////////////////////////////////////////////////////////////
  62. //
  63. // DoDataExchange
  64. //
  65. void
  66. EmitterGeneralPropPageClass::DoDataExchange (CDataExchange* pDX)
  67. {
  68. // Allow the base class to process this message
  69. CPropertyPage::DoDataExchange(pDX);
  70. //{{AFX_DATA_MAP(EmitterGeneralPropPageClass)
  71. DDX_Control(pDX, IDC_RENDER_MODE_COMBO, m_RenderModeCombo);
  72. DDX_Control(pDX, IDC_PARTICLE_LIFETIME_SPIN, m_LifetimeSpin);
  73. //}}AFX_DATA_MAP
  74. return ;
  75. }
  76. BEGIN_MESSAGE_MAP(EmitterGeneralPropPageClass, CPropertyPage)
  77. //{{AFX_MSG_MAP(EmitterGeneralPropPageClass)
  78. ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton)
  79. ON_EN_CHANGE(IDC_FILENAME_EDIT, OnChangeFilenameEdit)
  80. ON_EN_CHANGE(IDC_NAME_EDIT, OnChangeNameEdit)
  81. ON_EN_CHANGE(IDC_PARTICLE_LIFETIME_EDIT, OnChangeParticleLifetimeEdit)
  82. ON_CBN_SELCHANGE(IDC_SHADER_COMBO, OnSelchangeShaderCombo)
  83. ON_BN_CLICKED(IDC_PARTICLE_LIFETIME_CHECK, OnParticleLifetimeCheck)
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. /////////////////////////////////////////////////////////////
  87. //
  88. // Initialize
  89. //
  90. void
  91. EmitterGeneralPropPageClass::Initialize (void)
  92. {
  93. if (m_pEmitterList != NULL) {
  94. //
  95. // Get the emitter's texture
  96. //
  97. m_TextureFilename = m_pEmitterList->Get_Texture_Filename ();
  98. m_Lifetime = m_pEmitterList->Get_Lifetime ();
  99. m_EmitterName = m_pEmitterList->Get_Name ();
  100. m_pEmitterList->Get_Shader (m_Shader);
  101. }
  102. return ;
  103. }
  104. /////////////////////////////////////////////////////////////
  105. //
  106. // Add_Shader_To_Combo
  107. //
  108. void
  109. EmitterGeneralPropPageClass::Add_Shader_To_Combo
  110. (
  111. ShaderClass &shader,
  112. LPCTSTR name
  113. )
  114. {
  115. int index = SendDlgItemMessage (IDC_SHADER_COMBO, CB_ADDSTRING, 0, (LPARAM)name);
  116. if (index != CB_ERR) {
  117. SendDlgItemMessage (IDC_SHADER_COMBO, CB_SETITEMDATA, (WPARAM)index, (LPARAM)&shader);
  118. //
  119. // Is the blend mode of this shader the same as that of the
  120. // particle emitter's shader.
  121. //
  122. if ((shader.Get_Alpha_Test () == m_Shader.Get_Alpha_Test ()) &&
  123. (shader.Get_Dst_Blend_Func () == m_Shader.Get_Dst_Blend_Func ()) &&
  124. (shader.Get_Src_Blend_Func () == m_Shader.Get_Src_Blend_Func ())) {
  125. SendDlgItemMessage (IDC_SHADER_COMBO, CB_SETCURSEL, (WPARAM)index);
  126. }
  127. }
  128. return ;
  129. }
  130. /////////////////////////////////////////////////////////////
  131. //
  132. // OnInitDialog
  133. //
  134. BOOL
  135. EmitterGeneralPropPageClass::OnInitDialog (void)
  136. {
  137. // Allow the base class to process this message
  138. CPropertyPage::OnInitDialog ();
  139. //
  140. // Add the known shaders to the combobox
  141. //
  142. Add_Shader_To_Combo (ShaderClass::_PresetAdditiveSpriteShader, "Additive");
  143. Add_Shader_To_Combo (ShaderClass::_PresetAlphaSpriteShader, "Alpha");
  144. Add_Shader_To_Combo (ShaderClass::_PresetATestSpriteShader, "Alpha-Test");
  145. Add_Shader_To_Combo (ShaderClass::_PresetATestBlendSpriteShader, "Alpha-Test-Blend");
  146. Add_Shader_To_Combo (ShaderClass::_PresetScreenSpriteShader, "Screen");
  147. Add_Shader_To_Combo (ShaderClass::_PresetMultiplicativeSpriteShader, "Multiplicative");
  148. Add_Shader_To_Combo (ShaderClass::_PresetOpaqueSpriteShader, "Opaque");
  149. //
  150. // Fill the edit controls with the default values
  151. //
  152. SetDlgItemText (IDC_NAME_EDIT, m_EmitterName);
  153. SetDlgItemText (IDC_FILENAME_EDIT, m_TextureFilename);
  154. //
  155. // Initialize the lifetime control
  156. //
  157. SendDlgItemMessage (IDC_PARTICLE_LIFETIME_CHECK, BM_SETCHECK, (WPARAM)(m_Lifetime < 100));
  158. if (m_Lifetime > 100) {
  159. m_Lifetime = 0;
  160. }
  161. ::Initialize_Spinner (m_LifetimeSpin, m_Lifetime, 0, 1000);
  162. OnParticleLifetimeCheck ();
  163. //
  164. // Initialize the render mode combo
  165. //
  166. m_RenderModeCombo.SetCurSel(m_pEmitterList->Get_Render_Mode());
  167. return TRUE;
  168. }
  169. /////////////////////////////////////////////////////////////
  170. //
  171. // OnApply
  172. //
  173. BOOL
  174. EmitterGeneralPropPageClass::OnApply (void)
  175. {
  176. // Get the data from the dialog controls
  177. GetDlgItemText (IDC_NAME_EDIT, m_EmitterName);
  178. GetDlgItemText (IDC_FILENAME_EDIT, m_TextureFilename);
  179. m_Lifetime = ::GetDlgItemFloat (m_hWnd, IDC_PARTICLE_LIFETIME_EDIT);
  180. if (SendDlgItemMessage (IDC_PARTICLE_LIFETIME_CHECK, BM_GETCHECK) == 0) {
  181. m_Lifetime = 5000000.0F;
  182. }
  183. //
  184. // Get the shader from the combobox
  185. //
  186. int index = SendDlgItemMessage (IDC_SHADER_COMBO, CB_GETCURSEL);
  187. if (index != CB_ERR) {
  188. ShaderClass *shader = (ShaderClass *)SendDlgItemMessage (IDC_SHADER_COMBO, CB_GETITEMDATA, (WPARAM)index);
  189. if (shader != NULL) {
  190. m_Shader = (*shader);
  191. }
  192. }
  193. // Check to make sure the user entered a valid name for the emitter.
  194. BOOL retval = FALSE;
  195. if (m_EmitterName.GetLength () == 0) {
  196. ::MessageBox (m_hWnd, "Invalid emitter name. Please enter a new name.", "Invalid settings", MB_ICONEXCLAMATION | MB_OK);
  197. m_bValid = false;
  198. } else {
  199. //
  200. // Apply the changes to the emitter
  201. //
  202. m_pEmitterList->Set_Lifetime (m_Lifetime);
  203. m_pEmitterList->Set_Texture_Filename (m_TextureFilename);
  204. m_pEmitterList->Set_Name (m_EmitterName);
  205. m_pEmitterList->Set_Shader (m_Shader);
  206. m_pEmitterList->Set_Render_Mode (m_RenderModeCombo.GetCurSel());
  207. // Allow the base class to process this message
  208. retval = CPropertyPage::OnApply ();
  209. m_bValid = true;
  210. }
  211. // Return the TRUE/FALSE result code
  212. return retval;
  213. }
  214. /////////////////////////////////////////////////////////////
  215. //
  216. // OnBrowseButton
  217. //
  218. void
  219. EmitterGeneralPropPageClass::OnBrowseButton (void)
  220. {
  221. CFileDialog openFileDialog (TRUE,
  222. ".tga",
  223. NULL,
  224. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  225. "Textures files (*.tga)|*.tga||",
  226. ::AfxGetMainWnd ());
  227. // Ask the user what texture file they wish to load
  228. if (openFileDialog.DoModal () == IDOK) {
  229. SetDlgItemText (IDC_FILENAME_EDIT, openFileDialog.GetPathName ());
  230. SetModified ();
  231. }
  232. return ;
  233. }
  234. /////////////////////////////////////////////////////////////
  235. //
  236. // OnChangeFilenameEdit
  237. //
  238. void
  239. EmitterGeneralPropPageClass::OnChangeFilenameEdit (void)
  240. {
  241. SetModified ();
  242. return ;
  243. }
  244. /////////////////////////////////////////////////////////////
  245. //
  246. // OnChangeNameEdit
  247. //
  248. void
  249. EmitterGeneralPropPageClass::OnChangeNameEdit (void)
  250. {
  251. SetModified ();
  252. return ;
  253. }
  254. /////////////////////////////////////////////////////////////
  255. //
  256. // OnNotify
  257. //
  258. BOOL
  259. EmitterGeneralPropPageClass::OnNotify
  260. (
  261. WPARAM wParam,
  262. LPARAM lParam,
  263. LRESULT *pResult
  264. )
  265. {
  266. //
  267. // Update the spinner control if necessary
  268. //
  269. NMHDR *pheader = (NMHDR *)lParam;
  270. if ((pheader != NULL) && (pheader->code == UDN_DELTAPOS)) {
  271. LPNMUPDOWN pupdown = (LPNMUPDOWN)lParam;
  272. ::Update_Spinner_Buddy (pheader->hwndFrom, pupdown->iDelta);
  273. }
  274. // Allow the base class to process this message
  275. return CPropertyPage::OnNotify (wParam, lParam, pResult);
  276. }
  277. /////////////////////////////////////////////////////////////
  278. //
  279. // OnChangeParticleLifetimeEdit
  280. //
  281. void
  282. EmitterGeneralPropPageClass::OnChangeParticleLifetimeEdit (void)
  283. {
  284. SetModified ();
  285. return ;
  286. }
  287. /////////////////////////////////////////////////////////////
  288. //
  289. // OnSelchangeShaderCombo
  290. //
  291. void
  292. EmitterGeneralPropPageClass::OnSelchangeShaderCombo (void)
  293. {
  294. SetModified ();
  295. return ;
  296. }
  297. /////////////////////////////////////////////////////////////
  298. //
  299. // OnCommand
  300. //
  301. BOOL
  302. EmitterGeneralPropPageClass::OnCommand
  303. (
  304. WPARAM wParam,
  305. LPARAM lParam
  306. )
  307. {
  308. switch (LOWORD (wParam)) {
  309. case IDC_FILENAME_EDIT:
  310. case IDC_NAME_EDIT:
  311. case IDC_PARTICLE_LIFETIME_EDIT:
  312. if (HIWORD (wParam) == EN_CHANGE) {
  313. SetModified ();
  314. }
  315. break;
  316. case IDC_PARTICLE_LIFETIME_CHECK:
  317. if (HIWORD (wParam) == BN_CLICKED) {
  318. SetModified ();
  319. }
  320. break;
  321. case IDC_RENDER_MODE_COMBO:
  322. if (HIWORD (wParam) == CBN_SELCHANGE) {
  323. SetModified ();
  324. if (m_Parent != NULL) {
  325. int cur_mode = ::SendMessage ((HWND)lParam, CB_GETCURSEL, 0, 0);
  326. m_Parent->Notify_Render_Mode_Changed(cur_mode);
  327. }
  328. }
  329. break;
  330. }
  331. return CPropertyPage::OnCommand(wParam, lParam);
  332. }
  333. /////////////////////////////////////////////////////////////
  334. //
  335. // OnParticleLifetimeCheck
  336. //
  337. /////////////////////////////////////////////////////////////
  338. void
  339. EmitterGeneralPropPageClass::OnParticleLifetimeCheck (void)
  340. {
  341. bool enable = (SendDlgItemMessage (IDC_PARTICLE_LIFETIME_CHECK, BM_GETCHECK) == 1);
  342. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_PARTICLE_LIFETIME_EDIT), enable);
  343. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_PARTICLE_LIFETIME_SPIN), enable);
  344. if (enable == false) {
  345. m_Lifetime = 0;
  346. ::SetDlgItemFloat (m_hWnd, IDC_PARTICLE_LIFETIME_EDIT, 0);
  347. }
  348. SetModified ();
  349. return ;
  350. }