./vdo_button_pip.lua

  1. ----------------------------------------------------------------------------  
  2. -- Vdo_button_pip 
  3. -- A button that contains pips for use in the megalists usually for upgrades 
  4. ---------------------------------------------------------------------------- 
  5.  
  6.  
  7. -- Standard Init Function	 
  8. function vdo_button_pip_init() 
  9. end 
  10.  
  11.  
  12. -- Standard Cleanup Function 
  13. function vdo_button_pip_cleanup() 
  14. end 
  15.  
  16. -- Inherited from Vdo_base_object 
  17. Vdo_button_pip = Vdo_base_object:new_base() 
  18.  
  19. ---------------------------------------------------------------------------  
  20. -- Initializes VDO Object 
  21. --------------------------------------------------------------------------- 
  22. function Vdo_button_pip:init() 
  23. 	self.base_pip_img_h = vint_object_find("pip_img", self.handle, self.doc_handle) 
  24. end 
  25.  
  26.  
  27. ---------------------------------------------------------------------------  
  28. -- Set pips 
  29. --------------------------------------------------------------------------- 
  30. function Vdo_button_pip:set_pips(total, num_active, list_width, color) 
  31. 		 
  32. 	--Table of pips 
  33. 	self.pips_h = {} 
  34. 	self.color = color 
  35. 		 
  36. 	--Hide the base pip 
  37. 	vint_set_property(self.base_pip_img_h, "visible", false) 
  38. 	 
  39. 	--Get anchor of base pip 
  40. 	local base_x, base_y = vint_get_property(self.base_pip_img_h, "anchor") 
  41. 		 
  42. 	--Take the width of the list - (width of all the pips + 1.5 for padding) 
  43. 	local PIP_SPACE = 25 
  44. 	local new_x = list_width - ((total + 1.5) * PIP_SPACE) 
  45. 		 
  46. 	--Clone the pips we need 
  47. 	for i=1, total do 
  48. 		self.pips_h[i] = vint_object_clone(self.base_pip_img_h) 
  49. 		 
  50. 		local current_pip = self.pips_h[i] 
  51. 		 
  52. 		--Set pip on or off 
  53. 		if i <= num_active then 
  54. 			--On 
  55. 			vint_set_property(current_pip, "image", "ui_pip_full") 
  56. 		else 
  57. 			--Off 
  58. 			vint_set_property(current_pip, "image", "ui_pip_empty") 
  59. 		end 
  60. 		 
  61. 		--Space out pips 
  62. 		vint_set_property(current_pip, "anchor", new_x, base_y) 
  63. 		new_x = new_x + PIP_SPACE 
  64. 		 
  65. 		--Color pips 
  66. 		vint_set_property(current_pip, "tint", color.r, color.g, color.b) 
  67. 		 
  68. 		--Set visible 
  69. 		vint_set_property(current_pip, "visible", true) 
  70. 	end	 
  71. end 
  72.  
  73.  
  74. ---------------------------------------------------------------------------  
  75. -- Tint pips for highlight state 
  76. --------------------------------------------------------------------------- 
  77. function Vdo_button_pip:set_highlight(is_highlighted) 
  78. 	if self.pips_h ~= nil then 
  79. 		for i=1, #self.pips_h do 
  80. 			if is_highlighted then 
  81. 				vint_set_property(self.pips_h[i], "tint", 0, 0, 0) 
  82. 			else 
  83. 				vint_set_property(self.pips_h[i], "tint", self.color.R, self.color.G, self.color.B) 
  84. 			end 
  85. 		end 
  86. 	end 
  87. end 
  88.