OINGMENU.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : OINGMENU.H
  21. // Description : in-game menu (async version)
  22. #include <OVGA.h>
  23. #include <OVGABUF.h>
  24. #include <OSYS.h>
  25. #include <OIMGRES.h>
  26. #include <OMOUSE.h>
  27. #include <OMOUSECR.h>
  28. #include <KEY.h>
  29. #include <OPOWER.h>
  30. #include <OBOX.h>
  31. #include <OREMOTE.h>
  32. #include <OTUTOR.h>
  33. #include <ONATIONA.h>
  34. #include <OWORLDMT.h>
  35. #include <OGAME.h>
  36. #include <OOPTMENU.h>
  37. #include <OINGMENU.h>
  38. #include <OFONT.h>
  39. #include <OMUSIC.h>
  40. #ifdef AMPLUS
  41. enum { GAME_MENU_WIDTH = 350,
  42. GAME_MENU_HEIGHT = 400 };
  43. #else
  44. enum { GAME_MENU_WIDTH = 350,
  45. GAME_MENU_HEIGHT = 386 };
  46. #endif
  47. enum { GAME_MENU_X1 = ZOOM_X1 + ( (ZOOM_X2-ZOOM_X1+1) - GAME_MENU_WIDTH ) / 2,
  48. GAME_MENU_Y1 = ZOOM_Y1 + ( (ZOOM_Y2-ZOOM_Y1+1) - GAME_MENU_HEIGHT ) / 2 };
  49. enum { GAME_OPTION_WIDTH = 170,
  50. GAME_OPTION_HEIGHT = 34 };
  51. // ####### begin Gilbert 29/10 #########//
  52. #ifdef AMPLUS
  53. enum { GAME_OPTION_X1 = GAME_MENU_X1+90,
  54. GAME_OPTION_Y1 = GAME_MENU_Y1+93 };
  55. enum { MAP_ID_X1 = GAME_MENU_X1 + 18,
  56. MAP_ID_Y1 = GAME_MENU_Y1 + 362,
  57. MAP_ID_X2 = GAME_MENU_X1 + 330,
  58. MAP_ID_Y2 = GAME_MENU_Y1 + 382 };
  59. #else
  60. enum { GAME_OPTION_X1 = GAME_MENU_X1+90,
  61. GAME_OPTION_Y1 = GAME_MENU_Y1+76 };
  62. enum { MAP_ID_X1 = GAME_MENU_X1 + 18,
  63. MAP_ID_Y1 = GAME_MENU_Y1 + 350,
  64. MAP_ID_X2 = GAME_MENU_X1 + 330,
  65. MAP_ID_Y2 = GAME_MENU_Y1 + 373 };
  66. #endif
  67. // ####### end Gilbert 29/10 #########//
  68. unsigned InGameMenu::menu_hot_key[GAME_OPTION_COUNT] = {'o','s','l', 0,0,0,0,KEY_ESC };
  69. InGameMenu::InGameMenu()
  70. {
  71. active_flag = 0;
  72. }
  73. void InGameMenu::enter(char untilExitFlag)
  74. {
  75. if( active_flag )
  76. return;
  77. refresh_flag = 1;
  78. active_flag = 1;
  79. memset(game_menu_option_flag, 1, sizeof(game_menu_option_flag) );
  80. if( !nation_array.player_recno)
  81. {
  82. // when in observe mode
  83. game_menu_option_flag[1] = 0; // disable save game
  84. game_menu_option_flag[4] = 0; // disable retire
  85. }
  86. if( remote.is_enable() )
  87. {
  88. // when in when in multi-player mode,
  89. game_menu_option_flag[2] = 0; // disable load game
  90. game_menu_option_flag[3] = 0; // disable training
  91. game_menu_option_flag[4] = 0; // disable retire
  92. }
  93. mouse_cursor.set_icon(CURSOR_NORMAL);
  94. power.win_opened = 1;
  95. if( untilExitFlag )
  96. {
  97. while( is_active() )
  98. {
  99. sys.yield();
  100. mouse.get_event();
  101. // display on front buffer
  102. char useBackBuf = vga.use_back_buf;
  103. vga.use_front();
  104. disp();
  105. if(useBackBuf)
  106. vga.use_back();
  107. sys.blt_virtual_buf();
  108. music.yield();
  109. detect();
  110. }
  111. }
  112. }
  113. void InGameMenu::disp(int needRepaint)
  114. {
  115. if( !active_flag )
  116. return;
  117. // since use back buffer, always refresh
  118. if( Vga::use_back_buf || needRepaint )
  119. refresh_flag = 1;
  120. if( refresh_flag )
  121. {
  122. int x=GAME_MENU_X1+20, y=GAME_MENU_Y1+17;
  123. if( Vga::use_back_buf )
  124. image_interface.put_back( GAME_MENU_X1, GAME_MENU_Y1, "GAMEMENU" );
  125. else
  126. image_interface.put_front( GAME_MENU_X1, GAME_MENU_Y1, "GAMEMENU" );
  127. for( int b = 0; b < GAME_OPTION_COUNT; ++b)
  128. {
  129. if( !game_menu_option_flag[b])
  130. {
  131. // darked disabled button
  132. Vga::active_buf->adjust_brightness(
  133. GAME_OPTION_X1, GAME_OPTION_Y1 + b*GAME_OPTION_HEIGHT,
  134. GAME_OPTION_X1+GAME_OPTION_WIDTH-1,
  135. GAME_OPTION_Y1 + (b+1)*GAME_OPTION_HEIGHT-1, -8);
  136. }
  137. }
  138. String str;
  139. #if(defined(SPANISH))
  140. str = "I.D del Mapa: ";
  141. #elif(defined(FRENCH) )
  142. str = "Nº de la carte: ";
  143. #elif(defined(GERMAN))
  144. str = "Karten-I.D.: ";
  145. #else
  146. str = "Map I.D.: ";
  147. #endif
  148. str += info.random_seed;
  149. font_bible.center_put( MAP_ID_X1, MAP_ID_Y1, MAP_ID_X2, MAP_ID_Y2, str);
  150. refresh_flag = 0;
  151. }
  152. }
  153. int InGameMenu::detect()
  154. {
  155. if( !active_flag )
  156. return 0;
  157. int i, y=GAME_OPTION_Y1, x2, y2;
  158. for( i=1 ; i<=GAME_OPTION_COUNT ; i++, y+=GAME_OPTION_HEIGHT )
  159. {
  160. x2 = GAME_OPTION_X1+GAME_OPTION_WIDTH-1;
  161. y2 = y+GAME_OPTION_HEIGHT-1;
  162. if( game_menu_option_flag[i-1] == 1 &&
  163. (menu_hot_key[i-1] && mouse.key_code == menu_hot_key[i-1] ||
  164. mouse.single_click( GAME_OPTION_X1, y, x2, y2 )) )
  165. break;
  166. if( i == GAME_OPTION_COUNT && // assume last option is 'continue'
  167. (mouse.any_click(1) || mouse.key_code==KEY_ESC) )
  168. break;
  169. }
  170. if( i>GAME_OPTION_COUNT )
  171. return 0;
  172. //------ display the pressed down button -----//
  173. vga_front.save_area_common_buf( GAME_OPTION_X1, y, x2, y2 );
  174. image_interface.put_front( GAME_OPTION_X1, y, "MENU-DWN" );
  175. while( mouse.left_press ) // holding down the button
  176. {
  177. sys.yield();
  178. mouse.get_event();
  179. }
  180. vga_front.rest_area_common_buf(); // restore the up button
  181. //--------- run the option -------//
  182. exit(0);
  183. switch(i)
  184. {
  185. case 1: // options
  186. option_menu.enter(!remote.is_enable());
  187. break;
  188. case 2: // save game
  189. sys.save_game();
  190. break;
  191. case 3: // load game
  192. sys.load_game();
  193. break;
  194. case 4: // training
  195. tutor.select_run_tutor(1);
  196. break;
  197. case 5: // retire
  198. if( nation_array.player_recno ) // only when the player's kingdom still exists
  199. {
  200. if( box.ask("Do you really want to retire?", "Yes", "No", 175, 320) )
  201. {
  202. if( remote.is_enable() )
  203. {
  204. // BUGHERE : message will not be sent out
  205. short *shortPtr = (short *)remote.new_send_queue_msg( MSG_PLAYER_QUIT, 2*sizeof(short));
  206. shortPtr[0] = nation_array.player_recno;
  207. shortPtr[1] = 1; // retire
  208. }
  209. game.game_end(0, 0, 0, 1); // 1 - retire
  210. }
  211. }
  212. break;
  213. case 6: // quit to main menu
  214. {
  215. int boxX1;
  216. #ifdef GERMAN
  217. boxX1 = 125;
  218. #else
  219. boxX1 = 115;
  220. #endif
  221. if( !nation_array.player_recno ||
  222. box.ask( "Do you really want to quit to the Main Menu?", "Yes", "No", boxX1, 350 ) )
  223. {
  224. if( remote.is_enable() && nation_array.player_recno )
  225. {
  226. // BUGHERE : message will not be sent out
  227. short *shortPtr = (short *)remote.new_send_queue_msg( MSG_PLAYER_QUIT, 2*sizeof(short));
  228. shortPtr[0] = nation_array.player_recno;
  229. shortPtr[1] = 0; // not retire
  230. }
  231. sys.signal_exit_flag = 2;
  232. }
  233. break;
  234. }
  235. case 7: // quit to Windows
  236. if( !nation_array.player_recno ||
  237. box.ask( "Do you really want to quit to Windows?", "Yes", "No", 130, 400 ) )
  238. {
  239. if( remote.is_enable() && nation_array.player_recno )
  240. {
  241. // BUGHERE : message will not be sent out
  242. short *shortPtr = (short *)remote.new_send_queue_msg( MSG_PLAYER_QUIT, 2*sizeof(short));
  243. shortPtr[0] = nation_array.player_recno;
  244. shortPtr[1] = 1; // retire
  245. }
  246. sys.signal_exit_flag = 1;
  247. }
  248. break;
  249. }
  250. return 1;
  251. }
  252. void InGameMenu::exit(int action)
  253. {
  254. power.win_opened = 0;
  255. active_flag = 0;
  256. }
  257. void InGameMenu::abort()
  258. {
  259. power.win_opened = 0;
  260. active_flag = 0;
  261. }