- -- Inherited from Vdo_base_object  
- Vdo_cell_filter = Vdo_base_object:new_base()  
-   
- local FILTER_VERTICAL_SPACING = 26  
- local FILTER_SELECTED_COLOR = {R=175/255, G=63/255, B=213/255} 
- local FILTER_UNSELECTED_COLOR = {R=170/255, G=170/255, B=170/255} 
-   
- local FILTER_ICON_OFFSET_X = 30  
-   
- local Filter_icons = { 
- 	["PFT_ALL"] 			= "",  
- 	["PFT_ACTIVITIES"]	= "map_lod_activity",  
- 	["PFT_STORES"]		 	= "map_lod_store",  
- 	["PFT_PROPERTIES"] 	= "map_lod_property",  
- 	["PFT_FLASHPOINTS"]	= "map_lod_flashpoint",  
- 	["PFT_COLLECTION"] 	= "map_lod_flashpoint",  
- 	["PFT_CRIBS"] 			= "map_lod_crib",  
- 	["PFT_NONE"] 			= "",  
- }  
-   
- function vdo_cell_filter_init()  
- end  
-   
- function vdo_cell_filter_cleanup()  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Init filter list...  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:init()  
- 	self.selected_index = 0			--Currently selected filter.  
- 	self.filter_count = 0			--How many filters are in the list.  
- 	self.filters = {}					--Table of filter references... 
- 	  
- 	self.use_icons = false			--If we show a filter icon next to the name  
- 	  
- 	--Initialize the filters...  
- 	--Store globals for filter start point...  
- 	local h = Vdo_base_object:new("filter_type_grp", self.handle, self.doc_handle) 
- 	self.start_x, self.start_y = h:get_anchor()  
- 	h:set_visible(false)  
- 	local x_y_h = vint_object_find("x_of_y", h.handle, self.doc_handle) 
- 	vint_set_property(x_y_h, "text_tag", "00/00")  
- 	self.x_y_width = element_get_actual_size(x_y_h)  
- 	  
- 	--Set filter control buttons...  
- 	local dpad = Vdo_hint_button:new("filter_dpad", self.handle, self.doc_handle) 
- 	dpad:set_button(CTRL_BUTTON_DPAD_UP_DOWN, game_get_key_name(59))--"F1"  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Adds item into filter list...  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:add(filter_type, filter_name, x, y)  
-   
- 	--Clone Item  
- 	local orig_filter_item = Vdo_base_object:new("filter_type_grp", self.handle, self.doc_handle) 
- 	local filter_item = orig_filter_item:clone(orig_filter_item.handle)  
- 	filter_item:set_visible(true)  
- 	  
- 	--Store data...  
- 	self.filters[self.filter_count] = {  
- 		filter_type = filter_type,  
- 		item = filter_item,  
- 		filter_name = filter_name, 					  
- 		x = x,   
- 		y = y,  
- 	}  
- 		  
- 	--Reposition...  
- 	local pos_x = self.start_x  
- 	local pos_y = self.start_y + (FILTER_VERTICAL_SPACING * self.filter_count)  
- 	filter_item:set_anchor(pos_x, pos_y)  
-   
- 	-- Set text label  
- 	local filter_name_h = vint_object_find("filter_name", filter_item.handle, self.doc_handle) 
- 	vint_set_property(filter_name_h, "text_tag", filter_name)  
- 	  
- 	-- Set x/y  
- 	local x_of_y_h = vint_object_find("x_of_y", filter_item.handle, self.doc_handle) 
- 	if y > 0 or y == nil then  
- 		local x_of_y_string = x .. "/" .. y  
- 		vint_set_property(x_of_y_h, "text_tag", x_of_y_string)  
- 		vint_set_property(x_of_y_h, "visible", true)  
- 	else  
- 		--If y is 0 then there is no x/y. Hide it.  
- 		vint_set_property(x_of_y_h, "visible", false)  
- 	end  
- 	  
- 	--Set unhighlighted...  
- 	vint_set_property(filter_name_h, "tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B)  
- 	vint_set_property(x_of_y_h, 		"tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B)  
-   
- 	--Determine if we use icons, hide or show...  
- 	local icon_bmp_h = vint_object_find("filter_bmp", filter_item.handle, self.doc_handle) 
- 	if self.use_icons == true then  
- 		local filter_icon = Filter_icons[filter_type]  
- 		if filter_icon ~= "" then  
- 			vint_set_property(icon_bmp_h, "visible", true)  
- 			vint_set_property(icon_bmp_h, "image", filter_icon)  
- 		else  
- 			vint_set_property(icon_bmp_h, "visible", false)  
- 		end  
- 		local pos_x, pos_y = vint_get_property(filter_name_h, "anchor")  
- 		vint_set_property(filter_name_h, "anchor", FILTER_ICON_OFFSET_X, pos_y)  
- 	else  
- 		vint_set_property(icon_bmp_h, "visible", false)  
- 	end  
- 	  
-   
- 	--Scale size of background to fit filters... (This only adjusts the height of the box)  
- 	local background = Vdo_base_object:new("filter_bg", self.handle, self.doc_handle) 
- 	local width, height = background:get_actual_size()  
- 	  
- 	--MAGIC NUMBER 30 (box offset size)  
- 	height = self.start_y + (FILTER_VERTICAL_SPACING * self.filter_count) + 30  
- 	background:set_actual_size(width, height)  
-   
- 	self.filter_count = self.filter_count + 1  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Clears out list and deletes all objects in it.  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:clear()  
-   
- 	--Cycle through list and delete objects...  
- 	for idx, val in pairs(self.filters) do  
- 		val.item:object_destroy()  
- 	end  
- 	  
- 	self.filters = {} 
- 	self.filter_count = 0  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Navigates the filter list from current position...  
- --  
- -- @param	direction	+1 = up or -1 = down  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:move_cursor(direction)  
-   
- 	if self.filter_count == 0 then  
- 		--No Filters to nav...  
- 		return  
- 	end  
- 	  
- 	local new_index = self.selected_index + direction  
-   
- 	--Wrap index if needed...  
- 	if new_index < 0 then  
- 		new_index = self.filter_count - 1  
- 	elseif new_index == self.filter_count then  
- 		new_index = 0  
- 	end  
- 	  
- 	--Change the filter...  
- 	self:change_filter(new_index, true)  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Change to a specific filter.  
- -- @param	index					index of filter  
- --	@param	set_game_filter	(Bool) Determines if we set the game filter.  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:change_filter(index, do_callback)  
-   
- 	local filter_previous = self.filters[self.selected_index].item  
- 	local filter = self.filters[index]  
- 	local filter_obj = filter.item  
-   
- 	--Move D-Pad  
- 	local x, y = filter_obj:get_anchor()  
- 	local dpad = Vdo_base_object:new("filter_dpad", self.handle, self.doc_handle) 
- 	local dpad_x, dpad_y = dpad:get_anchor()  
- 	dpad:set_anchor(dpad_x, y)  
- 	  
- 	  
- 	local x_of_y_h = vint_object_find("x_of_y", filter_obj.handle, self.doc_handle) 
- 	local filter_name_h = vint_object_find("filter_name", filter_obj.handle, self.doc_handle)			 
- 	  
- 	vint_set_property(filter_name_h, "tint", FILTER_SELECTED_COLOR.R, FILTER_SELECTED_COLOR.G, FILTER_SELECTED_COLOR.B)  
- 	vint_set_property(x_of_y_h, 		"tint", FILTER_SELECTED_COLOR.R, FILTER_SELECTED_COLOR.G, FILTER_SELECTED_COLOR.B)  
- 	  
- 	--Change text colors  
- 	if index ~= self.selected_index then  
- 		x_of_y_h = vint_object_find("x_of_y", filter_previous.handle, self.doc_handle) 
- 		filter_name_h = vint_object_find("filter_name", filter_previous.handle, self.doc_handle)			 
- 		vint_set_property(filter_name_h, "tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B)  
- 		vint_set_property(x_of_y_h, 		"tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B)  
- 	end  
-   
- 	if do_callback then  
- 		self:filter_callback_change_do(filter.filter_type)  
- 	end  
- 	  
- 	--store index to object...  
- 	self.selected_index = index  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Changes the filter by filter type  
- --  
- -- @param	filter_type		filter type is determined by what the game uses to change filters  
- -- @param	do_callback		True to actually change the filter in game, False if to change the visual.  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:change_filter_by_type(filter_type, do_callback)  
- 	local filter_idx = self.filters[0]  
- 	for idx, val in pairs(self.filters) do  
- 		if val.filter_type == filter_type then  
- 			filter_idx = idx  
- 			break  
- 		end  
- 	end  
- 	self:change_filter(filter_idx, do_callback)  
- end  
-   
-   
- -------------------------------------------------------------------------------  
- -- Adjust layout of the screen  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:adjust_layout(min_width)  
- 	  
- 	--Go through filters and store the elements into a format to find widest text element...  
- 	local data = {} 
- 	for idx, val in pairs(self.filters) do  
- 		local h = vint_object_find("filter_name", val.item.handle) 
- 		data[idx] = h  
- 	end  
- 	  
- 	local widest_filter_element_h, filter_element_width = find_widest_text_element(data)  
- 	  
- 	if widest_filter_element_h == 0 then  
- 		--exit if no filter elements exit yet..  
- 		return 0  
- 	end  
- 		  
- 	local start_x, start_y = vint_get_property(widest_filter_element_h, "anchor")  
- 	local target_x = start_x + filter_element_width + self.x_y_width  + 10  
- 	  
- 	if min_width ~= nil then  
- 		--when resetting to our min width value we need to subtract the padding.  
- 		min_width = min_width - 32  
- 		target_x = min_width  
- 	end  
-   
- 	--reposition each x_y element...  
- 	for idx, val in pairs(self.filters) do  
- 		local x_y_h = vint_object_find("x_of_y", val.item.handle, self.doc_handle) 
- 		local x, y = vint_get_property(x_y_h, "anchor")  
- 		vint_set_property(x_y_h, "anchor", target_x, y )  
- 	end  
- 	  
- 	--Add padding in from the group on the left side.  
- 	return target_x + 32	  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Calls the game function callback to change the filter type.  
- -- @param filter_type	the filter type that the game reads to change it...  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:filter_callback_change_do(filter_type)  
- 	if self.filter_change_callback ~= nil then  
- 		self.filter_change_callback(filter_type)  
- 	end  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Sets the callback function for the vdo to call.  
- -- @param func		The game function that the vdo calls to change the filter type.  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:filter_callback_set(func)  
- 	self.filter_change_callback = func  
- end  
-   
- function Vdo_cell_filter:get_filter_data()  
- 	local filter = self.filters[self.selected_index]  
- 	local name 	= filter.filter_name  
- 	local x		= filter.x  
- 	local y 		= filter.y  
- 	return name, x, y  
- end  
-   
- -------------------------------------------------------------------------------  
- -- Determines whether or not we should show filter icons  
- -- @param func		The game function that the vdo calls to change the filter type.  
- -------------------------------------------------------------------------------  
- function Vdo_cell_filter:set_use_icons(use_icons)  
- 	self.use_icons = use_icons  
- end  
-   
- function Vdo_cell_filter:get_filter_index(handle)  
-   
- 	for idx, filter in pairs(self.filters) do  
- 		if filter.item.handle == handle then  
- 			return idx  
- 		end  
- 	end  
-   
- 	return -1  
- end  
-   
- -- callback_nav and callback_action are optional overrides (func_prefix is ignored if they are used)  
- function Vdo_cell_filter:add_mouse_inputs(func_prefix, input_tracker, priority, callback_nav, callback_action)  
- 	if (self.filters == nil) or (func_prefix == nil) or (input_tracker == nil) then  
- 		return  
- 	end  
- 	  
- 		-- Default priority value to 50  
- 	self.priority = priority or 50  
- 	  
- 	self.mouse_move_function = callback_nav or func_prefix.."_mouse_move"  
- 	self.mouse_click_function = callback_action or func_prefix.."_mouse_click"  
- 	  
- 	for idx, filter in pairs(self.filters) do  
- 		vint_set_property(filter.item.handle, "mouse_depth", -4002)  
- 		input_tracker:add_mouse_input("mouse_move", self.mouse_move_function, self.priority, filter.item.handle) 
- 		input_tracker:add_mouse_input("mouse_click", self.mouse_click_function, self.priority, filter.item.handle) 
- 	end  
- end