./vdo_cell_filter.lua

  1. -- Inherited from Vdo_base_object 
  2. Vdo_cell_filter = Vdo_base_object:new_base() 
  3.  
  4. local FILTER_VERTICAL_SPACING = 26 
  5. local FILTER_SELECTED_COLOR = {R=175/255, G=63/255, B=213/255} 
  6. local FILTER_UNSELECTED_COLOR = {R=170/255, G=170/255, B=170/255} 
  7.  
  8. local FILTER_ICON_OFFSET_X = 30 
  9.  
  10. local Filter_icons = { 
  11. 	["PFT_ALL"] 			= "", 
  12. 	["PFT_ACTIVITIES"]	= "map_lod_activity", 
  13. 	["PFT_STORES"]		 	= "map_lod_store", 
  14. 	["PFT_PROPERTIES"] 	= "map_lod_property", 
  15. 	["PFT_FLASHPOINTS"]	= "map_lod_flashpoint", 
  16. 	["PFT_COLLECTION"] 	= "map_lod_flashpoint", 
  17. 	["PFT_CRIBS"] 			= "map_lod_crib", 
  18. 	["PFT_NONE"] 			= "", 
  19. } 
  20.  
  21. function vdo_cell_filter_init() 
  22. end 
  23.  
  24. function vdo_cell_filter_cleanup() 
  25. end 
  26.  
  27. ------------------------------------------------------------------------------- 
  28. -- Init filter list... 
  29. ------------------------------------------------------------------------------- 
  30. function Vdo_cell_filter:init() 
  31. 	self.selected_index = 0			--Currently selected filter. 
  32. 	self.filter_count = 0			--How many filters are in the list. 
  33. 	self.filters = {}					--Table of filter references... 
  34. 	 
  35. 	self.use_icons = false			--If we show a filter icon next to the name 
  36. 	 
  37. 	--Initialize the filters... 
  38. 	--Store globals for filter start point... 
  39. 	local h = Vdo_base_object:new("filter_type_grp", self.handle, self.doc_handle) 
  40. 	self.start_x, self.start_y = h:get_anchor() 
  41. 	h:set_visible(false) 
  42. 	local x_y_h = vint_object_find("x_of_y", h.handle, self.doc_handle) 
  43. 	vint_set_property(x_y_h, "text_tag", "00/00") 
  44. 	self.x_y_width = element_get_actual_size(x_y_h) 
  45. 	 
  46. 	--Set filter control buttons... 
  47. 	local dpad = Vdo_hint_button:new("filter_dpad", self.handle, self.doc_handle) 
  48. 	dpad:set_button(CTRL_BUTTON_DPAD_UP_DOWN, game_get_key_name(59))--"F1" 
  49. end 
  50.  
  51. ------------------------------------------------------------------------------- 
  52. -- Adds item into filter list... 
  53. ------------------------------------------------------------------------------- 
  54. function Vdo_cell_filter:add(filter_type, filter_name, x, y) 
  55.  
  56. 	--Clone Item 
  57. 	local orig_filter_item = Vdo_base_object:new("filter_type_grp", self.handle, self.doc_handle) 
  58. 	local filter_item = orig_filter_item:clone(orig_filter_item.handle) 
  59. 	filter_item:set_visible(true) 
  60. 	 
  61. 	--Store data... 
  62. 	self.filters[self.filter_count] = {  
  63. 		filter_type = filter_type, 
  64. 		item = filter_item, 
  65. 		filter_name = filter_name, 					 
  66. 		x = x,  
  67. 		y = y, 
  68. 	} 
  69. 		 
  70. 	--Reposition... 
  71. 	local pos_x = self.start_x 
  72. 	local pos_y = self.start_y + (FILTER_VERTICAL_SPACING * self.filter_count) 
  73. 	filter_item:set_anchor(pos_x, pos_y) 
  74.  
  75. 	-- Set text label 
  76. 	local filter_name_h = vint_object_find("filter_name", filter_item.handle, self.doc_handle) 
  77. 	vint_set_property(filter_name_h, "text_tag", filter_name) 
  78. 	 
  79. 	-- Set x/y 
  80. 	local x_of_y_h = vint_object_find("x_of_y", filter_item.handle, self.doc_handle) 
  81. 	if y > 0 or y == nil then 
  82. 		local x_of_y_string = x .. "/" .. y 
  83. 		vint_set_property(x_of_y_h, "text_tag", x_of_y_string) 
  84. 		vint_set_property(x_of_y_h, "visible", true) 
  85. 	else 
  86. 		--If y is 0 then there is no x/y. Hide it. 
  87. 		vint_set_property(x_of_y_h, "visible", false) 
  88. 	end 
  89. 	 
  90. 	--Set unhighlighted... 
  91. 	vint_set_property(filter_name_h, "tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B) 
  92. 	vint_set_property(x_of_y_h, 		"tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B) 
  93.  
  94. 	--Determine if we use icons, hide or show... 
  95. 	local icon_bmp_h = vint_object_find("filter_bmp", filter_item.handle, self.doc_handle) 
  96. 	if self.use_icons == true then 
  97. 		local filter_icon = Filter_icons[filter_type] 
  98. 		if filter_icon ~= "" then 
  99. 			vint_set_property(icon_bmp_h, "visible", true) 
  100. 			vint_set_property(icon_bmp_h, "image", filter_icon) 
  101. 		else 
  102. 			vint_set_property(icon_bmp_h, "visible", false) 
  103. 		end 
  104. 		local pos_x, pos_y = vint_get_property(filter_name_h, "anchor") 
  105. 		vint_set_property(filter_name_h, "anchor", FILTER_ICON_OFFSET_X, pos_y) 
  106. 	else 
  107. 		vint_set_property(icon_bmp_h, "visible", false) 
  108. 	end 
  109. 	 
  110.  
  111. 	--Scale size of background to fit filters... (This only adjusts the height of the box) 
  112. 	local background = Vdo_base_object:new("filter_bg", self.handle, self.doc_handle) 
  113. 	local width, height = background:get_actual_size() 
  114. 	 
  115. 	--MAGIC NUMBER 30 (box offset size) 
  116. 	height = self.start_y + (FILTER_VERTICAL_SPACING * self.filter_count) + 30 
  117. 	background:set_actual_size(width, height) 
  118.  
  119. 	self.filter_count = self.filter_count + 1 
  120. end 
  121.  
  122. ------------------------------------------------------------------------------- 
  123. -- Clears out list and deletes all objects in it. 
  124. ------------------------------------------------------------------------------- 
  125. function Vdo_cell_filter:clear() 
  126.  
  127. 	--Cycle through list and delete objects... 
  128. 	for idx, val in pairs(self.filters) do 
  129. 		val.item:object_destroy() 
  130. 	end 
  131. 	 
  132. 	self.filters = {} 
  133. 	self.filter_count = 0 
  134. end 
  135.  
  136. ------------------------------------------------------------------------------- 
  137. -- Navigates the filter list from current position... 
  138. -- 
  139. -- @param	direction	+1 = up or -1 = down 
  140. ------------------------------------------------------------------------------- 
  141. function Vdo_cell_filter:move_cursor(direction) 
  142.  
  143. 	if self.filter_count == 0 then 
  144. 		--No Filters to nav... 
  145. 		return 
  146. 	end 
  147. 	 
  148. 	local new_index = self.selected_index + direction 
  149.  
  150. 	--Wrap index if needed... 
  151. 	if new_index < 0 then 
  152. 		new_index = self.filter_count - 1 
  153. 	elseif new_index == self.filter_count then 
  154. 		new_index = 0 
  155. 	end 
  156. 	 
  157. 	--Change the filter... 
  158. 	self:change_filter(new_index, true) 
  159. end 
  160.  
  161. ------------------------------------------------------------------------------- 
  162. -- Change to a specific filter. 
  163. -- @param	index					index of filter 
  164. --	@param	set_game_filter	(Bool) Determines if we set the game filter. 
  165. ------------------------------------------------------------------------------- 
  166. function Vdo_cell_filter:change_filter(index, do_callback) 
  167.  
  168. 	local filter_previous = self.filters[self.selected_index].item 
  169. 	local filter = self.filters[index] 
  170. 	local filter_obj = filter.item 
  171.  
  172. 	--Move D-Pad 
  173. 	local x, y = filter_obj:get_anchor() 
  174. 	local dpad = Vdo_base_object:new("filter_dpad", self.handle, self.doc_handle) 
  175. 	local dpad_x, dpad_y = dpad:get_anchor() 
  176. 	dpad:set_anchor(dpad_x, y) 
  177. 	 
  178. 	 
  179. 	local x_of_y_h = vint_object_find("x_of_y", filter_obj.handle, self.doc_handle) 
  180. 	local filter_name_h = vint_object_find("filter_name", filter_obj.handle, self.doc_handle)			 
  181. 	 
  182. 	vint_set_property(filter_name_h, "tint", FILTER_SELECTED_COLOR.R, FILTER_SELECTED_COLOR.G, FILTER_SELECTED_COLOR.B) 
  183. 	vint_set_property(x_of_y_h, 		"tint", FILTER_SELECTED_COLOR.R, FILTER_SELECTED_COLOR.G, FILTER_SELECTED_COLOR.B) 
  184. 	 
  185. 	--Change text colors 
  186. 	if index ~= self.selected_index then 
  187. 		x_of_y_h = vint_object_find("x_of_y", filter_previous.handle, self.doc_handle) 
  188. 		filter_name_h = vint_object_find("filter_name", filter_previous.handle, self.doc_handle)			 
  189. 		vint_set_property(filter_name_h, "tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B) 
  190. 		vint_set_property(x_of_y_h, 		"tint", FILTER_UNSELECTED_COLOR.R, FILTER_UNSELECTED_COLOR.G, FILTER_UNSELECTED_COLOR.B) 
  191. 	end 
  192.  
  193. 	if do_callback then 
  194. 		self:filter_callback_change_do(filter.filter_type) 
  195. 	end 
  196. 	 
  197. 	--store index to object... 
  198. 	self.selected_index = index 
  199. end 
  200.  
  201. ------------------------------------------------------------------------------- 
  202. -- Changes the filter by filter type 
  203. -- 
  204. -- @param	filter_type		filter type is determined by what the game uses to change filters 
  205. -- @param	do_callback		True to actually change the filter in game, False if to change the visual. 
  206. ------------------------------------------------------------------------------- 
  207. function Vdo_cell_filter:change_filter_by_type(filter_type, do_callback) 
  208. 	local filter_idx = self.filters[0] 
  209. 	for idx, val in pairs(self.filters) do 
  210. 		if val.filter_type == filter_type then 
  211. 			filter_idx = idx 
  212. 			break 
  213. 		end 
  214. 	end 
  215. 	self:change_filter(filter_idx, do_callback) 
  216. end 
  217.  
  218.  
  219. ------------------------------------------------------------------------------- 
  220. -- Adjust layout of the screen 
  221. ------------------------------------------------------------------------------- 
  222. function Vdo_cell_filter:adjust_layout(min_width) 
  223. 	 
  224. 	--Go through filters and store the elements into a format to find widest text element... 
  225. 	local data = {} 
  226. 	for idx, val in pairs(self.filters) do 
  227. 		local h = vint_object_find("filter_name", val.item.handle) 
  228. 		data[idx] = h 
  229. 	end 
  230. 	 
  231. 	local widest_filter_element_h, filter_element_width = find_widest_text_element(data) 
  232. 	 
  233. 	if widest_filter_element_h == 0 then 
  234. 		--exit if no filter elements exit yet.. 
  235. 		return 0 
  236. 	end 
  237. 		 
  238. 	local start_x, start_y = vint_get_property(widest_filter_element_h, "anchor") 
  239. 	local target_x = start_x + filter_element_width + self.x_y_width  + 10 
  240. 	 
  241. 	if min_width ~= nil then 
  242. 		--when resetting to our min width value we need to subtract the padding. 
  243. 		min_width = min_width - 32 
  244. 		target_x = min_width 
  245. 	end 
  246.  
  247. 	--reposition each x_y element... 
  248. 	for idx, val in pairs(self.filters) do 
  249. 		local x_y_h = vint_object_find("x_of_y", val.item.handle, self.doc_handle) 
  250. 		local x, y = vint_get_property(x_y_h, "anchor") 
  251. 		vint_set_property(x_y_h, "anchor", target_x, y ) 
  252. 	end 
  253. 	 
  254. 	--Add padding in from the group on the left side. 
  255. 	return target_x + 32	 
  256. end 
  257.  
  258. ------------------------------------------------------------------------------- 
  259. -- Calls the game function callback to change the filter type. 
  260. -- @param filter_type	the filter type that the game reads to change it... 
  261. ------------------------------------------------------------------------------- 
  262. function Vdo_cell_filter:filter_callback_change_do(filter_type) 
  263. 	if self.filter_change_callback ~= nil then 
  264. 		self.filter_change_callback(filter_type) 
  265. 	end 
  266. end 
  267.  
  268. ------------------------------------------------------------------------------- 
  269. -- Sets the callback function for the vdo to call. 
  270. -- @param func		The game function that the vdo calls to change the filter type. 
  271. ------------------------------------------------------------------------------- 
  272. function Vdo_cell_filter:filter_callback_set(func) 
  273. 	self.filter_change_callback = func 
  274. end 
  275.  
  276. function Vdo_cell_filter:get_filter_data() 
  277. 	local filter = self.filters[self.selected_index] 
  278. 	local name 	= filter.filter_name 
  279. 	local x		= filter.x 
  280. 	local y 		= filter.y 
  281. 	return name, x, y 
  282. end 
  283.  
  284. ------------------------------------------------------------------------------- 
  285. -- Determines whether or not we should show filter icons 
  286. -- @param func		The game function that the vdo calls to change the filter type. 
  287. ------------------------------------------------------------------------------- 
  288. function Vdo_cell_filter:set_use_icons(use_icons) 
  289. 	self.use_icons = use_icons 
  290. end 
  291.  
  292. function Vdo_cell_filter:get_filter_index(handle) 
  293.  
  294. 	for idx, filter in pairs(self.filters) do 
  295. 		if filter.item.handle == handle then 
  296. 			return idx 
  297. 		end 
  298. 	end 
  299.  
  300. 	return -1 
  301. end 
  302.  
  303. -- callback_nav and callback_action are optional overrides (func_prefix is ignored if they are used) 
  304. function Vdo_cell_filter:add_mouse_inputs(func_prefix, input_tracker, priority, callback_nav, callback_action) 
  305. 	if (self.filters == nil) or (func_prefix == nil) or (input_tracker == nil) then 
  306. 		return 
  307. 	end 
  308. 	 
  309. 		-- Default priority value to 50 
  310. 	self.priority = priority or 50 
  311. 	 
  312. 	self.mouse_move_function = callback_nav or func_prefix.."_mouse_move" 
  313. 	self.mouse_click_function = callback_action or func_prefix.."_mouse_click" 
  314. 	 
  315. 	for idx, filter in pairs(self.filters) do 
  316. 		vint_set_property(filter.item.handle, "mouse_depth", -4002) 
  317. 		input_tracker:add_mouse_input("mouse_move", self.mouse_move_function, self.priority, filter.item.handle) 
  318. 		input_tracker:add_mouse_input("mouse_click", self.mouse_click_function, self.priority, filter.item.handle) 
  319. 	end 
  320. end