SOUNDDLG.CPP (13457B)
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: F:\projects\c&c\vcs\code\sounddlg.cpv 2.17 16 Oct 1995 16:51:32 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 : Jan 18, 1995 [MML] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * SoundControlsClass::Process -- Handles all the options graphic interface. * 34 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 35 36 #include "function.h" 37 #include "sounddlg.h" 38 39 class MusicListClass : public ListClass 40 { 41 public: 42 MusicListClass(int id, int x, int y, int w, int h) : 43 ListClass(id, x, y, w, h, TPF_6PT_GRAD|TPF_NOSHADOW, Hires_Retrieve("BTN-UP.SHP"), Hires_Retrieve("BTN-DN.SHP")) 44 {}; 45 virtual ~MusicListClass(void) {}; 46 47 protected: 48 virtual void Draw_Entry(int index, int x, int y, int width, int selected); 49 }; 50 int SoundControlsClass::Init(void) 51 { 52 int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2; 53 Option_Width =292 * factor; 54 Option_Height =146 * factor; 55 56 Option_X =((SeenBuff.Get_Width() - Option_Width) / 2); 57 Option_Y =(SeenBuff.Get_Height() - Option_Height) / 2; 58 59 Listbox_X =1 * factor; 60 Listbox_Y =54 * factor; 61 Listbox_W =290 * factor; 62 Listbox_H =73 * factor; 63 64 Button_Width =85 * factor; 65 Button_X =Option_Width-(Button_Width + (7 * factor)); 66 Button_Y =130 * factor; 67 68 Stop_X =5 * factor; 69 Stop_Y =129 * factor; 70 71 Play_X =23 * factor; 72 Play_Y =129 * factor; 73 74 OnOff_Width =25 * factor; 75 #ifdef GERMAN 76 Shuffle_X =79 * factor; 77 #else 78 Shuffle_X =91 * factor; 79 #endif 80 81 Shuffle_Y =130 * factor; 82 83 Repeat_X =166 * factor; 84 Repeat_Y =130 * factor; 85 86 MSlider_X =147 * factor; 87 MSlider_Y =28 * factor; 88 MSlider_W =108 * factor; 89 MSlider_Height =5 * factor; 90 91 FXSlider_X =147 * factor; 92 FXSlider_Y =40 * factor; 93 FXSlider_W =108 * factor; 94 FXSlider_Height=5 * factor; 95 return(factor); 96 } 97 98 /*********************************************************************************************** 99 * OptionsClass::Process -- Handles all the options graphic interface. * 100 * * 101 * This routine is the main control for the visual representation of the options * 102 * screen. It handles the visual overlay and the player input. * 103 * * 104 * INPUT: none * 105 * * 106 * OUTPUT: none * 107 * * 108 * WARNINGS: none * 109 * * 110 * HISTORY: 12/31/1994 MML : Created. * 111 *=============================================================================================*/ 112 void SoundControlsClass::Process(void) 113 { 114 // ThemeType theme; 115 116 int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2; 117 118 Init(); 119 /* 120 ** List box that holds the score text strings. 121 */ 122 MusicListClass listbox(0, Option_X+Listbox_X, Option_Y+Listbox_Y, Listbox_W, Listbox_H); 123 124 /* 125 ** Return to options menu button. 126 */ 127 TextButtonClass returnto(BUTTON_OPTIONS, TXT_OPTIONS_MENU, TPF_6PT_GRAD|TPF_NOSHADOW, 128 #ifdef FRENCH 129 Option_X+Button_X-8*2, Option_Y+Button_Y, Button_Width+11*2); 130 #else 131 Option_X+Button_X, Option_Y+Button_Y, Button_Width); 132 #endif 133 134 /* 135 ** Stop playing button. 136 */ 137 char filename[30]; 138 if (factor == 1) 139 strcpy(filename,"BTN-ST.SHP"); 140 else 141 strcpy(filename,"BTN-STH.SHP"); 142 ShapeButtonClass stopbtn(BUTTON_STOP, MixFileClass::Retrieve(filename), 143 Option_X+Stop_X, Option_Y+Stop_Y); 144 145 /* 146 ** Start playing button. 147 */ 148 if (factor == 1) 149 strcpy(filename,"BTN-PL.SHP"); 150 else 151 strcpy(filename,"BTN-PLH.SHP"); 152 153 ShapeButtonClass playbtn(BUTTON_PLAY, MixFileClass::Retrieve(filename), 154 Option_X+Play_X, Option_Y+Play_Y); 155 156 /* 157 ** Shuffle control. 158 */ 159 TextButtonClass shufflebtn(BUTTON_SHUFFLE, TXT_OFF, TPF_6PT_GRAD|TPF_NOSHADOW, 160 Option_X+Shuffle_X, Option_Y+Shuffle_Y, OnOff_Width); 161 162 /* 163 ** Repeat control. 164 */ 165 TextButtonClass repeatbtn(BUTTON_REPEAT, TXT_OFF, TPF_6PT_GRAD|TPF_NOSHADOW, Option_X+Repeat_X, Option_Y+Repeat_Y, OnOff_Width); 166 167 /* 168 ** Music volume slider. 169 */ 170 SliderClass music(SLIDER_MUSIC, Option_X+MSlider_X, Option_Y+MSlider_Y, MSlider_W, MSlider_Height); 171 172 /* 173 ** Sound volume slider. 174 */ 175 SliderClass sound(SLIDER_SOUND, Option_X+FXSlider_X, Option_Y+FXSlider_Y, FXSlider_W, FXSlider_Height); 176 177 /* 178 ** Causes left mouse clicks inside the dialog area, but not on any 179 ** particular button, to be ignored. 180 */ 181 GadgetClass area(Option_X, Option_Y, Option_Width, Option_Height, GadgetClass::LEFTPRESS); 182 183 /* 184 ** Causes right clicks anywhere or left clicks outside of the dialog 185 ** box area to be the same a clicking the return to game options button. 186 */ 187 ControlClass ctrl(BUTTON_OPTIONS, 0, 0, SeenBuff.Get_Width(), SeenBuff.Get_Height(), GadgetClass::RIGHTPRESS|GadgetClass::LEFTPRESS); 188 189 /* 190 ** The repeat and shuffle buttons are of the toggle type. They toggle 191 ** between saying "on" and "off". 192 */ 193 shufflebtn.IsToggleType = true; 194 if (Options.IsScoreShuffle) { 195 shufflebtn.Turn_On(); 196 } else { 197 shufflebtn.Turn_Off(); 198 } 199 shufflebtn.Set_Text(shufflebtn.IsOn ? TXT_ON : TXT_OFF); 200 201 repeatbtn.IsToggleType = true; 202 if (Options.IsScoreRepeat) { 203 repeatbtn.Turn_On(); 204 } else { 205 repeatbtn.Turn_Off(); 206 } 207 repeatbtn.Set_Text(repeatbtn.IsOn ? TXT_ON : TXT_OFF); 208 209 /* 210 ** Set the initial values of the sliders. 211 */ 212 music.Set_Maximum(255); 213 music.Set_Thumb_Size(16); 214 music.Set_Value(Options.ScoreVolume); 215 sound.Set_Maximum(255); 216 sound.Set_Thumb_Size(16); 217 sound.Set_Value(Options.Volume); 218 219 /* 220 ** Set up the window. Window x-coords are in bytes not pixels. 221 */ 222 Set_Logic_Page(SeenBuff); 223 224 /* 225 ** Create Buttons. 226 */ 227 GadgetClass * optionsbtn = &returnto; 228 listbox.Add_Tail(*optionsbtn); 229 stopbtn.Add_Tail(*optionsbtn); 230 playbtn.Add_Tail(*optionsbtn); 231 shufflebtn.Add_Tail(*optionsbtn); 232 repeatbtn.Add_Tail(*optionsbtn); 233 music.Add_Tail(*optionsbtn); 234 sound.Add_Tail(*optionsbtn); 235 area.Add_Tail(*optionsbtn); 236 ctrl.Add_Tail(*optionsbtn); 237 238 /* 239 ** Add all the themes to the list box. The list box entries are constructed 240 ** and then stored into allocated EMS memory blocks. 241 */ 242 // char buffer[100]; 243 for (ThemeType index = THEME_FIRST; index < Theme.Max_Themes(); index++) { 244 if (Theme.Is_Allowed(index)) { 245 int length = Theme.Track_Length(index); 246 char const * fullname = Theme.Full_Name(index); 247 248 void * ptr = new char [sizeof(100)]; 249 if (ptr) { 250 sprintf((char *)ptr, "%cTrack %d\t%d:%02d\t%s", index, listbox.Count()+1, length / 60, length % 60, fullname); 251 listbox.Add_Item((char const *)ptr); 252 } 253 254 if (Theme.What_Is_Playing() == index) { 255 listbox.Set_Selected_Index(listbox.Count()-1); 256 } 257 } 258 } 259 static int _tabs[] = { 260 55*factor, 72*factor, 90*factor 261 }; 262 listbox.Set_Tabs(_tabs); 263 264 /* 265 ** Main Processing Loop. 266 */ 267 bool display = true; 268 bool process = true; 269 270 while (process) { 271 272 /* 273 ** Invoke game callback. 274 */ 275 if (GameToPlay == GAME_NORMAL) { 276 Call_Back(); 277 } else { 278 if (Main_Loop()) { 279 process = false; 280 } 281 } 282 283 /* 284 ** If we have just received input focus again after running in the background then 285 ** we need to redraw. 286 */ 287 if (AllSurfaces.SurfacesRestored){ 288 AllSurfaces.SurfacesRestored=FALSE; 289 display=TRUE; 290 } 291 292 /* 293 ** Refresh display if needed. 294 */ 295 if (display) { 296 297 Hide_Mouse(); 298 299 /* 300 ** Draw the background. 301 */ 302 Dialog_Box(Option_X, Option_Y, Option_Width, Option_Height); 303 304 Draw_Caption(TXT_SOUND_CONTROLS, Option_X, Option_Y, Option_Width); 305 306 /* 307 ** Draw the Music, Speech & Sound titles. 308 */ 309 Fancy_Text_Print(TXT_MUSIC_VOLUME, Option_X+MSlider_X-5, Option_Y+MSlider_Y-2, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW|TPF_RIGHT); 310 Fancy_Text_Print(TXT_SOUND_VOLUME, Option_X+FXSlider_X-5, Option_Y+FXSlider_Y-2, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW|TPF_RIGHT); 311 312 Fancy_Text_Print(TXT_SHUFFLE, Option_X+Shuffle_X-5, Option_Y+Shuffle_Y+1, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW|TPF_RIGHT); 313 Fancy_Text_Print(TXT_REPEAT, Option_X+Repeat_X-5, Option_Y+Repeat_Y+1, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW|TPF_RIGHT); 314 315 optionsbtn->Draw_All(); 316 Show_Mouse(); 317 display = false; 318 } 319 320 /* 321 ** Get user input. 322 */ 323 KeyNumType input = optionsbtn->Input(); 324 325 /* 326 ** Process Input. 327 */ 328 switch (input) { 329 330 case KN_ESC: 331 case BUTTON_OPTIONS|KN_BUTTON: 332 process = false; 333 break; 334 335 /* 336 ** Control music volume. 337 */ 338 case SLIDER_MUSIC|KN_BUTTON: 339 Options.Set_Score_Volume(music.Get_Value()); 340 break; 341 342 /* 343 ** Control sound volume. 344 */ 345 case SLIDER_SOUND|KN_BUTTON: 346 Options.Set_Sound_Volume(sound.Get_Value(), true); 347 break; 348 349 case BUTTON_LISTBOX|KN_BUTTON: 350 // Mono_Printf ("%d %s Listbox was pressed.\r",__LINE__, __FILE__); 351 break; 352 353 /* 354 ** Stop all themes from playing. 355 */ 356 case BUTTON_STOP|KN_BUTTON: 357 Theme.Queue_Song(THEME_NONE); 358 break; 359 360 /* 361 ** Start the currently selected theme to play. 362 */ 363 case KN_SPACE: 364 case BUTTON_PLAY|KN_BUTTON: 365 if (listbox.Count()) { 366 Theme.Queue_Song( (ThemeType)*((unsigned char *)listbox.Current_Item()) ); 367 } 368 break; 369 370 /* 371 ** Toggle the shuffle button. 372 */ 373 case BUTTON_SHUFFLE|KN_BUTTON: 374 shufflebtn.Set_Text(shufflebtn.IsOn ? TXT_ON : TXT_OFF); 375 Options.Set_Shuffle(shufflebtn.IsOn); 376 break; 377 378 /* 379 ** Toggle the repeat button. 380 */ 381 case BUTTON_REPEAT|KN_BUTTON: 382 repeatbtn.Set_Text(repeatbtn.IsOn ? TXT_ON : TXT_OFF); 383 Options.Set_Repeat(repeatbtn.IsOn); 384 break; 385 } 386 } 387 388 /* 389 ** If the score volume was turned all the way down, then actually 390 ** stop the scores from being played. 391 */ 392 if (!Options.ScoreVolume) { 393 Theme.Stop(); 394 } 395 396 /* 397 ** Save them settings - you know it makes sense 398 */ 399 Options.Save_Settings(); // save new value 400 401 /* 402 ** Free the items from the list box. 403 */ 404 while (listbox.Count()) { 405 char const * ptr = listbox.Get_Item(0); 406 listbox.Remove_Item(ptr); 407 delete [] (void*)ptr; 408 } 409 } 410 411 412 void MusicListClass::Draw_Entry(int index, int x, int y, int width, int selected) 413 { 414 if (TextFlags & TPF_6PT_GRAD) { 415 TextPrintType flags = TextFlags; 416 417 if (selected) { 418 flags = flags | TPF_BRIGHT_COLOR; 419 LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, CC_GREEN_SHADOW); 420 } else { 421 if (!(flags & TPF_USE_GRAD_PAL)) { 422 flags = flags | TPF_MEDIUM_COLOR; 423 } 424 } 425 426 Conquer_Clip_Text_Print((char *)Add_Long_To_Pointer(List[index], 1), x, y, CC_GREEN, TBLACK, flags, width, Tabs); 427 428 } else { 429 Conquer_Clip_Text_Print((char *)Add_Long_To_Pointer(List[index], 1), x, y, (selected ? BLUE : WHITE), TBLACK, TextFlags, width, Tabs); 430 } 431 }