CnC_Remastered_Collection

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

CONFDLG.CPP (8003B)


      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\confdlg.cpv   2.17   16 Oct 1995 16:49:52   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 : CONFDLG.CPP                                                  *
     24  *                                                                                             *
     25  *                   Programmer : Maria del Mar McCready Legg                                  *
     26  *                                  Joe L. Bostic                                              *
     27  *                                                                                             *
     28  *                   Start Date : Jan 30, 1995                                                 *
     29  *                                                                                             *
     30  *                  Last Update : Jan 30, 1995   [MML]                                         *
     31  *                                                                                             *
     32  *---------------------------------------------------------------------------------------------*
     33  * Functions:                                                                                  *
     34  *   ConfirmationClass::Process -- Handles all the options graphic interface.                  *
     35  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     36 
     37 #include	"function.h"
     38 #include	"confdlg.h"
     39 
     40 
     41 bool ConfirmationClass::Process(int text)
     42 {
     43 	return(Process(Text_String(text)));
     44 }
     45 
     46 
     47 /***********************************************************************************************
     48  * ConfirmationClass::Process -- Handles all the options graphic interface.                    *
     49  *                                                                                             *
     50  *    This dialog uses an edit box to confirm a deletion.                                      *
     51  *                                                                                             *
     52  * INPUT:   	char *string - display in edit box.                                             *
     53  * OUTPUT:  	none                                                                            *
     54  * WARNINGS:   none                                                                            *
     55  * HISTORY:    12/31/1994 MML : Created.                                                       *
     56  *=============================================================================================*/
     57 bool ConfirmationClass::Process(char const * string)
     58 {
     59 	int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
     60 
     61 	enum {
     62 		NUM_OF_BUTTONS = 2
     63 	};
     64 
     65 	char buffer[80*3];
     66 	int result = true;
     67 	int width;
     68 	int bwidth, bheight;				// button width and height
     69 	int height;
     70 	int selection;
     71 	bool pressed;
     72 	int curbutton;
     73 	TextButtonClass *buttons[NUM_OF_BUTTONS];
     74 
     75 	/*
     76 	**	Set up the window.  Window x-coords are in bytes not pixels.
     77 	*/
     78 	strcpy(buffer, string);
     79 	Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
     80 	Format_Window_String(buffer, 200*factor, width, height);
     81 	width += 60*factor;
     82 	height += 60*factor;
     83 	int x = (320*factor - width) / 2;
     84 	int y = (200*factor - height) / 2;
     85 
     86 	Set_Logic_Page(SeenBuff);
     87 
     88 	/*
     89 	**	Create Buttons.  Button coords are in pixels, but are window-relative.
     90 	*/
     91 
     92 	bheight = FontHeight + FontYSpacing + 2;
     93 	bwidth = MAX( (String_Pixel_Width( Text_String( TXT_YES ) ) + 8), 30U);
     94 
     95 	TextButtonClass yesbtn(BUTTON_YES, TXT_YES,
     96 		TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
     97 		x + 10*factor, y + height - (bheight + 5*factor), bwidth );
     98 
     99 	TextButtonClass nobtn(BUTTON_NO, TXT_NO,
    100 		TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
    101 		x + width - (bwidth + 10*factor),
    102 		y + height - (bheight + 5*factor), bwidth );
    103 
    104 	nobtn.Add_Tail(yesbtn);
    105 
    106 	curbutton = 1;
    107 	buttons[0] = &yesbtn;
    108 	buttons[1] = &nobtn;
    109 	buttons[curbutton]->Turn_On();
    110 
    111 	/*
    112 	**	This causes left mouse button clicking within the confines of the dialog to
    113 	**	be ignored if it wasn't recognized by any other button or slider.
    114 	*/
    115 	GadgetClass dialog(x, y, width, height, GadgetClass::LEFTPRESS);
    116 	dialog.Add_Tail(yesbtn);
    117 
    118 	/*
    119 	**	This causes a right click anywhere or a left click outside the dialog region
    120 	**	to be equivalent to clicking on the return to options dialog.
    121 	*/
    122 	ControlClass background(BUTTON_NO, 0, 0, SeenBuff.Get_Width(), SeenBuff.Get_Height(), GadgetClass::LEFTPRESS|GadgetClass::RIGHTPRESS);
    123 	background.Add_Tail(yesbtn);
    124 
    125 	/*
    126 	**	Main Processing Loop.
    127 	*/
    128 	bool display = true;
    129 	bool process = true;
    130 	pressed = false;
    131 	while (process) {
    132 
    133 		/*
    134 		**	Invoke game callback.
    135 		*/
    136 		if (GameToPlay == GAME_NORMAL) {
    137 			Call_Back();
    138 		} else {
    139 			if (Main_Loop()) {
    140 				process = false;
    141 				result = false;
    142 			}
    143 		}
    144 
    145 		/*
    146 		** If we have just received input focus again after running in the background then
    147 		** we need to redraw.
    148 		*/
    149 		if (AllSurfaces.SurfacesRestored){
    150 			AllSurfaces.SurfacesRestored=FALSE;
    151 			display=TRUE;
    152 		}
    153 
    154 		/*
    155 		**	Refresh display if needed.
    156 		*/
    157 		if (display) {
    158 			Hide_Mouse();
    159 
    160 			/*
    161 			**	Draw the background.
    162 			*/
    163 			Dialog_Box(x, y, width, height);
    164 			Draw_Caption(TXT_CONFIRMATION, x, y, width);
    165 			Fancy_Text_Print(buffer, x+20*factor, y+30*factor, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
    166 
    167 			/*
    168 			**	Draw the titles.
    169 			*/
    170 			yesbtn.Draw_All();
    171 			Show_Mouse();
    172 			display = false;
    173 		}
    174 
    175 		/*
    176 		**	Get user input.
    177 		*/
    178 		KeyNumType input = yesbtn.Input();
    179 
    180 		/*
    181 		**	Process Input.
    182 		*/
    183 		switch (input) {
    184 			case (BUTTON_YES | KN_BUTTON):
    185 				selection = BUTTON_YES;
    186 				pressed = true;
    187 				break;
    188 
    189 			case (KN_ESC):
    190 			case (BUTTON_NO | KN_BUTTON):
    191 				selection = BUTTON_NO;
    192 				pressed = true;
    193 				break;
    194 
    195 			case (KN_LEFT):
    196 				buttons[curbutton]->Turn_Off();
    197 				buttons[curbutton]->Flag_To_Redraw();
    198 
    199 				curbutton--;
    200 				if (curbutton < 0) {
    201 					curbutton = NUM_OF_BUTTONS - 1;
    202 				}
    203 
    204 				buttons[curbutton]->Turn_On();
    205 				buttons[curbutton]->Flag_To_Redraw();
    206 				break;
    207 
    208 			case (KN_RIGHT):
    209 				buttons[curbutton]->Turn_Off();
    210 				buttons[curbutton]->Flag_To_Redraw();
    211 
    212 				curbutton++;
    213 				if (curbutton > (NUM_OF_BUTTONS - 1) ) {
    214 					curbutton = 0;
    215 				}
    216 
    217 				buttons[curbutton]->Turn_On();
    218 				buttons[curbutton]->Flag_To_Redraw();
    219 				break;
    220 
    221 			case (KN_RETURN):
    222 				selection = curbutton + BUTTON_YES;
    223 				pressed = true;
    224 				break;
    225 
    226 			default:
    227 				break;
    228 		}
    229 
    230 		if (pressed) {
    231 			switch (selection) {
    232 				case (BUTTON_YES):
    233 					result = true;
    234 					process = false;
    235 					break;
    236 
    237 				case (BUTTON_NO):
    238 					result  = false;
    239 					process = false;
    240 					break;
    241 			}
    242 
    243 			pressed = false;
    244 		}
    245 	}
    246 	return(result);
    247 }