dlgcharacteroptions.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/commando/dlgcharacteroptions.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/07/02 10:56a $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgcharacteroptions.h"
  36. #include "listctrl.h"
  37. #include "translatedb.h"
  38. #include "string_ids.h"
  39. #include "skinpackagemgr.h"
  40. #include "skinpackage.h"
  41. #include "comboboxctrl.h"
  42. #include "purchasesettings.h"
  43. #include "viewerctrl.h"
  44. #include "physicalgameobj.h"
  45. #include "assets.h"
  46. #include "savegame.h"
  47. ////////////////////////////////////////////////////////////////
  48. //
  49. // CharacterOptionsMenuClass
  50. //
  51. ////////////////////////////////////////////////////////////////
  52. CharacterOptionsMenuClass::CharacterOptionsMenuClass (void) :
  53. UnloadDefs (false),
  54. MenuDialogClass (IDD_OPTIONS_CHARACTER)
  55. {
  56. SkinPackageMgrClass::Reset_List ();
  57. SkinPackageMgrClass::Build_List ();
  58. return ;
  59. }
  60. ////////////////////////////////////////////////////////////////
  61. //
  62. // ~CharacterOptionsMenuClass
  63. //
  64. ////////////////////////////////////////////////////////////////
  65. CharacterOptionsMenuClass::~CharacterOptionsMenuClass (void)
  66. {
  67. SkinPackageMgrClass::Reset_List ();
  68. //
  69. // Unload the definitions as necessary
  70. //
  71. if (UnloadDefs) {
  72. DefinitionMgrClass::Free_Definitions ();
  73. }
  74. return ;
  75. }
  76. ////////////////////////////////////////////////////////////////
  77. //
  78. // On_Init_Dialog
  79. //
  80. ////////////////////////////////////////////////////////////////
  81. void
  82. CharacterOptionsMenuClass::On_Init_Dialog (void)
  83. {
  84. Ensure_Definitions_Are_Loaded ();
  85. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_PACKAGE_COMBO);
  86. if (combo_box != NULL) {
  87. const StringClass &curr_package_name = SkinPackageMgrClass::Get_Current_Package ().Get_Name ();
  88. //
  89. // Add an entry for each package to the combobox
  90. //
  91. int count = SkinPackageMgrClass::Get_Package_Count ();
  92. for (int index = 0; index < count; index ++) {
  93. //
  94. // Add this entry to the combobox
  95. //
  96. const StringClass &name = SkinPackageMgrClass::Get_Package (index)->Get_Name ();
  97. WideStringClass wide_name;
  98. wide_name.Convert_From (name);
  99. int item_index = combo_box->Add_String (wide_name);
  100. //
  101. // Select this entry if its the active package
  102. //
  103. if (name.Compare_No_Case (curr_package_name) == 0) {
  104. combo_box->Set_Curr_Sel (item_index);
  105. }
  106. }
  107. //
  108. // Ensure that at least the first entry is selected
  109. //
  110. int curr_sel = combo_box->Get_Curr_Sel ();
  111. if (curr_sel == -1) {
  112. curr_sel = 0;
  113. combo_box->Set_Curr_Sel (curr_sel);
  114. }
  115. }
  116. //
  117. // Fill in the list of characters that can be overridden
  118. //
  119. Fill_Character_Combobox ();
  120. MenuDialogClass::On_Init_Dialog ();
  121. return ;
  122. }
  123. ////////////////////////////////////////////////////////////////
  124. //
  125. // On_Command
  126. //
  127. ////////////////////////////////////////////////////////////////
  128. void
  129. CharacterOptionsMenuClass::On_Command (int ctrl_id, int message_id, DWORD param)
  130. {
  131. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  132. return ;
  133. }
  134. ////////////////////////////////////////////////////////////////
  135. //
  136. // Fill_Character_Combobox
  137. //
  138. ////////////////////////////////////////////////////////////////
  139. void
  140. CharacterOptionsMenuClass::Fill_Character_Combobox (void)
  141. {
  142. PurchaseSettingsDefClass *settings1 = PurchaseSettingsDefClass::Find_Definition (PurchaseSettingsDefClass::TYPE_CLASSES, PurchaseSettingsDefClass::TEAM_GDI);
  143. PurchaseSettingsDefClass *settings2 = PurchaseSettingsDefClass::Find_Definition (PurchaseSettingsDefClass::TYPE_CLASSES, PurchaseSettingsDefClass::TEAM_NOD);
  144. if (settings1 == NULL || settings2 == NULL) {
  145. return ;
  146. }
  147. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_CHARACTER_COMBO);
  148. if (combo_box == NULL) {
  149. return ;
  150. }
  151. //
  152. // Fill in the GDI characters
  153. //
  154. const int MAX_ENTRIES = 10;
  155. for (int index = 0; index < MAX_ENTRIES; index ++) {
  156. int item_index = combo_box->Add_String (settings1->Get_Name (index));
  157. if (item_index != -1) {
  158. combo_box->Set_Item_Data (item_index, settings1->Get_Definition (index));
  159. }
  160. }
  161. //
  162. // Fill in the NOD characters
  163. //
  164. for (index = 0; index < MAX_ENTRIES; index ++) {
  165. int item_index = combo_box->Add_String (settings2->Get_Name (index));
  166. if (item_index != -1) {
  167. combo_box->Set_Item_Data (item_index, settings2->Get_Definition (index));
  168. }
  169. }
  170. //
  171. // Select the first entry by default
  172. //
  173. combo_box->Set_Curr_Sel (0);
  174. On_Character_Selected (0);
  175. return ;
  176. }
  177. ////////////////////////////////////////////////////////////////
  178. //
  179. // On_ComboBoxCtrl_Sel_Change
  180. //
  181. ////////////////////////////////////////////////////////////////
  182. void
  183. CharacterOptionsMenuClass::On_ComboBoxCtrl_Sel_Change
  184. (
  185. ComboBoxCtrlClass * combo_ctrl,
  186. int ctrl_id,
  187. int old_sel,
  188. int new_sel
  189. )
  190. {
  191. if (ctrl_id == IDC_PACKAGE_COMBO) {
  192. //
  193. // Select the current package and populate the skin list control
  194. //
  195. SkinPackageMgrClass::Set_Current_Package (new_sel);
  196. } else if (ctrl_id == IDC_CHARACTER_COMBO) {
  197. On_Character_Selected (new_sel);
  198. }
  199. return ;
  200. }
  201. ////////////////////////////////////////////////////////////////
  202. //
  203. // On_Character_Selected
  204. //
  205. ////////////////////////////////////////////////////////////////
  206. void
  207. CharacterOptionsMenuClass::On_Character_Selected (int index)
  208. {
  209. ComboBoxCtrlClass *combo_box = (ComboBoxCtrlClass *)Get_Dlg_Item (IDC_CHARACTER_COMBO);
  210. if (combo_box == NULL) {
  211. return ;
  212. }
  213. //
  214. // Display the model for this purchase
  215. //
  216. uint32 definition_id = combo_box->Get_Item_Data (index);
  217. Display_Default_Model (definition_id);
  218. return ;
  219. }
  220. ////////////////////////////////////////////////////////////////
  221. //
  222. // Display_Default_Model
  223. //
  224. ////////////////////////////////////////////////////////////////
  225. void
  226. CharacterOptionsMenuClass::Display_Default_Model (int definition_id)
  227. {
  228. //
  229. // Lookup the definition that goes with this character
  230. //
  231. DefinitionClass *definition = DefinitionMgrClass::Find_Definition (definition_id);
  232. if (definition != NULL) {
  233. PhysicalGameObjDef *phys_game_obj_def = static_cast<PhysicalGameObjDef *> (definition);
  234. //
  235. // Now, lookup the physics definition that this game object uses
  236. //
  237. DefinitionClass *phys_def = DefinitionMgrClass::Find_Definition (phys_game_obj_def->Get_Phys_Def_ID ());
  238. if (phys_def != NULL) {
  239. //
  240. // Display the model that this physics definition requires
  241. //
  242. const char *model_name = ((PhysDefClass *)phys_def)->Get_Model_Name ();
  243. Display_Model (model_name);
  244. }
  245. }
  246. return ;
  247. }
  248. ////////////////////////////////////////////////////////////////
  249. //
  250. // Display_Model
  251. //
  252. ////////////////////////////////////////////////////////////////
  253. void
  254. CharacterOptionsMenuClass::Display_Model (const char *model_name)
  255. {
  256. ViewerCtrlClass *viewer_ctrl = (ViewerCtrlClass *)Get_Dlg_Item (IDC_MODEL_VIEWER);
  257. if (viewer_ctrl == NULL) {
  258. return ;
  259. }
  260. //
  261. // Create and display model
  262. //
  263. RenderObjClass *model = ::Create_Render_Obj_From_Filename (model_name);
  264. viewer_ctrl->Set_Model (model);
  265. viewer_ctrl->Set_Animation ("S_A_HUMAN.H_A_A0A0");
  266. viewer_ctrl->Set_Interface_Mode (ViewerCtrlClass::Z_ROTATION, 45.0F);
  267. return ;
  268. }
  269. ////////////////////////////////////////////////////////////////
  270. //
  271. // Ensure_Definitions_Are_Loaded
  272. //
  273. ////////////////////////////////////////////////////////////////
  274. void
  275. CharacterOptionsMenuClass::Ensure_Definitions_Are_Loaded (void)
  276. {
  277. if (DefinitionMgrClass::Get_First () != NULL) {
  278. return ;
  279. }
  280. //
  281. // Force load the definitions as necessary
  282. //
  283. SaveGameManager::Load_Definitions ();
  284. UnloadDefs = true;
  285. return ;
  286. }