./vdo_item_stats.lua

  1. function vdo_item_stats_init() 
  2. end 
  3.  
  4. function vdo_item_stats_cleanup() 
  5. end 
  6.  
  7. -- Inherited from Vdo_base_object 
  8. Vdo_item_stats = Vdo_base_object:new_base() 
  9.  
  10. local ITEM_VERTICAL_SPACING = 0			-- Spacing between the elements vertically... 
  11. local ITEM_STATS_LABEL_SPACING = 10		--  
  12. local NUM_ITEM_LEVELS = 5 					-- needs to match the number in the vint_doc 
  13.  
  14. function Vdo_item_stats:init() 
  15. 	--Store base objects... 
  16. 	self.base_item_stat_h 	= vint_object_find("base_stat_grp", self.handle, self.doc_handle) 
  17. 	self.base_pulse_anim_h 	= vint_object_find("pulse_lvl_anim", self.handle, self.doc_handle) 
  18. 	self.base_pulse_twn_h 	= vint_object_find("pulse_lvl_twn", self.base_pulse_anim_h)  
  19.  
  20. 	-- Hide the initial stat 
  21. 	vint_set_property(self.base_item_stat_h, "visible", false)		 
  22. end 
  23.  
  24. -- Deletes the internal data and destroys the button clones 
  25. function Vdo_item_stats:cleanup() 
  26. 	if self.items ~= nil then 
  27. 		for index, item in pairs(self.items) do 
  28. 			vint_object_destroy(item.item_h) 
  29. 		end 
  30. 		self.items = nil 
  31. 	end 
  32. end 
  33.  
  34. ------------------------------------------------------------------------------- 
  35. -- Populates the data... 
  36. -- 
  37. --	Data example 
  38. -- 
  39. --	local Vehicle_stats_data = { 
  40. --			[1] = { 
  41. --				label = "TEST_TORQUE", 
  42. --				max_level = 5, 
  43. --				level = 2, 
  44. --			}, 
  45. --			[2] = { 
  46. --				label = "TEST_OFFENSE", 
  47. --				max_level = 5, 
  48. --				level = 5, 
  49. --			},	 
  50. --		} 
  51. ------------------------------------------------------------------------------- 
  52. function Vdo_item_stats:draw_items(data, show_next_level) 
  53. 	--Reset label width... 
  54. 	self.max_label_width = 0 
  55. 	 
  56. 	-- Destroy all clones 
  57. 	self:cleanup() 
  58. 	 
  59. 	-- Get position of first item 
  60. 	--local item_stat_x, item_stat_y = item_stat:get_property("anchor") 
  61. 	 
  62. 	-- Set up table for data and clones 
  63. 	self.items = {} 
  64. 	self.num_items = #data 
  65. 	 
  66. 	for index = 1, self.num_items do 
  67. 	 
  68. 		local item = {} 
  69. 		local item_h = vint_object_clone(self.base_item_stat_h) 
  70. 		local item_label_h = vint_object_find("item_label", item_h) 
  71. 		local lvl_grp_h = vint_object_find("lvl_grp", item_h) 
  72.  
  73. 		--Set text of our current row... 
  74. 		local label_str = data[index].label 
  75. 		vint_set_property(item_label_h, "text_tag", label_str) 
  76. 		 
  77. 		-- find max label width to line up stats 
  78. 		local label_width, label_height = element_get_actual_size(item_label_h) 
  79. 		self.max_label_width = max(label_width, self.max_label_width) 
  80. 		 
  81. 		-- Turn on the levels that we need... 
  82. 		for i = 1, NUM_ITEM_LEVELS do 
  83. 			--find each element... 
  84. 			local lvl_on_h = vint_object_find("lvl_on" .. i, item_h) 
  85. 			local lvl_off_h = vint_object_find("lvl_off" .. i, item_h)		 
  86.  
  87. 			vint_set_property(lvl_off_h, "visible", false) 
  88. 			vint_set_property(lvl_on_h, "visible", false)			 
  89. 			 
  90. 			if i <= data[index].max_level then 
  91. 				-- Only turn on what we need... 
  92. 				vint_set_property(lvl_off_h, "visible", true) 
  93. 				if i <= data[index].level  then 
  94. 					vint_set_property(lvl_on_h, "alpha", 1) 
  95. 					vint_set_property(lvl_on_h, "visible", true) 
  96. 				end 
  97. 			else 
  98. 				-- turn off the rest... 
  99. 				vint_set_property(lvl_off_h, "visible", false) 
  100. 				vint_set_property(lvl_on_h, "visible", false) 
  101. 			end 
  102. 		end		 
  103. 		 
  104. 		-- animate next level 
  105. 		if show_next_level then 
  106. 			local next_level = data[index].level + 1 
  107. 			local max_level = data[index].max_level 
  108. 			 
  109. 			--make sure we havn't already maxed out... 
  110. 			if max_level >= next_level then 
  111. 				local lvl_on_h = vint_object_find("lvl_on" .. next_level, item_h) 
  112. 				 
  113. 				--verify that we have a legitimate target... 
  114. 				if lvl_on_h ~= 0 and lvl_on_h ~= nil then 
  115. 					--show next level and animate it... 
  116. 					vint_set_property(lvl_on_h, "visible", true) 
  117. 					--vint_set_property(lvl_on_h, "tint", need color passed down) 
  118. 					vint_set_property(self.base_pulse_twn_h, "target_handle", lvl_on_h) 
  119. 					lua_play_anim(self.base_pulse_anim_h) 
  120. 				end 
  121. 			else 
  122. 				-- Pause animation 
  123. 				vint_set_property(self.base_pulse_anim_h, "is_paused", true) 
  124. 			end			 
  125. 		end 
  126. 		 
  127. 		--store object handles to a table for alignment and cleanup... 
  128. 		item.item_h = item_h 
  129. 		item.item_label_h = item_label_h 
  130. 		 
  131. 		--store item into the self... 
  132. 		self.items[index] = item 
  133. 		 
  134. 		-- position each element...	 
  135. 		local prev_x, prev_y 
  136. 		local new_y 
  137. 		 
  138. 		if index <= 1 then 
  139. 			new_y = 0 
  140. 		else 
  141. 			--get the previous button's y 
  142. 			local prev_item_h = self.items[index - 1].item_h  
  143. 			prev_x, prev_y = vint_get_property(prev_item_h, "anchor") 
  144. 			 
  145. 			--set the current button's y to the previous buttons y plus its height 
  146. 			new_y = prev_y + label_height + ITEM_VERTICAL_SPACING 
  147. 		end 
  148. 		 
  149. 		-- Move the button copy into the correct position\ 
  150. 		vint_set_property(item_h, "anchor", 0, new_y) 
  151. 		 
  152. 		 
  153. 		-- Make the button visible 
  154. 		vint_set_property(item_h, "visible", true) 
  155. 	end 
  156. 	 
  157. 	--Align all level meters in VDO to right of max level width... 
  158. 	for index = 1, self.num_items do 
  159. 		local lvl_grp_h = vint_object_find("lvl_grp", self.items[index].item_h)  
  160. 		local lvl_grp_x, lvl_grp_y = vint_set_property(lvl_grp_h, "anchor") 
  161. 		lvl_grp_x = self.max_label_width + ITEM_STATS_LABEL_SPACING 
  162. 		vint_set_property(lvl_grp_h, "anchor", lvl_grp_x, lvl_grp_y) 
  163. 	end 
  164. end 
  165.  
  166.  
  167.  
  168.