objectivesviewer.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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/Combat/objectivesviewer.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/23/02 3:31p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "objectivesviewer.h"
  36. #include "assetmgr.h"
  37. #include "texture.h"
  38. #include "font3d.h"
  39. #include "objectives.h"
  40. #include "translatedb.h"
  41. #include "wwaudio.h"
  42. #include "globalsettings.h"
  43. #include "scene.h"
  44. #include "evasettings.h"
  45. #include "rendobj.h"
  46. #include "string_ids.h"
  47. ////////////////////////////////////////////////////////////////
  48. // Constants
  49. ////////////////////////////////////////////////////////////////
  50. static const char *FONT_NAME = "FONT6X8.TGA";
  51. static const char *HEADER_FONT_NAME = "FONT8X8.TGA";
  52. static const char *BACKGROUND_MODEL_NAME = "FRAME_1BIG";
  53. static const char *UPPER_LEFT_BONE_NAME = "BONE00";
  54. static const char *LOWER_RIGHT_BONE_NAME = "BONE01";
  55. ////////////////////////////////////////////////////////////////
  56. //
  57. // ObjectivesViewerClass
  58. //
  59. ////////////////////////////////////////////////////////////////
  60. ObjectivesViewerClass::ObjectivesViewerClass (void) :
  61. IsDisplayed (false),
  62. TextWindow (NULL)
  63. {
  64. return ;
  65. }
  66. ////////////////////////////////////////////////////////////////
  67. //
  68. // ~ObjectivesViewerClass
  69. //
  70. ////////////////////////////////////////////////////////////////
  71. ObjectivesViewerClass::~ObjectivesViewerClass (void)
  72. {
  73. return ;
  74. }
  75. ////////////////////////////////////////////////////////////////
  76. //
  77. // Shutdown
  78. //
  79. ////////////////////////////////////////////////////////////////
  80. void
  81. ObjectivesViewerClass::Shutdown (void)
  82. {
  83. if (TextWindow != NULL) {
  84. delete TextWindow;
  85. TextWindow = NULL;
  86. }
  87. IsDisplayed = false;
  88. return ;
  89. }
  90. ////////////////////////////////////////////////////////////////
  91. //
  92. // Initialize
  93. //
  94. ////////////////////////////////////////////////////////////////
  95. void
  96. ObjectivesViewerClass::Initialize (void)
  97. {
  98. //
  99. // Start fresh
  100. //
  101. if (TextWindow != NULL) {
  102. delete TextWindow;
  103. TextWindow = NULL;
  104. }
  105. //
  106. // Allocate the new text window
  107. //
  108. TextWindow = new TextWindowClass;
  109. EvaSettingsDefClass *settings = EvaSettingsDefClass::Get_Instance ();
  110. //
  111. // Configure the backdrop for the text window
  112. //
  113. TextWindow->Set_Backdrop ("hud_6x4_Messages.tga", settings->Get_Objectives_Screen_Rect (),
  114. settings->Get_Objectives_Texture_Size (), settings->Get_Objectives_Endcap_Rect (),
  115. settings->Get_Objectives_Fadeout_Rect (), settings->Get_Objectives_Background_Rect ());
  116. //
  117. // Configure the area where text can be displayed in the window
  118. //
  119. TextWindow->Set_Text_Area (settings->Get_Objectives_Text_Rect ());
  120. //
  121. // Configure the fonts for the window
  122. //
  123. TextWindow->Set_Heading_Font (HEADER_FONT_NAME);
  124. TextWindow->Set_Text_Font (FONT_NAME);
  125. //
  126. // Configure the columns
  127. //
  128. TextWindow->Add_Column (TRANSLATE (IDS_MENU_MISSION_OBJECTIVE), 0.8F, Vector3 (0.75F, 1.0F, 0.75F));
  129. TextWindow->Add_Column (TRANSLATE (IDS_OBJ_STATUS), 0.2F, Vector3 (0.75F, 1.0F, 0.75F));
  130. TextWindow->Display_Columns (true);
  131. return ;
  132. }
  133. ////////////////////////////////////////////////////////////////
  134. //
  135. // Update
  136. //
  137. ////////////////////////////////////////////////////////////////
  138. void
  139. ObjectivesViewerClass::Update (void)
  140. {
  141. if (TextWindow == NULL) {
  142. return ;
  143. }
  144. int objective_count = ObjectiveManager::ObjectiveList.Count ();
  145. //
  146. // Build a temporary list of objectives that we can sort
  147. //
  148. SimpleDynVecClass<Objective *> sorted_list;
  149. for (int index = 0; index < objective_count; index ++){
  150. Objective *objective = ObjectiveManager::ObjectiveList[index];
  151. //
  152. // Filter out hidden objectives (if necessary)
  153. //
  154. if ( ObjectiveManager::Is_Objective_Debug_Mode_Enabled() == true ||
  155. (objective->Status != ObjectiveManager::STATUS_HIDDEN && objective->Status != ObjectiveManager::STATUS_ACCOMPLISHED))
  156. {
  157. sorted_list.Add (objective);
  158. }
  159. }
  160. objective_count = sorted_list.Count ();
  161. //
  162. // Sort the objectives
  163. //
  164. if (objective_count > 0) {
  165. ::qsort (&sorted_list[0], objective_count, sizeof (Objective *), fnCompareObjectivesCallback);
  166. }
  167. //
  168. // Start fresh
  169. //
  170. TextWindow->Delete_All_Items ();
  171. //
  172. // Add all the objectives to the text window
  173. //
  174. for (index = 0; index < objective_count; index ++){
  175. Objective *objective = sorted_list[index];
  176. const WCHAR *text = TranslateDBClass::Get_String (objective->ShortDescriptionID);
  177. const WCHAR *status_text = objective->Status_To_Name ();
  178. //
  179. // Insert an item for this objective
  180. //
  181. int item_index = TextWindow->Insert_Item (index, text);
  182. if (item_index >= 0) {
  183. //
  184. // Configure the entry
  185. //
  186. TextWindow->Set_Item_Text (item_index, COL_STATUS, status_text);
  187. TextWindow->Set_Item_Color (item_index, COL_DESC, objective->Type_To_Color ());
  188. TextWindow->Set_Item_Color (item_index, COL_STATUS, objective->Status_To_Color ());
  189. }
  190. }
  191. return ;
  192. }
  193. ////////////////////////////////////////////////////////////////
  194. //
  195. // Display
  196. //
  197. ////////////////////////////////////////////////////////////////
  198. void
  199. ObjectivesViewerClass::Display (bool onoff)
  200. {
  201. IsDisplayed = onoff;
  202. TextWindow->Display (onoff);
  203. //
  204. // Play the 'EVA displayed' sound effect
  205. //
  206. if (IsDisplayed) {
  207. int sound_id = GlobalSettingsDef::Get_Global_Settings ()->Get_EVA_Objectives_Sound_ID ();
  208. if (sound_id != 0) {
  209. WWAudioClass::Get_Instance ()->Create_Instant_Sound (sound_id, Matrix3D (1));
  210. }
  211. }
  212. return ;
  213. }
  214. ////////////////////////////////////////////////////////////////
  215. //
  216. // Page_Down
  217. //
  218. ////////////////////////////////////////////////////////////////
  219. void
  220. ObjectivesViewerClass::Page_Down (void)
  221. {
  222. if (TextWindow == NULL) {
  223. return ;
  224. }
  225. //
  226. // Page down the window
  227. //
  228. TextWindow->Page_Down ();
  229. //
  230. // Close the window if there is nothing left to display
  231. //
  232. if (TextWindow->Get_Display_Count () == 0) {
  233. Display (false);
  234. }
  235. return ;
  236. }
  237. ////////////////////////////////////////////////////////////////
  238. //
  239. // Render
  240. //
  241. ////////////////////////////////////////////////////////////////
  242. void
  243. ObjectivesViewerClass::Render (void)
  244. {
  245. if (IsDisplayed == false) {
  246. return ;
  247. }
  248. TextWindow->Render ();
  249. return ;
  250. }
  251. ////////////////////////////////////////////////////////////////
  252. //
  253. // fnCompareObjectivesCallback
  254. //
  255. ////////////////////////////////////////////////////////////////
  256. int __cdecl
  257. ObjectivesViewerClass::fnCompareObjectivesCallback
  258. (
  259. const void *elem1,
  260. const void *elem2
  261. )
  262. {
  263. WWASSERT (elem1 != NULL);
  264. WWASSERT (elem2 != NULL);
  265. Objective *objective1 = *((Objective **)elem1);
  266. Objective *objective2 = *((Objective **)elem2);
  267. //
  268. // Sort the objectives based on type
  269. //
  270. int result = 0;
  271. if (objective1->Type < objective2->Type) {
  272. result = -1;
  273. } else if (objective1->Type > objective2->Type) {
  274. result = 1;
  275. } else {
  276. //
  277. // Sort alphabetically if the types are the same
  278. //
  279. const WCHAR *text1 = TranslateDBClass::Get_String (objective1->ShortDescriptionID);
  280. const WCHAR *text2 = TranslateDBClass::Get_String (objective2->ShortDescriptionID);
  281. result = ::wcsicmp (text1, text2);
  282. }
  283. return result;
  284. }