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