GAMEDLG.CPP 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. /* $Header: /CounterStrike/GAMEDLG.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : GAMEDLG.CPP *
  22. * *
  23. * Programmer : Maria del Mar McCready Legg, Joe L. Bostic *
  24. * *
  25. * Start Date : Jan 8, 1995 *
  26. * *
  27. * Last Update : Jan 18, 1995 [MML] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * OptionsClass::Process -- Handles all the options graphic interface. *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #include "function.h"
  34. #include "gamedlg.h"
  35. #include "sounddlg.h"
  36. #include "visudlg.h"
  37. #define GERMAN_OFFSET_Y 4 //VG
  38. #ifdef WOLAPI_INTEGRATION
  39. #include "WolStrng.h"
  40. #include "WolapiOb.h"
  41. extern WolapiObject* pWolapi;
  42. bool WOL_Options_Dialog( WolapiObject* pWO, bool bCalledFromGame );
  43. #endif
  44. /***********************************************************************************************
  45. * OptionsClass::Process -- Handles all the options graphic interface. *
  46. * *
  47. * This routine is the main control for the visual representation of the options *
  48. * screen. It handles the visual overlay and the player input. *
  49. * *
  50. * INPUT: none *
  51. * OUTPUT: none *
  52. * WARNINGS: none *
  53. * HISTORY: *
  54. * 12/31/1994 MML : Created. *
  55. *=============================================================================================*/
  56. void GameControlsClass::Process(void)
  57. {
  58. /*
  59. ** Dialog & button dimensions
  60. */
  61. int d_dialog_w = 232 * RESFACTOR; // dialog width
  62. int d_dialog_h = 141 * RESFACTOR; // dialog height
  63. int d_dialog_x = ((SeenBuff.Get_Width() - d_dialog_w) / 2); // dialog x-coord
  64. int d_dialog_y = ((SeenBuff.Get_Height() - d_dialog_h) / 2); // centered y-coord
  65. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  66. int d_top_margin = 25 * RESFACTOR;
  67. int d_txt6_h = (6 * RESFACTOR) + 1; // ht of 6-pt text
  68. int d_margin1 = (5 * RESFACTOR); // large margin
  69. int d_margin2 = (2 * RESFACTOR); // small margin
  70. int d_speed_w = d_dialog_w - (34 * RESFACTOR);
  71. int d_speed_h = 6 * RESFACTOR;
  72. int d_speed_x = d_dialog_x + (17 * RESFACTOR);
  73. #ifdef GERMAN
  74. int d_speed_y = d_dialog_y + d_top_margin + d_margin1 + d_txt6_h - GERMAN_OFFSET_Y;
  75. #else
  76. int d_speed_y = d_dialog_y + d_top_margin + d_margin1 + d_txt6_h;
  77. #endif
  78. int d_scroll_w = d_dialog_w - (34 * RESFACTOR);
  79. int d_scroll_h = 6 * RESFACTOR;
  80. int d_scroll_x = d_dialog_x + (17 * RESFACTOR);
  81. #ifdef GERMAN
  82. int d_scroll_y = d_speed_y + d_speed_h + d_txt6_h + (d_margin1 * 2) + d_txt6_h - GERMAN_OFFSET_Y;
  83. #else
  84. int d_scroll_y = d_speed_y + d_speed_h + d_txt6_h + (d_margin1 * 2) + d_txt6_h;
  85. #endif
  86. int d_visual_w = d_dialog_w - (40 * RESFACTOR);
  87. int d_visual_h = 9 * RESFACTOR;
  88. int d_visual_x = d_dialog_x + (20 * RESFACTOR);
  89. int d_visual_y = d_scroll_y + d_scroll_h + d_txt6_h + (d_margin1 * 2);
  90. int d_sound_w = d_dialog_w - (40 * RESFACTOR);
  91. int d_sound_h = (9 * RESFACTOR);
  92. int d_sound_x = d_dialog_x + (20 * RESFACTOR);
  93. int d_sound_y = d_visual_y + d_visual_h + d_margin1;
  94. int d_ok_w = 20 * RESFACTOR;
  95. int d_ok_h = 9 * RESFACTOR;
  96. int d_ok_x = d_dialog_cx - (d_ok_w / 2);
  97. int d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin1 - (4 * RESFACTOR);
  98. #ifdef WOLAPI_INTEGRATION
  99. int d_wol_x = d_sound_x;
  100. int d_wol_y = d_sound_y + d_sound_h + d_margin1;
  101. int d_wol_w = d_sound_w;
  102. int d_wol_h = d_sound_h;
  103. bool bShowWolapi = ( pWolapi && !pWolapi->bConnectionDown );
  104. if( bShowWolapi )
  105. {
  106. // Enlarge dialog and shift ok button down.
  107. d_dialog_h += d_wol_h + d_margin1;
  108. d_dialog_y = ((SeenBuff.Get_Height() - d_dialog_h) / 2); // centered y-coord
  109. //d_ok_y += d_wol_h + d_margin1;
  110. d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin1 - (4 * RESFACTOR);
  111. }
  112. #endif
  113. /*
  114. ** Button Enumerations
  115. */
  116. #ifdef WOLAPI_INTEGRATION
  117. enum {
  118. BUTTON_SPEED = 100,
  119. BUTTON_SCROLLRATE,
  120. BUTTON_VISUAL,
  121. BUTTON_SOUND,
  122. BUTTON_WOLAPI,
  123. BUTTON_OK,
  124. BUTTON_COUNT,
  125. BUTTON_FIRST = BUTTON_SPEED,
  126. };
  127. #else
  128. enum {
  129. BUTTON_SPEED = 100,
  130. BUTTON_SCROLLRATE,
  131. BUTTON_VISUAL,
  132. BUTTON_SOUND,
  133. BUTTON_OK,
  134. BUTTON_COUNT,
  135. BUTTON_FIRST = BUTTON_SPEED,
  136. };
  137. #endif
  138. /*
  139. ** Dialog variables
  140. */
  141. KeyNumType input;
  142. int gamespeed = Options.GameSpeed;
  143. int scrollrate = Options.ScrollRate;
  144. int selection;
  145. bool pressed = false;
  146. int curbutton = 0;
  147. TextButtonClass *buttons[BUTTON_COUNT - BUTTON_FIRST];
  148. TextPrintType style;
  149. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  150. /*
  151. ** Buttons
  152. */
  153. GadgetClass * commands; // button list
  154. SliderClass gspeed_btn(BUTTON_SPEED, d_speed_x, d_speed_y, d_speed_w, d_speed_h, true);
  155. SliderClass scrate_btn(BUTTON_SCROLLRATE, d_scroll_x, d_scroll_y, d_scroll_w, d_scroll_h, true);
  156. TextButtonClass visual_btn(BUTTON_VISUAL, TXT_VISUAL_CONTROLS, TPF_BUTTON, d_visual_x, d_visual_y, d_visual_w, d_visual_h);
  157. TextButtonClass sound_btn(BUTTON_SOUND, TXT_SOUND_CONTROLS, TPF_BUTTON, d_sound_x, d_sound_y, d_sound_w, d_sound_h);
  158. TextButtonClass okbtn(BUTTON_OK, TXT_OPTIONS_MENU, TPF_BUTTON, d_ok_x, d_ok_y);
  159. okbtn.X = (SeenBuff.Get_Width()-okbtn.Width)/2;
  160. #ifdef WOLAPI_INTEGRATION
  161. TextButtonClass wol_btn( BUTTON_WOLAPI, TXT_WOL_OPTTITLE, TPF_BUTTON, d_wol_x, d_wol_y, d_wol_w, d_wol_h );
  162. #endif
  163. /*
  164. ** Various Inits.
  165. */
  166. Set_Logic_Page(SeenBuff);
  167. /*
  168. ** Build button list
  169. */
  170. commands = &okbtn;
  171. gspeed_btn.Add_Tail(*commands);
  172. scrate_btn.Add_Tail(*commands);
  173. visual_btn.Add_Tail(*commands);
  174. sound_btn.Add_Tail(*commands);
  175. #ifdef WOLAPI_INTEGRATION
  176. if( bShowWolapi )
  177. wol_btn.Add_Tail(*commands);
  178. #endif
  179. /*
  180. ** Init button states
  181. ** For sliders, the thumb ranges from 0 - (maxval-1), so to convert the
  182. ** thumb value to a real-world value:
  183. ** val = (MAX - slider.Get_Value()) - 1;
  184. ** and,
  185. ** slider.Set_Value(-(val + 1 - MAX));
  186. */
  187. gspeed_btn.Set_Maximum(OptionsClass::MAX_SPEED_SETTING); // varies from 0 - 7
  188. gspeed_btn.Set_Thumb_Size(1);
  189. gspeed_btn.Set_Value((OptionsClass::MAX_SPEED_SETTING-1) - gamespeed);
  190. scrate_btn.Set_Maximum(OptionsClass::MAX_SCROLL_SETTING); // varies from 0 - 7
  191. scrate_btn.Set_Thumb_Size(1);
  192. scrate_btn.Set_Value((OptionsClass::MAX_SCROLL_SETTING-1) - scrollrate);
  193. /*
  194. ** Fill array of button ptrs.
  195. */
  196. buttons[0] = NULL;
  197. buttons[1] = NULL;
  198. buttons[2] = &visual_btn;
  199. buttons[3] = &sound_btn;
  200. #ifdef WOLAPI_INTEGRATION
  201. buttons[4] = &wol_btn;
  202. buttons[5] = &okbtn;
  203. #else
  204. buttons[4] = &okbtn;
  205. #endif
  206. /*
  207. ** Processing loop.
  208. */
  209. bool process = true;
  210. bool display = true;
  211. bool refresh = true;
  212. while (process) {
  213. /*
  214. ** Invoke game callback.
  215. */
  216. if (Session.Type == GAME_NORMAL || Session.Type == GAME_SKIRMISH) {
  217. Call_Back();
  218. } else {
  219. if (Main_Loop()) {
  220. process = false;
  221. }
  222. }
  223. #ifdef WIN32
  224. /*
  225. ** If we have just received input focus again after running in the background then
  226. ** we need to redraw.
  227. */
  228. if (AllSurfaces.SurfacesRestored) {
  229. AllSurfaces.SurfacesRestored=FALSE;
  230. display = true;
  231. }
  232. #endif
  233. /*
  234. ** Refresh display if needed.
  235. */
  236. if (display) {
  237. Hide_Mouse();
  238. Map.Flag_To_Redraw(true);
  239. Map.Render();
  240. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  241. Draw_Caption(TXT_GAME_CONTROLS, d_dialog_x, d_dialog_y, d_dialog_w);
  242. Show_Mouse();
  243. display = false;
  244. refresh = true;
  245. }
  246. if (refresh) {
  247. Hide_Mouse();
  248. /*
  249. ** Label the game speed slider
  250. */
  251. style = TPF_TEXT;
  252. if (curbutton == (BUTTON_SPEED - BUTTON_FIRST)) {
  253. style = (TextPrintType)(style | TPF_BRIGHT_COLOR);
  254. }
  255. Fancy_Text_Print(TXT_SPEED, d_speed_x, d_speed_y - d_txt6_h, scheme, TBLACK, style);
  256. Fancy_Text_Print(TXT_SLOWER, d_speed_x, d_speed_y + d_speed_h + (1 * RESFACTOR), scheme, TBLACK, TPF_TEXT);
  257. Fancy_Text_Print(TXT_FASTER, d_speed_x + d_speed_w, d_speed_y + d_speed_h + (1 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  258. /*
  259. ** Label the scroll rate slider
  260. */
  261. style = TPF_TEXT;
  262. if (curbutton == (BUTTON_SCROLLRATE - BUTTON_FIRST)) {
  263. style = (TextPrintType)(style | TPF_BRIGHT_COLOR);
  264. }
  265. Fancy_Text_Print(TXT_SCROLLRATE, d_scroll_x, d_scroll_y - d_txt6_h, scheme, TBLACK, style);
  266. Fancy_Text_Print (TXT_SLOWER, d_scroll_x, d_scroll_y + d_scroll_h + (1 * RESFACTOR), scheme, TBLACK, TPF_TEXT);
  267. Fancy_Text_Print (TXT_FASTER, d_scroll_x + d_scroll_w, d_scroll_y + d_scroll_h + (1 * RESFACTOR), scheme, TBLACK, TPF_TEXT|TPF_RIGHT);
  268. commands->Draw_All();
  269. Show_Mouse();
  270. refresh = false;
  271. }
  272. /*
  273. ** Get user input.
  274. */
  275. input = commands->Input();
  276. /*
  277. ** Process input.
  278. */
  279. switch (input) {
  280. case (BUTTON_SPEED | KN_BUTTON):
  281. curbutton = (BUTTON_SPEED - BUTTON_FIRST);
  282. refresh = true;
  283. break;
  284. case (BUTTON_SCROLLRATE | KN_BUTTON):
  285. curbutton = (BUTTON_SCROLLRATE - BUTTON_FIRST);
  286. refresh = true;
  287. break;
  288. case (BUTTON_VISUAL | KN_BUTTON):
  289. selection = BUTTON_VISUAL;
  290. pressed = true;
  291. break;
  292. case (BUTTON_SOUND | KN_BUTTON):
  293. selection = BUTTON_SOUND;
  294. pressed = true;
  295. break;
  296. case (BUTTON_OK | KN_BUTTON):
  297. selection = BUTTON_OK;
  298. pressed = true;
  299. break;
  300. #ifdef WOLAPI_INTEGRATION
  301. case (BUTTON_WOLAPI | KN_BUTTON):
  302. selection = BUTTON_WOLAPI;
  303. pressed = true;
  304. break;
  305. #endif
  306. case (KN_ESC):
  307. process = false;
  308. break;
  309. case (KN_LEFT):
  310. if (curbutton == (BUTTON_SPEED - BUTTON_FIRST) ) {
  311. gspeed_btn.Bump(1);
  312. } else
  313. if (curbutton == (BUTTON_SCROLLRATE - BUTTON_FIRST) ) {
  314. scrate_btn.Bump(1);
  315. }
  316. break;
  317. case (KN_RIGHT):
  318. if (curbutton == (BUTTON_SPEED - BUTTON_FIRST) ) {
  319. gspeed_btn.Bump(0);
  320. } else
  321. if (curbutton == (BUTTON_SCROLLRATE - BUTTON_FIRST) ) {
  322. scrate_btn.Bump(0);
  323. }
  324. break;
  325. case (KN_UP):
  326. if (buttons[curbutton]) {
  327. buttons[curbutton]->Turn_Off();
  328. buttons[curbutton]->Flag_To_Redraw();
  329. }
  330. curbutton--;
  331. #ifdef WOLAPI_INTEGRATION
  332. if( !bShowWolapi )
  333. {
  334. if( curbutton == BUTTON_WOLAPI - BUTTON_FIRST )
  335. curbutton--; // Skip over missing button.
  336. }
  337. #endif
  338. if (curbutton < 0) {
  339. curbutton = (BUTTON_COUNT - BUTTON_FIRST - 1);
  340. }
  341. if (buttons[curbutton]) {
  342. buttons[curbutton]->Turn_On();
  343. buttons[curbutton]->Flag_To_Redraw();
  344. }
  345. refresh = true;
  346. break;
  347. case (KN_DOWN):
  348. if (buttons[curbutton]) {
  349. buttons[curbutton]->Turn_Off();
  350. buttons[curbutton]->Flag_To_Redraw();
  351. }
  352. curbutton++;
  353. #ifdef WOLAPI_INTEGRATION
  354. if( !bShowWolapi )
  355. {
  356. if( curbutton == BUTTON_WOLAPI - BUTTON_FIRST )
  357. curbutton++; // Skip over missing button.
  358. }
  359. #endif
  360. if (curbutton > (BUTTON_COUNT - BUTTON_FIRST - 1) ) {
  361. curbutton = 0;
  362. }
  363. if (buttons[curbutton]) {
  364. buttons[curbutton]->Turn_On();
  365. buttons[curbutton]->Flag_To_Redraw();
  366. }
  367. refresh = true;
  368. break;
  369. case (KN_RETURN):
  370. selection = curbutton + BUTTON_FIRST;
  371. pressed = true;
  372. break;
  373. default:
  374. break;
  375. }
  376. /*
  377. ** Perform some action. Either to exit the dialog or bring up another.
  378. */
  379. if (pressed) {
  380. /*
  381. ** Record the new options slider settings.
  382. ** The GameSpeed data member MUST NOT BE SET HERE! It will cause multiplayer
  383. ** games to go out of sync. It's set by virtue of the event being executed.
  384. */
  385. if (gamespeed != ((OptionsClass::MAX_SPEED_SETTING-1) - gspeed_btn.Get_Value()) ) {
  386. gamespeed = (OptionsClass::MAX_SPEED_SETTING-1) - gspeed_btn.Get_Value();
  387. OutList.Add(EventClass(EventClass::GAMESPEED, gamespeed));
  388. }
  389. if (scrollrate != ((OptionsClass::MAX_SCROLL_SETTING-1) - scrate_btn.Get_Value()) ) {
  390. scrollrate = (OptionsClass::MAX_SCROLL_SETTING-1) - scrate_btn.Get_Value();
  391. Options.ScrollRate = scrollrate;
  392. }
  393. process = false;
  394. /*
  395. ** Save the settings in such a way that the GameSpeed is only set during
  396. ** the save process; restore it when we're done, so multiplayer games don't
  397. ** go out of sync.
  398. */
  399. if (Session.Type == GAME_NORMAL) {
  400. Options.GameSpeed = gamespeed;
  401. Options.Save_Settings(); // save new value
  402. } else {
  403. int old = Options.GameSpeed; // save orig value
  404. Options.GameSpeed = gamespeed;
  405. Options.Save_Settings(); // save new value
  406. Options.GameSpeed = old; // restore old value
  407. }
  408. /*
  409. ** Possibly launch into another dialog if so directed.
  410. */
  411. switch (selection) {
  412. case (BUTTON_VISUAL):
  413. VisualControlsClass().Process();
  414. process = true;
  415. display = true;
  416. refresh = true;
  417. break;
  418. case (BUTTON_SOUND):
  419. if (!SoundType) {
  420. WWMessageBox().Process(Text_String(TXT_NO_SOUND_CARD));
  421. process = true;
  422. display = true;
  423. refresh = true;
  424. } else {
  425. SoundControlsClass().Process();
  426. process = true;
  427. display = true;
  428. refresh = true;
  429. }
  430. break;
  431. #ifdef WOLAPI_INTEGRATION
  432. case BUTTON_WOLAPI:
  433. if( WOL_Options_Dialog( pWolapi, true ) )
  434. {
  435. // The game ended while in this dialog.
  436. process = false;
  437. }
  438. else
  439. {
  440. process = true;
  441. display = true;
  442. refresh = true;
  443. }
  444. break;
  445. #endif
  446. case (BUTTON_OK):
  447. break;
  448. }
  449. pressed = false;
  450. }
  451. }
  452. }