local MAX_COL = 2
local MAX_ROW = 2
function vdo_cell_menu_init()
end
function vdo_cell_menu_cleanup()
end
-- Inherited from Vdo_base_object
Vdo_cell_menu = Vdo_base_object:new_base()
function Vdo_cell_menu:init()
local time_offset = 0
self.menu_btn = {}
--Declare and populate buttons with data
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
self.menu_btn[i ..j] = Vdo_cell_menu_button:new("menu_btn" ..i ..j, self.handle, self.doc_handle)
time_offset = time_offset + .05
self.menu_btn[i ..j]:animate_in(time_offset)
end
end
self.menu_grp = Vdo_base_object:new( "menu_grp", self.handle, self.doc_handle )
self.cursor_x = 0
self.cursor_y = 0
self:set_alpha(1)
local div_intro_anim_h = vint_object_find("div_intro_anim", self.handle, self.doc_handle)
lua_play_anim(div_intro_anim_h, 0)
end
function Vdo_cell_menu:cleanup()
end
function Vdo_cell_menu:populate_menu(data, cur_selection, animate_highlight)
local index = 0
local hidden_btn = {
label = "",
icon = nil,
is_enabled = false,
is_visible = false,
}
--populate buttons with data
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
local btn_data = hidden_btn
if index <= #data then
btn_data = data[index]
end
self.menu_btn[j ..i]:populate_button(btn_data.label, btn_data.icon, btn_data.is_enabled, btn_data.new_items, btn_data.is_visible, btn_data.can_wrap, btn_data.progress)
index = index + 1
self.menu_btn[j ..i]:set_highlight(false)
end
end
if cur_selection ~= nil and cur_selection > -1 and cur_selection < 9 then
self:set_id(cur_selection)
else
-- get first non-disabled button
local found = false
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
if self.menu_btn[j ..i].is_enabled ~= false then
if found == false then
found = true
self.cursor_x = j
self.cursor_y = i
end
end
end
end
end
self:set_highlight(self.cursor_x, self.cursor_y)
end
function Vdo_cell_menu:set_highlight(position_x, position_y)
local previous_x = self.cursor_x
local previous_y = self.cursor_y
--Unhighlight previous option...
self.menu_btn[previous_x .. previous_y]:set_highlight(false)
--Highlight new option...
self.menu_btn[position_x .. position_y]:set_highlight(true)
--Store positions to self.
self.cursor_x = position_x
self.cursor_y = position_y
end
function Vdo_cell_menu:show_highlight(show)
local previous_x = self.cursor_x
local previous_y = self.cursor_y
--Unhighlight previous option...
self.menu_btn[previous_x .. previous_y]:set_highlight(show)
end
-- navigation helper function
function row_down_wrap(cur_y)
return abs((cur_y + 1) % (MAX_ROW + 1))
end
function row_up_wrap(cur_y)
return abs((cur_y + MAX_ROW) % (MAX_ROW + 1))
end
function column_right_wrap(cur_x)
return abs((cur_x + 1) % (MAX_COL + 1))
end
function column_left_wrap(cur_x)
return abs((cur_x + MAX_COL) % (MAX_COL + 1))
end
function identity(cur)
return cur
end
-- check if cell button in row / column enabled
function Vdo_cell_menu:search_enabled_cell(cur_x, cur_y, update_x, update_y, try_count)
for i = 1, try_count, 1 do
if self.menu_btn[cur_x ..cur_y].is_enabled ~= false then
return true, cur_x, cur_y
end
cur_x = update_x(cur_x)
cur_y = update_y(cur_y)
end
return false, 0, 0
end
function Vdo_cell_menu:nav_up(event, acceleration)
ui_audio_post_event("UI_Hub_Navigate")
local cur_x = self.cursor_x
local cur_y = self.cursor_y
local orig_y = cur_y
-- check start column
local try_count = MAX_ROW
cur_y = row_up_wrap(cur_y)
local found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, identity, row_up_wrap, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(0)
return
end
-- move column left and try again
for i = 1, MAX_COL, 1 do
cur_x = column_left_wrap(cur_x)
cur_y = MAX_COL
try_count = MAX_ROW + 1
found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, identity, row_up_wrap, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(0)
return
end
end
end
function Vdo_cell_menu:nav_down(event, acceleration)
ui_audio_post_event("UI_Hub_Navigate")
local cur_x = self.cursor_x
local cur_y = self.cursor_y
-- check start column
local try_count = MAX_ROW
cur_y = row_down_wrap(cur_y)
local found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, identity, row_down_wrap, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(2)
return
end
-- move column left and try again
for i = 1, MAX_COL, 1 do
cur_x = column_right_wrap(cur_x)
cur_y = 0
try_count = MAX_ROW + 1
found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, identity, row_up_wrap, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(2)
return
end
end
end
function Vdo_cell_menu:nav_left(event, acceleration)
ui_audio_post_event("UI_Hub_Navigate")
local cur_x = self.cursor_x
local cur_y = self.cursor_y
-- check start row
local try_count = MAX_COL
cur_x = column_left_wrap(cur_x)
local found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, column_left_wrap, identity, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(3)
return
end
-- move row up and try again
for i = 1, MAX_ROW, 1 do
cur_x = MAX_ROW
cur_y = row_up_wrap(cur_y)
try_count = MAX_ROW + 1
found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, column_left_wrap, identity, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(3)
return
end
end
end
function Vdo_cell_menu:nav_right(event, acceleration)
ui_audio_post_event("UI_Hub_Navigate")
local cur_x = self.cursor_x
local cur_y = self.cursor_y
-- check start row
local try_count = MAX_COL
cur_x = column_right_wrap(cur_x)
local found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, column_right_wrap, identity, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(1)
return
end
-- move row down and try again
for i = 1, MAX_ROW, 1 do
cur_x = 0
cur_y = row_down_wrap(cur_y)
try_count = MAX_ROW + 1
found, found_x, found_y = self:search_enabled_cell(cur_x, cur_y, column_right_wrap, identity, try_count)
if found then
self:set_highlight(found_x, found_y)
--self:animate_menu(1)
return
end
end
end
function Vdo_cell_menu:animate_menu(direction)
-- 0 up
-- 1 right
-- 2 down
-- 3 left
local cur_x,cur_y = self.menu_grp:get_anchor()
local distance = 10
--[[if direction == 0 then
self.menu_tween:set_start_value(0,cur_y)
self.menu_tween:set_end_value(0,-1*distance)
self.menu_tween2:set_start_value(0,-1*distance)
elseif direction == 1 then
self.menu_tween:set_start_value(cur_x,0)
self.menu_tween:set_end_value(distance,0)
self.menu_tween2:set_start_value(distance,0)
elseif direction == 2 then
self.menu_tween:set_start_value(0,cur_y)
self.menu_tween:set_end_value(0,distance)
self.menu_tween2:set_start_value(0,distance)
elseif direction == 3 then
self.menu_tween:set_start_value(cur_x,0)
self.menu_tween:set_end_value(-1*distance,0)
self.menu_tween2:set_start_value(-1*distance,0)
end]]--
end
function Vdo_cell_menu:get_id()
local max_col_id = MAX_COL + 1
return (self.cursor_y * max_col_id + self.cursor_x)
end
function Vdo_cell_menu:set_id(id)
local max_col_id = MAX_COL + 1
self.cursor_y = abs(floor(id / max_col_id))
self.cursor_x = abs(id % max_col_id )
end
function Vdo_cell_menu:animate_in()
local div_intro_anim_h = vint_object_find("div_intro_anim", self.handle, self.doc_handle)
lua_play_anim(div_intro_anim_h, 0, self.doc_handle)
--Animated Buttons
local time_offset = 0
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
time_offset = time_offset + .05
self.menu_btn[i .. j]:animate_in(time_offset)
end
end
end
-- =====================================
-- Mouse Specific Functions
-- =====================================
-- Returns true and sets the highlight to the button if the target_handle matches its image
-- and if the button is not disabled
--
function Vdo_cell_menu:select_button(target_handle)
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
local button = self.menu_btn[j ..i]
if (button ~= nil) and (button.is_enabled ~= false) and (button.btn_bg_img_h == target_handle) then
self:set_highlight(j, i)
return true
end
end
end
return false
end
function Vdo_cell_menu:add_mouse_inputs(func_prefix, input_tracker, priority)
if (func_prefix == nil) or (input_tracker == nil) then
return
end
-- Set default priority value to 50
priority = priority or 50
local mouse_click_function = func_prefix.."_mouse_click"
local mouse_move_function = func_prefix.."_mouse_move"
-- Add mouse inputs to each of the cell phone button's images
for i = 0,MAX_ROW,1 do
for j = 0,MAX_COL,1 do
if self.menu_btn[j ..i] ~= nil then
input_tracker:add_mouse_input("mouse_click", mouse_click_function, priority, self.menu_btn[j ..i].btn_bg_img_h)
input_tracker:add_mouse_input("mouse_move", mouse_move_function, priority, self.menu_btn[j ..i].btn_bg_img_h)
end
end
end
end