WOL_CGAM.CPP 11 KB

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