./bg_saints.lua

  1. Bg_saints_doc_handle = 0	--Doc handle to bg saints... 
  2.  
  3. BG_TYPE_DEFAULT 		= 0 
  4. BG_TYPE_STRONGHOLD 	= 1 
  5. BG_TYPE_COMPLETION 	= 2 
  6. BG_TYPE_CENTER			= 3 
  7. BG_TYPE_FULLSCREEN	= 4 
  8.   
  9. local Bg_saints_scale = 1 
  10. local Bg_saints_type = BG_TYPE_DEFAULT 
  11.  
  12. -- BG Video frame times 
  13. local PRESS_START_LOOP_END 		= 186 
  14. local PRESS_START_TRANS_START 	= 200 
  15. local MAIN_MENU_LOOP_START 		= 291 
  16. local MAIN_MENU_LOOP_END	 		= 2614 
  17.  
  18.  
  19. local HD_Templates = { 
  20. 	[BG_TYPE_COMPLETION] 	= {	anchor_x = 100,  
  21. 											size_x = 468, 
  22. 											use_background = false}, 
  23. 							 
  24. 	[BG_TYPE_STRONGHOLD] 	= {	anchor_x = 100,  
  25. 											size_x = 488, 
  26. 											use_background = false}, 
  27. 	[BG_TYPE_DEFAULT] 		= {	anchor_x = -6,  
  28. 											size_x = 1290, 
  29. 											use_background = true}, 
  30. 	[BG_TYPE_CENTER] 			= {	anchor_x = 640,  
  31. 											size_x = 800, 
  32. 											use_background = false}, 
  33. 	[BG_TYPE_FULLSCREEN] 	= {	anchor_x = -6,  
  34. 											size_x = 1290, 
  35. 											use_background = false}, 
  36. } 
  37.  
  38. local SD_Templates = { 
  39. 	[BG_TYPE_COMPLETION] = {	anchor_x = 74, 
  40. 										size_x = 468, 
  41. 										use_background = false}, 
  42. 							 
  43. 	[BG_TYPE_STRONGHOLD] 	= {	anchor_x = 54,  
  44. 											size_x = 478, 
  45. 											use_background = false}, 
  46. 								 
  47. 	[BG_TYPE_DEFAULT] 		= {	anchor_x = -6,  
  48. 											size_x = 640, 
  49. 											use_background = true}, 
  50. 	[BG_TYPE_CENTER] 			= {	anchor_x = (320 * 1.5),  
  51. 											size_x = 800, 
  52. 											use_background = false}, 
  53. 	[BG_TYPE_FULLSCREEN] 	= {	anchor_x = -6,  
  54. 											size_x = (645 * 1.5), 
  55.                            		use_background = false}, 
  56. } 
  57. function bg_saints_init() 
  58. 	Bg_saints_doc_handle = vint_document_find("bg_saints") 
  59. 	 
  60. 	--Hide dimmer background 
  61. 	bg_saints_dimmer_show(false) 
  62. 	 
  63. 	--Set default type... 
  64. 	bg_saints_set_type(BG_TYPE_DEFAULT, false) 
  65. 	 
  66. 	 
  67. 	--Start background scroll 
  68. 	local anim_h = vint_object_find("crib_bg_loop_anim") 
  69. 	lua_play_anim(anim_h) 
  70. 	 
  71.  
  72. end 
  73.  
  74. function bg_saints_cleanup() 
  75. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  76. 	vint_set_property( bg_saints_video_h, "end_event", "" ) 
  77. end 
  78.  
  79. ------------------------------------------------------------------------------- 
  80. -- Sets type of background 
  81. -- @param	screen_type		Screen type: 	BG_TYPE_DEFAULT, BG_TYPE_STRONGHOLD, BG_TYPE_COMPLETION, BG_TYPE_CENTER 
  82. -- @param	morph				Bool:	do morph animation or not 
  83. -- @param	width				width override for background 
  84. -- @param	anchor			anchor override for background 
  85. -- 
  86. function bg_saints_set_type( screen_type, morph, width, anchor ) 
  87.  
  88. 	local bg_saints_mask_h = vint_object_find("bg_saints_mask", 0, Bg_saints_doc_handle) 
  89. 	local left_shadow_h = vint_object_find("left_shadow", 0, Bg_saints_doc_handle) 
  90. 	local right_shadow_h = vint_object_find("right_shadow", 0, Bg_saints_doc_handle) 
  91. 	local crib_bg_shadow_h = vint_object_find("crib_bg_shadow", 0, Bg_saints_doc_handle) 
  92. 	local screen_group_h = vint_object_find("screen_grp", 0, Bg_saints_doc_handle) 
  93. 	 
  94. 	local templates = HD_Templates 
  95. 	if vint_is_std_res() then 
  96. 		templates = SD_Templates 
  97. 	end 
  98. 	 
  99. 	Bg_saints_scale = vint_get_property(screen_group_h,"scale") 
  100. 	 
  101. 	Bg_saints_type = screen_type 
  102. 	 
  103. 	local template = templates[screen_type] 
  104. 	 
  105. 	--Check to see if our template is valid... 
  106. 	if template == nil then 
  107. 		template = templates[BG_TYPE_DEFAULT] 
  108. 	end 
  109. 	 
  110. 	--Get Template values. 
  111. 	--if anchor is nil then we will use template.anchor_x 
  112. 	local anchor_x = anchor or template.anchor_x 
  113. 	local anchor_y = -6 
  114. 	 
  115. 	--if width is nil then we will use template.size_x 
  116. 	local size_x = width or template.size_x 
  117. 	local size_y = 730 
  118. 	local use_background = template.use_background 
  119. 	 
  120. 	bg_saints_set_background(use_background) 
  121.  
  122. 	--do we need drop shadows? 
  123. 	if screen_type == BG_TYPE_DEFAULT then	 
  124. 		--no, hide them 
  125. 		vint_set_property( left_shadow_h, "visible", false ) 
  126. 		vint_set_property( right_shadow_h, "visible", false ) 
  127. 		vint_set_property( crib_bg_shadow_h, "visible", false ) 
  128. 	else 
  129. 		--yes, show them 
  130. 		vint_set_property( left_shadow_h, "visible", true ) 
  131. 		vint_set_property( right_shadow_h, "visible", true ) 
  132. 		vint_set_property( crib_bg_shadow_h, "visible", true ) 
  133. 	end 
  134. 	 
  135. 	--If Center aligned, create the center anchor point from the width of the mask 
  136. 	if screen_type == BG_TYPE_CENTER then 
  137. 		anchor_x = (anchor_x) - (size_x * 0.5) 
  138. 	end 
  139.  
  140. 	if morph then 
  141. 		--do the morph stuff 
  142. 		bg_saints_morph( screen_type, size_x, anchor_x ) 
  143. 	else 
  144. 		--Set template values, Position, Size, and if its a background layer... 
  145. 		vint_set_property(bg_saints_mask_h,"anchor", anchor_x, anchor_y) 
  146. 		element_set_actual_size(bg_saints_mask_h, size_x, size_y) 
  147. 		vint_set_property( left_shadow_h, "anchor", anchor_x, 40 ) 
  148. 		vint_set_property( right_shadow_h, "anchor", anchor_x + size_x, 660 ) 
  149. 	end 
  150. end 
  151.  
  152. ------------------------------------------------------------------------------- 
  153. -- Morphs background from previous size/position to the next... 
  154. -- @param	screen_type		Screen type: 	BG_TYPE_DEFAULT, BG_TYPE_STRONGHOLD, BG_TYPE_COMPLETION, BG_TYPE_CENTER 
  155. -- @param	size_end_x		width that the animation will end on 
  156. -- @param	anchor_end_x	x position that the animation will end on 
  157. -- 
  158. function bg_saints_morph( screen_type, size_end_x, anchor_end_x ) 
  159. 	--get handles for everyone 
  160. 	local bg_saints_mask_h = vint_object_find("bg_saints_mask", 0, Bg_saints_doc_handle) 
  161. 	local morph_anim_h = vint_object_find("mask_morph_anim", 0, Bg_saints_doc_handle) 
  162. 	local morph_scale_twn_h = vint_object_find("mask_morph_scale_twn", 0, Bg_saints_doc_handle) 
  163. 	local morph_anchor_twn_h = vint_object_find("mask_morph_anchor_twn", 0, Bg_saints_doc_handle)  
  164. 	local left_shadow_anchor_twn_h = vint_object_find("left_shadow_anchor_twn", 0, Bg_saints_doc_handle)  
  165. 	local right_shadow_anchor_twn_h = vint_object_find("right_shadow_anchor_twn", 0, Bg_saints_doc_handle)  
  166. 	local right_shadow_h = vint_object_find( "right_shadow",0,Bg_saints_doc_handle) 
  167. 	local left_shadow_h = vint_object_find( "left_shadow",0,Bg_saints_doc_handle) 
  168. 	local shadow_h = vint_object_find( "shadow_group", 0, Bg_saints_doc_handle ) 
  169. 	 
  170. 	--set up the left shadow start and end values 
  171. 	--get the starting x position 
  172. 	local anchor_start_x,anchor_start_y = vint_get_property( left_shadow_h, "anchor" ) 
  173.  
  174. 	vint_set_property( left_shadow_anchor_twn_h, "start_value", anchor_start_x, anchor_start_y ) 
  175. 	vint_set_property( left_shadow_anchor_twn_h, "end_value", anchor_end_x, anchor_start_y ) 
  176. 	 
  177. 	--set up the right shadow start and end values 
  178. 	anchor_start_x,anchor_start_y = vint_get_property( right_shadow_h, "anchor" ) 
  179. 	local adjusted_anchor_end_x = anchor_end_x + size_end_x 
  180. 	vint_set_property( right_shadow_anchor_twn_h, "start_value", anchor_start_x, anchor_start_y ) 
  181. 	vint_set_property( right_shadow_anchor_twn_h, "end_value", adjusted_anchor_end_x, anchor_start_y ) 
  182. 	 
  183. 	--setup the anchor for the mask 
  184. 	--get the starting x position 
  185. 	local mask_anchor_start_x,mask_anchor_start_y = vint_get_property( bg_saints_mask_h, "anchor" ) 
  186. 	vint_set_property(morph_anchor_twn_h, "start_value", mask_anchor_start_x, mask_anchor_start_y ) 
  187. 	vint_set_property(morph_anchor_twn_h, "end_value", anchor_end_x, mask_anchor_start_y ) 
  188. 	 
  189. 	--setup the scale of the mask 
  190. 	--get the starting scale 
  191. 	local size_start_x,size_start_y = vint_get_property(bg_saints_mask_h,"scale") 
  192. 	--get the correct size, this fixes SD scale issues 
  193. 	local adjusted_size_end_x,crap = element_get_scale_from_size(bg_saints_mask_h, size_end_x, 16) 
  194. 	vint_set_property(morph_scale_twn_h, "start_value", size_start_x , size_start_y) 
  195. 	vint_set_property(morph_scale_twn_h, "end_value", adjusted_size_end_x , size_start_y) 
  196. 	 
  197. 	--play the animation 
  198. 	lua_play_anim(morph_anim_h, 0, Bg_saints_doc_handle)	 
  199. 	 
  200. end 
  201.  
  202. ------------------------------------------------------------------------------- 
  203. -- Animates background into view... 
  204. -- 
  205. function bg_saints_animate() 
  206. 	local bg_h = vint_object_find( "bg", 0, Bg_saints_doc_handle ) 
  207. 	local shadow_h = vint_object_find( "shadow_group", 0, Bg_saints_doc_handle ) 
  208. 	vint_set_property(bg_h, "alpha", 1.0) 
  209. 	vint_set_property(shadow_h, "alpha", 0.5) 
  210. 	 
  211. 	local bg_saints_mask_h = vint_object_find( "bg_saints_mask", 0, Bg_saints_doc_handle ) 
  212. 	local mask_x,mask_y = vint_get_property( bg_saints_mask_h, "anchor" ) 
  213. 	local mask_tween_h = vint_object_find( "mask_drop_twn", 0, Bg_saints_doc_handle ) 
  214. 	vint_set_property(mask_tween_h,"start_value", -1000, mask_y) 
  215. 	vint_set_property(mask_tween_h,"end_value", mask_x, mask_y) 
  216. 	local anim = Vdo_anim_object:new("mask_drop_anim", 0, Bg_saints_doc_handle) 
  217. 	anim:play() 
  218. 	vint_apply_start_values(anim.handle) 
  219. 	bg_saints_show(true) 
  220. end 
  221.  
  222. ------------------------------------------------------------------------------- 
  223. -- Slides background into view... 
  224. -- 
  225. function bg_saints_slide_in(width, anchor) 
  226. 	local bg_h = vint_object_find( "bg", 0, Bg_saints_doc_handle ) 
  227. 	local shadow_h = vint_object_find( "shadow_group", 0, Bg_saints_doc_handle ) 
  228. 	local right_shadow_h = vint_object_find( "right_shadow", 0, Bg_saints_doc_handle ) 
  229. 	local left_shadow_h = vint_object_find( "left_shadow", 0, Bg_saints_doc_handle ) 
  230. 	vint_set_property(bg_h, "alpha", 1.0) 
  231. 	vint_set_property(shadow_h, "alpha", 0.5) 
  232. 	local bg_saints_mask_h = vint_object_find( "bg_saints_mask", 0, Bg_saints_doc_handle ) 
  233. 	 
  234. 	--get the resolution specific end position and width 
  235. 	local templates = HD_Templates 
  236. 	if vint_is_std_res() then 
  237. 		templates = SD_Templates 
  238. 	end 
  239. 	local template = templates[Bg_saints_type] 
  240. 	local anchor_x = anchor or template.anchor_x 
  241. 	local width = width or template.size_x 
  242. 	local left_anchor_x = anchor_x 
  243. 	if Bg_saints_type == BG_TYPE_CENTER then 
  244. 		left_anchor_x = (anchor_x) - (width * 0.5) 
  245. 		local right_anchor_x = (anchor_x) + (width * 0.5) 
  246. 		local crap_x,left_anchor_y = vint_get_property(left_shadow_h, "anchor") 
  247. 		vint_set_property(left_shadow_h, "anchor", left_anchor_x, left_anchor_y) 
  248. 		local crap_x,right_anchor_y = vint_get_property(right_shadow_h, "anchor") 
  249. 		vint_set_property(right_shadow_h, "anchor", right_anchor_x, right_anchor_y) 
  250. 	end 
  251. 	 
  252. 	--set the correct x and y for the mask 
  253. 	local start_x = -1000 
  254. 	local mask_x,mask_y = vint_get_property( bg_saints_mask_h, "anchor" ) 
  255. 	local mask_tween_h = vint_object_find( "mask_drop_twn_1", 0, Bg_saints_doc_handle ) 
  256. 	vint_set_property(mask_tween_h, "start_value", start_x, mask_y) 
  257. 	vint_set_property(mask_tween_h, "end_value", left_anchor_x, mask_y) 
  258. 	 
  259. 	--be sure to offest the start positions so that the anims match up 
  260. 	local shadow_tween_h = vint_object_find("shadow_drop_twn_1", 0, Bg_saints_doc_handle) 
  261. 	local shadow_x,shadow_y = vint_get_property(shadow_tween_h, "start_value") 
  262. 	vint_set_property(shadow_tween_h, "start_value", start_x - left_anchor_x, shadow_y) 
  263. 	 
  264. 	local anim = Vdo_anim_object:new("mask_slide_in_anim", 0, Bg_saints_doc_handle) 
  265. 	anim:play() 
  266. 	vint_apply_start_values(anim.handle) 
  267. 	bg_saints_show(true) 
  268. end 
  269.  
  270. ------------------------------------------------------------------------------- 
  271. -- Slides background out of view... 
  272. -- 
  273. function bg_saints_slide_out(new_end_x) 
  274. 	local bg_h = vint_object_find( "bg", 0, Bg_saints_doc_handle ) 
  275. 	local shadow_h = vint_object_find( "shadow_group", 0, Bg_saints_doc_handle ) 
  276. 	local left_shadow_h = vint_object_find( "left_shadow", 0, Bg_saints_doc_handle ) 
  277. 	vint_set_property(bg_h, "alpha", 1.0) 
  278. 	vint_set_property(shadow_h, "alpha", 0.5) 
  279. 	 
  280. 	local end_x = new_end_x or -1000 
  281. 	local bg_saints_mask_h = vint_object_find( "bg_saints_mask", 0, Bg_saints_doc_handle ) 
  282. 	local mask_x,mask_y = vint_get_property( bg_saints_mask_h, "anchor" ) 
  283. 	local mask_tween_h = vint_object_find( "mask_drop_twn_1_1", 0, Bg_saints_doc_handle ) 
  284. 	vint_set_property(mask_tween_h, "start_value", mask_x, mask_y) 
  285. 	vint_set_property(mask_tween_h, "end_value", end_x, mask_y) 
  286. 	 
  287. 	--be sure to offest the end positions so that the anims match up 
  288. 	local shadow_tween_h = vint_object_find("shadow_drop_twn_1_1", 0, Bg_saints_doc_handle) 
  289. 	local crap_x,shadow_y = vint_get_property(shadow_tween_h, "start_value") 
  290. 	local shadow_start_x,left_anchor_y = vint_get_property(left_shadow_h, "anchor") 
  291. 	--vint_set_property(shadow_tween_h, "start_value", 0, shadow_y) 
  292. 	vint_set_property(shadow_tween_h, "end_value", end_x - shadow_start_x, shadow_y) 
  293. 	 
  294. 	local anim = Vdo_anim_object:new("mask_slide_out_anim", 0, Bg_saints_doc_handle) 
  295. 	anim:play() 
  296. end 
  297.  
  298. ------------------------------------------------------------------------------- 
  299. -- Shows background 
  300. -- @param	is_visible 
  301. -- 
  302. function bg_saints_show( is_visible ) 
  303. 	local bg_saints_bg_h = vint_object_find( "bg", 0, Bg_saints_doc_handle ) 
  304. 	local bg_saints_shadow_h = vint_object_find( "shadow_group", 0, Bg_saints_doc_handle ) 
  305. 	vint_set_property( bg_saints_bg_h, "visible", is_visible ) 
  306. 	vint_set_property( bg_saints_shadow_h, "visible", is_visible ) 
  307. end 
  308.  
  309. ------------------------------------------------------------------------------- 
  310. -- Toggles the interface in background mode or not... 
  311. -- @param	is_visible 
  312. -- 
  313. function bg_saints_set_background(use_background) 
  314. 	local crib_bg_grp_h = vint_object_find("crib_bg_grp", 0, Bg_saints_doc_handle) 
  315. 	vint_set_property(crib_bg_grp_h, "background", use_background) 
  316. end 
  317.  
  318. ------------------------------------------------------------------------------- 
  319. -- Dims out everything behind bg saints... 
  320. -- @param	is_visible 
  321. -- 
  322. function bg_saints_dimmer_show( is_visible ) 
  323. 	local background_bmp_h = vint_object_find("background_bmp", 0, Bg_saints_doc_handle) 
  324. 	vint_set_property(background_bmp_h, "visible", is_visible) 
  325. end 
  326.  
  327. ------------------------------------------------------------------------------- 
  328. -- Sets video  
  329. -- @param	video_name 
  330. -- 
  331. function bg_saints_set_video( video_name ) 
  332. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle) 
  333. 	vint_set_property( bg_saints_video_h, "vid_name", video_name ) 
  334. end 
  335.  
  336. ------------------------------------------------------------------------------- 
  337. -- Plays video 
  338. -- @param	is_playing 
  339. -- 
  340. function bg_saints_play_video( is_playing, stop_callback ) 
  341. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  342. 	vint_set_property( bg_saints_video_h, "visible", is_playing ) 
  343. 	vint_set_property( bg_saints_video_h, "end_event", stop_callback )	 
  344.  
  345. 	if is_playing == false then 
  346. 		-- needed so we can unload it and steal its memories 
  347. 		vint_set_property( bg_saints_video_h, "is_stopped", true ) 
  348. 	else  
  349. 		vint_set_property( bg_saints_video_h, "is_paused", (not is_playing) ) 
  350. 	end 
  351. end 
  352.  
  353.  
  354. ------------------------------------------------------------------------------- 
  355. -- INTERFACE SPECIFIC FUNCTIONS 
  356. ------------------------------------------------------------------------------- 
  357. function bg_saints_stronghold_drop_out() 
  358. 	local anim_h = vint_object_find("mask_stronghold_out_anim", 0, Bg_saints_doc_handle) 
  359. 	lua_play_anim(anim_h, 0, Bg_saints_doc_handle) 
  360. end 
  361.  
  362.  
  363. ------------------------------------------------------------------------------- 
  364. -- MAIN MENU VIDEO CALLBACKS 
  365. ------------------------------------------------------------------------------- 
  366.  
  367. -- Press Start 
  368. function bg_saints_press_start_setup() 
  369. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  370. 	vint_set_property( bg_saints_video_h, "frame_event", "bg_saints_press_start_cb" ) 
  371. 	vint_set_property( bg_saints_video_h, "frame_event_num", PRESS_START_LOOP_END )	 
  372. end 
  373. 	 
  374. function bg_saints_press_start_cb() 
  375. 	thread_new("bg_saints_press_start_loop") 
  376. end 
  377.  
  378. function bg_saints_press_start_loop() 
  379. 	delay(0.1) 
  380. 	 
  381. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  382. 	vint_set_property( bg_saints_video_h, "frame", 1 )	 
  383. end 
  384.  
  385.  
  386. -- Main Menu 
  387. function bg_saints_main_menu_setup() 
  388. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  389. 	 
  390. 	--bg_saints_delay_trans() 
  391. 	vint_set_property( bg_saints_video_h, "frame", PRESS_START_TRANS_START) 
  392. 	 
  393. 	vint_set_property( bg_saints_video_h, "frame_event", "bg_saints_main_menu_cb" ) 
  394. 	vint_set_property( bg_saints_video_h, "frame_event_num", MAIN_MENU_LOOP_END )		 
  395. end 
  396.  
  397. -- function bg_saints_delay_trans() 
  398. 	-- thread_new("bg_saints_press_start_trans") 
  399. -- end 
  400.  
  401. -- function bg_saints_press_start_trans() 
  402. 	-- delay(0.1) 
  403. 	 
  404. 	-- local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  405. 	 
  406. 	-- vint_set_property( bg_saints_video_h, "frame", PRESS_START_TRANS_START )			 
  407. -- end 
  408.  
  409. function bg_saints_main_menu_cb() 
  410. 	thread_new("bg_saints_main_menu_loop") 
  411. end 
  412.  
  413. function bg_saints_main_menu_loop() 
  414. 	delay(0.005) 
  415. 	 
  416. 	local bg_saints_video_h = vint_object_find( "bg_video", 0, Bg_saints_doc_handle ) 
  417. 	vint_set_property( bg_saints_video_h, "frame", MAIN_MENU_LOOP_START ) 
  418. end 
  419.  
  420.  
  421.