./vdo_store_popup.lua

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