WOL_CGAM.CPP 11 KB

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