WOL_OPT.CPP 6.6 KB

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