SpecSheet.cpp 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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. // SpecSheet.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "specsheet.h"
  23. #include "definition.h"
  24. #include "parameterctrls.h"
  25. #include "wwstring.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. //////////////////////////////////////////////////////////////////////////////
  32. // Local prototypes
  33. //////////////////////////////////////////////////////////////////////////////
  34. int __cdecl fnCtrlCompareCallback (void const *ptr1, void const *ptr2);
  35. int Rate_Param_Type (ParameterClass::Type type);
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // SpecSheetClass
  39. //
  40. /////////////////////////////////////////////////////////////////////////////
  41. SpecSheetClass::SpecSheetClass (DefinitionClass *definition)
  42. : m_IsScrolling (false),
  43. m_ScrollPos (0),
  44. m_MaxScrollPos (0),
  45. m_IsTemp (false),
  46. m_IsReadOnly (false),
  47. m_ShowFileOnly (false),
  48. m_WereFilesChanged (false),
  49. m_AssetTreeOnly (true),
  50. m_Definition (definition)
  51. {
  52. return ;
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. //
  56. // ~SpecSheetClass
  57. //
  58. /////////////////////////////////////////////////////////////////////////////
  59. SpecSheetClass::~SpecSheetClass (void)
  60. {
  61. for (int index = 0; index < m_CtrlList.Count (); index ++) {
  62. ParameterCtrlClass *ctrl = m_CtrlList[index];
  63. delete ctrl;
  64. }
  65. //
  66. // Unlock all the parameters in this definition
  67. //
  68. int count = m_Definition->Get_Parameter_Count ();
  69. for (index = 0; index < count; index ++) {
  70. m_Definition->Unlock_Parameter (index);
  71. }
  72. m_CtrlList.Delete_All ();
  73. return ;
  74. }
  75. BEGIN_MESSAGE_MAP(SpecSheetClass, CWnd)
  76. //{{AFX_MSG_MAP(SpecSheetClass)
  77. ON_WM_CREATE()
  78. ON_WM_NCHITTEST()
  79. ON_WM_VSCROLL()
  80. ON_WM_SETCURSOR()
  81. ON_WM_NCMOUSEMOVE()
  82. ON_WM_NCLBUTTONDOWN()
  83. ON_WM_NCLBUTTONUP()
  84. ON_WM_LBUTTONDOWN()
  85. ON_WM_LBUTTONUP()
  86. ON_WM_MOUSEMOVE()
  87. ON_WM_SIZE()
  88. ON_WM_DESTROY()
  89. //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91. /////////////////////////////////////////////////////////////////////////////
  92. //
  93. // Is_Filtered
  94. //
  95. /////////////////////////////////////////////////////////////////////////////
  96. bool
  97. SpecSheetClass::Is_Filtered (ParameterClass *parameter)
  98. {
  99. bool retval = false;
  100. if (parameter != NULL) {
  101. if (m_ShowFileOnly) {
  102. int type = parameter->Get_Type ();
  103. if ( type != ParameterClass::TYPE_FILENAME &&
  104. type != ParameterClass::TYPE_SOUND_FILENAME )
  105. {
  106. retval = true;
  107. }
  108. }
  109. }
  110. return retval;
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. //
  114. // Add_Parameter
  115. //
  116. /////////////////////////////////////////////////////////////////////////////
  117. void
  118. SpecSheetClass::Add_Parameter (ParameterClass *parameter)
  119. {
  120. //
  121. // What type of parameter is this?
  122. //
  123. ParameterCtrlClass *parameter_ctrl = NULL;
  124. switch (parameter->Get_Type ()) {
  125. case ParameterClass::TYPE_INT:
  126. parameter_ctrl = new IntParameterCtrlClass ((IntParameterClass *)parameter);
  127. break;
  128. case ParameterClass::TYPE_FLOAT:
  129. parameter_ctrl = new FloatParameterCtrlClass ((FloatParameterClass *)parameter);
  130. break;
  131. case ParameterClass::TYPE_FILENAME:
  132. parameter_ctrl = new FileParameterCtrlClass ((FilenameParameterClass *)parameter);
  133. ((FileParameterCtrlClass *)parameter_ctrl)->Get_File_Picker ().Set_Asset_Tree_Only (m_AssetTreeOnly);
  134. break;
  135. case ParameterClass::TYPE_SOUND_FILENAME:
  136. parameter_ctrl = new SoundFileParameterCtrlClass ((SoundFilenameParameterClass *)parameter);
  137. ((FileParameterCtrlClass *)parameter_ctrl)->Get_File_Picker ().Set_Asset_Tree_Only (m_AssetTreeOnly);
  138. break;
  139. case ParameterClass::TYPE_STRING:
  140. parameter_ctrl = new StringParameterCtrlClass ((StringParameterClass *)parameter);
  141. break;
  142. case ParameterClass::TYPE_BOOL:
  143. parameter_ctrl = new BoolParameterCtrlClass ((BoolParameterClass *)parameter);
  144. break;
  145. case ParameterClass::TYPE_VECTOR3:
  146. parameter_ctrl = new Vector3ParameterCtrlClass ((Vector3ParameterClass *)parameter);
  147. break;
  148. case ParameterClass::TYPE_VECTOR2:
  149. parameter_ctrl = new Vector2ParameterCtrlClass ((Vector2ParameterClass *)parameter);
  150. break;
  151. case ParameterClass::TYPE_RECT:
  152. parameter_ctrl = new RectParameterCtrlClass ((RectParameterClass *)parameter);
  153. break;
  154. case ParameterClass::TYPE_COLOR:
  155. parameter_ctrl = new ColorParameterCtrlClass ((ColorParameterClass *)parameter);
  156. break;
  157. case ParameterClass::TYPE_ENUM:
  158. parameter_ctrl = new EnumParameterCtrlClass ((EnumParameterClass *)parameter);
  159. break;
  160. case ParameterClass::TYPE_PHYSDEFINITIONID:
  161. parameter_ctrl = new PhysDefParameterCtrlClass ((PhysDefParameterClass *)parameter);
  162. break;
  163. case ParameterClass::TYPE_GENERICDEFINITIONID:
  164. parameter_ctrl = new GenericDefParameterCtrlClass ((GenericDefParameterClass *)parameter);
  165. break;
  166. case ParameterClass::TYPE_GAMEOBJDEFINITIONID:
  167. parameter_ctrl = new GameObjDefParameterCtrlClass ((GameObjDefParameterClass *)parameter);
  168. break;
  169. case ParameterClass::TYPE_WEAPONOBJDEFINITIONID:
  170. parameter_ctrl = new WeaponObjDefParameterCtrlClass ((WeaponObjDefParameterClass *)parameter);
  171. break;
  172. case ParameterClass::TYPE_AMMOOBJDEFINITIONID:
  173. parameter_ctrl = new AmmoObjDefParameterCtrlClass ((AmmoObjDefParameterClass *)parameter);
  174. break;
  175. case ParameterClass::TYPE_EXPLOSIONDEFINITIONID:
  176. parameter_ctrl = new ExplosionObjDefParameterCtrlClass ((ExplosionObjDefParameterClass *)parameter);
  177. break;
  178. case ParameterClass::TYPE_SOUNDDEFINITIONID:
  179. parameter_ctrl = new SoundDefParameterCtrlClass ((SoundDefParameterClass *)parameter);
  180. break;
  181. case ParameterClass::TYPE_SCRIPT:
  182. parameter_ctrl = new ScriptParameterCtrlClass ((ScriptParameterClass *)parameter);
  183. break;
  184. case ParameterClass::TYPE_ANGLE:
  185. parameter_ctrl = new AngleParameterCtrlClass ((AngleParameterClass *)parameter);
  186. break;
  187. case ParameterClass::TYPE_DEFINITIONIDLIST:
  188. parameter_ctrl = new DefIDListParameterCtrlClass ((DefIDListParameterClass *)parameter);
  189. break;
  190. case ParameterClass::TYPE_FILENAMELIST:
  191. parameter_ctrl = new FilenameListParameterCtrlClass ((FilenameListParameterClass *)parameter);
  192. break;
  193. case ParameterClass::TYPE_SEPARATOR:
  194. parameter_ctrl = new SeparatorParameterCtrlClass ((SeparatorParameterClass *)parameter);
  195. break;
  196. case ParameterClass::TYPE_STRINGSDB_ID:
  197. parameter_ctrl = new StringsDBEntryParameterCtrlClass ((StringsDBEntryParameterClass *)parameter);
  198. break;
  199. }
  200. if (parameter_ctrl != NULL) {
  201. parameter_ctrl->Set_Is_Temp (m_IsTemp);
  202. parameter_ctrl->Set_Spec_Sheet (this);
  203. m_CtrlList.Add (parameter_ctrl);
  204. }
  205. return ;
  206. }
  207. /////////////////////////////////////////////////////////////////////////////
  208. //
  209. // OnCreate
  210. //
  211. /////////////////////////////////////////////////////////////////////////////
  212. int
  213. SpecSheetClass::OnCreate (LPCREATESTRUCT lpCreateStruct)
  214. {
  215. if (CWnd::OnCreate(lpCreateStruct) == -1)
  216. return -1;
  217. //
  218. // Set the font for this control
  219. //
  220. HFONT hfont = (HFONT)GetParent()->SendMessage (WM_GETFONT);
  221. SendMessage (WM_SETFONT, (WPARAM)hfont);
  222. CRect client_rect;
  223. GetClientRect (&client_rect);
  224. //
  225. // Create the scrollbar
  226. //
  227. HWND scrollbar = ::CreateWindow ( "SCROLLBAR",
  228. "",
  229. WS_CHILD | WS_VISIBLE | SBS_VERT,
  230. client_rect.right - ::GetSystemMetrics (SM_CXVSCROLL),
  231. 0,
  232. ::GetSystemMetrics (SM_CXVSCROLL),
  233. client_rect.Height (),
  234. m_hWnd,
  235. (HMENU)878,
  236. ::AfxGetInstanceHandle (),
  237. NULL);
  238. //
  239. // Configure the scrollbar
  240. //
  241. ::SendMessage (scrollbar, SBM_SETRANGE, (WPARAM)0, (WPARAM)100);
  242. ::SendMessage (scrollbar, WM_SETFONT, (WPARAM)hfont, 0L);
  243. //
  244. // Create a control object for every parameter
  245. //
  246. int count = m_Definition->Get_Parameter_Count ();
  247. for (int index = 0; index < count; index ++) {
  248. ParameterClass *parameter = m_Definition->Lock_Parameter (index);
  249. //
  250. // Add this control to the dialog if its not filtered...
  251. //
  252. if (Is_Filtered (parameter) == false) {
  253. Add_Parameter (parameter);
  254. }
  255. }
  256. int start_id = 500;
  257. CRect rect;
  258. GetClientRect (rect);
  259. rect.top += 10;
  260. rect.bottom = rect.top;
  261. //
  262. // Ask each control to create its UI
  263. //
  264. for (index = 0; index < m_CtrlList.Count (); index ++) {
  265. ParameterCtrlClass *parameter_ctrl = m_CtrlList[index];
  266. parameter_ctrl->Set_Read_Only (m_IsReadOnly);
  267. start_id = parameter_ctrl->Create (m_hWnd, start_id, &rect);
  268. rect.top = rect.bottom + 10;
  269. rect.bottom = rect.top;
  270. }
  271. m_MaxScrollPos = rect.bottom;
  272. return 0;
  273. }
  274. /////////////////////////////////////////////////////////////////////////////
  275. //
  276. // Get_Current_Filename_Value
  277. //
  278. /////////////////////////////////////////////////////////////////////////////
  279. void
  280. SpecSheetClass::Get_Current_Filename_Value (int index, CString &value)
  281. {
  282. //
  283. // Is the index valid?
  284. //
  285. ASSERT (index >= 0 && index < Get_Parameter_Count ());
  286. if (index >= 0 && index < Get_Parameter_Count ()) {
  287. //
  288. // Return the parameter that is associated with this ctrl
  289. //
  290. ParameterCtrlClass *ctrl = m_CtrlList[index];
  291. if ( ctrl->Get_Type () == ParameterClass::TYPE_FILENAME ||
  292. ctrl->Get_Type () == ParameterClass::TYPE_SOUND_FILENAME )
  293. {
  294. ((FileParameterCtrlClass *)ctrl)->Get_Current_Value (value);
  295. }
  296. }
  297. return ;
  298. }
  299. /////////////////////////////////////////////////////////////////////////////
  300. //
  301. // Get_Parameter
  302. //
  303. /////////////////////////////////////////////////////////////////////////////
  304. ParameterClass *
  305. SpecSheetClass::Get_Parameter (int index)
  306. {
  307. ParameterClass *parameter = NULL;
  308. //
  309. // Is the index valid?
  310. //
  311. ASSERT (index >= 0 && index < Get_Parameter_Count ());
  312. if (index >= 0 && index < Get_Parameter_Count ()) {
  313. //
  314. // Return the parameter that is associated with this ctrl
  315. //
  316. ParameterCtrlClass *ctrl = m_CtrlList[index];
  317. parameter = ctrl->Get_Parameter ();
  318. }
  319. return parameter;
  320. }
  321. /////////////////////////////////////////////////////////////////////////////
  322. //
  323. // OnNcHitTest
  324. //
  325. /////////////////////////////////////////////////////////////////////////////
  326. UINT
  327. SpecSheetClass::OnNcHitTest (CPoint point)
  328. {
  329. return HTCLIENT;
  330. }
  331. /////////////////////////////////////////////////////////////////////////////
  332. //
  333. // OnVScroll
  334. //
  335. /////////////////////////////////////////////////////////////////////////////
  336. void
  337. SpecSheetClass::OnVScroll
  338. (
  339. UINT nSBCode,
  340. UINT nPos,
  341. CScrollBar *pScrollBar
  342. )
  343. {
  344. if (pScrollBar != NULL && GetWindowLong (*pScrollBar, GWL_ID) == 878) {
  345. int new_pos = m_ScrollPos;
  346. CRect client_rect;
  347. GetClientRect (&client_rect);
  348. int height = client_rect.Height ();
  349. switch (nSBCode)
  350. {
  351. case SB_BOTTOM:
  352. new_pos = m_MaxScrollPos;
  353. break;
  354. case SB_LINEDOWN:
  355. if (new_pos < (m_MaxScrollPos - 10)) {
  356. new_pos += 10;
  357. } else {
  358. new_pos = m_MaxScrollPos;
  359. }
  360. break;
  361. case SB_LINEUP:
  362. if (new_pos > 10) {
  363. new_pos -= 10;
  364. } else {
  365. new_pos = 0;
  366. }
  367. break;
  368. case SB_PAGEDOWN:
  369. if (new_pos < (m_MaxScrollPos - (height / 2))) {
  370. new_pos += (height / 2);
  371. } else {
  372. new_pos = m_MaxScrollPos;
  373. }
  374. break;
  375. case SB_PAGEUP:
  376. if (new_pos > (height / 2)) {
  377. new_pos -= (height / 2);
  378. } else {
  379. new_pos = 0;
  380. }
  381. break;
  382. case SB_THUMBTRACK:
  383. case SB_THUMBPOSITION:
  384. new_pos = (m_MaxScrollPos * nPos) / 100;
  385. break;
  386. }
  387. //
  388. // Scroll to the new position
  389. //
  390. Set_Scroll_Pos (new_pos);
  391. }
  392. CWnd::OnVScroll (nSBCode, nPos, pScrollBar);
  393. return ;
  394. }
  395. /////////////////////////////////////////////////////////////////////////////
  396. //
  397. // Set_Scroll_Pos
  398. //
  399. /////////////////////////////////////////////////////////////////////////////
  400. void
  401. SpecSheetClass::Set_Scroll_Pos (int new_pos)
  402. {
  403. //
  404. // Scroll the controls
  405. //
  406. Scroll_Controls (m_ScrollPos - new_pos);
  407. m_ScrollPos = new_pos;
  408. //
  409. // Update the scroll bar
  410. //
  411. int sb_pos = ((m_ScrollPos * 100) / m_MaxScrollPos);
  412. SendDlgItemMessage (878, SBM_SETPOS, (WPARAM)sb_pos, (LPARAM)TRUE);
  413. return ;
  414. }
  415. /////////////////////////////////////////////////////////////////////////////
  416. //
  417. // OnSetCursor
  418. //
  419. /////////////////////////////////////////////////////////////////////////////
  420. BOOL
  421. SpecSheetClass::OnSetCursor
  422. (
  423. CWnd * pWnd,
  424. UINT nHitTest,
  425. UINT message
  426. )
  427. {
  428. BOOL retval = FALSE;
  429. if (nHitTest == HTCLIENT) {
  430. ::SetCursor (::LoadCursor (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDC_OBJ_MOVE)));
  431. //retval = TRUE;
  432. } else {
  433. retval = CWnd::OnSetCursor (pWnd, nHitTest, message);
  434. }
  435. return retval;
  436. }
  437. /////////////////////////////////////////////////////////////////////////////
  438. //
  439. // OnNcMouseMove
  440. //
  441. /////////////////////////////////////////////////////////////////////////////
  442. void
  443. SpecSheetClass::OnNcMouseMove
  444. (
  445. UINT nHitTest,
  446. CPoint point
  447. )
  448. {
  449. CWnd::OnNcMouseMove (nHitTest, point);
  450. return ;
  451. }
  452. /////////////////////////////////////////////////////////////////////////////
  453. //
  454. // OnNcLButtonDown
  455. //
  456. /////////////////////////////////////////////////////////////////////////////
  457. void
  458. SpecSheetClass::OnNcLButtonDown
  459. (
  460. UINT nHitTest,
  461. CPoint point
  462. )
  463. {
  464. /*if (nHitTest == HTVSCROLL) {
  465. m_IsScrolling = true;
  466. m_LastPoint = point;
  467. SetCapture ();
  468. }*/
  469. CWnd::OnNcLButtonDown (nHitTest, point);
  470. return ;
  471. }
  472. /////////////////////////////////////////////////////////////////////////////
  473. //
  474. // OnNcLButtonDown
  475. //
  476. /////////////////////////////////////////////////////////////////////////////
  477. void
  478. SpecSheetClass::OnNcLButtonUp
  479. (
  480. UINT nHitTest,
  481. CPoint point
  482. )
  483. {
  484. CWnd::OnNcLButtonUp (nHitTest, point);
  485. return ;
  486. }
  487. /////////////////////////////////////////////////////////////////////////////
  488. //
  489. // OnLButtonDown
  490. //
  491. /////////////////////////////////////////////////////////////////////////////
  492. void
  493. SpecSheetClass::OnLButtonDown (UINT nFlags, CPoint point)
  494. {
  495. //if (nHitTest == HTVSCROLL) {
  496. m_IsScrolling = true;
  497. m_LastPoint = point;
  498. SetCapture ();
  499. //}
  500. CWnd::OnLButtonDown(nFlags, point);
  501. return ;
  502. }
  503. /////////////////////////////////////////////////////////////////////////////
  504. //
  505. // OnLButtonUp
  506. //
  507. /////////////////////////////////////////////////////////////////////////////
  508. void
  509. SpecSheetClass::OnLButtonUp (UINT nFlags, CPoint point)
  510. {
  511. m_IsScrolling = false;
  512. ReleaseCapture ();
  513. CWnd::OnLButtonUp (nFlags, point);
  514. return ;
  515. }
  516. /////////////////////////////////////////////////////////////////////////////
  517. //
  518. // OnMouseMove
  519. //
  520. /////////////////////////////////////////////////////////////////////////////
  521. void
  522. SpecSheetClass::OnMouseMove (UINT nFlags, CPoint point)
  523. {
  524. if (m_IsScrolling) {
  525. CPoint delta = m_LastPoint - point;
  526. int scroll_amt = delta.y;
  527. int new_pos = m_ScrollPos + scroll_amt;
  528. //
  529. // Clip the scroll position to the min and max
  530. //
  531. if (new_pos < 0) {
  532. new_pos = 0;
  533. } else if (new_pos > m_MaxScrollPos) {
  534. new_pos = m_MaxScrollPos;
  535. }
  536. //
  537. // Scroll to the new position
  538. //
  539. Set_Scroll_Pos (new_pos);
  540. //
  541. // Remember the last point
  542. //
  543. m_LastPoint = point;
  544. }
  545. CWnd::OnMouseMove (nFlags, point);
  546. return ;
  547. }
  548. /////////////////////////////////////////////////////////////////////////////
  549. //
  550. // Scroll_Controls
  551. //
  552. /////////////////////////////////////////////////////////////////////////////
  553. void
  554. SpecSheetClass::Scroll_Controls (int amount)
  555. {
  556. DynamicVectorClass<HWND> child_wnd_list;
  557. //
  558. // Build a list of all the child windows we want to scroll
  559. //
  560. for ( HWND child_wnd = ::GetWindow (m_hWnd, GW_CHILD);
  561. child_wnd != NULL;
  562. child_wnd = ::GetWindow (child_wnd, GW_HWNDNEXT))
  563. {
  564. //
  565. // If this isn't the scroll-bar, then add it to the list
  566. //
  567. if (::GetWindowLong (child_wnd, GWL_ID) != 878) {
  568. child_wnd_list.Add (child_wnd);
  569. }
  570. }
  571. //
  572. // Build a defer struct so that we can move all the windows in one
  573. // operation
  574. //
  575. int count = child_wnd_list.Count ();
  576. HDWP defer_struct = ::BeginDeferWindowPos (count);
  577. for (int index = 0; index < count; index ++) {
  578. child_wnd = child_wnd_list[index];
  579. //
  580. // Get the current position of the child window
  581. //
  582. CRect rect;
  583. ::GetWindowRect (child_wnd, &rect);
  584. ScreenToClient (&rect);
  585. //
  586. // Scroll the window
  587. //
  588. ::DeferWindowPos (defer_struct, child_wnd, NULL, rect.left, rect.top + amount, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW);
  589. }
  590. //
  591. // Perform the move operations in batch
  592. //
  593. ::EndDeferWindowPos (defer_struct);
  594. CRect client_rect;
  595. GetClientRect (&client_rect);
  596. client_rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  597. HDC dc = ::GetDC (m_hWnd);
  598. ::ScrollDC (dc, 0, amount, &client_rect, &client_rect, NULL, NULL);
  599. ::ReleaseDC (m_hWnd, dc);
  600. if (amount > 0) {
  601. client_rect.bottom = client_rect.top + amount;
  602. } else {
  603. client_rect.top = client_rect.bottom + amount;
  604. }
  605. InvalidateRect (client_rect, TRUE);
  606. UpdateWindow ();
  607. /*CRect client_rect;
  608. GetClientRect (&client_rect);
  609. client_rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  610. InvalidateRect (client_rect, TRUE);
  611. UpdateWindow ();*/
  612. return ;
  613. }
  614. /////////////////////////////////////////////////////////////////////////////
  615. //
  616. // OnSize
  617. //
  618. /////////////////////////////////////////////////////////////////////////////
  619. void
  620. SpecSheetClass::OnSize
  621. (
  622. UINT nType,
  623. int cx,
  624. int cy
  625. )
  626. {
  627. CRect client_rect;
  628. GetClientRect (&client_rect);
  629. //
  630. // Resize the scrollbar
  631. //
  632. HWND scrollbar = ::GetDlgItem (m_hWnd, 878);
  633. ::SetWindowPos ( scrollbar,
  634. NULL,
  635. client_rect.right - ::GetSystemMetrics (SM_CXVSCROLL),
  636. 0,
  637. ::GetSystemMetrics (SM_CXVSCROLL),
  638. client_rect.Height (),
  639. SWP_NOZORDER);
  640. //
  641. // Resize the controls
  642. //
  643. client_rect.right -= (::GetSystemMetrics (SM_CXVSCROLL) + 10);
  644. for (int index = 0; index < m_CtrlList.Count (); index ++) {
  645. ParameterCtrlClass *ctrl = m_CtrlList[index];
  646. ctrl->Resize (client_rect);
  647. }
  648. CWnd::OnSize (nType, cx, cy);
  649. return ;
  650. }
  651. /////////////////////////////////////////////////////////////////////////////
  652. //
  653. // PreCreateWindow
  654. //
  655. /////////////////////////////////////////////////////////////////////////////
  656. BOOL
  657. SpecSheetClass::PreCreateWindow (CREATESTRUCT &cs)
  658. {
  659. cs.dwExStyle |= WS_EX_CONTROLPARENT;
  660. return CWnd::PreCreateWindow(cs);
  661. }
  662. /////////////////////////////////////////////////////////////////////////////
  663. //
  664. // Apply
  665. //
  666. /////////////////////////////////////////////////////////////////////////////
  667. void
  668. SpecSheetClass::Apply (void)
  669. {
  670. m_WereFilesChanged = false;
  671. for (int index = 0; index < m_CtrlList.Count (); index ++) {
  672. ParameterCtrlClass *ctrl = m_CtrlList[index];
  673. //
  674. // Determine if any file parameters were changed...
  675. //
  676. int type = ctrl->Get_Type ();
  677. if ( type == ParameterClass::TYPE_FILENAME ||
  678. type == ParameterClass::TYPE_SOUND_FILENAME )
  679. {
  680. m_WereFilesChanged |= ctrl->Is_Modified ();
  681. }
  682. //
  683. // Get the control to read its data from the dialog controls
  684. //
  685. ctrl->Read_Data (NULL);
  686. }
  687. return ;
  688. }
  689. /////////////////////////////////////////////////////////////////////////////
  690. //
  691. // Rate_Param_Type
  692. //
  693. /////////////////////////////////////////////////////////////////////////////
  694. int
  695. Rate_Param_Type (ParameterClass::Type type)
  696. {
  697. int retval = 100;
  698. switch (type)
  699. {
  700. case ParameterClass::TYPE_FILENAME:
  701. case ParameterClass::TYPE_SOUND_FILENAME:
  702. retval = 0;
  703. break;
  704. case ParameterClass::TYPE_PHYSDEFINITIONID:
  705. retval = 1;
  706. break;
  707. case ParameterClass::TYPE_GAMEOBJDEFINITIONID:
  708. case ParameterClass::TYPE_WEAPONOBJDEFINITIONID:
  709. case ParameterClass::TYPE_AMMOOBJDEFINITIONID:
  710. case ParameterClass::TYPE_SOUNDDEFINITIONID:
  711. retval = 2;
  712. break;
  713. case ParameterClass::TYPE_SCRIPT:
  714. retval = 3;
  715. break;
  716. case ParameterClass::TYPE_STRING:
  717. retval = 4;
  718. break;
  719. case ParameterClass::TYPE_ENUM:
  720. retval = 5;
  721. break;
  722. case ParameterClass::TYPE_COLOR:
  723. retval = 8;
  724. break;
  725. case ParameterClass::TYPE_VECTOR3:
  726. retval = 9;
  727. break;
  728. case ParameterClass::TYPE_INT:
  729. retval = 10;
  730. break;
  731. case ParameterClass::TYPE_ANGLE:
  732. retval = 11;
  733. break;
  734. case ParameterClass::TYPE_FLOAT:
  735. retval = 12;
  736. break;
  737. case ParameterClass::TYPE_BOOL:
  738. retval = 20;
  739. break;
  740. }
  741. return retval;
  742. }
  743. /////////////////////////////////////////////////////////////////////////////
  744. //
  745. // fnCtrlCompareCallback
  746. //
  747. /////////////////////////////////////////////////////////////////////////////
  748. int __cdecl
  749. fnCtrlCompareCallback (void const *ptr1, void const *ptr2)
  750. {
  751. ParameterClass::Type type1 = (*((ParameterCtrlClass **)ptr1))->Get_Type ();
  752. ParameterClass::Type type2 = (*((ParameterCtrlClass **)ptr2))->Get_Type ();
  753. //
  754. // Determine a sort rating based on the param type
  755. //
  756. int rating1 = ::Rate_Param_Type (type1);
  757. int rating2 = ::Rate_Param_Type (type2);
  758. int retval = rating1 - rating2;
  759. //
  760. // If the type is the same, then sort alphanumerically
  761. //
  762. if (retval == 0) {
  763. ParameterClass *param1 = (*((ParameterCtrlClass **)ptr1))->Get_Parameter ();
  764. ParameterClass *param2 = (*((ParameterCtrlClass **)ptr2))->Get_Parameter ();
  765. //
  766. // Compare the param names
  767. //
  768. CString name1 = param1->Get_Name ();
  769. CString name2 = param2->Get_Name ();
  770. retval = name1.CompareNoCase (name2);
  771. }
  772. return retval;
  773. }
  774. /////////////////////////////////////////////////////////////////////////////
  775. //
  776. // OnCommand
  777. //
  778. /////////////////////////////////////////////////////////////////////////////
  779. BOOL
  780. SpecSheetClass::OnCommand
  781. (
  782. WPARAM wParam,
  783. LPARAM lParam
  784. )
  785. {
  786. bool processed = false;
  787. for (int index = 0; (index < m_CtrlList.Count ()) && !processed; index ++) {
  788. ParameterCtrlClass *ctrl = m_CtrlList[index];
  789. processed = ctrl->On_Command (*this, wParam, lParam);
  790. }
  791. return CWnd::OnCommand (wParam, lParam);
  792. }
  793. /////////////////////////////////////////////////////////////////////////////
  794. //
  795. // OnDestroy
  796. //
  797. /////////////////////////////////////////////////////////////////////////////
  798. void
  799. SpecSheetClass::OnDestroy (void)
  800. {
  801. for (int index = 0; index < m_CtrlList.Count (); index ++) {
  802. ParameterCtrlClass *ctrl = m_CtrlList[index];
  803. ctrl->On_Destroy ();
  804. }
  805. CWnd::OnDestroy ();
  806. return ;
  807. }
  808. /////////////////////////////////////////////////////////////////////////////
  809. //
  810. // WindowProc
  811. //
  812. /////////////////////////////////////////////////////////////////////////////
  813. LRESULT
  814. SpecSheetClass::WindowProc (UINT message, WPARAM wParam, LPARAM lParam)
  815. {
  816. LRESULT result = 0L;
  817. if (message == WM_DRAWITEM) {
  818. //
  819. // Determine which parameter ctrl wants to process this message...
  820. //
  821. for (int index = 0; (index < m_CtrlList.Count ()) && (result == 0L); index ++) {
  822. ParameterCtrlClass *ctrl = m_CtrlList[index];
  823. if (ctrl->On_DrawItem (*this, wParam, lParam)) {
  824. result = 1L;
  825. }
  826. }
  827. }
  828. if (result == 0L) {
  829. result = CWnd::WindowProc(message, wParam, lParam);
  830. }
  831. return result;
  832. }