./cell_extras.lua

  1. ID_CHEATS	= 0 
  2. ID_STATS		= 1 
  3.  
  4. local Data = { 
  5. 	[ID_CHEATS] = { 
  6. 		label = "MENU_CHEATS", 
  7. 		icon = "ui_cell_icon_cheats" 
  8. 	},	 
  9. 	[ID_STATS] = { 
  10. 		label = "MENU_STATS", 
  11. 		icon = "ui_cell_icon_stats", 
  12. 		can_wrap = false 
  13. 	}, 
  14. } 
  15.  
  16. local Menu_extras 
  17. local Hint_bar 
  18. local Input_tracker 
  19. local Mouse_input_tracker 
  20. local Cell_extras_doc_h = -1 
  21.  
  22. function cell_extras_init() 
  23. 	-- Subscribe to the button presses we need 
  24. 	Cell_extras_doc_h = vint_document_find("cell_extras") 
  25. 	 
  26. 	--Build input tracker... 
  27. 	Input_tracker = Vdo_input_tracker:new() 
  28. 	Input_tracker:add_input("map", "cell_extras_button_map", 50) 
  29. 	Input_tracker:add_input("select", "cell_extras_button_a", 50) 
  30. 	Input_tracker:add_input("back", "cell_extras_button_b", 50) 
  31. 	Input_tracker:add_input("nav_up", "cell_extras_nav_up", 50) 
  32. 	Input_tracker:add_input("nav_down", "cell_extras_nav_down", 50) 
  33. 	Input_tracker:add_input("nav_left", "cell_extras_nav_left", 50) 
  34. 	Input_tracker:add_input("nav_right", "cell_extras_nav_right", 50) 
  35. 	 
  36. 	--Build menu... 
  37. 	Menu_extras = Vdo_cell_menu:new("cell_menu") 
  38. 	Menu_extras:populate_menu(Data) 
  39. 	 
  40. 	if game_get_platform() == "PC" then 
  41. 		-- Setup Button Hints 
  42. 		Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Cell_extras_doc_h) 
  43. 		local hint_data = { 
  44. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  45. 		} 
  46. 		Hint_bar:set_hints(hint_data)  
  47. 		Hint_bar:set_visible(true)	 
  48. 		Hint_bar:set_highlight(0) 
  49. 		 
  50. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  51. 		Menu_extras:add_mouse_inputs("cell_extras", Mouse_input_tracker) 
  52. 		Hint_bar:add_mouse_inputs("cell_extras", Mouse_input_tracker) 
  53. 	end 
  54.  
  55. 	debug_print("vint", "double transition\n") 
  56. 	--Transition the screen in... 
  57. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_EXTRAS, CELL_SCREEN_MAIN, cell_extras_gained_focus) 
  58. end 
  59.  
  60. function cell_extras_cleanup() 
  61. 	-- Nuke all button subscriptions 
  62. 	Input_tracker:subscribe(false) 
  63. 	if Mouse_input_tracker ~= nil then 
  64. 		Mouse_input_tracker:subscribe(false) 
  65. 	end 
  66. end 
  67.  
  68. function cell_extras_nav_up(event, acceleration) 
  69. 	Menu_extras:nav_up() 
  70. end 
  71.  
  72. function cell_extras_nav_down(event, acceleration) 
  73. 	Menu_extras:nav_down() 
  74. end 
  75.  
  76. function cell_extras_nav_left(event, acceleration) 
  77. 	Menu_extras:nav_left() 
  78. end 
  79.  
  80. function cell_extras_nav_right(event, acceleration) 
  81. 	Menu_extras:nav_right() 
  82. end 
  83.  
  84. function cell_extras_button_map(event, acceleration) 
  85. 	game_UI_audio_play("UI_Cell_Close") 
  86. 	cell_extras_lock_controls() 
  87. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_EXTRAS, cell_extras_exit_to_game) 
  88. end 
  89.  
  90. function cell_extras_button_b(event, acceleration) 
  91. 	game_UI_audio_play("UI_Cell_Nav_Back") 
  92. 	cell_extras_lock_controls() 
  93. 	Menu_extras:show_highlight(false) 
  94. 	cell_transition_screen(CELL_STATE_PORTRAIT,  CELL_SCREEN_MAIN, CELL_SCREEN_EXTRAS, cell_extras_exit_to_main) 
  95. end 
  96.  
  97. function cell_extras_exit_to_main() 
  98. 	pop_screen()	--Extras 
  99. end 
  100.  
  101. function cell_extras_exit_to_game() 
  102. 	pop_screen()	--Extras 
  103. 	pop_screen()	--Main 
  104. 	pop_screen()	--frame 
  105. end 
  106.  
  107. function cell_extras_button_a(event, acceleration) 
  108. 	cell_extras_lock_controls() 
  109. 	--TODO: Check to see if tween is done before you move to next screen. 
  110. 	--Get id and change state... 
  111. 	local current_id = Menu_extras:get_id() 
  112. 	cell_extras_handle_state(current_id) 
  113. end 
  114.  
  115. function cell_extras_mouse_click(event, target_handle) 
  116. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  117. 	if hint_index == 1 then 
  118. 		cell_extras_button_b() 
  119. 	end 
  120. 	 
  121. 	-- If the target_handle matches a button, activate it 
  122. 	if Menu_extras:select_button(target_handle) == true then 
  123. 		cell_extras_button_a() 
  124. 	end 
  125. end 
  126.  
  127. function cell_extras_mouse_move(event, target_handle) 
  128. 	Hint_bar:set_highlight(0) 
  129. 	 
  130. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  131. 	if hint_index ~= 0 then 
  132. 		Hint_bar:set_highlight(hint_index) 
  133. 		game_UI_audio_play("UI_Cell_Nav") 
  134. 	end 
  135. 	 
  136. 	-- If the target_handle matches a button, highlight it and play a sound 
  137. 	if Menu_extras:select_button(target_handle) == true then 
  138. 		game_UI_audio_play("UI_Cell_Nav") 
  139. 	end 
  140. end 
  141.  
  142. function cell_extras_handle_state(state) 
  143. 	-- If we are in a different state than -1, then we need the phone to "load that application" 
  144. 	local safe_frame = vint_object_find("safe_frame") 
  145. 	vint_set_property(safe_frame, "visible", true) 
  146. 	 
  147. 	if state == ID_STATS then 
  148. 		push_screen("cell_stats") 
  149. 		game_UI_audio_play("UI_Cell_Select") 
  150. 	elseif state == ID_CHEATS then 
  151. 		push_screen("cell_cheats") 
  152. 		game_UI_audio_play("UI_Cell_Select") 
  153. 	end 
  154. 	 
  155. end 
  156.  
  157. function cell_extras_unlock_controls() 
  158. 	Input_tracker:subscribe(true) 
  159. 	if Mouse_input_tracker ~= nil then 
  160. 		Mouse_input_tracker:subscribe(true) 
  161. 	end 
  162. end 
  163.  
  164. function cell_extras_lock_controls() 
  165. 	Input_tracker:subscribe(false) 
  166. 	if Mouse_input_tracker ~= nil then 
  167. 		Mouse_input_tracker:subscribe(false) 
  168. 	end 
  169. end 
  170.  
  171. function cell_extras_lost_focus() 
  172. 	Input_tracker:subscribe(false) 
  173. 	if Mouse_input_tracker ~= nil then 
  174. 		Mouse_input_tracker:subscribe(false) 
  175. 	end 
  176. end 
  177.  
  178. function cell_extras_gained_focus() 
  179. 	Input_tracker:subscribe(true) 
  180. 	if Mouse_input_tracker ~= nil then 
  181. 		Mouse_input_tracker:subscribe(true) 
  182. 	end 
  183. end 
  184.