dlgcncteaminfo.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 : commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgcncteaminfo.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/24/02 2:06p $*
  29. * *
  30. * $Revision:: 12 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgcncteaminfo.h"
  36. #include "resource.h"
  37. #include "listctrl.h"
  38. #include "imagectrl.h"
  39. #include "playertype.h"
  40. #include "combat.h"
  41. #include "playermanager.h"
  42. #include "player.h"
  43. #include "soldier.h"
  44. #include "gameinitmgr.h"
  45. #include "gamemode.h"
  46. #include "input.h"
  47. #include "healthbarctrl.h"
  48. #include "basecontroller.h"
  49. #include "building.h"
  50. #include "damage.h"
  51. #include "vehicle.h"
  52. #include "assets.h"
  53. #include "translatedb.h"
  54. #include "WOLGMode.h"
  55. #include <WWOnline\WOLUser.h>
  56. #include "string_ids.h"
  57. #include "mousemgr.h"
  58. #include "directinput.h"
  59. ////////////////////////////////////////////////////////////////
  60. // Local constants
  61. ////////////////////////////////////////////////////////////////
  62. enum
  63. {
  64. COL_RANK,
  65. COL_NAME,
  66. COL_CREDITS,
  67. COL_SCORE,
  68. COL_CHARACTER,
  69. COL_VEHICLE,
  70. };
  71. ////////////////////////////////////////////////////////////////
  72. //
  73. // CNCTeamInfoDialogClass
  74. //
  75. ////////////////////////////////////////////////////////////////
  76. CNCTeamInfoDialogClass::CNCTeamInfoDialogClass (void) :
  77. MenuDialogClass (IDD_CNC_TEAM_INFO)
  78. {
  79. return ;
  80. }
  81. ////////////////////////////////////////////////////////////////
  82. //
  83. // ~CNCTeamInfoDialogClass
  84. //
  85. ////////////////////////////////////////////////////////////////
  86. CNCTeamInfoDialogClass::~CNCTeamInfoDialogClass (void)
  87. {
  88. GameInitMgrClass::Continue_Game ();
  89. return ;
  90. }
  91. ////////////////////////////////////////////////////////////////
  92. //
  93. // On_Init_Dialog
  94. //
  95. ////////////////////////////////////////////////////////////////
  96. void
  97. CNCTeamInfoDialogClass::On_Init_Dialog (void)
  98. {
  99. MenuDialogClass::On_Init_Dialog ();
  100. MouseMgrClass::Show_Cursor (false);
  101. //
  102. // Get a pointer to the list control
  103. //
  104. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  105. if (list_ctrl != NULL) {
  106. //
  107. // Configure the columns
  108. //
  109. list_ctrl->Add_Column (TRANSLATE (IDS_MENU_RANK), 0.065F, Vector3 (1, 1, 1));
  110. list_ctrl->Add_Column (TRANSLATE (IDS_MENU_NAME), 0.2F, Vector3 (1, 1, 1));
  111. list_ctrl->Add_Column (TRANSLATE (IDS_MP_MONEY), 0.092F, Vector3 (1, 1, 1));
  112. list_ctrl->Add_Column (TRANSLATE (IDS_MENU_SCORE), 0.075F, Vector3 (1, 1, 1));
  113. list_ctrl->Add_Column (TRANSLATE (IDS_MENU_TEXT004), 0.33F, Vector3 (1, 1, 1));
  114. list_ctrl->Add_Column (TRANSLATE (IDS_MENU_TEXT002), 0.24F, Vector3 (1, 1, 1));
  115. //
  116. // Configure the icon support
  117. //
  118. list_ctrl->Set_Min_Row_Height (20);
  119. list_ctrl->Set_Icon_Size (19, 19);
  120. }
  121. //
  122. // Fill in the player list
  123. //
  124. Populate_Player_List ();
  125. //
  126. // Setup the team and building icons on the dialog
  127. //
  128. Configure_Icons ();
  129. //
  130. // Activate the menu game mode (if necessary)
  131. //
  132. GameModeClass *menu_game_mode = GameModeManager::Find ("Menu");
  133. if (menu_game_mode != NULL && menu_game_mode->Is_Active () == false) {
  134. menu_game_mode->Activate ();
  135. }
  136. return ;
  137. }
  138. ////////////////////////////////////////////////////////////////
  139. //
  140. // Configure_Icons
  141. //
  142. ////////////////////////////////////////////////////////////////
  143. void
  144. CNCTeamInfoDialogClass::Configure_Icons (void)
  145. {
  146. BaseControllerClass *base = BaseControllerClass::Find_Base_For_Star ();
  147. if (base == NULL) {
  148. return ;
  149. }
  150. StringClass team_icon_name ("HUD_C&C_GDILOGO.TGA");
  151. StringClass defenses_icon_name ("HUD_C&C_G_GUARDTOW.TGA");
  152. StringClass refinery_icon_name ("HUD_C&C_G_REFINERY.TGA");
  153. StringClass pplant_icon_name ("HUD_C&C_G_POWER.TGA");
  154. StringClass sfact_icon_name ("HUD_C&C_G_BARRACKS.TGA");
  155. StringClass vfact_icon_name ("HUD_C&C_G_WARFACT.TGA");
  156. //
  157. // Switch icons for the NOD team
  158. //
  159. if (COMBAT_STAR->Get_Player_Type () == PLAYERTYPE_NOD) {
  160. team_icon_name = "HUD_C&C_NODLOGO.TGA";
  161. defenses_icon_name = "HUD_C&C_OBLISK.TGA";
  162. refinery_icon_name = "HUD_C&C_N_REFINERY.TGA";
  163. pplant_icon_name = "HUD_C&C_N_POWER.TGA";
  164. sfact_icon_name = "HUD_C&C_N_HANDOF.TGA";
  165. vfact_icon_name = "HUD_C&C_N_AIRSTRIP.TGA";
  166. }
  167. const int ICON_CTRLS[] =
  168. {
  169. IDC_BUILDING01_ICON,
  170. IDC_BUILDING02_ICON,
  171. IDC_BUILDING03_ICON,
  172. IDC_BUILDING04_ICON,
  173. IDC_BUILDING05_ICON,
  174. };
  175. const int HEALTH_CTRLS[] =
  176. {
  177. IDC_BUILDING01_HEALTHBAR,
  178. IDC_BUILDING02_HEALTHBAR,
  179. IDC_BUILDING03_HEALTHBAR,
  180. IDC_BUILDING04_HEALTHBAR,
  181. IDC_BUILDING05_HEALTHBAR,
  182. };
  183. int next_slot = 0;
  184. //
  185. // Configure the image ctrls on the dialog
  186. //
  187. ((ImageCtrlClass *)Get_Dlg_Item (IDC_TEAM_ICON))->Set_Texture (team_icon_name);
  188. //
  189. // Configure the base defense building
  190. //
  191. BuildingGameObj *building = base->Find_Building (BuildingConstants::TYPE_BASE_DEFENSE);
  192. if (building != NULL) {
  193. float life = building->Get_Defense_Object ()->Get_Health () / building->Get_Defense_Object ()->Get_Health_Max ();
  194. ((ImageCtrlClass *)Get_Dlg_Item (ICON_CTRLS[next_slot]))->Set_Texture (defenses_icon_name);
  195. ((HealthBarCtrlClass *)Get_Dlg_Item (HEALTH_CTRLS[next_slot]))->Set_Life (life);
  196. next_slot ++;
  197. }
  198. //
  199. // Configure the refinery building
  200. //
  201. building = base->Find_Building (BuildingConstants::TYPE_REFINERY);
  202. if (building != NULL) {
  203. float life = building->Get_Defense_Object ()->Get_Health () / building->Get_Defense_Object ()->Get_Health_Max ();
  204. ((ImageCtrlClass *)Get_Dlg_Item (ICON_CTRLS[next_slot]))->Set_Texture (refinery_icon_name);
  205. ((HealthBarCtrlClass *)Get_Dlg_Item (HEALTH_CTRLS[next_slot]))->Set_Life (life);
  206. next_slot ++;
  207. }
  208. //
  209. // Configure the powerplant building
  210. //
  211. building = base->Find_Building (BuildingConstants::TYPE_POWER_PLANT);
  212. if (building != NULL) {
  213. float life = building->Get_Defense_Object ()->Get_Health () / building->Get_Defense_Object ()->Get_Health_Max ();
  214. ((ImageCtrlClass *)Get_Dlg_Item (ICON_CTRLS[next_slot]))->Set_Texture (pplant_icon_name);
  215. ((HealthBarCtrlClass *)Get_Dlg_Item (HEALTH_CTRLS[next_slot]))->Set_Life (life);
  216. next_slot ++;
  217. }
  218. //
  219. // Configure the soldier factory building
  220. //
  221. building = base->Find_Building (BuildingConstants::TYPE_SOLDIER_FACTORY);
  222. if (building != NULL) {
  223. float life = building->Get_Defense_Object ()->Get_Health () / building->Get_Defense_Object ()->Get_Health_Max ();
  224. ((ImageCtrlClass *)Get_Dlg_Item (ICON_CTRLS[next_slot]))->Set_Texture (sfact_icon_name);
  225. ((HealthBarCtrlClass *)Get_Dlg_Item (HEALTH_CTRLS[next_slot]))->Set_Life (life);
  226. next_slot ++;
  227. }
  228. //
  229. // Configure the soldier factory building
  230. //
  231. building = base->Find_Building (BuildingConstants::TYPE_VEHICLE_FACTORY);
  232. if (building != NULL) {
  233. float life = building->Get_Defense_Object ()->Get_Health () / building->Get_Defense_Object ()->Get_Health_Max ();
  234. ((ImageCtrlClass *)Get_Dlg_Item (ICON_CTRLS[next_slot]))->Set_Texture (vfact_icon_name);
  235. ((HealthBarCtrlClass *)Get_Dlg_Item (HEALTH_CTRLS[next_slot]))->Set_Life (life);
  236. next_slot ++;
  237. }
  238. //
  239. // Hide the remaining (unused) controls
  240. //
  241. for (int index = next_slot; index < 5; index ++) {
  242. Get_Dlg_Item (ICON_CTRLS[index])->Show (false);
  243. Get_Dlg_Item (HEALTH_CTRLS[index])->Show (false);
  244. }
  245. return ;
  246. }
  247. ////////////////////////////////////////////////////////////////
  248. //
  249. // Populate_Player_List
  250. //
  251. ////////////////////////////////////////////////////////////////
  252. void
  253. CNCTeamInfoDialogClass::Populate_Player_List (void)
  254. {
  255. //
  256. // Get a pointer to the list control
  257. //
  258. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  259. if (list_ctrl == NULL) {
  260. return ;
  261. }
  262. //
  263. // Determine which team the player is on
  264. //
  265. int team_id = COMBAT_STAR->Get_Player_Type ();
  266. //
  267. // Find the player's name that most closely matches the typed name
  268. //
  269. int index = 0;
  270. for ( SLNode<cPlayer> *player_node = cPlayerManager::Get_Player_Object_List ()->Head ();
  271. player_node != NULL;
  272. player_node = player_node->Next ())
  273. {
  274. cPlayer *player = player_node->Data ();
  275. WWASSERT (player != NULL);
  276. if (player->Get_Is_Active().Is_False()) {
  277. continue;
  278. }
  279. //
  280. // Does this player belong to the same team?
  281. //
  282. if (player->Get_Player_Type () == team_id) {
  283. //
  284. // Make a new entry for this player
  285. //
  286. int item_index = list_ctrl->Insert_Entry (index ++, L"");
  287. if (item_index >= 0) {
  288. WideStringClass displayName(0, true);
  289. Build_Player_Display_Name(player, displayName);
  290. list_ctrl->Set_Entry_Text (item_index, COL_NAME, (const WCHAR*)displayName);
  291. list_ctrl->Set_Entry_Int (item_index, COL_RANK, player->Get_Rung ());
  292. list_ctrl->Set_Entry_Int (item_index, COL_CREDITS, (int) player->Get_Money ());
  293. list_ctrl->Set_Entry_Int (item_index, COL_SCORE, (int) player->Get_Score ());
  294. //
  295. // Fill in the character and vehicle columns
  296. //
  297. SmartGameObj *game_obj = player->Get_GameObj ();
  298. if (game_obj != NULL && game_obj->As_SoldierGameObj () != NULL) {
  299. //StringClass tga_filename;
  300. //::Strip_Path_From_Filename (tga_filename, game_obj->Get_Definition ().Get_Icon_Filename ());
  301. //list_ctrl->Add_Icon (item_index, COL_CHARACTER, tga_filename);
  302. const WCHAR *name = TRANSLATE (game_obj->Get_Translated_Name_ID ());
  303. list_ctrl->Set_Entry_Text (item_index, COL_CHARACTER, name);
  304. //
  305. // Fill in the vehicle icon (if the player is in one)
  306. //
  307. SoldierGameObj *soldier = game_obj->As_SoldierGameObj ();
  308. VehicleGameObj *vehicle = soldier->Get_Vehicle ();
  309. if (vehicle != NULL) {
  310. //::Strip_Path_From_Filename (tga_filename, vehicle->Get_Definition ().Get_Icon_Filename ());
  311. //list_ctrl->Add_Icon (item_index, COL_VEHICLE, tga_filename);
  312. name = TRANSLATE (vehicle->Get_Translated_Name_ID ());
  313. list_ctrl->Set_Entry_Text (item_index, COL_VEHICLE, name);
  314. }
  315. }
  316. //
  317. // Put a star by the player's name if this is the local player
  318. //
  319. if (game_obj == COMBAT_STAR) {
  320. list_ctrl->Add_Icon (item_index, COL_NAME, "IF_LRGSTAR.TGA");
  321. list_ctrl->Set_Entry_Color (item_index, COL_RANK, Vector3 (1.0F, 1.0F, 1.0F));
  322. list_ctrl->Set_Entry_Color (item_index, COL_NAME, Vector3 (1.0F, 1.0F, 1.0F));
  323. list_ctrl->Set_Entry_Color (item_index, COL_CREDITS, Vector3 (1.0F, 1.0F, 1.0F));
  324. list_ctrl->Set_Entry_Color (item_index, COL_SCORE, Vector3 (1.0F, 1.0F, 1.0F));
  325. list_ctrl->Set_Entry_Color (item_index, COL_CHARACTER, Vector3 (1.0F, 1.0F, 1.0F));
  326. list_ctrl->Set_Entry_Color (item_index, COL_VEHICLE, Vector3 (1.0F, 1.0F, 1.0F));
  327. }
  328. //
  329. // Set the ranking as this entries user data so we can sort by it...
  330. //
  331. list_ctrl->Set_Entry_Data (item_index, COL_RANK, player->Get_Rung ());
  332. }
  333. }
  334. }
  335. //
  336. // Now, sort the players by rank
  337. //
  338. list_ctrl->Sort (ListSortCallback, 0);
  339. // list_ctrl->Auto_Size_Columns_Include_Contents (4.0F);
  340. return ;
  341. }
  342. ////////////////////////////////////////////////////////////////
  343. //
  344. // ListSortCallback
  345. //
  346. ////////////////////////////////////////////////////////////////
  347. int CALLBACK
  348. CNCTeamInfoDialogClass::ListSortCallback
  349. (
  350. ListCtrlClass * list_ctrl,
  351. int item_index1,
  352. int item_index2,
  353. uint32 user_param
  354. )
  355. {
  356. int rank1 = (int)list_ctrl->Get_Entry_Data (item_index1, COL_RANK);
  357. int rank2 = (int)list_ctrl->Get_Entry_Data (item_index2, COL_RANK);
  358. return (rank1 - rank2);
  359. }
  360. ////////////////////////////////////////////////////////////////
  361. //
  362. // On_Frame_Update
  363. //
  364. ////////////////////////////////////////////////////////////////
  365. void
  366. CNCTeamInfoDialogClass::On_Frame_Update (void)
  367. {
  368. //
  369. // End the dialog when the user releases the player list key
  370. //
  371. int dik_id = Input::Get_Primary_Key_For_Function (INPUT_FUNCTION_TEAM_INFO_TOGGLE);
  372. if ((DirectInput::Get_Keyboard_Button (dik_id) & DirectInput::DI_BUTTON_HELD) == 0) {
  373. End_Dialog ();
  374. }
  375. return ;
  376. }
  377. void CNCTeamInfoDialogClass::Build_Player_Display_Name(const cPlayer* player, WideStringClass& outName)
  378. {
  379. // Denzil 02/24/02 Day 1 Patch - Do not show clan abbreviation for now because
  380. // it does not always fit in the space alloted. For now it is better not to
  381. // show it than to have it chopped off.
  382. #if(0)
  383. GameModeClass* gameMode = GameModeManager::Find("WOL");
  384. if (gameMode && gameMode->Is_Active()) {
  385. WolGameModeClass* wolGame = static_cast<WolGameModeClass*>(gameMode);
  386. WWASSERT(wolGame);
  387. RefPtr<WWOnline::UserData> user = wolGame->Get_WOL_User_Data(player->Get_Name());
  388. if (user.IsValid()) {
  389. // Set there clan information
  390. RefPtr<WWOnline::SquadData> clan = user->GetSquad();
  391. if (clan.IsValid()) {
  392. outName.Format(L"%s [%S]", player->Get_Name(), clan->GetAbbr());
  393. return;
  394. }
  395. }
  396. }
  397. #endif
  398. outName = player->Get_Name();
  399. }