sr2lua/hud_mp_hud.lua

  1. --Touch_combo_data = {} 
  2.  
  3.  
  4. --#####################################################################  
  5. --Touch Combo System 
  6. --##################################################################### 
  7.  
  8.  
  9. -- Hud_mp_snatch_elements = { 
  10. -- 	main_grp_h = -1, 
  11. -- 	head_img_bg_h = -1, 
  12. -- 	recruitment_fill_h = -1, 
  13. -- } 
  14.  
  15.  
  16. -- show_mode 
  17. -- 0 = Show Right stick 
  18. -- 1 = Show Both sticks 
  19. -- 2 = Show Right stick, dim left stick. 
  20.  
  21.  
  22. Hud_mp_snatch_info = {	 
  23. 	--hos Info 
  24. 	hos = { }, 
  25. 	johns = { }, 
  26. } 
  27.  
  28.  
  29.  
  30. function hud_mp_snatch_init() 
  31. 	--Find objects 
  32. 	Hud_mp_snatch_elements.main_grp_h = vint_object_find("Extra_homie") 
  33. 	Hud_mp_snatch_elements.snatch_grp_h = vint_object_find("mp_snatch_john") 
  34. 	local h = Hud_mp_snatch_elements.snatch_grp_h 
  35. 	Hud_mp_snatch_elements.snatch_heart_1 = vint_object_find("mp_snatch_heart_1", h) 
  36. 	Hud_mp_snatch_elements.snatch_heart_2 = vint_object_find("mp_snatch_heart_2", h) 
  37. 	Hud_mp_snatch_elements.snatch_heart_3 = vint_object_find("mp_snatch_heart_3", h) 
  38. 	Hud_mp_snatch_elements.snatch_heart_4 = vint_object_find("mp_snatch_heart_4", h) 
  39. 	Hud_mp_snatch_elements.snatch_heart_5 = vint_object_find("mp_snatch_heart_5", h) 
  40. 	 
  41. 	vint_set_property(Hud_mp_snatch_elements.snatch_heart_1, "tint", 0.5, 0.5, 0.5) 
  42. 	vint_set_property(Hud_mp_snatch_elements.snatch_heart_2, "tint", 0.5, 0.5, 0.5) 
  43. 	vint_set_property(Hud_mp_snatch_elements.snatch_heart_3, "tint", 0.5, 0.5, 0.5) 
  44. 	vint_set_property(Hud_mp_snatch_elements.snatch_heart_4, "tint", 0.5, 0.5, 0.5) 
  45. 	vint_set_property(Hud_mp_snatch_elements.snatch_heart_5, "tint", 0.5, 0.5, 0.5) 
  46. 	 
  47. 	-- Touch Combo HUD 
  48. 	vint_datagroup_add_subscription("mp_snatch_ho_indicator_data", "insert", "hud_mp_snatch_system_update") 
  49. 	vint_datagroup_add_subscription("mp_snatch_ho_indicator_data", "update", "hud_mp_snatch_system_update") 
  50. 	vint_datagroup_add_subscription("mp_snatch_ho_indicator_data", "remove", "hud_mp_snatch_system_update") 
  51. 	 
  52. 	vint_datagroup_add_subscription("mp_snatch_john_indicator_data", "insert", "hud_mp_john_system_update") 
  53. 	vint_datagroup_add_subscription("mp_snatch_john_indicator_data", "update", "hud_mp_john_system_update") 
  54. 	vint_datagroup_add_subscription("mp_snatch_john_indicator_data", "remove", "hud_mp_john_system_update")	 
  55. end 
  56.  
  57.  
  58.  
  59. function hud_mp_snatch_system_update(di_h, event) 
  60. 	 
  61. 	 
  62. 	local index, screen_x, screen_y, z_depth, distance, recruit_pct, follower_index, contested, friendly_recruiting, is_visible, bitmap_head  = vint_dataitem_get(di_h) 
  63. 	 
  64. 	if event == "insert"  or event == "update" then 
  65.  
  66. 		--check to see if there is a ho indicator for the index 
  67. 		if Hud_mp_snatch_info.hos[index] == nil then 
  68. 			 
  69. 			 
  70. 			--Doesn't currently exist so create the ho indicator 
  71. 			local grp_h = vint_object_clone(Hud_mp_snatch_elements.main_grp_h) 
  72. 			local head_h = vint_object_find("Follower_head", grp_h) 
  73. 			local fill_h = vint_object_find("Follower_health_fill", grp_h)			 
  74. 			 
  75. 			local end_angle = 1.57 
  76. 			vint_set_property(fill_h, "end_angle", end_angle ) 
  77. 						 
  78. 			-- record everything here for later.  
  79. 			Hud_mp_snatch_info.hos[index] = { 
  80. 				grp_h = grp_h, 
  81. 				head_h = head_h, 
  82. 				fill_h = fill_h, 
  83. 				screen_x = screen_x, 
  84. 				screen_y = screen_y, 
  85. 				z_depth = z_depth, 
  86. 				distance = distance, 
  87. 				recruit_pct = recruit_pct, 
  88. 				follower_index = follower_index, 
  89. 				contested = contested, 
  90. 				friendly_recruiting = friendly_recruiting, 
  91. 				is_visible = is_visible, 
  92. 				bitmap_head = bitmap_head, 
  93. 			}			 
  94. 			 
  95. 			 
  96. 			-- initialize it 
  97. 			if contested then 
  98. 				vint_set_property(fill_h,  "image", "ui_hud_base_smcirc_ammo") 
  99. 			else  
  100. 				if friendly_recruiting then 
  101. 					vint_set_property(fill_h,  "image", "ui_hud_base_smcirc_mp_ho") 
  102. 				else  
  103. 					vint_set_property(fill_h,  "image", "ui_hud_base_smcirc_health") 
  104. 				end 
  105. 			end	 
  106. 			 
  107. 			vint_set_property(head_h, "image", bitmap_head) 
  108. 					 
  109. 			if follower_index ~= 0  then 
  110. 			 
  111. 				local follower_master_obj_h = vint_object_find("followers"); 
  112. 				local main_x, main_y = vint_get_property(follower_master_obj_h, "anchor") 
  113. 				local anchor_x, anchor_y = vint_get_property(Hud_followers.slot_objects[follower_index].group_h, "anchor") 
  114. 					 
  115. 				main_x = main_x + anchor_x 
  116. 				main_y = main_y + anchor_y 
  117. 				 
  118. 				 
  119. 				vint_set_property(grp_h, "anchor", main_x, main_y)	 
  120.  
  121. 				vint_set_property(grp_h, "scale", 1.0, 1.0) 
  122. 					 
  123. 				vint_set_property(grp_h, "depth", z_depth) 
  124. 			end  
  125. 			 
  126. 			--Update Health 
  127. 			local end_angle = 1.57 + (1.57 * recruit_pct) 
  128. 			vint_set_property(fill_h, "end_angle", end_angle ) 
  129. 			 
  130. 		end 
  131. 		 
  132. 		 
  133. 		--Shorter name for ease of use 
  134. 		local ho = Hud_mp_snatch_info.hos[index] 
  135. 	 
  136. 		 
  137. 		if is_visible == false then 
  138. 		--visible false 
  139. 		vint_set_property(ho.grp_h, "visible", false) 
  140. 		else 
  141. 		--visible true 
  142. 		vint_set_property(ho.grp_h, "visible", true) 
  143. 		end 
  144. 		 
  145. 		--Update Health 
  146. 		if recruit_pct ~= ho.recruit_pct then 
  147. 			local end_angle = 1.57 + (1.57 * recruit_pct) 
  148. 			vint_set_property(ho.fill_h, "end_angle", end_angle ) 
  149. 			ho.recruit_pct = recruit_pct 
  150. 		end 
  151. 		 
  152. 		if bitmap_head ~= ho.bitmap_head then 
  153. 			vint_set_property(ho.head_h, "image", bitmap_head) 
  154. 			ho.bitmap_head = bitmap_head 
  155. 		end 
  156. 				 
  157. 		if follower_index ~= 0  then 
  158. 			local follower_master_obj_h = vint_object_find("followers"); 
  159. 			local main_x, main_y = vint_get_property(follower_master_obj_h, "anchor") 
  160. 			local anchor_x, anchor_y = vint_get_property(Hud_followers.slot_objects[follower_index].group_h, "anchor") 
  161. 				 
  162. 			main_x = main_x + anchor_x 
  163. 			main_y = main_y + anchor_y 
  164. 			 
  165. 			 
  166. 			vint_set_property(ho.grp_h, "anchor", main_x, main_y)	 
  167.  
  168. 			vint_set_property(ho.grp_h, "scale", 1.0, 1.0) 
  169. 					 
  170. 			vint_set_property(ho.grp_h, "depth", z_depth) 
  171. 				 
  172. 			 
  173. 		else 
  174. 			--Screen Position 
  175. 			-- ummm? 
  176. 			 
  177. 			local grp_width = 64			 
  178. 			local x = screen_x -- (grp_width * 0.5) 
  179. 			local y = screen_y 
  180. 			vint_set_property(ho.grp_h, "anchor", x, y)	 
  181.  
  182. 			--Scale 
  183. 			local maxclamp = 0.40 
  184. 			local minclamp = 0.1 
  185. 			 
  186. 			local maxscale = 1 
  187. 			local minscale = 0.5 
  188. 			 
  189. 			--Clamp the distances 
  190. 			if distance <= minclamp then 
  191. 				distance = minclamp  
  192. 				elseif distance >= maxclamp then 
  193. 				distance = maxclamp 
  194. 			end 
  195.  
  196. 			local newdist = (distance - minclamp) 
  197. 			local ratio = 1 - (newdist / (maxclamp - minclamp)) 
  198. 			local scale = (ratio * (maxscale-minscale)) + minscale 
  199. 		 
  200.  
  201. 			vint_set_property(ho.grp_h, "scale", scale, scale) 
  202. 			--vint_set_property(ho.grp_h, "alpha", scale) 
  203. 				 
  204. 			--Z Depth 
  205. 			if z_depth ~= ho.z_depth then 
  206. 				vint_set_property(ho.grp_h,  "depth", z_depth) 
  207. 			end 
  208. 			 
  209. 		end 
  210. 	 
  211. 		if contested then 
  212. 			if not ho.contested then 
  213. 				-- set the punk yellow! 
  214. 				vint_set_property(ho.fill_h,  "image", "ui_hud_base_smcirc_ammo") 
  215. 				ho.contested = contested 
  216. 			end 
  217. 		else  
  218. 			if friendly_recruiting then 
  219. 				if (not ho.friendly_recruiting) or ho.contested then 
  220. 					-- set the ho green 
  221. 					vint_set_property(ho.fill_h,  "image", "ui_hud_base_smcirc_mp_ho") 
  222. 					ho.friendly_recruiting = friendly_recruiting 
  223. 				end 
  224. 			else  
  225. 				-- got this far, your unfriendly! 
  226. 				if ho.friendly_recruiting or ho.contested then 
  227. 					vint_set_property(ho.fill_h,  "image", "ui_hud_base_smcirc_health") 
  228. 					ho.friendly_recruiting = friendly_recruiting 
  229. 				end 
  230. 			end 
  231. 		end	 
  232. 		 
  233. 		ho.recruit_pct = recruit_pct 
  234. 		ho.screen_x = screen_x 		 
  235. 		ho.screen_y = screen_y 		 
  236. 		ho.z_depth = z_depth 
  237. 		ho.distance = distance 
  238. 		ho.follower_index = follower_index 
  239. 		ho.contested = contested 
  240. 		ho.friendly_recruiting = friendly_recruiting 
  241. 		ho.is_visible = is_visible 
  242. 		 
  243.  
  244. 	end 
  245. 	 
  246. 	--If you got a remove event, remove the clones	 
  247. 	if event == "remove" and Hud_mp_snatch_info.hos[index] ~= nil then 
  248. 		local ho = Hud_mp_snatch_info.hos[index] 
  249. 		vint_object_destroy(ho.grp_h) 
  250. 		Hud_mp_snatch_info.hos[index] = nil 
  251. 	end 
  252. 			 
  253. end 
  254.  
  255. 			 
  256. --######################################### 
  257. ------------------------------------------- 
  258. -- JOHN METER 
  259. ------------------------------------------- 
  260. --######################################### 
  261.  
  262. function hud_mp_john_system_update(di_h, event) 
  263. 	 
  264. 	 
  265. 	local index, screen_x, screen_y, z_depth, distance, recruit_pct, contested, is_visible = vint_dataitem_get(di_h) 
  266. 	 
  267.  
  268. 	if event == "insert"  or event == "update" then 
  269.  
  270. 		if Hud_mp_snatch_info.johns[index] == nil then 
  271. 			 
  272. 			--Doesn't currently exist so create the ho indicator 
  273. 			local grp_h = vint_object_clone(Hud_mp_snatch_elements.snatch_grp_h) 
  274. 			local heart_1_h = vint_object_find("mp_snatch_heart_1", grp_h)	 
  275. 			local heart_2_h = vint_object_find("mp_snatch_heart_2", grp_h)	 
  276. 			local heart_3_h = vint_object_find("mp_snatch_heart_3", grp_h)	 
  277. 			local heart_4_h = vint_object_find("mp_snatch_heart_4", grp_h)	 
  278. 			local heart_5_h = vint_object_find("mp_snatch_heart_5", grp_h)				 
  279. 						 
  280. 			-- record everything here for later.  
  281. 			Hud_mp_snatch_info.johns[index] = { 
  282. 				grp_h = grp_h, 
  283. 				heart_1_h = heart_1_h, 
  284. 				heart_2_h = heart_2_h, 
  285. 				heart_3_h = heart_3_h, 
  286. 				heart_4_h = heart_4_h, 
  287. 				heart_5_h = heart_5_h, 
  288. 				screen_x = screen_x, 
  289. 				screen_y = screen_y, 
  290. 				z_depth = z_depth, 
  291. 				distance = distance, 
  292. 				recruit_pct = recruit_pct, 
  293. 				is_visible = is_visible, 
  294. 			}			 
  295. 			 
  296. 		end 
  297.  
  298.  
  299. 		--Shorter name for ease of use 
  300. 		local john = Hud_mp_snatch_info.johns[index] 
  301.  
  302. 		vint_set_property(john.grp_h, "visible", is_visible) 
  303.  
  304. 		local grp_width = 97		 
  305. 		local x = screen_x -- (grp_width * 0.5) 
  306. 		local y = screen_y 
  307. 		vint_set_property(john.grp_h, "anchor", x, y)	 
  308.  
  309. 		--Scale 
  310. 		local maxclamp = 0.40 
  311. 		local minclamp = 0.1 
  312.  
  313. 		local maxscale = 1 
  314. 		local minscale = 0.5 
  315.  
  316. 		if recruit_pct > .2 then 
  317. 			vint_set_property(john.heart_1_h, "tint", .86, 0, 0) 
  318. 			vint_set_property(john.heart_2_h, "tint", 0.5, 0.5, 0.5) 
  319. 			vint_set_property(john.heart_3_h, "tint", 0.5, 0.5, 0.5) 
  320. 			vint_set_property(john.heart_4_h, "tint", 0.5, 0.5, 0.5) 
  321. 			vint_set_property(john.heart_5_h, "tint", 0.5, 0.5, 0.5) 
  322. 		end 
  323. 		if recruit_pct > .4 then 
  324. 			vint_set_property(john.heart_1_h, "tint", .86, 0, 0) 
  325. 			vint_set_property(john.heart_2_h, "tint", .86, 0, 0) 
  326. 			vint_set_property(john.heart_3_h, "tint", 0.5, 0.5, 0.5) 
  327. 			vint_set_property(john.heart_4_h, "tint", 0.5, 0.5, 0.5) 
  328. 			vint_set_property(john.heart_5_h, "tint", 0.5, 0.5, 0.5) 
  329. 		end 
  330. 		if recruit_pct > .6 then 
  331. 			vint_set_property(john.heart_1_h, "tint", .86, 0, 0) 
  332. 			vint_set_property(john.heart_2_h, "tint", .86, 0, 0) 
  333. 			vint_set_property(john.heart_3_h, "tint", .86, 0, 0) 
  334. 			vint_set_property(john.heart_4_h, "tint", 0.5, 0.5, 0.5) 
  335. 			vint_set_property(john.heart_5_h, "tint", 0.5, 0.5, 0.5) 
  336. 		end 
  337. 		if recruit_pct > .8 then 
  338. 			vint_set_property(john.heart_1_h, "tint", .86, 0, 0) 
  339. 			vint_set_property(john.heart_2_h, "tint", .86, 0, 0) 
  340. 			vint_set_property(john.heart_3_h, "tint", .86, 0, 0) 
  341. 			vint_set_property(john.heart_4_h, "tint", .86, 0, 0) 
  342. 			vint_set_property(john.heart_5_h, "tint", 0.5, 0.5, 0.5) 
  343. 		end 
  344. 		if recruit_pct >= 1 then 
  345. 			vint_set_property(john.heart_1_h, "tint", .86, 0, 0) 
  346. 			vint_set_property(john.heart_2_h, "tint", .86, 0, 0) 
  347. 			vint_set_property(john.heart_3_h, "tint", .86, 0, 0) 
  348. 			vint_set_property(john.heart_4_h, "tint", .86, 0, 0) 
  349. 			vint_set_property(john.heart_5_h, "tint", .86, 0, 0) 
  350. 		end 
  351. 		if recruit_pct == 0 then 
  352. 			vint_set_property(john.heart_1_h, "tint", 0.5, 0.5, 0.5) 
  353. 			vint_set_property(john.heart_2_h, "tint", 0.5, 0.5, 0.5) 
  354. 			vint_set_property(john.heart_3_h, "tint", 0.5, 0.5, 0.5) 
  355. 			vint_set_property(john.heart_4_h, "tint", 0.5, 0.5, 0.5) 
  356. 			vint_set_property(john.heart_5_h, "tint", 0.5, 0.5, 0.5) 
  357. 		end 
  358.  
  359. 		--Clamp the distances 
  360. 		if distance <= minclamp then 
  361. 			distance = minclamp  
  362. 		elseif distance >= maxclamp then 
  363. 			distance = maxclamp 
  364. 		end 
  365.  
  366. 		local newdist = (distance - minclamp) 
  367. 		local ratio = 1 - (newdist / (maxclamp - minclamp)) 
  368. 		local scale = (ratio * (maxscale-minscale)) + minscale 
  369.  
  370. 		vint_set_property(john.grp_h, "scale", scale, scale) 
  371. 		--vint_set_property(john.grp_h, "alpha", scale) 
  372. 			 
  373. 		--Z Depth 
  374. 		if z_depth ~= john.z_depth then 
  375. 			vint_set_property(john.grp_h,  "depth", z_depth) 
  376. 		end 
  377.  
  378. 		john.recruit_pct = recruit_pct 
  379. 		john.screen_x = screen_x 		 
  380. 		john.screen_y = screen_y 		 
  381. 		john.z_depth = z_depth 
  382. 		john.distance = distance 
  383. 		john.is_visible = is_visible 
  384.  
  385. 	end 
  386. 	 
  387. 	if event == "remove" and Hud_mp_snatch_info.johns[index] ~= nil then 
  388. 		local john = Hud_mp_snatch_info.johns[index] 
  389. 		vint_object_destroy(john.grp_h) 
  390. 		Hud_mp_snatch_info.johns[index] = nil 
  391. 	end 
  392. end