./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. end 
  59.  
  60. function cell_music_sub_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_music_sub_nav_up(event, acceleration) 
  69. 	Menu_extras:nav_up() 
  70. end 
  71.  
  72. function cell_music_sub_nav_down(event, acceleration) 
  73. 	Menu_extras:nav_down() 
  74. end 
  75.  
  76. function cell_music_sub_nav_left(event, acceleration) 
  77. 	Menu_extras:nav_left() 
  78. end 
  79.  
  80. function cell_music_sub_nav_right(event, acceleration) 
  81. 	Menu_extras:nav_right() 
  82. end 
  83.  
  84. function cell_music_sub_button_map(event, acceleration) 
  85. 	game_UI_audio_play("UI_Cell_Close") 
  86. 	cell_music_sub_lock_controls() 
  87. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MUSIC_SUB, cell_music_sub_exit_to_game) 
  88. end 
  89.  
  90. function cell_music_sub_button_b(event, acceleration) 
  91. 	game_UI_audio_play("UI_Cell_Nav_Back") 
  92. 	cell_music_sub_lock_controls() 
  93. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_MUSIC_SUB, cell_music_sub_exit_to_main) 
  94. end 
  95.  
  96. function cell_music_sub_exit_to_main() 
  97. 	pop_screen()	--Extras 
  98. end 
  99.  
  100. function cell_music_sub_exit_to_game() 
  101. 	pop_screen()	--Extras 
  102. 	pop_screen()	--Main 
  103. 	pop_screen()	--frame 
  104. end 
  105.  
  106. function cell_music_sub_button_a(event, acceleration) 
  107. 		 
  108. 	--TODO: Check to see if tween is done before you move to next screen. 
  109. 	--Get id and change state... 
  110. 	local current_id = Menu_extras:get_id() 
  111. 	cell_music_sub_handle_state(current_id) 
  112. end 
  113.  
  114. function cell_music_sub_mouse_click(event, target_handle) 
  115. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  116. 	if hint_index == 1 then 
  117. 		cell_music_sub_button_b() 
  118. 	end 
  119. 	 
  120. 	-- If the target_handle matches a button, activate it 
  121. 	if Menu_extras:select_button(target_handle) == true then 
  122. 		cell_music_sub_button_a() 
  123. 	end 
  124. end 
  125.  
  126. function cell_music_sub_mouse_move(event, target_handle) 
  127. 	Hint_bar:set_highlight(0) 
  128. 	 
  129. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  130. 	if hint_index ~= 0 then 
  131. 		Hint_bar:set_highlight(hint_index) 
  132. 		game_UI_audio_play("UI_Cell_Nav") 
  133. 	end 
  134. 	 
  135. 	-- If the target_handle matches a button, highlight it and play a sound 
  136. 	if Menu_extras:select_button(target_handle) == true then 
  137. 		game_UI_audio_play("UI_Cell_Nav") 
  138. 	end 
  139. end 
  140.  
  141. function cell_music_sub_handle_state(state) 
  142. 	if state == ID_RADIO then 
  143. 		push_screen("cell_music_menu") 
  144. 		game_UI_audio_play("UI_Cell_Select") 
  145. 		cell_music_sub_lock_controls() 
  146. 	elseif state == ID_MIXTAPE then 
  147. 		push_screen("cell_playlist") 
  148. 		game_UI_audio_play("UI_Cell_Select") 
  149. 		cell_music_sub_lock_controls() 
  150. 	end 
  151. 	 
  152. end 
  153.  
  154. function cell_music_sub_unlock_controls() 
  155. 	Input_tracker:subscribe(true) 
  156. 	if Mouse_input_tracker ~= nil then 
  157. 		Mouse_input_tracker:subscribe(true) 
  158. 	end 
  159. end 
  160.  
  161. function cell_music_sub_lock_controls() 
  162. 	Input_tracker:subscribe(false) 
  163. 	if Mouse_input_tracker ~= nil then 
  164. 		Mouse_input_tracker:subscribe(false) 
  165. 	end 
  166. end 
  167.  
  168. function cell_music_sub_lost_focus() 
  169. 	Input_tracker:subscribe(false) 
  170. 	if Mouse_input_tracker ~= nil then 
  171. 		Mouse_input_tracker:subscribe(false) 
  172. 	end 
  173. end 
  174.  
  175. function cell_music_sub_gained_focus() 
  176. 	Input_tracker:subscribe(true) 
  177. 	if Mouse_input_tracker ~= nil then 
  178. 		Mouse_input_tracker:subscribe(true) 
  179. 	end 
  180. end