PhysObjEditTab.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. // PhysObjEditDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "PhysObjEditTab.h"
  23. #include "SpecSheet.h"
  24. #include "definitionmgr.h"
  25. #include "definitionfactorymgr.h"
  26. #include "definition.h"
  27. #include "definitionfactory.h"
  28. #include "Utils.h"
  29. #include "phys.h"
  30. #include "parameter.h"
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // PhysObjEditTabClass
  39. //
  40. /////////////////////////////////////////////////////////////////////////////
  41. PhysObjEditTabClass::PhysObjEditTabClass (void)
  42. : m_ParamSheet (NULL),
  43. m_PhysDefParam (NULL),
  44. m_DefinitionID (0),
  45. m_IsTemp (false),
  46. m_ReadOnly (false),
  47. DockableFormClass (PhysObjEditTabClass::IDD)
  48. {
  49. //{{AFX_DATA_INIT(PhysObjEditTabClass)
  50. // NOTE: the ClassWizard will add member initialization here
  51. //}}AFX_DATA_INIT
  52. return ;
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. //
  56. // ~PhysObjEditTabClass
  57. //
  58. /////////////////////////////////////////////////////////////////////////////
  59. PhysObjEditTabClass::~PhysObjEditTabClass (void)
  60. {
  61. return ;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. //
  65. // DoDataExchange
  66. //
  67. /////////////////////////////////////////////////////////////////////////////
  68. void
  69. PhysObjEditTabClass::DoDataExchange (CDataExchange* pDX)
  70. {
  71. DockableFormClass::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(PhysObjEditTabClass)
  73. DDX_Control(pDX, IDC_TYPE_COMBO, m_ObjTypeCombo);
  74. DDX_Control(pDX, IDC_SETTINGS_GROUP, m_SettingsGroup);
  75. //}}AFX_DATA_MAP
  76. return ;
  77. }
  78. BEGIN_MESSAGE_MAP(PhysObjEditTabClass, DockableFormClass)
  79. //{{AFX_MSG_MAP(PhysObjEditTabClass)
  80. ON_WM_DESTROY()
  81. ON_CBN_SELCHANGE(IDC_TYPE_COMBO, OnSelChangeTypeCombo)
  82. //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. //
  86. // HandleInitDialog
  87. //
  88. /////////////////////////////////////////////////////////////////////////////
  89. void
  90. PhysObjEditTabClass::HandleInitDialog (void)
  91. {
  92. DefinitionClass *default_definition = DefinitionMgrClass::Find_Definition (m_DefinitionID, false);
  93. uint32 default_classid = 0;
  94. if (default_definition != NULL) {
  95. default_classid = default_definition->Get_Class_ID ();
  96. }
  97. //
  98. // Fill in the list of all the definition types
  99. //
  100. DefinitionFactoryClass *factory = NULL;
  101. for ( factory = DefinitionFactoryMgrClass::Get_First (CLASSID_PHYSICS);
  102. factory != NULL;
  103. factory = DefinitionFactoryMgrClass::Get_Next (factory, CLASSID_PHYSICS))
  104. {
  105. //
  106. // If this is the default definition, then add the existing
  107. // definition instead of creating a new one.
  108. //
  109. if (default_classid == factory->Get_Class_ID ()) {
  110. int index = m_ObjTypeCombo.AddString (factory->Get_Name ());
  111. m_ObjTypeCombo.SetItemData (index, (ULONG)default_definition);
  112. m_ObjTypeCombo.SetCurSel (index);
  113. } else {
  114. DefinitionClass *definition = factory->Create ();
  115. if (definition != NULL) {
  116. //
  117. // If this definition passes the filter, then add it to
  118. // the combo-box, otherwise delete it
  119. //
  120. if (((PhysDefClass *)definition)->Is_Type (m_FilterString)) {
  121. int index = m_ObjTypeCombo.AddString (factory->Get_Name ());
  122. m_ObjTypeCombo.SetItemData (index, (ULONG)definition);
  123. } else {
  124. SAFE_DELETE (definition);
  125. }
  126. }
  127. }
  128. }
  129. if (default_classid == 0) {
  130. m_ObjTypeCombo.SetCurSel (0);
  131. }
  132. if (m_ReadOnly) {
  133. m_ObjTypeCombo.EnableWindow (FALSE);
  134. }
  135. // Update the spec sheet based on the current object type
  136. OnSelChangeTypeCombo ();
  137. return ;
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. //
  141. // Apply_Changes
  142. //
  143. /////////////////////////////////////////////////////////////////////////////
  144. bool
  145. PhysObjEditTabClass::Apply_Changes (void)
  146. {
  147. CWaitCursor wait_cursor;
  148. if (m_ParamSheet != NULL) {
  149. // Save the UI changes to the definition
  150. m_ParamSheet->Apply ();
  151. //
  152. // Determine what definition ID to store
  153. //
  154. DefinitionClass *definition = m_ParamSheet->Get_Definition ();
  155. m_DefinitionID = 0;
  156. if (definition != NULL) {
  157. //
  158. // Does the definition already have an ID?
  159. //
  160. m_DefinitionID = definition->Get_ID ();
  161. if (m_DefinitionID == 0) {
  162. //
  163. // Give the definition a new ID
  164. //
  165. if (m_IsTemp) {
  166. m_DefinitionID = ::Get_Next_Temp_ID ();
  167. } else {
  168. m_DefinitionID = DefinitionMgrClass::Get_New_ID (definition->Get_Class_ID ());
  169. }
  170. definition->Set_ID (m_DefinitionID);
  171. }
  172. //
  173. // Incorporate this definition into the framework
  174. //
  175. DefinitionMgrClass::Register_Definition (definition);
  176. //
  177. // Pass this new definition ID onto the parameter-object we
  178. // are editing (if there was one...)
  179. //
  180. if (m_PhysDefParam != NULL) {
  181. m_PhysDefParam->Set_Value (m_DefinitionID);
  182. }
  183. }
  184. }
  185. return true;
  186. }
  187. /////////////////////////////////////////////////////////////////////////////
  188. //
  189. // OnDestroy
  190. //
  191. /////////////////////////////////////////////////////////////////////////////
  192. void
  193. PhysObjEditTabClass::OnDestroy (void)
  194. {
  195. SAFE_DELETE (m_ParamSheet);
  196. for (int index = 0; index < m_ObjTypeCombo.GetCount (); index ++) {
  197. DefinitionClass *definition = (DefinitionClass *)m_ObjTypeCombo.GetItemData (index);
  198. if (definition != NULL) {
  199. //
  200. // Delete all the definitions EXCEPT for the one we
  201. // will be returning to the caller.
  202. //
  203. if (definition->Get_ID () != m_DefinitionID) {
  204. DefinitionMgrClass::Unregister_Definition (definition);
  205. delete definition;
  206. }
  207. }
  208. }
  209. DockableFormClass::OnDestroy ();
  210. return ;
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. //
  214. // OnSelChangeTypeCombo
  215. //
  216. /////////////////////////////////////////////////////////////////////////////
  217. void
  218. PhysObjEditTabClass::OnSelChangeTypeCombo (void)
  219. {
  220. if (::IsWindow (m_ObjTypeCombo)) {
  221. SetRedraw (false);
  222. //
  223. // Free the old param sheet if necessary
  224. //
  225. if (m_ParamSheet != NULL) {
  226. m_ParamSheet->Apply ();
  227. m_ParamSheet->DestroyWindow ();
  228. SAFE_DELETE (m_ParamSheet);
  229. }
  230. //
  231. // Determine which definition to display
  232. //
  233. int index = m_ObjTypeCombo.GetCurSel ();
  234. if (index != CB_ERR) {
  235. DefinitionClass *definition = (DefinitionClass *)m_ObjTypeCombo.GetItemData (index);
  236. //
  237. // Create the param sheet that is used to edit the definition's settings
  238. //
  239. CRect rect;
  240. m_SettingsGroup.GetWindowRect (&rect);
  241. ScreenToClient (&rect);
  242. rect.left += 10;
  243. rect.right -= 10;
  244. rect.top += 15;
  245. rect.bottom -= 10;
  246. m_ParamSheet = new SpecSheetClass (definition);
  247. m_ParamSheet->Set_Is_Temp (m_IsTemp);
  248. m_ParamSheet->Set_Read_Only (m_ReadOnly);
  249. m_ParamSheet->Create ("static", "", WS_CHILD | WS_VISIBLE, rect, this, 101);
  250. }
  251. SetRedraw (true);
  252. InvalidateRect (NULL, FALSE);
  253. UpdateWindow ();
  254. }
  255. return ;
  256. }