dlgevaobjectivestab.cpp 8.6 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. /***********************************************************************************************
  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/dlgevaobjectivestab.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/07/01 12:28p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgevaobjectivestab.h"
  36. #include "listctrl.h"
  37. #include "string_ids.h"
  38. #include "translatedb.h"
  39. #include "objectives.h"
  40. #include "imagectrl.h"
  41. ////////////////////////////////////////////////////////////////
  42. // Local constants
  43. ////////////////////////////////////////////////////////////////
  44. enum
  45. {
  46. COL_PRIORITY = 0,
  47. COL_TEXT,
  48. COL_STATUS
  49. };
  50. //
  51. // This is extremely poor, but I need to get the index
  52. // of the currently displayed POG in the HUD.
  53. //
  54. extern int CurrentObjectiveIndex;
  55. ////////////////////////////////////////////////////////////////
  56. //
  57. // EvaObjectivesTabClass
  58. //
  59. ////////////////////////////////////////////////////////////////
  60. EvaObjectivesTabClass::EvaObjectivesTabClass (void) :
  61. ChildDialogClass (IDD_ENCYCLOPEDIA_OBJECTIVES_TAB)
  62. {
  63. return ;
  64. }
  65. ////////////////////////////////////////////////////////////////
  66. //
  67. // On_Init_Dialog
  68. //
  69. ////////////////////////////////////////////////////////////////
  70. void
  71. EvaObjectivesTabClass::On_Init_Dialog (void)
  72. {
  73. //
  74. // Get a pointer to the list control
  75. //
  76. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_OBJECTIVES_LIST_CTRL);
  77. if (list_ctrl != NULL) {
  78. //
  79. // Configure the list control
  80. //
  81. list_ctrl->Add_Column (TRANSLATE (IDS_OBJHDR_PRIORITY), 0.25F, Vector3 (1, 1, 1));
  82. list_ctrl->Add_Column (TRANSLATE (IDS_OBJHDR_OBJECTIVE), 0.5F, Vector3 (1, 1, 1));
  83. list_ctrl->Add_Column (TRANSLATE (IDS_OBJHDR_STATUS), 0.25F, Vector3 (1, 1, 1));
  84. Fill_Objectives_List ();
  85. }
  86. ChildDialogClass::On_Init_Dialog ();
  87. return ;
  88. }
  89. ////////////////////////////////////////////////////////////////
  90. //
  91. // On_Command
  92. //
  93. ////////////////////////////////////////////////////////////////
  94. void
  95. EvaObjectivesTabClass::On_Command (int ctrl_id, int message_id, DWORD param)
  96. {
  97. ChildDialogClass::On_Command (ctrl_id, message_id, param);
  98. return ;
  99. }
  100. ////////////////////////////////////////////////////////////////
  101. //
  102. // On_ListCtrl_Sel_Change
  103. //
  104. ////////////////////////////////////////////////////////////////
  105. void
  106. EvaObjectivesTabClass::On_ListCtrl_Sel_Change (ListCtrlClass *list_ctrl, int ctrl_id, int old_index, int new_index)
  107. {
  108. if (ctrl_id == IDC_OBJECTIVES_LIST_CTRL) {
  109. Update_Curr_Objective_Controls ();
  110. }
  111. return ;
  112. }
  113. ////////////////////////////////////////////////////////////////
  114. //
  115. // Update_Curr_Objective_Controls
  116. //
  117. ////////////////////////////////////////////////////////////////
  118. void
  119. EvaObjectivesTabClass::Update_Curr_Objective_Controls (void)
  120. {
  121. //
  122. // Get a pointer to the list controls
  123. //
  124. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_OBJECTIVES_LIST_CTRL);
  125. ImageCtrlClass *image_ctrl = (ImageCtrlClass *)Get_Dlg_Item (IDC_IMAGE);
  126. if (list_ctrl == NULL || image_ctrl == NULL) {
  127. return ;
  128. }
  129. //
  130. // Get the current selection from the list control
  131. //
  132. int curr_sel = list_ctrl->Get_Curr_Sel ();
  133. if (curr_sel >= 0) {
  134. Objective *objective = ObjectiveManager::Get_Objective (list_ctrl->Get_Entry_Data (curr_sel, 0));
  135. if (objective != NULL) {
  136. //
  137. // Put the long description into the edit control
  138. //
  139. Set_Dlg_Item_Text (IDC_DESCRIPTION_EDIT, TRANSLATE (objective->LongDescriptionID));
  140. //
  141. // Configure the image ctrl
  142. //
  143. image_ctrl->Set_Texture (objective->HUDPogTextureName);
  144. }
  145. }
  146. return ;
  147. }
  148. ////////////////////////////////////////////////////////////////
  149. //
  150. // Fill_Objectives_List
  151. //
  152. ////////////////////////////////////////////////////////////////
  153. void
  154. EvaObjectivesTabClass::Fill_Objectives_List (void)
  155. {
  156. //
  157. // Get a pointer to the list control
  158. //
  159. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_OBJECTIVES_LIST_CTRL);
  160. if (list_ctrl == NULL) {
  161. return ;
  162. }
  163. //
  164. // Loop over all the objectives
  165. //
  166. int count = ObjectiveManager::Get_Objective_Count ();
  167. for (int index = 0; index < count; index ++) {
  168. Objective *objective = ObjectiveManager::Get_Objective (index);
  169. if (objective != NULL) {
  170. //
  171. // Don't display hidden objectives (unless you really want to)
  172. //
  173. if ( objective->Status != ObjectiveManager::STATUS_HIDDEN ||
  174. ObjectiveManager::Is_Objective_Debug_Mode_Enabled ())
  175. {
  176. //
  177. // Add this entry to the list
  178. //
  179. int item_index = list_ctrl->Insert_Entry (index, objective->Type_To_Name ());
  180. if (item_index != -1) {
  181. WideStringClass text = TRANSLATE (objective->ShortDescriptionID);
  182. //
  183. // Strip off the line delimiter (if necessary)
  184. //
  185. if (text.Get_Length () > 0 && text[text.Get_Length () - 1] == L'\n') {
  186. text.Erase (text.Get_Length () - 1, 1);
  187. }
  188. list_ctrl->Set_Entry_Text (item_index, COL_TEXT, text);
  189. list_ctrl->Set_Entry_Text (item_index, COL_STATUS, objective->Status_To_Name ());
  190. list_ctrl->Set_Entry_Data (item_index, 0, index);
  191. //
  192. // Colorize this entry
  193. //
  194. Vector3 color = objective->Type_To_Color ();
  195. list_ctrl->Set_Entry_Color (item_index, COL_PRIORITY, color);
  196. list_ctrl->Set_Entry_Color (item_index, COL_TEXT, color);
  197. list_ctrl->Set_Entry_Color (item_index, COL_STATUS, color);
  198. }
  199. }
  200. }
  201. }
  202. //
  203. // Sort the objectives...
  204. //
  205. list_ctrl->Sort (ListSortCallback, 0);
  206. //
  207. // Select the first entry by default
  208. //
  209. if (count > 0) {
  210. list_ctrl->Set_Curr_Sel (0);
  211. Update_Curr_Objective_Controls ();
  212. }
  213. return ;
  214. }
  215. ////////////////////////////////////////////////////////////////
  216. //
  217. // ListSortCallback
  218. //
  219. ////////////////////////////////////////////////////////////////
  220. int CALLBACK
  221. EvaObjectivesTabClass::ListSortCallback
  222. (
  223. ListCtrlClass * list_ctrl,
  224. int item_index1,
  225. int item_index2,
  226. uint32 user_param
  227. )
  228. {
  229. int count = list_ctrl->Get_Entry_Count ();
  230. Objective *objective1 = ObjectiveManager::Get_Objective (list_ctrl->Get_Entry_Data (item_index1, 0));
  231. Objective *objective2 = ObjectiveManager::Get_Objective (list_ctrl->Get_Entry_Data (item_index2, 0));
  232. int result = 0;
  233. //
  234. // Sort the objective based on status
  235. //
  236. if ( objective1->Status != ObjectiveManager::STATUS_ACCOMPLISHED &&
  237. objective2->Status == ObjectiveManager::STATUS_ACCOMPLISHED)
  238. {
  239. result = -1;
  240. } else if ( objective1->Status == ObjectiveManager::STATUS_ACCOMPLISHED &&
  241. objective2->Status != ObjectiveManager::STATUS_ACCOMPLISHED)
  242. {
  243. result = 1;
  244. } else {
  245. if (item_index1 < CurrentObjectiveIndex) {
  246. item_index1 += count;
  247. }
  248. if (item_index2 < CurrentObjectiveIndex) {
  249. item_index2 += count;
  250. }
  251. //
  252. // Sort based on relative position to the current objective
  253. //
  254. result = (item_index1 - item_index2);
  255. }
  256. return result;
  257. }