./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. 	--Get station info... 
  37. 	Grid_data = {} 
  38. 	vint_dataresponder_request("cell_music_menu_populate", "cell_music_menu_add_station", 0) 
  39.  
  40. 	cell_music_show_grid() 
  41. 	 
  42. 	if game_get_platform() == "PC" then 
  43. 		Hint_bar:set_highlight(0) 
  44. 		 
  45. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  46. 		Hint_bar:add_mouse_inputs("cell_music_menu", Mouse_input_tracker) 
  47. 		Mouse_input_tracker:subscribe(true) 
  48. 	end 
  49. 	 
  50. 	--Lock controls... 
  51. 	cell_music_lock_controls() 
  52. 	 
  53. 	--Transition the screen in... 
  54. 	cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_MUSIC, CELL_SCREEN_MUSIC_SUB, cell_music_unlock_controls) 
  55. end 
  56.  
  57. function cell_music_menu_button_b(event, acceleration) 
  58. 	cell_music_menu_close() 
  59. end 
  60.  
  61. function cell_music_menu_button_map(event, acceleration) 
  62. 	-- Next time come back to phone main... 
  63. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN) 
  64. 	cell_music_lock_controls() 
  65. 	 
  66. 	--Transition the screen in... 
  67. 	cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MUSIC, cell_music_exit_to_game) 
  68. end 
  69.  
  70. function cell_music_menu_close() 
  71. 	-- Next time come back to phone main... 
  72. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN) 
  73. 	cell_music_lock_controls() 
  74. 	 
  75. 	--Transition the screen in... 
  76. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MUSIC_SUB, CELL_SCREEN_MUSIC, cell_music_exit_to_sub) 
  77. end 
  78.  
  79. function cell_music_exit_to_sub() 
  80. 	pop_screen() 
  81. end 
  82.  
  83. function cell_music_exit_to_game() 
  84. 	pop_screen()	--music 
  85. 	pop_screen()	--music sub 
  86. 	pop_screen()	--main menu 
  87. 	pop_screen()	--cellphone frame 
  88. end 
  89.  
  90. -- called from C once everything is loaded 
  91. function cell_music_show_grid() 
  92. 	Station_grid:draw_items(Grid_data, Grid_idx, 4, 3, 270, 160, 60, nil, nil, false, false) 
  93. 	cell_music_menu_set_station_info( Grid_idx ) 
  94. 	Station_grid:set_visible(true)	 
  95. end 
  96.  
  97. function cell_music_grid_selected(event, value) 
  98. 	if event == "select"  or event == "mouse_click" then 
  99. 		local idx = Station_grid:return_selected_index() 
  100. 		if idx <= #Grid_data then 
  101. 			cell_music_menu_toggle_station(Grid_data[idx].id) 
  102. 			Station_grid:button_a() -- should change it to checked 
  103. 			game_UI_audio_play("UI_Cell_Select") 
  104. 		end 
  105. 	elseif event == "back" then 
  106. 		--exit screen 
  107. 		cell_music_menu_close() 
  108. 		game_UI_audio_play("UI_Cell_Nav_Back") 
  109. 	end 
  110. end 
  111.  
  112. local Old_index = 0 
  113. -- Handle navigating grid 
  114. function cell_music_grid_nav(event, value) 
  115. 	local new_index  = 1 
  116. 	if event == "nav_up" then	 
  117. 		Station_grid:move_cursor(-2)	 
  118. 	elseif event == "nav_down" then 
  119. 		Station_grid:move_cursor(2) 
  120. 	elseif event == "nav_left" then 
  121. 		Station_grid:move_cursor(-1) 
  122. 	elseif event == "nav_right" then 
  123. 		Station_grid:move_cursor(1) 
  124. 	elseif event == "mouse_move" then 
  125. 		new_index = Station_grid:get_data_index(value) 
  126. 		if new_index ~= 0 then 
  127. 			if Old_index ~= new_index then 
  128. 				Station_grid:set_selection(new_index) 
  129. 				Station_grid:move_cursor(0, false, false) 
  130. 				Old_index = new_index 
  131. 			end 
  132. 		end 
  133. 	else 
  134. 		new_index = 0 
  135. 	end 
  136. 	if new_index ~= 0 then 
  137. 		cell_music_menu_set_station_info( Station_grid:get_selection() ) 
  138. 		game_UI_audio_play("UI_Cell_Nav") 
  139. 	end 
  140. end 
  141.  
  142. function cell_music_menu_set_station_info( station_index ) 
  143. 	--get a handle for the id and genre text from the doc 
  144. 	local station_id = Vdo_base_object:new( "station_id" ) 
  145. 	local station_genre = Vdo_base_object:new( "station_genre" ) 
  146. 	--set the correct text based on the current grid highlight position(statiopn_index) 
  147. 	if Grid_data[station_index].label ~= nil then 
  148. 		station_id:set_text( Grid_data[station_index].label ) 
  149. 	else 
  150. 		station_id:set_text( "" ) 
  151. 	end 
  152. 	if Grid_data[station_index].genre ~= nil then 
  153. 		station_genre:set_text( Grid_data[station_index].genre ) 
  154. 	else 
  155. 		station_genre:set_text( "" ) 
  156. 	end 
  157. end 
  158.  
  159. function cell_music_menu_add_station(station_name, station_genre, id, disabled, image) 
  160. 	local i = #Grid_data + 1 
  161. 	local item = { 
  162. 		index = id, 
  163. 		id = id, 
  164. 		icon = image, 
  165. 		label = station_name, 
  166. 		genre = station_genre, 
  167. 		color = {red =1, green=1, blue=1}, 
  168. 		disabled = disabled, 
  169. 		is_canceled_type = true 
  170. 	} 
  171. 	if station_name ~= "" and station_name ~= nil then 
  172. 		Grid_data[i] = item 
  173. 	end 
  174. end 
  175.  
  176. function cell_music_unlock_controls() 
  177. 	Input_tracker:subscribe(true) 
  178. 	Station_grid:nav_enable(true, "cell_music_grid_selected", "cell_music_grid_nav") 
  179. 	if Mouse_input_tracker ~= nil then 
  180. 		Mouse_input_tracker:subscribe(true) 
  181. 	end 
  182. end 
  183.  
  184. function cell_music_lock_controls() 
  185. 	Input_tracker:subscribe(false) 
  186. 	Station_grid:nav_enable(false) 
  187. 	if Mouse_input_tracker ~= nil then 
  188. 		Mouse_input_tracker:subscribe(false) 
  189. 	end 
  190. end 
  191.  
  192. -- Mouse inputs 
  193. function cell_music_menu_mouse_click(event, target_handle, mouse_x, mouse_y) 
  194. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  195. 	if hint_index == 1 then 
  196. 		cell_music_grid_selected("back") 
  197. 	elseif hint_index == 2 then 
  198. 		cell_music_grid_selected("mouse_click") 
  199. 	end 
  200. end 
  201.  
  202. function cell_music_menu_mouse_move(event, target_handle) 
  203. 	Hint_bar:set_highlight(0) 
  204. 	 
  205. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  206. 	if hint_index ~= 0 then 
  207. 		Hint_bar:set_highlight(hint_index) 
  208. 	end 
  209. end 
  210.