local Input_tracker
local Store_music_menu_doc_handle = -1
local Cell_music_menu_doc_handle = -1
local Hint_bar
local Hint_bar_rotate
local Station_grid
local Mouse_input_tracker
local Grid_data = {}
local Grid_idx = 1
function cell_music_menu_init()
-- Subscribe to the button presses we need
-- Find doc handle
Cell_music_menu_doc_handle = vint_document_find("cell_music_menu")
--Setup Button Hints
Hint_bar = Vdo_hint_bar:new("station_hints", 0, Cell_music_menu_doc_handle)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_MENU_BUTTON_A, "MENU_RADIO_TOGGLE_STATION"},
}
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("map", "cell_music_menu_button_map", 50)
-- Setup grid
Station_grid = Vdo_grid_list:new("station_grid", 0, Cell_music_menu_doc_handle)
Station_grid:set_visible(false)
Station_grid:show_highlight_text( false )
Station_grid:tint_current_button( true )
--Get station info...
Grid_data = {}
vint_dataresponder_request("cell_music_menu_populate", "cell_music_menu_add_station", 0)
cell_music_show_grid()
if game_get_platform() == "PC" then
Hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Hint_bar:add_mouse_inputs("cell_music_menu", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
--Lock controls...
cell_music_lock_controls()
--Transition the screen in...
cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_MUSIC, CELL_SCREEN_MUSIC_SUB, cell_music_unlock_controls)
end
function cell_music_menu_button_b(event, acceleration)
cell_music_menu_close()
end
function cell_music_menu_button_map(event, acceleration)
-- Next time come back to phone main...
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
cell_music_lock_controls()
--Transition the screen in...
cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_MUSIC, cell_music_exit_to_game)
end
function cell_music_menu_close()
-- Next time come back to phone main...
vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)
cell_music_lock_controls()
--Transition the screen in...
cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MUSIC_SUB, CELL_SCREEN_MUSIC, cell_music_exit_to_sub)
end
function cell_music_exit_to_sub()
pop_screen()
end
function cell_music_exit_to_game()
pop_screen() --music
pop_screen() --music sub
pop_screen() --main menu
pop_screen() --cellphone frame
end
-- called from C once everything is loaded
function cell_music_show_grid()
Station_grid:draw_items(Grid_data, Grid_idx, 4, 3, 270, 160, 60, nil, nil, false, false)
cell_music_menu_set_station_info( Grid_idx )
Station_grid:set_visible(true)
end
function cell_music_grid_selected(event, value)
if event == "select" or event == "mouse_click" then
local idx = Station_grid:return_selected_index()
if idx <= #Grid_data then
cell_music_menu_toggle_station(Grid_data[idx].id)
Station_grid:button_a() -- should change it to checked
game_UI_audio_play("UI_Cell_Select")
end
elseif event == "back" then
--exit screen
cell_music_menu_close()
game_UI_audio_play("UI_Cell_Nav_Back")
end
end
local Old_index = 0
-- Handle navigating grid
function cell_music_grid_nav(event, value)
local new_index = 1
if event == "nav_up" then
Station_grid:move_cursor(-2)
elseif event == "nav_down" then
Station_grid:move_cursor(2)
elseif event == "nav_left" then
Station_grid:move_cursor(-1)
elseif event == "nav_right" then
Station_grid:move_cursor(1)
elseif event == "mouse_move" then
new_index = Station_grid:get_data_index(value)
if new_index ~= 0 then
if Old_index ~= new_index then
Station_grid:set_selection(new_index)
Station_grid:move_cursor(0, false, false)
Old_index = new_index
end
end
else
new_index = 0
end
if new_index ~= 0 then
cell_music_menu_set_station_info( Station_grid:get_selection() )
game_UI_audio_play("UI_Cell_Nav")
end
end
function cell_music_menu_set_station_info( station_index )
--get a handle for the id and genre text from the doc
local station_id = Vdo_base_object:new( "station_id" )
local station_genre = Vdo_base_object:new( "station_genre" )
--set the correct text based on the current grid highlight position(statiopn_index)
if Grid_data[station_index].label ~= nil then
station_id:set_text( Grid_data[station_index].label )
else
station_id:set_text( "" )
end
if Grid_data[station_index].genre ~= nil then
station_genre:set_text( Grid_data[station_index].genre )
else
station_genre:set_text( "" )
end
end
function cell_music_menu_add_station(station_name, station_genre, id, disabled, image)
local i = #Grid_data + 1
local item = {
index = id,
id = id,
icon = image,
label = station_name,
genre = station_genre,
color = {red =1, green=1, blue=1},
disabled = disabled,
is_canceled_type = true
}
if station_name ~= "" and station_name ~= nil then
Grid_data[i] = item
end
end
function cell_music_unlock_controls()
Input_tracker:subscribe(true)
Station_grid:nav_enable(true, "cell_music_grid_selected", "cell_music_grid_nav")
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function cell_music_lock_controls()
Input_tracker:subscribe(false)
Station_grid:nav_enable(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
-- Mouse inputs
function cell_music_menu_mouse_click(event, target_handle, mouse_x, mouse_y)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cell_music_grid_selected("back")
elseif hint_index == 2 then
cell_music_grid_selected("mouse_click")
end
end
function cell_music_menu_mouse_move(event, target_handle)
Hint_bar:set_highlight(0)
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Hint_bar:set_highlight(hint_index)
end
end