OGAMMENU.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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 : OGAMMENU.CPP
  21. //Description: In Game Menu
  22. #include <KEY.h>
  23. #include <OVGA.h>
  24. #include <OSYS.h>
  25. #include <OMOUSE.h>
  26. #include <OMOUSECR.h>
  27. #include <OPOWER.h>
  28. #include <OBOX.h>
  29. #include <OFONT.h>
  30. #include <OIMGRES.h>
  31. #include <OINFO.h>
  32. #include <OGAME.h>
  33. #include <OGFILE.h>
  34. #include <OCONFIG.h>
  35. #include <ORACERES.h>
  36. #include <OBUTT3D.h>
  37. #include <OBUTTCUS.h>
  38. #include <OCOLTBL.h>
  39. #include <OMUSIC.h>
  40. #include <OSLIDCUS.h>
  41. #include <OAUDIO.h>
  42. #include <OREMOTE.h>
  43. #include <OTUTOR.h>
  44. #include <OOPTMENU.h>
  45. //--------- Define Constant ----------//
  46. enum { GAME_MENU_WIDTH = 350,
  47. GAME_MENU_HEIGHT = 386 };
  48. enum { GAME_MENU_X1 = ZOOM_X1 + ( (ZOOM_X2-ZOOM_X1+1) - GAME_MENU_WIDTH ) / 2,
  49. GAME_MENU_Y1 = ZOOM_Y1 + ( (ZOOM_Y2-ZOOM_Y1+1) - GAME_MENU_HEIGHT ) / 2 };
  50. enum { GAME_OPTION_WIDTH = 170,
  51. GAME_OPTION_HEIGHT = 34 };
  52. // ####### begin Gilbert 29/10 #########//
  53. enum { GAME_OPTION_X1 = GAME_MENU_X1+90,
  54. GAME_OPTION_Y1 = GAME_MENU_Y1+76 };
  55. enum { MAP_ID_X1 = GAME_MENU_X1 + 18,
  56. MAP_ID_Y1 = GAME_MENU_Y1 + 352 };
  57. // ####### end Gilbert 29/10 #########//
  58. enum { GAME_OPTION_COUNT = 8 };
  59. static char game_menu_option_flag[GAME_OPTION_COUNT];
  60. static unsigned menu_hot_key[GAME_OPTION_COUNT] = {'o','s','l', 0,0,0,0,KEY_ESC };
  61. //------- Define static functions -------//
  62. static void init_game_menu_option_flag();
  63. static int detect_game_option();
  64. static int slide_to_percent_volume(int);
  65. static int percent_to_slide_volume(int);
  66. //------- Begin of function Game::in_game_menu -------//
  67. void Game::in_game_menu()
  68. {
  69. int x=GAME_MENU_X1+20, y=GAME_MENU_Y1+17;
  70. // vga_back.adjust_brightness( x, y, x+GAME_MENU_WIDTH-1, y+GAME_MENU_HEIGHT-1, -6 );
  71. // vga.blt_buf( x, y, x+GAME_MENU_WIDTH-1, y+GAME_MENU_HEIGHT-1, 0 );
  72. image_interface.put_front( GAME_MENU_X1, GAME_MENU_Y1, "GAMEMENU" );
  73. init_game_menu_option_flag();
  74. for( int b = 0; b < GAME_OPTION_COUNT; ++b)
  75. {
  76. if( !game_menu_option_flag[b])
  77. {
  78. // darked disabled button
  79. vga_front.adjust_brightness(
  80. GAME_OPTION_X1, GAME_OPTION_Y1 + b*GAME_OPTION_HEIGHT,
  81. GAME_OPTION_X1+GAME_OPTION_WIDTH-1,
  82. GAME_OPTION_Y1 + (b+1)*GAME_OPTION_HEIGHT-1, -8);
  83. }
  84. }
  85. // ####### begin Gilbert 29/10 #########//
  86. int textX;
  87. textX = font_bible.put( MAP_ID_X1, MAP_ID_Y1, "Map Id : ");
  88. textX = font_bible.put( textX, MAP_ID_Y1, info.random_seed);
  89. // ####### end Gilbert 29/10 #########//
  90. mouse_cursor.set_icon(CURSOR_NORMAL);
  91. power.win_opened = 1;
  92. while(1)
  93. {
  94. //---------- yield --------//
  95. sys.yield();
  96. mouse.get_event();
  97. sys.blt_virtual_buf();
  98. // ------- play music --------//
  99. int oldSongId = music.song_id;
  100. if( config.music_flag )
  101. {
  102. if( !music.is_playing() )
  103. music.play(music.random_bgm_track(oldSongId), sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  104. }
  105. else
  106. {
  107. // stop any music playing
  108. music.stop();
  109. }
  110. //----- detect options ------//
  111. if( detect_game_option() )
  112. break;
  113. //----- right click or ESC to quit -----//
  114. if( mouse.any_click(1) || mouse.key_code==KEY_ESC )
  115. break;
  116. }
  117. power.win_opened = 0;
  118. }
  119. //-------- End of function Game::in_game_menu --------//
  120. // ------- Begin of static function init_game_menu_option_flag -----//
  121. static void init_game_menu_option_flag()
  122. {
  123. memset(game_menu_option_flag, 1, sizeof(game_menu_option_flag) );
  124. if( !nation_array.player_recno)
  125. {
  126. // when in observe mode
  127. game_menu_option_flag[1] = 0; // disable save game
  128. game_menu_option_flag[4] = 0; // disable retire
  129. }
  130. if( remote.is_enable() )
  131. {
  132. // when in when in multi-player mode,
  133. game_menu_option_flag[2] = 0; // disable load game
  134. game_menu_option_flag[3] = 0; // disable training
  135. game_menu_option_flag[4] = 0; // disable retire
  136. }
  137. }
  138. // ------- End of static function init_game_menu_option_flag -----//
  139. //------- Begin of static function detect_game_option -------//
  140. static int detect_game_option()
  141. {
  142. int i, y=GAME_OPTION_Y1, x2, y2;
  143. for( i=1 ; i<=GAME_OPTION_COUNT ; i++, y+=GAME_OPTION_HEIGHT )
  144. {
  145. x2 = GAME_OPTION_X1+GAME_OPTION_WIDTH-1;
  146. y2 = y+GAME_OPTION_HEIGHT-1;
  147. if( game_menu_option_flag[i-1] == 1 &&
  148. (menu_hot_key[i-1] && mouse.key_code == menu_hot_key[i-1] ||
  149. mouse.single_click( GAME_OPTION_X1, y, x2, y2 )) )
  150. break;
  151. }
  152. if( i>GAME_OPTION_COUNT )
  153. return 0;
  154. //------ display the pressed down button -----//
  155. vga_front.save_area_common_buf( GAME_OPTION_X1, y, x2, y2 );
  156. // image_interface.put_front( GAME_OPTION_X1, y, "GAM_DOWN" );
  157. image_interface.put_front( GAME_OPTION_X1, y, "MENU-DWN" );
  158. while( mouse.left_press ) // holding down the button
  159. {
  160. sys.yield();
  161. mouse.get_event();
  162. }
  163. vga_front.rest_area_common_buf(); // restore the up button
  164. //--------- run the option -------//
  165. switch(i)
  166. {
  167. case 1: // options
  168. // game.in_game_option_menu();
  169. option_menu.enter(!remote.is_enable());
  170. break;
  171. case 2: // save game
  172. sys.save_game();
  173. break;
  174. case 3: // load game
  175. sys.load_game();
  176. break;
  177. case 4: // training
  178. tutor.select_run_tutor(1);
  179. break;
  180. case 5: // retire
  181. if( nation_array.player_recno ) // only when the player's kingdom still exists
  182. {
  183. if( box.ask("Do you really want to retire?", "Yes", "No", 175, 320) )
  184. game.game_end(0, 0, 0, 1); // 1 - retire
  185. }
  186. break;
  187. case 6: // quit to main menu
  188. if( !nation_array.player_recno ||
  189. box.ask( "Do you really want to quit to the Main Menu?", "Yes", "No", 115, 350 ) )
  190. {
  191. if( remote.is_enable() && nation_array.player_recno )
  192. {
  193. // BUGHERE : message will not be sent out
  194. short *shortPtr = (short *)remote.new_send_queue_msg( MSG_PLAYER_QUIT, 2*sizeof(short));
  195. shortPtr[0] = nation_array.player_recno;
  196. shortPtr[1] = 0; // not retire
  197. }
  198. sys.signal_exit_flag = 2;
  199. }
  200. break;
  201. case 7: // quit to Windows
  202. if( !nation_array.player_recno ||
  203. box.ask( "Do you really want to quit to Windows?", "Yes", "No", 130, 400 ) )
  204. {
  205. if( remote.is_enable() && nation_array.player_recno )
  206. {
  207. // BUGHERE : message will not be sent out
  208. short *shortPtr = (short *)remote.new_send_queue_msg( MSG_PLAYER_QUIT, 2*sizeof(short));
  209. shortPtr[0] = nation_array.player_recno;
  210. shortPtr[1] = 1; // retire
  211. }
  212. sys.signal_exit_flag = 1;
  213. }
  214. break;
  215. }
  216. return 1;
  217. }
  218. //-------- End of static function detect_game_option -------//
  219. enum { BASIC_OPTION_X_SPACE = 78,
  220. BASIC_OPTION_HEIGHT = 32 };
  221. enum { COLOR_OPTION_X_SPACE = 35,
  222. COLOR_OPTION_HEIGHT = 32 };
  223. enum { SERVICE_OPTION_X_SPACE = 180,
  224. SERVICE_OPTION_HEIGHT = 139 };
  225. enum { SLIDE_BUTTON_WIDTH = 23,
  226. SLIDE_BUTTON_HEIGHT = 24 };
  227. static char race_table[MAX_RACE] = // race translation table
  228. {
  229. RACE_CHINESE, RACE_GREEK, RACE_JAPANESE, RACE_MAYA,
  230. RACE_PERSIAN, RACE_NORMAN, RACE_VIKING
  231. };
  232. static char reverse_race_table[MAX_RACE] = // race translation table
  233. {
  234. 5, 3, 1, 6, 4, 0, 2
  235. };
  236. static void disp_virtual_button(ButtonCustom *button, int);
  237. static void disp_slide_bar(SlideBar *slideBar, int);
  238. // return 1 if ok, config is changed
  239. #define IGOPTION_SE_VOL 0x00000001
  240. #define IGOPTION_MUSIC_VOL 0x00000002
  241. #define IGOPTION_RACE 0x00000004
  242. #define IGOPTION_HELP 0x00000008
  243. #define IGOPTION_NEWS 0x00000010
  244. #define IGOPTION_GAME_SPEED 0x00000020
  245. #define IGOPTION_SCROLL_SPEED 0x00000040
  246. #define IGOPTION_REPORT 0x00000080
  247. #define IGOPTION_SHOW_ICON 0x00000100
  248. #define IGOPTION_DRAW_PATH 0x00000200
  249. #define IGOPTION_PAGE 0x40000000
  250. #define IGOPTION_ALL 0x7FFFFFFF
  251. // ---------- begin of function Game::in_game_option_menu ------//
  252. int Game::in_game_option_menu()
  253. {
  254. int i;
  255. int retFlag = 0;
  256. int refreshFlag = IGOPTION_ALL;
  257. info.save_game_scr();
  258. Config& tempConfig = config;
  259. Config oldConfig = config;
  260. // -------- initialize sound effect volume --------//
  261. SlideBar seVolSlide;
  262. seVolSlide.init_slide(264, 123, 420, 123+SLIDE_BUTTON_HEIGHT-1,
  263. SLIDE_BUTTON_WIDTH, disp_slide_bar);
  264. seVolSlide.set(0, 100, tempConfig.sound_effect_flag ? tempConfig.sound_effect_volume : 0);
  265. // -------- initialize music volume --------//
  266. SlideBar musicVolSlide;
  267. musicVolSlide.init_slide(566, 123, 722, 123+SLIDE_BUTTON_HEIGHT-1,
  268. SLIDE_BUTTON_WIDTH, disp_slide_bar);
  269. musicVolSlide.set(0, 100, tempConfig.music_flag ? tempConfig.wav_music_volume : 0);
  270. // -------- initialize frame speed volume --------//
  271. SlideBar frameSpeedSlide;
  272. frameSpeedSlide.init_slide(196, 410, 352, 410+SLIDE_BUTTON_HEIGHT-1,
  273. SLIDE_BUTTON_WIDTH, disp_slide_bar);
  274. frameSpeedSlide.set(0, 31, tempConfig.frame_speed <= 30 ? tempConfig.frame_speed: 31);
  275. // use frame 31 to represent full speed (i.e. 99)
  276. // -------- initialize scroll speed volume --------//
  277. SlideBar scrollSpeedSlide;
  278. scrollSpeedSlide.init_slide(196, 454, 352, 454+SLIDE_BUTTON_HEIGHT-1,
  279. SLIDE_BUTTON_WIDTH, disp_slide_bar);
  280. scrollSpeedSlide.set(0, 10, tempConfig.scroll_speed );
  281. // --------- initialize race buttons ---------- //
  282. ButtonCustom raceButton[MAX_RACE];
  283. for( i = 0; i < MAX_RACE; ++i )
  284. {
  285. raceButton[i].create(181+i*BASIC_OPTION_X_SPACE, 162,
  286. 181+(i+1)*BASIC_OPTION_X_SPACE-1, 162+BASIC_OPTION_HEIGHT-1,
  287. disp_virtual_button, ButtonCustomPara(NULL, race_table[i]));
  288. }
  289. // --------- initialize help button group ---------- //
  290. ButtonCustomGroup helpGroup(3);
  291. for( i = 0; i < 3; ++i )
  292. {
  293. helpGroup[i].create(120+i*BASIC_OPTION_X_SPACE, 244,
  294. 120+(i+1)*BASIC_OPTION_X_SPACE-1, 244+BASIC_OPTION_HEIGHT-1,
  295. disp_virtual_button, ButtonCustomPara(&helpGroup, i), 0, 0);
  296. }
  297. // --------- initialize news button group ---------- //
  298. ButtonCustomGroup newsGroup(2);
  299. for( i = 0; i < 2; ++i )
  300. {
  301. newsGroup[i].create(198+i*BASIC_OPTION_X_SPACE, 320,
  302. 198+(i+1)*BASIC_OPTION_X_SPACE-1, 320+BASIC_OPTION_HEIGHT-1,
  303. disp_virtual_button, ButtonCustomPara(&newsGroup, 1-i), 0, 0);
  304. }
  305. // --------- initialize report button group ---------- //
  306. ButtonCustomGroup reportGroup(2);
  307. for( i = 0; i < 2; ++i )
  308. {
  309. reportGroup[i].create(572+i*BASIC_OPTION_X_SPACE, 244,
  310. 572+(i+1)*BASIC_OPTION_X_SPACE-1, 244+BASIC_OPTION_HEIGHT-1,
  311. disp_virtual_button, ButtonCustomPara(&reportGroup, 1-i), 0, 0);
  312. }
  313. // --------- initialize show icon button group ---------- //
  314. ButtonCustomGroup showIconGroup(2);
  315. for( i = 0; i < 2; ++i )
  316. {
  317. showIconGroup[i].create(572+i*BASIC_OPTION_X_SPACE, 320,
  318. 572+(i+1)*BASIC_OPTION_X_SPACE-1, 320+BASIC_OPTION_HEIGHT-1,
  319. disp_virtual_button, ButtonCustomPara(&showIconGroup, 1-i), 0, 0);
  320. }
  321. // --------- initialize show path button group ---------- //
  322. ButtonCustomGroup showPathGroup(4);
  323. for( i = 0; i < 4; ++i )
  324. {
  325. showPathGroup[i].create(572+(i/2)*BASIC_OPTION_X_SPACE, 408+(i%2)*BASIC_OPTION_HEIGHT,
  326. 572+(i/2+1)*BASIC_OPTION_X_SPACE-1, 408+(i%2+1)*BASIC_OPTION_HEIGHT-1,
  327. disp_virtual_button, ButtonCustomPara(&showPathGroup, i), 0, 0);
  328. }
  329. // --------- other buttons --------//
  330. Button3D startButton, cancelButton;
  331. startButton.create(200, 520, "RETURN-U", "RETURN-D", 1, 0);
  332. cancelButton.create(416, 520, "CANCEL-U", "CANCEL-D", 1, 0);
  333. mouse_cursor.set_icon(CURSOR_NORMAL);
  334. power.win_opened = 1;
  335. while(1)
  336. {
  337. sys.yield();
  338. mouse.get_event();
  339. // ------- display --------//
  340. if(refreshFlag)
  341. {
  342. if( refreshFlag & IGOPTION_PAGE )
  343. {
  344. image_interface.put_to_buf( &vga_back, "OPTIONS");
  345. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  346. startButton.paint();
  347. cancelButton.paint();
  348. }
  349. if( refreshFlag & IGOPTION_SE_VOL )
  350. {
  351. seVolSlide.paint(tempConfig.sound_effect_flag ? percent_to_slide_volume(tempConfig.sound_effect_volume) : 0);
  352. }
  353. if( refreshFlag & IGOPTION_MUSIC_VOL )
  354. {
  355. musicVolSlide.paint(tempConfig.music_flag ? percent_to_slide_volume(tempConfig.wav_music_volume) : 0);
  356. }
  357. if( refreshFlag & IGOPTION_RACE )
  358. {
  359. for( i = 0; i < MAX_RACE; ++i )
  360. raceButton[i].paint();
  361. }
  362. if( refreshFlag & IGOPTION_HELP )
  363. {
  364. helpGroup.paint(tempConfig.help_mode);
  365. }
  366. if( refreshFlag & IGOPTION_NEWS )
  367. {
  368. newsGroup.paint(1-tempConfig.disp_news_flag);
  369. }
  370. if( refreshFlag & IGOPTION_GAME_SPEED )
  371. {
  372. frameSpeedSlide.paint(tempConfig.frame_speed <= 30 ? tempConfig.frame_speed: 31);
  373. }
  374. if( refreshFlag & IGOPTION_SCROLL_SPEED )
  375. {
  376. scrollSpeedSlide.paint(tempConfig.scroll_speed);
  377. }
  378. if( refreshFlag & IGOPTION_REPORT )
  379. {
  380. reportGroup.paint(1-tempConfig.opaque_report);
  381. }
  382. if( refreshFlag & IGOPTION_SHOW_ICON )
  383. {
  384. showIconGroup.paint(1-tempConfig.show_all_unit_icon);
  385. }
  386. if( refreshFlag & IGOPTION_DRAW_PATH )
  387. {
  388. showPathGroup.paint(tempConfig.show_unit_path);
  389. }
  390. refreshFlag = 0;
  391. }
  392. // ------- play music --------//
  393. int oldSongId = music.song_id;
  394. if( config.music_flag )
  395. {
  396. if( !music.is_playing() )
  397. music.play(music.random_bgm_track(oldSongId), sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  398. }
  399. else
  400. {
  401. // stop any music playing
  402. music.stop();
  403. }
  404. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  405. // -------- detect button --------//
  406. if( seVolSlide.detect() == 1)
  407. {
  408. tempConfig.sound_effect_flag = seVolSlide.view_recno > 0;
  409. if( seVolSlide.view_recno > 0)
  410. tempConfig.sound_effect_volume = slide_to_percent_volume(seVolSlide.view_recno);
  411. else
  412. tempConfig.sound_effect_volume = 1; // never set sound_effect_volume = 0
  413. audio.set_wav_volume(tempConfig.sound_effect_volume);
  414. // change music volume, sound effect volume may change music volume
  415. if( tempConfig.music_flag )
  416. {
  417. music.change_volume( tempConfig.wav_music_volume);
  418. }
  419. }
  420. else if( musicVolSlide.detect() == 1)
  421. {
  422. tempConfig.music_flag = musicVolSlide.view_recno > 0;
  423. tempConfig.wav_music_volume = slide_to_percent_volume(musicVolSlide.view_recno);
  424. if( tempConfig.music_flag )
  425. {
  426. music.change_volume( tempConfig.wav_music_volume );
  427. }
  428. }
  429. else if( frameSpeedSlide.detect() == 1)
  430. {
  431. tempConfig.frame_speed = frameSpeedSlide.view_recno <= 30 ? frameSpeedSlide.view_recno : 99;
  432. }
  433. else if( scrollSpeedSlide.detect() == 1)
  434. {
  435. tempConfig.scroll_speed = scrollSpeedSlide.view_recno;
  436. }
  437. for( i = 0; i < MAX_RACE; ++i )
  438. {
  439. if( raceButton[i].detect() )
  440. {
  441. if( config.music_flag )
  442. {
  443. music.play( raceButton[i].custom_para.value + 1,
  444. sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  445. }
  446. else
  447. {
  448. // stop any music playing
  449. music.stop();
  450. }
  451. }
  452. }
  453. if( helpGroup.detect() >= 0)
  454. {
  455. tempConfig.help_mode = helpGroup[helpGroup()].custom_para.value;
  456. //refreshFlag |= IGOPTION_HELP;
  457. }
  458. else if( newsGroup.detect() >= 0)
  459. {
  460. tempConfig.disp_news_flag = newsGroup[newsGroup()].custom_para.value;
  461. //refreshFlag |= IGOPTION_HELP;
  462. }
  463. else if( reportGroup.detect() >= 0)
  464. {
  465. tempConfig.opaque_report = reportGroup[reportGroup()].custom_para.value;
  466. //refreshFlag |= IGOPTION_REPORT;
  467. }
  468. else if( showIconGroup.detect() >= 0)
  469. {
  470. tempConfig.show_all_unit_icon = showIconGroup[showIconGroup()].custom_para.value;
  471. //refreshFlag |= IGOPTION_SHOW_ICON;
  472. }
  473. else if( showPathGroup.detect() >= 0)
  474. {
  475. tempConfig.show_unit_path = showPathGroup[showPathGroup()].custom_para.value;
  476. //refreshFlag |= IGOPTION_SHOW_PATH;
  477. }
  478. else if( startButton.detect(KEY_RETURN) )
  479. {
  480. if( &config != &tempConfig)
  481. config = tempConfig;
  482. // save config
  483. Config fileConfig;
  484. if( !fileConfig.load("CONFIG.DAT") )
  485. fileConfig.init();
  486. fileConfig.change_preference(tempConfig);
  487. fileConfig.save("CONFIG.DAT");
  488. retFlag = 1;
  489. break;
  490. }
  491. else if( cancelButton.detect(KEY_ESC) )
  492. {
  493. config = oldConfig;
  494. retFlag = 0;
  495. break;
  496. }
  497. }
  498. // reflect the effect of config.music_flag, config.wav_music_volume
  499. audio.set_wav_volume(config.sound_effect_volume);
  500. if( config.music_flag )
  501. {
  502. if( music.is_playing() )
  503. {
  504. music.change_volume(config.wav_music_volume);
  505. }
  506. }
  507. else
  508. {
  509. music.stop();
  510. }
  511. info.rest_game_scr();
  512. power.win_opened = 0;
  513. return retFlag;
  514. }
  515. // ---------- end of function Game::in_game_option_menu ------//
  516. // ---------- begin of static function disp_virtual_button -----//
  517. static void disp_virtual_button(ButtonCustom *button, int)
  518. {
  519. mouse.hide_area(button->x1, button->y1, button->x2, button->y2);
  520. if( !button->pushed_flag )
  521. {
  522. // copy from back buffer to front buffer
  523. IMGcopy(vga_front.buf_ptr(), vga_front.buf_pitch(),
  524. vga_back.buf_ptr(), vga_back.buf_pitch(),
  525. button->x1, button->y1, button->x2, button->y2 );
  526. }
  527. else
  528. {
  529. // copy from back buffer to front buffer, but the area is
  530. // darkened by 2 scale
  531. IMGcopyRemap(vga_front.buf_ptr(), vga_front.buf_pitch(),
  532. vga_back.buf_ptr(), vga_back.buf_pitch(),
  533. button->x1, button->y1, button->x2, button->y2,
  534. vga.vga_color_table->get_table(-2) );
  535. // draw black frame
  536. if( button->x2-button->x1+1 == BASIC_OPTION_X_SPACE &&
  537. button->y2-button->y1+1 == BASIC_OPTION_HEIGHT )
  538. {
  539. image_interface.put_front(button->x1, button->y1, "BAS_DOWN");
  540. }
  541. else if( button->x2-button->x1+1 == COLOR_OPTION_X_SPACE &&
  542. button->y2-button->y1+1 == COLOR_OPTION_HEIGHT )
  543. {
  544. image_interface.put_front(button->x1, button->y1, "COL_DOWN");
  545. }
  546. else if( button->x2-button->x1+1 == SERVICE_OPTION_X_SPACE &&
  547. button->y2-button->y1+1 == SERVICE_OPTION_HEIGHT )
  548. {
  549. image_interface.put_front(button->x1, button->y1, "NMPG-1BD");
  550. }
  551. }
  552. mouse.show_area();
  553. }
  554. // ---------- end of static function disp_virtual_button -----//
  555. // ---------- begin of static function disp_slide_bar -----//
  556. static void disp_slide_bar(SlideBar *slideBar, int)
  557. {
  558. vga.blt_buf(slideBar->scrn_x1, slideBar->scrn_y1,
  559. slideBar->scrn_x2, slideBar->scrn_y2, 0 );
  560. image_interface.put_front(slideBar->rect_left(), slideBar->scrn_y1, "SLIDBALL");
  561. }
  562. // ---------- end of static function disp_slide_bar -----//
  563. static int slide_to_percent_volume(int slideVolume)
  564. {
  565. switch( slideVolume / 10)
  566. {
  567. case 0:
  568. return slideVolume * 5;
  569. case 1:
  570. case 2:
  571. case 3:
  572. return slideVolume+40;
  573. break;
  574. case 4:
  575. case 5:
  576. return slideVolume/2 + 60;
  577. break;
  578. case 6:
  579. case 7:
  580. case 8:
  581. case 9:
  582. case 10:
  583. return slideVolume/4+75;
  584. break;
  585. default:
  586. err_here();
  587. return slideVolume;
  588. }
  589. }
  590. // slideVolume 0 10 20 30 40 50 60 70 80 90 100
  591. // !----!----!----!----!----!----!----!----!----!----!
  592. // percentVoume 0 50 80 90 100
  593. static int percent_to_slide_volume(int percentVolume)
  594. {
  595. switch(percentVolume/10)
  596. {
  597. case 0:
  598. case 1:
  599. case 2:
  600. case 3:
  601. case 4:
  602. return percentVolume/5;
  603. case 5:
  604. case 6:
  605. case 7:
  606. return percentVolume - 40;
  607. case 8:
  608. return (percentVolume-60) * 2;
  609. case 9:
  610. case 10:
  611. return (percentVolume-75) * 4;
  612. default:
  613. err_here();
  614. return percentVolume;
  615. }
  616. }
  617. void Game::disp_gen_map_status( int curStep, int maxStep, int section )
  618. {
  619. const int POPUP_WINDOW_WIDTH = 266;
  620. const int POPUP_WINDOW_HEIGHT = 149;
  621. const int POPUP_WINDOW_X1 = (vga_front.buf_width() - POPUP_WINDOW_WIDTH) / 2;
  622. const int POPUP_WINDOW_Y1 = (vga_front.buf_height() - POPUP_WINDOW_HEIGHT) / 2;
  623. const int BAR_X1 = POPUP_WINDOW_X1 + 46;
  624. // ###### begin Gilbert 29/10 ######//
  625. const int BAR_Y1 = POPUP_WINDOW_Y1 + 106;
  626. // ###### end Gilbert 29/10 ######//
  627. const int MAX_SECTION = 2; // section 0 for world.genmap, section 1 for battle.run
  628. static int accSectionWeight[MAX_SECTION+1] = { 0, 60, 100 };
  629. if( section == 0 && curStep == 0)
  630. {
  631. image_menu.put_front(POPUP_WINDOW_X1, POPUP_WINDOW_Y1, "NEWWORLD");
  632. }
  633. err_when( section < 0 || section >= MAX_SECTION );
  634. err_when( curStep < 0 || curStep > maxStep );
  635. if( curStep >= 0 && curStep <= maxStep)
  636. {
  637. float r = float(accSectionWeight[section]) +
  638. float((accSectionWeight[section+1]-accSectionWeight[section]) * curStep) / maxStep;
  639. vga_front.indicator(4, BAR_X1, BAR_Y1, r, (float)accSectionWeight[MAX_SECTION], 0);
  640. }
  641. sys.blt_virtual_buf();
  642. }