./player_choice_tutorial.lua

  1. local Input_tracker = 0 
  2.  
  3. Player_choice_tutorial_doc_handle = 0 
  4.  
  5. Player_choice_tutorial_data = {} 
  6. Player_choice_tutorial_image = 0 
  7.  
  8. Player_choice_disconnect_dialog_handle = 0 
  9.  
  10. local PLAYER_CHOICE_TEXT_PADDING = 20 
  11.  
  12. function player_choice_tutorial_init() 
  13. 	--store handles to important docs... 
  14. 	Player_choice_tutorial_doc_handle = vint_document_find("player_choice") 
  15. 	 
  16. 	--Hide safe frame 
  17. 	local safe_frame_h = vint_object_find("safe_frame") 
  18. 	vint_set_property(safe_frame_h, "visible", false) 
  19.  
  20. 	--Hide bg saints 
  21. 	bg_saints_show(false) 
  22.  
  23. 	Input_tracker = Vdo_input_tracker:new() 
  24.  
  25. 	-- Data responder request 
  26. 	vint_dataresponder_request("player_choice_populate", "player_choice_tutorial_populate", 0) 
  27.  
  28. 	--Setup screen and insert data... 
  29. 	local title_h 		= vint_object_find("choice_title") 
  30. 	local body_h 		= vint_object_find("choice_body") 
  31. 	local title_clone_h = title_h 
  32. 	local body_clone_h = body_h 
  33. 	local format_data = {} 
  34. 	 
  35. 	--Loop through data and populate our elements... 
  36. 	for idx, val in pairs(Player_choice_tutorial_data) do 
  37. 		--don't clone the first item... 
  38. 		if idx > 1 then 
  39. 			title_clone_h = vint_object_clone(title_h) 
  40. 			body_clone_h = vint_object_clone(body_h) 
  41. 		end 
  42. 		 
  43. 		--set text tages of child elements... 
  44. 		vint_set_property(title_clone_h, "text_tag_crc", val.title) 
  45. 		vint_set_property(body_clone_h, "text_tag_crc", val.body) 
  46.  
  47. 		format_data[#format_data + 1] = {h = title_clone_h, type = VINT_OBJECT_TEXT, space = 20 * max(idx - 1,1)} 
  48. 		format_data[#format_data + 1] = {h = body_clone_h, type = VINT_OBJECT_TEXT, space = 5} 
  49. 	end 
  50. 	 
  51. 	--Format our screen... 
  52. 	local width, height = vint_align_elements(format_data, true) 
  53. 	 
  54. 	--Position the SP/COOP options elements below all the choices...(continue / waiting for other player) 
  55. 	local ctrl_info_h = vint_object_find("ctrl_info_grp") 
  56. 	local coop_info_h = vint_object_find("coop_base_grp") 
  57. 	local h_x, h_y =  vint_get_property(ctrl_info_h, "anchor") 
  58. 	local x, y = vint_get_property(title_h, "anchor") 
  59. 	local y = height + y + 20 
  60. 	vint_set_property(ctrl_info_h, "anchor", h_x, y) 
  61. 	vint_set_property(coop_info_h, "anchor", h_x, y) 
  62.  
  63. 	--vertically centera all options... center of screen - half the group size - 50 offset. 
  64. 	local choice_options_grp_h = vint_object_find("choice_options_grp") 
  65. 	local x, y = vint_get_property(choice_options_grp_h, "anchor") 
  66. 	y = Screen_center_y - (height * .5) - 50 
  67. 	vint_set_property(choice_options_grp_h, "anchor", x, y) 
  68. 	 
  69. 	--Control button... 
  70. 	local ctrl_btn = Vdo_hint_button:new("ctrl_btn") 
  71. 	ctrl_btn:set_button(CTRL_MENU_BUTTON_A) 
  72. 	 
  73. 	--Load peg... callback will continue the screen... 
  74. 	game_peg_load_with_cb("player_choice_tutorial_image_loaded", 1, Player_choice_tutorial_image) 
  75. end 
  76.  
  77. function player_choice_tutorial_cleanup() 
  78. 	--Game peg unload... 
  79. 	if Player_choice_tutorial_image ~= 0 then 
  80. 		game_peg_unload(Player_choice_tutorial_image) 
  81. 	end 
  82. 	 
  83. 	--make sure we close any open dialog boxes... 
  84. 	if Dialog_pause_disconnect_dialog_handle ~= 0 then 
  85. 		dialog_box_force_close(Dialog_pause_disconnect_dialog_handle) 
  86. 	end 
  87. end 
  88.  
  89. ------------------------------------------------------------------------------- 
  90. -- Populates the player choice tutorial via data responder. 
  91. -- @param	image		image name, this is the same for every line item. 
  92. -- @param 	title		title_crc for the title of the choice 
  93. -- @param 	body		body_crc for the body of the choice 
  94. -- 
  95. function player_choice_tutorial_populate(image, title, body) 
  96. 	local item_num = #Player_choice_tutorial_data + 1 
  97. 	Player_choice_tutorial_data[item_num] = { 
  98. 		title = title, 
  99. 		body = body, 
  100. 	} 
  101. 	Player_choice_tutorial_image = image 
  102. end 
  103.  
  104. ------------------------------------------------------------------------------- 
  105. -- Player choice image loaded... 
  106. -- this is when we set the image and display the screen, and apply for input... 
  107. -- 
  108. function player_choice_tutorial_image_loaded() 
  109. 	local image_h = vint_object_find("image") 
  110. 	vint_set_property(image_h, "image", Player_choice_tutorial_image) 
  111. 	vint_set_property(image_h, "scale", 1.0, 1.0) 
  112. 	 
  113. 	local safe_frame_h = vint_object_find("safe_frame") 
  114. 	vint_set_property(safe_frame_h, "visible", true) 
  115.  
  116. 	bg_saints_show(true) 
  117. 	 
  118. 	bg_saints_set_type(BG_TYPE_CENTER, false, 1290, false) 
  119. 	 
  120. 	local control_grp_h = vint_object_find("ctrl_info_grp") 
  121. 	local coop_grp_h = vint_object_find("coop_base_grp") 
  122.  
  123. 	if game_get_is_host() == false then 
  124. 		--Hide controls group... 
  125. 		vint_set_property(control_grp_h, "visible", false) 
  126. 		 
  127. 		local hint_data = { 
  128. 			{CTRL_MENU_BUTTON_BACK, "COMPLETION_COOP_DISCONNECT"}, 
  129. 		} 
  130.  
  131. 		--Setup hints... 
  132. 		local coop_hintbar = Vdo_hint_bar:new("coop_hint_bar") 
  133. 		coop_hintbar:set_hints(hint_data) 
  134. 		coop_hintbar:enable_text_shadow(true) 
  135. 		 
  136. 		Input_tracker:add_input("map", "pc_tutorial_coop_input", 50) 
  137. 		Input_tracker:add_input("all_unassigned", "pc_tutorial_coop_input", 50) 
  138. 		Input_tracker:subscribe(true) 
  139. 	else 
  140. 		--Hide coop group... 
  141. 		vint_set_property(coop_grp_h, "visible", false) 
  142. 		 
  143. 		Input_tracker:add_input("select", "pc_tutorial_input", 50) 
  144. 		 
  145. 		--only host gets controls to  
  146. 		Input_tracker:subscribe(true) 
  147. 	end 
  148. end 
  149.  
  150. ------------------------------------------------------------------------------- 
  151. -- Player choice input 
  152. -- 
  153. function pc_tutorial_input(event) 
  154. 	if event == "select" then 
  155. 		--screen is over... 
  156. 		pop_screen() 
  157. 	end 
  158. end 
  159.  
  160. ------------------------------------------------------------------------------- 
  161. -- Player choice input for coop... 
  162. -- 
  163. function pc_tutorial_coop_input(event) 
  164. 	if event == "map" then 
  165. 		--Coop quit dialog brings up the quit dialog for the coop player(Client) if they want to quit or not... 
  166. 		local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" } 
  167. 		Player_choice_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "pc_tutorial_coop_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false) 
  168. 	end 
  169. end 
  170.  
  171. ------------------------------------------------------------------------------- 
  172. -- When the coop disconnect dialog closes... this is called. 
  173. -- 
  174. function pc_tutorial_coop_disconnect(result, action) 
  175. 	--They selected yes... 
  176. 	if result == 0 then 
  177. 		dialog_box_disconnect() 
  178. 	end 
  179. 	 
  180. 	Player_choice_disconnect_dialog_handle = 0 
  181. end