./vdo_gsi_meter.lua

  1. ------------------------------------------------------------------------------- 
  2. --GSI Meter Component 
  3. ------------------------------------------------------------------------------- 
  4. -- Inherited from Vdo_base_object 
  5. Vdo_gsi_meter = Vdo_base_object:new_base() 
  6.  
  7. -- Standard Init Function 
  8. function vdo_gsi_meter_init() 
  9. end 
  10.  
  11. -- Standard Cleanup Function 
  12. function vdo_gsi_meter_cleanup() 
  13. end 
  14.  
  15. --CONSTANTS 
  16. local METER_LABEL_PADDING = 9 
  17.  
  18. function Vdo_gsi_meter:init() 
  19. 	--retaget anim 
  20. 	self.meter_pulse_anim_h = vint_object_find("meter_pulse_anim", self.handle) 
  21. 	vint_set_property(self.meter_pulse_anim_h, "target_handle", self.handle) 
  22. 	 
  23. 	self.meter_highlight_grp_h = vint_object_find("meter_highlight_grp", self.handle) 
  24. 	vint_set_property(self.meter_highlight_grp_h, "visible", false) 
  25. end 
  26.  
  27. ------------------------------------------------------------------------------- 
  28. -- Creates and initializes the meter. Still requires an update call afterwards,  
  29. -- but this helps with seperating the two processes of initializing and update. 
  30. ------------------------------------------------------------------------------- 
  31. function Vdo_gsi_meter:create(skin) 
  32. 	--Setup skin 
  33. 	local skin = GSI_SKIN[skin] 
  34. 	if skin == nil then 
  35. 		--No skin use default 
  36. 		skin = GSI_SKIN["Default"]  
  37. 	end 
  38. 	 
  39. 	--Set Tint on Meters 
  40. 	local fill_h = vint_object_find("fill", self.handle) 
  41. 	local highlight_fill_h = vint_object_find("highlight_fill", self.handle) 
  42. 	 
  43. 	local tint = skin.tint 
  44. 	vint_set_property(fill_h, "tint", tint[1], tint[2], tint[3]) 
  45. 	vint_set_property(highlight_fill_h, "tint", tint[1], tint[2], tint[3]) 
  46. 		 
  47. 	--Set width of meter by referencing 
  48. 	local fill_size_full	= vint_get_property(fill_h, "scale") 
  49. 	local fill_size_empty = 0 
  50. 	 
  51. 	--Initialize Standard Indicator Values 
  52. 	self.visible = -1						--Is the indicator displaying?  
  53. 	self.is_dirty = true					--Is the indicator dirty? we set this to true if we want the GSI to re-align everything. 
  54. 	self.skin = skin 
  55. 	 
  56. 	--Store off max size of meter... 
  57. 	local meter_bg_h = vint_object_find("bg", self.handle) 
  58. 	self.meter_width, self.meter_height = element_get_actual_size(meter_bg_h)  
  59. 	 
  60. 	self.label_width = 0 
  61. 	self.width = 100 
  62. 	self.height = 10 
  63. 	 
  64. 	--Get objects for modification in our update... 
  65. 	local text_h = vint_object_find("label_txt", self.handle) 
  66. 	local meter_grp_h = vint_object_find("meter_grp", self.handle) 
  67. 	local meter_highlight_grp_h = vint_object_find("meter_highlight_grp", self.handle) 
  68. 	local highlight_mask_h = vint_object_find("highlight_mask", self.handle) 
  69.  
  70. 	--Store handles to objects... 
  71. 	self.text_h = text_h 
  72. 	self.meter_grp_h = meter_grp_h 
  73. 	self.meter_highlight_grp_h = meter_highlight_grp_h 
  74. 	self.meter_bg_h = meter_bg_h 
  75. 	self.fill_h = fill_h 
  76. 	self.highlight_fill_h = highlight_fill_h 
  77. 	self.highlight_mask_h = highlight_mask_h 
  78. 	 
  79. 	--Initialize Custom Values  
  80. 	self.meter_percent = 1 
  81. 	self.fill_size_full = fill_size_full 
  82. 	self.fill_size_empty = fill_size_empty 
  83. 	self.is_flashing = false 
  84. 	self.label = 0 
  85. end 
  86.  
  87. ------------------------------------------------------------------------------- 
  88. --Updates the meter 
  89. ------------------------------------------------------------------------------- 
  90. function Vdo_gsi_meter:update(visible, skin, label_crc, meter_percent, is_flashing) 
  91. 	--Set visible 
  92. 	self:set_visible(visible) 
  93. 	 
  94. 	local text_h = self.text_h 
  95. 	local fill_h = self.fill_h 
  96. 	local highlight_fill_h = self.highlight_fill_h 
  97. 	local meter_highlight_grp_h = self.meter_highlight_grp_h 
  98. 	local highlight_mask_h = self.highlight_mask_h 
  99. 	local meter_grp_h = self.meter_grp_h 
  100.  
  101.  
  102. 	--Set label with crc 
  103. 	if label_crc ~= self.label_crc then 
  104. 	 
  105. 		if label_crc == 0 or label_crc == nil then 
  106. 			--No crc or Invalid crc 
  107. 			vint_set_property(text_h, "text_tag", "") 
  108. 		else 
  109. 			vint_set_property(text_h, "text_tag_crc", label_crc) 
  110. 		end 
  111. 		self.is_dirty = true 
  112. 	end 
  113. 	 
  114. 	--Setup properties for fills 
  115. 	--Set Meter Fill based on percent input 
  116. 	local fill_width, fill_height = vint_get_property(fill_h, "scale") 
  117. 	fill_width = self.fill_size_full * meter_percent -- overwrite fill width multiplied by percentage 
  118. 	vint_set_property(fill_h, "scale", fill_width, fill_height) 
  119. 	vint_set_property(highlight_mask_h, "scale", fill_width, 1.1) 
  120. 	 
  121. 	--If meter is using mayhem skin update its color every time its updated,  
  122. 	--because it changes based on the color of the bonus cash. 
  123. 	if skin == "Mayhem" then	 
  124. 		vint_set_property(fill_h, "tint", Hud_mayhem_world_cash_status.color_r, Hud_mayhem_world_cash_status.color_g, Hud_mayhem_world_cash_status.color_b) 
  125. 		vint_set_property(highlight_fill_h, "tint", Hud_mayhem_world_cash_status.color_r, Hud_mayhem_world_cash_status.color_g, Hud_mayhem_world_cash_status.color_b) 
  126. 	end 
  127. 	 
  128. 	--Only re-align if this is the first time the element has been updated 
  129. 	if self.is_dirty == true then 
  130. 		--Get Label size... 
  131. 		 
  132. 		local label_width, label_height = element_get_actual_size(text_h) 
  133. 		self:set_meter_position(label_width) 
  134. 		self.label_width = label_width 
  135. 		self.height = label_height 
  136. 	end 
  137. 	 
  138. 	if self.is_flashing ~= is_flashing then 
  139. 		if is_flashing == true then 
  140. 			--Play and show flashing object 
  141. 			lua_play_anim(self.meter_pulse_anim_h) 
  142. 			vint_set_property(meter_highlight_grp_h, "visible", true) 
  143. 		elseif is_flashing == false then 
  144. 			--Pause and hide flashing object 
  145. 			vint_set_property(self.meter_pulse_anim_h, "is_paused", true) 
  146. 			vint_set_property(meter_highlight_grp_h, "visible", false) 
  147. 		end 
  148. 	end 
  149.  
  150. 	--Store Values 
  151. 	self.label_crc = label_crc 
  152. 	self.meter_percent = meter_percent 
  153. 	self.is_flashing = is_flashing 
  154. end 
  155.  
  156. function Vdo_gsi_meter:get_size() 
  157. 	return self.width, self.height 
  158. end 
  159.  
  160. ------------------------------------------------------------------------------- 
  161. -- returns the label width of the meter... 
  162. ------------------------------------------------------------------------------- 
  163. function Vdo_gsi_meter:get_label_width() 
  164. 	return self.label_width  
  165. end 
  166.  
  167. ------------------------------------------------------------------------------- 
  168. -- Sets the meter position of the gsi meter, this is done in vdo_gsi to 
  169. -- get the meters aligned if there is two of them... 
  170. -- @param label_width 
  171. -- 
  172. function Vdo_gsi_meter:set_meter_position(label_width) 
  173. 	local meter_x, meter_y = vint_get_property(self.meter_grp_h, "anchor") 
  174. 	 
  175. 	--Set Padding of label 
  176. 	local label_padding = METER_LABEL_PADDING	 
  177. 	if label_width == 0 then 
  178. 		--If the label doesn't exist then we don't need any padding 
  179. 		label_padding = 0  
  180. 	end 
  181. 	 
  182. 	meter_x = label_padding + label_width + label_padding 
  183. 	vint_set_property(self.meter_grp_h, "anchor",  meter_x, meter_y) 
  184. 	vint_set_property(self.meter_highlight_grp_h, "anchor",  meter_x, meter_y) 
  185. 	 
  186. 	self.width 	= meter_x + self.meter_width + 20 
  187. end 
  188.  
  189. --Standard Indicator Functions 
  190. function Vdo_gsi_meter:set_visible(visible) 
  191. 	--Hide the indicator if it is not visible 
  192. 	if visible ~= self.visible then 
  193. 		if visible == true then 
  194. 			self:set_property("visible", true) 
  195. 			self.visible = visible 
  196. 		else 
  197. 			self:set_property("visible", false) 
  198. 			self.visible = visible 
  199. 		end 
  200. 		 
  201. 		--Format of the indicators changed, so lets make sure we set the flag to dirty. 
  202. 		--The vdo_gsi will take care of everything when we set this dirty flag to true... 
  203. 		self.is_dirty = true 
  204. 	end 
  205. end 
  206.  
  207. function Vdo_gsi_meter:debug(debug_enabled) 
  208. 	self.debug_enabled = debug_enabled 
  209. end