CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

SOUNDDLG.CPP (16537B)


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