WOL_OPT.CPP 6.7 KB

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