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