RingGeneralPropPage.cpp 10 KB

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