CONFDLG.CPP 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. ** Command & Conquer(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&c\vcs\code\confdlg.cpv 2.17 16 Oct 1995 16:49: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. * OUTPUT: none *
  51. * WARNINGS: none *
  52. * HISTORY: 12/31/1994 MML : Created. *
  53. *=============================================================================================*/
  54. bool ConfirmationClass::Process(char const * string)
  55. {
  56. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  57. enum {
  58. NUM_OF_BUTTONS = 2
  59. };
  60. char buffer[80*3];
  61. int result = true;
  62. int width;
  63. int bwidth, bheight; // button width and height
  64. int height;
  65. int selection;
  66. bool pressed;
  67. int curbutton;
  68. TextButtonClass *buttons[NUM_OF_BUTTONS];
  69. /*
  70. ** Set up the window. Window x-coords are in bytes not pixels.
  71. */
  72. strcpy(buffer, string);
  73. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  74. Format_Window_String(buffer, 200*factor, width, height);
  75. width += 60*factor;
  76. height += 60*factor;
  77. int x = (320*factor - width) / 2;
  78. int y = (200*factor - height) / 2;
  79. Set_Logic_Page(SeenBuff);
  80. /*
  81. ** Create Buttons. Button coords are in pixels, but are window-relative.
  82. */
  83. bheight = FontHeight + FontYSpacing + 2;
  84. bwidth = MAX( (String_Pixel_Width( Text_String( TXT_YES ) ) + 8), 30);
  85. TextButtonClass yesbtn(BUTTON_YES, TXT_YES,
  86. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  87. x + 10*factor, y + height - (bheight + 5*factor), bwidth );
  88. TextButtonClass nobtn(BUTTON_NO, TXT_NO,
  89. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  90. x + width - (bwidth + 10*factor),
  91. y + height - (bheight + 5*factor), bwidth );
  92. nobtn.Add_Tail(yesbtn);
  93. curbutton = 1;
  94. buttons[0] = &yesbtn;
  95. buttons[1] = &nobtn;
  96. buttons[curbutton]->Turn_On();
  97. /*
  98. ** This causes left mouse button clicking within the confines of the dialog to
  99. ** be ignored if it wasn't recognized by any other button or slider.
  100. */
  101. GadgetClass dialog(x, y, width, height, GadgetClass::LEFTPRESS);
  102. dialog.Add_Tail(yesbtn);
  103. /*
  104. ** This causes a right click anywhere or a left click outside the dialog region
  105. ** to be equivalent to clicking on the return to options dialog.
  106. */
  107. ControlClass background(BUTTON_NO, 0, 0, SeenBuff.Get_Width(), SeenBuff.Get_Height(), GadgetClass::LEFTPRESS|GadgetClass::RIGHTPRESS);
  108. background.Add_Tail(yesbtn);
  109. /*
  110. ** Main Processing Loop.
  111. */
  112. bool display = true;
  113. bool process = true;
  114. pressed = false;
  115. while (process) {
  116. /*
  117. ** Invoke game callback.
  118. */
  119. if (GameToPlay == GAME_NORMAL) {
  120. Call_Back();
  121. } else {
  122. if (Main_Loop()) {
  123. process = false;
  124. result = false;
  125. }
  126. }
  127. /*
  128. ** If we have just received input focus again after running in the background then
  129. ** we need to redraw.
  130. */
  131. if (AllSurfaces.SurfacesRestored){
  132. AllSurfaces.SurfacesRestored=FALSE;
  133. display=TRUE;
  134. }
  135. /*
  136. ** Refresh display if needed.
  137. */
  138. if (display) {
  139. Hide_Mouse();
  140. /*
  141. ** Draw the background.
  142. */
  143. Dialog_Box(x, y, width, height);
  144. Draw_Caption(TXT_CONFIRMATION, x, y, width);
  145. Fancy_Text_Print(buffer, x+20*factor, y+30*factor, CC_GREEN, TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_NOSHADOW);
  146. /*
  147. ** Draw the titles.
  148. */
  149. yesbtn.Draw_All();
  150. Show_Mouse();
  151. display = false;
  152. }
  153. /*
  154. ** Get user input.
  155. */
  156. KeyNumType input = yesbtn.Input();
  157. /*
  158. ** Process Input.
  159. */
  160. switch (input) {
  161. case (BUTTON_YES | KN_BUTTON):
  162. selection = BUTTON_YES;
  163. pressed = true;
  164. break;
  165. case (KN_ESC):
  166. case (BUTTON_NO | KN_BUTTON):
  167. selection = BUTTON_NO;
  168. pressed = true;
  169. break;
  170. case (KN_LEFT):
  171. buttons[curbutton]->Turn_Off();
  172. buttons[curbutton]->Flag_To_Redraw();
  173. curbutton--;
  174. if (curbutton < 0) {
  175. curbutton = NUM_OF_BUTTONS - 1;
  176. }
  177. buttons[curbutton]->Turn_On();
  178. buttons[curbutton]->Flag_To_Redraw();
  179. break;
  180. case (KN_RIGHT):
  181. buttons[curbutton]->Turn_Off();
  182. buttons[curbutton]->Flag_To_Redraw();
  183. curbutton++;
  184. if (curbutton > (NUM_OF_BUTTONS - 1) ) {
  185. curbutton = 0;
  186. }
  187. buttons[curbutton]->Turn_On();
  188. buttons[curbutton]->Flag_To_Redraw();
  189. break;
  190. case (KN_RETURN):
  191. selection = curbutton + BUTTON_YES;
  192. pressed = true;
  193. break;
  194. default:
  195. break;
  196. }
  197. if (pressed) {
  198. switch (selection) {
  199. case (BUTTON_YES):
  200. result = true;
  201. process = false;
  202. break;
  203. case (BUTTON_NO):
  204. result = false;
  205. process = false;
  206. break;
  207. }
  208. pressed = false;
  209. }
  210. }
  211. return(result);
  212. }