./vdo_city_control.lua

  1. function vdo_city_control_init() 
  2. end 
  3.  
  4. -- Inherited from Vdo_base_object 
  5. Vdo_city_control = Vdo_base_object:new_base() 
  6.  
  7. --Local Constants... 
  8. local CONTROL_START_ANGLE 	= 2.5 
  9. local CONTROL_END_ANGLE 	= 2.49		-- This is really negative, but entering as positive to make equation work 
  10. local RESPECT_START_ANGLE 	= 2.7547 
  11. local RESPECT_END_ANGLE 	= 2.77315 
  12.  
  13. --Standard Init... 
  14. function Vdo_city_control:init() 
  15.  
  16. 	--Retarget animations... 
  17. 	local control_text_anim = Vdo_anim_object:new("control_text_anim", self.handle, self.doc_handle, self.doc_handle) 
  18. 	local control_up_anim	= Vdo_anim_object:new("control_up_anim", self.handle, self.doc_handle, self.doc_handle) 
  19. 	local respect_text_anim = Vdo_anim_object:new("respect_text_anim", self.handle, self.doc_handle, self.doc_handle) 
  20. 	control_text_anim:set_target_handle(self.handle) 
  21. 	control_up_anim:set_target_handle(self.handle) 
  22. 	respect_text_anim:set_target_handle(self.handle) 
  23. 	 
  24. 	self.start_angle 	= CONTROL_START_ANGLE 
  25. 	self.end_angle 	= CONTROL_END_ANGLE 
  26. 	 
  27. 	--Initalize Values 
  28. 	self.pct = 0 
  29. 	self:update(0, false) 
  30. end 
  31.  
  32.  
  33. -- Update/animate the respect meter 
  34. -- 
  35. -- @param	total_respect		current total amount of respect player has 
  36. -- @param	respect_pct		 	% the player is towards their next rank level 
  37. -- @param	level: player		rank level 
  38.  
  39. ---------------------------------------------------------------------------  
  40. -- Fills up the meter and plays added respect animation. 
  41. -- After animation is complete it does a callback which checks if we've 
  42. -- Increased a level and calls that animation... 
  43. -- 
  44. -- @param	total_respect		current total amount of respect player has 
  45. -- @param	old_respect_pct 	% previous player is towards their next rank level 
  46. -- @param	respect_pct		 	% the player is towards their next rank level 
  47. -- @param	level_old			rank level previous  
  48. -- @param	level_new			rank level new 
  49. --------------------------------------------------------------------------- 
  50. function Vdo_city_control:update_respect(total_respect, respect_pct, level, do_animation) 
  51.  
  52. 	-- min/max for a percentage 
  53. 	respect_pct = limit(respect_pct, 0, 1) 
  54. 	 
  55. 	local start_angle = self.start_angle - ((self.start_angle + self.end_angle) * self.pct) 
  56. 	local end_angle = self.start_angle - ((self.start_angle + self.end_angle) * respect_pct) 
  57. 	 
  58. 	--Find objects for  
  59. 	local level_txt = Vdo_base_object:new("percent_text", self.handle, self.doc_handle) 
  60. 	local control_pct_new = Vdo_base_object:new("new_percent_text", self.handle, self.doc_handle) 
  61. 	 
  62. 	 
  63. 	level_txt:set_visible(false) 
  64. 	control_pct_new:set_text("+" .. total_respect) 
  65. 	 
  66. 	if do_animation == true then 
  67. 		-- Animate Meter 
  68. 		local control_up_anim = Vdo_anim_object:new("control_up_anim", self.handle, self.doc_handle) 
  69. 		local meter_tween = Vdo_tween_object:new("meter_tween",self.handle, self.doc_handle) 
  70. 		local meter_bg_tween = Vdo_tween_object:new("meter_bg_tween",self.handle, self.doc_handle) 
  71. 		 
  72. 		-- Animate from previous to new		 
  73. 		meter_tween:set_property("start_value", start_angle) 
  74. 		meter_tween:set_property("end_value", end_angle) 
  75. 		meter_bg_tween:set_property("start_value", start_angle - .06) 
  76. 		meter_bg_tween:set_property("end_value", end_angle - .06) 
  77. 		control_up_anim:play(0) 
  78. 		 
  79. 		--Play text animation... 
  80. 		local control_text_anim = Vdo_anim_object:new("control_text_anim", self.handle, self.doc_handle) 
  81. 		local respect_text_anim = Vdo_anim_object:new("respect_text_anim", self.handle, self.doc_handle) 
  82. 		control_text_anim:play(0) 
  83. 		respect_text_anim:play(0) 
  84. 	else 
  85. 		--Set Meter Manually. 
  86. 		local meter = Vdo_base_object:new("meter", self.handle, self.doc_handle) 
  87. 		local meter_bg = Vdo_base_object:new("meter_bg", self.handle, self.doc_handle) 
  88. 		meter:set_property("end_angle", end_angle, self.doc_handle) 
  89. 		meter_bg:set_property("end_angle", end_angle - .06) 
  90. 	end 
  91. 	 
  92. 	self.pct = respect_pct 
  93. 	self.level = level 
  94. end 
  95.  
  96. -- Update/animate the control meter 
  97. -- 
  98. -- @param	pct					% of control of district... 
  99. -- @param	do_animation		if set to true we animate from the last value set... 
  100. function Vdo_city_control:update(control_pct, do_animation) 
  101.  
  102. 	-- min/max for a percentage 
  103. 	control_pct = limit(control_pct, 0, 1) 
  104. 	 
  105. 	local start_angle = self.start_angle - ((self.start_angle + self.end_angle) * self.pct) 
  106. 	local end_angle = self.start_angle - ((self.start_angle + self.end_angle) * control_pct) 
  107. 	 
  108. 	--Find objects for  
  109. 	local control_pct_old = Vdo_base_object:new("percent_text", self.handle, self.doc_handle) 
  110. 	local control_pct_new = Vdo_base_object:new("new_percent_text", self.handle, self.doc_handle) 
  111. 	 
  112. 	if do_animation == true then 
  113. 		--Set Text Percentages %%% 
  114. 		control_pct_old:set_text(floor(self.pct * 100 + 0.5) .. "%%") 
  115. 		control_pct_new:set_text(floor(control_pct * 100 + 0.5) .. "%%") 
  116.  
  117. 		-- Animate Meter 
  118. 		local control_up_anim = Vdo_anim_object:new("control_up_anim", self.handle, self.doc_handle) 
  119. 		local meter_tween = Vdo_tween_object:new("meter_tween",self.handle, self.doc_handle) 
  120. 		local meter_bg_tween = Vdo_tween_object:new("meter_bg_tween",self.handle, self.doc_handle) 
  121. 		 
  122. 		-- Animate from previous to new		 
  123. 		meter_tween:set_property("start_value", start_angle) 
  124. 		meter_tween:set_property("end_value", end_angle) 
  125. 		meter_bg_tween:set_property("start_value", start_angle - .06) 
  126. 		meter_bg_tween:set_property("end_value", end_angle - .06) 
  127. 		control_up_anim:play(0)		 
  128.  
  129. 		--Play text animation... 
  130. 		local control_text_anim = Vdo_anim_object:new("control_text_anim", self.handle, self.doc_handle) 
  131. 		control_text_anim:play(0)		 
  132. 	else 
  133. 		--Control Percentages... 
  134. 		control_pct_old:set_text(floor(control_pct * 100 + 0.5) .. "%%") 
  135. 		control_pct_new:set_text(floor(control_pct * 100 + 0.5) .. "%%") 
  136. 		 
  137. 		--Set Meter Manually. 
  138. 		local meter = Vdo_base_object:new("meter", self.handle, self.doc_handle) 
  139. 		local meter_bg = Vdo_base_object:new("meter_bg", self.handle, self.doc_handle) 
  140. 		meter:set_property("end_angle", end_angle) 
  141. 		meter_bg:set_property("end_angle", end_angle - .06) 
  142. 	end 
  143. 	self.pct = control_pct 
  144. end 
  145.  
  146. -- Shows or hides the pulse of the icon when control is added... 
  147. function Vdo_city_control:pulse_icon(pulse_bool) 
  148. 	local pulse = Vdo_base_object:new("fist_pulse", self.handle, self.doc_handle) 
  149. 	pulse:set_visible(pulse_bool) 
  150. end 
  151.  
  152. function Vdo_city_control:set_icon(icon_bmp_name) 
  153.  
  154. end 
  155.  
  156.  
  157. ------------------------------------------------------------------------------- 
  158. -- Augments the meter and turns it into a respect type... 
  159. ------------------------------------------------------------------------------- 
  160. function Vdo_city_control:change_to_respect() 
  161. 	--Change Icon 
  162. 	local icon = Vdo_base_object:new("icon", self.handle, self.doc_handle) 
  163. 	icon:set_image("ui_hud_respect_power") 
  164.  
  165. 	--Change color... 
  166. 	local meter = Vdo_base_object:new("meter", self.handle, self.doc_handle) 
  167. 	local meter_bg = Vdo_base_object:new("meter_bg", self.handle, self.doc_handle) 
  168. 	local meter_tint_tween = Vdo_tween_object:new("control_meter_tint", self.handle, self.doc_handle) 
  169. 	meter:set_color(COLOR_RESPECT_METER.R, COLOR_RESPECT_METER.G, COLOR_RESPECT_METER.B) 
  170. 	meter_tint_tween:set_property("start_value", COLOR_RESPECT_METER.R, COLOR_RESPECT_METER.G, COLOR_RESPECT_METER.B) 
  171. 	meter_tint_tween:set_property("end_value", COLOR_RESPECT_METER_HIGHLIGHT.R, COLOR_RESPECT_METER_HIGHLIGHT.G, COLOR_RESPECT_METER_HIGHLIGHT.B) 
  172. 	 
  173. 	self.start_angle 	= RESPECT_START_ANGLE 	 
  174. 	self.end_angle 	= RESPECT_END_ANGLE 
  175.  
  176. 	meter:set_property("start_angle", self.start_angle) 
  177. 	meter_bg:set_property("start_angle", self.start_angle - .06) 
  178. 	 
  179. 	self.pct = 0 
  180. 	self:update(0, false) 
  181. 	--Sets rotation on text... 
  182. 	local new_respect_text = Vdo_base_object:new("new_percent_text", self.handle, self.doc_handle) 
  183. 	new_respect_text:set_rotation(-8 * DEG_TO_RAD) 
  184. end