./vdo_store_popup.lua

  1.  
  2. function vdo_store_popup_init() 
  3. end 
  4.  
  5.  
  6. -- Inherited from Vdo_base_object 
  7. Vdo_store_popup = Vdo_base_object:new_base() 
  8.  
  9.  
  10. local Input_tracker 
  11. local Mouse_input_tracker 
  12.  
  13. local STORE_POPUP_BORDER_PAD = 5 
  14. local STORE_POPUP_TITLE_PAD = 38 
  15. local STORE_POPUP_TEXT_PAD = 10 
  16. local STORE_POPUP_LIST_PAD = 2 
  17.  
  18.  
  19. function Vdo_store_popup:init() 
  20. 	self.title = Vdo_base_object:new("popup_title",self.handle, self.doc_handle) 
  21. 	self.text = Vdo_base_object:new("popup_text",self.handle, self.doc_handle) 
  22. 	self.border_h = vint_object_find("popup_border",self.handle, self.doc_handle) 
  23. 	self.fill_h = vint_object_find("popup_fill",self.handle, self.doc_handle) 
  24. 	self.list = Vdo_mega_list:new("popup_list", self.handle, self.doc_handle) 
  25. 	 
  26. 	self.menu_option_text_scale = 1 
  27. 	Input_tracker = Vdo_input_tracker:new() 
  28. 	 
  29. 	-- Initialize the mouse input tracker for the PC 
  30. 	if game_get_platform() == "PC" then 
  31. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  32. 	end 
  33. end 
  34.  
  35.  
  36. function Vdo_store_popup:cleanup() 
  37. 	self.list:cleanup() 
  38. 	self:subscribe_modify(false) 
  39. end 
  40.  
  41.  
  42. function Vdo_store_popup:populate_list(list_data, current_index, width, max_buttons) 
  43. 	self.list:draw_items(list_data, current_index, width - (STORE_POPUP_BORDER_PAD * 4), max_buttons, LIST_FONT_SCALE, nil, false) 
  44. 	self.max_buttons = max_buttons 
  45. 	game_UI_audio_play("UI_HUD_Help")	 
  46. end 
  47.  
  48.  
  49. function Vdo_store_popup:set_text(new_text) 
  50. 	self.text:set_text(new_text) 
  51.  
  52. 	-- Resize the list and border to fit text size 
  53. 	local text_width, text_height = self.text:get_actual_size() 
  54. 	local text_x, text_y = self.text:get_anchor() 
  55. 	local list_x, list_y = self.list:get_anchor() 
  56. 	 
  57. 	self.list:set_anchor(list_x, (text_y - STORE_POPUP_LIST_PAD) + text_height + STORE_POPUP_TEXT_PAD)	 
  58. 	 
  59. 	--calculate width and height of box and set it... 
  60. 	local list_width, list_height = self.list:get_size() 
  61. 	local height = STORE_POPUP_TITLE_PAD + list_height + text_height + (STORE_POPUP_TEXT_PAD * 2) 
  62. 	local width = self.width 
  63. 	self:set_size(width, height)	 
  64. end 
  65.  
  66.  
  67. function Vdo_store_popup:set_title(new_title)	 
  68. 	self.title:set_text(new_title)		 
  69. end 
  70.  
  71.  
  72. function Vdo_store_popup:set_menu_option_text_scale(scale) 
  73. 	self.menu_option_text_scale = scale 
  74. end 
  75.  
  76.  
  77. ------------------------------------------------------------------------------- 
  78. -- Sets color of popup... 
  79. -- primary		table.R, table.G, table.B 
  80. -- secondary	table.R, table.G, table.B 
  81. -- tertiary		table.R, table.G, table.B 
  82. ------------------------------------------------------------------------------- 
  83. function Vdo_store_popup:set_color(primary, secondary, tertiary) 
  84. 	vint_set_property(self.border_h, "tint", primary.R, primary.G, primary.B) 
  85. 	self.list:set_highlight_color(primary) 
  86. end 
  87.  
  88.  
  89. function Vdo_store_popup:set_size(width, height) 
  90. 	self.width = width 
  91. 	self.height = height 
  92.  
  93. 	local fill_width = width - (STORE_POPUP_BORDER_PAD * 2) 
  94. 	local fill_height = height - STORE_POPUP_TITLE_PAD 
  95. 	 
  96. 	element_set_actual_size(self.border_h, width, height) 
  97. 	element_set_actual_size(self.fill_h, fill_width, fill_height) 
  98. 	vint_set_property(self.text.handle, "wrap_width", width - 67)	-- This should be standardized... I just took this out of store common list size and subtracted what was in the document. JMH 7/5/2011) 
  99. end 
  100.  
  101.  
  102. function Vdo_store_popup:get_size() 
  103. 	return self.width, self.height 
  104. end 
  105.  
  106.  
  107. function Vdo_store_popup:subscribe_modify(do_subscribe) 
  108. 	Input_tracker:subscribe(do_subscribe) 
  109. 	if Mouse_input_tracker ~= nil then 
  110. 		Mouse_input_tracker:subscribe(do_subscribe) 
  111. 	end 
  112. end 
  113.  
  114.  
  115. function Vdo_store_popup:nav_enable(is_on, callback_action, callback_nav)	 
  116. 	if is_on then	 
  117. 		-- Remove the button presses that are already set 
  118. 		Input_tracker:remove_input("select") 
  119. 		Input_tracker:remove_input("back") 
  120. 		Input_tracker:remove_input("nav_up") 
  121. 		Input_tracker:remove_input("nav_down") 
  122. 		Input_tracker:remove_input("alt_select") 
  123. 		Input_tracker:remove_input("all_unassigned")	 
  124. 		Input_tracker:subscribe(false) 
  125. 		 
  126. 		if Mouse_input_tracker ~= nil then 
  127. 			Mouse_input_tracker:remove_all() 
  128. 		end	 
  129. 	 
  130. 		-- Subscribe to the button presses we need 
  131. 		Input_tracker:add_input("select", callback_action, 200) 
  132. 		Input_tracker:add_input("back", callback_action, 200) 
  133. 		Input_tracker:add_input("nav_up", callback_nav, 200) 
  134. 		Input_tracker:add_input("nav_down", callback_nav, 200) 
  135. 		Input_tracker:add_input("alt_select", "store_common_do_nothing", 200) 
  136. 		Input_tracker:add_input("all_unassigned", "store_common_do_nothing", 200) 
  137. 		Input_tracker:subscribe(true) 
  138. 		 
  139. 		-- Subscribe to the mouse inputs needed for the PC 
  140. 		if Mouse_input_tracker ~= nil and self.list.buttons ~= nil then 
  141. 			self:add_mouse_inputs(callback_action, callback_nav, Mouse_input_tracker) 
  142. 			Mouse_input_tracker:subscribe(true) 
  143. 		end 
  144. 		 
  145. 		self:set_visible(true) 
  146. 		 
  147. 		self.callback_action = callback_action 
  148. 	else 
  149. 		-- Remove the button presses we needed 
  150. 		Input_tracker:remove_input("select") 
  151. 		Input_tracker:remove_input("back") 
  152. 		Input_tracker:remove_input("nav_up") 
  153. 		Input_tracker:remove_input("nav_down") 
  154. 		Input_tracker:remove_input("alt_select") 
  155. 		Input_tracker:remove_input("all_unassigned")	 
  156. 		Input_tracker:subscribe(false) 
  157. 		 
  158. 		if Mouse_input_tracker ~= nil then 
  159. 			Mouse_input_tracker:remove_all() 
  160. 		end 
  161. 		 
  162. 		self:set_visible(false) 
  163. 		self.callback_action = nil 
  164. 	end 
  165. end 
  166.  
  167.  
  168. function Vdo_store_popup:get_selected_data() 
  169. 	return self.list:get_selection() 
  170. end 
  171.  
  172.  
  173. -- ===================================== 
  174. --       Mouse Specific Functions 
  175. -- ===================================== 
  176.  
  177. -- Adds "mouse_click" and "mouse_move" input subscriptions to each button in the popup's list 
  178. -- 
  179. function Vdo_store_popup:add_mouse_inputs(callback_action, callback_nav, input_tracker, priority) 
  180. 	if (self.list.buttons == nil) or (callback_action == nil) or (callback_nav == nil) then 
  181. 		return 
  182. 	end 
  183. 	 
  184. 	-- Default priority value to 200 
  185. 	priority = priority or 200 
  186.  
  187. 	-- Use the list to add the actual inputs because it's not exactly straightforward 
  188. 	self.list:add_mouse_inputs("blank", Mouse_input_tracker, priority, callback_nav, callback_action, -9000) 
  189. end