./vdo_cell_missions_list.lua

  1. function vdo_cell_missions_list_init() 
  2. end 
  3.  
  4. function vdo_cell_missions_list_cleanup() 
  5. end 
  6.  
  7. -- Inherited from Vdo_base_object 
  8. Vdo_cell_missions_list = Vdo_base_object:new_base() 
  9.  
  10. local LIST_BUTTON_SPACE = -5 
  11. local MISSION_BUTTON_HEIGHT = 100 
  12. local MISSION_BUTTON_SPACING = 5 
  13. local Game_platform 
  14. local CLIP_PADDING = 20 
  15. local Draw_items_called = false 
  16.  
  17. function Vdo_cell_missions_list:initialize() 
  18. 	Game_platform = game_get_platform() 
  19. 	 
  20. 	-- Hide the initial button 
  21. 	vint_set_property(vint_object_find("btn_mission", self.handle), "visible", false) 
  22. 	 
  23. 	self.clip_h = vint_object_find("clip_mission", self.handle, self.doc_handle)	 
  24. 	vint_set_property(self.clip_h,"visible", false) 
  25. 	 
  26. 	self.scrollbar = Vdo_scrollbar:new("scrollbar", self.handle, self.doc_handle) 
  27. 	self.scrollbar:set_highlight_color(COLOR_SAINTS_PURPLE) 
  28. 	self.scrollbar:set_size(SCROLLBAR_WIDTH, 390) 
  29. 	self.scrollbar:set_visible(false) 
  30. 	 
  31. 	self.visible_start_idx = 1 
  32. 	self.visible_end_idx = self.max_buttons 
  33. 	self.prev_y = -1			 
  34. end 
  35.  
  36. -- Deletes the internal data and destroys the button clones 
  37. function Vdo_cell_missions_list:cleanup() 
  38. 	if Draw_items_called and self.buttons ~= nil then 
  39. 		for index, button in pairs(self.buttons) do 
  40. 			button:object_destroy() 
  41. 		end 
  42. 		self.buttons = nil 
  43. 	end 
  44. end 
  45.  
  46. --	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 } 
  47. function Vdo_cell_missions_list:draw_items(data, current_option, max_buttons) 
  48.  
  49. 	self:initialize() 
  50. 	 
  51. 	Draw_items_called = true 
  52.  
  53. 	-- Destroy all clones 
  54. 	self:cleanup() 
  55. 	 
  56. 	local btn_mission = Vdo_cell_missions_button:new("btn_mission", self.handle, self.doc_handle) 
  57. 	 
  58. 	-- Get position of first button 
  59. 	local btn_mission_x, btn_mission_y = btn_mission:get_property("anchor") 
  60. 	 
  61. 	-- Set up table for data and clones 
  62. 	self.buttons = {} 
  63. 	self.num_buttons = #data 
  64. 	self.max_buttons = max_buttons 
  65. 	 
  66. 	for index = 1, self.num_buttons do 
  67. 	 
  68. 		self.buttons[index] = Vdo_cell_missions_button:clone(btn_mission.handle) 
  69. 		 
  70. 		local current_button = self.buttons[index] 
  71. 		 
  72. 		-- Set the button info 
  73. 		current_button:populate_button(data[index].display_name, data[index].contact_image, data[index].contact_name, data[index].is_new) 
  74. 		 
  75. 		local prev_x, prev_y 
  76. 		local new_y = 0 
  77. 		if index > 1 then 
  78. 			--get the previous button's height 
  79. 			--local prev_width, prev_height = element_get_actual_size(btn_mission.handle) --self.buttons[index-1]:get_property("screen_size") 
  80. 			 
  81. 			--get the previous button's y 
  82. 			prev_x, prev_y = self.buttons[index-1]:get_property("anchor") 
  83. 			 
  84. 			--set the current button's y to the previous buttons y plus its height 
  85. 			new_y = prev_y + MISSION_BUTTON_HEIGHT --+ LIST_BUTTON_SPACE 
  86. 		end 
  87.  
  88. 		-- Move the button copy into the correct position 
  89. 		current_button:set_property("anchor", btn_mission_x, new_y) 
  90. 		 
  91. 		-- Make the button visible 
  92. 		current_button:set_property("visible", true)		 
  93. 	 
  94. 	end 
  95. 	 
  96. 	-- Set initial cursor position 
  97. 	if current_option == nil then 
  98. 		current_option = 1 
  99. 	elseif current_option > self.num_buttons then 
  100. 		current_option = self.num_buttons 
  101. 	end 
  102. 	 
  103. 	--set the current button to the passed in variable for the current option 
  104. 	self.current_idx = current_option 
  105. 	 
  106. 	-- Handle scrolling 
  107. 	local clip_height = max_buttons * MISSION_BUTTON_HEIGHT 
  108. 	local clip_width, bogus_height = element_get_actual_size(self.clip_h) 
  109. 	local clip_x, clip_y = vint_get_property(self.clip_h,"anchor") 
  110. 	local scrollbar_x, scrollbar_y = self.scrollbar:get_anchor() 
  111. 	vint_set_property(self.clip_h, "clip_size", clip_width, clip_height) 
  112. 	self.scrollbar:set_anchor(scrollbar_x,clip_y) 
  113. 		 
  114. 	if(self.num_buttons > max_buttons) then 
  115. 		--show the scroll bar 
  116. 		self.scrollbar:set_property("visible", true) 
  117. 		vint_set_property(self.clip_h,"visible", true) 
  118. 		 
  119. 		local scrollbar_height = clip_height -- CLIP_PADDING 
  120. 		if Game_platform == "PC" then 
  121. 			local total_height = self.num_buttons * MISSION_BUTTON_HEIGHT  
  122. 			self.scrollbar:set_size(SCROLLBAR_WIDTH, scrollbar_height, total_height) 
  123. 		else 
  124. 			--set the size of the scrollbar 
  125. 			self.scrollbar:set_size(SCROLLBAR_WIDTH, scrollbar_height) 
  126. 		end		 
  127. 	else 
  128. 		--hide the scroll bar 
  129. 		self.scrollbar:set_property("visible", false) 
  130. 		vint_set_property(self.clip_h,"visible", false) 
  131. 	end	 
  132.  
  133. 	-- Draw the cursor 
  134. 	self:move_cursor(0)	 
  135. end 
  136.  
  137. function Vdo_cell_missions_list:move_cursor(direction, is_mouse_input, is_scroll) 
  138.  
  139. 	-- Get current button 
  140. 	self.current_idx = wrap_index(self.current_idx, direction, self.num_buttons) 
  141. 	local current_button = self.buttons[self.current_idx]	 
  142. 	 
  143. 	if is_scroll ~= true then 
  144. 		-- Clear out old highlight 
  145. 		for index, buttons in pairs(self.buttons) do 
  146. 			buttons:set_highlight(false) 
  147. 			buttons:set_property("depth",1) 
  148. 		end 
  149.  
  150. 		debug_print("vint","self.current_idx ========= "..self.current_idx.."\n\n") 
  151. 		current_button = self.buttons[self.current_idx]	 
  152. 		-- Highlight current button 
  153. 		current_button:set_highlight(true) 
  154. 		current_button:set_property("depth", -1) 
  155. 		 
  156. 		--Adjust scrollbar 
  157. 		self.scrollbar:set_value(self.num_buttons, self.current_idx, false ) 
  158. 	end 
  159.  
  160. 	local visual_center = self.max_buttons * 0.5 
  161. 	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) 
  162. 	local new_y = 0  
  163. 	 
  164. 	if is_mouse_input then 
  165. 		new_y = self.prev_y 
  166. 	else	 
  167. 		if self.current_idx < visual_center + 1 or self.num_buttons <= self.max_buttons then 
  168. 			--scrolling in top of list... 
  169. 			-- or no scrolling because there isn't enough missions...  
  170. 			new_y = 0 
  171. 		elseif self.current_idx > self.num_buttons - visual_center then 
  172. 			--Scrolling in bottom of list... 
  173. 			new_y = -(self.num_buttons - self.max_buttons) * move_height  
  174. 		else 
  175. 			--move the list... 
  176. 			new_y = -move_height * (self.current_idx - visual_center) 
  177. 		end 
  178. 	end 
  179. 	 
  180. 	local mission_btn_grp_h = vint_object_find("mission_btn_grp") 
  181. 	local mission_scroll_anim_h = vint_object_find("mission_scroll_anim") 
  182. 	local scroll_twn_h = vint_object_find("scroll_twn", mission_scroll_anim_h)	 
  183. 	 
  184. 	local start_x, start_y = vint_get_property(mission_btn_grp_h, "anchor") 
  185. 	local end_x = start_x 
  186. 	local end_y = new_y 
  187.  
  188. 	vint_set_property(scroll_twn_h, "start_value", start_x, start_y) 
  189. 	vint_set_property(scroll_twn_h, "end_value", end_x, end_y) 
  190. 	lua_play_anim(mission_scroll_anim_h) 
  191. 	 
  192. 	--we scrolled so update visual indices	 
  193. 	if new_y ~= self.prev_y then 
  194. 		if self.current_idx > 1 then 
  195. 			self.visible_start_idx = self.current_idx - 1 
  196. 		else 
  197. 			self.visible_start_idx = 1 
  198. 		end	 
  199. 		 
  200. 		self.visible_end_idx = self.visible_start_idx + (self.max_buttons - 1)	 
  201. 	end	 
  202. 	 
  203. 	self.prev_y = new_y 
  204. end 
  205.  
  206. function Vdo_cell_missions_list:add_mouse_inputs(func_prefix, input_tracker, priority) 
  207. 	if func_prefix == nil then 
  208. 		return 
  209. 	end 
  210. 	 
  211. 	priority = priority or 50 
  212. 	 
  213. 	local mouse_click_function = func_prefix.."_mouse_click" 
  214. 	local mouse_move_function = func_prefix.."_mouse_move" 
  215.  
  216. 	for index, buttons in pairs(self.buttons) do 
  217. 		input_tracker:add_mouse_input("mouse_click", mouse_click_function, priority, buttons.handle) 
  218. 		input_tracker:add_mouse_input("mouse_move", mouse_move_function, priority, buttons.handle) 
  219. 	end 
  220. end 
  221.  
  222. function Vdo_cell_missions_list:get_button_index(target_handle) 
  223. 	for index, buttons in pairs(self.buttons) do 
  224. 		if buttons.handle == target_handle then 
  225. 			return index 
  226. 		end 
  227. 	end 
  228. 	 
  229. 	-- Return 0 as an invalid index 
  230. 	return 0 
  231. end 
  232.  
  233. function Vdo_cell_missions_list:set_selection(index, is_mouse_input, is_scroll) 
  234. 	self.current_idx = index 
  235. 	self:move_cursor(0, is_mouse_input, is_scroll) 
  236. end 
  237.  
  238.