./vdo_button_highlight.lua

  1. ---------------------------------------------------------------------------  
  2. -- Vdo_button_highlight 
  3. -- 
  4. -- The highlight behind a botton toggle for use in a megalist. 
  5. --------------------------------------------------------------------------- 
  6. local BOTTOM_FILL_PAD = 8 
  7. local Levels_off = {} 
  8. local Levels_on = {} 
  9.  
  10. -- Standard Init Function	 
  11. function vdo_button_highlight_init() 
  12. end 
  13.  
  14. -- Standard Cleanup Function 
  15. function vdo_button_highlight_cleanup() 
  16. end 
  17.  
  18. -- Inherited from Vdo_base_object 
  19. Vdo_button_highlight = Vdo_base_object:new_base() 
  20.  
  21. ---------------------------------------------------------------------------  
  22. -- Initializes VDO Object 
  23. --------------------------------------------------------------------------- 
  24. function Vdo_button_highlight:init() 
  25.    self.bottom_grp = Vdo_base_object:new("bottom_grp", self.handle, self.doc_handle) 
  26. 	self.bottom_bar = Vdo_base_object:new("bottom_bar", self.handle, self.doc_handle) 
  27. 	self.extended_text = Vdo_base_object:new("extended_text", self.handle, self.doc_handle) 
  28. 	 
  29. 	self.item_stats = Vdo_item_stats:new("item_stats", self.handle, self.doc_handle) 
  30. 	 
  31. 	--Hide bottom group.. 
  32. 	self.bottom_grp:set_visible(false) 
  33. end 
  34.  
  35. function Vdo_button_highlight:cleanup() 
  36. 	if self.item_stats ~= nil then 
  37. 		self.item_stats:cleanup() 
  38. 	end 
  39. end 
  40.  
  41. ---------------------------------------------------------------------------  
  42. -- Sets the button image on the VDO Object. 
  43. -- @param button_icon	Button Icon, please use the globals set in  
  44. --								vdo_hint_button.lua. If no button is provided the 
  45. --								button is hidden. 
  46. --------------------------------------------------------------------------- 
  47. function Vdo_button_highlight:show_button(button_icon, override_show) 
  48. 	local button = Vdo_hint_button:new("icon", self.handle, self.doc_handle) 
  49. 	local always_show = override_show or false 
  50. 	 
  51. 	if game_is_active_input_gamepad() or always_show == true then 
  52. 		if button.handle ~= 0 then 
  53. 			if button_icon == "" then 
  54. 				button:set_property("visible", false) 
  55. 			else 
  56. 				if always_show == true then 
  57. 					button:set_button( button_icon, "", true ) 
  58. 				else 
  59. 					button:set_button( button_icon ) 
  60. 				end 
  61. 				button:set_property("visible", true) 
  62. 			end 
  63. 		end 
  64. 	else 
  65. 		button:set_property("visible", false) 
  66. 	end 
  67. end 
  68.  
  69.  
  70. ---------------------------------------------------------------------------  
  71. -- Sets width of the button highlight 
  72. -- @param width    Width of the highlight in pixels 
  73. --------------------------------------------------------------------------- 
  74. function Vdo_button_highlight:set_width(width) 
  75. 	-- Set width of bottom fill 
  76. 	local bg = Vdo_base_object:new("bg", self.handle, self.doc_handle) 
  77. 	local bottom_bar = Vdo_base_object:new("bottom_bar", self.handle, self.doc_handle) 
  78. 	local bottom_fill = Vdo_base_object:new("bottom_bar_fill", self.handle, self.doc_handle) 
  79. 	 
  80. 	--Get sizes of width and height for manipulation... 
  81. 	local bg_width, bg_height = bg:get_actual_size() 
  82. 	local bottom_bar_width, bottom_bar_height = bottom_bar:get_actual_size() 
  83. 	local bottom_fill_width, bottom_fill_height = bottom_fill:get_actual_size() 
  84. 	 
  85. 	--Set sizes of bar... 
  86. 	bg:set_actual_size(width, bg_height) 
  87. 	bottom_bar:set_actual_size(width, bottom_bar_height) 
  88. 	bottom_fill:set_actual_size(width - BOTTOM_FILL_PAD, bottom_fill_height) 
  89. end 
  90.  
  91. function Vdo_button_highlight:set_highlight() 
  92. end 
  93.  
  94.  
  95. ---------------------------------------------------------------------------  
  96. -- Colors highlight bar 
  97.  
  98. -- @param new_color    	  Sets color of highlight 
  99. ---------------------------------------------------------------------------  
  100. function Vdo_button_highlight:set_highlight_color(new_color) 
  101. 	local bg = Vdo_base_object:new("bg", self.handle, self.doc_handle) 
  102. 	self.highlight_color = new_color 
  103. 	 
  104. 	bg:set_color(new_color.R, new_color.G, new_color.B)	 
  105. 	self.bottom_bar:set_color(new_color.R, new_color.G, new_color.B)	 
  106. 	self.extended_text:set_color(new_color.R, new_color.G, new_color.B)		 
  107. end 
  108.  
  109.  
  110. ---------------------------------------------------------------------------  
  111. -- Reveals extra info on highlight for items that have levels 
  112.  
  113. -- @param is_extended    	Determines visibilty of extra highlight  
  114. --									line. 
  115. ---------------------------------------------------------------------------  
  116. function Vdo_button_highlight:show_extended(is_extended) 
  117.  
  118. 	self.bottom_grp:set_visible(is_extended) 
  119. end 
  120.  
  121. ---------------------------------------------------------------------------  
  122. -- Sets levels for items that are upgradable such as rewards,  
  123. -- performance mods, etc. 
  124.  
  125. -- @param max_level    		Max level of item.  Determines how  
  126. --									many slots to show. 
  127. -- 
  128. -- @param current_level		Current level of item. Fills in the 
  129. --									the slots. 
  130. ---------------------------------------------------------------------------  
  131. function Vdo_button_highlight:set_level(max_level, current_level, is_purchased, show_next_level) 
  132. 	 
  133. 	local stats_data 
  134. 	if is_purchased == false or is_purchased == nil then 
  135. 		--Set current level... 
  136. 		stats_data = { 
  137. 			[1] = { 
  138. 				label = "STORE_LEVEL", 
  139. 				level = current_level, 
  140. 				max_level = max_level, 
  141. 			}		 
  142. 		} 
  143. 	else 
  144. 		-- If user has max levels then they own that item 
  145. 		stats_data = { 
  146. 			[1] = { 
  147. 				label = "STORE_LEVEL", 
  148. 				level = current_level, 
  149. 				max_level = max_level, 
  150. 			}	 
  151. 		} 
  152. 	end 
  153.  
  154. 	--Set item stats level... 
  155. 	self.item_stats:draw_items(stats_data, show_next_level) 
  156. end 
  157.