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