./vdo_gsi_info.lua

  1. ------------------------------------------------------------------------------- 
  2. -- GSI Info Component 
  3. -- This combonent is used to display in the format of the following. 
  4. -- STATUS: XXXX 
  5. --  
  6. -- It is used for things like mayhem to keep track of combos. i.e. COMBO: 1  
  7. ------------------------------------------------------------------------------- 
  8. -- Inherited from Vdo_base_object 
  9. Vdo_gsi_info = Vdo_base_object:new_base() 
  10.  
  11. -- Standard Init Function 
  12. function vdo_gsi_info_init() 
  13. end 
  14.  
  15. -- Standard Cleanup Function 
  16. function vdo_gsi_info_cleanup() 
  17. end 
  18.  
  19. --Constants 
  20. local GSI_INFO_LABEL_PADDING = 9 
  21.  
  22. function Vdo_gsi_info:init() 
  23. end 
  24.  
  25. function Vdo_gsi_info:create(skin) 
  26. 	--Initialize Standard Indicator Values 
  27. 	self.visible = -1						--Is the indicator displaying?  
  28. 	self.is_dirty = true					--Is the indicator dirty? we set this to true if we want the GSI to re-align everything. 
  29. 	self.skin = skin 
  30. 	self.width = 100 
  31. 	self.height = 10 
  32. 	 
  33. 	--Initialize Custom Values  
  34. 	self.info_value = "XXXX: IS AWESOME" 
  35. 	self.label = 0 
  36. end 
  37.  
  38. function Vdo_gsi_info:update(visible, skin, label_crc, info_crc, info_value) 
  39. 	--Set visible 
  40. 	self:set_visible(visible) 
  41. 	 
  42. 	--Check if everything is formatted during change? 
  43. 	 
  44. 	local info_txt_obj = Vdo_base_object:new("info_txt", self.handle) 
  45. 	local label_txt_obj = Vdo_base_object:new("label_txt", self.handle) 
  46. 	 
  47. 	--Set label with crc 
  48. 	if label_crc == 0 or label_crc == nil then 
  49. 		--No crc or Invalid crc 
  50. 		label_txt_obj:set_text("") 
  51. 	else 
  52. 		label_txt_obj:set_text_crc(label_crc) 
  53. 	end 
  54. 	 
  55. 	--Set Info Part 
  56. 	if info_crc == 0 and info_value == nil then 
  57. 		--no string 
  58. 		info_txt_obj:set_text("") 
  59. 	elseif info_crc == 0 then 
  60. 		--Use string 
  61. 		 
  62. 		--Skin processing 
  63. 		if skin == "Cash" then 
  64. 			--format the cash 
  65. 			info_value = "$" .. format_cash(tonumber(info_value)) 
  66. 		elseif skin == "TrailBlazing" then 
  67. 			--Trailblazing specific 
  68. 			local insertion_text 	= { [0] = info_value } 
  69. 			info_value = vint_insert_values_in_string("HUD_AMT_SECS_B", insertion_text) 
  70. 			 
  71. 			--Tint the bonus yellow 
  72. 			info_txt_obj:set_color(GSI_SKIN["Default"].tint[1], GSI_SKIN["Default"].tint[2], GSI_SKIN["Default"].tint[3]) 
  73. 		end 
  74. 		 
  75. 		info_txt_obj:set_text(info_value) 
  76. 	else 
  77. 		--use crc 
  78. 		info_txt_obj:set_text_crc(info_crc) 
  79. 	end 
  80. 	 
  81. 	--Mayhem Activity Specific Coloring 
  82. 	if skin == "Mayhem" then 
  83. 		if info_value ~= "0" then 
  84. 			info_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) 
  85. 		else 
  86. 			--reset color 
  87. 			info_txt_obj:set_color(GSI_SKIN["Mayhem"].tint[1], GSI_SKIN["Mayhem"].tint[2], GSI_SKIN["Mayhem"].tint[3]) 
  88. 		end 
  89. 	end 
  90.  
  91. 	label_txt_obj:set_scale(1,1) 
  92. 	info_txt_obj:set_scale(1,1) 
  93. 	 
  94. 	--Repostion Elements and Calculate width/height 
  95. 	local label_width, label_height = label_txt_obj:get_actual_size() 
  96. 	local info_width, info_height = info_txt_obj:get_actual_size() 
  97. 	 
  98. 	--Resize if its too wide to fit within reason... 
  99. 	local width_total = label_width + info_width 
  100. 	local width_max = 536 
  101. 	if width_total > width_max then 
  102. 		local scale = width_max/width_total 
  103. 		label_txt_obj:set_scale(scale, 1) 
  104. 		info_txt_obj:set_scale(scale, 1) 
  105. 		label_width = label_width * scale 
  106. 		info_width = info_width * scale 
  107. 	end 
  108. 	 
  109. 	local label_padding = GSI_INFO_LABEL_PADDING 
  110. 	if label_width == 0 then 
  111. 		--If the label doesn't exist then we don't need any padding 
  112. 		label_padding = 0  
  113. 	end 
  114. 	 
  115. 	--Left Aligned Only? 
  116. 	local info_x = label_padding + label_width 
  117. 	local info_y = 0 
  118. 	 
  119. 	info_txt_obj:set_anchor(info_x, info_y) 
  120. 	 
  121. 	--Override width for mayhem only. 
  122. 	if skin == "Mayhem" then 
  123. 		info_width = 30 
  124. 	end 
  125. 	 
  126. 	--Clean up GSI if the label changed... 
  127. 	if label_crc ~= self.label_crc  then 
  128. 		self.is_dirty = true	 
  129. 	end 
  130. 	 
  131. 	--Add spacing to width 
  132. 	local width = info_x + info_width + GSI_TEXT_SPACING 
  133. 	local width_dif = abs(self.width - width) 
  134. 	 
  135. 	--Determine if we need to do more cleanup? 
  136. 	if width_dif > 3 then 
  137. 		self.is_dirty = true	 
  138. 	end 
  139.  
  140. 	--Get Height of object... 
  141. 	local height = info_height 
  142. 	if label_height > info_height then 
  143. 		height = label_height 
  144. 	end 
  145. 	 
  146. 	--Store new width and height of indicator 
  147. 	self.width = width 
  148. 	self.height = height 
  149. 	 
  150. 	---Store Values 
  151. 	self.label_crc = label_crc 
  152. 	self.info_value = info_value 
  153. end 
  154.  
  155. function Vdo_gsi_info:get_size() 
  156. 	return self.width, self.height 
  157. end 
  158.  
  159. --Standard Indicator Functions 
  160. function Vdo_gsi_info:set_visible(visible) 
  161. 	--Hide the indicator if it is not visible 
  162. 	if visible ~= self.visible then 
  163. 		if visible == true then 
  164. 			self:set_property("visible", true) 
  165. 			self.visible = visible 
  166. 		else 
  167. 			self:set_property("visible", false) 
  168. 			self.visible = visible 
  169. 		end 
  170. 		 
  171. 		--Format of the indicators changed, so lets make sure we set the flag to dirty. 
  172. 		--The vdo_gsi will take care of everything when we set this dirty flag to true... 
  173. 		self.is_dirty = true 
  174. 	end 
  175. end