CONFDLG.CPP 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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: F:\projects\c&c0\vcs\code\confdlg.cpv 4.67 27 Aug 1996 15:46:52 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 : CONFDLG.CPP *
  26. * *
  27. * Programmer : Maria del Mar McCready Legg *
  28. * Joe L. Bostic *
  29. * *
  30. * Start Date : Jan 30, 1995 *
  31. * *
  32. * Last Update : Jan 30, 1995 [MML] *
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * ConfirmationClass::Process -- Handles all the options graphic interface. *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "function.h"
  39. #include "confdlg.h"
  40. bool ConfirmationClass::Process(int text)
  41. {
  42. return(Process(Text_String(text)));
  43. }
  44. /***********************************************************************************************
  45. * ConfirmationClass::Process -- Handles all the options graphic interface. *
  46. * *
  47. * This dialog uses an edit box to confirm a deletion. *
  48. * *
  49. * INPUT: char * string - display in edit box. *
  50. * *
  51. * OUTPUT: none *
  52. * *
  53. * WARNINGS: none *
  54. * *
  55. * HISTORY: 12/31/1994 MML : Created. *
  56. *=============================================================================================*/
  57. bool ConfirmationClass::Process(char const * string)
  58. {
  59. enum {
  60. NUM_OF_BUTTONS = 2
  61. };
  62. char buffer[80*3];
  63. int result = true;
  64. int width;
  65. int bwidth, bheight; // button width and height
  66. int height;
  67. int selection = 0;
  68. bool pressed;
  69. int curbutton;
  70. TextButtonClass * buttons[NUM_OF_BUTTONS];
  71. /*
  72. ** Set up the window. Window x-coords are in bytes not pixels.
  73. */
  74. strcpy(buffer, string);
  75. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_6PT_GRAD | TPF_NOSHADOW);
  76. Format_Window_String(buffer, 200, width, height);
  77. width += 60;
  78. height += 60;
  79. int x = (320 - width) / 2;
  80. int y = (200 - height) / 2;
  81. Set_Logic_Page(SeenBuff);
  82. /*
  83. ** Create Buttons. Button coords are in pixels, but are window-relative.
  84. */
  85. bheight = FontHeight + FontYSpacing + 2;
  86. bwidth = max( (String_Pixel_Width( Text_String( TXT_YES ) ) + 8), 30);
  87. TextButtonClass yesbtn(BUTTON_YES, TXT_YES,
  88. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  89. x + 10, y + height - (bheight + 5), bwidth );
  90. TextButtonClass nobtn(BUTTON_NO, TXT_NO,
  91. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  92. x + width - (bwidth + 10),
  93. y + height - (bheight + 5), bwidth );
  94. nobtn.Add_Tail(yesbtn);
  95. curbutton = 1;
  96. buttons[0] = &yesbtn;
  97. buttons[1] = &nobtn;
  98. buttons[curbutton]->Turn_On();
  99. /*
  100. ** This causes left mouse button clicking within the confines of the dialog to
  101. ** be ignored if it wasn't recognized by any other button or slider.
  102. */
  103. GadgetClass dialog(x, y, width, height, GadgetClass::LEFTPRESS);
  104. dialog.Add_Tail(yesbtn);
  105. /*
  106. ** This causes a right click anywhere or a left click outside the dialog region
  107. ** to be equivalent to clicking on the return to options dialog.
  108. */
  109. ControlClass background(BUTTON_NO, 0, 0, 320, 200, GadgetClass::LEFTPRESS|GadgetClass::RIGHTPRESS);
  110. background.Add_Tail(yesbtn);
  111. /*
  112. ** Main Processing Loop.
  113. */
  114. bool display = true;
  115. bool process = true;
  116. pressed = false;
  117. while (process) {
  118. /*
  119. ** Invoke game callback.
  120. */
  121. if (Session.Type == GAME_NORMAL) {
  122. Call_Back();
  123. } else {
  124. if (Main_Loop()) {
  125. process = false;
  126. result = false;
  127. }
  128. }
  129. /*
  130. ** Refresh display if needed.
  131. */
  132. if (display) {
  133. Hide_Mouse();
  134. /*
  135. ** Draw the background.
  136. */
  137. Dialog_Box(x, y, width, height);
  138. Draw_Caption(TXT_CONFIRMATION, x, y, width);
  139. Fancy_Text_Print(buffer, x+20, y+30, GadgetClass::Get_Color_Scheme(), TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  140. /*
  141. ** Draw the titles.
  142. */
  143. yesbtn.Draw_All();
  144. Show_Mouse();
  145. display = false;
  146. }
  147. /*
  148. ** Get user input.
  149. */
  150. KeyNumType input = yesbtn.Input();
  151. /*
  152. ** Process Input.
  153. */
  154. switch (input) {
  155. case KeyNumType(BUTTON_YES | KN_BUTTON):
  156. selection = BUTTON_YES;
  157. pressed = true;
  158. break;
  159. case (KN_ESC):
  160. case KeyNumType(BUTTON_NO | KN_BUTTON):
  161. selection = BUTTON_NO;
  162. pressed = true;
  163. break;
  164. case (KN_LEFT):
  165. buttons[curbutton]->Turn_Off();
  166. buttons[curbutton]->Flag_To_Redraw();
  167. curbutton--;
  168. if (curbutton < 0) {
  169. curbutton = NUM_OF_BUTTONS - 1;
  170. }
  171. buttons[curbutton]->Turn_On();
  172. buttons[curbutton]->Flag_To_Redraw();
  173. break;
  174. case (KN_RIGHT):
  175. buttons[curbutton]->Turn_Off();
  176. buttons[curbutton]->Flag_To_Redraw();
  177. curbutton++;
  178. if (curbutton > (NUM_OF_BUTTONS - 1) ) {
  179. curbutton = 0;
  180. }
  181. buttons[curbutton]->Turn_On();
  182. buttons[curbutton]->Flag_To_Redraw();
  183. break;
  184. case (KN_RETURN):
  185. selection = curbutton + BUTTON_YES;
  186. pressed = true;
  187. break;
  188. default:
  189. break;
  190. }
  191. if (pressed) {
  192. switch (selection) {
  193. case (BUTTON_YES):
  194. result = true;
  195. process = false;
  196. break;
  197. case (BUTTON_NO):
  198. result = false;
  199. process = false;
  200. break;
  201. default:
  202. break;
  203. }
  204. pressed = false;
  205. }
  206. }
  207. return(result);
  208. }