sr2lua/hud_touch_combo.lua

  1. --#####################################################################  
  2. --Touch Combo System 
  3. --##################################################################### 
  4.  
  5. -- show_mode 
  6. -- 0 = Show Right stick 
  7. -- 1 = Show Both sticks 
  8. -- 2 = Show Right stick, dim left stick. 
  9.  
  10. Sexy_time_tween = -1 
  11.  
  12. Hud_combo_elements = { 
  13. 	main_grp_h = -1, 
  14. 	left_grp_h = -1,  
  15. 	left_stick_h = -1, 
  16. 	left_highlight = -1, 
  17. 	hud_left_stick_highlight = { 
  18. 		[1] = -1, 
  19. 		[2] = -1, 
  20. 		[3] = -1, 
  21. 		[4] = -1, 
  22. 	}, 
  23. 	right_grp_h = -1, 
  24. 	right_stick_h = -1, 
  25. 	right_highlight = -1, 
  26. 	target_dot_h = -1, 
  27. } 
  28.  
  29. Hud_touch_combo_status = { 
  30. 	combo_active = false, 
  31. 	show_mode = false, 
  32. 	left_stick_x = 0.0, 
  33. 	left_stick_x = 0.0, 
  34. 	right_stick_x = 0.0, 
  35. 	right_stick_y = 0.0, 
  36. 	rumble_level = -1, 
  37. 	grp_x = 640, 
  38. 	grp_y = 360, 
  39. } 
  40.  
  41. function hud_touch_combo_init() 
  42. 	--Find objects 
  43. 	Hud_combo_elements.main_grp_h = vint_object_find("combo_grp") 
  44. 	 
  45. 	local x, y = vint_get_property(Hud_combo_elements.main_grp_h, "anchor") 
  46. 	Hud_touch_combo_status.grp_x = x 
  47. 	Hud_touch_combo_status.grp_y = y 
  48. 	 
  49. 	 
  50. 	local bmp_h = vint_object_find("left_stick") 
  51. 	Hud_combo_elements.left_grp_h = bmp_h 																		--Left Stick Group 
  52. 	Hud_combo_elements.left_stick_h = vint_object_find("stick_l", bmp_h) 
  53. 	Hud_combo_elements.left_stick_hl_h = vint_object_find("stick_l_hl", bmp_h)	--Left Stick  
  54. 	Hud_combo_elements.left_circle_h = vint_object_find("l_bg", bmp_h) 
  55. 	 
  56. 	-- fix the image. 
  57. 	if (get_platform() == "PS3") then  
  58. 		local stick_bmp_h = vint_object_find("stick_bmp", Hud_combo_elements.left_stick_h) 
  59. 		vint_set_property(stick_bmp_h, "image", "ui_hud_combo_thumb_ps3") 
  60. 		local stick_txt_h = vint_object_find("stick_txt", Hud_combo_elements.left_stick_h ) 
  61. 		vint_set_property(stick_txt_h, "text_tag", "L") 
  62. 	end 
  63. 	 
  64. 	if (get_platform() == "PC") then  
  65. 		local stick_txt_h = vint_object_find("stick_txt", Hud_combo_elements.left_stick_h ) 
  66. 		vint_set_property(stick_txt_h, "text_tag", "") 
  67. 	end 
  68.  
  69. 	 
  70. 	Hud_combo_elements.hud_left_stick_highlight[1] = vint_object_find("combo_arrow_n", bmp_h)	--Left Highlight North 
  71. 	Hud_combo_elements.hud_left_stick_highlight[2] = vint_object_find("combo_arrow_s", bmp_h)	--Left Highlight South 
  72. 	Hud_combo_elements.hud_left_stick_highlight[3] = vint_object_find("combo_arrow_w", bmp_h)	--Left Highlight West 
  73. 	Hud_combo_elements.hud_left_stick_highlight[4] = vint_object_find("combo_arrow_e", bmp_h)	--Left Highlight East 
  74.  
  75. 	local bmp_h = vint_object_find("right_stick") 
  76. 	Hud_combo_elements.right_grp_h = bmp_h															--Right Stick Group 
  77. 	Hud_combo_elements.right_stick_h = vint_object_find("stick_r", bmp_h)					--Right Stick  
  78. 	Hud_combo_elements.right_stick_hl_h = vint_object_find("stick_r_hl", bmp_h) 
  79. 	Hud_combo_elements.right_circle_h = vint_object_find("r_bg", bmp_h) 
  80. 	 
  81. 	-- fix the image 
  82. 	if (get_platform() == "PS3") then  
  83. 		local stick_bmp_h = vint_object_find("stick_bmp", Hud_combo_elements.right_stick_h )								--Left Stick  
  84. 		vint_set_property(stick_bmp_h, "image", "ui_hud_combo_thumb_ps3") 
  85. 		local stick_txt_h = vint_object_find("stick_txt", Hud_combo_elements.right_stick_h )								--Left Stick  
  86. 		vint_set_property(stick_txt_h, "text_tag", "R") 
  87. 	end 
  88.  
  89. 	if (get_platform() == "PC") then  
  90. 		local stick_txt_h = vint_object_find("stick_txt", Hud_combo_elements.right_stick_h )								--Left Stick  
  91. 		vint_set_property(stick_txt_h, "text_tag", "") 
  92. 	end 
  93.  
  94. 	Hud_combo_elements.target_dot_h = vint_object_find("marker", bmp_h)	--Right marker 
  95. 	Hud_combo_elements.target_dot_big_h = vint_object_find("marker_big", bmp_h) --right big glow 
  96. 	 
  97. 	--animations, rumble 
  98. 	Hud_combo_elements.right_stick_rumble_light = vint_object_find("combo_stick_shake_light") 
  99. 	Hud_combo_elements.right_stick_rumble_heavy = vint_object_find("combo_stick_shake_heavy") 
  100. 	vint_set_property(Hud_combo_elements.right_stick_rumble_light, "is_paused", true) 
  101. 	vint_set_property(Hud_combo_elements.right_stick_rumble_heavy, "is_paused", true) 
  102. 	--stick blink 
  103. 	Hud_combo_elements.combo_stick_hl_l = vint_object_find("combo_stick_hl_l") 
  104. 	Hud_combo_elements.combo_stick_hl_r = vint_object_find("combo_stick_hl_r") 
  105. 	vint_set_property(Hud_combo_elements.combo_stick_hl_l, "is_paused", true) 
  106. 	vint_set_property(Hud_combo_elements.combo_stick_hl_r, "is_paused", true) 
  107. 	--fade in 
  108. 	Hud_combo_elements.combo_sticks_fade_in = vint_object_find("combo_sticks_fade_in") 
  109. 	vint_set_property(Hud_combo_elements.combo_sticks_fade_in, "is_paused", true) 
  110. 	--fade out 
  111. 	Hud_combo_elements.combo_sticks_fade_out = vint_object_find("combo_sticks_fade_out") 
  112. 	vint_set_property(Hud_combo_elements.combo_sticks_fade_out, "is_paused", true) 
  113. 	 
  114. 	 
  115. 	-- Touch Combo HUD 
  116. 	vint_dataitem_add_subscription("touch_combo_info", "update", "hud_touch_combo_system_update") 
  117. 	vint_dataitem_add_subscription("sexy_time_move_list", "update", "hud_sexy_time_move_list_update") 
  118. end 
  119.  
  120. function hud_touch_combo_system_update(di_h) 
  121. 	local combo_active, show_mode, right_stick_x, right_stick_y, left_stick_x, left_stick_y, target_x, target_y, rumble_level= vint_dataitem_get(di_h) 
  122. 	 
  123. 	 
  124. 	if combo_active ~= Hud_touch_combo_status.combo_active then 
  125. 		--debug_print("vint", "combo_active " .. var_to_string(combo_active) .. "\n") 
  126. 		Hud_touch_combo_status.combo_active = combo_active 
  127. 		 
  128. 		if combo_active == true then  
  129. 			debug_print("vint", "*** sexy time fade in *** \n") 
  130. 			hud_touch_combo_fade_in() 
  131. 			vint_set_property(Hud_combo_elements.main_grp_h, "visible", true)                                  
  132. 			vint_set_property(Hud_combo_elements.target_dot_h, "visible", false) 
  133. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[1], "visible", true) 
  134. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[2], "visible", true) 
  135. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[3], "visible", true) 
  136. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[4], "visible", true) 
  137. 		else 
  138. 			debug_print("vint", "*** sexy time fade out *** \n") 
  139. 			hud_touch_combo_fade_out() 
  140. 			hud_touch_combo_rumble_none() 
  141. 			vint_set_property(Hud_combo_elements.main_grp_h, "anchor", Hud_touch_combo_status.grp_x, Hud_touch_combo_status.grp_y) 
  142. 			vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", false) 
  143. 			vint_set_property(Hud_combo_elements.target_dot_h, "visible", false) 
  144. 			vint_set_property(Hud_combo_elements.left_grp_h, "alpha", 1)  
  145. 			vint_set_property(Hud_combo_elements.right_grp_h, "alpha", 1)  
  146. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[1], "visible", false) 
  147. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[2], "visible", false) 
  148. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[3], "visible", false) 
  149. 			vint_set_property(Hud_combo_elements.hud_left_stick_highlight[4], "visible", false) 
  150. 			return 
  151. 		end 
  152. 	end 
  153.  
  154. 	 
  155. 	if combo_active then 
  156. 		--which stick should we show 
  157. 		 
  158. 		local stick_radius = 15 
  159. 		local stick_grp_mult = 7 
  160. 		 
  161. 		if left_stick_x ~= Hud_touch_combo_status.left_stick_x  or  left_stick_y ~= Hud_touch_combo_status.left_stick_y then  
  162. 			vint_set_property(Hud_combo_elements.left_stick_h, "anchor", stick_radius * left_stick_x, stick_radius * -left_stick_y)			 
  163. 		end 
  164. 				 
  165. 		if right_stick_x ~= Hud_touch_combo_status.right_stick_x  or  right_stick_y ~= Hud_touch_combo_status.right_stick_y then  
  166. 			vint_set_property(Hud_combo_elements.right_stick_h, "anchor", stick_radius * right_stick_x, stick_radius * -right_stick_y) 
  167. 		end 
  168. 	 
  169. 		Hud_touch_combo_status.left_stick_x = left_stick_x  
  170. 		Hud_touch_combo_status.left_stick_y = left_stick_y 
  171.  
  172. 		Hud_touch_combo_status.right_stick_x = right_stick_x  
  173. 		Hud_touch_combo_status.right_stick_y = right_stick_y 
  174. 		 
  175. 		if target_x ~= Hud_touch_combo_status.target_x  or  target_y ~= Hud_touch_combo_status.target_y then  
  176. 			vint_set_property(Hud_combo_elements.target_dot_h, "anchor", stick_radius * target_x, stick_radius * -target_y) 
  177. 		end 
  178. 		 
  179. 		Hud_touch_combo_status.target_x = target_x  
  180. 		Hud_touch_combo_status.target_y = target_y 
  181. 		 
  182. 		--jiggle the group if using left stick 
  183. 		if show_mode == 1 then 
  184. 			local new_x = Hud_touch_combo_status.grp_x + (stick_grp_mult * left_stick_x) 
  185. 			local new_y = Hud_touch_combo_status.grp_y + (stick_grp_mult * -left_stick_y) 
  186. 			vint_set_property(Hud_combo_elements.main_grp_h, "anchor", new_x, new_y)			 
  187. 		else 
  188. 			vint_set_property(Hud_combo_elements.main_grp_h, "anchor", Hud_touch_combo_status.grp_x, Hud_touch_combo_status.grp_y) 
  189. 		end 
  190. 		 
  191. 		debug_print("vint", "rumble " .. var_to_string(rumble_level) .. ", show " .. var_to_string(show_mode) .. "\n") 
  192.  
  193. 		--how much rumble do we have 
  194. 		if Hud_touch_combo_status.rumble_level ~= rumble_level then	 
  195. 			--note: i look for rumble 0 farther down 
  196. 			if rumble_level == 1 then 
  197. 				--cancel the heavy stuff 
  198. 				vint_set_property(Hud_combo_elements.right_stick_rumble_heavy, "is_paused", true) 
  199. 				--play the light stuff 
  200. 				hud_touch_combo_rumble_light() 
  201. 			elseif rumble_level == 2 then 
  202. 				--cancel the light stuff 
  203. 				vint_set_property(Hud_combo_elements.right_stick_rumble_light, "is_paused", true) 
  204. 				--play the heavy stuff 
  205. 				hud_touch_combo_rumble_heavy() 
  206. 			end 
  207. 		end 
  208. 		 
  209. 		--find mode, turn off the correct shit 
  210. 		if show_mode ~= Hud_touch_combo_status.show_mode then 
  211. 			if show_mode == 0 then  
  212. 				-- show the right stick 
  213. 				vint_set_property(Hud_combo_elements.left_grp_h, "alpha", .25)  
  214. 				vint_set_property(Hud_combo_elements.right_grp_h, "alpha", 1)  
  215. 				vint_set_property(Hud_combo_elements.target_dot_h, "visible", false) 
  216. 				vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", true) 
  217. 				hud_touch_combo_blink_right() 
  218. 				 
  219. 			elseif show_mode == 1 then 
  220. 				--show the left stick 
  221. 				vint_set_property(Hud_combo_elements.left_grp_h, "alpha", 1)  
  222. 				vint_set_property(Hud_combo_elements.right_grp_h, "alpha", 0.25)  
  223. 				vint_set_property(Hud_combo_elements.target_dot_h, "visible", true) 
  224. 				vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", false) 
  225. 				hud_touch_combo_blink_left() 
  226. 			elseif show_mode == 2 then 
  227. 				--show the right stick 
  228. 				vint_set_property(Hud_combo_elements.left_grp_h, "alpha", 0)  
  229. 				vint_set_property(Hud_combo_elements.right_grp_h, "alpha", 1)  
  230. 				hud_touch_combo_blink_right() 
  231. 			end 
  232. 		end 
  233. 		 
  234. 		--hide the small dot, or the big dot... 
  235. 		if show_mode == 0 then 
  236. 			vint_set_property(Hud_combo_elements.target_dot_h, "visible", false) 
  237. 			vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", true) 
  238. 		else 
  239. 			vint_set_property(Hud_combo_elements.target_dot_h, "visible", true) 
  240. 			vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", false) 
  241. 		end	 
  242. 		 
  243. 		if rumble_level == 0 then 
  244. 			hud_touch_combo_rumble_none()	 
  245. 		end 
  246. 		 
  247. 		Hud_touch_combo_status.rumble_level = rumble_level 
  248. 		Hud_touch_combo_status.show_mode = show_mode 
  249. 	end	 
  250. end 
  251.  
  252. function hud_touch_combo_blink_left() 
  253. 	--blink left 
  254. 	lua_play_anim(Hud_combo_elements.combo_stick_hl_l, 0) 
  255. 	vint_set_property(Hud_combo_elements.combo_stick_hl_r, "is_paused", true) 
  256. 	vint_set_property(Hud_combo_elements.right_stick_hl_h, "alpha", 0) 
  257. end 
  258.  
  259. function hud_touch_combo_blink_right() 
  260. 	--blink right 
  261. 	lua_play_anim(Hud_combo_elements.combo_stick_hl_r, 0) 
  262. 	vint_set_property(Hud_combo_elements.combo_stick_hl_l, "is_paused", true) 
  263. 	vint_set_property(Hud_combo_elements.right_stick_hl_h, "alpha", 0) 
  264. end 
  265.  
  266. function hud_touch_combo_rumble_light() 
  267. 	lua_play_anim(Hud_combo_elements.right_stick_rumble_light, 0) 
  268. end 
  269.  
  270. function hud_touch_combo_rumble_heavy() 
  271. 	lua_play_anim(Hud_combo_elements.right_stick_rumble_heavy, 0) 
  272. end 
  273.  
  274. function hud_touch_combo_rumble_none() 
  275. 	vint_set_property(Hud_combo_elements.target_dot_big_h, "alpha", 0) 
  276. 	vint_set_property(Hud_combo_elements.target_dot_big_h, "visible", false) 
  277. 	lua_play_anim(Hud_combo_elements.right_stick_rumble_light, 0) 
  278. 	lua_play_anim(Hud_combo_elements.right_stick_rumble_heavy, 0) 
  279. 	vint_set_property(Hud_combo_elements.right_stick_rumble_light, "is_paused", true) 
  280. 	vint_set_property(Hud_combo_elements.right_stick_rumble_heavy, "is_paused", true) 
  281. 	vint_set_property(Hud_combo_elements.right_circle_h, "scale", 1, 1) 
  282. end 
  283.  
  284. function hud_touch_combo_fade_out() 
  285. 	lua_play_anim(Hud_combo_elements.combo_sticks_fade_out, 0) 
  286. end 
  287.  
  288. function hud_touch_combo_fade_in() 
  289. 	lua_play_anim(Hud_combo_elements.combo_sticks_fade_in, 0) 
  290. end 
  291.  
  292. function hud_sexy_time_move_list_update(di_h) 
  293. 	-- get the data. 
  294. 	local sexy_time_direction = vint_dataitem_get(di_h) 
  295. 	 
  296. 	hud_sexy_time_tween_cleanup() 
  297. 	if sexy_time_direction ~= -1 then 
  298. 		hud_sexy_time_flash_current_movement(sexy_time_direction) 
  299. 	end 
  300. end 
  301.  
  302. function hud_sexy_time_create_tween(name, target_h, target_prop, duration) 
  303. 	local tween_h = vint_object_create(name, "tween", vint_object_find("root_animation")) 
  304. 	vint_set_property(tween_h, "duration", duration) 
  305. 	vint_set_property(tween_h, "target_handle", target_h) 
  306. 	vint_set_property(tween_h, "target_property", target_prop) 
  307. 	vint_set_property(tween_h, "max_loops", 0)  -- doing a lot so we don't run out of this stuff. 
  308. 	vint_set_property(tween_h, "loop_mode", 2) 
  309. 	vint_set_property(tween_h, "algorithm", 0) 
  310. 	vint_set_property(tween_h, "start_time",	vint_get_time_index() ) 
  311. 	vint_set_property(tween_h, "state", 1) 
  312. 	return tween_h 
  313. end 
  314.  
  315. function hud_sexy_time_tween_cleanup() 
  316.  
  317. 	if Sexy_time_tween ~= -1 then 
  318. 	 
  319. 		-- this is a new tween.  Stop the old one. 
  320. 		local target_handle = vint_get_property(Sexy_time_tween, "target_handle") 
  321. 		--vint_set_property(target_handle, "tint", 1,0,1) 
  322. 		vint_object_destroy(Sexy_time_tween) 
  323. 		vint_set_property(target_handle, "alpha", 0) 
  324. 		Sexy_time_tween = -1 
  325. 	end 
  326. 	 
  327. end 
  328.  
  329. Sexy_time_tweens = {} 
  330.  
  331. function hud_sexy_time_flash_current_movement(current_direction) 
  332. 	 
  333. 	 
  334. 	local current_item = 1 
  335. 	local continue_processing = true 
  336. 	local item_h 
  337. 	local tween_h 
  338. 	 
  339. 	if Sexy_time_tween ~= -1 then 				-- this is a new tween.  Stop the old one. 
  340. 		vint_object_destroy(Sexy_time_tween) 
  341. 		Sexy_time_tween = -1 
  342. 	end 
  343. 	 
  344. 	local time_between_flashes = .25 
  345. 	local flash_duration = .25 
  346. 	 
  347. 	--Create Tween 
  348. 	item_h = Hud_combo_elements.hud_left_stick_highlight[current_direction]		 
  349. 	tween_h = hud_sexy_time_create_tween("tween" .. current_item, item_h , "alpha", flash_duration) 
  350.  
  351. 	vint_set_property(tween_h, "start_value", .1) 
  352. 	vint_set_property(tween_h, "end_value", 1) 
  353. 	 
  354. 	Sexy_time_tween = tween_h 
  355. 	 
  356. end