GameMtlPassDlg.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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:: /Bay/Tools/max2w3d/GameMtlPassDlg.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 10/22/99 9:54a $*
  29. * *
  30. * $Revision:: 9 $*
  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 "GameMtlShaderDlg.h"
  51. #include "PS2GameMtlShaderDlg.h"
  52. #include "GameMtlTextureDlg.h"
  53. #include "GameMtlVertexMaterialDlg.h"
  54. #include "w3d_file.h"
  55. static int _Pass_Index_To_Flag[] =
  56. {
  57. GAMEMTL_PASS0_ROLLUP_OPEN,
  58. GAMEMTL_PASS1_ROLLUP_OPEN,
  59. GAMEMTL_PASS2_ROLLUP_OPEN,
  60. GAMEMTL_PASS3_ROLLUP_OPEN,
  61. };
  62. /***********************************************************************************************
  63. * PassDlgProc -- dialog proc which thunks into a GameMtlPassDlg *
  64. * *
  65. * INPUT: *
  66. * *
  67. * OUTPUT: *
  68. * *
  69. * WARNINGS: *
  70. * *
  71. * HISTORY: *
  72. * 11/23/98 GTH : Created. *
  73. *=============================================================================================*/
  74. static BOOL CALLBACK PassDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  75. {
  76. GameMtlPassDlg *theDlg;
  77. if (msg==WM_INITDIALOG) {
  78. theDlg = (GameMtlPassDlg*)lParam;
  79. theDlg->HwndPanel = hwndDlg;
  80. SetWindowLong(hwndDlg, GWL_USERDATA,lParam);
  81. } else {
  82. if ((theDlg = (GameMtlPassDlg *)GetWindowLong(hwndDlg, GWL_USERDATA) ) == NULL) {
  83. return FALSE;
  84. }
  85. }
  86. return theDlg->DialogProc(hwndDlg,msg,wParam,lParam);
  87. }
  88. /***********************************************************************************************
  89. * GameMtlPassDlg::GameMtlPassDlg -- constructor *
  90. * *
  91. * INPUT: *
  92. * *
  93. * OUTPUT: *
  94. * *
  95. * WARNINGS: *
  96. * *
  97. * HISTORY: *
  98. * 11/23/98 GTH : Created. *
  99. *=============================================================================================*/
  100. GameMtlPassDlg::GameMtlPassDlg(HWND hwMtlEdit, IMtlParams *imp, GameMtl *m,int pass)
  101. {
  102. HwndEdit = hwMtlEdit;
  103. TheMtl = m;
  104. IParams = imp;
  105. PassIndex = pass;
  106. char title[200];
  107. sprintf(title, "Pass %d", pass + 1);
  108. HwndPanel = IParams->AddRollupPage(
  109. AppInstance,
  110. MAKEINTRESOURCE(IDD_GAMEMTL_PASS),
  111. PassDlgProc,
  112. title,
  113. (LPARAM)this,
  114. TheMtl->Get_Flag(_Pass_Index_To_Flag[PassIndex]) ? 0 : APPENDROLL_CLOSED
  115. );
  116. }
  117. /***********************************************************************************************
  118. * GameMtlPassDlg::~GameMtlPassDlg -- destructor *
  119. * *
  120. * INPUT: *
  121. * *
  122. * OUTPUT: *
  123. * *
  124. * WARNINGS: *
  125. * *
  126. * HISTORY: *
  127. * 11/23/98 GTH : Created. *
  128. *=============================================================================================*/
  129. GameMtlPassDlg::~GameMtlPassDlg()
  130. {
  131. TheMtl->Set_Flag(_Pass_Index_To_Flag[PassIndex],IParams->IsRollupPanelOpen(HwndPanel));
  132. IParams->DeleteRollupPage(HwndPanel);
  133. SetWindowLong(HwndPanel, GWL_USERDATA, NULL);
  134. }
  135. /***********************************************************************************************
  136. * GameMtlPassDlg::DialogProc -- windows message handler *
  137. * *
  138. * INPUT: *
  139. * *
  140. * OUTPUT: *
  141. * *
  142. * WARNINGS: *
  143. * *
  144. * HISTORY: *
  145. * 11/23/98 GTH : Created. *
  146. *=============================================================================================*/
  147. BOOL GameMtlPassDlg::DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  148. {
  149. int i=0;
  150. int id = LOWORD(wParam);
  151. int code = HIWORD(wParam);
  152. switch (message) {
  153. case WM_INITDIALOG:
  154. {
  155. Page[0] = new GameMtlVertexMaterialDlg(HwndPanel,IParams,TheMtl,PassIndex);
  156. if (TheMtl->Get_Shader_Type() == GameMtl::STE_PC_SHADER) {
  157. Page[1] = new GameMtlShaderDlg(HwndPanel,IParams,TheMtl,PassIndex);
  158. } else {
  159. // The PS2 shader is different.
  160. Page[1] = new PS2GameMtlShaderDlg(HwndPanel,IParams,TheMtl,PassIndex);
  161. }
  162. Page[2] = new GameMtlTextureDlg(HwndPanel,IParams,TheMtl,PassIndex);
  163. for (i=0; i<PAGE_COUNT; i++) {
  164. HWND hwnd = Page[i]->Get_Hwnd();
  165. // set the tab names
  166. char name[64];
  167. ::GetWindowText(hwnd,name,sizeof(name));
  168. TC_ITEM tcitem = { TCIF_TEXT,0,0,name,0 };
  169. TabCtrl_InsertItem(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),i,&tcitem);
  170. }
  171. // Get the display rectangle of the tab control
  172. RECT rect;
  173. ::GetWindowRect(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),&rect);
  174. TabCtrl_AdjustRect(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),FALSE, &rect);
  175. // Convert the display rectangle from screen to client coords
  176. ScreenToClient(HwndPanel,(POINT *)(&rect));
  177. ScreenToClient(HwndPanel, ((LPPOINT)&rect) + 1);
  178. for (i=0; i<PAGE_COUNT; i++) {
  179. HWND hwnd = Page[i]->Get_Hwnd();
  180. // Loop through all the tabs in the property sheet
  181. // Get a pointer to this tab
  182. SetWindowPos( hwnd,
  183. NULL,
  184. rect.left, rect.top,
  185. rect.right - rect.left, rect.bottom - rect.top,
  186. SWP_NOZORDER);
  187. }
  188. CurPage = 0;
  189. TabCtrl_SetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),CurPage);
  190. Page[CurPage]->Show();
  191. break;
  192. }
  193. case WM_PAINT:
  194. {
  195. if (!Valid) {
  196. Valid = TRUE;
  197. ReloadDialog();
  198. }
  199. return FALSE;
  200. }
  201. case WM_NOTIFY:
  202. {
  203. NMHDR * header = (NMHDR *)lParam;
  204. switch(header->code) {
  205. case TCN_SELCHANGE:
  206. {
  207. int sel = TabCtrl_GetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB));
  208. Page[sel]->Show();
  209. for (int i=0; i < PAGE_COUNT; i++) {
  210. if (i != sel) Page[i]->Show(false);
  211. }
  212. CurPage = sel;
  213. TheMtl->Set_Current_Page(PassIndex,CurPage);
  214. }
  215. };
  216. break;
  217. }
  218. }
  219. return FALSE;
  220. }
  221. /***********************************************************************************************
  222. * GameMtlPassDlg::Invalidate -- invalidate the dialog *
  223. * *
  224. * INPUT: *
  225. * *
  226. * OUTPUT: *
  227. * *
  228. * WARNINGS: *
  229. * *
  230. * HISTORY: *
  231. * 11/23/98 GTH : Created. *
  232. *=============================================================================================*/
  233. void GameMtlPassDlg::Invalidate()
  234. {
  235. Valid = FALSE;
  236. InvalidateRect(HwndPanel,NULL,0);
  237. }
  238. /***********************************************************************************************
  239. * GameMtlPassDlg::ReloadDialog -- update the contents of all of the controls *
  240. * *
  241. * INPUT: *
  242. * *
  243. * OUTPUT: *
  244. * *
  245. * WARNINGS: *
  246. * *
  247. * HISTORY: *
  248. * 11/23/98 GTH : Created. *
  249. *=============================================================================================*/
  250. void GameMtlPassDlg::ReloadDialog()
  251. {
  252. int i;
  253. DebugPrint("GameMtlPassDlg::ReloadDialog\n");
  254. Interval v;
  255. TheMtl->Update(IParams->GetTime(),v);
  256. for (i=0; i<PAGE_COUNT; i++) {
  257. Page[i]->ReloadDialog();
  258. }
  259. CurPage = TheMtl->Get_Current_Page(PassIndex);
  260. TabCtrl_SetCurSel(GetDlgItem(HwndPanel,IDC_GAMEMTL_TAB),CurPage);
  261. Page[CurPage]->Show();
  262. for (i=0; i < PAGE_COUNT; i++) {
  263. if (i != CurPage) Page[i]->Show(false);
  264. }
  265. }
  266. /***********************************************************************************************
  267. * GameMtlPassDlg::ClassID -- returns classID of the object being edited *
  268. * *
  269. * INPUT: *
  270. * *
  271. * OUTPUT: *
  272. * *
  273. * WARNINGS: *
  274. * *
  275. * HISTORY: *
  276. * 11/23/98 GTH : Created. *
  277. *=============================================================================================*/
  278. Class_ID GameMtlPassDlg::ClassID()
  279. {
  280. return GameMaterialClassID;
  281. }
  282. /***********************************************************************************************
  283. * GameMtlPassDlg::SetThing -- set the material being edited *
  284. * *
  285. * INPUT: *
  286. * *
  287. * OUTPUT: *
  288. * *
  289. * WARNINGS: *
  290. * *
  291. * HISTORY: *
  292. * 11/23/98 GTH : Created. *
  293. *=============================================================================================*/
  294. void GameMtlPassDlg::SetThing(ReferenceTarget* target)
  295. {
  296. // Note, parent will "reload" when our "thing" changes :-)
  297. assert (target->SuperClassID()==MATERIAL_CLASS_ID);
  298. assert (target->ClassID()==GameMaterialClassID);
  299. TheMtl = (GameMtl *)target;
  300. for (int i=0; i<PAGE_COUNT; i++) {
  301. Page[i]->SetThing(target);
  302. }
  303. }
  304. /***********************************************************************************************
  305. * GameMtlPassDlg::ActivateDlg -- activate or deactivate the dialog *
  306. * *
  307. * some of the custom max controls need to be activated and deactivated *
  308. * *
  309. * INPUT: *
  310. * *
  311. * OUTPUT: *
  312. * *
  313. * WARNINGS: *
  314. * *
  315. * HISTORY: *
  316. * 11/23/98 GTH : Created. *
  317. *=============================================================================================*/
  318. void GameMtlPassDlg::ActivateDlg(BOOL onoff)
  319. {
  320. for (int i=0; i<PAGE_COUNT; i++) {
  321. Page[i]->ActivateDlg(onoff);
  322. }
  323. }
  324. /***********************************************************************************************
  325. * GameMtlPassDlg::SetTime -- set the current time *
  326. * *
  327. * INPUT: *
  328. * *
  329. * OUTPUT: *
  330. * *
  331. * WARNINGS: *
  332. * *
  333. * HISTORY: *
  334. * 11/23/98 GTH : Created. *
  335. *=============================================================================================*/
  336. void GameMtlPassDlg::SetTime(TimeValue t)
  337. {
  338. // parent dialog class keeps track of the validty and we
  339. // don't have to do anything in this function (it will never
  340. // be called in fact)
  341. }