./main_menu_new_game.lua

  1. local EASY_INDEX			= 1 
  2. local MEDIUM_INDEX		= 2 
  3. local HARD_INDEX			= 3 
  4.  
  5. local ID_EASY				= 1 
  6. local ID_MEDIUM			= 2 
  7. local ID_HARD				= 3 
  8.  
  9. local Data = { 
  10. 	[EASY_INDEX] = { 
  11. 		type = TYPE_BUTTON, 
  12. 		label = "DLT_CASUAL", 
  13. 		id = ID_EASY, 
  14. 	}, 
  15. 	[MEDIUM_INDEX] = { 
  16. 		type = TYPE_BUTTON, 
  17. 		label = "DLT_NORMAL", 
  18. 		id = ID_MEDIUM, 
  19. 	}, 
  20. 	[HARD_INDEX] = { 
  21. 		type = TYPE_BUTTON, 
  22. 		label = "DLT_HARDCORE", 
  23. 		id = ID_HARD, 
  24. 	}, 
  25. } 
  26. local Main_menu_new_game_doc_handle = -1 
  27. local Screen_width = 550 
  28.  
  29. local Input_tracker 
  30. local Mouse_input_tracker 
  31.  
  32. local Tween_done = true 
  33. local Device_selected = false 
  34. local Slide_out = true 
  35.  
  36. ---------------------------------------------------------------------------  
  37. -- Initialize Pause Options Menu. 
  38. --------------------------------------------------------------------------- 
  39. function main_menu_new_game_init() 
  40. 	 
  41. 	Main_menu_new_game_doc_handle = vint_document_find("main_menu_new_game") 
  42. 	 
  43. 	-- Subscribe to the button presses we need 
  44. 	Input_tracker = Vdo_input_tracker:new() 
  45. 	Input_tracker:add_input("select", "main_menu_new_game_button_a", 50) 
  46. 	Input_tracker:add_input("back", "main_menu_new_game_button_b", 50) 
  47. 	Input_tracker:add_input("nav_up", "main_menu_new_game_nav", 50) 
  48. 	Input_tracker:add_input("nav_down", "main_menu_new_game_nav", 50) 
  49. 	Input_tracker:add_input("nav_left", "main_menu_new_game_nav", 50) 
  50. 	Input_tracker:add_input("nav_right", "main_menu_new_game_nav", 50) 
  51. 	Input_tracker:subscribe(false) 
  52.  
  53. 	--Initialize Header 
  54. 	Header_obj:set_text("MAINMENU_NEW_GAME_DIFF_HDR", Screen_width) 
  55. 	 
  56. 	--Setup Button Hints 
  57. 	local hint_data = { 
  58. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  59. 	} 
  60. 	Menu_hint_bar:set_hints(hint_data)   
  61. 	 
  62. 	List:draw_items(Data, get_current_difficulty() + 1, Screen_width) 
  63. 	 
  64. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  65. 	 
  66. 	local text_anim_in_h 
  67. 	if First_time then 
  68. 	 
  69. 		text_anim_in_h = vint_object_find("text_slide_in_anim",0,Main_menu_new_game_doc_handle) 
  70. 	 
  71. 		Screen_in_anim:play(0) 
  72. 		bg_saints_slide_in(Screen_width) 
  73. 	 
  74. 		First_time = false 
  75. 		menu_common_set_screen_data(List, Header_obj, nil, Screen_back_out_anim, Screen_out_anim) 
  76. 	else 
  77. 		text_anim_in_h = vint_object_find("text_back_in_anim",0,Main_menu_new_game_doc_handle) 
  78. 		 
  79. 		Slide_out = false 
  80. 		menu_common_set_screen_data(List, Header_obj, nil, Screen_back_out_anim, Screen_slide_out_anim) 
  81. 	end 
  82. 	 
  83. 	lua_play_anim(text_anim_in_h,0,Main_menu_new_game_doc_handle) 
  84. 	 
  85. 	main_menu_new_game_set_description() 
  86.  
  87. 	-- Add mouse inputs for the PC 
  88. 	if game_get_platform() == "PC" then 
  89. 		Menu_hint_bar:set_highlight(0) 
  90. 		 
  91. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  92. 		List:add_mouse_inputs("main_menu_new_game", Mouse_input_tracker) 
  93. 		Menu_hint_bar:add_mouse_inputs("main_menu_new_game", Mouse_input_tracker) 
  94. 		Mouse_input_tracker:subscribe(true) 
  95. 		 
  96. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  97. 	end 
  98. end 
  99.  
  100. function main_menu_new_game_cleanup() 
  101. 	-- Nuke all button subscriptions 
  102. 	Input_tracker:subscribe(false) 
  103. 	if Mouse_input_tracker ~= nil then 
  104. 		Mouse_input_tracker:subscribe(false) 
  105. 	end 
  106. 	List:enable_toggle_input(false) 
  107. end 
  108.  
  109. function main_menu_new_game_nav(event, acceleration) 
  110. 	if Tween_done == true then 
  111. 		if event == "nav_up" then 
  112. 			-- Move highlight up 
  113. 			List:move_cursor(-1) 
  114. 		elseif event == "nav_down" then 
  115. 			-- Move highlight down 
  116. 			List:move_cursor(1) 
  117. 		elseif event == "nav_left" then 
  118. 			-- Move highlight left 
  119. 			List:move_slider(-1) 
  120. 		elseif event == "nav_right" then 
  121. 			-- Move highlight right 
  122. 			List:move_slider(1) 
  123. 		end 
  124. 		 
  125. 		main_menu_new_game_set_description() 
  126. 		 
  127. 	end 
  128. end 
  129.  
  130. function main_menu_new_game_set_description() 
  131. 	local id = List:get_id() 
  132. 	local text_h = vint_object_find("difficulty_text",0,Main_menu_new_game_doc_handle) 
  133. 	 
  134. 	if id == ID_EASY then 
  135. 		vint_set_property(text_h, "text_tag", "DLT_DESC_CASUAL") 
  136. 	elseif id == ID_MEDIUM then 
  137. 		vint_set_property(text_h, "text_tag", "DLT_DESC_NORMAL") 
  138. 	elseif id == ID_HARD then 
  139. 		vint_set_property(text_h, "text_tag", "DLT_DESC_HARDCORE") 
  140. 	end 
  141. end 
  142.  
  143. function main_menu_new_game_block_input() 
  144. 	Input_tracker:subscribe(false) 
  145. 	 
  146. 	if game_get_platform() == "PC" then 
  147. 		Mouse_input_tracker:subscribe(false) 
  148. 	end 
  149. end 
  150.  
  151. function main_menu_new_game_button_a(event, acceleration) 
  152. 	if Tween_done == true and Device_selected == true then 
  153. 		--Set the screen data to the list data 
  154. 		Data = List:return_data() 
  155. 		local current_id = List:get_id() 
  156. 		 
  157. 		game_UI_audio_play("UI_Main_Menu_Select") 
  158. 		 
  159. 		--Do something with the difficulty selection... 
  160. 		game_difficulty_select(current_id - 1)	-- Difficulties indexed by 0 
  161. 		 
  162. 		local has_seen_cal_screen = pause_menu_has_seen_display_cal_screen() 
  163. 		if has_seen_cal_screen then 
  164. 			Start_game_after_display = false 
  165. 			main_menu_new_game() 
  166. 		else 
  167. 			Start_game_after_display = true 
  168. 			push_screen("pause_options_display_cal") 
  169. 		end 
  170. 	end 
  171. end 
  172.  
  173.  
  174. function main_menu_new_game_button_b(event, acceleration) 
  175. 	if Tween_done == true and Device_selected == true then 
  176. 		--pass off the input to the list 
  177. 		List:button_b() 
  178. 	 
  179. 		Input_tracker:subscribe(false) 
  180. 			if game_get_platform() == "PC" then 
  181. 			Mouse_input_tracker:subscribe(false) 
  182. 		end 
  183. 	 
  184. 		--Remove current menu from the stack 
  185. 		menu_common_stack_remove() 
  186. 		 
  187. 		--Pop Screen off the list 
  188. 		menu_common_transition_pop(1) 
  189. 		 
  190. 		local text_anim_out_h 
  191. 		if not First_time then 
  192. 			if Slide_out then 
  193. 				text_anim_out_h = vint_object_find("text_slide_out_anim",0,Main_menu_new_game_doc_handle) 
  194. 				bg_saints_slide_out() 
  195. 			else 
  196. 				text_anim_out_h = vint_object_find("text_back_out_anim",0,Main_menu_new_game_doc_handle) 
  197. 			end 
  198. 			lua_play_anim(text_anim_out_h,0,Main_menu_new_game_doc_handle) 
  199. 		end 
  200. 	end 
  201. end 
  202.  
  203. function main_menu_new_game_mouse_click(event, target_handle) 
  204. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  205. 	if hint_index == 1 then 
  206. 		main_menu_new_game_button_b() 
  207. 	end 
  208.  
  209. 	local new_index = List:get_button_index(target_handle) 
  210. 	if new_index ~= 0 then 
  211. 		List:set_selection(new_index) 
  212. 		main_menu_new_game_button_a() 
  213. 	end 
  214. end 
  215.  
  216. function main_menu_new_game_mouse_move(event, target_handle) 
  217. 	Menu_hint_bar:set_highlight(0) 
  218. 	 
  219. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  220. 	if hint_index ~= 0 then 
  221. 		Menu_hint_bar:set_highlight(hint_index) 
  222. 	end 
  223. 	 
  224. 	local new_index = List:get_button_index(target_handle) 
  225. 	if new_index ~= 0 then 
  226. 		List:set_selection(new_index) 
  227. 		List:move_cursor(0, true) 
  228. 		main_menu_new_game_set_description() 
  229. 	end 
  230. end 
  231.  
  232. function device_selected() 
  233. 	Device_selected = true 
  234. 	Input_tracker:subscribe(true) 
  235. 	if game_get_platform() == "PC" then 
  236. 		Mouse_input_tracker:subscribe(true) 
  237. 	end 
  238. end