WOL_CGAM.CPP (11772B)
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 // Implies FIXIT_CSII. 17 18 // Wol_CGam.cpp - Create game dialog. 19 // ajw 09/9/98 20 21 #include "function.h" 22 23 #ifndef FIXIT_CSII 24 #error FIXIT_CSII must be defined. 25 #endif 26 27 #include "IconList.h" 28 #include "WolapiOb.h" 29 #include "WolStrng.h" 30 #include "SEditDlg.h" 31 #include "BigCheck.h" 32 33 //extern char* LoadShpFile( const char* szShpFile ); 34 void SetPlayerCountList( IconListClass& PlayerCountList, int iPlayerMax, char* pShpBoxCheck, char* pShpBoxEmpty ); 35 36 //*********************************************************************************************** 37 CREATEGAMEINFO WOL_CreateGame_Dialog( WolapiObject* pWO ) 38 { 39 CREATEGAMEINFO cgiReturn; 40 cgiReturn.bCreateGame = false; 41 cgiReturn.iPlayerMax = 2; 42 cgiReturn.bTournament = false; 43 cgiReturn.bPrivate = false; 44 cgiReturn.GameKind = CREATEGAMEINFO::RAGAME; 45 *cgiReturn.szPassword = 0; 46 47 bool bEscapeDown = false; 48 bool bReturnDown = false; 49 50 /* 51 ** Dialog & button dimensions 52 */ 53 int d_dialog_w = 150 * RESFACTOR; // dialog width 54 int d_dialog_h = 135 * RESFACTOR; // dialog height 55 int d_dialog_x = (((320 * RESFACTOR) - d_dialog_w) / 2); 56 int d_dialog_y = (((200 * RESFACTOR) - d_dialog_h) / 2); 57 int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // coord of x-center 58 59 int d_txt8_h = 11 * RESFACTOR; // ht of 8-pt text 60 int d_margin = 7 * RESFACTOR; // margin width/height 61 int x_margin = 16 * RESFACTOR; // margin width/height 62 63 int top_margin = 0; 64 65 int d_gaugeplayers_w = 70 * RESFACTOR; 66 int d_gaugeplayers_h = 9 * RESFACTOR; 67 int d_gaugeplayers_x = d_dialog_cx - d_gaugeplayers_w / 2; 68 int d_gaugeplayers_y = d_dialog_y + d_margin + 42; 69 70 int d_checktourn_w = 75 * RESFACTOR; 71 int d_checktourn_h = 9 * RESFACTOR; 72 int d_checktourn_x = d_dialog_cx - d_checktourn_w / 2; 73 int d_checktourn_y = d_gaugeplayers_y + d_gaugeplayers_h + 10; 74 75 int d_checkpriv_w = d_checktourn_w; 76 int d_checkpriv_h = 9 * RESFACTOR; 77 int d_checkpriv_x = d_checktourn_x; 78 int d_checkpriv_y = d_checktourn_y + d_checktourn_h + 10; 79 80 int d_checkra_w = d_checktourn_w; 81 int d_checkra_h = 9 * RESFACTOR; 82 int d_checkra_x = d_checktourn_x; 83 int d_checkra_y = d_checkpriv_y + d_checkpriv_h + 20; 84 85 int d_checkcs_w = d_checktourn_w; 86 int d_checkcs_h = 9 * RESFACTOR; 87 int d_checkcs_x = d_checktourn_x; 88 int d_checkcs_y = d_checkra_y + d_checkra_h + 5; 89 90 int d_checkam_w = d_checktourn_w; 91 int d_checkam_h = 9 * RESFACTOR; 92 int d_checkam_x = d_checktourn_x; 93 int d_checkam_y = d_checkcs_y + d_checkcs_h + 5; 94 95 #if (GERMAN | FRENCH) 96 int d_ok_w = 30 * RESFACTOR; 97 #else 98 int d_ok_w = 30 * RESFACTOR; 99 #endif 100 int d_ok_h = 13 * RESFACTOR; 101 int d_ok_x = d_dialog_x + ( d_dialog_w / 3 ) - ( d_ok_w / 2 ); 102 int d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin; 103 104 int d_cancel_w = 40 * RESFACTOR; 105 int d_cancel_h = 9 * RESFACTOR; 106 int d_cancel_x = d_dialog_x + ( ( d_dialog_w * 2 ) / 3 ) - ( d_cancel_w / 2 ); 107 int d_cancel_y = d_ok_y; 108 109 /* 110 ** Button enumerations 111 */ 112 enum { 113 BUTTON_OK = 100, 114 BUTTON_CANCEL, 115 GAUGE_PLAYERCOUNT, 116 CHECK_TOURNAMENT, 117 CHECK_PRIVACY, 118 CHECK_RA, 119 CHECK_CS, 120 CHECK_AM, 121 }; 122 123 /* 124 ** Buttons 125 */ 126 ControlClass* commands = NULL; // the button list 127 128 TextButtonClass OkBtn( BUTTON_OK, TXT_OK, TPF_BUTTON, d_ok_x, d_ok_y, d_ok_w ); 129 TextButtonClass CancelBtn( BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w ); 130 131 StaticButtonClass PlayerCountStatic( 0, " ", TPF_TEXT, d_gaugeplayers_x, d_gaugeplayers_y - 16 ); 132 GaugeClass PlayerCountGauge( GAUGE_PLAYERCOUNT, d_gaugeplayers_x, d_gaugeplayers_y, d_gaugeplayers_w, d_gaugeplayers_h ); 133 134 if( pWO->bEgg8Player ) 135 PlayerCountGauge.Set_Maximum( 6 ); 136 else 137 PlayerCountGauge.Set_Maximum( 2 ); 138 PlayerCountGauge.Set_Value( cgiReturn.iPlayerMax - 2 ); 139 140 BigCheckBoxClass TournamentCheck( CHECK_TOURNAMENT, d_checktourn_x, d_checktourn_y, d_checktourn_w, d_checktourn_h, 141 TXT_WOL_CG_TOURNAMENT, TPF_6PT_GRAD | TPF_NOSHADOW, cgiReturn.bTournament ); 142 143 BigCheckBoxClass PrivacyCheck( CHECK_PRIVACY, d_checkpriv_x, d_checkpriv_y, d_checkpriv_w, d_checkpriv_h, 144 TXT_WOL_CG_PRIVACY, TPF_6PT_GRAD | TPF_NOSHADOW, cgiReturn.bPrivate ); 145 146 BigCheckBoxClass RA_Check( CHECK_RA, d_checkra_x, d_checkra_y, d_checkra_w, d_checkra_h, 147 TXT_WOL_CG_RAGAME, TPF_6PT_GRAD | TPF_NOSHADOW, cgiReturn.GameKind == CREATEGAMEINFO::RAGAME ); 148 BigCheckBoxClass CS_Check( CHECK_CS, d_checkcs_x, d_checkcs_y, d_checkcs_w, d_checkcs_h, 149 TXT_WOL_CG_CSGAME, TPF_6PT_GRAD | TPF_NOSHADOW, cgiReturn.GameKind == CREATEGAMEINFO::CSGAME ); 150 BigCheckBoxClass AM_Check( CHECK_AM, d_checkam_x, d_checkam_y, d_checkam_w, d_checkam_h, 151 TXT_WOL_CG_AMGAME, TPF_6PT_GRAD | TPF_NOSHADOW, cgiReturn.GameKind == CREATEGAMEINFO::AMGAME ); 152 153 if( !Is_Counterstrike_Installed() ) 154 CS_Check.Disable(); 155 156 if( !Is_Aftermath_Installed() ) 157 AM_Check.Disable(); 158 159 /* 160 ** Initialize. 161 */ 162 Set_Logic_Page(SeenBuff); 163 164 /* 165 ** Create the button list. 166 */ 167 commands = &OkBtn; 168 CancelBtn.Add_Tail(*commands); 169 PlayerCountStatic.Add_Tail(*commands); 170 PlayerCountGauge.Add_Tail(*commands); 171 TournamentCheck.Add_Tail(*commands); 172 PrivacyCheck.Add_Tail(*commands); 173 RA_Check.Add_Tail(*commands); 174 CS_Check.Add_Tail(*commands); 175 AM_Check.Add_Tail(*commands); 176 177 char szPlayerCount[ 100 ]; 178 sprintf( szPlayerCount, TXT_WOL_CG_PLAYERS, cgiReturn.iPlayerMax ); 179 PlayerCountStatic.Set_Text( szPlayerCount ); 180 181 /* 182 ** Main Processing Loop. 183 */ 184 Keyboard->Clear(); 185 bool display = true; 186 bool process = true; 187 while (process) { 188 189 /* 190 ** Invoke game callback. 191 */ 192 Call_Back(); 193 194 #ifdef WIN32 195 /* 196 ** If we have just received input focus again after running in the background then 197 ** we need to redraw. 198 */ 199 if (AllSurfaces.SurfacesRestored) { 200 AllSurfaces.SurfacesRestored=FALSE; 201 display = true; 202 } 203 #endif 204 205 /* 206 ** Refresh display if needed. 207 */ 208 if (display) { 209 210 /* 211 ** Display the dialog box. 212 */ 213 Hide_Mouse(); 214 Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h); 215 Draw_Caption( TXT_WOL_CG_TITLE, d_dialog_x, d_dialog_y, d_dialog_w ); 216 // Fancy_Text_Print( TXT_WOL_CG_PLAYERS, d_gaugeplayers_x - 2*RESFACTOR, d_gaugeplayers_y, 217 // GadgetClass::Get_Color_Scheme(), TBLACK, TPF_TEXT | TPF_RIGHT ); 218 commands->Flag_List_To_Redraw(); 219 Show_Mouse(); 220 display = false; 221 } 222 223 // Force mouse visible, as some beta testers report unexplicable disappearing cursors. 224 while( Get_Mouse_State() ) 225 Show_Mouse(); 226 // Be nice to other apps. 227 Sleep( 50 ); 228 229 /* 230 ** Get user input. 231 */ 232 KeyNumType input = commands->Input(); 233 234 // My hack for triggering escape and return on key up instead of down... 235 // The problem that was occurring was that the calling dialog would act on the key up, 236 // though this dialog handled the key down. ajw 237 if( ( ::GetAsyncKeyState( VK_ESCAPE ) & 0x8000 ) ) 238 { 239 bEscapeDown = true; 240 } 241 else if( bEscapeDown ) 242 { 243 input = (KeyNumType)( BUTTON_CANCEL | KN_BUTTON ); 244 bEscapeDown = false; 245 } 246 if( ( ::GetAsyncKeyState( VK_RETURN ) & 0x8000 ) ) 247 { 248 bReturnDown = true; 249 } 250 else if( bReturnDown ) 251 { 252 input = (KeyNumType)( BUTTON_OK | KN_BUTTON ); 253 bReturnDown = false; 254 } 255 256 /* 257 ** Process input. 258 */ 259 260 switch( input ) 261 { 262 case ( BUTTON_OK | KN_BUTTON ): 263 cgiReturn.bCreateGame = true; 264 process = false; 265 break; 266 267 case ( BUTTON_CANCEL | KN_BUTTON ): 268 process = false; 269 break; 270 271 case ( GAUGE_PLAYERCOUNT | KN_BUTTON ): 272 if( PlayerCountGauge.Get_Value() != 0 && cgiReturn.bTournament ) 273 { 274 WWMessageBox().Process( TXT_WOL_TOURNAMENTPLAYERLIMIT ); 275 PlayerCountGauge.Set_Value( 0 ); 276 display = true; 277 } 278 cgiReturn.iPlayerMax = PlayerCountGauge.Get_Value() + 2; 279 sprintf( szPlayerCount, TXT_WOL_CG_PLAYERS, cgiReturn.iPlayerMax ); 280 PlayerCountStatic.Set_Text( szPlayerCount ); 281 PlayerCountStatic.Draw_Me(); 282 break; 283 284 case ( CHECK_TOURNAMENT | KN_BUTTON ): 285 cgiReturn.bTournament = TournamentCheck.IsOn; 286 if( cgiReturn.bTournament ) 287 { 288 PlayerCountGauge.Set_Value( 0 ); 289 // PlayerCountGauge.Disable(); 290 cgiReturn.iPlayerMax = 2; 291 sprintf( szPlayerCount, TXT_WOL_CG_PLAYERS, cgiReturn.iPlayerMax ); 292 PlayerCountStatic.Set_Text( szPlayerCount ); 293 PlayerCountStatic.Draw_Me(); 294 } 295 // else 296 // PlayerCountGauge.Enable(); 297 break; 298 299 case ( CHECK_PRIVACY | KN_BUTTON ): 300 cgiReturn.bPrivate = PrivacyCheck.IsOn; 301 break; 302 303 case ( CHECK_RA | KN_BUTTON ): 304 if( RA_Check.IsOn ) 305 { 306 // Box was checked. 307 CS_Check.Turn_Off(); 308 AM_Check.Turn_Off(); 309 cgiReturn.GameKind = CREATEGAMEINFO::RAGAME; 310 } 311 else 312 // Box was unchecked. Has no effect. 313 RA_Check.Turn_On(); 314 break; 315 case ( CHECK_CS | KN_BUTTON ): 316 if( CS_Check.IsOn ) 317 { 318 // Box was checked. 319 RA_Check.Turn_Off(); 320 AM_Check.Turn_Off(); 321 cgiReturn.GameKind = CREATEGAMEINFO::CSGAME; 322 } 323 else 324 // Box was unchecked. Has no effect. 325 CS_Check.Turn_On(); 326 break; 327 case ( CHECK_AM | KN_BUTTON ): 328 if( AM_Check.IsOn ) 329 { 330 // Box was checked. 331 RA_Check.Turn_Off(); 332 CS_Check.Turn_Off(); 333 cgiReturn.GameKind = CREATEGAMEINFO::AMGAME; 334 } 335 else 336 // Box was unchecked. Has no effect. 337 AM_Check.Turn_On(); 338 break; 339 340 default: 341 break; 342 } 343 } 344 345 if( cgiReturn.bCreateGame && cgiReturn.bPrivate ) 346 { 347 // Get a password for the channel. 348 Fancy_Text_Print( TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_TEXT ); // Required before String_Pixel_Width() call, for god's sake. 349 SimpleEditDlgClass* pEditDlg = new SimpleEditDlgClass( 300, TXT_WOL_CREATEPRIVGAMETITLE, 350 TXT_WOL_PASSPROMPT, WOL_CHANKEY_LEN_MAX ); 351 pWO->bPump_In_Call_Back = true; 352 if( strcmp( pEditDlg->Show(), Text_String( TXT_OK ) ) == 0 && *pEditDlg->szEdit ) 353 strcpy( cgiReturn.szPassword, pEditDlg->szEdit ); 354 else 355 cgiReturn.bCreateGame = false; // Cancel creation. 356 pWO->bPump_In_Call_Back = false; 357 } 358 359 return cgiReturn; 360 } 361 362 //*********************************************************************************************** 363 void SetPlayerCountList( IconListClass& PlayerCountList, int iPlayerMax, char* pShpBoxCheck, char* pShpBoxEmpty ) 364 { 365 // Checks appropriate list item based on iPlayerMax. 366 switch( iPlayerMax ) 367 { 368 case 2: 369 PlayerCountList.Set_Icon( 0, 0, (void*)pShpBoxCheck, ICON_SHAPE ); 370 PlayerCountList.Set_Icon( 1, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 371 PlayerCountList.Set_Icon( 2, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 372 break; 373 case 3: 374 PlayerCountList.Set_Icon( 0, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 375 PlayerCountList.Set_Icon( 1, 0, (void*)pShpBoxCheck, ICON_SHAPE ); 376 PlayerCountList.Set_Icon( 2, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 377 break; 378 case 4: 379 PlayerCountList.Set_Icon( 0, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 380 PlayerCountList.Set_Icon( 1, 0, (void*)pShpBoxEmpty, ICON_SHAPE ); 381 PlayerCountList.Set_Icon( 2, 0, (void*)pShpBoxCheck, ICON_SHAPE ); 382 break; 383 } 384 } 385 386 #endif