./cell_music_sub.lua

  1. ID_RADIO	= 0 
  2. ID_MIXTAPE		= 1 
  3.  
  4. local Data = { 
  5. 	[ID_RADIO] = { 
  6. 		label = "MENU_RADIO", 
  7. 		icon = "ui_cell_icon_music" 
  8. 	},	 
  9. 	[ID_MIXTAPE] = { 
  10. 		label = "MENU_PLAYLIST", 
  11. 		icon = "ui_cell_icon_mix", 
  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_music_sub_doc_h = -1 
  21.  
  22. function cell_music_sub_init() 
  23. 	-- Subscribe to the button presses we need 
  24. 	cell_music_sub_doc_h = vint_document_find("cell_music_sub") 
  25. 	 
  26. 	--Build input tracker... 
  27. 	Input_tracker = Vdo_input_tracker:new() 
  28. 	Input_tracker:add_input("map", "cell_music_sub_button_map", 50) 
  29. 	Input_tracker:add_input("select", "cell_music_sub_button_a", 50) 
  30. 	Input_tracker:add_input("back", "cell_music_sub_button_b", 50) 
  31. 	Input_tracker:add_input("nav_up", "cell_music_sub_nav_up", 50) 
  32. 	Input_tracker:add_input("nav_down", "cell_music_sub_nav_down", 50) 
  33. 	Input_tracker:add_input("nav_left", "cell_music_sub_nav_left", 50) 
  34. 	Input_tracker:add_input("nav_right", "cell_music_sub_nav_right", 50) 
  35. 	 
  36. 	--Build menu... 
  37. 	Menu_extras = Vdo_cell_menu:new("cell_menu") 
  38. 	Menu_extras:populate_menu(Data) 
  39. 	 
  40. 	-- Setup Button Hints 
  41. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, cell_music_sub_doc_h) 
  42. 	local hint_data = { 
  43. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  44. 	} 
  45. 	Hint_bar:set_hints(hint_data)  
  46. 	 
  47. 	if game_get_platform() == "PC" then 
  48. 		Hint_bar:set_visible(true)	 
  49. 		Hint_bar:set_highlight(0) 
  50. 		 
  51. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  52. 		Hint_bar:add_mouse_inputs("cell_music_sub", Mouse_input_tracker) 
  53. 		Menu_extras:add_mouse_inputs("cell_music_sub", Mouse_input_tracker) 
  54. 	end 
  55.  
  56. 	--Transition the screen in... 
  57. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MUSIC_SUB, CELL_SCREEN_MAIN, cell_music_sub_gained_focus) 
  58. 	 
  59. 	 
  60. end 
  61.  
  62. function cell_music_sub_cleanup() 
  63. 	-- Nuke all button subscriptions 
  64. 	Input_tracker:subscribe(false) 
  65. 	if Mouse_input_tracker ~= nil then 
  66. 		Mouse_input_tracker:subscribe(false) 
  67. 	end 
  68. end 
  69.  
  70. function cell_music_sub_nav_up(event, acceleration) 
  71. 	Menu_extras:nav_up() 
  72. end 
  73.  
  74. function cell_music_sub_nav_down(event, acceleration) 
  75. 	Menu_extras:nav_down() 
  76. end 
  77.  
  78. function cell_music_sub_nav_left(event, acceleration) 
  79. 	Menu_extras:nav_left() 
  80. end 
  81.  
  82. function cell_music_sub_nav_right(event, acceleration) 
  83. 	Menu_extras:nav_right() 
  84. end 
  85.  
  86. function cell_music_sub_button_map(event, acceleration) 
  87. 	--Play menu back audio 
  88. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  89. 	cell_music_sub_lock_controls() 
  90. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MUSIC_SUB, cell_music_sub_exit_to_game) 
  91. end 
  92.  
  93. function cell_music_sub_button_b(event, acceleration) 
  94. 	--Play menu back audio 
  95. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  96. 	cell_music_sub_lock_controls() 
  97. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_MUSIC_SUB, cell_music_sub_exit_to_main) 
  98. end 
  99.  
  100. function cell_music_sub_exit_to_main() 
  101. 	pop_screen()	--Extras 
  102. end 
  103.  
  104. function cell_music_sub_exit_to_game() 
  105. 	pop_screen()	--Extras 
  106. 	pop_screen()	--Main 
  107. 	pop_screen()	--frame 
  108. end 
  109.  
  110. function cell_music_sub_button_a(event, acceleration) 
  111. 		 
  112. 	--TODO: Check to see if tween is done before you move to next screen. 
  113. 	--Get id and change state... 
  114. 	local current_id = Menu_extras:get_id() 
  115. 	cell_music_sub_handle_state(current_id) 
  116. end 
  117.  
  118. function cell_music_sub_mouse_click(event, target_handle) 
  119. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  120. 	if hint_index == 1 then 
  121. 		cell_music_sub_button_b() 
  122. 	end 
  123. 	 
  124. 	-- If the target_handle matches a button, activate it 
  125. 	if Menu_extras:select_button(target_handle) == true then 
  126. 		cell_music_sub_button_a() 
  127. 	end 
  128. end 
  129.  
  130. function cell_music_sub_mouse_move(event, target_handle) 
  131. 	Hint_bar:set_highlight(0) 
  132. 	 
  133. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  134. 	if hint_index ~= 0 then 
  135. 		Hint_bar:set_highlight(hint_index) 
  136. 		game_UI_audio_play("UI_Cell_Nav") 
  137. 	end 
  138. 	 
  139. 	-- If the target_handle matches a button, highlight it and play a sound 
  140. 	if Menu_extras:select_button(target_handle) == true then 
  141. 		game_UI_audio_play("UI_Cell_Nav") 
  142. 	end 
  143. end 
  144.  
  145. function cell_music_sub_handle_state(state) 
  146. 	if state == ID_RADIO then 
  147. 		push_screen("cell_music_menu") 
  148. 		ui_audio_post_event("UI_Hub_Menu_Forward") 
  149. 		cell_music_sub_lock_controls() 
  150. 	elseif state == ID_MIXTAPE then 
  151. 		push_screen("cell_playlist") 
  152. 		ui_audio_post_event("UI_Hub_Menu_Forward") 
  153. 		cell_music_sub_lock_controls() 
  154. 	end 
  155. 	 
  156. end 
  157.  
  158. function cell_music_sub_unlock_controls() 
  159. 	Input_tracker:subscribe(true) 
  160. 	if Mouse_input_tracker ~= nil then 
  161. 		Mouse_input_tracker:subscribe(true) 
  162. 	end 
  163. end 
  164.  
  165. function cell_music_sub_lock_controls() 
  166. 	Input_tracker:subscribe(false) 
  167. 	if Mouse_input_tracker ~= nil then 
  168. 		Mouse_input_tracker:subscribe(false) 
  169. 	end 
  170. end 
  171.  
  172. function cell_music_sub_lost_focus() 
  173. 	Input_tracker:subscribe(false) 
  174. 	if Mouse_input_tracker ~= nil then 
  175. 		Mouse_input_tracker:subscribe(false) 
  176. 	end 
  177. end 
  178.  
  179. function cell_music_sub_gained_focus() 
  180. 	Input_tracker:subscribe(true) 
  181. 	if Mouse_input_tracker ~= nil then 
  182. 		Mouse_input_tracker:subscribe(true) 
  183. 	end 
  184. 	--glitch 
  185. 	--glitch_cell() 
  186. end