./vdo_qte_key.lua

  1. -- Inherited from Vdo_base_object 
  2. Vdo_qte_key = Vdo_base_object:new_base() 
  3.  
  4.  
  5. local HUD_QTE_ANIM_NONE = -1 
  6. local HUD_QTE_ANIM_MASH_STANDARD = 0 
  7. local HUD_QTE_ANIM_MASH_FAST = 1 
  8.  
  9.  
  10. HUD_QTE_KEY_ARROW_N	= 1 
  11. HUD_QTE_KEY_ARROW_E	= 2 
  12. HUD_QTE_KEY_ARROW_S	= 3 
  13. HUD_QTE_KEY_ARROW_W	= 4 
  14.  
  15. local HUD_QTE_ARROW_DIRECTION_ROTATIONS = { 
  16. 	[HUD_QTE_KEY_ARROW_N] = 0, 
  17. 	[HUD_QTE_KEY_ARROW_E] = 90 * DEG_TO_RAD, 
  18. 	[HUD_QTE_KEY_ARROW_S] = 180 * DEG_TO_RAD, 
  19. 	[HUD_QTE_KEY_ARROW_W] = 270 * DEG_TO_RAD, 
  20. } 
  21.  
  22. function Vdo_qte_key:init() 
  23. 	self.key_off_handles = {} 
  24. 	local key_off_grp_h = vint_object_find("key_off_grp", self.handle) 
  25. 	 
  26. 	local key_on_grp_h = vint_object_find("key_on_grp", self.handle) 
  27. 	local key_glow_grp_h = vint_object_find("key_glow_grp", self.handle) 
  28. 	 
  29. 	self.key_off_grp_h 	= key_off_grp_h 
  30. 	 
  31. 	self.key_on_grp_h 	= key_on_grp_h 
  32. 	self.key_glow_grp_h 	= key_glow_grp_h 
  33. 	 
  34. 	self.key_off_w_h = vint_object_find("key_w", key_off_grp_h) 
  35. 	self.key_off_m_h = vint_object_find("key_m", key_off_grp_h) 
  36. 	self.key_off_e_h = vint_object_find("key_e", key_off_grp_h) 
  37. 	 
  38. 	self.key_on_w_h = vint_object_find("key_w", key_on_grp_h) 
  39. 	self.key_on_m_h = vint_object_find("key_m", key_on_grp_h) 
  40. 	self.key_on_e_h = vint_object_find("key_e", key_on_grp_h) 
  41. 	 
  42. 	self.key_glow_w_h = vint_object_find("key_w", key_glow_grp_h) 
  43. 	self.key_glow_m_h = vint_object_find("key_m", key_glow_grp_h) 
  44. 	self.key_glow_e_h = vint_object_find("key_e", key_glow_grp_h) 
  45. 	 
  46. 	self.success_base_h 		= vint_object_find("success_base_grp", self.handle) 
  47. 	self.success_base_w_h 	= vint_object_find("success_key_w", self.success_base_h) 
  48. 	self.success_base_m_h 	= vint_object_find("success_key_m", self.success_base_h) 
  49. 	self.success_base_e_h 	= vint_object_find("success_key_e", self.success_base_h) 
  50. 	 
  51. 	self.key_arrow_grp_h = vint_object_find("key_arrow_grp", self.handle) 
  52. 	 
  53. 	self.width = 0 
  54. 	self.mash_fast_anim_h 		= vint_object_find("mash_fast_anim", self.handle) 
  55. 	 
  56. 	self.arrow_anim_h 			= vint_object_find("arrow_anim", self.handle) 
  57. 	 
  58. 	vint_set_property(self.mash_fast_anim_h, "target_handle", self.handle) 
  59. 	vint_set_property(self.arrow_anim_h, "target_handle", self.handle) 
  60.  
  61. 	self.success_clones = {} 
  62. 	self.success_anim_clones = {} 
  63. 	 
  64. 	self:mash(HUD_QTE_ANIM_NONE) 
  65. end 
  66.  
  67. function Vdo_qte_key:cleanup() 
  68. end 
  69.  
  70. function Vdo_qte_key:set_text(text_tag) 
  71. 	local key_txt_h = vint_object_find("key_txt", self.handle) 
  72. 	vint_set_property(key_txt_h, "text_tag", text_tag) 
  73. 	vint_set_property(key_txt_h, "scale", 1.0, 1.0) 
  74. 	 
  75. 	local width, height = element_get_actual_size(key_txt_h) 
  76. 	local width_max = 226 
  77. 	local width_min = 20 
  78. 	width = max(width, width_min) 
  79.  
  80. 	--keep a min width on everything... 
  81. 	if width < 50	then 
  82. 		width = 30 
  83. 		vint_set_property(key_txt_h, "anchor", 40, -1) 
  84. 	else 
  85. 		vint_set_property(key_txt_h, "anchor", (width)*.5 + 25, -1) 
  86. 	end 
  87. 	 
  88. 	if width > width_max then 
  89. 		local scale = width_max/width 
  90. 		vint_set_property(key_txt_h, "scale", scale, scale) 
  91. 		width = width * scale 
  92. 	end 
  93. 	 
  94. 	width = width + 35 
  95. 	self:resize(width) 
  96. end 
  97.  
  98.  
  99. function Vdo_qte_key:resize(width) 
  100. 	--self.key_off_handles.key_w 
  101. 	 
  102. 	--Expand the center using source_se.x, source_se.y 
  103. 	---self.key_off_w_h  
  104. 	--self.key_off_m_h  
  105. 	--self.key_off_e_h  
  106. 	local source_se_x, source_se_y = vint_get_property(self.key_off_m_h, "source_se") 
  107. 	vint_set_property(self.key_off_m_h, "source_se", width, source_se_y) 
  108. 	 
  109. 	vint_set_property(self.key_on_m_h, "source_se", width, source_se_y) 
  110.  
  111. 	--Move Right Side 
  112. 	local x, y = vint_get_property(self.key_off_e_h, "anchor") 
  113. 	vint_set_property(self.key_off_e_h, "anchor", width - 40, y) 
  114. 	 
  115. 	vint_set_property(self.key_on_e_h, "anchor", width - 40, y) 
  116. 	 
  117. 	--Build Glow... 
  118. 	local glow_m_width, glow_m_height = element_get_actual_size(self.key_glow_m_h) 
  119. 	element_set_actual_size(self.key_glow_m_h, width - 19, glow_m_height) 
  120. 	local x, y = vint_get_property(self.key_glow_e_h, "anchor") 
  121. 	vint_set_property(self.key_glow_e_h, "anchor", width, y) 
  122.  
  123. 	--This stuff works... 
  124. 	local inverse_start_scale = 1.669 
  125. 	local center_width = (width * inverse_start_scale) - 50 
  126. 	local center_offset = 10 
  127.  
  128. 	vint_set_property(self.success_base_m_h, "scale", 1.0, 1.0) 
  129. 	local success_m_width, success_m_height = element_get_actual_size(self.success_base_m_h) 
  130. 	element_set_actual_size(self.success_base_m_h, center_width, success_m_height) 
  131. 	 
  132. 	local x, y = vint_get_property(self.success_base_w_h, "anchor") 
  133. 	vint_set_property(self.success_base_w_h, "anchor", -center_width * 0.5 , y) 
  134. 	 
  135. 	local x, y = vint_get_property(self.success_base_e_h, "anchor") 
  136. 	vint_set_property(self.success_base_e_h, "anchor", center_width * 0.5 , y) 
  137. 	 
  138. 	local success_center_grp_h = vint_object_find("success_center_grp", self.success_base_h) 
  139. 	local x, y = vint_get_property(success_center_grp_h, "anchor") 
  140. 	local x = ((width ) * 0.5)  + center_offset 
  141. 	vint_set_property(success_center_grp_h, "anchor", x, y) 
  142. 	vint_set_property(success_center_grp_h, "scale", 0.65, 0.65) 
  143. 	vint_set_property(success_center_grp_h, "alpha", 0) 
  144. 	 
  145. 	--Store width with extra padding and it centers nicely. 
  146. 	self.width = width + 18 
  147. end 
  148.  
  149. function Vdo_qte_key:get_width() 
  150. 	return self.width  
  151. end 
  152. 	 
  153. function Vdo_qte_key:mash(mash_type) 
  154.  
  155. 	--Always stop any mashing... 
  156. 	vint_set_property(self.key_off_grp_h, 	"alpha", 1) 
  157. 	vint_set_property(self.key_on_grp_h, 	"alpha", 0) 
  158. 	vint_set_property(self.key_glow_grp_h, "alpha", 0) 
  159. 	self.mash_type = mash_type 
  160. 	 
  161. 	if mash_type == HUD_QTE_ANIM_NONE then 
  162. 		vint_set_property(self.mash_fast_anim_h,"is_paused", true) 
  163. 		 
  164. 		vint_set_property(self.arrow_anim_h, "is_paused", true) 
  165. 		vint_set_property(self.key_arrow_grp_h, "visible", false) 
  166. 		return 
  167. 	elseif mash_type == HUD_QTE_ANIM_MASH_STANDARD or  mash_type == HUD_QTE_ANIM_MASH_FAST then	 
  168. 		lua_play_anim(self.mash_fast_anim_h) 
  169. 		 
  170. 		lua_play_anim(self.arrow_anim_h) 
  171. 		vint_set_property(self.key_arrow_grp_h, "visible", self.arrows_are_visible) 
  172. 	end 
  173. end 
  174.  
  175. function Vdo_qte_key:show_arrows(is_visible) 
  176. 	if self.mash_type == HUD_QTE_ANIM_NONE then 
  177. 		vint_set_property(self.key_arrow_grp_h, "visible", false) 
  178. 	else 
  179. 		vint_set_property(self.key_arrow_grp_h, "visible", is_visible) 
  180. 	end 
  181. 	self.arrows_are_visible = is_visible 
  182. end 
  183.  
  184. function Vdo_qte_key:set_arrow_direction(direction) 
  185.  
  186. 	if self.width == 0 then 
  187. 		return 
  188. 	end 
  189. 	 
  190. 	local x, y 
  191. 	if direction == HUD_QTE_KEY_ARROW_N then 
  192. 		x = self.width * .5 
  193. 		y = -37.0 
  194. 	elseif direction == HUD_QTE_KEY_ARROW_E then 
  195. 		x = self.width + 5 
  196. 		y = 0 
  197. 	elseif direction == HUD_QTE_KEY_ARROW_S then  
  198. 		x = self.width * .5 
  199. 		y = 37.0 
  200. 	elseif direction == HUD_QTE_KEY_ARROW_W  then  
  201. 		x =  - 5 
  202. 		y = 0 
  203. 	end 
  204. 	 
  205. 	vint_set_property(self.key_arrow_grp_h, "anchor", x, y) 
  206. 	local angle = HUD_QTE_ARROW_DIRECTION_ROTATIONS[direction]  
  207. 	vint_set_property(self.key_arrow_grp_h, "rotation", angle) 
  208. end 
  209.  
  210. function Vdo_qte_key:success(is_success) 
  211. 	if #self.success_clones ~= 0 then 
  212. 		for i = 1, #self.success_clones do 
  213. 			vint_object_destroy(self.success_clones[i]) 
  214. 			vint_object_destroy(self.success_anim_clones[i]) 
  215. 		end 
  216. 		self.success_clones = {} 
  217. 		self.success_anim_clones = {} 
  218. 	end 
  219.  
  220. 	if is_success then 
  221. 		--create mouse success items 
  222. 		for i = 1, 4 do 
  223. 			self.success_clones[i] = vint_object_clone(self.success_base_h) 
  224. 			self.success_anim_clones[i] = vint_object_clone(vint_object_find("success_anim")) 
  225. 			vint_set_property(self.success_anim_clones[i], "target_handle", self.success_clones[i]) 
  226. 			lua_play_anim(self.success_anim_clones[i], (i - 1) * .1) 
  227. 		end 
  228. 		 
  229. 		vint_set_property(self.key_on_grp_h, "visible", false) 
  230. 	else 
  231. 	 
  232. 		vint_set_property(self.key_on_grp_h, "visible", true) 
  233. 	end 
  234. end