SphereGeneralPropPage.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. // SphereGeneralPropPage.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "SphereGeneralPropPage.h"
  23. #include "utils.h"
  24. #include "assetmgr.h"
  25. #include "texture.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. IMPLEMENT_DYNCREATE(SphereGeneralPropPageClass, CPropertyPage)
  32. /////////////////////////////////////////////////////////////
  33. //
  34. // SphereGeneralPropPageClass
  35. //
  36. /////////////////////////////////////////////////////////////
  37. SphereGeneralPropPageClass::SphereGeneralPropPageClass (SphereRenderObjClass *sphere)
  38. : m_bValid (true),
  39. m_Lifetime (1.0F),
  40. m_RenderObj (sphere),
  41. CPropertyPage(SphereGeneralPropPageClass::IDD)
  42. {
  43. //{{AFX_DATA_INIT(SphereGeneralPropPageClass)
  44. // NOTE: the ClassWizard will add member initialization here
  45. //}}AFX_DATA_INIT
  46. Initialize ();
  47. return ;
  48. }
  49. /////////////////////////////////////////////////////////////
  50. //
  51. // ~SphereGeneralPropPageClass
  52. //
  53. /////////////////////////////////////////////////////////////
  54. SphereGeneralPropPageClass::~SphereGeneralPropPageClass()
  55. {
  56. return ;
  57. }
  58. void
  59. SphereGeneralPropPageClass::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CPropertyPage::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(SphereGeneralPropPageClass)
  63. DDX_Control(pDX, IDC_LIFETIME_SPIN, m_LifetimeSpin);
  64. //}}AFX_DATA_MAP
  65. return ;
  66. }
  67. BEGIN_MESSAGE_MAP(SphereGeneralPropPageClass, CPropertyPage)
  68. //{{AFX_MSG_MAP(SphereGeneralPropPageClass)
  69. ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton)
  70. ON_EN_CHANGE(IDC_FILENAME_EDIT, OnChangeFilenameEdit)
  71. ON_EN_CHANGE(IDC_NAME_EDIT, OnChangeNameEdit)
  72. ON_EN_CHANGE(IDC_LIFETIME_EDIT, OnChangeLifetimeEdit)
  73. ON_CBN_SELCHANGE(IDC_SHADER_COMBO, OnSelchangeShaderCombo)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////
  77. //
  78. // Initialize
  79. //
  80. /////////////////////////////////////////////////////////////
  81. void
  82. SphereGeneralPropPageClass::Initialize (void)
  83. {
  84. if (m_RenderObj != NULL) {
  85. //
  86. // Get the object's texture
  87. //
  88. TextureClass *texture = m_RenderObj->Peek_Texture ();
  89. if (texture != NULL) {
  90. m_TextureFilename = texture->Get_Texture_Name();
  91. }
  92. //
  93. // Get the other misc data we care about
  94. //
  95. m_Lifetime = m_RenderObj->Get_Animation_Duration ();
  96. m_Name = m_RenderObj->Get_Name ();
  97. m_Shader = m_RenderObj->Get_Shader ();
  98. }
  99. return ;
  100. }
  101. /////////////////////////////////////////////////////////////
  102. //
  103. // Add_Shader_To_Combo
  104. //
  105. /////////////////////////////////////////////////////////////
  106. void
  107. SphereGeneralPropPageClass::Add_Shader_To_Combo
  108. (
  109. ShaderClass & shader,
  110. LPCTSTR name
  111. )
  112. {
  113. int index = SendDlgItemMessage (IDC_SHADER_COMBO, CB_ADDSTRING, 0, (LPARAM)name);
  114. if (index != CB_ERR) {
  115. SendDlgItemMessage (IDC_SHADER_COMBO, CB_SETITEMDATA, (WPARAM)index, (LPARAM)&shader);
  116. //
  117. // Is the blend mode of this shader the same as that of the
  118. // object's shader.
  119. //
  120. if ((shader.Get_Alpha_Test () == m_Shader.Get_Alpha_Test ()) &&
  121. (shader.Get_Dst_Blend_Func () == m_Shader.Get_Dst_Blend_Func ()) &&
  122. (shader.Get_Src_Blend_Func () == m_Shader.Get_Src_Blend_Func ()))
  123. {
  124. SendDlgItemMessage (IDC_SHADER_COMBO, CB_SETCURSEL, (WPARAM)index);
  125. }
  126. }
  127. return ;
  128. }
  129. /////////////////////////////////////////////////////////////
  130. //
  131. // OnInitDialog
  132. //
  133. /////////////////////////////////////////////////////////////
  134. BOOL
  135. SphereGeneralPropPageClass::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::_PresetAdditiveShader, "Additive");
  143. Add_Shader_To_Combo (ShaderClass::_PresetAlphaShader, "Alpha");
  144. Add_Shader_To_Combo (ShaderClass::_PresetOpaqueShader, "Opaque");
  145. Add_Shader_To_Combo (ShaderClass::_PresetMultiplicativeShader, "Multiplicative");
  146. CheckDlgButton (IDC_CAMERA_ALIGNED_CHECK, (m_RenderObj->Get_Flags () & SphereRenderObjClass::USE_CAMERA_ALIGN) != 0);
  147. CheckDlgButton (IDC_LOOPING_CHECK, (m_RenderObj->Get_Flags () & SphereRenderObjClass::USE_ANIMATION_LOOP) != 0);
  148. //
  149. // Fill the edit controls with the default values
  150. //
  151. SetDlgItemText (IDC_NAME_EDIT, m_Name);
  152. SetDlgItemText (IDC_FILENAME_EDIT, m_TextureFilename);
  153. //
  154. // Initialize the lifetime control
  155. //
  156. ::Initialize_Spinner (m_LifetimeSpin, m_Lifetime, 0, 1000);
  157. return TRUE;
  158. }
  159. /////////////////////////////////////////////////////////////
  160. //
  161. // OnApply
  162. //
  163. /////////////////////////////////////////////////////////////
  164. BOOL
  165. SphereGeneralPropPageClass::OnApply (void)
  166. {
  167. // Get the data from the dialog controls
  168. GetDlgItemText (IDC_NAME_EDIT, m_Name);
  169. GetDlgItemText (IDC_FILENAME_EDIT, m_TextureFilename);
  170. m_Lifetime = ::GetDlgItemFloat (m_hWnd, IDC_LIFETIME_EDIT);
  171. //
  172. // Get the shader from the combobox
  173. //
  174. int index = SendDlgItemMessage (IDC_SHADER_COMBO, CB_GETCURSEL);
  175. if (index != CB_ERR) {
  176. ShaderClass *shader = (ShaderClass *)SendDlgItemMessage (IDC_SHADER_COMBO, CB_GETITEMDATA, (WPARAM)index);
  177. if (shader != NULL) {
  178. m_Shader = (*shader);
  179. }
  180. }
  181. // Check to make sure the user entered a valid name for the object
  182. BOOL retval = FALSE;
  183. if (m_Name.GetLength () == 0) {
  184. ::MessageBox (m_hWnd, "Invalid sphere name. Please enter a new name.", "Invalid settings", MB_ICONEXCLAMATION | MB_OK);
  185. m_bValid = false;
  186. } else {
  187. //
  188. // Create a texture and pass it onto the object
  189. //
  190. TextureClass *texture = NULL;
  191. if (m_TextureFilename.GetLength () > 0) {
  192. texture = WW3DAssetManager::Get_Instance ()->Get_Texture (::Get_Filename_From_Path (m_TextureFilename));
  193. }
  194. m_RenderObj->Set_Texture (texture);
  195. REF_PTR_RELEASE (texture);
  196. //
  197. // Apply the changes to the emitter
  198. //
  199. m_RenderObj->Set_Name (m_Name);
  200. m_RenderObj->Set_Shader (m_Shader);
  201. m_RenderObj->Set_Animation_Duration (m_Lifetime);
  202. m_RenderObj->Set_Flag (SphereRenderObjClass::USE_CAMERA_ALIGN, IsDlgButtonChecked (IDC_CAMERA_ALIGNED_CHECK) != 0);
  203. m_RenderObj->Set_Flag (SphereRenderObjClass::USE_ANIMATION_LOOP, IsDlgButtonChecked (IDC_LOOPING_CHECK) != 0);
  204. // Allow the base class to process this message
  205. retval = CPropertyPage::OnApply ();
  206. m_bValid = true;
  207. }
  208. // Return the TRUE/FALSE result code
  209. return retval;
  210. }
  211. /////////////////////////////////////////////////////////////
  212. //
  213. // OnBrowseButton
  214. //
  215. /////////////////////////////////////////////////////////////
  216. void
  217. SphereGeneralPropPageClass::OnBrowseButton (void)
  218. {
  219. CFileDialog dialog ( TRUE,
  220. ".tga",
  221. NULL,
  222. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  223. "Textures files (*.tga)|*.tga||",
  224. ::AfxGetMainWnd ());
  225. // Ask the user what texture file they wish to load
  226. if (dialog.DoModal () == IDOK) {
  227. SetDlgItemText (IDC_FILENAME_EDIT, dialog.GetPathName ());
  228. SetModified ();
  229. }
  230. return ;
  231. }
  232. /////////////////////////////////////////////////////////////
  233. //
  234. // OnChangeFilenameEdit
  235. //
  236. /////////////////////////////////////////////////////////////
  237. void
  238. SphereGeneralPropPageClass::OnChangeFilenameEdit (void)
  239. {
  240. SetModified ();
  241. return ;
  242. }
  243. /////////////////////////////////////////////////////////////
  244. //
  245. // OnChangeNameEdit
  246. //
  247. /////////////////////////////////////////////////////////////
  248. void
  249. SphereGeneralPropPageClass::OnChangeNameEdit (void)
  250. {
  251. SetModified ();
  252. return ;
  253. }
  254. /////////////////////////////////////////////////////////////
  255. //
  256. // OnNotify
  257. //
  258. /////////////////////////////////////////////////////////////
  259. BOOL
  260. SphereGeneralPropPageClass::OnNotify
  261. (
  262. WPARAM wParam,
  263. LPARAM lParam,
  264. LRESULT * pResult
  265. )
  266. {
  267. //
  268. // Update the spinner control if necessary
  269. //
  270. NMHDR *header = (NMHDR *)lParam;
  271. if ((header != NULL) && (header->code == UDN_DELTAPOS)) {
  272. LPNMUPDOWN updown = (LPNMUPDOWN)lParam;
  273. ::Update_Spinner_Buddy (header->hwndFrom, updown->iDelta);
  274. }
  275. // Allow the base class to process this message
  276. return CPropertyPage::OnNotify (wParam, lParam, pResult);
  277. }
  278. /////////////////////////////////////////////////////////////
  279. //
  280. // OnChangeLifetimeEdit
  281. //
  282. /////////////////////////////////////////////////////////////
  283. void
  284. SphereGeneralPropPageClass::OnChangeLifetimeEdit (void)
  285. {
  286. SetModified ();
  287. return ;
  288. }
  289. /////////////////////////////////////////////////////////////
  290. //
  291. // OnSelchangeShaderCombo
  292. //
  293. /////////////////////////////////////////////////////////////
  294. void
  295. SphereGeneralPropPageClass::OnSelchangeShaderCombo (void)
  296. {
  297. SetModified ();
  298. return ;
  299. }
  300. /////////////////////////////////////////////////////////////
  301. //
  302. // OnCommand
  303. //
  304. /////////////////////////////////////////////////////////////
  305. BOOL
  306. SphereGeneralPropPageClass::OnCommand
  307. (
  308. WPARAM wParam,
  309. LPARAM lParam
  310. )
  311. {
  312. switch (LOWORD (wParam))
  313. {
  314. case IDC_FILENAME_EDIT:
  315. case IDC_NAME_EDIT:
  316. case IDC_LIFETIME_EDIT:
  317. if (HIWORD (lParam) == EN_CHANGE) {
  318. SetModified ();
  319. }
  320. break;
  321. case IDC_LOOPING_CHECK:
  322. case IDC_CAMERA_ALIGNED_CHECK:
  323. SetModified ();
  324. break;
  325. }
  326. return CPropertyPage::OnCommand(wParam, lParam);
  327. }