./main_menu_campaign.lua

  1. local NEW_GAME_INDEX			= 1 
  2. local LOAD_GAME_INDEX		= 2 
  3.  
  4. local ID_NEW_GAME				= 1 
  5. local ID_LOAD_GAME			= 2 
  6.  
  7. local New_game_button = { 
  8. 	type = TYPE_BUTTON, 
  9. 	label = "MAINMENU_NEW", 
  10. 	id = ID_NEW_GAME, 
  11. } 
  12.  
  13. local Load_game_button = { 
  14. 	type = TYPE_BUTTON, 
  15. 	label = "SAVELOAD_LOAD_GAME", 
  16. 	id = ID_LOAD_GAME, 
  17. } 
  18.  
  19. local Data 
  20. local Anims = {} 
  21.  
  22. local Input_tracker 
  23. local Mouse_input_tracker 
  24.  
  25. local Tween_done = true 
  26.  
  27. ---------------------------------------------------------------------------  
  28. -- Initialize Pause Options Menu. 
  29. --------------------------------------------------------------------------- 
  30. function main_menu_campaign_init() 
  31. 	-- Subscribe to the button presses we need 
  32. 	  
  33. 	Input_tracker = Vdo_input_tracker:new() 
  34. 	Input_tracker:add_input("select", "main_menu_campaign_button_a", 50) 
  35. 	Input_tracker:add_input("back", "main_menu_campaign_button_b", 50) 
  36. 	Input_tracker:add_input("nav_up", "main_menu_campaign_nav_up", 50) 
  37. 	Input_tracker:add_input("nav_down", "main_menu_campaign_nav_down", 50) 
  38. 	Input_tracker:add_input("nav_left", "main_menu_campaign_nav_left", 50) 
  39. 	Input_tracker:add_input("nav_right", "main_menu_campaign_nav_right", 50) 
  40. 	Input_tracker:subscribe(false) 
  41. 	 
  42. 	local screen_width = 495 
  43. 	local header_str = "MAINMENU_CAMPAIGN" 
  44. 	Data = { } 
  45. 		 
  46. 	Data[NEW_GAME_INDEX] = New_game_button 
  47. 	Data[LOAD_GAME_INDEX] = Load_game_button	 
  48. 	 
  49. 	--Initialize Header 
  50. 	Header_obj:set_text(header_str, screen_width) 
  51.  
  52. 	--Setup Button Hints  
  53. 	local hint_data = { 
  54. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  55. 	} 
  56. 	Menu_hint_bar:set_hints(hint_data)   
  57. 	 
  58. 	--Get the selection option from when the menu was last loaded 
  59. 	local last_option_selected = menu_common_stack_get_index() 
  60.  
  61. 	List:draw_items(Data, last_option_selected, screen_width) 
  62. 	 
  63. 	--Store some locals to the pause menu common for screen processing. 
  64. 	menu_common_set_list_style(List, Header_obj, screen_width) 
  65. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim) 
  66. 	 
  67. 	if First_time then 
  68. 		Screen_in_anim:play(0) 
  69. 		bg_saints_slide_in(495) 
  70. 		First_time = false 
  71. 	end 
  72. 	 
  73. 	-- Add mouse inputs for the PC 
  74. 	if game_get_platform() == "PC" then 
  75. 		Menu_hint_bar:set_highlight(0) 
  76. 		 
  77. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  78. 		List:add_mouse_inputs("main_menu_campaign", Mouse_input_tracker) 
  79. 		Menu_hint_bar:add_mouse_inputs("main_menu_campaign", Mouse_input_tracker) 
  80. 		Mouse_input_tracker:subscribe(true) 
  81. 		 
  82. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  83. 	end 
  84. end 
  85.  
  86. function main_menu_campaign_cleanup() 
  87. 	-- Nuke all button subscriptions 
  88. 	Input_tracker:subscribe(false) 
  89. 	if Mouse_input_tracker ~= nil then 
  90. 		Mouse_input_tracker:subscribe(false) 
  91. 	end 
  92. 	List:enable_toggle_input(false) 
  93. end 
  94.  
  95. function main_menu_campaign_nav_up(event, acceleration) 
  96. 	-- Move highlight up 
  97. 	List:move_cursor(-1) 
  98. end 
  99.  
  100. function main_menu_campaign_nav_down(event, acceleration) 
  101. 	-- Move highlight down 
  102. 	List:move_cursor(1) 
  103. end 
  104.  
  105. function main_menu_campaign_nav_left(event, acceleration) 
  106. 	-- Move highlight left 
  107. 	List:move_slider(-1) 
  108. end 
  109.  
  110. function main_menu_campaign_nav_right(event, acceleration) 
  111. 	-- Move highlight right 
  112. 	List:move_slider(1) 
  113. end 
  114.  
  115. function main_menu_campaign_button_a(event, acceleration) 
  116. 	if Tween_done == true then 
  117. 		--Set the screen data to the list data 
  118. 		Data = List:return_data() 
  119. 		local current_id = List:get_id() 
  120.  
  121. 		--Add current selection to the stack to store the selected position on the menu 
  122. 		menu_common_stack_add(current_id) 
  123. 		 
  124. 		if current_id == ID_NEW_GAME then 
  125. 			menu_common_transition_push("main_menu_new_game") 
  126. 			return	 
  127. 		elseif current_id == ID_LOAD_GAME then 
  128. 			menu_common_transition_push("pause_save_game")			 
  129. 			return	 
  130. 		end	 
  131. 	end 
  132. end 
  133.  
  134. function main_menu_campaign_button_b(event, acceleration) 
  135. 	if Tween_done == true then 
  136. 		--pass off the input to the list 
  137. 		List:button_b() 
  138. 		--Remove current menu from the stack 
  139. 		menu_common_stack_remove() 
  140. 		 
  141. 		--Pop Screen off the list 
  142. 		menu_common_transition_pop(1) 
  143. 		 
  144. 		bg_saints_slide_out() 
  145. 	end 
  146. end 
  147.  
  148. function main_menu_campaign_mouse_click(event, target_handle) 
  149. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  150. 	if hint_index == 1 then 
  151. 		main_menu_campaign_button_b() 
  152. 	end 
  153.  
  154. 	local new_index = List:get_button_index(target_handle) 
  155. 	if new_index ~= 0 then 
  156. 		List:set_selection(new_index) 
  157. 		main_menu_campaign_button_a() 
  158. 	end 
  159. end 
  160.  
  161. function main_menu_campaign_mouse_move(event, target_handle) 
  162. 	Menu_hint_bar:set_highlight(0) 
  163. 	 
  164. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  165. 	if hint_index ~= 0 then 
  166. 		Menu_hint_bar:set_highlight(hint_index) 
  167. 	end 
  168. 	 
  169. 	local new_index = List:get_button_index(target_handle) 
  170. 	if new_index ~= 0 then 
  171. 		List:set_selection(new_index) 
  172. 		List:move_cursor(0, true) 
  173. 	end 
  174. end 
  175.