OTUTOR2.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 : OTUTOR2.CPP
  21. //Description : Class Tutor
  22. #include <OSYS.h>
  23. #include <OGAME.h>
  24. #include <OMOUSE.h>
  25. #include <OMOUSECR.h>
  26. #include <OVGABUF.h>
  27. #include <OIMGRES.h>
  28. #include <OBUTT3D.h>
  29. #include <OSLIDCUS.h>
  30. #include <OBOX.h>
  31. #include <OPOWER.h>
  32. #include <OFONT.h>
  33. #include <KEY.h>
  34. #include <OBLOB.h>
  35. #include <OTUTOR.h>
  36. #include <OINFO.h>
  37. // ####### begin Gilbert 4/11 #######//
  38. #include <OMUSIC.h>
  39. // ####### end Gilbert 4/11 #######//
  40. // --------- declare static funtion --------//
  41. static void disp_scroll_bar_func(SlideVBar *scroll, int);
  42. enum { TUTOR_MENU_X1 = 0,
  43. TUTOR_MENU_Y1 = 0,
  44. TUTOR_MENU_WIDTH = VGA_WIDTH,
  45. TUTOR_MENU_HEIGHT = VGA_HEIGHT };
  46. enum { SCROLL_X1 = 757,
  47. SCROLL_Y1 = 309,
  48. SCROLL_X2 = 770,
  49. SCROLL_Y2 = 492 };
  50. enum { BROWSE_X1 = 30,
  51. BROWSE_Y1 = 292,
  52. BROWSE_REC_WIDTH = 725,
  53. BROWSE_REC_HEIGHT = 44,
  54. BROWSE_X2 = BROWSE_X1 + BROWSE_REC_WIDTH - 1,
  55. MAX_BROWSE_DISP_REC = 5 };
  56. enum { TEXT_AREA_X1 = 40,
  57. TEXT_AREA_Y1 = 198,
  58. TEXT_AREA_X2 = 768,
  59. TEXT_AREA_Y2 = 260,
  60. TEXT_AREA_WIDTH = TEXT_AREA_X2 - TEXT_AREA_X1 + 1,
  61. TEXT_AREA_HEIGHT = TEXT_AREA_Y2 - TEXT_AREA_Y1 + 1,
  62. };
  63. enum { TEXT_OFFSET_X = 11,
  64. TEXT_OFFSET_Y = 9 };
  65. #define TU_USE_BACKUP_SURFACE
  66. #define TUOPTION_BROWSE(s) (1 << (s))
  67. #define TUOPTION_ALL_BROWSE 0x0000ffff
  68. #define TUOPTION_PAGE 0x00010000
  69. #define TUOPTION_TEXT_AREA 0x00020000
  70. #define TUOPTION_PIC_AREA 0x00040000
  71. #define TUOPTION_SCROLL 0x00080000
  72. #define TUOPTION_ALL 0xffffffff
  73. // actionMode = -2 save to back buffer
  74. // -1 restore from back buffer
  75. //
  76. // return 0 for cancelled
  77. // -1 for failure
  78. // >0 recno selected
  79. int Tutor::select_tutor(int actionMode)
  80. {
  81. if( actionMode == -2 || actionMode == -1)
  82. {
  83. // copy or restore screen to back buffer
  84. int scrnX1, scrnY1, scrnX2, scrnY2;
  85. scrnX1 = TUTOR_MENU_X1;
  86. scrnY1 = TUTOR_MENU_Y1;
  87. scrnX2 = scrnX1 + TUTOR_MENU_WIDTH-1;
  88. scrnY2 = scrnY1 + TUTOR_MENU_HEIGHT-1;
  89. mouse.hide_area( scrnX1, scrnY1, scrnX2, scrnY2);
  90. if( actionMode == -2 )
  91. {
  92. info.save_game_scr();
  93. // save to back buffer
  94. IMGcopy(vga_back.buf_ptr(), vga_back.buf_pitch(),
  95. vga_front.buf_ptr(), vga_front.buf_pitch(),
  96. scrnX1, scrnY1, scrnX2, scrnY2);
  97. }
  98. else
  99. {
  100. // restore from back buffer
  101. IMGcopy(vga_front.buf_ptr(), vga_front.buf_pitch(),
  102. vga_back.buf_ptr(), vga_back.buf_pitch(),
  103. scrnX1, scrnY1, scrnX2, scrnY2);
  104. info.rest_game_scr();
  105. }
  106. mouse.show_area();
  107. return 1;
  108. }
  109. if( tutor_count==0 )
  110. {
  111. box.msg( "Tutorial files not found." );
  112. return 0;
  113. }
  114. //-------------------------------------//
  115. // ##### begin Gilbert 4/11 ########//
  116. // stop any music
  117. music.stop();
  118. // ##### end Gilbert 4/11 ########//
  119. int menuX1 = TUTOR_MENU_X1;
  120. int menuY1 = TUTOR_MENU_Y1;
  121. // int x=menuX1, y=menuY1+17;
  122. // vga_back.adjust_brightness( x, y, x+menuX1-1, y+menuY1-1, -6 );
  123. // vga.blt_buf( x, y, x+menuX1-1, y+menuY1-1, 0 );
  124. mouse_cursor.set_icon(CURSOR_NORMAL);
  125. power.win_opened = 1;
  126. int minRecno = 1;
  127. int browseRecno = minRecno;
  128. // ###### begin Gilbert 29/9 #######//
  129. // if called during the game, set the current tutorial selected
  130. if( cur_tutor_id >= 1 && cur_tutor_id <= tutor_count )
  131. {
  132. browseRecno = cur_tutor_id;
  133. }
  134. // ###### end Gilbert 29/9 #######//
  135. //--------------------------------------//
  136. Button3D scrollUp, scrollDown, startButton, cancelButton;
  137. int retFlag = 0;
  138. int refreshFlag = TUOPTION_ALL;
  139. scrollUp.create(menuX1+SCROLL_X1,menuY1+SCROLL_Y1-17, "SV-UP-U", "SV-UP-D", 1, 0);
  140. scrollDown.create(menuX1+SCROLL_X1,menuY1+SCROLL_Y2+1, "SV-DW-U", "SV-DW-D", 1, 0);
  141. startButton.create(menuX1+170, menuY1+529, "START-U", "START-D",1, 0);
  142. cancelButton.create(menuX1+465, menuY1+529, "CANCEL-U", "CANCEL-D", 1, 0);
  143. SlideVBar scrollBar;
  144. scrollBar.init_scroll(menuX1+SCROLL_X1, menuY1+SCROLL_Y1, menuX1+SCROLL_X2, menuY1+SCROLL_Y2,
  145. MAX_BROWSE_DISP_REC, disp_scroll_bar_func);
  146. scrollBar.set(minRecno, tutor_count, minRecno);
  147. // try to centre the selected record on the browser
  148. // int newBrowseTopRecno = browseRecno - MAX_BROWSE_DISP_REC/2;
  149. // if( newBrowseTopRecno > scrollBar.max_view_recno() )
  150. // newBrowseTopRecno = scrollBar.max_view_recno();
  151. // if( newBrowseTopRecno < scrollBar.min_recno )
  152. /// newBrowseTopRecno = scrollBar.min_recno;
  153. scrollBar.set_view_recno(browseRecno - MAX_BROWSE_DISP_REC/2);
  154. #ifdef TU_USE_BACKUP_SURFACE
  155. // create temporary surface
  156. Blob browseArea[MAX_BROWSE_DISP_REC];
  157. Blob scrollArea;
  158. Blob textArea;
  159. #endif
  160. while(1)
  161. {
  162. //---------- yield --------//
  163. sys.yield();
  164. mouse.get_event();
  165. // --------- display ----------//
  166. if( refreshFlag )
  167. {
  168. #ifndef TU_USE_BACKUP_SURFACE
  169. refreshFlag = TUOPTION_ALL;
  170. #endif
  171. if( refreshFlag & TUOPTION_PAGE )
  172. {
  173. mouse.hide_area(menuX1, menuY1, menuX1+TUTOR_MENU_WIDTH, menuY1+TUTOR_MENU_HEIGHT);
  174. image_interface.put_front( menuX1, menuY1, "TUTORIAL" );
  175. #ifdef TU_USE_BACKUP_SURFACE
  176. // capture into browseArea, scrollArea, textArea
  177. for( int j = 0; j < MAX_BROWSE_DISP_REC; ++j)
  178. {
  179. browseArea[j].resize(2*sizeof(short) + BROWSE_REC_WIDTH*BROWSE_REC_HEIGHT);
  180. vga_front.read_bitmap(
  181. menuX1+BROWSE_X1, menuY1+BROWSE_Y1 + j*BROWSE_REC_HEIGHT,
  182. menuX1+BROWSE_X2, menuY1+BROWSE_Y1 + j*BROWSE_REC_HEIGHT+BROWSE_REC_HEIGHT-1,
  183. browseArea[j].ptr);
  184. }
  185. scrollArea.resize(2*sizeof(short)+(SCROLL_X2-SCROLL_X1+1)*(SCROLL_Y2-SCROLL_Y1+1));
  186. vga_front.read_bitmap(menuX1+SCROLL_X1,menuY1+SCROLL_Y1,menuX1+SCROLL_X2,menuY1+SCROLL_Y2, scrollArea.ptr);
  187. textArea.resize(2*sizeof(short)+TEXT_AREA_WIDTH*TEXT_AREA_HEIGHT);
  188. vga_front.read_bitmap(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1,
  189. menuX1+TEXT_AREA_X2, menuY1+TEXT_AREA_Y2, textArea.ptr);
  190. #endif
  191. scrollUp.paint();
  192. scrollDown.paint();
  193. startButton.paint();
  194. cancelButton.paint();
  195. mouse.show_area();
  196. }
  197. if( refreshFlag & TUOPTION_PIC_AREA )
  198. {
  199. if( browseRecno && image_tutorial.get_index(this->operator[](browseRecno)->code) )
  200. {
  201. image_tutorial.put_large(&vga_front, 21,19, this->operator[](browseRecno)->code);
  202. }
  203. else
  204. {
  205. // draw the background
  206. #ifdef TU_USE_BACKUP_SURFACE
  207. // copy from ?
  208. #endif
  209. }
  210. }
  211. if( refreshFlag & TUOPTION_TEXT_AREA )
  212. {
  213. #ifdef TU_USE_BACKUP_SURFACE
  214. // copy from back buffer
  215. vga_front.put_bitmap(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1,
  216. textArea.ptr);
  217. #endif
  218. if( browseRecno )
  219. {
  220. #if(defined(GERMAN) || defined(FRENCH) || defined(SPANISH))
  221. int lineSpace = 2;
  222. #else
  223. int lineSpace = 4;
  224. #endif
  225. font_std.put_paragraph(menuX1+TEXT_AREA_X1, menuY1+TEXT_AREA_Y1, menuX1+TEXT_AREA_X2, menuY1+TEXT_AREA_Y2,
  226. get_intro(browseRecno), lineSpace ); // 4 - space between lines
  227. }
  228. }
  229. if( refreshFlag & TUOPTION_SCROLL )
  230. {
  231. #ifdef TU_USE_BACKUP_SURFACE
  232. // copy from back buffer
  233. vga_front.put_bitmap(menuX1+SCROLL_X1, menuY1+SCROLL_Y1,
  234. scrollArea.ptr);
  235. #endif
  236. // display scroll bar
  237. scrollBar.paint();
  238. }
  239. if( refreshFlag & TUOPTION_ALL_BROWSE )
  240. {
  241. int rec, slot;
  242. for( slot = 0; slot < scrollBar.view_size; ++slot)
  243. {
  244. int browseSlotX1 = menuX1+BROWSE_X1;
  245. int browseSlotY1 = menuY1+BROWSE_Y1+slot*BROWSE_REC_HEIGHT;
  246. int browseSlotX2 = menuX1+BROWSE_X2;
  247. int browseSlotY2 = menuY1+BROWSE_Y1+(slot+1)*BROWSE_REC_HEIGHT-1;
  248. rec = scrollBar.view_recno + slot;
  249. if( refreshFlag & TUOPTION_BROWSE(slot) )
  250. {
  251. #ifdef TU_USE_BACKUP_SURFACE
  252. vga_front.put_bitmap(browseSlotX1, browseSlotY1,
  253. browseArea[rec%MAX_BROWSE_DISP_REC].ptr);
  254. #endif
  255. if( rec >= 1 && rec <= tutor_count )
  256. {
  257. int textX = font_bible.put(browseSlotX1+TEXT_OFFSET_X,
  258. browseSlotY1+TEXT_OFFSET_Y, m.format(rec), 0, browseSlotX2 );
  259. textX = font_bible.put(textX, browseSlotY1+TEXT_OFFSET_Y,
  260. ". ", 0, browseSlotX2 );
  261. textX = font_bible.put(textX, browseSlotY1+TEXT_OFFSET_Y,
  262. this->operator[](rec)->des, 0, browseSlotX2 );
  263. if( rec == browseRecno )
  264. {
  265. vga_front.adjust_brightness(browseSlotX1, browseSlotY1, browseSlotX2, browseSlotY2, -2);
  266. //vga_front.put_bitmap_trans_decompress( menuX1+BROWSE_X1, menuY1+BROWSE_Y1+slot*BROWSE_REC_HEIGHT,
  267. // image_button.read("LS-DWN"));
  268. }
  269. }
  270. }
  271. }
  272. }
  273. refreshFlag = 0;
  274. }
  275. sys.blt_virtual_buf();
  276. if( scrollBar.detect() == 1)
  277. {
  278. refreshFlag |= TUOPTION_SCROLL | TUOPTION_ALL_BROWSE;
  279. }
  280. else if( scrollUp.detect() )
  281. {
  282. // click on scroll up
  283. int oldValue = scrollBar.view_recno;
  284. //if( scrollBar.view_recno > minRecno )
  285. //{
  286. // scrollBar.set_view_recno(oldValue-1);
  287. // refreshFlag = 1;
  288. //}
  289. if( oldValue != scrollBar.set_view_recno(oldValue-1) )
  290. refreshFlag |= TUOPTION_ALL_BROWSE | TUOPTION_SCROLL;
  291. }
  292. else if( scrollDown.detect() )
  293. {
  294. // click on scroll down
  295. int oldValue = scrollBar.view_recno;
  296. //if( scrollBar.view_recno+scrollBar.view_size <= tutor_count )
  297. //{
  298. // scrollBar.set_view_recno(oldValue+1);
  299. // refreshFlag = 1;
  300. //}
  301. if( oldValue != scrollBar.set_view_recno(oldValue+1) )
  302. refreshFlag |= TUOPTION_ALL_BROWSE | TUOPTION_SCROLL;
  303. }
  304. else if( mouse.double_click( menuX1+BROWSE_X1, menuY1+BROWSE_Y1,
  305. menuX1+BROWSE_X1+BROWSE_REC_WIDTH-1,
  306. menuY1+BROWSE_Y1+ BROWSE_REC_HEIGHT*MAX_BROWSE_DISP_REC -1) )
  307. {
  308. // double click on game slot
  309. int oldValue = browseRecno;
  310. int newValue = scrollBar.view_recno + (mouse.click_y(0) - BROWSE_Y1 - menuY1) / BROWSE_REC_HEIGHT;
  311. if( newValue <= tutor_count && newValue == oldValue)
  312. {
  313. browseRecno = newValue;
  314. retFlag = newValue;
  315. break;
  316. }
  317. }
  318. else if( mouse.single_click( menuX1+BROWSE_X1, menuY1+BROWSE_Y1,
  319. menuX1+BROWSE_X1+BROWSE_REC_WIDTH-1,
  320. menuY1+BROWSE_Y1+ BROWSE_REC_HEIGHT*MAX_BROWSE_DISP_REC -1) )
  321. {
  322. // click on game slot
  323. int oldValue = browseRecno;
  324. int newValue = scrollBar.view_recno + (mouse.click_y(0) - BROWSE_Y1 - menuY1) / BROWSE_REC_HEIGHT;
  325. // ##### begin Gilbert 31/10 ########//
  326. if( newValue <= tutor_count )
  327. {
  328. if( oldValue != newValue )
  329. {
  330. browseRecno = newValue;
  331. refreshFlag |= TUOPTION_BROWSE(newValue-scrollBar.view_recno)
  332. | TUOPTION_TEXT_AREA | TUOPTION_PIC_AREA;
  333. if( oldValue-scrollBar.view_recno >= 0 && oldValue-scrollBar.view_recno < MAX_BROWSE_DISP_REC )
  334. refreshFlag |= TUOPTION_BROWSE(oldValue-scrollBar.view_recno);
  335. }
  336. }
  337. // ##### end Gilbert 31/10 ########//
  338. }
  339. else if( cancelButton.detect(KEY_ESC) || mouse.any_click(RIGHT_BUTTON) > 0) // also when ESC key is pressed or right button
  340. {
  341. // cancel button or escape key
  342. refreshFlag = TUOPTION_ALL;
  343. retFlag = 0;
  344. break; // break while(1)
  345. }
  346. else if( startButton.detect() )
  347. {
  348. // load button
  349. refreshFlag = TUOPTION_ALL;
  350. retFlag = browseRecno;
  351. break;
  352. }
  353. }
  354. power.win_opened = 0;
  355. return retFlag;
  356. }
  357. static void disp_scroll_bar_func(SlideVBar *scroll, int)
  358. {
  359. short rectTop = scroll->rect_top();
  360. short rectBottom = scroll->rect_bottom();
  361. vga_front.bar( scroll->scrn_x1, rectTop, scroll->scrn_x2, rectBottom, VGA_YELLOW+1);
  362. if( rectBottom - rectTop > 6 )
  363. {
  364. vga_front.d3_panel_up(scroll->scrn_x1, rectTop, scroll->scrn_x2, rectBottom,2,0);
  365. }
  366. }