PresetMgr.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/PresetMgr.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/23/01 6:26p $*
  29. * *
  30. * $Revision:: 20 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __PRESET_MGR_H
  39. #define __PRESET_MGR_H
  40. #include "saveloadsubsystem.h"
  41. #include "vector.h"
  42. #include "bittype.h"
  43. #include "listtypes.h"
  44. #include "ntree.h"
  45. //////////////////////////////////////////////////////////////////////////
  46. // Forward declarations
  47. //////////////////////////////////////////////////////////////////////////
  48. class PresetClass;
  49. //////////////////////////////////////////////////////////////////////////
  50. // Typedefs
  51. //////////////////////////////////////////////////////////////////////////
  52. typedef SortedNTreeClass<PresetClass *> PRESET_TREE;
  53. typedef SortedNTreeLeafClass<PresetClass *> PRESET_TREE_LEAF;
  54. typedef SortedNTreeClass<uint32> FACTORY_TREE;
  55. typedef SortedNTreeLeafClass<uint32> FACTORY_TREE_LEAF;
  56. //////////////////////////////////////////////////////////////////////////
  57. // Singleton instance
  58. //////////////////////////////////////////////////////////////////////////
  59. extern class PresetMgrClass _ThePresetMgr;
  60. //////////////////////////////////////////////////////////////////////////
  61. // Constants
  62. //////////////////////////////////////////////////////////////////////////
  63. const DWORD TEMP_DEF_ID_START = 1000000000;
  64. //////////////////////////////////////////////////////////////////////////
  65. //
  66. // PresetMgrClass
  67. //
  68. //////////////////////////////////////////////////////////////////////////
  69. class PresetMgrClass : public SaveLoadSubSystemClass
  70. {
  71. public:
  72. //////////////////////////////////////////////////////////////
  73. // Public constructors/destructors
  74. //////////////////////////////////////////////////////////////
  75. PresetMgrClass (void);
  76. virtual ~PresetMgrClass (void);
  77. //////////////////////////////////////////////////////////////
  78. // Public methods
  79. //////////////////////////////////////////////////////////////
  80. // From SaveLoadSubSystemClass
  81. virtual uint32 Chunk_ID (void) const;
  82. virtual const char * Name (void) const { return "PresetMgrClass"; }
  83. // Initialization
  84. static void Initialize (void);
  85. static void Shutdown (void);
  86. // List management
  87. static void Add_Preset (PresetClass *preset);
  88. static void Remove_Preset (PresetClass *preset);
  89. static void Free_Presets (void);
  90. static void Free_All_Embedded_Nodes (void);
  91. static bool Check_Out_Database (uint32 class_id, bool *should_undo_on_err);
  92. static bool Check_Out_Database (LPCTSTR path, bool *should_undo_on_err);
  93. static bool Check_In_Database (LPCTSTR path);
  94. static bool Is_Database_Checked_Out (LPCTSTR full_path);
  95. static bool Undo_Database_Check_Out (uint32 class_id);
  96. // Enumeration
  97. typedef enum
  98. {
  99. ID_CLASS = 1,
  100. ID_SUPERCLASS,
  101. } ID_TYPE;
  102. static PresetClass * Find_Typed_Preset (uint32 class_id, LPCTSTR name);
  103. static PresetClass * Find_Preset (uint32 id);
  104. static PresetClass * Find_Preset (LPCTSTR name);
  105. static PresetClass * Get_First (void);
  106. static PresetClass * Get_First (uint32 id, ID_TYPE type, bool include_twiddlers = false);
  107. static PresetClass * Get_Next (PresetClass *current);
  108. static PresetClass * Get_Next (PresetClass *current, uint32 class_id, ID_TYPE type, bool include_twiddlers = false);
  109. //
  110. // Tree building methods
  111. //
  112. static void Build_Preset_Tree (uint32 class_id, PRESET_TREE &tree, bool include_twiddlers = true);
  113. static void Build_Factory_Tree (uint32 class_id, FACTORY_TREE &tree);
  114. //
  115. // Content control
  116. //
  117. static void Put_Presets_Back (PRESET_LIST &preset_list);
  118. static void Remove_Non_Matching_Presets (uint32 class_id, bool class_id_matters, bool is_temp, PRESET_LIST &removed_preset_list);
  119. //
  120. // Preset creation
  121. //
  122. static PresetClass * Create_Preset (uint32 class_id, const char * name, bool is_temp);
  123. //
  124. // Dirty preset methods
  125. //
  126. static bool Are_Presets_Dirty (void) { return _PresetsDirty; }
  127. static void Set_Presets_Dirty (void) { _PresetsDirty = true; }
  128. static void Add_Dirty_Preset (int preset_id);
  129. static void Check_In_Presets (void);
  130. static void Discard_Preset_Changes (void);
  131. static bool Get_Immediate_Check_In_Mode (void) { return _ImmediateCheckInMode; }
  132. static void Set_Immediate_Check_In_Mode (bool onoff) { _ImmediateCheckInMode = onoff; }
  133. static void Add_Dirty_Preset_Files_To_VSS (void);
  134. //
  135. // Export methods
  136. //
  137. static void Export_Settings (uint32 class_id, const char *filename);
  138. protected:
  139. //////////////////////////////////////////////////////////////
  140. // Protected methods
  141. //////////////////////////////////////////////////////////////
  142. // From SaveLoadSubSystemClass
  143. virtual bool Contains_Data(void) const;
  144. virtual bool Save (ChunkSaveClass &csave);
  145. virtual bool Load (ChunkLoadClass &cload);
  146. // Save/load methods
  147. bool Save_Presets (ChunkSaveClass &csave);
  148. bool Load_Presets (ChunkLoadClass &cload);
  149. bool Save_Embedded_Node_Data (ChunkSaveClass &csave);
  150. bool Load_Embedded_Node_Data (ChunkLoadClass &csave);
  151. // Version methods
  152. static void Validate_Version (void);
  153. // Tree building methods
  154. static void Add_Children_To_Tree (uint32 parent_id, PRESET_TREE_LEAF *leaf, bool include_twiddlers);
  155. // Type checking
  156. static bool Is_One_Of (uint32 id_to_find, ID_TYPE type, bool include_twiddlers, PresetClass *preset);
  157. private:
  158. /////////////////////////////////////////////////////////////////////
  159. // Private methods
  160. /////////////////////////////////////////////////////////////////////
  161. static void Link_Preset (PresetClass *preset);
  162. static void Unlink_Preset (PresetClass *preset);
  163. /////////////////////////////////////////////////////////////////////
  164. // Static member data
  165. /////////////////////////////////////////////////////////////////////
  166. static PresetClass * _PresetListHead;
  167. static DynamicVectorClass<int> _DirtyPresetList;
  168. static bool _PresetsDirty;
  169. static bool _ImmediateCheckInMode;
  170. };
  171. /////////////////////////////////////////////////////////////////////
  172. // Get_First
  173. /////////////////////////////////////////////////////////////////////
  174. inline PresetClass *
  175. PresetMgrClass::Get_First (void)
  176. {
  177. return _PresetListHead;
  178. }
  179. //////////////////////////////////////////////////////////////////////////
  180. //
  181. // PresetListNode
  182. //
  183. //////////////////////////////////////////////////////////////////////////
  184. class PresetListNode
  185. {
  186. public:
  187. //////////////////////////////////////////////////////////////
  188. // Public constructors/destructors
  189. //////////////////////////////////////////////////////////////
  190. PresetListNode (void)
  191. : m_Preset (NULL) { }
  192. virtual ~PresetListNode (void) { Reset (); }
  193. //////////////////////////////////////////////////////////////
  194. // Public methods
  195. //////////////////////////////////////////////////////////////
  196. PresetClass * Get_Preset (void) { return m_Preset; }
  197. PRESET_NODE_LIST & Get_Children (void) { return m_Children; }
  198. void Set_Preset (PresetClass *preset) { m_Preset = preset; }
  199. void Add_Child (PresetClass *preset, bool sort = true);
  200. void Reset (void);
  201. protected:
  202. //////////////////////////////////////////////////////////////
  203. // Protected member data
  204. //////////////////////////////////////////////////////////////
  205. PRESET_NODE_LIST m_Children;
  206. PresetClass * m_Preset;
  207. };
  208. #endif //__PRESET_MGR_H