./pause_voice_tut.lua

  1. local PAUSE_VOICE_TUT_NUM_LINES 	= 10 
  2.  
  3. local Input_tracker 
  4. local Mouse_input_tracker 
  5. local Hint_bar 
  6.  
  7. local pause_voice_tut_doc_handle = -1 
  8. local pause_voice_tut_objects = { } 
  9. local pause_voice_tut_page = 1 
  10. local pause_voice_tut_num_pages = 1 
  11. local Num_stat_data = 0 
  12. local pause_voice_tut_data = { } 
  13. local Arrow_left 
  14. local Arrow_right 
  15. local Page_header 
  16.  
  17. local Screen_width 
  18. if vint_is_std_res() then 
  19. 	Screen_width = 750 
  20. else 
  21. 	Screen_width = 840 
  22. end 
  23.  
  24. function pause_voice_tut_init() 
  25. 	pause_voice_tut_doc_handle = vint_document_find("pause_voice_tut") 
  26.  
  27. 	-- Subscribe to the button presses we need 
  28. 	Input_tracker = Vdo_input_tracker:new() 
  29. 	Input_tracker:add_input("nav_left", "pause_voice_tut_nav_left", 50) 
  30. 	Input_tracker:add_input("nav_right", "pause_voice_tut_nav_right", 50) 
  31. 	Input_tracker:add_input("back", "pause_voice_tut_button_b", 50) 
  32. 	Input_tracker:add_input("map", "pause_voice_tut_button_map", 50) 
  33. 	-- unused 
  34. 	Input_tracker:add_input("nav_up", "pause_voice_tut_nav_nothing", 50) 
  35. 	Input_tracker:add_input("nav_down", "pause_voice_tut_nav_nothing", 50)	 
  36. 	Input_tracker:add_input("select", "pause_voice_tut_nav_nothing", 50) 
  37.  
  38. 	--hintbar... 
  39. 	local hint_data = { 
  40. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  41. 	} 
  42. 	 
  43. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  44. 	Hint_bar:set_hints(hint_data) 
  45.  
  46. 	--Set up title 
  47. 	local cell_title_h = Vdo_pause_header:new("cell_title", 0, pause_voice_tut_doc_handle) 
  48. 	cell_title_h:set_text("MENU_VOICE_TUT", Screen_width) 
  49. 	--cell_title_h:set_icon("ui_cell_icon_stats") 
  50. 	--cell_title_h:play_dots_anim() 
  51. 	 
  52. 	--add right and left group objects	 
  53. 	local label_grp_h = vint_object_find("label_grp", 0, pause_voice_tut_doc_handle) 
  54. 	local value_grp_h = vint_object_find("value_grp", 0, pause_voice_tut_doc_handle) 
  55. 	 
  56. 	for i = 1, PAUSE_VOICE_TUT_NUM_LINES do 
  57. 		pause_voice_tut_objects[i] = { 
  58. 			label_h = vint_object_find("label_" .. i, label_grp_h), 
  59. 			value_h = vint_object_find("value_" .. i, value_grp_h), 
  60. 		} 
  61. 	end 
  62. 	 
  63. 	-- populate the stats 
  64. 	vint_dataresponder_request("pause_voice_tut_populate", "pause_voice_tut_populate", 0) 
  65. 	pause_voice_tut_num_pages = Num_stat_data / PAUSE_VOICE_TUT_NUM_LINES 
  66. 	pause_voice_tut_page = 1 
  67. 	pause_voice_tut_show_page(pause_voice_tut_page) 
  68. 	 
  69. 	-- Add mouse input subscriptions for the PC 
  70. 	if game_get_platform() == "PC" then 
  71. 		Arrow_left = Vdo_base_object:new("arrow_l", 0, pause_voice_tut_doc_handle) 
  72. 		Arrow_right = Vdo_base_object:new("arrow_r", 0, pause_voice_tut_doc_handle) 
  73. 		Page_header =  Vdo_base_object:new("scroll_bg", 0, pause_voice_tut_doc_handle) 
  74. 		Hint_bar:set_highlight(0) 
  75. 	 
  76. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  77. 		Hint_bar:add_mouse_inputs("pause_voice_tut", Mouse_input_tracker)		 
  78. 		Mouse_input_tracker:add_mouse_input("mouse_move", "pause_voice_tut_mouse_move", 0, Page_header.handle) 
  79. 		Mouse_input_tracker:add_mouse_input("mouse_down", "pause_voice_tut_mouse_down", 0, Page_header.handle) 
  80. 		Mouse_input_tracker:add_mouse_input("mouse_click", "pause_voice_tut_mouse_click", 0, Page_header.handle) 
  81. 		Mouse_input_tracker:add_mouse_input("mouse_drag", "pause_voice_tut_mouse_drag", 0, Page_header.handle) 
  82. 		Mouse_input_tracker:add_mouse_input("mouse_drag_release", "pause_voice_tut_mouse_drag_release", 0, Page_header.handle) 
  83. 		Mouse_input_tracker:subscribe(false) 
  84. 	end 
  85. 	 
  86. 	--Transition the screen in... 
  87. 	--cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_STATS, CELL_SCREEN_EXTRAS, pause_voice_tut_unlock_controls) 
  88. 	--glitch 
  89. 	pause_voice_tut_unlock_controls() 
  90. 	glitch_cell() 
  91. end 
  92.  
  93. function pause_voice_tut_cleanup() 
  94. 	-- Nuke all button subscriptions 
  95. 	Input_tracker:subscribe(false) 
  96. 	 
  97. 	if Mouse_input_tracker ~= nil then 
  98. 		Mouse_input_tracker:subscribe(false) 
  99. 	end 
  100. end 
  101.  
  102. function pause_voice_tut_populate(display_name, has_value, value_str) 
  103. 	pause_voice_tut_data[Num_stat_data] = { } 
  104. 	pause_voice_tut_data[Num_stat_data].display_name = display_name 
  105. 	if has_value == 1 then 
  106. 		pause_voice_tut_data[Num_stat_data].value = value_str 
  107. 	end 
  108. 	Num_stat_data = Num_stat_data + 1 
  109. end 
  110.  
  111. function pause_voice_tut_show_page(page_idx) 
  112. 	local stat_index = (page_idx - 1) * PAUSE_VOICE_TUT_NUM_LINES 
  113. 	 
  114. 	for i = 1, PAUSE_VOICE_TUT_NUM_LINES do 
  115. 		if stat_index < Num_stat_data then 
  116. 			vint_set_property(pause_voice_tut_objects[i].label_h, "visible", true) 
  117. 			vint_set_property(pause_voice_tut_objects[i].label_h, "text_tag", pause_voice_tut_data[stat_index].display_name) 
  118. 			 
  119. 			--checks if label string is too long and scales 
  120. 			vint_set_property(pause_voice_tut_objects[i].label_h, "scale", 1,1) 
  121. 			local MAX_WIDTH_LABEL = 509 
  122. 			local text_width_label, text_height_label = element_get_actual_size(pause_voice_tut_objects[i].label_h) 
  123.  
  124. 			if text_width_label > MAX_WIDTH_LABEL then 
  125. 				local text_scale_label = MAX_WIDTH_LABEL/text_width_label 
  126. 				vint_set_property(pause_voice_tut_objects[i].label_h, "scale", text_scale_label,1) 
  127. 			end 
  128. 			 
  129. 			if pause_voice_tut_data[stat_index].value ~= nil then 
  130. 				vint_set_property(pause_voice_tut_objects[i].value_h, "visible", true) 
  131. 				vint_set_property(pause_voice_tut_objects[i].value_h, "text_tag", pause_voice_tut_data[stat_index].value) 
  132. 				 
  133. 				--checks if value string is too long and scales 
  134. 				vint_set_property(pause_voice_tut_objects[i].value_h, "scale", 1,1) 
  135. 				local MAX_WIDTH_VALUE = 408 
  136. 				local text_width_value, text_height_value = element_get_actual_size(pause_voice_tut_objects[i].value_h) 
  137.  
  138. 				if text_width_value > MAX_WIDTH_VALUE then 
  139. 					local text_scale_value = MAX_WIDTH_VALUE/text_width_value 
  140. 					vint_set_property(pause_voice_tut_objects[i].value_h, "scale", text_scale_value,1) 
  141. 				end 
  142. 				 
  143. 			else 
  144. 				vint_set_property(pause_voice_tut_objects[i].value_h, "visible", false) 
  145. 			end 
  146. 		else 
  147. 		 
  148. 			vint_set_property(pause_voice_tut_objects[i].label_h, "visible", false) 
  149. 			vint_set_property(pause_voice_tut_objects[i].value_h, "visible", false) 
  150. 		end 
  151. 		stat_index = stat_index + 1 
  152. 	end 
  153. 	 
  154. 	--pause_voice_tut_num_pages = 3 
  155. 	 
  156. 	--Sets the text in the scroll bar 
  157. 	local current_page_h = vint_object_find("current_page", 0, pause_voice_tut_doc_handle) 
  158. 	local total_page_round = ceil(pause_voice_tut_num_pages) 
  159. 	 
  160. 	local insert_values = {[0] = pause_voice_tut_page, [1] = total_page_round} 
  161. 	local stats_string = vint_insert_values_in_string("STATS_PAGE", insert_values) 
  162. 	vint_set_property(current_page_h, "text_tag", stats_string) 
  163. 	vint_set_property(current_page_h, "scale", 1,1) 
  164. 	local max_width = 130 
  165. 	local text_width, text_height = element_get_actual_size(current_page_h) 
  166.  
  167. 	if text_width > max_width then 
  168. 		local text_scale = max_width/text_width 
  169. 		vint_set_property(current_page_h, "scale", text_scale,1) 
  170. 	end 
  171.  
  172. 	 
  173. 	----------------------------------------------------------------- 
  174. 	--THIS EQUATION IS MAGIC, FOR THE LOVE OF GOD DON'T DELETE IT! 
  175. 	--sets scroll bar in correct spot 
  176. 	--629 is the width of the total bg minus the scroll bar (188) 
  177. 	--The -475 offsets it to the correct spot on the screen 
  178. 	----------------------------------------------------------------- 
  179. 	 
  180. 	--local scroll_pct = (((pause_voice_tut_page / total_page_round) * 629) - ((1 / total_page_round ) * 629))   +   ((((pause_voice_tut_page - 1) / total_page_round) / (total_page_round - 1)) * 629)  - 475    
  181. 	local scroll_pct = (((pause_voice_tut_page / total_page_round) * 629) - ((1 / total_page_round ) * 629))   +   ((((pause_voice_tut_page - 1) / total_page_round) / (total_page_round - 1)) * 629)  - 495    
  182. 	 
  183. 	local scroll_grp_h = vint_object_find("scroll_grp", 0, pause_voice_tut_doc_handle) 
  184. 	vint_set_property(scroll_grp_h, "anchor", scroll_pct, 20) 
  185. end 
  186.  
  187. MOUSE_DOWN = 0 
  188. local PAGE_SPACING 
  189. function cells_stats_adjust_page_position(mouse_diff_x, pure_mouse_x) 
  190. 	local moved = false; 
  191. 	PAGE_SPACING = 629 / (pause_voice_tut_num_pages + 1) 
  192. 	--local x = Page_header:get_anchor() 
  193. 	 
  194. 	if mouse_diff_x > PAGE_SPACING * 1.0 then 
  195. 		pause_voice_tut_nav_right() 
  196. 		moved = true 
  197. 	elseif mouse_diff_x < PAGE_SPACING * -1.0 then 
  198. 		pause_voice_tut_nav_left() 
  199. 		moved = true 
  200. 	end 
  201. 	if moved == true then 
  202. 		--x = Page_header:get_anchor() 
  203. 		MOUSE_DOWN = pure_mouse_x 
  204. 	end 
  205. end 
  206.  
  207. function pause_voice_tut_nav_left(event, acceleration) 
  208. 	if pause_voice_tut_page > 1 then 
  209. 		pause_voice_tut_page = pause_voice_tut_page - 1  
  210. 		pause_voice_tut_show_page(pause_voice_tut_page) 
  211. 		ui_audio_post_event("UI_Hub_Navigate") 
  212. 	end 
  213. end 
  214.  
  215. function pause_voice_tut_nav_right(event, acceleration) 
  216. 	if pause_voice_tut_page < pause_voice_tut_num_pages then 
  217. 		pause_voice_tut_page = pause_voice_tut_page + 1  
  218. 		pause_voice_tut_show_page(pause_voice_tut_page) 
  219. 		ui_audio_post_event("UI_Hub_Navigate") 
  220. 	end 
  221. end 
  222.  
  223. function pause_voice_tut_nav_nothing(event, accel) 
  224. end 
  225.  
  226. function pause_voice_tut_button_map(event, acceleration) 
  227. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  228. 	pause_voice_tut_lock_controls() 
  229. 	 
  230. 	--Transition the screen out 
  231. 	--cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_STATS, pause_voice_tut_exit_to_game) 
  232. end 
  233.  
  234. function pause_voice_tut_button_b(event, acceleration) 
  235. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  236. 	pause_voice_tut_lock_controls() 
  237. 	 
  238. 	--Transition the screen back 
  239. 	pop_screen() 
  240. end 
  241.  
  242. function pause_voice_tut_exit_to_extras() 
  243. 	pop_screen()	-- stats 
  244. end 
  245.  
  246. function pause_voice_tut_exit_to_game() 
  247. 	pop_screen()	-- stats 
  248. 	pop_screen()	-- extras 
  249. 	pop_screen()	-- main 
  250. 	pop_screen()	-- cell frame 
  251. end 
  252.  
  253. function pause_voice_tut_lock_controls() 
  254. 	Input_tracker:subscribe(false) 
  255. 	 
  256. 	if Mouse_input_tracker ~= nil then 
  257. 		Mouse_input_tracker:subscribe(false) 
  258. 	end 
  259. end 
  260.  
  261. function pause_voice_tut_unlock_controls() 
  262. 	Input_tracker:subscribe(true) 
  263. 	 
  264. 	if Mouse_input_tracker ~= nil then 
  265. 		Mouse_input_tracker:subscribe(true) 
  266. 	end 
  267. end 
  268.  
  269. function pause_voice_tut_mouse_click(event, target_handle) 
  270. 	-- First check if the target_handle is in the hint bar 
  271. 	local hint_index =Hint_bar:get_hint_index(target_handle) 
  272. 	if hint_index == 1 then 
  273. 		pause_voice_tut_button_b(event) 
  274. 	end 
  275. 	 
  276. 	if target_handle == Arrow_left.handle then 
  277. 		pause_voice_tut_nav_left() 
  278. 	elseif target_handle == Arrow_right.handle then 
  279. 		pause_voice_tut_nav_right() 
  280. 	end 
  281. end 
  282.  
  283. function pause_voice_tut_mouse_move(event, target_handle) 
  284.  
  285. 	 
  286. 	-- Reset highlights 
  287. 	Hint_bar:set_highlight(0) 
  288. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  289. 	if hint_index ~= 0 then 
  290. 		Hint_bar:set_highlight(hint_index) 
  291. 	end 
  292. 	 
  293.  
  294. 	-- Highlight the page header 
  295. 	local page_text = vint_object_find("current_page", 0, pause_voice_tut_doc_handle) 
  296. 	vint_set_property(page_text, "tint", 0, 0, 0) 
  297. 	 
  298. 	-- Highlight the arrows 
  299. 	Arrow_left:set_color(0, 0, 0) 
  300. 	Arrow_right:set_color(0, 0, 0) 
  301.  
  302. 	if target_handle == Page_header.handle then 
  303. 		vint_set_property(page_text, "tint", COLOR_CELL_MENU_HIGHLIGHT_TEXT.R, COLOR_CELL_MENU_HIGHLIGHT_TEXT.G, COLOR_CELL_MENU_HIGHLIGHT_TEXT.B) 
  304. 		Arrow_left:set_color(COLOR_CELL_MENU_HIGHLIGHT_TEXT) 
  305. 		Arrow_right:set_color(COLOR_CELL_MENU_HIGHLIGHT_TEXT) 
  306. 		vint_set_mouse_cursor("Ui_cursor_hand_open") 
  307. 	else 
  308. 		vint_set_mouse_cursor("") 
  309. 	end 
  310. end 
  311.  
  312. function pause_voice_tut_mouse_drag(event, target_handle, mouse_x) 
  313. 	if target_handle == Page_header.handle then 
  314. 		cells_stats_adjust_page_position(mouse_x - MOUSE_DOWN, mouse_x) 
  315. 		vint_set_mouse_cursor("Ui_cursor_hand_closed") 
  316. 	end 
  317. end 
  318.  
  319. function pause_voice_tut_mouse_drag_release(event, target_handle, mouse_x, mouse_y, scroll_lines, current_target_handle) 
  320. 	debug_print("vint", "highlighted_handle: " 			.. var_to_string(current_target_handle) .. "\n") 
  321. 	debug_print("vint", "Page_header.handle: " 	.. var_to_string(Page_header.handle) .. "\n") 
  322. 	if current_target_handle == Page_header.handle then 
  323. 		vint_set_mouse_cursor("Ui_cursor_hand_open") 
  324. 	else 
  325. 		vint_set_mouse_cursor("") 
  326. 	end 
  327. end 
  328.  
  329. function pause_voice_tut_mouse_down(event, target_handle, mouse_x) 
  330. 	if target_handle == Page_header.handle then 
  331. 		MOUSE_DOWN = mouse_x 
  332. 	end 
  333. end 
  334.  
  335. function pause_voice_tut_mouse_release(event, target_handle, mouse_x) 
  336. 	if target_handle == Page_header.handle then 
  337. 		MOUSE_DOWN = mouse_x 
  338. 		vint_set_mouse_cursor("Ui_cursor_hand_closed") 
  339. 	end 
  340. end