./vdo_susan.lua

  1. local MAX_SUSANS = 9 
  2. local Highlight_index = 1 
  3. local Previous_index = 1 
  4. local Susan_is_done = true 
  5. local Susan_images = {} 
  6. local Susan_arrow_left_h 
  7. local Susan_arrow_right_h 
  8. local GRAY = 30 
  9.  
  10. local Foward_values = { 
  11. 	alpha_start 	= {0,1,1,1,1,1,0}, 
  12. 	alpha_end 		= {1,1,1,1,1,0,0}, 
  13. 	anchor_start	= {-638,-473,-252,0,225,473,0}, 
  14. 	anchor_end		= {-473,-252,0,225,473,638,0}, 
  15. 	scale_start		= {.4,.6,.8,1,.8,.6,0}, 
  16. 	scale_end		= {.6,.8,1,.8,.6,.4,0}, 
  17. 	tint_start		= {0,0,GRAY,255,GRAY,0,0}, 
  18. 	tint_end			= {0,GRAY,255,GRAY,0,0,0}, 
  19. } 
  20.  
  21. local Reverse_values = { 
  22. 	alpha_start 	= {0,1,1,1,1,1,0}, 
  23. 	alpha_end 		= {0,0,1,1,1,1,1}, 
  24. 	anchor_start	= {0,-473,-252,0,225,473,638}, 
  25. 	anchor_end		= {0,-638,-473,-225,0,225,473}, 
  26. 	scale_start		= {0,.6,.8,1,.8,.6,.4}, 
  27. 	scale_end		= {0,.4,.6,.8,1,.8,.6}, 
  28. 	tint_start		= {0,0,GRAY,255,GRAY,0,0}, 
  29. 	tint_end			= {0,0,0,GRAY,255,GRAY,0}, 
  30. } 
  31.  
  32. function vdo_susan_init() 
  33. end 
  34.  
  35. -- Inherited from Vdo_base_object 
  36. Vdo_susan = Vdo_base_object:new_base() 
  37.  
  38. function Vdo_susan:init() 
  39. 	--make a handle to the animation 
  40. 	self.go_susan = Vdo_anim_object:new("go_susan", self.handle, self.doc_handle) 
  41. 	self.init_susan = Vdo_anim_object:new("init_susan", self.handle, self.doc_handle) 
  42. 	self.arrow_right_anim = Vdo_anim_object:new("arrow_right_move", self.handle, self.doc_handle) 
  43. 	self.arrow_left_anim = Vdo_anim_object:new("arrow_left_move", self.handle, self.doc_handle) 
  44. 	self.arrow_pulse_anim = Vdo_anim_object:new("arrow_pulse", self.handle, self.doc_handle) 
  45. 	self.txt_in_anim = Vdo_anim_object:new("txt_intro", self.handle, self.doc_handle) 
  46. 	self.arrow_right = Vdo_base_object:new("susan_arrow_right", self.handle, self.doc_handle) 
  47. 	self.arrow_left = Vdo_base_object:new("susan_arrow_left", self.handle, self.doc_handle) 
  48. 	self.title_txt = Vdo_base_object:new("title_txt", self.handle, self.doc_handle) 
  49. 	self.desc_txt = Vdo_base_object:new("desc_txt", self.handle, self.doc_handle) 
  50. 	 
  51. 	--init download character text to false 
  52. 	self.text_is_visible = false 
  53. 	 
  54. 	vint_apply_start_values(self.txt_in_anim.handle) 
  55. 	 
  56. 	Susan_arrow_right_h = Vdo_base_object:new("susan_arrow_right", self.handle, self.doc_handle) 
  57. 	Susan_arrow_left_h = Vdo_base_object:new("susan_arrow_left", self.handle, self.doc_handle) 
  58. 	 
  59. 	--hide text until needed 
  60. 	self.title_txt:set_visible(false) 
  61. 	self.desc_txt:set_visible(false) 
  62. 	 
  63. 	--hide the left arrow, screen inits to index of 1 
  64. 	Susan_arrow_left_h:set_visible(false) 
  65. 	 
  66. 	local end_event_twn = Vdo_tween_object:new("susan_1_alpha", self.go_susan.handle) 
  67. 	 
  68. 	local callback_string = self:package_tween_callback("reset")	 
  69. 	end_event_twn:set_end_event(callback_string) 
  70. 	 
  71. 	end_event_twn = Vdo_tween_object:new("new_tween14", self.init_susan.handle) 
  72. 	 
  73. 	callback_string = self:package_tween_callback("intro_done")	 
  74. 	end_event_twn:set_end_event(callback_string) 
  75. 	 
  76. 	self.arrow_pulse_anim:play() 
  77. end 
  78.  
  79. function Vdo_susan:move_right() 
  80. 	 
  81. 	if Highlight_index == 1 or not Susan_is_done then 
  82. 		return 
  83. 	end 
  84. 	Susan_arrow_left_h:set_visible(true) 
  85. 	Susan_arrow_right_h:set_visible(true) 
  86. 	--subtract from the index 
  87. 	Previous_index = Highlight_index 
  88. 	Highlight_index = Highlight_index - 1 
  89. 	if Highlight_index < 1 then 
  90. 		Highlight_index = 1 
  91. 	end 
  92. 	if Highlight_index <= 1 then 
  93. 		Susan_arrow_left_h:set_visible(false) 
  94. 	end 
  95.  
  96. 	local tween_h  
  97. 	for i = 1,7 do 
  98. 		local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle) 
  99. 		 
  100. 		if i == 3 then 
  101. 			current_susan_h:set_depth(-2) 
  102. 		elseif i == 4 then 
  103. 			current_susan_h:set_depth(-1) 
  104. 		elseif i == 5 then 
  105. 			current_susan_h:set_depth(0) 
  106. 		elseif i == 1 and Previous_index > 3 then 
  107. 			-- Doesn't matter which images we set this to, as long as it's loaded.  The image will be 
  108. 			-- tinted black at this point.  But if it's not loaded, we'll see ui_blank 
  109. 			current_susan_h:set_visible(true)			 
  110. 			current_susan_h:set_image(Susan_images[Previous_index].image_name) 
  111. 		end 
  112. 		 
  113. 		if i < 3 or i > 5 then 
  114. 			--set the alpha tweens 
  115. 			local tween_h = Vdo_base_object:new("susan_"..i.."_alpha", self.handle) 
  116. 			tween_h:set_property("start_value", Foward_values.alpha_start[i]) 
  117. 			tween_h:set_property("end_value", Foward_values.alpha_end[i]) 
  118. 		end 
  119. 		--set the anchor tweens 
  120. 		tween_h = Vdo_base_object:new("susan_"..i.."_anchor", self.handle) 
  121. 		tween_h:set_property("start_value", Foward_values.anchor_start[i], 0) 
  122. 		tween_h:set_property("end_value", Foward_values.anchor_end[i], 0) 
  123. 		--set the scale tweens 
  124. 		tween_h = Vdo_base_object:new("susan_"..i.."_scale", self.handle) 
  125. 		tween_h:set_property("start_value", Foward_values.scale_start[i], Foward_values.scale_start[i]) 
  126. 		tween_h:set_property("end_value", Foward_values.scale_end[i], Foward_values.scale_end[i]) 
  127. 		--set the tint tweens 
  128. 		tween_h = Vdo_base_object:new("susan_"..i.."_tint", self.handle) 
  129. 		local tint = Foward_values.tint_start[i] 
  130. 		tween_h:set_property("start_value", tint/255, tint/255, tint/255) 
  131. 		tint = Foward_values.tint_end[i] 
  132. 		tween_h:set_property("end_value", tint/255, tint/255, tint/255) 
  133. 		local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD 
  134. 		--set the rotation tweens 
  135. 		local old_rotation = current_susan_h:get_rotation() 
  136. 		--get a random rotation 
  137. 		local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD 
  138. 		tween_h = Vdo_base_object:new("susan_"..i.."_rotation", self.handle) 
  139. 		tween_h:set_property("start_value", old_rotation ) 
  140. 		tween_h:set_property("end_value", random_rotation ) 
  141. 			 
  142. 	end 
  143. 	self.go_susan:play() 
  144. 	self.arrow_left_anim:play() 
  145. 	Susan_is_done = false 
  146. end 
  147.  
  148. function Vdo_susan:move_left() 
  149. 	 
  150. 	if Highlight_index == MAX_SUSANS or not Susan_is_done then 
  151. 		return 
  152. 	end 
  153. 	Susan_arrow_right_h:set_visible(true) 
  154. 	Susan_arrow_left_h:set_visible(true) 
  155. 	--add to the index 
  156. 	Previous_index = Highlight_index 
  157. 	Highlight_index = Highlight_index + 1 
  158. 	if Highlight_index > MAX_SUSANS then 
  159. 		Highlight_index = MAX_SUSANS 
  160. 	end 
  161. 	 
  162. 	if Highlight_index >= MAX_SUSANS then 
  163. 		Susan_arrow_right_h:set_visible(false) 
  164. 	end 
  165. 	 
  166. 	local tween_h  
  167. 	for i = 1,7 do 
  168. 		local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle) 
  169. 		 
  170. 		if i == 3 then 
  171. 			current_susan_h:set_depth(0) 
  172. 		elseif i == 4 then 
  173. 			current_susan_h:set_depth(-1) 
  174. 		elseif i == 5 then 
  175. 			current_susan_h:set_depth(-2) 
  176. 		elseif i == 7 and Previous_index < MAX_SUSANS - 2 then 
  177. 			-- Doesn't matter which images we set this to, as long as it's loaded.  The image will be 
  178. 			-- tinted black at this point.  But if it's not loaded, we'll see ui_blank 
  179. 			current_susan_h:set_visible(true)			 
  180. 			current_susan_h:set_image(Susan_images[Previous_index].image_name) 
  181. 		end 
  182. 		 
  183. 		if i < 3 or i > 5 then 
  184. 			--set the alpha tweens 
  185. 			tween_h = Vdo_base_object:new("susan_"..i.."_alpha", self.handle) 
  186. 			tween_h:set_property("start_value", Reverse_values.alpha_start[i]) 
  187. 			tween_h:set_property("end_value", Reverse_values.alpha_end[i]) 
  188. 		end 
  189. 		--set the anchor tweens 
  190. 		tween_h = Vdo_base_object:new("susan_"..i.."_anchor", self.handle) 
  191. 		tween_h:set_property("start_value", Reverse_values.anchor_start[i], 0) 
  192. 		tween_h:set_property("end_value", Reverse_values.anchor_end[i], 0) 
  193. 		--set the scale tweens 
  194. 		tween_h = Vdo_base_object:new("susan_"..i.."_scale", self.handle) 
  195. 		tween_h:set_property("start_value", Reverse_values.scale_start[i], Reverse_values.scale_start[i]) 
  196. 		tween_h:set_property("end_value", Reverse_values.scale_end[i], Reverse_values.scale_end[i]) 
  197. 		--set the tint tweens 
  198. 		tween_h = Vdo_base_object:new("susan_"..i.."_tint", self.handle) 
  199. 		local tint = Reverse_values.tint_start[i] 
  200. 		tween_h:set_property("start_value", tint/255, tint/255, tint/255) 
  201. 		tint = Reverse_values.tint_end[i] 
  202. 		tween_h:set_property("end_value", tint/255, tint/255, tint/255) 
  203. 		--get a random rotation 
  204. 		local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD 
  205. 		local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle) 
  206. 		local old_rotation = current_susan_h:get_rotation() 
  207. 		--set the rotation tweens 
  208. 		tween_h = Vdo_base_object:new("susan_"..i.."_rotation", self.handle) 
  209. 		tween_h:set_property("start_value", old_rotation ) 
  210. 		tween_h:set_property("end_value", random_rotation ) 
  211. 				 
  212. 	end 
  213. 	self.go_susan:play() 
  214. 	self.arrow_right_anim:play() 
  215. 	Susan_is_done = false 
  216. end 
  217.  
  218. function Vdo_susan:reset() 
  219.  
  220. 	local rotations = {} 
  221. 	local index_change = Highlight_index - Previous_index 
  222. 	 
  223. 	-- save off rotations first 
  224. 	for i = 1,7 do 
  225. 		local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle) 
  226. 		rotations[i] = current_susan_h:get_rotation() 
  227. 	end 
  228. 	 
  229. 	for i = 1,7 do 
  230. 		local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle) 
  231. 		current_susan_h:set_anchor(Foward_values.anchor_start[i],0) 
  232. 		current_susan_h:set_alpha(Foward_values.alpha_start[i]) 
  233. 		local tint = Reverse_values.tint_start[i] 
  234. 		current_susan_h:set_color(tint/255, tint/255, tint/255) 
  235. 		current_susan_h:set_rotation(rotations[i + index_change]) 
  236. 		current_susan_h:set_scale(Foward_values.scale_start[i],Foward_values.scale_start[i]) 
  237. 		 
  238. 		-- streamer_index is the first loaded image.  Find this based on the current Highlight_index. 
  239. 		local streamer_index = i + Highlight_index - 4 
  240. 		if streamer_index >= 1 and streamer_index <= MAX_SUSANS and Susan_images[streamer_index].image_name ~= nil then 
  241. 			current_susan_h:set_visible(true) 
  242. 			current_susan_h:set_image(Susan_images[streamer_index].image_name) 
  243. 		else 
  244. 			current_susan_h:set_visible(false) 
  245. 		end 
  246. 		 
  247. 		if i == 3 then 
  248. 			current_susan_h:set_depth(-1) 
  249. 		elseif i == 4 then 
  250. 			current_susan_h:set_depth(-2) 
  251. 		elseif i == 5 then 
  252. 			current_susan_h:set_depth(-1) 
  253. 		end 
  254. 	end 
  255. 	 
  256. 	Susan_is_done = true	 
  257. end 
  258.  
  259. function Vdo_susan:show_text(title, desc, is_visible) 
  260. 	 
  261. 	if title ~= nil then 
  262. 		self.title_txt:set_text(title)		 
  263. 	end 
  264. 	 
  265. 	if desc ~= nil then 
  266. 		self.desc_txt:set_text(desc) 
  267. 	end 
  268. 	 
  269. 	self.title_txt:set_visible(is_visible) 
  270. 	self.desc_txt:set_visible(is_visible) 
  271. 	 
  272. 	self.txt_in_anim:play(0) 
  273. 	 
  274. 	-- save off params so we can call again if needed when 
  275. 	-- susan animates in again.  This assumes we're only 
  276. 	-- using this for one item. 
  277. 	self.title = title		 
  278. 	self.desc = desc 
  279. 	self.text_is_visible = is_visible 
  280. end 
  281.  
  282. function Vdo_susan:get_index() 
  283. 	return Highlight_index 
  284. end 
  285.  
  286. function Vdo_susan:is_in_progress() 
  287. 	return not Susan_is_done 
  288. end 
  289.  
  290. function Vdo_susan:set_images(image_table) 
  291. 	Susan_images = image_table 
  292. 	self:reset() 
  293. end 
  294.  
  295. function Vdo_susan:play_intro() 
  296. 	local end_event_twn_h = vint_object_find("init_done_twn", self.init_susan.handle)	 
  297. 	local callback_string = self:package_tween_callback("init_anim_complete")	 
  298. 	 
  299. 	vint_set_property(end_event_twn_h, "end_event", callback_string) 
  300. 	 
  301. 	vint_apply_start_values(self.init_susan.handle)	 
  302. 	vint_apply_start_values(self.txt_in_anim.handle) 
  303. 	 
  304. 	self.init_susan:play() 
  305. 	Susan_is_done = false 
  306. end 
  307.  
  308. function Vdo_susan:intro_done() 
  309. 	Susan_is_done = true 
  310. end 
  311.  
  312. -------------------------------------------------------------------------------------------- 
  313. -- Callback triggered when last tween of init_susan anim is done. 
  314. -- Determines if text should be shown or not. 
  315. function Vdo_susan:init_anim_complete()		 
  316. 	if self.text_is_visible == true then 
  317. 		self:show_text(self.title, self.desc, self.text_is_visible) 
  318. 	end 
  319. end 
  320.  
  321.  
  322.  
  323.