MPGSET.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /****************************************************************************
  15. *
  16. * FILE
  17. * MpgSet.cpp
  18. *
  19. * DESCRIPTION
  20. * Mpeg movie settings manager
  21. *
  22. * PROGRAMMER
  23. * Denzil E. Long, Jr.
  24. *
  25. * DATE
  26. * June 30, 1998
  27. *
  28. ****************************************************************************/
  29. #include "function.h"
  30. #ifdef DVD
  31. #include "mpgset.h"
  32. #ifdef MCIMPEG
  33. bool EnumMCI(MCIDevice* desc, void* context);
  34. #endif
  35. /****************************************************************************
  36. *
  37. * NAME
  38. * MPGSettings(DeviceName)
  39. *
  40. * DESCRIPTION
  41. * Default constructor
  42. *
  43. * INPUTS
  44. * DeviceName - Initial device to use for MPG playback (NULL = DXMedia)
  45. *
  46. * RESULT
  47. * NONE
  48. *
  49. ****************************************************************************/
  50. MPGSettings::MPGSettings(const char* deviceName)
  51. : mDeviceName(NULL)
  52. {
  53. SetDeviceName(deviceName);
  54. #ifdef MCIMPEG
  55. int count = mMCI.GetDeviceCount();
  56. mMCIDevices = NULL;
  57. mCount = 0;
  58. if (count)
  59. {
  60. mMCIDevices = new MCIDevice[count];
  61. if (mMCIDevices)
  62. {
  63. mMCI.EnumerateDevices(EnumMCI, this);
  64. }
  65. }
  66. #endif
  67. }
  68. MPGSettings::MPGSettings(FileClass& file)
  69. : mDeviceName(NULL)
  70. {
  71. INIClass ini;
  72. char buffer[256];
  73. char* device = NULL;
  74. #ifdef MCIMPEG
  75. int count = mMCI.GetDeviceCount();
  76. mMCIDevices = NULL;
  77. mCount = 0;
  78. // Enumerate all the MCI devices that can play a movie
  79. if (count)
  80. {
  81. mMCIDevices = new MCIDevice[count];
  82. if (mMCIDevices)
  83. {
  84. mMCI.EnumerateDevices(EnumMCI, this);
  85. }
  86. }
  87. #endif
  88. // Retrieve the user specified device from the config file
  89. buffer[0] = '\0';
  90. if (ini.Load(file))
  91. {
  92. ini.Get_String("MovieSettings", "Device", "Default", buffer, sizeof(buffer));
  93. }
  94. // If there is a specification in the config and it isn't the default
  95. if ((strlen(buffer) != 0) && (stricmp(buffer, "Default") != 0))
  96. {
  97. #ifdef MCIMPEG
  98. // Search for selection
  99. for (int i = 0; i < mCount; i++)
  100. {
  101. if (stricmp(buffer, mMCIDevices[i].name) == 0)
  102. {
  103. device = mMCIDevices[i].name;
  104. break;
  105. }
  106. }
  107. #endif
  108. }
  109. SetDeviceName(device);
  110. }
  111. /****************************************************************************
  112. *
  113. * NAME
  114. * ~MPGSettings
  115. *
  116. * DESCRIPTION
  117. * Destructor
  118. *
  119. * INPUTS
  120. * NONE
  121. *
  122. * RESULT
  123. * NONE
  124. *
  125. ****************************************************************************/
  126. MPGSettings::~MPGSettings(void)
  127. {
  128. if (mDeviceName)
  129. free(mDeviceName);
  130. #ifdef MCIMPEG
  131. if (mMCIDevices)
  132. delete[] mMCIDevices;
  133. #endif
  134. }
  135. /****************************************************************************
  136. *
  137. * NAME
  138. * SetDeviceName(DeviceName)
  139. *
  140. * DESCRIPTION
  141. * Change current device used for mpeg playback
  142. *
  143. * INPUTS
  144. * DeviceName - Device name type (IE: mpegvideo)
  145. *
  146. * RESULT
  147. * NONE
  148. *
  149. ****************************************************************************/
  150. void MPGSettings::SetDeviceName(const char* deviceName)
  151. {
  152. if (mDeviceName)
  153. free(mDeviceName);
  154. mDeviceName = NULL;
  155. if (deviceName)
  156. mDeviceName = strdup(deviceName);
  157. }
  158. bool MPGSettings::Save(FileClass& file)
  159. {
  160. INIClass ini;
  161. if (ini.Load(file))
  162. {
  163. const char* device = GetDeviceName();
  164. if (device)
  165. {
  166. ini.Put_String("MovieSettings", "Device", device);
  167. }
  168. else
  169. {
  170. ini.Put_String("MovieSettings", "Device", "Default");
  171. }
  172. ini.Save(file);
  173. return true;
  174. }
  175. return false;
  176. }
  177. /****************************************************************************
  178. *
  179. * NAME
  180. * Dialog()
  181. *
  182. * DESCRIPTION
  183. * Mpeg playback settings dialog
  184. *
  185. * INPUTS
  186. * NONE
  187. *
  188. * RESULT
  189. * NONE
  190. *
  191. ****************************************************************************/
  192. void MPGSettings::Dialog(void)
  193. {
  194. // Dialog & button dimensions
  195. int d_dialog_w = 200 *RESFACTOR;
  196. int d_dialog_h = 100 *RESFACTOR;
  197. int d_dialog_x = (((320*RESFACTOR) - d_dialog_w) / 2);
  198. int d_dialog_y = 70 * RESFACTOR;
  199. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2);
  200. int d_txt6_h = 7 *RESFACTOR;
  201. int d_margin = 7 *RESFACTOR;
  202. int d_okay_w = 40 *RESFACTOR;
  203. int d_okay_h = 9 *RESFACTOR;
  204. int d_okay_x = d_dialog_x + d_margin + 20;
  205. int d_okay_y = ((d_dialog_y + d_dialog_h) - (d_okay_h + 20));
  206. int d_test_w = 40 *RESFACTOR;
  207. int d_test_h = 9 *RESFACTOR;
  208. int d_test_x = (d_dialog_cx - (d_test_w / 2));
  209. int d_test_y = ((d_dialog_y + d_dialog_h) - (d_test_h + 20));
  210. int d_cancel_w = 40 *RESFACTOR;
  211. int d_cancel_h = 9 *RESFACTOR;
  212. int d_cancel_x = ((d_dialog_x + d_dialog_w) - (d_cancel_w + d_margin + 20));
  213. int d_cancel_y = ((d_dialog_y + d_dialog_h) - (d_cancel_h + 20));
  214. int d_method_w = 165 * RESFACTOR;
  215. int d_method_h = 50 * RESFACTOR;
  216. int d_method_x = (d_dialog_cx - (d_method_w / 2));
  217. int d_method_y = (d_dialog_y + 40);
  218. // Button enumerations:
  219. enum
  220. {
  221. BUTTON_OKAY = 100,
  222. BUTTON_TEST,
  223. BUTTON_CANCEL,
  224. BUTTON_METHOD,
  225. NUM_OF_BUTTONS = 4,
  226. };
  227. int num_of_buttons = NUM_OF_BUTTONS;
  228. // Redraw values: in order from "top" to "bottom" layer of the dialog
  229. typedef enum
  230. {
  231. REDRAW_NONE = 0,
  232. REDRAW_BUTTONS, // includes map interior & coord values
  233. REDRAW_BACKGROUND, // includes box, map bord, key, coord labels, btns
  234. REDRAW_ALL = REDRAW_BACKGROUND
  235. } RedrawType;
  236. // Dialog variables:
  237. KeyNumType input; // input from user
  238. bool process; // loop while true
  239. RedrawType display; // true = re-draw everything
  240. int selection;
  241. bool pressed;
  242. int curbutton;
  243. TextButtonClass * buttons[NUM_OF_BUTTONS];
  244. int i;
  245. char* origDevice = NULL;
  246. // Buttons
  247. ControlClass * commands = NULL; // the button list
  248. TextButtonClass okaybtn(BUTTON_OKAY, TXT_OK, TPF_BUTTON,
  249. d_okay_x, d_okay_y, d_okay_w, d_okay_h);
  250. TextButtonClass testbtn(BUTTON_TEST, "Test", TPF_BUTTON,
  251. d_test_x, d_test_y, d_test_w, d_test_h);
  252. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
  253. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  254. ListClass method(BUTTON_METHOD, d_method_x, d_method_y, d_method_w,
  255. d_method_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  256. // Initialize
  257. Set_Logic_Page(SeenBuff);
  258. // Create the list
  259. commands = &okaybtn;
  260. testbtn.Add_Tail(*commands);
  261. cancelbtn.Add_Tail(*commands);
  262. method.Add_Tail(*commands);
  263. // Fill array of button ptrs
  264. curbutton = 0;
  265. buttons[0] = &okaybtn;
  266. buttons[1] = &testbtn;
  267. buttons[2] = &cancelbtn;
  268. buttons[curbutton]->Turn_On();
  269. Keyboard->Clear();
  270. Fancy_Text_Print(TXT_NONE, 0, 0, GadgetClass::Get_Color_Scheme(), TBLACK,
  271. TPF_CENTER | TPF_TEXT);
  272. // Add device to device control
  273. method.Add_Item("DirectX Media (Default)");
  274. #ifdef MCIMPEG
  275. for (i = 0; i < mCount; i++)
  276. {
  277. if (mMCIDevices[i].description != NULL)
  278. {
  279. method.Add_Item(mMCIDevices[i].description);
  280. }
  281. }
  282. #endif
  283. method.Set_Selected_Index(0);
  284. #ifdef MCIMPEG
  285. // Search for current selection
  286. if (GetDeviceName())
  287. {
  288. for (i = 0; i < mCount; i++)
  289. {
  290. if (stricmp(GetDeviceName(), mMCIDevices[i].name) == 0)
  291. {
  292. method.Set_Selected_Index(i + 1);
  293. break;
  294. }
  295. }
  296. }
  297. #endif
  298. // Save original device selection
  299. if (GetDeviceName())
  300. origDevice = strdup(GetDeviceName());
  301. //------------------------------------------------------------------------
  302. // Main Processing Loop
  303. //------------------------------------------------------------------------
  304. display = REDRAW_ALL;
  305. process = true;
  306. pressed = false;
  307. while (process)
  308. {
  309. #ifdef WIN32
  310. /*
  311. ** If we have just received input focus again after running in the background then
  312. ** we need to redraw.
  313. */
  314. if (AllSurfaces.SurfacesRestored)
  315. {
  316. AllSurfaces.SurfacesRestored=FALSE;
  317. display = REDRAW_ALL;
  318. }
  319. #endif
  320. // Invoke game callback
  321. Call_Back();
  322. // Refresh display if needed
  323. if (display)
  324. {
  325. Hide_Mouse();
  326. if (display >= REDRAW_BACKGROUND)
  327. {
  328. // Refresh the backdrop
  329. Load_Title_Page(true);
  330. CCPalette.Set();
  331. // Draw the background
  332. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  333. Draw_Caption("Movie Settings", d_dialog_x, d_dialog_y, d_dialog_w);
  334. }
  335. // Redraw buttons
  336. if (display >= REDRAW_BUTTONS)
  337. commands->Flag_List_To_Redraw();
  338. Show_Mouse();
  339. display = REDRAW_NONE;
  340. }
  341. // Get user input
  342. input = commands->Input();
  343. // Process input
  344. switch (input)
  345. {
  346. case (BUTTON_OKAY | KN_BUTTON):
  347. selection = BUTTON_OKAY;
  348. pressed = true;
  349. break;
  350. case (BUTTON_TEST | KN_BUTTON):
  351. selection = BUTTON_TEST;
  352. pressed = true;
  353. break;
  354. case (KN_ESC):
  355. case (BUTTON_CANCEL | KN_BUTTON):
  356. selection = BUTTON_CANCEL;
  357. pressed = true;
  358. break;
  359. case KN_UP:
  360. buttons[curbutton]->Turn_Off();
  361. buttons[curbutton]->Flag_To_Redraw();
  362. curbutton--;
  363. if (curbutton < 0)
  364. curbutton = (num_of_buttons - 1);
  365. buttons[curbutton]->Turn_On();
  366. buttons[curbutton]->Flag_To_Redraw();
  367. break;
  368. case KN_DOWN:
  369. buttons[curbutton]->Turn_Off();
  370. buttons[curbutton]->Flag_To_Redraw();
  371. curbutton++;
  372. if (curbutton > (num_of_buttons - 1))
  373. curbutton = 0;
  374. buttons[curbutton]->Turn_On();
  375. buttons[curbutton]->Flag_To_Redraw();
  376. break;
  377. case KN_RETURN:
  378. selection = curbutton + BUTTON_OKAY;
  379. pressed = true;
  380. break;
  381. default:
  382. break;
  383. }
  384. if (pressed)
  385. {
  386. // to make sure the selection is correct in case they used the mouse
  387. buttons[curbutton]->Turn_Off();
  388. buttons[curbutton]->Flag_To_Redraw();
  389. curbutton = selection - BUTTON_OKAY;
  390. buttons[curbutton]->Turn_On();
  391. buttons[curbutton]->IsPressed = true;
  392. buttons[curbutton]->Draw_Me(true);
  393. switch (selection)
  394. {
  395. case (BUTTON_TEST):
  396. buttons[curbutton]->IsPressed = false;
  397. if (method.Current_Index() == 0)
  398. {
  399. SetDeviceName(NULL);
  400. }
  401. else
  402. {
  403. i = method.Current_Index();
  404. #ifdef MCIMPEG
  405. SetDeviceName(mMCIDevices[i - 1].name);
  406. #endif
  407. }
  408. Theme.Fade_Out();
  409. Hide_Mouse();
  410. VisiblePage.Clear();
  411. //PlayMpegMovie("acrop"); //PG
  412. Keyboard->Clear();
  413. Show_Mouse();
  414. Theme.Queue_Song(THEME_CRUS);
  415. display = REDRAW_ALL;
  416. buttons[curbutton]->Turn_Off();
  417. buttons[curbutton]->Flag_To_Redraw();
  418. buttons[0]->Turn_On();
  419. curbutton = 0;
  420. break;
  421. case (BUTTON_OKAY):
  422. process = false;
  423. if (method.Current_Index() == 0)
  424. {
  425. SetDeviceName(NULL);
  426. }
  427. else
  428. {
  429. i = method.Current_Index();
  430. #ifdef MCIMPEG
  431. SetDeviceName(mMCIDevices[i - 1].name);
  432. #endif
  433. }
  434. {
  435. RawFileClass file(CONFIG_FILE_NAME);
  436. Save(file);
  437. }
  438. break;
  439. case (BUTTON_CANCEL):
  440. process = false;
  441. SetDeviceName(origDevice);
  442. break;
  443. }
  444. pressed = false;
  445. }
  446. }
  447. if (origDevice)
  448. free(origDevice);
  449. }
  450. #ifdef MCIMPEG
  451. /****************************************************************************
  452. *
  453. * NAME
  454. * EnumMCI(DeviceDesc, Context)
  455. *
  456. * DESCRIPTION
  457. * MCI device enumeration callback
  458. *
  459. * INPUTS
  460. * DeviceDesc - MCI device description
  461. * Context - User defined context variable
  462. *
  463. * RESULT
  464. * Continue - Continue with next device flag
  465. *
  466. ****************************************************************************/
  467. bool EnumMCI(MCIDevice* desc, void* context)
  468. {
  469. MPGSettings* mpgset = (MPGSettings*)context;
  470. // Digital video device type?
  471. if (desc->type == MCI_DEVTYPE_DIGITAL_VIDEO)
  472. {
  473. if (MciMovie)
  474. {
  475. CCFileClass file;
  476. const char* filename;
  477. filename = file.Set_Name("movies\\acrop.mpg");
  478. if (!file.Is_Available())
  479. {
  480. char buffer[256];
  481. sprintf(buffer, "Couldn't test MCI device %s\n", desc->name);
  482. VisiblePage.Clear();
  483. GamePalette.Set();
  484. Show_Mouse();
  485. WWMessageBox().Process(buffer);
  486. Hide_Mouse();
  487. VisiblePage.Clear();
  488. return true;
  489. }
  490. if (MciMovie->Open(filename, desc->name))
  491. {
  492. MciMovie->Close();
  493. memcpy((void*)&mpgset->mMCIDevices[mpgset->mCount], (void*)desc,
  494. sizeof(MCIDevice));
  495. mpgset->mCount++;
  496. }
  497. }
  498. }
  499. return true;
  500. }
  501. #endif
  502. #endif