./cell_music_menu.lua

  1. local Input_tracker 
  2. local Store_music_menu_doc_handle = -1 
  3. local Cell_music_menu_doc_handle = -1 
  4. local Hint_bar 
  5. local Hint_bar_rotate 
  6. local Station_grid 
  7. local Mouse_input_tracker 
  8.  
  9. local Grid_data = {} 
  10. local Grid_idx = 1 
  11.  
  12. function cell_music_menu_init() 
  13. 	-- Subscribe to the button presses we need 
  14.  
  15. 	-- Find doc handle 
  16. 	Cell_music_menu_doc_handle = vint_document_find("cell_music_menu") 
  17. 	 
  18. 	--Setup Button Hints 
  19. 	Hint_bar = Vdo_hint_bar:new("station_hints", 0, Cell_music_menu_doc_handle) 
  20. 	local hint_data = { 
  21. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  22. 		{CTRL_MENU_BUTTON_A, "MENU_RADIO_TOGGLE_STATION"}, 
  23. 	} 
  24. 	Hint_bar:set_hints(hint_data)  
  25. 	Hint_bar:set_visible(true)	 
  26. 	 
  27. 	Input_tracker = Vdo_input_tracker:new() 
  28. 	Input_tracker:add_input("map", "cell_music_menu_button_map", 50) 
  29.  
  30. 	-- Setup grid 
  31. 	Station_grid = Vdo_grid_list:new("station_grid", 0, Cell_music_menu_doc_handle) 
  32. 	Station_grid:set_visible(false) 
  33. 	Station_grid:show_highlight_text( false ) 
  34. 	Station_grid:tint_current_button( true ) 
  35.  
  36. 	--Set up title 
  37. 	local cell_title_h = Vdo_cell_title:new("cell_title", 0, Cell_music_menu_doc_handle) 
  38. 	cell_title_h:set_text("PAUSE_MENU_STATION_SELECTION") 
  39. 	cell_title_h:set_icon("ui_cell_icon_music") 
  40. 	cell_title_h:play_dots_anim() 
  41. 	 
  42. 	--Get station info... 
  43. 	Grid_data = {} 
  44. 	vint_dataresponder_request("cell_music_menu_populate", "cell_music_menu_add_station", 0) 
  45.  
  46. 	cell_music_show_grid() 
  47. 	 
  48. 	if game_get_platform() == "PC" then 
  49. 		Hint_bar:set_highlight(0) 
  50. 		 
  51. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  52. 		Hint_bar:add_mouse_inputs("cell_music_menu", Mouse_input_tracker) 
  53. 		Mouse_input_tracker:subscribe(true) 
  54. 	end 
  55. 	 
  56. 	--Lock controls... 
  57. 	cell_music_lock_controls() 
  58. 	 
  59. 	--Transition the screen in... 
  60. 	cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_MUSIC, CELL_SCREEN_MUSIC_SUB, cell_music_unlock_controls) 
  61. 	--glitch 
  62. 	--glitch_cell() 
  63. end 
  64.  
  65. function cell_music_menu_button_b(event, acceleration) 
  66. 	cell_music_menu_close() 
  67. end 
  68.  
  69. function cell_music_menu_button_map(event, acceleration) 
  70. 	-- Next time come back to phone main... 
  71. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN) 
  72. 	cell_music_lock_controls() 
  73. 	 
  74. 	--Transition the screen in... 
  75. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MUSIC, cell_music_exit_to_game) 
  76. end 
  77.  
  78. function cell_music_menu_close() 
  79. 	 
  80. 	-- Next time come back to phone main... 
  81. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN) 
  82. 	cell_music_lock_controls() 
  83. 	 
  84. 	--Transition the screen in... 
  85. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MUSIC_SUB, CELL_SCREEN_MUSIC, cell_music_exit_to_sub) 
  86. end 
  87.  
  88. function cell_music_exit_to_sub() 
  89. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  90. 	pop_screen() 
  91. end 
  92.  
  93. function cell_music_exit_to_game() 
  94. 	ui_audio_post_event("UI_Hub_Menu_Back") 
  95. 	pop_screen()	--music 
  96. 	pop_screen()	--music sub 
  97. 	pop_screen()	--main menu 
  98. 	pop_screen()	--cellphone frame 
  99. end 
  100.  
  101. -- called from C once everything is loaded 
  102. function cell_music_show_grid() 
  103. 	Station_grid:draw_items(Grid_data, Grid_idx, 4, 3, 270, 160, 67, nil, nil, false, false) 
  104. 	cell_music_menu_set_station_info( Grid_idx ) 
  105. 	Station_grid:set_visible(true)	 
  106. end 
  107.  
  108. function cell_music_grid_selected(event, value) 
  109. 	if event == "select"  or event == "mouse_click" then 
  110. 		local idx = Station_grid:return_selected_index() 
  111. 		if idx <= #Grid_data then 
  112. 			cell_music_menu_toggle_station(Grid_data[idx].id) 
  113. 			Station_grid:button_a() -- should change it to checked 
  114. 			ui_audio_post_event("ui_radio_toggle_on") 
  115. 		end 
  116. 	elseif event == "back" then 
  117. 		--exit screen		 
  118. 		cell_music_menu_close()		 
  119. 	end 
  120. end 
  121.  
  122. local Old_index = 0 
  123. -- Handle navigating grid 
  124. function cell_music_grid_nav(event, value) 
  125. 	local new_index  = 1 
  126. 	if event == "nav_up" then	 
  127. 		Station_grid:move_cursor(-2)	 
  128. 	elseif event == "nav_down" then 
  129. 		Station_grid:move_cursor(2) 
  130. 	elseif event == "nav_left" then 
  131. 		Station_grid:move_cursor(-1) 
  132. 	elseif event == "nav_right" then 
  133. 		Station_grid:move_cursor(1) 
  134. 	elseif event == "mouse_move" then 
  135. 		new_index = Station_grid:get_data_index(value) 
  136. 		if new_index ~= 0 then 
  137. 			if Old_index ~= new_index then 
  138. 				Station_grid:set_selection(new_index) 
  139. 				Station_grid:move_cursor(0, false, false) 
  140. 				Old_index = new_index 
  141. 			end 
  142. 		end 
  143. 	else 
  144. 		new_index = 0 
  145. 	end 
  146. 	if new_index ~= 0 then 
  147. 		cell_music_menu_set_station_info( Station_grid:get_selection() ) 
  148. 		--ui_audio_post_event("UI_Hub_Navigate") 
  149. 	end 
  150. end 
  151.  
  152. function cell_music_menu_set_station_info( station_index ) 
  153. 	--get a handle for the id and genre text from the doc 
  154. 	local station_id = Vdo_base_object:new( "station_id" ) 
  155. 	local station_genre = Vdo_base_object:new( "station_genre" ) 
  156. 	--set the correct text based on the current grid highlight position(statiopn_index) 
  157. 	if Grid_data[station_index].label ~= nil then 
  158. 		station_id:set_text( Grid_data[station_index].label ) 
  159. 	else 
  160. 		station_id:set_text( "" ) 
  161. 	end 
  162. 	if Grid_data[station_index].genre ~= nil then 
  163. 		station_genre:set_text( Grid_data[station_index].genre ) 
  164. 	else 
  165. 		station_genre:set_text( "" ) 
  166. 	end 
  167. end 
  168.  
  169. function cell_music_menu_add_station(station_name, station_genre, id, disabled, image) 
  170. 	local i = #Grid_data + 1 
  171. 	local item = { 
  172. 		index = id, 
  173. 		id = id, 
  174. 		icon = image, 
  175. 		label = station_name, 
  176. 		genre = station_genre, 
  177. 		color = {red =1, green=1, blue=1}, 
  178. 		disabled = disabled, 
  179. 		is_canceled_type = true 
  180. 	} 
  181. 	if station_name ~= "" and station_name ~= nil then 
  182. 		Grid_data[i] = item 
  183. 	end 
  184. end 
  185.  
  186. function cell_music_unlock_controls() 
  187. 	Input_tracker:subscribe(true) 
  188. 	Station_grid:nav_enable(true, "cell_music_grid_selected", "cell_music_grid_nav") 
  189. 	if Mouse_input_tracker ~= nil then 
  190. 		Mouse_input_tracker:subscribe(true) 
  191. 	end 
  192. end 
  193.  
  194. function cell_music_lock_controls() 
  195. 	Input_tracker:subscribe(false) 
  196. 	Station_grid:nav_enable(false) 
  197. 	if Mouse_input_tracker ~= nil then 
  198. 		Mouse_input_tracker:subscribe(false) 
  199. 	end 
  200. end 
  201.  
  202. -- Mouse inputs 
  203. function cell_music_menu_mouse_click(event, target_handle, mouse_x, mouse_y) 
  204. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  205. 	if hint_index == 1 then 
  206. 		cell_music_grid_selected("back") 
  207. 	elseif hint_index == 2 then 
  208. 		cell_music_grid_selected("mouse_click") 
  209. 	end 
  210. end 
  211.  
  212. function cell_music_menu_mouse_move(event, target_handle) 
  213. 	Hint_bar:set_highlight(0) 
  214. 	 
  215. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  216. 	if hint_index ~= 0 then 
  217. 		Hint_bar:set_highlight(hint_index) 
  218. 	end 
  219. end 
  220.