./vdo_gsi_combo.lua

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