./credits.lua

  1. ------------- 
  2. -- CREDITS -- 
  3. ------------- 
  4. -- Credits Constants 
  5. --Movement Constants 
  6. CREDITS_PIXELS_PER_SEC_MAX 	= 480 
  7. CREDITS_PIXELS_PER_SEC_MAX_PC = 480 
  8. CREDITS_PIXELS_PER_SEC_NORMAL = 50  
  9. CREDITS_PIXELS_PER_SEC_MIN 	= 5 
  10.  
  11. -- Enum types for credits 
  12. local CREDITS_TYPE_HEADER		=	0 
  13. local CREDITS_TYPE_HEADER_SUB	=	1 
  14. local CREDITS_TYPE_ROLE_NAME	=	2 
  15. local CREDITS_TYPE_MUSIC		=	3 
  16. local CREDITS_TYPE_IMAGE		=	4 
  17. local CREDITS_TYPE_CENTERED	=	5 
  18.  
  19. local CREDITS_FINISHED_TOKEN	= 100 
  20.  
  21. local Credits_finished = false 
  22. local Credit_skipped = false 
  23. local Input_tracker 
  24.  
  25.  
  26.  
  27.  
  28. -------------------------------------- 
  29. --Defines spacing above each item... 
  30. -------------------------------------- 
  31. local CREDIT_OBJECT_FORMATTING = { 
  32. 	[CREDITS_TYPE_HEADER] = { 
  33. 			base_grp = "credit_header_grp",			-- Base group in the vint doc... 
  34. 			txt_objects = {"header_txt"},				-- Text object in the base group... 
  35. 			stacked = false,								-- If the items are stacked or set side to side. 
  36. 			[CREDITS_TYPE_HEADER] = 70,				-- Spacing to set from bottom of this item type... 
  37. 			[CREDITS_TYPE_HEADER_SUB] = 70, 
  38. 			[CREDITS_TYPE_ROLE_NAME] = 70, 
  39. 			[CREDITS_TYPE_MUSIC] = 70, 
  40. 			[CREDITS_TYPE_CENTERED] = 70, 
  41. 			[CREDITS_TYPE_IMAGE] = 30, 
  42. 		}, 
  43. 	[CREDITS_TYPE_HEADER_SUB] = { 
  44. 			base_grp = "credit_header_sub_grp", 
  45. 			txt_objects = {"header_sub_txt"}, 
  46. 			stacked = false, 
  47. 			[CREDITS_TYPE_HEADER] = 30, 
  48. 			[CREDITS_TYPE_HEADER_SUB] = 65, 
  49. 			[CREDITS_TYPE_ROLE_NAME] = 70, 
  50. 			[CREDITS_TYPE_MUSIC] = 70, 
  51. 			[CREDITS_TYPE_CENTERED] = 70, 
  52. 			[CREDITS_TYPE_IMAGE] = 30, 
  53. 		}, 
  54. 	[CREDITS_TYPE_ROLE_NAME] = { 
  55. 			base_grp = "credit_role_name_grp", 
  56. 			txt_objects = {"role_txt", "name_txt"}, 
  57. 			stacked = false, 
  58. 			[CREDITS_TYPE_HEADER] = 20, 
  59. 			[CREDITS_TYPE_HEADER_SUB] = 25, 
  60. 			[CREDITS_TYPE_ROLE_NAME] = 0, 
  61. 			[CREDITS_TYPE_MUSIC] = 35, 
  62. 			[CREDITS_TYPE_CENTERED] = 35, 
  63. 			[CREDITS_TYPE_IMAGE] = 30, 
  64. 		}, 
  65. 	[CREDITS_TYPE_MUSIC] = { 
  66. 			base_grp = "credit_music_grp", 
  67. 			txt_objects = {"song_name_txt", "description_txt"}, 
  68. 			stacked = true, 
  69. 			[CREDITS_TYPE_HEADER] = 20, 
  70. 			[CREDITS_TYPE_HEADER_SUB] = 25, 
  71. 			[CREDITS_TYPE_ROLE_NAME] = 35, 
  72. 			[CREDITS_TYPE_MUSIC] = 35, 
  73. 			[CREDITS_TYPE_CENTERED] = 35, 
  74. 			[CREDITS_TYPE_IMAGE] = 30, 
  75. 		}, 
  76. 	[CREDITS_TYPE_IMAGE] = { 
  77. 			base_grp = "credit_image_grp", 
  78. 			img_object = "image_bmp", 
  79. 			[CREDITS_TYPE_HEADER] = 20, 
  80. 			[CREDITS_TYPE_HEADER_SUB] = 25, 
  81. 			[CREDITS_TYPE_ROLE_NAME] = 35, 
  82. 			[CREDITS_TYPE_MUSIC] = 35, 
  83. 			[CREDITS_TYPE_CENTERED] = 35, 
  84. 			[CREDITS_TYPE_IMAGE] = 30, 
  85. 		}, 
  86. 	[CREDITS_TYPE_CENTERED] = { 
  87. 			base_grp = "credit_centered_grp", 
  88. 			txt_objects = {"centered_txt"}, 
  89. 			stacked = false, 
  90. 			[CREDITS_TYPE_HEADER] = 20, 
  91. 			[CREDITS_TYPE_HEADER_SUB] = 25, 
  92. 			[CREDITS_TYPE_ROLE_NAME] = 35, 
  93. 			[CREDITS_TYPE_MUSIC] = 35, 
  94. 			[CREDITS_TYPE_CENTERED] = 0, 
  95. 			[CREDITS_TYPE_IMAGE] = 30, 
  96. 		}, 
  97. } 
  98.  
  99. --General Constants 
  100. CREDITS_HALF_SCREEN_HEIGHT = 360 
  101. CREDITS_SCREEN_LEEWAY_TOP 				= 50 
  102. CREDITS_SCREEN_LEEWAY_BOTTOM 			= 250 
  103. CREDITS_IMAGE_SCREEN_LEEWAY_TOP		= 50 
  104. CREDITS_IMAGE_SCREEN_LEEWAY_BOTTOM 	= 250 
  105.  
  106.  
  107. Credits_images = { 
  108. 	"ui_credits_001", 
  109. 	"ui_credits_002", 
  110. 	"ui_credits_003", 
  111. 	"ui_credits_004", 
  112. 	"ui_credits_005", 
  113. 	"ui_credits_006", 
  114. 	"ui_credits_007", 
  115. 	"ui_credits_008", 
  116. 	"ui_credits_009", 
  117. 	"ui_credits_010", 
  118. 	"ui_credits_011", 
  119. 	"ui_credits_012", 
  120. 	"ui_credits_013", 
  121. 	"ui_credits_014", 
  122. 	"ui_credits_015", 
  123. 	"ui_credits_016", 
  124. 	"ui_credits_017", 
  125. 	"ui_credits_018", 
  126. 	"ui_credits_019", 
  127. 	"ui_credits_020", 
  128. 	"ui_credits_021", 
  129. 	"ui_credits_022", 
  130. 	"ui_credits_023", 
  131. 	"ui_credits_024", 
  132. 	"ui_credits_025", 
  133. 	"ui_credits_026", 
  134. 	"ui_credits_027", 
  135. 	"ui_credits_028", 
  136. 	"ui_credits_029", 
  137. 	"ui_credits_030", 
  138. 	"ui_credits_031", 
  139. 	"ui_credits_032", 
  140. 	"ui_credits_033", 
  141. 	"ui_credits_034", 
  142. 	"ui_credits_035", 
  143. 	"ui_credits_036", 
  144. 	"ui_credits_037", 
  145. 	"ui_credits_038", 
  146. 	"ui_credits_039", 
  147. 	"ui_credits_040", 
  148. 	"ui_credits_041", 
  149. 	"ui_credits_042", 
  150. 	"ui_credits_043", 
  151. 	"ui_credits_044", 
  152. 	"ui_credits_045", 
  153. 	"ui_credits_046", 
  154. 	"ui_credits_047", 
  155. 	"ui_credits_048", 
  156. 	"ui_credits_049", 
  157. 	"ui_credits_050",	 
  158. 	"ui_credits_051", 
  159. 	"ui_credits_052", 
  160. 	"ui_credits_053", 
  161. 	"ui_credits_054", 
  162. 	"ui_credits_055", 
  163. 	"ui_credits_056", 
  164. 	"ui_credits_057", 
  165. 	"ui_credits_058", 
  166. 	"ui_credits_059", 
  167. 	"ui_credits_060",	 
  168. 	"ui_credits_061", 
  169. 	"ui_credits_062", 
  170. 	"ui_credits_063", 
  171. 	"ui_credits_064", 
  172. 	"ui_credits_065", 
  173. 	"ui_credits_066", 
  174. 	"ui_credits_067", 
  175. 	"ui_credits_068", 
  176. 	"ui_credits_069", 
  177. 	"ui_credits_070",		 
  178. 	"ui_credits_071", 
  179. 	"ui_credits_072", 
  180. 	"ui_credits_073", 
  181. 	"ui_credits_074", 
  182. 	"ui_credits_075", 
  183. 	"ui_credits_076", 
  184. 	"ui_credits_077", 
  185. 	"ui_credits_078", 
  186. 	"ui_credits_079", 
  187. 	"ui_credits_080",	 
  188. 	"ui_credits_081", 
  189. 	"ui_credits_082", 
  190. 	"ui_credits_083", 
  191. 	"ui_credits_084", 
  192. } 
  193.  
  194.  
  195. --init text size globals 
  196. Credits_cur_idx = -1				--Current credit index... 
  197. Credits_oldest_idx = 0			 
  198. Credits_cur_slide_pos = 400	--Position of slide... 400 starts us off the bottom of the screen... 
  199. Credits_num_items = 0			--Num Items 
  200. Credits_scroll_speed = CREDITS_PIXELS_PER_SEC_NORMAL 
  201. Credits_skip_available  = true 
  202.  
  203. Credits_objects = {} 
  204.  
  205. Credits = {} 
  206. Credits_data = { } 
  207.  
  208. --Credits Reel (aka images) 
  209. CREDITS_REEL_IMG_SPACING  = 20			--Spacing between reel images... 
  210. CREDITS_REEL_IMG_HEIGHT  = 169			--Height of reel image... 
  211. Credits_reel_cur_idx = -1					--Current credit index... 
  212. Credits_reel_oldest_idx = 0 
  213. Credits_reel_cur_slide_pos = 640			--Position of slide... 600 starts us a bit below the log. 
  214. Credits_reel_num_items = 0	--Num Items 
  215. Credits_reel_data = {} 
  216.  
  217. local Credits_reel_load_queue = {}		--Images that we are loading... 
  218. local Credits_reel_load_num = 0			--# Images that we plan to load 
  219. local Credits_reel_loaded_num = 0		--# Images that loaded... 
  220.  
  221. Credits_inverse_scale			= 1.0 
  222. Credits_reel_inverse_scale		= 1.0 
  223.  
  224. --[[ 
  225. 	-- Comment Used as reference.... 
  226. 	Credits_data = { 
  227. 		[0] = {type = CREDITS_TYPE_HEADER, 			data = {"Volition"}}, 
  228. 		[1] = {type = CREDITS_TYPE_HEADER_SUB, 	data = {"Leads"}}, 
  229. 		[2] = {type = CREDITS_TYPE_ROLE_NAME, 		data = {"Producer", "Gred Donovan"}}, 
  230. 		[3] = {type = CREDITS_TYPE_ROLE_NAME, 		data = {"Product Technical Director", "Nick Lee"}}, 
  231. 		[4] = {type = CREDITS_TYPE_ROLE_NAME, 		data = {"Programmer", "David Absug"}}, 
  232. 		[5] = {type = CREDITS_TYPE_ROLE_NAME,		data = {"Programmer", "Jim Brennan"}}, 
  233. 		[6] = {type = CREDITS_TYPE_ROLE_NAME, 		data = {"Programmer", "John Buckley"}}, 
  234. 		[7] = {type = CREDITS_TYPE_MUSIC,			data = {"This is how we do it", "Performed by Jesus Christ Superstar. This covers any SR2 specific technical details that need to be documented. Things pertaining to how parts of the"}}, 
  235. 		[8] = {type = CREDITS_TYPE_MUSIC, 			data = {"Dear Maria, Count Me In", "Performed by All Time Low. Concerts, album reviews, pop, jazz and classical music news from the Los Angeles Times."}}, 
  236. 		[9] = {type = CREDITS_TYPE_MUSIC, 			data = {"Sorry", "Peformed by Buck Cherry. Check out new bands and artists on MySpace Music: Watch music videos, check out concerts and tour dates, music, news and more."}}, 
  237. 	} 
  238. 	Credits_num_items = 10 
  239. ]] 
  240.  
  241. Credits_thread = -1			--Thread for credits processing.... 
  242. Credits_reel_thread = -1			--Thread for credits processing.... 
  243. Credits_is_in_game = false 
  244.  
  245.  
  246. function credits_init() 
  247. 	 
  248. 	--Check to see if we are in game... 
  249. 	if vint_document_find("main_menu_common") == 0 then 
  250. 		Credits_is_in_game = true  
  251. 	else 
  252. 		audio_object_post_event("Credits_main_menu", nil, nil, nil, false) 
  253. 	end 
  254. 	 
  255. 	--Dumping pause map if in game... 
  256. 	if Credits_is_in_game then 
  257. 		pause_map_dump() 
  258. 	end 
  259. 	 
  260. 	if vint_is_std_res() then 
  261. 		--Must scale overides in the document 
  262. 		Credits_inverse_scale		= 1/.55 
  263. 		Credits_reel_inverse_scale	= 1/.48		 
  264. 	end 
  265. 	 
  266. 	Credits_objects = {} 
  267. 	 
  268. 	--Build image table from out list (This just makes coding easier) 
  269. 	for idx, img in pairs(Credits_images) do 
  270. 		Credits_reel_data[Credits_reel_num_items] = { img = img } 
  271. 		Credits_reel_num_items = Credits_reel_num_items + 1 
  272. 	end 
  273. 	--Wipe out original credits table... 
  274. 	Credits_images = {} 
  275. 	 
  276. 	--Template Elements 
  277. 	Credits_objects.credits_base_h = vint_object_find("credits_base_grp") 
  278. 	Credits_objects.credits_slide_h = vint_object_find("credits_slide_grp") 
  279. 	Credits_objects.credits_reel_slide_h = vint_object_find("credits_reel_slide_grp") 
  280. 	 
  281. 	--Hide all base objects 
  282. 	for idx, val in pairs(CREDIT_OBJECT_FORMATTING) do 
  283. 		local base_grp_h = vint_object_find(val.base_grp) 
  284. 		vint_set_property(base_grp_h, "visible", false) 
  285. 	end 
  286.  
  287. 	--Hide reel base object... 
  288. 	local h = vint_object_find("reel_bmp", Credits_objects.credits_reel_slide_h) 
  289. 	vint_set_property(h, "visible", false) 
  290. 	 
  291. 	--logo img placeholder 
  292. 	Credits_objects.logo = vint_object_find("credit_logo") 
  293.  
  294. 	--populate first item with image... 
  295. 	Credits_data[Credits_num_items] = { type = CREDITS_TYPE_IMAGE, data = {"ui_credits_logo"} } 
  296. 	Credits_num_items = Credits_num_items + 1 
  297. 	 
  298. 	--Download 50 of the first credits... 
  299. 	vint_dataresponder_request("credits_grab_credits", "credits_populate", 50) 
  300. 	 
  301. 	--Start thread for credits processing.... 
  302. 	Credits_thread = thread_new("credits_process") 
  303. 	Credits_reel_thread = thread_new("credits_reel_process") 
  304. 	 
  305. 	--hide background layers... 
  306. 	local background_base_bg_h = vint_object_find("background_base_bg") 
  307. 	local credits_bg_grp_h = vint_object_find("credits_bg_grp") 
  308. 	vint_set_property(background_base_bg_h, "alpha", 0) 
  309. 	vint_set_property(credits_bg_grp_h, "alpha", 0) 
  310. 	 
  311. 	--Is the main menu loaded? if so do not delay background fade in. 
  312. 	 
  313. 	if Credits_is_in_game then 
  314. 		--Fade in background. 
  315. 		local anim_h = vint_object_find("credits_bg_game_fade_in") 
  316. 		lua_play_anim(anim_h)	--delay background fade in by 2 seconds... 
  317. 	else 
  318. 		--We are in main menu, play different anim 
  319. 		local anim_h = vint_object_find("credits_bg_main_menu_fade_in") 
  320. 		lua_play_anim(anim_h) 
  321. 	end 
  322. 	 
  323. 	local anim = vint_object_find("credit_bg_loop_anim") 
  324. 	lua_play_anim(anim,0) 
  325. 	 
  326. 	--Subscribe to input... 
  327. 	Input_tracker = Vdo_input_tracker:new() 
  328. 	Input_tracker:add_input("select", "credits_button_b", 50) 
  329. 	Input_tracker:add_input("back", "credits_button_b", 50) 
  330. 	Input_tracker:add_input("map", "credits_button_b", 50) 
  331. 	Input_tracker:add_input("inventory_y", "credits_input_stick", 50, true) 
  332. 	 
  333. 	if game_get_platform() == "PC" then 
  334. 		Input_tracker:add_input("key_down", "credits_input_faster", 50) 
  335. 		Input_tracker:add_input("key_up", "credits_input_slower", 50) 
  336. 	end 
  337.  
  338. 	Input_tracker:subscribe(true) 
  339. end 
  340.  
  341. function credits_cleanup() 
  342. 	-- stop audio 
  343. 	audio_object_post_event("Credits_stop", nil, nil, nil, false) 
  344. 	 
  345. 	---Cleanup any loaded pegs from our image reel... 
  346. 	for idx, val in pairs(Credits_reel_load_queue) do 
  347. 		if val ~= nil then 
  348. 			game_peg_unload(val.image_name) 
  349. 		end 
  350. 	end 
  351.  
  352. 	-- If we are in game we need to restore the pause map... 
  353. 	if Credits_is_in_game then 
  354. 		local cte_news_doc = vint_document_find("cte_news") 
  355. 		if cte_news_doc == 0 then 
  356. 			--restore pause map... 
  357. 			pause_map_restore() 
  358. 		end 
  359. 	end	 
  360.  
  361. 	if Credits_thread ~= -1 then 
  362. 		thread_kill(Credits_thread) 
  363. 	end 
  364. 	 
  365. 	if Credits_reel_thread ~= -1 then 
  366. 		thread_kill(Credits_reel_thread) 
  367. 	end 
  368. 	 
  369. 	Input_tracker:subscribe(false) 
  370. end 
  371.  
  372. ------------------------------------------------------------------------------- 
  373. -- Populates the credits... 
  374. -- 
  375. function credits_populate(item_type, str1, str2) 
  376. 	if item_type == CREDITS_FINISHED_TOKEN then 
  377. 		Credits_finished = true 
  378. 		return 
  379. 	end 
  380.  
  381. 	--If string is empty skip this credit... 
  382. 	if str1 == "" or  str1 == nil then 
  383. 		Credit_skipped = true 
  384. 		return 
  385. 	end 
  386. 	 
  387. 	Credits_data[Credits_num_items] = { type = item_type, y = -1 } 
  388. 	 
  389. 	if str2 ~= nil then  
  390. 		if item_type == CREDITS_TYPE_ROLE_NAME then 
  391. 			Credits_data[Credits_num_items].data = { str2, str1 } 
  392. 		else 
  393. 			Credits_data[Credits_num_items].data = { str1, str2 } 
  394. 		end 
  395. 	else 
  396. 		Credits_data[Credits_num_items].data = { str1 } 
  397. 	end 
  398. 	Credits_num_items = Credits_num_items + 1 
  399. end 
  400.  
  401. -------------------------------------------------------------------------------- 
  402. -- Credits process thread... used for formatting and moving the credits.... 
  403. -------------------------------------------------------------------------------- 
  404. function credits_process() 
  405. 	 
  406. 	local move_amount = 0 
  407. 	 
  408. 	local prev_item, new_item, credit_h, h, item_width, item_height, prev_height, prev_item_y, item_y 
  409. 	local create_new_item = false 
  410. 	local credits_play = true 
  411. 	 
  412. 	while credits_play do 
  413. 		--move credits 
  414. 		move_amount = Credits_scroll_speed * get_frame_time() 
  415. 		 
  416. 		--Slide Credits up 
  417. 		Credits_cur_slide_pos = Credits_cur_slide_pos - move_amount 
  418. 		vint_set_property(Credits_objects.credits_slide_h, "anchor", 0, Credits_cur_slide_pos) 
  419. 	 
  420. 		--Is the first top item off the screen?	 
  421. 		if Credits_cur_idx < 0 then 
  422. 			--Initialize always create first item... 
  423. 			create_new_item = true 
  424. 		else 
  425. 			--Remove first item? 
  426. 			local actual_slide_pos = Credits_cur_slide_pos + CREDITS_HALF_SCREEN_HEIGHT  
  427. 			 
  428. 			if Credits_data[Credits_oldest_idx] ~= nil then	 
  429. 				if actual_slide_pos <  (Credits_data[Credits_oldest_idx].y + (Credits_data[Credits_oldest_idx].height * Credits_inverse_scale) + CREDITS_SCREEN_LEEWAY_TOP) * -1 then 
  430. 					--Lets kill it 
  431. 					if Credits_data[Credits_oldest_idx].credit_h ~= nil then 
  432. 						vint_object_destroy(Credits_data[Credits_oldest_idx].credit_h) 
  433. 					end 
  434. 					 
  435. 					Credits_data[Credits_oldest_idx] = nil 
  436. 					Credits_oldest_idx = Credits_oldest_idx + 1 
  437. 					 
  438. 					--Attempt to Get the next credit... 
  439. 					if Credits_finished ~= true then 
  440. 						Credit_skipped = true 
  441. 						while Credit_skipped == true do 
  442. 							Credit_skipped = false 
  443. 							vint_dataresponder_request("credits_grab_credits", "credits_populate", 1) 
  444. 						end 
  445. 					end 
  446. 					 
  447. 					--Are credits complete? 
  448. 					if Credits_num_items == Credits_oldest_idx then 
  449. 						--Credits complete 
  450. 						credits_complete() 
  451. 						credits_play = false 
  452. 					end 
  453. 				end 
  454. 			end	 
  455.  
  456. 			if Credits_data[Credits_cur_idx] ~= nil then		 
  457. 				--Build next item 
  458. 				local next_item_build_at = (Credits_data[Credits_cur_idx].y + Credits_data[Credits_cur_idx].height) * -1 
  459. 				actual_slide_pos = Credits_cur_slide_pos - CREDITS_HALF_SCREEN_HEIGHT  
  460. 				if actual_slide_pos < next_item_build_at + CREDITS_SCREEN_LEEWAY_BOTTOM then 
  461. 					create_new_item = true  
  462. 				end 
  463. 			end 
  464. 		end 
  465. 		 
  466. 		--Should I create an item on the bottom? 
  467. 		if create_new_item == true then 
  468. 			--What is the new item going to be? 
  469. 			local next_index = Credits_cur_idx + 1 
  470. 			new_item = Credits_data[next_index] 
  471. 			 
  472. 			if new_item ~= nil and next_index <= Credits_num_items then 
  473. 				--store new index to global. 
  474. 				Credits_cur_idx = next_index 
  475. 	 
  476. 				--get item type, data and formatting for that item... 
  477. 				local item_type = new_item.type 
  478. 				local item_data = new_item.data 
  479. 				local credit_object_format = CREDIT_OBJECT_FORMATTING[item_type] 
  480. 					 
  481. 				--find our base object 
  482. 				local base_grp = credit_object_format.base_grp 
  483. 				local base_grp_h = vint_object_find(base_grp)  
  484. 					 
  485. 				--Clone it... 
  486. 				local base_grp_clone_h = vint_object_clone(base_grp_h) 
  487. 				 
  488. 				local height = 0 
  489. 				 
  490. 				if item_type == CREDITS_TYPE_IMAGE then 
  491. 					--Image Type 
  492. 					local image_h = vint_object_find("img_bmp", base_grp_clone_h) 
  493. 					local image_name = item_data[1] 
  494. 					 
  495. 					vint_set_property(image_h, "image", image_name) 
  496. 					local image_width, image_height = element_get_actual_size(image_h) 
  497. 					height = image_height 
  498. 				else 
  499. 					--All other types... 
  500. 					local txt_objects = credit_object_format.txt_objects 
  501. 					local num_txt_objects = #txt_objects 
  502. 					 
  503. 					for i = 1, num_txt_objects do 
  504. 						local txt_object = txt_objects[i] 
  505. 						 
  506. 						--Find our text object... 
  507. 						local txt_object_h = vint_object_find(txt_object, base_grp_clone_h) 
  508. 						 
  509. 						local txt_data = item_data[i] 
  510. 						 
  511. 						--Set text tag... 
  512. 						vint_set_property(txt_object_h, "text_tag", txt_data) 
  513. 						 
  514. 						--calculate height... 
  515. 						if txt_data ~= "" then 
  516. 							--only calculate height on credit items with strings in them... 
  517. 							local text_width, text_height = element_get_actual_size(txt_object_h) 
  518. 							 
  519. 							--move name down on wrapped roles 
  520. 							if item_type == CREDITS_TYPE_ROLE_NAME then 
  521. 								if i == 1 then 
  522. 									local next_txt_object_h = vint_object_find(txt_objects[i+1], base_grp_clone_h) 
  523. 									local role_width, role_height = element_get_actual_size(txt_object_h) 
  524. 									local name_width, name_height = element_get_actual_size(next_txt_object_h) 
  525. 									if txt_object == "role_txt" and role_height > name_height then 
  526. 										local x, y = vint_get_property(next_txt_object_h, "anchor") 
  527. 										local name_move = y + (role_height - name_height) 
  528. 										vint_set_property(next_txt_object_h, "anchor", x, name_move) 
  529. 									end 
  530. 								end 
  531. 							end 
  532. 							 
  533. 							if credit_object_format.stacked == true then 
  534. 								 
  535. 								if i > 1 then 
  536. 									--get original position 
  537. 									local x, y = vint_get_property(txt_object_h, "anchor") 
  538. 									 
  539. 									--shift y down... +3 offset for each item. 
  540. 									y = height + (3 * (i - 1)) 
  541. 									 
  542. 									--set new position 
  543. 									vint_set_property(txt_object_h, "anchor", x, y) 
  544. 								end 
  545. 								 
  546. 								--stacked... add heights... 
  547. 								height = height + text_height 
  548. 							else 
  549. 								--Not stacked... figure out largest height... 
  550. 								height = max(height, text_height) 
  551. 							end 
  552. 						end 
  553. 					end 
  554. 					 
  555. 				end 
  556. 				 
  557. 				 
  558. 				--Reassign parent and set visible... 
  559. 				vint_object_set_parent(base_grp_clone_h, Credits_objects.credits_slide_h) 
  560. 				vint_set_property(base_grp_clone_h, "visible", true) 
  561. 				 
  562. 				--Calculate y from previous item data 
  563. 				prev_item = Credits_data[Credits_cur_idx - 1] 
  564. 				 
  565. 				if prev_item == nil then 
  566. 					--no item, so we always start at 0. 
  567. 					item_y = 0 
  568. 				else 
  569. 					local prev_type = prev_item.type 
  570. 					local vertical_spacing = credit_object_format[prev_type]		--get spacing from our previous object type... 
  571. 					local prev_height = prev_item.height								--get height of previous item...					 
  572. 					item_y = prev_item.y + prev_height + vertical_spacing			--add previous item y + height + spacing. 
  573. 				end 
  574. 				 
  575. 				--Position object 
  576. 				vint_set_property(base_grp_clone_h, "anchor", 0, item_y) 
  577. 				 
  578. 				--store off the new object for processing and cleanup... 
  579. 				new_item.credit_h = base_grp_clone_h 
  580. 				new_item.height = height  
  581. 				new_item.type = item_type  
  582. 				new_item.y = item_y  
  583. 			end 
  584. 			 
  585. 			--Do not create the next item automatically 
  586. 			create_new_item = false 
  587. 		end 
  588. 		thread_yield() 
  589. 	end 
  590. end 
  591.  
  592. -------------------------------------------------------------------------------- 
  593. -- Reel Slide 
  594. -------------------------------------------------------------------------------- 
  595. function credits_reel_process() 
  596. 	 
  597. 	local move_amount = 0 
  598. 	 
  599. 	local prev_item, new_item, credit_h, h, item_width, item_height, prev_item_height, prev_item_y, item_y 
  600. 	local next_item_build_at = 0 
  601. 	local create_new_item = false 
  602. 	local credits_play = true 
  603. 	 
  604. 	while credits_play do 
  605. 		--move Reel... 
  606. 		 
  607. 		--Reel moves at half speed of normal credit speed... 
  608. 		move_amount = Credits_scroll_speed * get_frame_time() *.5 
  609. 		 
  610. 		--Slide Credits up 
  611. 		Credits_reel_cur_slide_pos = Credits_reel_cur_slide_pos - move_amount 
  612. 		vint_set_property(Credits_objects.credits_reel_slide_h, "anchor", 0, Credits_reel_cur_slide_pos) 
  613. 		 
  614. 		--Is the first top item off the screen?	 
  615. 		if Credits_reel_cur_idx < 0 then 
  616. 			--Initialize always create first item... 
  617. 			create_new_item = true 
  618. 		else 
  619. 			--Remove first item? 
  620. 			local actual_slide_pos = Credits_reel_cur_slide_pos + CREDITS_HALF_SCREEN_HEIGHT  
  621. 			 
  622. 			if Credits_reel_data[Credits_reel_oldest_idx] ~= nil then	 
  623. 				if actual_slide_pos <  (Credits_reel_data[Credits_reel_oldest_idx].y + (CREDITS_REEL_IMG_HEIGHT * Credits_reel_inverse_scale) + CREDITS_IMAGE_SCREEN_LEEWAY_TOP) * -1 then 
  624. 					--Lets kill it 
  625. 					if Credits_reel_data[Credits_reel_oldest_idx].img_h ~= nil then 
  626. 						local image_data = Credits_reel_data[Credits_reel_oldest_idx] 
  627. 						vint_object_destroy(image_data.img_h) 
  628. 						game_peg_unload(image_data.img) 
  629. 						 
  630. 						Credits_reel_load_queue[image_data.queue_num] = nil 
  631. 					end 
  632. 					 
  633. 					Credits_reel_data[Credits_reel_oldest_idx] = nil 
  634. 					Credits_reel_oldest_idx = Credits_reel_oldest_idx + 1 
  635. 					 
  636. 					--Are credits complete? 
  637. 					if Credits_reel_num_items == Credits_reel_oldest_idx then 
  638. 						--Credit reel complete... 
  639. 						credits_play = false 
  640. 					end 
  641. 				end 
  642. 			end	 
  643. 			if Credits_reel_data[Credits_reel_cur_idx] ~= nil then		 
  644. 				actual_slide_pos = Credits_reel_cur_slide_pos - CREDITS_HALF_SCREEN_HEIGHT  
  645. 				if actual_slide_pos < next_item_build_at + CREDITS_IMAGE_SCREEN_LEEWAY_BOTTOM then				 
  646. 					create_new_item = true  
  647. 				end 
  648. 			end 
  649. 		end 
  650.  
  651. 		--Should I create an item on the bottom? 
  652. 		if create_new_item == true then 
  653. 			--What is the new item going to be? 
  654. 			local next_idx = Credits_reel_cur_idx + 1 
  655. 			new_item = Credits_reel_data[next_idx] 
  656. 			 
  657. 			if new_item ~= nil and next_idx <= Credits_reel_num_items then	 
  658. 				--store current index to global... 
  659. 				Credits_reel_cur_idx = next_idx 
  660. 				 
  661. 				local image_name = Credits_reel_data[Credits_reel_cur_idx].img 
  662. 		 
  663. 				--Position Image 
  664. 				local base_image_h = vint_object_find("reel_bmp", Credits_objects.credits_reel_slide_h) 
  665. 				 
  666. 				--Clone image base 
  667. 				local image_clone_h = vint_object_clone(base_image_h) 
  668. 				vint_object_set_parent(image_clone_h, Credits_objects.credits_reel_slide_h) 
  669. 				vint_set_property(image_clone_h, "visible", true) 
  670.  
  671. 				--Stream in the next image... 
  672. 				local queue_num = Credits_reel_load_num 
  673. 				game_peg_load_with_cb("credits_reel_peg_loaded", 1, image_name) 
  674. 				Credits_reel_load_queue[queue_num] = { image_name = image_name, image_h = image_clone_h} 
  675. 				Credits_reel_load_num = Credits_reel_load_num + 1 
  676. 				 
  677. 				--Position it. 
  678. 				 
  679. 				--Calculate y from previous item data 
  680. 				prev_item = Credits_reel_data[Credits_reel_cur_idx - 1] 
  681. 				if prev_item == nil then 
  682. 					--no item, so we always start at 0. 
  683. 					item_y = 0 
  684. 				else 
  685. 					item_y = prev_item.y + CREDITS_REEL_IMG_HEIGHT + CREDITS_REEL_IMG_SPACING --add previous item y + height + spacing. 
  686. 				end 
  687. 					 
  688. 				--Position object 
  689. 				vint_set_property(image_clone_h, "anchor", 0, item_y) 
  690. 				 
  691. 				--store off the new object for processing and cleanup... 
  692. 				new_item.img_h = image_clone_h 
  693. 				new_item.height = CREDITS_REEL_IMG_HEIGHT 
  694. 				new_item.queue_num = queue_num		--Store queue number so we can remove it from the list on peg unload... 
  695. 				 
  696. 				--Build next item 
  697. 				next_item_build_at = (item_y + CREDITS_REEL_IMG_HEIGHT) * -1 
  698. 				new_item.y = item_y  
  699. 			end 
  700. 			 
  701. 			--Do not create the next item automatically 
  702. 			create_new_item = false 
  703. 		end 
  704. 		thread_yield() 
  705. 	end 
  706. end 
  707.  
  708.  
  709. function credits_complete() 
  710. 	--Unsubscribe from controls 
  711. 	Input_tracker:subscribe(false) 
  712. 	 
  713. 	--Tell game that credits are done rolling 
  714. 	--TODO: Darryl needs to hook this in... 
  715. 	--credits_are_finished() 
  716. 	pop_screen() 
  717. end 
  718.  
  719. ---------------------------------- 
  720. --Input Functions 
  721. ---------------------------------- 
  722. function credits_input_stick(event, value) 
  723. 	if event == "inventory_y" then 
  724. 		--Adjust credit speed 
  725. 		if value > 0 then 
  726. 			Credits_scroll_speed = CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MIN - CREDITS_PIXELS_PER_SEC_NORMAL ) * value  
  727. 			 
  728. 		elseif value < 0 then 
  729. 		 
  730. 			Credits_scroll_speed = 	CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MAX - CREDITS_PIXELS_PER_SEC_NORMAL) * value * -1  
  731. 		else 
  732. 			Credits_scroll_speed = CREDITS_PIXELS_PER_SEC_NORMAL  
  733. 		end 
  734. 	end 
  735. end 
  736.  
  737.  
  738. function credits_input_faster(event) 
  739. 	local slow_speed = CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MIN - CREDITS_PIXELS_PER_SEC_NORMAL)  
  740. 	local fast_speed = CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MAX_PC - CREDITS_PIXELS_PER_SEC_NORMAL)  
  741. 	if Credits_scroll_speed == slow_speed then 
  742. 		Credits_scroll_speed = CREDITS_PIXELS_PER_SEC_NORMAL 
  743. 	elseif Credits_scroll_speed == CREDITS_PIXELS_PER_SEC_NORMAL then 
  744. 		Credits_scroll_speed = fast_speed 
  745. 	else 
  746. 		--Credits_scroll_speed = slow_speed 
  747. 	end 
  748. end 
  749.  
  750. function credits_input_slower(event) 
  751.  
  752. 	local slow_speed = CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MIN - CREDITS_PIXELS_PER_SEC_NORMAL)  
  753. 	local fast_speed = CREDITS_PIXELS_PER_SEC_NORMAL + (CREDITS_PIXELS_PER_SEC_MAX_PC - CREDITS_PIXELS_PER_SEC_NORMAL)  
  754. 	if Credits_scroll_speed == fast_speed then 
  755. 		Credits_scroll_speed = CREDITS_PIXELS_PER_SEC_NORMAL 
  756. 	elseif Credits_scroll_speed == CREDITS_PIXELS_PER_SEC_NORMAL then 
  757. 		Credits_scroll_speed = slow_speed 
  758. 	else 
  759. 		--Credits_scroll_speed = fast_speed 
  760. 	end 
  761. end 
  762.  
  763. function credits_button_b(event, acceleration) 
  764. 	--exit credits 
  765. 	credits_complete() 
  766. end 
  767.  
  768.  
  769. function credits_reel_peg_loaded() 
  770. 	--after images load then we have to set the image on the bitmap handle... 
  771. 	local image_info = Credits_reel_load_queue[Credits_reel_loaded_num] 
  772. 	if image_info == nil then 
  773. 		return 
  774. 	end 
  775. 	 
  776. 	local image_name = image_info.image_name 
  777. 	local image_h = image_info.image_h 
  778. 	vint_set_property(image_h, "image", image_name) 
  779.  
  780. 	Credits_reel_loaded_num = Credits_reel_loaded_num + 1 
  781. end 
  782. --[[ 
  783. OLD FUNCTIONALITY??? 
  784. function credits_input_btn(event, accelleration) 
  785. 	 
  786. 	if Credits_skip_available == true then 
  787. 		if event == "exit" then 
  788. 			credits_were_skipped() 
  789. 		elseif credits_in_cutscene() == false then 
  790. 			credits_complete() 
  791. 		end 
  792. 	end 
  793. end 
  794. ]] 
  795.