CnC_Remastered_Collection

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

WOL_OPT.CPP (6863B)


      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 #ifdef WOLAPI_INTEGRATION
     17 
     18 //	Wol_Opt.cpp - WW online options dialog.
     19 //	ajw 09/1/98
     20 
     21 #include "function.h"
     22 
     23 #include "IconList.h"
     24 #include "WolapiOb.h"
     25 #include "WolStrng.h"
     26 #include "BigCheck.h"
     27 //#include "WolDebug.h"
     28 
     29 extern bool cancel_current_msgbox;
     30 
     31 //***********************************************************************************************
     32 bool WOL_Options_Dialog( WolapiObject* pWO, bool bCalledFromGame )
     33 {
     34 	//	Returns true only if called from inside game, and the game ended on us unexpectedly.
     35 	bool bReturn = false;
     36 
     37 	bool bEscapeDown = false;
     38 	bool bReturnDown = false;
     39 
     40 	bool bIgnoreReturnDown = false;
     41 	if( ( ::GetAsyncKeyState( VK_RETURN ) & 0x8000 ) )
     42 	{
     43 		//	The return key is already down, as we enter the dialog.
     44 		//	Until it comes up again, ignore this fact, so that we don't act on a return press that's not valid.
     45 		bIgnoreReturnDown = true;
     46 	}
     47 
     48 	/*
     49 	**	Dialog & button dimensions
     50 	*/
     51 #ifdef GERMAN
     52 	int d_list_w = 180 * RESFACTOR;
     53 #else
     54 #ifdef FRENCH
     55 	int d_list_w = 165 * RESFACTOR;
     56 #else
     57 	int d_list_w = 165 * RESFACTOR;
     58 #endif
     59 #endif
     60 
     61 	int d_dialog_w = d_list_w + 40 * RESFACTOR;											// dialog width
     62 	int d_dialog_h = 90 * RESFACTOR;											// dialog height
     63 	int d_dialog_x = (((320 * RESFACTOR) - d_dialog_w) / 2);
     64 	int d_dialog_y = (((200 * RESFACTOR) - d_dialog_h) / 2);
     65 	int d_dialog_cx = d_dialog_x + (d_dialog_w / 2);		// coord of x-center
     66 
     67 	int d_txt8_h = 11 * RESFACTOR;												// ht of 8-pt text
     68 	int d_margin = 7 * RESFACTOR;												// margin width/height
     69 	int x_margin = 16 * RESFACTOR;												// margin width/height
     70 
     71 	int top_margin = 0;
     72 
     73 //	int d_list_w = 100 * RESFACTOR;
     74 	int d_list_h = 7 * RESFACTOR;
     75 	int d_list_x = d_dialog_cx - d_list_w / 2;
     76 	int d_list_y = d_dialog_y + d_margin + 24;
     77 
     78 #if (GERMAN | FRENCH)
     79 	int d_ok_w = 40 * RESFACTOR;
     80 #else
     81 	int d_ok_w = 40 * RESFACTOR;
     82 #endif
     83 	int d_ok_h = 13 * RESFACTOR;
     84 	int d_ok_x = d_dialog_cx - d_ok_w / 2;
     85 	int d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin;
     86 
     87 	/*
     88 	**	Button enumerations
     89 	*/
     90 	enum {
     91 		BUTTON_OK = 100,
     92 		CHECK_FIND,
     93 		CHECK_PAGE,
     94 		CHECK_LANGUAGE,
     95 		CHECK_ALLGAMES,
     96 		CHECK_RANKAM,
     97 	};
     98 
     99 	/*
    100 	**	Buttons
    101 	*/
    102 	ControlClass* commands = NULL;		// the button list
    103 
    104 	TextButtonClass OkBtn( BUTTON_OK, TXT_OK, TPF_BUTTON, d_ok_x, d_ok_y, d_ok_w );
    105 
    106 	BigCheckBoxClass FindCheck( CHECK_FIND, d_list_x, d_list_y, d_list_w, d_list_h, 
    107 								TXT_WOL_OPTFIND, TPF_6PT_GRAD | TPF_NOSHADOW, pWO->bFindEnabled );
    108 	BigCheckBoxClass PageCheck( CHECK_PAGE, d_list_x, d_list_y + d_list_h + 2, d_list_w, d_list_h, 
    109 								TXT_WOL_OPTPAGE, TPF_6PT_GRAD | TPF_NOSHADOW, pWO->bPageEnabled );
    110 	BigCheckBoxClass LanguageCheck( CHECK_LANGUAGE, d_list_x, d_list_y + 2 * ( d_list_h + 2 ), d_list_w, d_list_h, 
    111 									TXT_WOL_OPTLANGUAGE, TPF_6PT_GRAD | TPF_NOSHADOW, pWO->bLangFilter );
    112 	BigCheckBoxClass GamescopeCheck( CHECK_ALLGAMES, d_list_x, d_list_y + 3 * ( d_list_h + 2 ), d_list_w, d_list_h, 
    113 									TXT_WOL_OPTGAMESCOPE, TPF_6PT_GRAD | TPF_NOSHADOW, !pWO->bAllGamesShown );
    114 	BigCheckBoxClass RankAMCheck( CHECK_RANKAM, d_list_x, d_list_y + 4 * ( d_list_h + 2 ), d_list_w, d_list_h, 
    115 									TXT_WOL_OPTRANKAM, TPF_6PT_GRAD | TPF_NOSHADOW, !pWO->bShowRankRA );
    116 
    117 	/*
    118 	**	Initialize.
    119 	*/
    120 	Set_Logic_Page(SeenBuff);
    121 
    122 	/*
    123 	**	Create the button list.
    124 	*/
    125 	commands = &OkBtn;
    126 	FindCheck.Add_Tail(*commands);
    127 	PageCheck.Add_Tail(*commands);
    128 	LanguageCheck.Add_Tail(*commands);
    129 	GamescopeCheck.Add_Tail(*commands);
    130 	RankAMCheck.Add_Tail(*commands);
    131 
    132 	/*
    133 	**	Main Processing Loop.
    134 	*/
    135 	Keyboard->Clear();
    136 	bool display = true;
    137 	bool process = true;
    138 	while (process) {
    139 
    140 		/*
    141 		**	Invoke game callback.
    142 		*/
    143 		if( !bCalledFromGame )
    144 			Call_Back();
    145 		else
    146 		{
    147 			if( Main_Loop() )	//	Game ended on us in the background.
    148 			{
    149 				process = false;
    150 				bReturn = true;
    151 			}
    152 		}
    153 
    154 		#ifdef WIN32
    155 		/*
    156 		** If we have just received input focus again after running in the background then
    157 		** we need to redraw.
    158 		*/
    159 		if (AllSurfaces.SurfacesRestored) {
    160 			AllSurfaces.SurfacesRestored=FALSE;
    161 			display = true;
    162 		}
    163 		#endif
    164 
    165 		/*
    166 		**	Refresh display if needed.
    167 		*/
    168 		if (display) {
    169 
    170 			/*
    171 			**	Display the dialog box.
    172 			*/
    173 			Hide_Mouse();
    174 			Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
    175 			Draw_Caption( TXT_WOL_OPTTITLE, d_dialog_x, d_dialog_y, d_dialog_w );
    176 			commands->Flag_List_To_Redraw();
    177 			Show_Mouse();
    178 			display = false;
    179 		}
    180 
    181 		//	Force mouse visible, as some beta testers report unexplicable disappearing cursors.
    182 		while( Get_Mouse_State() )
    183 			Show_Mouse();
    184 		//	Be nice to other apps.
    185 		Sleep( 50 );
    186 
    187 		/*
    188 		**	Get user input.
    189 		*/
    190 		KeyNumType input = commands->Input();
    191 
    192 		//	My hack for triggering escape and return on key up instead of down...
    193 		//	The problem that was occurring was that the calling dialog would act on the key up,
    194 		//	though this dialog handled the key down. ajw
    195 		if( ( ::GetAsyncKeyState( VK_ESCAPE ) & 0x8000 ) )
    196 		{
    197 			bEscapeDown = true;
    198 		}
    199 		else if( bEscapeDown )
    200 		{
    201 			input = (KeyNumType)( BUTTON_OK | KN_BUTTON );
    202 			bEscapeDown = false;
    203 		}
    204 		if( ( ::GetAsyncKeyState( VK_RETURN ) & 0x8000 ) )
    205 		{
    206 			if( !bIgnoreReturnDown )
    207 				bReturnDown = true;
    208 		}
    209 		else
    210 		{
    211 			bIgnoreReturnDown = false;
    212 			if( bReturnDown )
    213 			{
    214 				input = (KeyNumType)( BUTTON_OK | KN_BUTTON );
    215 				bReturnDown = false;
    216 			}
    217 		}
    218 
    219 		/*
    220 		**	Process input.
    221 		*/
    222 
    223 		if( cancel_current_msgbox )
    224 		{
    225 			cancel_current_msgbox = false;
    226 			input = (KeyNumType)( BUTTON_OK | KN_BUTTON );
    227 		}
    228 		switch( input )
    229 		{
    230 			case ( BUTTON_OK | KN_BUTTON ):
    231 				process = false;
    232 				break;
    233 
    234 			case ( CHECK_FIND | KN_BUTTON ):
    235 			case ( CHECK_PAGE | KN_BUTTON ):
    236 			case ( CHECK_LANGUAGE | KN_BUTTON ):
    237 			case ( CHECK_ALLGAMES | KN_BUTTON ):
    238 				pWO->SetOptions( FindCheck.IsOn, PageCheck.IsOn, LanguageCheck.IsOn, !GamescopeCheck.IsOn );
    239 				break;
    240 
    241 			case ( CHECK_RANKAM | KN_BUTTON ):
    242 				pWO->bShowRankRA = !RankAMCheck.IsOn;
    243 				pWO->bMyRecordUpdated = true;
    244 				pWO->bShowRankUpdated = true;
    245 				break;
    246 
    247 			default:
    248 				break;
    249 		}
    250 	}
    251 	return bReturn;
    252 }
    253 
    254 #endif