SOUNDDLG.CPP 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. /* $Header: /CounterStrike/SOUNDDLG.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : SOUNDDLG.CPP *
  22. * *
  23. * Programmer : Maria del Mar McCready-Legg, Joe L. Bostic *
  24. * *
  25. * Start Date : Jan 8, 1995 *
  26. * *
  27. * Last Update : September 22, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * MusicListClass::Draw_Entry -- Draw the score line in a list box. *
  32. * SoundControlsClass::Process -- Handles all the options graphic interface. *
  33. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  34. #include "function.h"
  35. #include "sounddlg.h"
  36. class MusicListClass : public ListClass
  37. {
  38. public:
  39. MusicListClass(int id, int x, int y, int w, int h) :
  40. ListClass(id, x, y, w, h, TPF_6PT_GRAD|TPF_NOSHADOW, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"))
  41. {};
  42. virtual ~MusicListClass(void) {};
  43. protected:
  44. virtual void Draw_Entry(int index, int x, int y, int width, int selected);
  45. };
  46. /***********************************************************************************************
  47. * SoundControlsClass::Process -- Handles all the options graphic interface. *
  48. * *
  49. * This routine is the main control for the visual representation of the options *
  50. * screen. It handles the visual overlay and the player input. *
  51. * *
  52. * INPUT: none *
  53. * *
  54. * OUTPUT: none *
  55. * *
  56. * WARNINGS: none *
  57. * *
  58. * HISTORY: 12/31/1994 MML : Created. *
  59. *=============================================================================================*/
  60. void SoundControlsClass::Process(void)
  61. {
  62. /*
  63. ** Adjust dialog controls for resolution
  64. */
  65. int option_width= OPTION_WIDTH * RESFACTOR;
  66. int option_height= OPTION_HEIGHT * RESFACTOR;
  67. int option_x= OPTION_X * RESFACTOR;
  68. int option_y= OPTION_Y * RESFACTOR;
  69. int listbox_x= LISTBOX_X * RESFACTOR;
  70. int listbox_y= LISTBOX_Y * RESFACTOR;
  71. int listbox_w= LISTBOX_W * RESFACTOR;
  72. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  73. #ifdef WIN32
  74. int listbox_h= (LISTBOX_H * RESFACTOR)+2;
  75. #else
  76. int listbox_h= LISTBOX_H * RESFACTOR;
  77. #endif
  78. #else
  79. int listbox_h= LISTBOX_H * RESFACTOR;
  80. #endif
  81. int button_width= BUTTON_WIDTH * RESFACTOR;
  82. int button_x= BUTTON_X * RESFACTOR;
  83. int button_y= BUTTON_Y * RESFACTOR;
  84. int stop_x= STOP_X * RESFACTOR;
  85. int stop_y= STOP_Y * RESFACTOR;
  86. int play_x= PLAY_X * RESFACTOR;
  87. int play_y= PLAY_Y * RESFACTOR;
  88. int onoff_width= ONOFF_WIDTH * RESFACTOR;
  89. int shuffle_x= SHUFFLE_X * RESFACTOR;
  90. int shuffle_y= SHUFFLE_Y * RESFACTOR;
  91. int repeat_x= REPEAT_X * RESFACTOR;
  92. int repeat_y= REPEAT_Y * RESFACTOR;
  93. int mslider_x= MSLIDER_X * RESFACTOR;
  94. int mslider_y= MSLIDER_Y * RESFACTOR;
  95. int mslider_w= MSLIDER_W * RESFACTOR;
  96. int mslider_height= MSLIDER_HEIGHT * RESFACTOR;
  97. int fxslider_x= FXSLIDER_X * RESFACTOR;
  98. int fxslider_y= FXSLIDER_Y * RESFACTOR;
  99. int fxslider_w= FXSLIDER_W * RESFACTOR;
  100. int fxslider_height= FXSLIDER_HEIGHT * RESFACTOR;
  101. int button_stop= BUTTON_STOP;
  102. int button_play= BUTTON_PLAY;
  103. int button_shuffle= BUTTON_SHUFFLE;
  104. int button_repeat= BUTTON_REPEAT;
  105. int button_options= BUTTON_OPTIONS;
  106. int slider_music= SLIDER_MUSIC;
  107. int slider_sound= SLIDER_SOUND;
  108. int button_listbox= BUTTON_LISTBOX;
  109. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  110. // ThemeType theme;
  111. /*
  112. ** List box that holds the score text strings.
  113. */
  114. MusicListClass listbox(0, option_x+listbox_x, option_y+listbox_y, listbox_w, listbox_h);
  115. /*
  116. ** Return to options menu button.
  117. */
  118. TextButtonClass returnto(BUTTON_OPTIONS, TXT_OK, TPF_BUTTON, option_x+button_x, option_y+button_y, button_width);
  119. // TextButtonClass returnto(BUTTON_OPTIONS, TXT_OPTIONS_MENU, TPF_BUTTON,
  120. /*
  121. ** Stop playing button.
  122. */
  123. ShapeButtonClass stopbtn(BUTTON_STOP, MFCD::Retrieve("BTN-ST.SHP"), option_x+stop_x, option_y+stop_y);
  124. /*
  125. ** Start playing button.
  126. */
  127. ShapeButtonClass playbtn(BUTTON_PLAY, MFCD::Retrieve("BTN-PL.SHP"), option_x+play_x, option_y+play_y);
  128. /*
  129. ** Shuffle control.
  130. */
  131. TextButtonClass shufflebtn(BUTTON_SHUFFLE, TXT_OFF, TPF_BUTTON, option_x+shuffle_x, option_y+shuffle_y, onoff_width);
  132. // TextButtonClass shufflebtn(BUTTON_SHUFFLE, TXT_OFF, TPF_BUTTON, option_x+shuffle_x, option_y+shuffle_y, ONOFF_WIDTH);
  133. /*
  134. ** Repeat control.
  135. */
  136. TextButtonClass repeatbtn(BUTTON_REPEAT, TXT_OFF, TPF_BUTTON, option_x+repeat_x, option_y+repeat_y, onoff_width);
  137. /*
  138. ** Music volume slider.
  139. */
  140. SliderClass music(SLIDER_MUSIC, option_x+mslider_x, option_y+mslider_y, mslider_w, mslider_height, true);
  141. /*
  142. ** Sound volume slider.
  143. */
  144. SliderClass sound(SLIDER_SOUND, option_x+fxslider_x, option_y+fxslider_y, fxslider_w, fxslider_height, true);
  145. /*
  146. ** Causes left mouse clicks inside the dialog area, but not on any
  147. ** particular button, to be ignored.
  148. */
  149. GadgetClass area(option_x, option_y, option_width, option_height, GadgetClass::LEFTPRESS);
  150. /*
  151. ** Causes right clicks anywhere or left clicks outside of the dialog
  152. ** box area to be the same a clicking the return to game options button.
  153. */
  154. ControlClass ctrl(BUTTON_OPTIONS, 0, 0, SeenBuff.Get_Width(), SeenBuff.Get_Height(), GadgetClass::RIGHTPRESS|GadgetClass::LEFTPRESS);
  155. /*
  156. ** The repeat and shuffle buttons are of the toggle type. They toggle
  157. ** between saying "on" and "off".
  158. */
  159. shufflebtn.IsToggleType = true;
  160. if (Options.IsScoreShuffle) {
  161. shufflebtn.Turn_On();
  162. } else {
  163. shufflebtn.Turn_Off();
  164. }
  165. shufflebtn.Set_Text(shufflebtn.IsOn ? TXT_ON : TXT_OFF);
  166. repeatbtn.IsToggleType = true;
  167. if (Options.IsScoreRepeat) {
  168. repeatbtn.Turn_On();
  169. } else {
  170. repeatbtn.Turn_Off();
  171. }
  172. repeatbtn.Set_Text(repeatbtn.IsOn ? TXT_ON : TXT_OFF);
  173. /*
  174. ** Set the initial values of the sliders.
  175. */
  176. music.Set_Maximum(255);
  177. music.Set_Thumb_Size(16);
  178. music.Set_Value(Options.ScoreVolume * 256);
  179. sound.Set_Maximum(255);
  180. sound.Set_Thumb_Size(16);
  181. sound.Set_Value(Options.Volume * 256);
  182. /*
  183. ** Set up the window. Window x-coords are in bytes not pixels.
  184. */
  185. Set_Logic_Page(SeenBuff);
  186. /*
  187. ** Create Buttons.
  188. */
  189. GadgetClass * optionsbtn = &returnto;
  190. listbox.Add_Tail(*optionsbtn);
  191. stopbtn.Add_Tail(*optionsbtn);
  192. playbtn.Add_Tail(*optionsbtn);
  193. shufflebtn.Add_Tail(*optionsbtn);
  194. repeatbtn.Add_Tail(*optionsbtn);
  195. music.Add_Tail(*optionsbtn);
  196. sound.Add_Tail(*optionsbtn);
  197. area.Add_Tail(*optionsbtn);
  198. ctrl.Add_Tail(*optionsbtn);
  199. /*
  200. ** Add all the themes to the list box. The list box entries are constructed
  201. ** and then stored into allocated EMS memory blocks.
  202. */
  203. for (ThemeType index = THEME_FIRST; index < Theme.Max_Themes(); index++) {
  204. if (Theme.Is_Allowed(index)) {
  205. char buffer[100];
  206. int length = Theme.Track_Length(index);
  207. char const * fullname = Theme.Full_Name(index);
  208. void * ptr = new char [sizeof(buffer)];
  209. if (ptr) {
  210. sprintf((char *)ptr, "%cTrack %d\t%d:%02d\t%s", index, listbox.Count()+1, length / 60, length % 60, fullname);
  211. listbox.Add_Item((char const *)ptr);
  212. }
  213. if (Theme.What_Is_Playing() == index) {
  214. listbox.Set_Selected_Index(listbox.Count()-1);
  215. }
  216. }
  217. }
  218. static int _tabs[] = {
  219. 55 * RESFACTOR, 72 * RESFACTOR, 90 * RESFACTOR
  220. };
  221. listbox.Set_Tabs(_tabs);
  222. /*
  223. ** Main Processing Loop.
  224. */
  225. bool display = true;
  226. bool process = true;
  227. while (process) {
  228. /*
  229. ** Invoke game callback.
  230. */
  231. if (Session.Type == GAME_NORMAL || Session.Type == GAME_SKIRMISH) {
  232. Call_Back();
  233. } else {
  234. if (Main_Loop()) {
  235. process = false;
  236. }
  237. }
  238. #ifdef WIN32
  239. /*
  240. ** If we have just received input focus again after running in the background then
  241. ** we need to redraw.
  242. */
  243. if (AllSurfaces.SurfacesRestored) {
  244. AllSurfaces.SurfacesRestored=FALSE;
  245. display = true;
  246. }
  247. #endif
  248. /*
  249. ** Refresh display if needed.
  250. */
  251. if (display) {
  252. Hide_Mouse();
  253. /*
  254. ** Draw the background.
  255. */
  256. Dialog_Box(option_x, option_y, option_width, option_height);
  257. Draw_Caption(TXT_SOUND_CONTROLS, option_x, option_y, option_width);
  258. /*
  259. ** Draw the Music, Speech & Sound titles.
  260. */
  261. Fancy_Text_Print(TXT_MUSIC_VOLUME, option_x+mslider_x-(5 * RESFACTOR), option_y+mslider_y-(2 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  262. Fancy_Text_Print(TXT_SOUND_VOLUME, option_x+fxslider_x-(5 * RESFACTOR), option_y+fxslider_y-(2 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  263. #if defined(GERMAN) || defined(FRENCH)
  264. Fancy_Text_Print(TXT_SHUFFLE, option_x+4+shuffle_x-(5 * RESFACTOR), option_y+shuffle_y+(1 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  265. #else
  266. Fancy_Text_Print(TXT_SHUFFLE, option_x+shuffle_x-(5 * RESFACTOR), option_y+shuffle_y+(1 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  267. #endif
  268. Fancy_Text_Print(TXT_REPEAT, option_x+repeat_x-(5 * RESFACTOR), option_y+repeat_y+(1 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  269. optionsbtn->Draw_All();
  270. Show_Mouse();
  271. display = false;
  272. }
  273. /*
  274. ** Get user input.
  275. */
  276. KeyNumType input = optionsbtn->Input();
  277. /*
  278. ** Process Input.
  279. */
  280. switch (input) {
  281. case KN_ESC:
  282. case BUTTON_OPTIONS|KN_BUTTON:
  283. process = false;
  284. break;
  285. /*
  286. ** Control music volume.
  287. */
  288. case SLIDER_MUSIC|KN_BUTTON:
  289. Options.Set_Score_Volume(fixed(music.Get_Value(), 256), true);
  290. #ifdef FIXIT_VERSION_3
  291. if( Session.Type != GAME_NORMAL )
  292. Options.MultiScoreVolume = Options.ScoreVolume;
  293. #endif
  294. break;
  295. /*
  296. ** Control sound volume.
  297. */
  298. case SLIDER_SOUND|KN_BUTTON:
  299. Options.Set_Sound_Volume(fixed(sound.Get_Value(), 256), true);
  300. break;
  301. case BUTTON_LISTBOX|KN_BUTTON:
  302. break;
  303. /*
  304. ** Stop all themes from playing.
  305. */
  306. case BUTTON_STOP|KN_BUTTON:
  307. Theme.Stop();
  308. Theme.Queue_Song(THEME_QUIET);
  309. // Theme.Queue_Song(THEME_NONE);
  310. break;
  311. /*
  312. ** Start the currently selected theme to play.
  313. */
  314. case KN_SPACE:
  315. case BUTTON_PLAY|KN_BUTTON:
  316. Theme.Queue_Song( (ThemeType)*((unsigned char *)listbox.Current_Item()) );
  317. break;
  318. /*
  319. ** Toggle the shuffle button.
  320. */
  321. case BUTTON_SHUFFLE|KN_BUTTON:
  322. shufflebtn.Set_Text(shufflebtn.IsOn ? TXT_ON : TXT_OFF);
  323. Options.Set_Shuffle(shufflebtn.IsOn);
  324. break;
  325. /*
  326. ** Toggle the repeat button.
  327. */
  328. case BUTTON_REPEAT|KN_BUTTON:
  329. repeatbtn.Set_Text(repeatbtn.IsOn ? TXT_ON : TXT_OFF);
  330. Options.Set_Repeat(repeatbtn.IsOn);
  331. break;
  332. }
  333. }
  334. /*
  335. ** If the score volume was turned all the way down, then actually
  336. ** stop the scores from being played.
  337. */
  338. if (Options.ScoreVolume == 0) {
  339. Theme.Stop();
  340. }
  341. /*
  342. ** Free the items from the list box.
  343. */
  344. while (listbox.Count()) {
  345. char const * ptr = listbox.Get_Item(0);
  346. listbox.Remove_Item(ptr);
  347. delete [] (void*)ptr;
  348. }
  349. }
  350. /***********************************************************************************************
  351. * MusicListClass::Draw_Entry -- Draw the score line in a list box. *
  352. * *
  353. * This routine will display the score line in a list box. It overrides the list box *
  354. * handler for line drawing. *
  355. * *
  356. * INPUT: index -- The index within the list box that is being drawn. *
  357. * *
  358. * x,y -- The pixel coordinates of the upper left position of the line. *
  359. * *
  360. * width -- The width of the line that drawing is allowed to use. *
  361. * *
  362. * selected-- Is the current line selected? *
  363. * *
  364. * OUTPUT: none *
  365. * *
  366. * WARNINGS: none *
  367. * *
  368. * HISTORY: *
  369. * 09/22/1995 JLB : Created. *
  370. *=============================================================================================*/
  371. void MusicListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  372. {
  373. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  374. if (TextFlags & TPF_6PT_GRAD) {
  375. TextPrintType flags = TextFlags;
  376. if (selected) {
  377. flags = flags | TPF_BRIGHT_COLOR;
  378. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1,
  379. GadgetClass::Get_Color_Scheme()->Shadow);
  380. } else {
  381. if (!(flags & TPF_USE_GRAD_PAL)) {
  382. flags = flags | TPF_MEDIUM_COLOR;
  383. }
  384. }
  385. Conquer_Clip_Text_Print((char *)List[index] + 1, x, y, scheme, TBLACK, flags, width, Tabs);
  386. } else {
  387. Conquer_Clip_Text_Print((char *)List[index] + 1, x, y,
  388. (selected ? &ColorRemaps[PCOLOR_DIALOG_BLUE] : &ColorRemaps[PCOLOR_GREY]), TBLACK, TextFlags, width, Tabs);
  389. }
  390. }