./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 button_cap = Vdo_base_object:new("button_cap", self.handle, self.doc_handle) 
  78.  
  79. 	local bottom_bar = Vdo_base_object:new("bottom_bar", self.handle, self.doc_handle) 
  80. 	local bottom_fill = Vdo_base_object:new("bottom_bar_fill", self.handle, self.doc_handle) 
  81. 	 
  82. 	--Get sizes of width and height for manipulation... 
  83. 	local bg_width, bg_height = bg:get_actual_size() 
  84. 	local button_cap_width, button_cap_height = button_cap:get_actual_size() 
  85.  
  86. 	local bottom_bar_width, bottom_bar_height = bottom_bar:get_actual_size() 
  87. 	local bottom_fill_width, bottom_fill_height = bottom_fill:get_actual_size() 
  88. 	 
  89. 	--Set sizes of bar... 
  90. 	bg:set_actual_size(width-button_cap_width, bg_height) 
  91. 	button_cap:set_actual_size(button_cap_width, bg_height) 
  92.  
  93. 	bottom_bar:set_actual_size(width-button_cap_width, bottom_bar_height) 
  94. 	bottom_fill:set_actual_size(width - BOTTOM_FILL_PAD, bottom_fill_height) 
  95. end 
  96.  
  97. function Vdo_button_highlight:set_highlight() 
  98. end 
  99.  
  100.  
  101. ---------------------------------------------------------------------------  
  102. -- Colors highlight bar 
  103.  
  104. -- @param new_color    	  Sets color of highlight 
  105. ---------------------------------------------------------------------------  
  106. function Vdo_button_highlight:set_highlight_color(new_color) 
  107. 	local bg = Vdo_base_object:new("bg", self.handle, self.doc_handle) 
  108. 	local button_buffer = Vdo_base_object:new("button_buffer", self.handle, self.doc_handle) 
  109. 	local button_cap = Vdo_base_object:new("button_cap", self.handle, self.doc_handle) 
  110. 	self.highlight_color = new_color 
  111. 	 
  112. 	bg:set_color(new_color.R, new_color.G, new_color.B)	 
  113. 	button_buffer:set_color(new_color.R, new_color.G, new_color.B) 
  114. 	button_cap:set_color(new_color.R, new_color.G, new_color.B) 
  115. 	self.bottom_bar:set_color(new_color.R, new_color.G, new_color.B)	 
  116. 	self.extended_text:set_color(new_color.R, new_color.G, new_color.B)		 
  117. end 
  118.  
  119.  
  120. ---------------------------------------------------------------------------  
  121. -- Reveals extra info on highlight for items that have levels 
  122.  
  123. -- @param is_extended    	Determines visibilty of extra highlight  
  124. --									line. 
  125. ---------------------------------------------------------------------------  
  126. function Vdo_button_highlight:show_extended(is_extended) 
  127.  
  128. 	self.bottom_grp:set_visible(is_extended) 
  129. end 
  130.  
  131. ---------------------------------------------------------------------------  
  132. -- Sets levels for items that are upgradable such as rewards,  
  133. -- performance mods, etc. 
  134.  
  135. -- @param max_level    		Max level of item.  Determines how  
  136. --									many slots to show. 
  137. -- 
  138. -- @param current_level		Current level of item. Fills in the 
  139. --									the slots. 
  140. ---------------------------------------------------------------------------  
  141. function Vdo_button_highlight:set_level(max_level, current_level, is_purchased, show_next_level) 
  142. 	 
  143. 	local stats_data 
  144. 	if is_purchased == false or is_purchased == nil then 
  145. 		--Set current level... 
  146. 		stats_data = { 
  147. 			[1] = { 
  148. 				label = "STORE_LEVEL", 
  149. 				level = current_level, 
  150. 				max_level = max_level, 
  151. 			}		 
  152. 		} 
  153. 	else 
  154. 		-- If user has max levels then they own that item 
  155. 		stats_data = { 
  156. 			[1] = { 
  157. 				label = "STORE_LEVEL", 
  158. 				level = current_level, 
  159. 				max_level = max_level, 
  160. 			}	 
  161. 		} 
  162. 	end 
  163.  
  164. 	--Set item stats level... 
  165. 	self.item_stats:draw_items(stats_data, show_next_level) 
  166. end 
  167.