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