GameMtlPassDlg.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Max2W3d *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/GameMtlPassDlg.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 3/13/02 10:30a $*
  29. * *
  30. * $Revision:: 22 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * PassDlgProc -- dialog proc which thunks into a GameMtlPassDlg *
  35. * GameMtlPassDlg::GameMtlPassDlg -- constructor *
  36. * GameMtlPassDlg::~GameMtlPassDlg -- destructor *
  37. * GameMtlPassDlg::DialogProc -- windows message handler *
  38. * GameMtlPassDlg::Invalidate -- invalidate the dialog *
  39. * GameMtlPassDlg::ReloadDialog -- update the contents of all of the controls *
  40. * GameMtlPassDlg::ClassID -- returns classID of the object being edited *
  41. * GameMtlPassDlg::SetThing -- set the material being edited *
  42. * GameMtlPassDlg::ActivateDlg -- activate or deactivate the dialog *
  43. * GameMtlPassDlg::SetTime -- set the current time *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #include "GameMtlPassDlg.h"
  46. #include "dllmain.h"
  47. #include "resource.h"
  48. #include "GameMtl.h"
  49. #include "GameMtlDlg.h"
  50. #include "GMaxMtlDlg.h"
  51. #include "GameMtlShaderDlg.h"
  52. #include "PS2GameMtlShaderDlg.h"
  53. #include "GameMtlTextureDlg.h"
  54. #include "GameMtlVertexMaterialDlg.h"
  55. #include "w3d_file.h"
  56. static int _Pass_Index_To_Flag[] =
  57. {
  58. GAMEMTL_PASS0_ROLLUP_OPEN,
  59. GAMEMTL_PASS1_ROLLUP_OPEN,
  60. GAMEMTL_PASS2_ROLLUP_OPEN,
  61. GAMEMTL_PASS3_ROLLUP_OPEN,
  62. };
  63. extern GMaxMtlDlg * GMaxMaterialDialog;
  64. extern bool _UsingLargeFonts;
  65. /***********************************************************************************************
  66. * PassDlgProc -- dialog proc which thunks into a GameMtlPassDlg *
  67. * *
  68. * INPUT: *
  69. * *
  70. * OUTPUT: *
  71. * *
  72. * WARNINGS: *
  73. * *
  74. * HISTORY: *
  75. * 11/23/98 GTH : Created. *
  76. *=============================================================================================*/
  77. static BOOL CALLBACK PassDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  78. {
  79. GameMtlPassDlg *theDlg;
  80. if (msg==WM_INITDIALOG) {
  81. #if defined W3D_GMAXDEV
  82. lParam = ((PROPSHEETPAGE*)lParam)->lParam;
  83. #endif
  84. theDlg = (GameMtlPassDlg*)lParam;
  85. theDlg->HwndPanel = hwndDlg;
  86. SetWindowLong(hwndDlg, GWL_USERDATA,lParam);
  87. } else {
  88. if ((theDlg = (GameMtlPassDlg *)GetWindowLong(hwndDlg, GWL_USERDATA) ) == NULL) {
  89. return FALSE;
  90. }
  91. }
  92. return theDlg->DialogProc(hwndDlg,msg,wParam,lParam);
  93. }
  94. /***********************************************************************************************
  95. * GameMtlPassDlg::GameMtlPassDlg -- constructor *
  96. * *
  97. * INPUT: *
  98. * *
  99. * OUTPUT: *
  100. * *
  101. * WARNINGS: *
  102. * *
  103. * HISTORY: *
  104. * 11/23/98 GTH : Created. *
  105. *=============================================================================================*/
  106. GameMtlPassDlg::GameMtlPassDlg(HWND hwMtlEdit, IMtlParams *imp, GameMtl *m,int pass)
  107. {
  108. HwndEdit = hwMtlEdit;
  109. TheMtl = m;
  110. IParams = imp;
  111. PassIndex = pass;
  112. char title[200];
  113. sprintf(title, "Pass %d", pass + 1);
  114. #if !defined W3D_GMAXDEV
  115. HwndPanel = IParams->AddRollupPage(
  116. AppInstance,
  117. MAKEINTRESOURCE(IDD_GAMEMTL_PASS),
  118. PassDlgProc,
  119. title,
  120. (LPARAM)this,
  121. TheMtl->Get_Flag(_Pass_Index_To_Flag[PassIndex]) ? 0 : APPENDROLL_CLOSED
  122. );
  123. #else
  124. PROPSHEETPAGE ps_Page;
  125. ps_Page.dwSize = sizeof(PROPSHEETPAGE);
  126. ps_Page.dwFlags = PSP_USEICONID | PSP_USETITLE;
  127. ps_Page.hInstance = AppInstance;
  128. if(_UsingLargeFonts){
  129. ps_Page.pszTemplate= MAKEINTRESOURCE(IDD_GMAXMTL_PASS);
  130. }else{
  131. ps_Page.pszTemplate= MAKEINTRESOURCE(IDD_GMAXMTL_PASS_SMALL);
  132. }
  133. ps_Page.pszIcon = MAKEINTRESOURCE(IDI_ICONW3D);
  134. ps_Page.pfnDlgProc = PassDlgProc;
  135. ps_Page.pszTitle = title;
  136. ps_Page.lParam = (LPARAM)this;
  137. ps_Page.pfnCallback= NULL;
  138. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&ps_Page);
  139. PropSheet_AddPage(HwndEdit,hPage);
  140. HwndPanel = HwndEdit;
  141. #endif
  142. }
  143. /***********************************************************************************************
  144. * GameMtlPassDlg::~GameMtlPassDlg -- destructor *
  145. * *
  146. * INPUT: *
  147. * *
  148. * OUTPUT: *
  149. * *
  150. * WARNINGS: *
  151. * *
  152. * HISTORY: *
  153. * 11/23/98 GTH : Created. *
  154. *=============================================================================================*/
  155. GameMtlPassDlg::~GameMtlPassDlg()
  156. {
  157. #if ! defined W3D_GMAXDEV
  158. TheMtl->Set_Flag(_Pass_Index_To_Flag[PassIndex],IParams->IsRollupPanelOpen(HwndPanel));
  159. IParams->DeleteRollupPage(HwndPanel);
  160. #endif
  161. SetWindowLong(HwndPanel, GWL_USERDATA, NULL);
  162. }
  163. /***********************************************************************************************
  164. * GameMtlPassDlg::DialogProc -- windows message handler *
  165. * *
  166. * INPUT: *
  167. * *
  168. * OUTPUT: *
  169. * *
  170. * WARNINGS: *
  171. * *
  172. * HISTORY: *
  173. * 11/23/98 GTH : Created. *
  174. *=============================================================================================*/
  175. BOOL GameMtlPassDlg::DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  176. {
  177. int i=0;
  178. int id = LOWORD(wParam);
  179. int code = HIWORD(wParam);
  180. switch (message) {
  181. case WM_INITDIALOG:{
  182. #if defined W3D_GMAXDEV
  183. GMaxMaterialDialog->LoadButtonBitmaps(hDlg);
  184. #endif
  185. Page[0] = new GameMtlVertexMaterialDlg(HwndPanel,IParams,TheMtl,PassIndex);
  186. if (TheMtl->Get_Shader_Type() == GameMtl::STE_PC_SHADER) {
  187. Page[1] = new GameMtlShaderDlg(HwndPanel,IParams,TheMtl,PassIndex);
  188. } else {
  189. // The PS2 shader is different.
  190. Page[1] = new PS2GameMtlShaderDlg(HwndPanel,IParams,TheMtl,PassIndex);
  191. }
  192. Page[2] = new GameMtlTextureDlg(HwndPanel,IParams,TheMtl,PassIndex);
  193. for (i=0; i<PAGE_COUNT; i++) {
  194. HWND hwnd = Page[i]->Get_Hwnd();
  195. // set the tab names
  196. char name[64];
  197. ::GetWindowText(hwnd,name,sizeof(name));
  198. TC_ITEM tcitem = { TCIF_TEXT,0,0,name,0 };
  199. TabCtrl_InsertItem(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),i,&tcitem);
  200. }
  201. // Get the display rectangle of the tab control
  202. RECT rect;
  203. ::GetWindowRect(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),&rect);
  204. TabCtrl_AdjustRect(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),FALSE, &rect);
  205. // Convert the display rectangle from screen to client coords
  206. ScreenToClient(HwndPanel,(POINT *)(&rect));
  207. ScreenToClient(HwndPanel, ((LPPOINT)&rect) + 1);
  208. for (i=0; i<PAGE_COUNT; i++) {
  209. HWND hwnd = Page[i]->Get_Hwnd();
  210. // Loop through all the tabs in the property sheet
  211. // Get a pointer to this tab
  212. SetWindowPos( hwnd,
  213. NULL,
  214. rect.left, rect.top,
  215. rect.right - rect.left, rect.bottom - rect.top,
  216. SWP_NOZORDER);
  217. }
  218. CurPage = 0;
  219. TabCtrl_SetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),CurPage);
  220. Page[CurPage]->Show();
  221. break;
  222. }
  223. case WM_PAINT:
  224. {
  225. #if defined W3D_GMAXDEV
  226. if (!Valid) {
  227. Valid = TRUE;
  228. }
  229. ReloadDialog();
  230. #else
  231. if (!Valid) {
  232. Valid = TRUE;
  233. ReloadDialog();
  234. }
  235. #endif
  236. return FALSE;
  237. }
  238. case WM_NOTIFY:{
  239. NMHDR * header = (NMHDR *)lParam;
  240. switch(header->code) {
  241. case TCN_SELCHANGE:{
  242. int sel = TabCtrl_GetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB));
  243. Page[sel]->Show();
  244. for (int i=0; i < PAGE_COUNT; i++) {
  245. if (i != sel) Page[i]->Show(false);
  246. }
  247. CurPage = sel;
  248. TheMtl->Set_Current_Page(PassIndex,CurPage);
  249. break;
  250. }
  251. #if defined W3D_GMAXDEV
  252. case PSN_RESET:{
  253. SetWindowLong(hDlg,DWL_MSGRESULT,FALSE);
  254. ::SendMessage(hDlg, WM_USER+140,0,0);
  255. return FALSE;
  256. }
  257. case PSN_SETACTIVE:{
  258. GMaxMaterialDialog->SetCurrentPage(PassIndex+1);
  259. if(GMaxMaterialDialog->HasMultiMtl()){
  260. ShowWindow(GetDlgItem(hDlg,IDC_NEXTSIBLING),SW_SHOW);
  261. ShowWindow(GetDlgItem(hDlg,IDC_PREVIOUSSIBLING),SW_SHOW);
  262. }else{
  263. ShowWindow(GetDlgItem(hDlg,IDC_NEXTSIBLING),SW_HIDE);
  264. ShowWindow(GetDlgItem(hDlg,IDC_PREVIOUSSIBLING),SW_HIDE);
  265. }
  266. return TRUE;
  267. }
  268. #endif
  269. }
  270. break;
  271. }
  272. #if defined W3D_GMAXDEV
  273. case WM_USER+140:{
  274. ShowWindow(HwndEdit, SW_HIDE);
  275. return FALSE;
  276. }
  277. case WM_COMMAND:{
  278. switch(LOWORD(wParam)){
  279. case IDC_GETMTL:{
  280. GMaxMaterialDialog->DoGetMaterial();
  281. break;
  282. }
  283. case IDC_NEWMTL:{
  284. GMaxMaterialDialog->DoNewMaterial();
  285. break;
  286. }
  287. case IDC_NAVIGATOR:{
  288. GMaxMaterialDialog->DoMaterialNavigator();
  289. break;
  290. }
  291. case IDC_ASSIGN:{
  292. GMaxMaterialDialog->ApplyToSelection(TheMtl);
  293. break;
  294. }
  295. case IDC_DELETEMTL:{
  296. GMaxMaterialDialog->DeleteMtl();
  297. break;
  298. }
  299. case IDC_NEXTSIBLING:{
  300. GMaxMaterialDialog->NextSibling();
  301. break;
  302. }
  303. case IDC_PREVIOUSSIBLING:{
  304. GMaxMaterialDialog->PreviousSibling();
  305. break;
  306. }
  307. }
  308. break;
  309. }
  310. #endif
  311. }
  312. return FALSE;
  313. }
  314. /***********************************************************************************************
  315. * GameMtlPassDlg::Invalidate -- invalidate the dialog *
  316. * *
  317. * INPUT: *
  318. * *
  319. * OUTPUT: *
  320. * *
  321. * WARNINGS: *
  322. * *
  323. * HISTORY: *
  324. * 11/23/98 GTH : Created. *
  325. *=============================================================================================*/
  326. void GameMtlPassDlg::Invalidate()
  327. {
  328. Valid = FALSE;
  329. InvalidateRect(HwndPanel,NULL,0);
  330. }
  331. /***********************************************************************************************
  332. * GameMtlPassDlg::ReloadDialog -- update the contents of all of the controls *
  333. * *
  334. * INPUT: *
  335. * *
  336. * OUTPUT: *
  337. * *
  338. * WARNINGS: *
  339. * *
  340. * HISTORY: *
  341. * 11/23/98 GTH : Created. *
  342. *=============================================================================================*/
  343. void GameMtlPassDlg::ReloadDialog()
  344. {
  345. int i;
  346. DebugPrint("GameMtlPassDlg::ReloadDialog\n");
  347. Interval v;
  348. #if ! defined W3D_GMAXDEV
  349. TheMtl->Update(IParams->GetTime(),v);
  350. #else
  351. TheMtl->Update(GetCOREInterface()->GetTime(),v);
  352. #endif
  353. for (i=0; i<PAGE_COUNT; i++) {
  354. if(Page[i]){
  355. Page[i]->ReloadDialog();
  356. }
  357. }
  358. CurPage = TheMtl->Get_Current_Page(PassIndex);
  359. TabCtrl_SetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),CurPage);
  360. Page[CurPage]->Show();
  361. for (i=0; i < PAGE_COUNT; i++) {
  362. if (i != CurPage) Page[i]->Show(false);
  363. }
  364. }
  365. /***********************************************************************************************
  366. * GameMtlPassDlg::ClassID -- returns classID of the object being edited *
  367. * *
  368. * INPUT: *
  369. * *
  370. * OUTPUT: *
  371. * *
  372. * WARNINGS: *
  373. * *
  374. * HISTORY: *
  375. * 11/23/98 GTH : Created. *
  376. *=============================================================================================*/
  377. Class_ID GameMtlPassDlg::ClassID()
  378. {
  379. return GameMaterialClassID;
  380. }
  381. /***********************************************************************************************
  382. * GameMtlPassDlg::SetThing -- set the material being edited *
  383. * *
  384. * INPUT: *
  385. * *
  386. * OUTPUT: *
  387. * *
  388. * WARNINGS: *
  389. * *
  390. * HISTORY: *
  391. * 11/23/98 GTH : Created. *
  392. *=============================================================================================*/
  393. void GameMtlPassDlg::SetThing(ReferenceTarget* target)
  394. {
  395. // Note, parent will "reload" when our "thing" changes :-)
  396. assert (target->SuperClassID()==MATERIAL_CLASS_ID);
  397. assert (target->ClassID()==GameMaterialClassID);
  398. TheMtl = (GameMtl *)target;
  399. for (int i=0; i<PAGE_COUNT; i++) {
  400. Page[i]->SetThing(target);
  401. }
  402. }
  403. /***********************************************************************************************
  404. * GameMtlPassDlg::ActivateDlg -- activate or deactivate the dialog *
  405. * *
  406. * some of the custom max controls need to be activated and deactivated *
  407. * *
  408. * INPUT: *
  409. * *
  410. * OUTPUT: *
  411. * *
  412. * WARNINGS: *
  413. * *
  414. * HISTORY: *
  415. * 11/23/98 GTH : Created. *
  416. *=============================================================================================*/
  417. void GameMtlPassDlg::ActivateDlg(BOOL onoff)
  418. {
  419. for (int i=0; i<PAGE_COUNT; i++) {
  420. Page[i]->ActivateDlg(onoff);
  421. }
  422. }
  423. /***********************************************************************************************
  424. * GameMtlPassDlg::SetTime -- set the current time *
  425. * *
  426. * INPUT: *
  427. * *
  428. * OUTPUT: *
  429. * *
  430. * WARNINGS: *
  431. * *
  432. * HISTORY: *
  433. * 11/23/98 GTH : Created. *
  434. *=============================================================================================*/
  435. void GameMtlPassDlg::SetTime(TimeValue t)
  436. {
  437. // parent dialog class keeps track of the validty and we
  438. // don't have to do anything in this function (it will never
  439. // be called in fact)
  440. }