./menu_common.lua

  1. ---------------------------------------------------------------------------  
  2. -- Stack tracking for the pause menu. Keeps track of the current index for 
  3. -- a particular menu system. Each screen must manage the retreiving, adding  
  4. -- and removal of the stack. 
  5. --------------------------------------------------------------------------- 
  6. Menu_common_stack = {} 
  7. Menu_common_stack.current_stack = 0 
  8.  
  9. Current_menu_anim_in_cb = 0 
  10.  
  11. ---------------------------------------------------------------------------  
  12. -- Adds an element to the stack. Use when making a selection on the menu. 
  13. -- @param index	Index of the current selected option 
  14. --------------------------------------------------------------------------- 
  15. function menu_common_stack_add(index) 
  16. 	Menu_common_stack[Menu_common_stack.current_stack] = index 
  17. 	Menu_common_stack.current_stack = Menu_common_stack.current_stack + 1 
  18. end 
  19.  
  20. ---------------------------------------------------------------------------  
  21. -- Removes an element from the stack. Use when going back a menu. 
  22. --------------------------------------------------------------------------- 
  23. function menu_common_stack_remove() 
  24. 	--Nothing in menu stack return default selection 
  25. 	if Menu_common_stack.current_stack == 0 then 
  26. 		return 
  27. 	end 
  28.  
  29. 	--Remove value of current stack 
  30. 	Menu_common_stack[Menu_common_stack.current_stack] = nil 
  31. 	Menu_common_stack.current_stack = Menu_common_stack.current_stack - 1 
  32. end 
  33.  
  34. ---------------------------------------------------------------------------  
  35. -- Returns the current index for a particular menu. 
  36. --------------------------------------------------------------------------- 
  37. function menu_common_stack_get_index(data) 
  38. 	--Nothing stored in the current stack then return default index 
  39. 	local stack_id = Menu_common_stack[Menu_common_stack.current_stack] 
  40. 	if stack_id == nil then 
  41. 		--No stack created, select first item in list... 
  42. 		return 1 
  43. 	end 
  44.  
  45. 	local option_selected = stack_id 
  46. 	 
  47. 	--if data is defined then loop through and find the currently selected option from id. 
  48. 	if data ~= nil then	 
  49. 		for i = 1, #data do 
  50. 			if data[i].id == stack_id then 
  51. 				option_selected = i 
  52. 				break 
  53. 			end 
  54. 		end 
  55. 	end 
  56. 	 
  57. 	--Remove value of current stack 
  58. 	return option_selected 
  59. end 
  60.  
  61. ---------------------------------------------------------------------------  
  62. -- + Input blocking for each menu during transitions... 
  63. -- + Push/Pop queueing for after transitions... 
  64. --------------------------------------------------------------------------- 
  65. local Current_menu_input_tracker		= 0		--Local to store the current input tracker  
  66. local Current_mouse_input_tracker	= 0		--Local to store the current mouse input tracker  
  67. local Current_menu_list					= 0		--Local to store the current list 
  68. local Current_menu_header				= 0		--Local to store the current header  
  69. local Menu_common_push_screen 		= ""		--Local to store the current screen to push  
  70. local Menu_common_num_pops				= 0		--Local to store the current times to pop  
  71. local Current_menu_anim_pop			= 0		--Local to store the current pop animation 
  72. local Current_menu_anim_push			= 0		--Local to store the current push animation 
  73.  
  74. --Stores local screen data and sets callbacks for screen subscriptions... 
  75. function menu_common_set_screen_data(list, header, input_tracker, push_anim, pop_anim, anim_in_cb) 
  76. 	 
  77. 	Current_menu_list = list 
  78. 	Current_menu_header = header 
  79. 	Current_menu_input_tracker = input_tracker 
  80. 	Current_menu_anim_pop = pop_anim 
  81. 	Current_menu_anim_push = push_anim 
  82. 	 
  83. 	if anim_in_cb ~= nil then 
  84. 		Current_menu_anim_in_cb = anim_in_cb 
  85. 	else 
  86. 		Current_menu_anim_in_cb = 0 
  87. 	end 
  88. 	 
  89. 	--reset transition out variables... 
  90. 	Menu_common_push_screen = "" 
  91. 	Menu_common_num_pops = 0 
  92. 	 
  93. 	-- Use this later for transitioning megalist... JMH(4/27/2011) 
  94. 	--list:set_anim_in_cb("menu_common_anim_in_cb") 
  95. 	--list:set_anim_out_cb("menu_common_anim_out_cb") 
  96. 	--menu_common_anim_in_cb() 
  97. end 
  98.  
  99. function menu_common_set_mouse_tracker(input_tracker) 
  100. 	Current_mouse_input_tracker = input_tracker 
  101. end 
  102.  
  103. --Callback for when the menus are done transitioning... 
  104. function menu_common_anim_in_cb() 
  105. 	if Current_menu_input_tracker ~= nil and Current_menu_input_tracker ~= 0 then 
  106. 		Current_menu_input_tracker:subscribe(true) 
  107. 	end 
  108. 	 
  109. 	if Current_mouse_input_tracker ~= nil and Current_mouse_input_tracker ~= 0 then 
  110. 		Current_mouse_input_tracker:subscribe(true) 
  111. 	end 
  112. 	 
  113. 	if Current_menu_anim_in_cb ~= 0 then 
  114. 		Current_menu_anim_in_cb() 
  115. 	end 
  116. end 
  117.  
  118. --Callback for when the menus are done transitioning... 
  119. function menu_common_anim_out_cb() 
  120.  
  121. 	--Pop or push screen? 
  122. 	if Menu_common_num_pops == 0 and Menu_common_push_screen ~= "" then 
  123. 		--Push screen 
  124. 		push_screen(Menu_common_push_screen) 
  125. 	else 
  126. 		--Pop Screen 
  127. 		for i = 1, Menu_common_num_pops do 
  128. 			pop_screen() 
  129. 		end 
  130. 	end 
  131. end 
  132.  
  133.  
  134. -- Transition into another screen... 
  135. -- @param	target_screen		string of target screen... i.e. "pause_options_menu" 
  136. function menu_common_transition_push(target_screen) 
  137. 	if Current_menu_input_tracker ~= nil and Current_menu_input_tracker ~= 0 then 
  138. 		Current_menu_input_tracker:subscribe(false) 
  139. 	end 
  140. 	 
  141. 	if Current_mouse_input_tracker ~= nil and Current_mouse_input_tracker ~= 0 then 
  142. 		Current_mouse_input_tracker:subscribe(false) 
  143. 	end 
  144. 	 
  145. 	Menu_common_push_screen = target_screen 
  146.  
  147. 	-- Use this later for transitioning megalist... JMH(4/27/2011) 
  148. 	--	Current_menu_list:transition_out() 
  149. 	Current_menu_anim_push:play() 
  150. 	 
  151. 	Menu_hint_bar:set_hints(false) 
  152. 	 
  153. 	if Current_menu_header then 
  154. 		--Current_menu_header:anim_out() 
  155. 	end 
  156. 	 
  157. 	--menu_common_anim_out_cb() 
  158. 	 
  159. 	--play the SELECT button sound 
  160. 	game_UI_audio_play("UI_Main_Menu_Select") 
  161. 	 
  162. end 
  163.  
  164. -- Transition back into previous screens. 
  165. -- @param num_pops	how many times we want to pop after transition... 
  166. function menu_common_transition_pop(num_pops) 
  167. 	if Current_menu_input_tracker ~= nil and Current_menu_input_tracker ~= 0 then 
  168. 		Current_menu_input_tracker:subscribe(false) 
  169. 	end 
  170. 	 
  171. 	if Current_mouse_input_tracker ~= nil and Current_mouse_input_tracker ~= 0 then 
  172. 		Current_mouse_input_tracker:subscribe(false) 
  173. 	end 
  174. 	 
  175. 	if num_pops == nil then 
  176. 		num_pos = 1 
  177. 	end 
  178. 	Menu_common_num_pops = num_pops 
  179. 	 
  180. 	-- Use this later for transitioning megalist... JMH(4/27/2011) 
  181. 	--Current_menu_list:transition_out() 
  182. 	Current_menu_anim_pop:play() 
  183. 	 
  184. 	if Current_menu_header then 
  185. 		--Current_menu_header:anim_out() 
  186. 	end 
  187. 	Menu_hint_bar:set_hints(false) 
  188. 	 
  189. 	--menu_common_anim_out_cb() 
  190. 	 
  191. 	--play the BACK button sound 
  192. 	game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  193. 	 
  194. end 
  195.  
  196. function menu_common_set_list_style(List, Header, Width) 
  197. 	if In_pause_menu then 
  198. 		pause_menu_set_style(List, Header, Width, Menu_common_num_pops) 
  199. 	else 
  200. 		main_menu_set_style(List, Header, Width, Menu_common_num_pops) 
  201. 	end 
  202. end 
  203.  
  204. function menu_common_stack_clear() 
  205. 	Menu_common_stack = {} 
  206. 	Menu_common_stack.current_stack = 0 
  207. end