dlgmovieoptions.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/dlgmovieoptions.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/15/02 9:28p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgmovieoptions.h"
  36. #include "listctrl.h"
  37. #include "binkmovie.h"
  38. #include "registry.h"
  39. #include "translatedb.h"
  40. #include "_globals.h"
  41. #include "string_ids.h"
  42. #include "wwaudio.h"
  43. ////////////////////////////////////////////////////////////////
  44. //
  45. // MovieOptionsMenuClass
  46. //
  47. ////////////////////////////////////////////////////////////////
  48. MovieOptionsMenuClass::MovieOptionsMenuClass (void) :
  49. IsPlaying (false),
  50. MenuDialogClass (IDD_OPTIONS_MOVIES)
  51. {
  52. return ;
  53. }
  54. ////////////////////////////////////////////////////////////////
  55. //
  56. // On_Init_Dialog
  57. //
  58. ////////////////////////////////////////////////////////////////
  59. void
  60. MovieOptionsMenuClass::On_Init_Dialog (void)
  61. {
  62. //
  63. // Get a pointer to the list control
  64. //
  65. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  66. if (list_ctrl != NULL) {
  67. //
  68. // Configure the list control
  69. //
  70. list_ctrl->Add_Column (TRANSLATE (IDS_MOVIE_COL_HEADER), 1.0F, Vector3 (1, 1, 1));
  71. //
  72. // Add the movies to the list...
  73. //
  74. RegistryClass registry (APPLICATION_SUB_KEY_NAME_MOVIES);
  75. if (registry.Is_Valid ()) {
  76. const char *INTRO_MOVIE = "DATA\\MOVIES\\R_INTRO.BIK";
  77. //
  78. // Insert the renegade intro movie by default...
  79. //
  80. int item_index = list_ctrl->Insert_Entry (0xFF, TRANSLATE (IDS_INTRO_MOVIE));
  81. if (item_index != -1) {
  82. list_ctrl->Set_Entry_Data (item_index, 0, (DWORD)new StringClass (INTRO_MOVIE));
  83. }
  84. //
  85. // Get the list of entries from the registry
  86. //
  87. DynamicVectorClass<StringClass> list;
  88. registry.Get_Value_List (list);
  89. //
  90. // Loop over all the movies in the registry
  91. //
  92. for (int index = 0; index < list.Count (); index ++) {
  93. StringClass string_id_des;
  94. registry.Get_String (list[index], string_id_des);
  95. //
  96. // Add an entry for this movie
  97. //
  98. const WCHAR *wide_desc = TRANSLATE_BY_DESC(string_id_des);
  99. int item_index = list_ctrl->Insert_Entry (0xFF, wide_desc);
  100. if (item_index != -1) {
  101. list_ctrl->Set_Entry_Data (item_index, 0, (DWORD)new StringClass (list[index]));
  102. }
  103. }
  104. }
  105. }
  106. MenuDialogClass::On_Init_Dialog ();
  107. return ;
  108. }
  109. ////////////////////////////////////////////////////////////////
  110. //
  111. // On_Command
  112. //
  113. ////////////////////////////////////////////////////////////////
  114. void
  115. MovieOptionsMenuClass::On_Command (int ctrl_id, int message_id, DWORD param)
  116. {
  117. if (IsPlaying) {
  118. return ;
  119. }
  120. //
  121. // Play the movie if the user clicked the play button
  122. //
  123. if (ctrl_id == IDC_MENU_PLAY_MOVIE_BUTTON) {
  124. Begin_Play_Movie ();
  125. }
  126. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  127. return ;
  128. }
  129. ////////////////////////////////////////////////////////////////
  130. //
  131. // On_ListCtrl_Delete_Entry
  132. //
  133. ////////////////////////////////////////////////////////////////
  134. void
  135. MovieOptionsMenuClass::On_ListCtrl_Delete_Entry
  136. (
  137. ListCtrlClass *list_ctrl,
  138. int ctrl_id,
  139. int item_index
  140. )
  141. {
  142. if (IsPlaying) {
  143. return ;
  144. }
  145. if (ctrl_id == IDC_LIST_CTRL) {
  146. //
  147. // Remove the data we associated with this entry
  148. //
  149. StringClass *filename = (StringClass *)list_ctrl->Get_Entry_Data (item_index, 0);
  150. list_ctrl->Set_Entry_Data (item_index, 0, 0);
  151. if (filename != NULL) {
  152. delete filename;
  153. }
  154. }
  155. return ;
  156. }
  157. ////////////////////////////////////////////////////////////////
  158. //
  159. // On_ListCtrl_DblClk
  160. //
  161. ////////////////////////////////////////////////////////////////
  162. void
  163. MovieOptionsMenuClass::On_ListCtrl_DblClk
  164. (
  165. ListCtrlClass *list_ctrl,
  166. int ctrl_id,
  167. int item_index
  168. )
  169. {
  170. if (IsPlaying) {
  171. return ;
  172. }
  173. Begin_Play_Movie ();
  174. return ;
  175. }
  176. ////////////////////////////////////////////////////////////////
  177. //
  178. // Begin_Play_Movie
  179. //
  180. ////////////////////////////////////////////////////////////////
  181. void
  182. MovieOptionsMenuClass::Begin_Play_Movie (void)
  183. {
  184. //
  185. // Get a pointer to the list control
  186. //
  187. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_LIST_CTRL);
  188. if (list_ctrl == NULL) {
  189. return ;
  190. }
  191. //
  192. // Get the currently selected entry
  193. //
  194. int curr_sel = list_ctrl->Get_Curr_Sel ();
  195. if (curr_sel != -1) {
  196. StringClass *filename = (StringClass *)list_ctrl->Get_Entry_Data (curr_sel, 0);
  197. //
  198. // Play the movie (if it exists locally)
  199. //
  200. if (::GetFileAttributes (filename->Peek_Buffer ()) != 0xFFFFFFFF) {
  201. Play_Movie (filename->Peek_Buffer ());
  202. } else {
  203. //
  204. // Strip any path information off the filename
  205. //
  206. StringClass filename_only (filename->Peek_Buffer (), true);
  207. const char *delimiter = ::strrchr (filename->Peek_Buffer (), '\\');
  208. if (delimiter != NULL) {
  209. filename_only = delimiter + 1;
  210. }
  211. //
  212. // Try to find the CD...
  213. //
  214. StringClass cd_path;
  215. if (CDVerifier.Get_CD_Path (cd_path)) {
  216. //
  217. // Build a full-path to the movie on the CD
  218. //
  219. StringClass full_path = cd_path;
  220. if (cd_path[cd_path.Get_Length () - 1] != '\\') {
  221. full_path += "\\";
  222. }
  223. full_path += filename_only;
  224. Play_Movie (full_path);
  225. } else {
  226. PendingMovieFilename = filename_only;
  227. CDVerifier.Display_UI (this);
  228. }
  229. }
  230. }
  231. return ;
  232. }
  233. ////////////////////////////////////////////////////////////////
  234. //
  235. // Play_Movie
  236. //
  237. ////////////////////////////////////////////////////////////////
  238. void
  239. MovieOptionsMenuClass::Play_Movie (const char *filename)
  240. {
  241. WWAudioClass::Get_Instance ()->Temp_Disable_Audio (true);
  242. FontCharsClass* font = StyleMgrClass::Get_Font(StyleMgrClass::FONT_INGAME_SUBTITLE_TXT);
  243. BINKMovie::Play (filename, "data\\subtitle.ini", font);
  244. if (font) {
  245. font->Release_Ref();
  246. }
  247. IsPlaying = true;
  248. return ;
  249. }
  250. ////////////////////////////////////////////////////////////////
  251. //
  252. // Render
  253. //
  254. ////////////////////////////////////////////////////////////////
  255. void
  256. MovieOptionsMenuClass::Render (void)
  257. {
  258. //
  259. // Render the movie or stop it from playing as necessary
  260. //
  261. if (IsPlaying) {
  262. if (BINKMovie::Is_Complete () == false) {
  263. BINKMovie::Render ();
  264. } else {
  265. WWAudioClass::Get_Instance ()->Temp_Disable_Audio (false);
  266. BINKMovie::Stop ();
  267. IsPlaying = false;
  268. }
  269. }
  270. MenuDialogClass::Render ();
  271. return ;
  272. }
  273. ////////////////////////////////////////////////////////////////
  274. //
  275. // On_Frame_Update
  276. //
  277. ////////////////////////////////////////////////////////////////
  278. void
  279. MovieOptionsMenuClass::On_Frame_Update (void)
  280. {
  281. //
  282. // Let the movie update (if nececessary)
  283. //
  284. BINKMovie::Update ();
  285. MenuDialogClass::On_Frame_Update ();
  286. return ;
  287. }
  288. ////////////////////////////////////////////////////////////////
  289. //
  290. // On_Key_Down
  291. //
  292. ////////////////////////////////////////////////////////////////
  293. bool
  294. MovieOptionsMenuClass::On_Key_Down (uint32 key_id, uint32 key_data)
  295. {
  296. bool retval = false;
  297. //
  298. // Stop playing the movie on any keypress
  299. //
  300. if (IsPlaying && key_id == VK_ESCAPE) {
  301. WWAudioClass::Get_Instance ()->Temp_Disable_Audio (false);
  302. BINKMovie::Stop ();
  303. IsPlaying = false;
  304. retval = true;
  305. } else if (IsPlaying == false) {
  306. retval = MenuDialogClass::On_Key_Down (key_id, key_data);
  307. }
  308. return retval;
  309. }
  310. ////////////////////////////////////////////////////////////////
  311. //
  312. // HandleNotification
  313. //
  314. ////////////////////////////////////////////////////////////////
  315. void
  316. MovieOptionsMenuClass::HandleNotification (CDVerifyEvent &event)
  317. {
  318. if (event.Event () == CDVerifyEvent::VERIFIED) {
  319. //
  320. // Get the path to the CD...
  321. //
  322. StringClass cd_path;
  323. if (CDVerifier.Get_CD_Path (cd_path)) {
  324. //
  325. // Build a full-path to the movie on the CD
  326. //
  327. StringClass full_path = cd_path;
  328. if (cd_path[cd_path.Get_Length () - 1] != '\\') {
  329. full_path += "\\";
  330. }
  331. full_path += PendingMovieFilename;
  332. Play_Movie (full_path);
  333. }
  334. }
  335. PendingMovieFilename = "";
  336. return ;
  337. }