./vdo_gsi_xy.lua

  1. ------------------------------------------------------------------------------- 
  2. --GSI XY Component 
  3. ------------------------------------------------------------------------------- 
  4. -- Inherited from Vdo_base_object 
  5. Vdo_gsi_xy = Vdo_base_object:new_base() 
  6.  
  7. -- Standard Init Function 
  8. function vdo_gsi_xy_init() 
  9. end 
  10.  
  11. -- Standard Cleanup Function 
  12. function vdo_gsi_meter_cleanup() 
  13. end 
  14.  
  15. --Constants 
  16. local	GSI_XY_LABEL_PADDING = 9  
  17. local	GSI_XY_SLASH_PADDING = 2 
  18.  
  19. function Vdo_gsi_xy:init() 
  20.  
  21. 	--Store references to objects 
  22. 	self.label_txt_h 	= vint_object_find("label_txt", self.handle) 
  23. 	self.slash_txt_h 	= vint_object_find("slash_txt", self.handle) 
  24. 	self.x_txt_h 		= vint_object_find("x_txt", self.handle) 
  25. 	self.y_txt_h  		= vint_object_find("y_txt", self.handle) 
  26. 	self.gsi_x_anim_h = vint_object_find("gsi_x_anim", self.handle) 
  27. 	 
  28. 	--Retarget_animation... 
  29. 	vint_set_property(self.gsi_x_anim_h, "target_handle", self.x_txt_h) 
  30. end 
  31.  
  32. function Vdo_gsi_xy:create(skin) 
  33. 	--Initialize Standard Indicator Values 
  34. 	self.visible = -1						--Is the indicator displaying?  
  35. 	self.is_dirty = true					--Is the indicator dirty? we set this to true if we want the GSI to re-align everything. 
  36. 	self.skin = skin 
  37. 	self.width = -1 
  38. 	self.height = -1 
  39. 	 
  40. 	--Initialize Custom Values  
  41. 	self.x_value = 200 
  42. 	self.y_value = 200 
  43. 	self.label = 0 
  44. end 
  45.  
  46. function Vdo_gsi_xy:update(visible, skin, label_crc, x_value, y_value, is_cash) 
  47. 	--Set visible 
  48. 	self:set_visible(visible) 
  49. 	 
  50. 	local label_txt_h = self.label_txt_h 
  51. 	local slash_txt_h = self.slash_txt_h 
  52. 	local x_txt_h = self.x_txt_h 
  53. 	local y_txt_h = self.y_txt_h 
  54.  
  55. 	 
  56. 	--Set label with crc 
  57. 	if label_crc == 0 or label_crc == nil then 
  58. 		--No crc or Invalid crc 
  59. 		vint_set_property(label_txt_h, "text_tag", "") 
  60. 	else 
  61. 		vint_set_property(label_txt_h, "text_tag_crc", label_crc) 
  62. 	end 
  63. 	 
  64. 	--Animate it... 
  65. 	if x_value ~= self.x_value then 
  66. 		lua_play_anim(self.gsi_x_anim_h) 
  67. 	end 
  68. 	 
  69. 	--If skin is left blank then  
  70. 	if skin == "" then 
  71. 		if is_cash == true then 
  72. 			skin = "cash" 
  73. 		else  
  74. 			skin = "default" 
  75. 		end 
  76. 	end 
  77. 		 
  78. 	--Apply any special formatting to the text 
  79. 	local x_value_text, y_value_text 
  80. 	 
  81. 	if skin == "Cash" or skin == "Cash_Flash_Disabled" then 
  82. 		x_value_text = "$" .. format_cash(x_value) 
  83. 		y_value_text = "$" .. format_cash(y_value) 
  84. 	else 
  85. 		x_value_text = x_value 
  86. 		y_value_text = y_value 
  87. 	end 
  88. 	 
  89. 	--Set Text Fields 
  90. 	vint_set_property(x_txt_h, "text_tag", x_value_text) 
  91. 	 
  92. 	--test size in the y slot because the x slot could be scaling because of animation... 
  93. 	vint_set_property(y_txt_h, "text_tag", x_value_text) 
  94. 	local x_width, x_height = element_get_actual_size(y_txt_h) 
  95. 	 
  96. 	vint_set_property(y_txt_h, "text_tag", y_value_text) 
  97. 	 
  98. 	 
  99. 	--Get Sizes first 
  100. 	local label_x, label_y = vint_get_property(label_txt_h, "anchor") 
  101. 	local label_width, label_height = element_get_actual_size(label_txt_h) 
  102.  
  103. 	local slash_width, slash_height = element_get_actual_size(slash_txt_h) 
  104. 	local y_width, y_height = element_get_actual_size(y_txt_h) 
  105.  
  106. 	local x_anchor_x = x_width/2 
  107. 	if label_width ~= 0 then 
  108. 		x_anchor_x = label_x + label_width + GSI_XY_LABEL_PADDING + x_anchor_x 
  109. 	end 
  110. 	 
  111. 	--Set Positions 
  112. 	local slash_anchor_x = x_anchor_x + x_width/2 + GSI_XY_SLASH_PADDING 
  113. 	local y_anchor_x = slash_anchor_x + slash_width + GSI_XY_SLASH_PADDING 
  114. 	 
  115. 	vint_set_property(x_txt_h, "anchor", x_anchor_x, label_y) 
  116. 	vint_set_property(y_txt_h, "anchor", y_anchor_x, label_y) 
  117. 	vint_set_property(slash_txt_h, "anchor", slash_anchor_x, label_y) 
  118. 	 
  119. 	--Calculate Width 
  120. 	local width = y_anchor_x + y_width + (GSI_TEXT_SPACING * 1.5) 
  121. 	local width_dif = abs(self.width - width) 
  122. 	 
  123. 	if width_dif > 3 then 
  124. 		self.is_dirty = true 
  125. 	end 
  126. 	 
  127. 	--Store size values 
  128. 	self.width = width 
  129. 	self.height = x_height 
  130. 	 
  131. 	--Store Object values 
  132. 	self.label_crc = label_crc 
  133. 	self.x_value = x_value 
  134. 	self.y_value = y_value 
  135. end 
  136.  
  137. function Vdo_gsi_xy:get_size() 
  138. 	return self.width, self.height 
  139. end 
  140.  
  141. --Standard Indicator Functions 
  142. function Vdo_gsi_xy:set_visible(visible) 
  143. 	--Hide the indicator if it is not visible 
  144. 	if visible ~= self.visible then 
  145. 		if visible == true then 
  146. 			self:set_property("visible", true) 
  147. 			self.visible = visible 
  148. 		else 
  149. 			self:set_property("visible", false) 
  150. 			self.visible = visible 
  151. 		end 
  152. 		 
  153. 		--Format of the indicators changed, so lets make sure we set the flag to dirty. 
  154. 		--The vdo_gsi will take care of everything when we set this dirty flag to true... 
  155. 		self.is_dirty = true 
  156. 	end 
  157. end