function vdo_cell_missions_list_init()
end
function vdo_cell_missions_list_cleanup()
end
-- Inherited from Vdo_base_object
Vdo_cell_missions_list = Vdo_base_object:new_base()
local LIST_BUTTON_SPACE = -5
local MISSION_BUTTON_HEIGHT = 100
local MISSION_BUTTON_SPACING = 5
local Game_platform
local CLIP_PADDING = 20
local Draw_items_called = false
function Vdo_cell_missions_list:initialize()
Game_platform = game_get_platform()
-- Hide the initial button
vint_set_property(vint_object_find("btn_mission", self.handle), "visible", false)
self.clip_h = vint_object_find("clip_mission", self.handle, self.doc_handle)
vint_set_property(self.clip_h,"visible", false)
self.scrollbar = Vdo_scrollbar:new("scrollbar", self.handle, self.doc_handle)
self.scrollbar:set_highlight_color(COLOR_SAINTS_PURPLE)
self.scrollbar:set_size(SCROLLBAR_WIDTH, 390)
self.scrollbar:set_visible(false)
self.visible_start_idx = 1
self.visible_end_idx = self.max_buttons
self.prev_y = -1
end
-- Deletes the internal data and destroys the button clones
function Vdo_cell_missions_list:cleanup()
if Draw_items_called and self.buttons ~= nil then
for index, button in pairs(self.buttons) do
button:object_destroy()
end
self.buttons = nil
end
end
-- Data[Num_items] = { handle = handle, mission_name = mission_name, display_name = display_name, contact_name = contact_name, contact_image = contact_image, is_new = is_new }
function Vdo_cell_missions_list:draw_items(data, current_option, max_buttons)
self:initialize()
Draw_items_called = true
-- Destroy all clones
self:cleanup()
local btn_mission = Vdo_cell_missions_button:new("btn_mission", self.handle, self.doc_handle)
-- Get position of first button
local btn_mission_x, btn_mission_y = btn_mission:get_property("anchor")
-- Set up table for data and clones
self.buttons = {}
self.num_buttons = #data
self.max_buttons = max_buttons
for index = 1, self.num_buttons do
self.buttons[index] = Vdo_cell_missions_button:clone(btn_mission.handle)
local current_button = self.buttons[index]
-- Set the button info
current_button:populate_button(data[index].display_name, data[index].contact_image, data[index].contact_name, data[index].is_new)
local prev_x, prev_y
local new_y = 0
if index > 1 then
--get the previous button's height
--local prev_width, prev_height = element_get_actual_size(btn_mission.handle) --self.buttons[index-1]:get_property("screen_size")
--get the previous button's y
prev_x, prev_y = self.buttons[index-1]:get_property("anchor")
--set the current button's y to the previous buttons y plus its height
new_y = prev_y + MISSION_BUTTON_HEIGHT --+ LIST_BUTTON_SPACE
end
-- Move the button copy into the correct position
current_button:set_property("anchor", btn_mission_x, new_y)
-- Make the button visible
current_button:set_property("visible", true)
end
-- Set initial cursor position
if current_option == nil then
current_option = 1
elseif current_option > self.num_buttons then
current_option = self.num_buttons
end
--set the current button to the passed in variable for the current option
self.current_idx = current_option
-- Handle scrolling
local clip_height = max_buttons * MISSION_BUTTON_HEIGHT
local clip_width, bogus_height = element_get_actual_size(self.clip_h)
local clip_x, clip_y = vint_get_property(self.clip_h,"anchor")
local scrollbar_x, scrollbar_y = self.scrollbar:get_anchor()
vint_set_property(self.clip_h, "clip_size", clip_width, clip_height)
self.scrollbar:set_anchor(scrollbar_x,clip_y)
if(self.num_buttons > max_buttons) then
--show the scroll bar
self.scrollbar:set_property("visible", true)
vint_set_property(self.clip_h,"visible", true)
local scrollbar_height = clip_height -- CLIP_PADDING
if Game_platform == "PC" then
local total_height = self.num_buttons * MISSION_BUTTON_HEIGHT
self.scrollbar:set_size(SCROLLBAR_WIDTH, scrollbar_height, total_height)
else
--set the size of the scrollbar
self.scrollbar:set_size(SCROLLBAR_WIDTH, scrollbar_height)
end
else
--hide the scroll bar
self.scrollbar:set_property("visible", false)
vint_set_property(self.clip_h,"visible", false)
end
-- Draw the cursor
self:move_cursor(0)
end
function Vdo_cell_missions_list:move_cursor(direction, is_mouse_input, is_scroll)
-- Get current button
self.current_idx = wrap_index(self.current_idx, direction, self.num_buttons)
local current_button = self.buttons[self.current_idx]
if is_scroll ~= true then
-- Clear out old highlight
for index, buttons in pairs(self.buttons) do
buttons:set_highlight(false)
buttons:set_property("depth",1)
end
debug_print("vint","self.current_idx ========= "..self.current_idx.."\n\n")
current_button = self.buttons[self.current_idx]
-- Highlight current button
current_button:set_highlight(true)
current_button:set_property("depth", -1)
--Adjust scrollbar
self.scrollbar:set_value(self.num_buttons, self.current_idx, false )
end
local visual_center = self.max_buttons * 0.5
local move_height = MISSION_BUTTON_HEIGHT --element_get_actual_size(current_button.handle) --current_button:get_property("screen_size")--element_get_actual_size(current_button.handle)
local new_y = 0
if is_mouse_input then
new_y = self.prev_y
else
if self.current_idx < visual_center + 1 or self.num_buttons <= self.max_buttons then
--scrolling in top of list...
-- or no scrolling because there isn't enough missions...
new_y = 0
elseif self.current_idx > self.num_buttons - visual_center then
--Scrolling in bottom of list...
new_y = -(self.num_buttons - self.max_buttons) * move_height
else
--move the list...
new_y = -move_height * (self.current_idx - visual_center)
end
end
local mission_btn_grp_h = vint_object_find("mission_btn_grp")
local mission_scroll_anim_h = vint_object_find("mission_scroll_anim")
local scroll_twn_h = vint_object_find("scroll_twn", mission_scroll_anim_h)
local start_x, start_y = vint_get_property(mission_btn_grp_h, "anchor")
local end_x = start_x
local end_y = new_y
vint_set_property(scroll_twn_h, "start_value", start_x, start_y)
vint_set_property(scroll_twn_h, "end_value", end_x, end_y)
lua_play_anim(mission_scroll_anim_h)
--we scrolled so update visual indices
if new_y ~= self.prev_y then
if self.current_idx > 1 then
self.visible_start_idx = self.current_idx - 1
else
self.visible_start_idx = 1
end
self.visible_end_idx = self.visible_start_idx + (self.max_buttons - 1)
end
self.prev_y = new_y
end
function Vdo_cell_missions_list:add_mouse_inputs(func_prefix, input_tracker, priority)
if func_prefix == nil then
return
end
priority = priority or 50
local mouse_click_function = func_prefix.."_mouse_click"
local mouse_move_function = func_prefix.."_mouse_move"
for index, buttons in pairs(self.buttons) do
input_tracker:add_mouse_input("mouse_click", mouse_click_function, priority, buttons.handle)
input_tracker:add_mouse_input("mouse_move", mouse_move_function, priority, buttons.handle)
end
end
function Vdo_cell_missions_list:get_button_index(target_handle)
for index, buttons in pairs(self.buttons) do
if buttons.handle == target_handle then
return index
end
end
-- Return 0 as an invalid index
return 0
end
function Vdo_cell_missions_list:set_selection(index, is_mouse_input, is_scroll)
self.current_idx = index
self:move_cursor(0, is_mouse_input, is_scroll)
end