SOUNDDLG.CPP 16 KB

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