GAMEDLG.CPP 15 KB

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