sr2lua/hud.lua

  1. HUD_DOC_HANDLE = -1 
  2.  
  3.  
  4. -- this structure is all the data needed to display and track the status of the notoriety display 
  5. TWEEN_STATE_IDLE = 0 
  6. TWEEN_STATE_RUNNING = 1 
  7. TWEEN_STATE_PAUSED = 2 
  8. TWEEN_STATE_DISABLE = 3 
  9.  
  10. --Threads 
  11. Sprint_cool_down_thread = -1 
  12.  
  13. Hud_process_thread = -1 
  14.  
  15. --Globals 
  16. MP_enabled = false 
  17.  
  18. Hud_sounds = { 
  19. 	radial_open 			= audio_get_audio_id("SYS_WEP_MENU"), 
  20. 	radial_select 			= audio_get_audio_id("SYS_WEP_SCROLL"), 
  21. 	radial_equip_weapon 	= audio_get_audio_id("SYS_RADIAL_WEAPON_EQUIP"), 
  22. 	radial_equip_food 	= audio_get_audio_id("SYS_RADIAL_DRUG_EQUIP"), 
  23. } 
  24.   
  25. Hud_noto_data = { 
  26. 	gangs = { 
  27. 		cur_team = 0, 
  28. 		cur_level = -1, 
  29. 		base_icon_name = "gang_noto_icon_", 
  30.  
  31. 		teams = { 
  32. 			["brotherhood"]	= {icon_image = "ui_hud_not_brotherhood",	bar_0_color = {0.5843, 0.0000, 0.004},	bar_1_color = {0.8039, 0.0000, 0.004}, noto_level = -1}, 
  33. 			["ronin"]	= {icon_image = "ui_hud_not_ronin",			bar_0_color = {0.7255, 0.6157, 0.184},	bar_1_color = {0.8980, 0.8667, 0.004}, noto_level = -1}, 
  34. 			["samedi"]	= {icon_image = "ui_hud_not_samedi",		bar_0_color = {0.0196, 0.4235, 0.004},	bar_1_color = {0.0353, 0.7098, 0.004}, noto_level = -1}, 
  35. 			 
  36. 			-- local_player is for mp only 
  37. 			["local_player"]	= {icon_image = "ui_hud_not_samedi",		bar_0_color = {0.0196, 0.4235, 0.004},	bar_1_color = {0.0353, 0.7098, 0.004}, noto_level = -1}, 
  38. 		}, 
  39.  
  40. 		icons = { 
  41. 			[1] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  42. 			[2] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  43. 			[3] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  44. 			[4] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  45. 			[5] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0} 
  46. 		}, 
  47.  
  48. 		meter = { meter_fill_0_h = 0, meter_fill_1_h = 0, meter_bg_h = 0, start_angle = 3.141592654, end_angle = 6.283185307, cw = true, tween = 0 }, 
  49. 	}, 
  50.  
  51. 	police = { 
  52. 		cur_team = 0, 
  53. 		cur_level = -1, 
  54. 		base_icon_name = "police_noto_icon_", 
  55.  
  56. 		teams = { 
  57. 			["police"]	= {icon_image = "ui_hud_not_police",		bar_0_color = {0.0000, 0.0000, 0.324},	bar_1_color = {0.0000, 0.0000, 0.754}, noto_level = -1}, 
  58. 			["ultor"]	= {icon_image = "ui_hud_not_ultor",			bar_0_color = {0.2549, 0.2549, 0.254},	bar_1_color = {0.4706, 0.4706, 0.474}, noto_level = -1}, 
  59. 		}, 
  60.  
  61. 		icons = { 
  62. 			[1] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  63. 			[2] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  64. 			[3] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  65. 			[4] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0}, 
  66. 			[5] = {tween_end = 0, anim_0 = 0, anim_1 = 0, anim_2 = 0, anim_3 = 0, bmp_clone_0 = 0, bmp_clone_1 = 0} 
  67. 		}, 
  68.  
  69. 		meter = { meter_fill_0_h = 0, meter_fill_1_h = 0, meter_bg_h = 0, start_angle = 0, end_angle = 3.141592654, cw = false, tween = 0 }, 
  70. 	}, 
  71. } 
  72.  
  73. Hud_player_status = { 
  74. 	cash = 0, 
  75. 	health_pct = 1.0, 
  76. 	health_recovering = false, 
  77. 	sprint_pct = 1.0, 
  78. 	respect = -1, 
  79. 	respect_needed = -1, 
  80. 	sprint_enabled = true, 
  81. 	is_sprinting = false, 
  82. 	orientation = 0, 
  83. 	inventory_disabled = false, 
  84. 	cruise_control_active = -1, 
  85. 	cruise_control_h = -1, 
  86. 	cruise_control_anim = -1, 
  87. 	health_bar = 	{ bg_h = 0, fill_0_h = 0,  fill_1_h = 0, fill_decay_h = 0,  
  88. 							fill_start_angle = PI + 0.03, fill_end_angle = PI2 - 0.03, angle_offset = 0.045, 
  89. 							anim = 0, anim_delay_start = .25, anim_delay = .25, anim_delay_decay = .9,  
  90. 							is_flashing = false}, 
  91. 	sprint_bar = 	{ bg_h = 0, fill_0_h = 0, fill_1_h = 0,  
  92. 							fill_start_angle = PI + 0.03, fill_end_angle = PI2 - 0.03, angle_offset = 0.045, 
  93. 							bar_0_color = {0, 0, 0},	bar_1_color = {0, 0, 0}, 
  94. 							is_flashing = false, 
  95. 						}, 
  96. 	respect_bar =	{ bg_h = 0, fill_0_h = 0, fill_1_h = 0, txt_grp = 0, txt = 0, 
  97. 							fill_start_angle = 0 + 0.025, fill_end_angle = PI - 0.005, angle_offset = 0.035,			 
  98. 						}, 
  99. 						 
  100. } 
  101.  
  102.  
  103. Hud_enemy_status = { 
  104. 	respect = -1, 
  105. 	respect_needed = -1, 
  106. 	respect_bar =	{ bg_h = 0, fill_0_h = 0, fill_1_h = 0, txt_grp = 0, txt = 0, 
  107. 							start_angle = 0, end_angle = 3.14						 
  108. 						} 
  109. } 
  110.  
  111. Hud_weapon_status = { 
  112. 	wpn_ready = true, 
  113. 	fine_aim_transition = 0, 
  114. 	sniper_visible = -1, 
  115. 	ammo_text_h = 0, 
  116. 	single_wpn_icon_h = 0, 
  117. 	dual_wpn_icon_1_h = 0, 
  118. 	dual_wpn_icon_2_h = 0 
  119. } 
  120.  
  121. Hud_followers = { 
  122. 	slot_arrange = {1, 2, 3}, 
  123. 	slot_objects = { {}, {}, {} }, 
  124. 	follower_data = { 
  125. 		[1] = { head_img_name = "" }, 
  126. 		[2] = { head_img_name = "" }, 
  127. 		[3] = { head_img_name = "" }, 
  128. 	}, 
  129. } 
  130.  
  131. Hud_balance_status = { 
  132. 	active = -1,  
  133. 	position = 0, 
  134. 	balance_grp_h = 0, 
  135. 	base_image_h = 0, 
  136. 	arrow_image_h = 0, 
  137. 	min_angle = -0.466, 
  138. 	max_angle = 0.466, 
  139. 	color_base = {0.2000, 0.7529, 0.014}, 
  140. 	color_alarm = {0.5569, 0.1451, 0.004} 
  141. } 
  142.  
  143. Hud_vignettes = { 
  144. 	health = { 
  145. 		grp_h = -1, 
  146. 		fade_anim_h = -1, 
  147. 		fade_twn_h = -1, 
  148. 		tint_anim_h = -1, 
  149. 		tint_twn_h = -1 
  150. 	}, 
  151. 	fine_aim_dim = { 
  152. 		grp_h = -1, 
  153. 	} 
  154. } 
  155.  
  156. Reticule_hits = {} 
  157. Hud_hit_elements = { 
  158. 	main = -1, 
  159. 	minor = -1, 
  160. 	major = -1, 
  161. 	anim = -1, 
  162. } 
  163.  
  164. Hud_mp_snatch_elements = { 
  165. 	main_grp_h = -1, 
  166. 	head_img_bg_h = -1, 
  167. 	recruitment_fill_h = -1, 
  168. } 
  169.  
  170. Hud_radial_menu = { 
  171. 	radial_grp_h = -1, 
  172. 	ammo_angle_full = -3.2, 
  173. 	ammo_angle_empty = -4.7, 
  174. 	stick_grp_h = -1, 
  175. 	dpad_highlight_h = -1, 
  176. 	dpad_highlight_anim_h = -1, 
  177. 	stick_text_h = -1, 
  178. 	selector_h = -1, 
  179. 	stick_mag = 0, 
  180. 	slot_selected = 5, 
  181. 	slot_equipped = 0, 
  182. 	slot_desc_h = -1, 
  183. 	slots = {}, 
  184. } 
  185.  
  186. Hud_smoked_busted = {} 
  187.  
  188. Hud_inventory = {} 
  189.  
  190. Hud_current_veh_logo = 0 
  191. Hud_current_radio_station = 0 
  192. Hud_radio_show = false 
  193. Hud_map = {} 
  194.  
  195.  
  196. Hud_lockon = { 
  197. 	color_locked = {r=.7,g=0,b=0}, 
  198. 	color_unlocked = {r=0,g=.8,b=0}, 
  199. 	base_pixel_size =100 
  200. } 
  201.  
  202. function hud_init() 
  203. 		 
  204. 	--Store document handle 
  205. 	HUD_DOC_HANDLE = vint_document_find("hud") 
  206. 	 
  207. 	MP_enabled = mp_is_enabled() 
  208. 	 
  209. 	--Pause all animations 
  210. 	vint_set_property(vint_object_find("noto_anim_0"), "is_paused", true) 
  211. 	vint_set_property(vint_object_find("noto_anim_1"), "is_paused", true) 
  212. 	vint_set_property(vint_object_find("noto_anim_2"), "is_paused", true) 
  213. 	vint_set_property(vint_object_find("noto_anim_3"), "is_paused", true) 
  214.  
  215. 	vint_set_property(vint_object_find("health_anim_0"), "is_paused", true) 
  216. 	vint_set_property(vint_object_find("health_anim_1"), "is_paused", true) 
  217.  
  218. 	vint_set_property(vint_object_find("sprint_anim_0"), "is_paused", true) 
  219. 	vint_set_property(vint_object_find("sprint_anim_1"), "is_paused", true) 
  220.  
  221. 	vint_set_property(vint_object_find("follow_anim_0"), "is_paused", true) 
  222. 	vint_set_property(vint_object_find("follow_anim_1"), "is_paused", true) 
  223. 	vint_set_property(vint_object_find("follow_rev_anim_0"), "is_paused", true) 
  224. 	 
  225. 	vint_set_property(vint_object_find("dpad_highlight_anim_1"), "is_paused", true) 
  226. 	 
  227. 	vint_set_property(vint_object_find("gsi_xy_anim_in"), "is_paused", true) 
  228. 	 
  229. 	vint_set_property(vint_object_find("vehicle_logo_anim_1"), "is_paused", true) 
  230. 	vint_set_property(vint_object_find("radio_station_anim_1"), "is_paused", true) 
  231. 	 
  232. 	--Notoriety Meters 
  233. 	Hud_noto_data.gangs.meter.meter_fill_0_h = vint_object_find("gang_noto_fill_0") 
  234. 	Hud_noto_data.gangs.meter.meter_fill_1_h = vint_object_find("gang_noto_fill_1") 
  235. 	Hud_noto_data.police.meter.meter_fill_0_h = vint_object_find("police_noto_fill_0") 
  236. 	Hud_noto_data.police.meter.meter_fill_1_h = vint_object_find("police_noto_fill_1") 
  237. 	Hud_noto_data.gangs.meter.meter_bg_h = vint_object_find("gang_noto_bg") 
  238. 	Hud_noto_data.police.meter.meter_bg_h = vint_object_find("police_noto_bg") 
  239.  
  240. 	--Health Meter 
  241. 	Hud_player_status.health_bar.bg_h = vint_object_find("health_bar_bg") 
  242. 	Hud_player_status.health_bar.fill_0_h = vint_object_find("health_bar_fill_0") 
  243. 	Hud_player_status.health_bar.fill_1_h = vint_object_find("health_bar_fill_1") 
  244. 	Hud_player_status.health_bar.fill_decay_h = vint_object_find("health_bar_fill_decay") 
  245.  
  246. 	--Map 
  247. 	Hud_map.base_grp_h = vint_object_find("map_grp") 
  248. 	 
  249. 	--Sprint Meter 
  250. 	Hud_player_status.sprint_bar.bg_h = vint_object_find("sprint_bar_bg") 
  251. 	Hud_player_status.sprint_bar.fill_0_h = vint_object_find("sprint_bar_fill_0") 
  252. 	Hud_player_status.sprint_bar.fill_1_h = vint_object_find("sprint_bar_fill_1") 
  253. 	 
  254. 	--Respect Mater 
  255. 	Hud_player_status.respect_bar.bg_h = vint_object_find("respect_bar_bg") 
  256. 	Hud_player_status.respect_bar.fill_0_h = vint_object_find("respect_bar_fill_0") 
  257. 	Hud_player_status.respect_bar.fill_1_h = vint_object_find("respect_bar_fill_1") 
  258. 	Hud_player_status.respect_bar.txt_grp = vint_object_find("respect_count_grp") 
  259. 	Hud_player_status.respect_bar.txt = vint_object_find("respect_count_txt") 
  260. 		 
  261. 	--Reset angles on health meter 
  262. 	local bar = Hud_player_status.health_bar 
  263. 	vint_set_property(bar.bg_h, 		"start_angle", bar.fill_start_angle - bar.angle_offset) 
  264. 	vint_set_property(bar.bg_h, 		"end_angle", 	bar.fill_end_angle + bar.angle_offset) 
  265. 	vint_set_property(bar.fill_0_h,	"start_angle", bar.fill_start_angle) 
  266. 	vint_set_property(bar.fill_0_h, 	"end_angle", 	bar.fill_end_angle) 
  267. 	vint_set_property(bar.fill_1_h, 	"start_angle", bar.fill_start_angle) 
  268. 	vint_set_property(bar.fill_1_h, 	"end_angle", 	bar.fill_end_angle) 
  269.  
  270. 	--Reset angles on sprint meter 
  271. 	bar = Hud_player_status.sprint_bar 
  272. 	vint_set_property(bar.bg_h, 		"start_angle", bar.fill_start_angle - bar.angle_offset) 
  273. 	vint_set_property(bar.bg_h, 		"end_angle", 	bar.fill_end_angle + bar.angle_offset) 
  274. 	vint_set_property(bar.fill_0_h,	"start_angle", bar.fill_start_angle) 
  275. 	vint_set_property(bar.fill_0_h, 	"end_angle", 	bar.fill_end_angle) 
  276. 	vint_set_property(bar.fill_1_h, 	"start_angle", bar.fill_start_angle) 
  277. 	vint_set_property(bar.fill_1_h, 	"end_angle", 	bar.fill_end_angle) 
  278. 	 
  279. 	--Reset angles on Respect meter 
  280. 	bar = Hud_player_status.respect_bar 
  281. 	vint_set_property(bar.bg_h, 		"start_angle", bar.fill_start_angle - bar.angle_offset) 
  282. 	vint_set_property(bar.bg_h, 		"end_angle", 	bar.fill_end_angle + bar.angle_offset) 
  283. 	vint_set_property(bar.fill_0_h,	"start_angle", bar.fill_start_angle) 
  284. 	vint_set_property(bar.fill_0_h, 	"end_angle", 	bar.fill_end_angle) 
  285. 	vint_set_property(bar.fill_1_h, 	"start_angle", bar.fill_start_angle) 
  286. 	vint_set_property(bar.fill_1_h, 	"end_angle", 	bar.fill_end_angle) 
  287. 	 
  288. 	--Store sprint colors from document information 
  289. 	Hud_player_status.sprint_bar.bar_0_color[1], Hud_player_status.sprint_bar.bar_0_color[2], Hud_player_status.sprint_bar.bar_0_color[3] = vint_get_property(Hud_player_status.sprint_bar.fill_0_h,  "tint") 
  290. 	Hud_player_status.sprint_bar.bar_1_color[1], Hud_player_status.sprint_bar.bar_1_color[2], Hud_player_status.sprint_bar.bar_1_color[3] = vint_get_property(Hud_player_status.sprint_bar.fill_1_h,  "tint") 
  291. 	 
  292. 	--Cash 
  293. 	Hud_player_status.cash_h = vint_object_find("cash") 
  294. 	 
  295. 	--Ammo/Weapons 
  296. 	Hud_weapon_status.ammo_text_h = vint_object_find("ammo_status") 
  297. 	Hud_weapon_status.single_wpn_icon_h = vint_object_find("weapon_icon") 
  298. 	Hud_weapon_status.dual_wpn_icon_1_h = vint_object_find("dual_weapon_1") 
  299. 	Hud_weapon_status.dual_wpn_icon_2_h = vint_object_find("dual_weapon_2") 
  300.  
  301. 	--Balance Meter 
  302. 	local balance_meter = vint_object_find("balance_meter") 
  303. 	Hud_balance_status.balance_grp_h = balance_meter 
  304. 	Hud_balance_status.base_grp_h = vint_object_find("base_grp", balance_meter) 
  305. 	Hud_balance_status.arrow_image_h = vint_object_find("arrow_grp", balance_meter) 
  306. 	 
  307. 	--Vignette 
  308. 	local h = vint_object_find("vignettes") 
  309. 	Hud_vignettes.health.grp_h = vint_object_find("vignette_health", h ) 
  310. 	Hud_vignettes.health.fade_anim_h = vint_object_find("vignette_fade_anim") 
  311. 	Hud_vignettes.health.fade_twn_h = vint_object_find("vignette_alpha_twn") 
  312. 	 
  313. 	local vignette_doc = vint_document_find("vignette") 
  314. 	Hud_vignettes.fine_aim_dim.grp_h = vint_object_find("vignette", nil, vignette_doc) 
  315. 	vint_set_property(Hud_vignettes.health.fade_anim_h, "is_paused", true) 
  316.  
  317. 	--Pause Animations 
  318. 	vint_set_property(vint_object_find("hit_anim"), "is_paused", true) 
  319. 	--Followers 
  320. 	local master_follower_anim_0 = vint_object_find("follow_anim_0") 
  321. 	local master_follower_anim_1 = vint_object_find("follow_anim_1") 
  322. 	local master_count_tween_alpha = vint_object_find("follow_rev_count_alpha_0") 
  323. 	local master_count_tween_scale = vint_object_find("follow_rev_count_scale_0") 
  324. 	vint_set_property(master_follower_anim_0, "is_paused", true) 
  325. 	vint_set_property(master_follower_anim_1, "is_paused", true) 
  326. 	 
  327. 	for i = 1, 3 do 
  328. 		local slot_object = Hud_followers.slot_objects[i] 
  329. 		local grp = vint_object_find("follower_grp_" .. i) 
  330. 		slot_object.name = i 
  331. 		slot_object.head_img_h = vint_object_find("follower_head", grp) 
  332. 		slot_object.frame_img_h = vint_object_find("follower_frame", grp) 
  333. 		slot_object.health_img_bg_h = vint_object_find("follower_health_bg", grp) 
  334. 		slot_object.health_img_fill_h = vint_object_find("follower_health_fill", grp) 
  335. 		slot_object.revive_timer_h = vint_object_find("follower_count", grp) 
  336. 		slot_object.visible = -1 
  337. 		slot_object.group_h = grp 
  338.  
  339. 		--clone animations into slots 
  340. 		local anim_0 = vint_object_clone(master_follower_anim_0) 
  341. 		local anim_1 = vint_object_clone(master_follower_anim_1) 
  342. 		slot_object.anim_0 = anim_0 
  343. 		slot_object.anim_1 = anim_1 
  344. 		vint_set_property(anim_0, "is_paused", true) 
  345. 		vint_set_property(anim_1, "is_paused", true) 
  346. 		vint_set_property(anim_0, "target_handle", grp) 
  347. 		vint_set_property(anim_1, "target_handle", grp) 
  348.  
  349. 		 
  350. 		--Duplicate Tweens for Counting Anim 
  351. 		vint_set_property(vint_object_clone(master_count_tween_alpha), "target_handle", slot_object.revive_timer_h) 
  352. 		vint_set_property(vint_object_clone(master_count_tween_scale), "target_handle", slot_object.revive_timer_h) 
  353. 	end 
  354.  
  355. 	--Radial Menu 
  356. 	local slot_anchors = {} 
  357. 	Hud_radial_menu.radial_grp_h = vint_object_find("radial_grp") 
  358. 	Hud_radial_menu.stick_grp_h = vint_object_find("stick_grp", Hud_radial_menu.radial_grp_h) 
  359. 	Hud_radial_menu.stick_text_h = vint_object_find("stick_text", Hud_radial_menu.radial_grp_h) 
  360. 	Hud_radial_menu.selector_h = vint_object_find("slot_select", Hud_radial_menu.radial_grp_h) 
  361. 	Hud_radial_menu.slot_desc_h = vint_object_find("slot_description") 
  362. 	Hud_radial_menu.dpad_highlight_h = vint_object_find("dpad_highlight", Hud_radial_menu.radial_grp_h) 
  363. 	Hud_radial_menu.dpad_highlight_anim_h = vint_object_find("dpad_highlight_anim_1") 
  364. 	 
  365. 	-- platform specific changes! 
  366. 	local control_group_h = vint_object_find("control_stick", Hud_radial_menu.radial_grp_h) 
  367. 	local control_base_h = vint_object_find("base", control_group_h) 
  368. 	vint_set_property(control_base_h, "image", get_control_stick_base()) 
  369. 	local control_stick_group_h = vint_object_find("stick_grp", control_group_h) 
  370. 	local control_stick_h = vint_object_find("stick", control_stick_group_h) 
  371. 	vint_set_property(control_stick_h, "image", get_control_stick_thumb())	 
  372. 	local control_stick_text_h = vint_object_find("stick_text", control_stick_group_h) 
  373. 	vint_set_property(control_stick_text_h, "text_tag", get_control_stick_text()) 
  374. 	 
  375. 	local control_dpad_h = vint_object_find("dpad", Hud_radial_menu.radial_grp_h) 
  376. 	vint_set_property(control_dpad_h, "image", get_dpad_image()) 
  377. 	 
  378. 	 
  379. 	local slot_grp_h 
  380. 	local item_x, item_y 
  381. 	 
  382. 	--store slot locations skip over 0 and 8(These are templates) 
  383. 	for i = 1, 7 do 
  384. 		slot_grp_h = vint_object_find("slot_" .. i, Hud_radial_menu.radial_grp_h) 
  385. 		 
  386. 		 
  387. 		item_x, item_y = vint_get_property(slot_grp_h, "anchor") 
  388. 		slot_anchors[i] = { x = item_x, y = item_y} 
  389. 		vint_object_destroy(slot_grp_h) 
  390. 	end 
  391. 	for i = 9, 11 do 
  392. 		slot_grp_h = vint_object_find("slot_" .. i) 
  393. 		item_x, item_y = vint_get_property(slot_grp_h, "anchor") 
  394. 		slot_anchors[i] = { x = item_x, y = item_y} 
  395. 		vint_object_destroy(slot_grp_h) 
  396. 	end 
  397. 	 
  398. 	--Create template elements 
  399. 	for i = 0, 11 do 
  400. 		Hud_radial_menu.slots[i] = { 
  401. 			grp_h = -1, 
  402. 			ammo_bar_fill_h = -1, 
  403. 			ammo_bar_bg_h = -1, 
  404. 			item_element_h = -1, 
  405. 			item_name_crc = -1, 
  406. 			infinite_h = -1, 
  407. 			bmp_name = -1, 
  408. 			availability = -1, 
  409. 			ammo_infinite = -1, 
  410. 			dual_wield = -1, 
  411. 			ammo_cur = -1, 
  412. 			ammo_max = -1, 
  413. 		} 
  414. 	end 
  415.  
  416. 	--Now populate radial menu groups groups using templates 0 and 8 
  417. 	Hud_radial_menu.slots[0].grp_h = vint_object_find("slot_0", Hud_radial_menu.radial_grp_h) 
  418. 	Hud_radial_menu.slots[0].ammo_bar_fill_h = vint_object_find("ammo", Hud_radial_menu.slots[0].grp_h) 
  419. 	Hud_radial_menu.slots[0].ammo_bar_bg_h = vint_object_find("ammo_bg", Hud_radial_menu.slots[0].grp_h) 
  420. 	Hud_radial_menu.slots[0].infinite_h =  vint_object_find("infinite", Hud_radial_menu.slots[0].grp_h) 
  421. 	 
  422. 	Hud_radial_menu.slots[8].grp_h = vint_object_find("slot_8", Hud_radial_menu.radial_grp_h) 
  423. 	Hud_radial_menu.slots[8].item_element_h = vint_object_find("inv_icon", Hud_radial_menu.slots[8].grp_h) 
  424. 	 
  425. 	--Radial Menu Weapon Slots 
  426. 	for i = 1, 7 do 
  427. 		slot_grp_h = vint_object_clone(Hud_radial_menu.slots[0].grp_h) 
  428. 		vint_set_property(slot_grp_h, "anchor", slot_anchors[i].x, slot_anchors[i].y)  
  429. 		Hud_radial_menu.slots[i].grp_h = slot_grp_h 
  430. 		Hud_radial_menu.slots[i].ammo_bar_fill_h = vint_object_find("ammo", slot_grp_h) 
  431. 		Hud_radial_menu.slots[i].ammo_bar_bg_h = vint_object_find("ammo_bg", slot_grp_h) 
  432. 		Hud_radial_menu.slots[i].infinite_h = vint_object_find("infinite", slot_grp_h) 
  433. 		vint_object_rename(slot_grp_h, "slot_" .. i) 
  434. 	end 
  435. 	 
  436. 	--Radial Menu Food Slots 
  437. 	for i = 9, 11 do 
  438. 		slot_grp_h = vint_object_clone(Hud_radial_menu.slots[8].grp_h) 
  439. 		vint_set_property(slot_grp_h, "anchor", slot_anchors[i].x, slot_anchors[i].y)  
  440. 		Hud_radial_menu.slots[i].grp_h = slot_grp_h 
  441. 		Hud_radial_menu.slots[i].item_element_h = vint_object_find("inv_icon", slot_grp_h) 
  442. 	end 
  443. 	 
  444. 	--Hit Indicator  
  445. 	Hud_hit_elements.main_h = vint_object_find("hits") 
  446. 	h = Hud_hit_elements.main_h  
  447. 	Hud_hit_elements.minor_h = vint_object_find("major", h) 
  448. 	Hud_hit_elements.major_h = vint_object_find("major", h) 
  449. 	Hud_hit_elements.anim_h = vint_object_find("hit_anim") 
  450.  
  451. 	--Cruise Control 
  452. 	Hud_player_status.cruise_control_h = vint_object_find("cruise_control_grp") 
  453. 	Hud_player_status.cruise_control_anim = vint_object_find("cruise_control_fade_anim") 
  454. 	 
  455. 	--Hud Lockon 
  456. 	 
  457. 	Hud_lockon.lock_h = vint_object_find("lockon") 
  458. 	Hud_lockon.lock1_h = vint_object_find("lockon_1", Hud_lockon.lockon_h ) 
  459. 	Hud_lockon.lock2_h = vint_object_find("lockon_2", Hud_lockon.lockon_h ) 
  460. 	Hud_lockon.lock3_h = vint_object_find("lockon_3", Hud_lockon.lockon_h ) 
  461. 	Hud_lockon.lock4_h = vint_object_find("lockon_4", Hud_lockon.lockon_h ) 
  462. 	 
  463. 	--lockon base screensize 
  464. 	Hud_lockon.lock_base_width, Hud_lockon.lock_base_height = vint_get_property(Hud_lockon.lock1_h, "scale") 
  465. 	 
  466. 	 
  467. 	--Initialize Gameplay Status Indicator 
  468. 	hud_gsi_init() 
  469. 	 
  470. 	--Initialize Mayhem Hud 
  471. 	hud_mayhem_init() 
  472. 	 
  473. 	--Initialize Floating Healthbars (sewage version) 
  474. 	hud_healthbars_init() 
  475. 	 
  476. 	--Initialize mp snatch system 
  477. 	hud_mp_snatch_init() 
  478. 	 
  479. 	--Initialize reticule related stuff, 
  480. 	hud_reticules_init() 
  481. 	 
  482. 	hud_collection_msg_init() 
  483. 	hud_busted_init() 
  484.  
  485. 	--Subscribe to datagroups and dataitems 
  486. 	 
  487. 	--Notoriety` 
  488. 	vint_datagroup_add_subscription("sr2_notoriety", "update", "hud_noto_change") 
  489. 	vint_datagroup_add_subscription("sr2_notoriety", "insert", "hud_noto_change") 
  490. 	 
  491. 	--Hood 
  492. 	vint_dataitem_add_subscription("sr2_local_player_hood", "update", "hud_player_hood_change") 
  493. 	vint_dataitem_add_subscription("sr2_local_player_status", "update", "hud_player_status_change") 
  494.  
  495.  
  496. 	--Followers 
  497. 	vint_datagroup_add_subscription("sr2_local_player_followers", "insert", "hud_player_followers_change") 
  498. 	vint_datagroup_add_subscription("sr2_local_player_followers", "update", "hud_player_followers_change") 
  499.  
  500. 	--Infrequent 
  501. 	--..moving below followers, hopefully solves homie update issues (Derik) 
  502. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "hud_player_status_inf_change") 
  503. 	 
  504. 	--Radial Menu 
  505. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "insert", "hud_radial_menu_update") 
  506. 	vint_datagroup_add_subscription("sr2_local_player_inventory", "update", "hud_radial_menu_update") 
  507.  
  508. 	--Weapons 
  509. 	vint_dataitem_add_subscription("sr2_local_player_weapons", "update", "hud_player_weapon_change") 
  510. 	vint_dataitem_add_subscription("sr2_local_player_frequent_weapon", "update", "hud_player_weapon_freq_change") 
  511. 	 
  512. 	--Lockon 
  513. 	vint_dataitem_add_subscription("sr2_local_player_lockon", "update", "hud_player_lockon_update") 
  514. 	 
  515.  
  516.  
  517. 	--TODO: This shouldn't use the same data group anyways. Sean will need to fix this gameside 
  518. 	if MP_enabled == false then 
  519. 		vint_dataitem_add_subscription("sr2_local_player_respect", "update", "hud_player_respect_change") 
  520. 		 
  521. 	elseif MP_enabled == true then 
  522. 		--Need to hide the respect meter 
  523. 		vint_set_property(Hud_player_status.respect_bar.bg_h, "visible", false) 
  524. 		vint_set_property(Hud_player_status.respect_bar.fill_0_h, "visible", false) 
  525. 		vint_set_property(Hud_player_status.respect_bar.fill_1_h, "visible", false) 
  526. 		vint_set_property(Hud_player_status.respect_bar.txt_grp, "visible", false) 
  527. 		vint_set_property(Hud_player_status.respect_bar.txt, "visible", false) 
  528. 		 
  529. 		--Hide the food UI 
  530. 		vint_set_property(vint_object_find("dpad"), "visible", false) 
  531. 		for i = 8, 11 do 
  532. 			vint_set_property(Hud_radial_menu.slots[i].grp_h, "visible", false)  
  533. 		end 
  534. 		 
  535. 		--Hide cash element 
  536. 		vint_set_property(Hud_player_status.cash_h, "visible", false) 
  537. 		 
  538. 		-- Hide followers 
  539. 		vint_set_property(Hud_followers.slot_objects[1].group_h, "visible", false) 
  540. 		vint_set_property(Hud_followers.slot_objects[2].group_h, "visible", false) 
  541. 		vint_set_property(Hud_followers.slot_objects[3].group_h, "visible", false) 
  542. 	end 
  543. 	 
  544. 	vint_dataitem_add_subscription("sr2_balance_meter", "update", "hud_balance_meter_change") 
  545.  
  546. 	--HUD Process Thread 
  547. 	Hud_process_thread = thread_new("hud_process") 
  548. end 
  549.  
  550. function hud_cleanup() 
  551.  
  552. 	--kill threads 
  553.  
  554. 	--Clean up hud 
  555. 	hud_inventory_hide() 
  556. end 
  557.  
  558. function hud_hide_map() 
  559. 	vint_set_property(Hud_map.base_grp_h, "visible", false) 
  560. end 
  561.  
  562. function hud_show_map() 
  563. 	vint_set_property(Hud_map.base_grp_h, "visible", true) 
  564. end 
  565.  
  566. function hud_inventory_input(event, value) 
  567. 	--debug_print("vint", "Inventory Event: " .. event .. " : "  .. value .. "\n") 
  568. 	--debug_print("vint", "Inventory is disabled: " .. lua_test_var(Hud_player_status.inventory_disabled) .. "\n") 
  569. 	if event == "inventory" then 
  570. 		if value > 0.5 then		 
  571. 		 
  572. 			if MP_enabled then 
  573. 				-- We're doing a fast weapon switch if you tap the button 
  574. 				if Hud_inventory.is_pressed == false then 
  575. 					if Hud_inventory.tap_thread == nil then 
  576. 						Hud_inventory.tap_thread = thread_new( "hud_inventory_delayed_show" ) 
  577. 					end	 
  578. 				end 
  579. 			else 
  580. 				--still want to keep track of is_pressed to show inventory when status is enabled 
  581. 				Hud_inventory.is_pressed = true 
  582. 				 
  583. 				if Hud_player_status.inventory_disabled == false then 
  584. 					hud_inventory_show() 
  585. 				end 
  586. 			end 
  587. 			 
  588. 		else 
  589. 		 
  590. 			Hud_inventory.is_pressed = false 
  591. 			 
  592. 			if Hud_inventory.tap_thread ~= nil then 
  593. 				--only switch if the inventory is enabled 
  594. 				if Hud_player_status.inventory_disabled == false then 
  595. 					-- Counts as a tap, do a quick weapon switch 
  596. 					--debug_print( "vint", "Inventory button was tapped, quick weapon switch\n" ) 
  597. 					inventory_switch_to_next_slot() 
  598. 				end 
  599. 				 
  600. 				thread_kill( Hud_inventory.tap_thread ) 
  601. 				Hud_inventory.tap_thread = nil 
  602. 			end 
  603. 			 
  604. 			if Hud_inventory.thread ~= nil then 
  605. 				--Check to see if the item is selectable 
  606. 				local slot = Hud_radial_menu.slots[Hud_radial_menu.slot_selected] 
  607. 				if slot.availability == true and slot.bmp_name ~= nil and Hud_radial_menu.slot_selected ~= Hud_radial_menu.slot_equipped then 
  608. 					--Slot is available and there is an item in the slot 
  609. 					--Select item in game code 
  610. 					use_radial_menu_item(Hud_radial_menu.slot_selected) 
  611. 					if Hud_radial_menu.slot_selected < 8 then 
  612. 						--If it wasn't a food item change the equipped slot 
  613. 						Hud_radial_menu.slot_equipped = Hud_radial_menu.slot_selected 
  614. 						local radial_is_visible =  vint_get_property(Hud_radial_menu.radial_grp_h, "visible") 
  615. 						if radial_is_visible then 
  616. 							audio_play(Hud_sounds.radial_equip_weapon) 
  617. 						end 
  618. 						 
  619. 					elseif Hud_radial_menu.slot_selected > 7 then 
  620. 						--if a food item play sound for food. 
  621. 						local radial_is_visible =  vint_get_property(Hud_radial_menu.radial_grp_h, "visible") 
  622. 						if radial_is_visible then 
  623. 							audio_play(Hud_sounds.radial_equip_food) 
  624. 						end 
  625. 					end 
  626. 				end 
  627. 				hud_inventory_hide() 
  628. 			end 
  629. 		end 
  630. 	elseif event == "inventory_x" then 
  631. 		Hud_inventory.x = value 
  632. 		Hud_inventory.stale = true 
  633. 	elseif event == "inventory_y" then 
  634. 		Hud_inventory.y = value 
  635. 		Hud_inventory.stale = true 
  636. 	elseif event == "inventory_up" then 
  637. 		--Note: Dpad events only occur on press and if the stick is not in use 
  638. 		if value > 0.5 and Hud_radial_menu.stick_mag < 0.1 then 
  639. 			Hud_radial_menu_change_select(8) 
  640. 		end 
  641. 	elseif event == "inventory_right" then 
  642. 		if value > 0.5 and Hud_radial_menu.stick_mag < 0.1 then 
  643. 			Hud_radial_menu_change_select(9) 
  644. 		end 
  645. 	elseif event == "inventory_down" then 
  646. 		if value > 0.5 and Hud_radial_menu.stick_mag < 0.1 then 
  647. 			Hud_radial_menu_change_select(10) 
  648. 		end 
  649. 	elseif event == "inventory_left" then	 
  650. 		if value > 0.5 and Hud_radial_menu.stick_mag < 0.1 then 
  651. 			Hud_radial_menu_change_select(11) 
  652. 		end 
  653. 	end 
  654. end 
  655.  
  656. function chat_input(target, event, accel) 
  657. 	if mp_is_enabled() then 
  658. 		if event == "chat_all" then 
  659. 			hud_open_chat_all_window() 
  660. 		elseif event == "chat_team" then 
  661. 			hud_open_chat_team_window() 
  662. 		end 
  663. 	elseif coop_is_active() then 
  664. 		if event == "chat_all" or event == "chat_team" then 
  665. 			hud_open_chat_all_window() 
  666. 		end 
  667. 	end 
  668. end 
  669.  
  670. function hud_inventory_process() 
  671. 	while true do  
  672. 		if Hud_inventory.stale == true then 
  673. 		 
  674. 			local x = Hud_inventory.x 
  675. 			local y = Hud_inventory.y 
  676. 			local selected_weapon_index = 0 
  677. 			local mag = sqrt((x * x) + (y * y)) 
  678. 			local pi = 3.14159 
  679. 			 
  680. 			if mag > 0.5 then 
  681. 				 
  682. 				-- Y resolves out so don't bother with it 
  683. 				x = x/mag 
  684. 				local radians = acos(x) 
  685. 				 
  686. 				if y < 0.0 then 
  687. 					radians = pi + (pi - radians) 
  688. 				end 
  689. 	 
  690. 				local eighth = pi / 8 
  691. 				local fourth = pi / 4 
  692. 				local selected_weapon_index = Hud_radial_menu.slot_equiped 
  693. 				 
  694. 				if radians < eighth then 
  695. 					selected_weapon_index = 2; 
  696. 				elseif radians < (fourth + eighth) then 
  697. 					selected_weapon_index = 1 
  698. 				elseif radians < (2.0 * fourth + eighth) then 
  699. 					selected_weapon_index = 0 
  700. 				elseif radians < (3.0 * fourth + eighth) then 
  701. 					selected_weapon_index = 7 
  702. 				elseif radians < (4.0 * fourth + eighth) then 
  703. 					selected_weapon_index = 6 
  704. 				elseif radians < (5.0 * fourth + eighth) then 
  705. 					selected_weapon_index = 5 
  706. 				elseif radians < (6.0 * fourth + eighth) then 
  707. 					selected_weapon_index = 4; 
  708. 				elseif radians < (7.0 * fourth + eighth) then				 
  709. 					selected_weapon_index = 3; 
  710. 				else 
  711. 					selected_weapon_index = 2; 
  712. 				end 
  713. 				 
  714. 				--Change selected item in the menu 
  715. 				Hud_radial_menu_change_select(selected_weapon_index)	 
  716. 			end 
  717. 	 
  718. 			--Update Stick location on radial menu 
  719. 			local stick_pixel_mag = 12 
  720. 			local x = Hud_inventory.x * stick_pixel_mag 
  721. 			local y = -Hud_inventory.y * stick_pixel_mag 
  722. 			vint_set_property(Hud_radial_menu.stick_grp_h, "anchor", x, y) 
  723. 			 
  724. 			Hud_radial_menu.stick_mag = mag 
  725. 			Hud_inventory.stale = false 
  726. 		end 
  727. 		thread_yield() 
  728. 	end 
  729. end 
  730.  
  731. function hud_process() 
  732.  
  733. 	local display_cash = Hud_player_status.cash - 1 --Subtract one so it gets formatted in the loop. 
  734. 	local hud_had_focus = nil 
  735. 	 
  736. 	while true do 
  737. 		thread_yield() 
  738. 		 
  739. 		-- Animate Cash 
  740. 		if display_cash ~= Hud_player_status.cash then 
  741. 			local diff_cash = Hud_player_status.cash - display_cash 
  742. 			 
  743. 			if diff_cash > 5 or diff_cash < -5 then 
  744. 				diff_cash = floor(diff_cash * 0.5) 
  745. 			end 
  746. 			 
  747. 			display_cash = display_cash + diff_cash 
  748. 			vint_set_property(Hud_player_status.cash_h, "text_tag", "$" .. format_cash(display_cash)) 
  749. 		end 
  750. 		 
  751. 		-- check to see if the hud has lost focus 
  752. 		if hud_had_focus ~= Hud_has_focus then 
  753. 			if Hud_has_focus == false then 
  754. 				hud_inventory_disable() 
  755. 			else 
  756. 				hud_inventory_enable() 
  757. 			end	 
  758. 			hud_had_focus = Hud_has_focus 
  759. 		end 
  760. 		 
  761. 		hud_msg_process() 
  762. 	end 
  763. end 
  764.  
  765. function hud_inventory_enable()	 
  766. 	if Hud_has_focus == true then 
  767. 		--Can only enable inventory if HUD has focus 
  768. 		Hud_inventory.subs = vint_subscribe_to_raw_input("inventory", "hud_inventory_input") 
  769. 		 
  770. 		Hud_inventory.subs_chat_all = vint_subscribe_to_input_event(nil, "chat_all", "chat_input") 
  771. 		Hud_inventory.subs_chat_team = vint_subscribe_to_input_event(nil, "chat_team", "chat_input") 
  772. 	end 
  773. end 
  774.  
  775. function hud_inventory_disable() 
  776. 	if Hud_inventory.thread ~= nil then 
  777. 		--Hud lost focus so kill the inventory 
  778. 		hud_inventory_hide() 
  779. 	end 
  780. 	 
  781. 	if Hud_inventory.subs ~= nil then 
  782. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs) 
  783. 	end 
  784. 	if Hud_inventory.subs_chat_all ~= nil then 
  785. 		vint_unsubscribe_to_input_event(Hud_inventory.subs_chat_all) 
  786. 		vint_unsubscribe_to_input_event(Hud_inventory.subs_chat_team) 
  787. 	end	 
  788. 	Hud_inventory = { } 
  789. end 
  790.  
  791. -- Thread function to delay showing the inventory hud in case the player wants to tap the button 
  792. function hud_inventory_delayed_show() 
  793. 	-- It's a tap if the button's released within 1/5 of a second 
  794. 	delay( 0.2 ) 
  795. 	 
  796. 	-- Double-check disabling before we actually open the inventory 
  797. 	if not Hud_player_status.inventory_disabled then 
  798. 		hud_inventory_show() 
  799. 	end 
  800. 	 
  801. 	Hud_inventory.is_pressed = true 
  802.  
  803. 	Hud_inventory.tap_thread = nil 
  804. end 
  805.  
  806. function hud_inventory_show() 
  807.  
  808. 	hud_update_inventory() 
  809.  
  810. 	if Hud_inventory.thread == nil then 
  811. 		--Show Inventory 
  812. 	 
  813. 		vint_set_property(Hud_radial_menu.radial_grp_h, "visible", true) 
  814. 		 
  815. 		 
  816. 		--Subscribe to input 
  817. 		Hud_inventory.extra_buttons = { 
  818. 			vint_subscribe_to_input_event(nil, "alt_select", "hud_inventory_input"), 
  819. 			vint_subscribe_to_input_event(nil, "select", "hud_inventory_input"), 
  820. 			vint_subscribe_to_input_event(nil, "exit", "hud_inventory_input"), 
  821. 			vint_subscribe_to_input_event(nil, "back", "hud_inventory_input"), 
  822. 			vint_subscribe_to_input_event(nil, "white", "hud_inventory_input"), 
  823. 			vint_subscribe_to_input_event(nil, "black", "hud_inventory_input"), 
  824. 			vint_subscribe_to_input_event(nil, "map", "hud_inventory_input"), 
  825. 			vint_subscribe_to_input_event(nil, "pause", "hud_inventory_input"), 
  826. 			vint_subscribe_to_input_event(nil, "scroll_up", "hud_inventory_input"), 
  827. 			vint_subscribe_to_input_event(nil, "scroll_down", "hud_inventory_input"), 
  828. 			--vint_subscribe_to_input_event(nil, "scroll_left", "hud_inventory_input"), 
  829. 			--vint_subscribe_to_input_event(nil, "scroll_right", "hud_inventory_input"), 
  830. 		} 
  831.  
  832. 		Hud_inventory.subs_x = vint_subscribe_to_raw_input("inventory_x", "hud_inventory_input") 
  833. 		Hud_inventory.subs_y = vint_subscribe_to_raw_input("inventory_y", "hud_inventory_input") 
  834. 		Hud_inventory.subs_up = vint_subscribe_to_raw_input("inventory_up", "hud_inventory_input") 
  835. 		Hud_inventory.subs_right = vint_subscribe_to_raw_input("inventory_right", "hud_inventory_input") 
  836. 		Hud_inventory.subs_down = vint_subscribe_to_raw_input("inventory_down", "hud_inventory_input") 
  837. 		Hud_inventory.subs_left = vint_subscribe_to_raw_input("inventory_left", "hud_inventory_input") 
  838.  
  839. 		--Reset visual analog stick and get the proper text tag on it. 
  840. 		Hud_inventory.x = 0 
  841. 		Hud_inventory.y = 0 
  842. 		vint_set_property(Hud_radial_menu.stick_grp_h, "anchor", 0, 0) 
  843. 		--vint_set_property(Hud_radial_menu.stick_text_h, "text_tag", Hud_inv_select_stick) 
  844. 		vint_set_property(Hud_radial_menu.stick_text_h, "text_tag", get_control_stick_text()) 
  845. 		Hud_radial_menu_change_select(Hud_radial_menu.slot_equipped) 
  846. 		 
  847. 		audio_play(Hud_sounds.radial_open) 
  848.  
  849. 		--vint_set_property(Hud_radial_menu.stick_grp_h,"anchor", 0, 0) 
  850. 		Hud_inventory.thread = thread_new("hud_inventory_process")			 
  851. 	end 
  852. end 
  853.  
  854. function hud_inventory_hide() 
  855. 	if Hud_inventory.thread ~= nil then 
  856. 		--Hide Inventory 
  857. 		vint_set_property(Hud_radial_menu.radial_grp_h, "visible", false) 
  858. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_x) 
  859. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_y) 
  860. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_up) 
  861. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_right) 
  862. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_down) 
  863. 		vint_unsubscribe_to_raw_input(Hud_inventory.subs_left) 
  864. 		 
  865. 		for idx, val in Hud_inventory.extra_buttons do  
  866. 			vint_unsubscribe_to_input_event(val) 
  867. 		end 
  868. 		Hud_inventory.extra_buttons = nil				 
  869. 		thread_kill(Hud_inventory.thread) 
  870. 		Hud_inventory.thread = nil 
  871. 	end 
  872. 	 
  873. 	-- Kill a delayed show thread 
  874. 	if Hud_inventory.tap_thread ~= nil then 
  875. 		thread_kill( Hud_inventory.tap_thread ) 
  876. 		Hud_inventory.tap_thread = nil 
  877. 	end 
  878. 	 
  879. end 
  880.  
  881. --------------------- 
  882. --Food inventory for the food/liqour store 
  883. -------------------- 
  884. function hud_inventory_food_show() 
  885. 	--Show Inventory 
  886. 	vint_set_property(Hud_radial_menu.radial_grp_h, "visible", true) 
  887. 	vint_set_property(vint_object_find("control_stick", Hud_radial_menu.radial_grp_h), "visible", false) 
  888. 	vint_set_property(Hud_radial_menu.slot_desc_h, "visible", false) 
  889. 	vint_set_property(Hud_radial_menu.dpad_highlight_h, "visible", false) 
  890. 	vint_set_property(Hud_radial_menu.selector_h, "visible", false) 
  891. 	 
  892. 	--Hide the radial slots... 
  893. 	local slot_h 
  894. 	for i = 0, 7 do 
  895. 		vint_set_property(Hud_radial_menu.slots[i].grp_h, "visible", false) 
  896. 	end	 
  897. end 
  898.  
  899.  
  900.  
  901. function hud_inventory_food_hide() 
  902. 	--Hide Inventory 
  903. 	vint_set_property(Hud_radial_menu.radial_grp_h, "visible", false) 
  904. 	vint_set_property(vint_object_find("control_stick", Hud_radial_menu.radial_grp_h), "visible", true) 
  905. 	vint_set_property(Hud_radial_menu.slot_desc_h, "visible", true) 
  906. 	vint_set_property(Hud_radial_menu.dpad_highlight_h, "visible", true) 
  907. 	vint_set_property(Hud_radial_menu.selector_h, "visible", true) 
  908. 	 
  909. 	--Reset to show the radial slots 
  910. 	local slot_h 
  911. 	for i = 0, 7 do 
  912. 		vint_set_property(Hud_radial_menu.slots[i].grp_h, "visible", true) 
  913. 	end 
  914. end 
  915.  
  916. function hud_inventory_food_highlight_slot(slot_num) 
  917. 	if slot_num == nil then 
  918. 		vint_set_property(Hud_radial_menu.selector_h, "visible", false) 
  919. 		hud_radial_menu_slot_scales_reset() 
  920. 	else 
  921. 		vint_set_property(Hud_radial_menu.selector_h, "visible", true) 
  922. 		Hud_radial_menu_change_select(slot_num + 8, true) 
  923. 	end 
  924. end 
  925.  
  926.  
  927. function hud_player_hood_change(data_item_handle, event_name) 
  928. 	local hood_name, cur_hood_owner, orig_hood_owner, is_contested = vint_dataitem_get(data_item_handle) 
  929.  
  930. 	-- this will become relevant for pushbacks and display of notoriety since we always will show 
  931. 	-- gang noto for mission/activity gang or hood owner if hood is contested 
  932. end 
  933.  
  934. function hud_noto_change(data_item_h, event_name) 
  935. 	local team_name, noto_level, noto_icon = vint_dataitem_get(data_item_h) 
  936. 	 
  937. 	local noto_data, display_data, icon_data, meter_data, team_data 
  938. 	 
  939. 	--	debug_print("vint", team_name.."/"..noto_level.."/"..noto_icon.."\n") 
  940.  
  941. 	-- find the interesting data for team 
  942. 	for key, value in Hud_noto_data do 
  943. 		if value.teams[team_name] ~= nil then 
  944. 			noto_data = value 
  945. 			display_data = value.teams[team_name] 
  946. 			icon_data = value.icons 
  947. 			meter_data = value.meter 
  948. 			break 
  949. 		end 
  950. 	end 
  951.  
  952. 	if noto_data == nil then 
  953. 		-- not an interesting team so outta here 
  954. 		return 
  955. 	end 
  956.  
  957. 	-- update the notoriety table 
  958. 	display_data.noto_level = noto_level 
  959.  
  960. 	-- find the team in this group with highest notoriety 
  961. 	noto_level = -1 
  962. 	team_name = nil 
  963. 	for key, value in noto_data.teams do 
  964. 		if value.noto_level > noto_level then 
  965. 			team_name = key 
  966. 			noto_level = value.noto_level 
  967. 			team_data = value 
  968. 		end 
  969. 	end 
  970.  
  971. 	-- better safe then sorry 
  972. 	if team_name == nil then 
  973. 		return 
  974. 	end 
  975.  
  976. 	local base_new_noto = floor(noto_level) 
  977. 	local base_old_noto = floor(noto_data.cur_level) 
  978. 	local icon_h = 0 
  979.  
  980. 	-- new team, animate in all icons 
  981. 	if team_name ~= noto_data.cur_team then 
  982. 		for i = 1, 5 do 
  983. 			icon_h = vint_object_find(noto_data.base_icon_name .. i) 
  984. 			if base_new_noto >= i then 
  985. --				debug_print("vint", "team changed: new icon:" .. team_data.icon_image .. "\n") 
  986. 				local icon 
  987. 				 
  988. 				if MP_enabled == true then 
  989. 					icon = noto_icon 
  990. 				else 
  991. 					icon  = noto_data.teams[team_name].icon_image 
  992. 				end 
  993. 				 
  994. 				vint_set_property(icon_h, "image", icon) 
  995. 				hud_noto_show_icon(icon_h, noto_data.icons[i]) 
  996. 			else 
  997. 				hud_noto_hide_icon(icon_h, noto_data.icons[i]) 
  998. 			end 
  999. 		end 
  1000.  
  1001. 		noto_data.cur_team = team_name 
  1002. 		vint_set_property(meter_data.meter_fill_0_h, "tint", team_data.bar_0_color[1], team_data.bar_0_color[2], team_data.bar_0_color[3]) 
  1003. 		vint_set_property(meter_data.meter_fill_1_h, "tint", team_data.bar_1_color[1], team_data.bar_1_color[2], team_data.bar_1_color[3]) 
  1004. 		 
  1005. 		--debug_print("vint", "Changing to team " .. team_name .. "\n") 
  1006.  
  1007. 	-- noto on the rise, animate in all new icons 
  1008. 	elseif base_new_noto > base_old_noto then 
  1009. 		for i = 1, 5 do 
  1010. 			icon_h = vint_object_find(noto_data.base_icon_name .. i) 
  1011. 			if base_new_noto >= i and base_old_noto < i then 
  1012. 				vint_set_property_typed("string", icon_h, "image", team_data.icon_image) 
  1013. 				hud_noto_show_icon(icon_h, noto_data.icons[i]) 
  1014. 			elseif base_new_noto < i then 
  1015. 				hud_noto_hide_icon(icon_h, noto_data.icons[i]) 
  1016. 			end 
  1017. 		end 
  1018.  
  1019. 	-- noto falling, animate the highest active icon 
  1020. 	elseif base_new_noto < base_old_noto then 
  1021. 		for i = 1, 5 do 
  1022. 			icon_h = vint_object_find(noto_data.base_icon_name .. i) 
  1023. 			if base_new_noto == i then 
  1024. 				hud_noto_show_icon(icon_h, noto_data.icons[i]) 
  1025. 			elseif base_new_noto < i then 
  1026. 				hud_noto_hide_icon(icon_h, noto_data.icons[i]) 
  1027. 			end 
  1028. 		end 
  1029. 	end 
  1030.  
  1031. 	-- update meter 
  1032. 	local part_new_noto = noto_level - base_new_noto 
  1033. 		 
  1034. 	if meter_data.cw == false then 
  1035. 		-- Lower Bar Update 
  1036. 		 
  1037. 		local start_angle = meter_data.end_angle + ((meter_data.start_angle - meter_data.end_angle) * part_new_noto) 
  1038. 		 
  1039. 		vint_set_property(meter_data.meter_fill_0_h, "start_angle", start_angle) 
  1040. 		vint_set_property(meter_data.meter_fill_1_h, "start_angle", start_angle) 
  1041. 		vint_set_property(meter_data.meter_bg_h, "start_angle", start_angle - 0.02) 
  1042. 		 
  1043. 	else 
  1044. 		-- Upper Bar Update 
  1045. 		local end_angle = meter_data.start_angle + ((meter_data.end_angle - meter_data.start_angle) * part_new_noto) 
  1046. 		vint_set_property(meter_data.meter_fill_0_h, "end_angle", end_angle) 
  1047. 		vint_set_property(meter_data.meter_fill_1_h, "end_angle", end_angle) 
  1048. 		vint_set_property(meter_data.meter_bg_h, "end_angle", end_angle + 0.02) 
  1049. 	 
  1050. 	end 
  1051. 	 
  1052. 	if part_new_noto == 0 then 
  1053. 		-- If the meter is at 0 then we should hide it 
  1054. 		vint_set_property(meter_data.meter_fill_0_h, "visible", false) 
  1055. 		vint_set_property(meter_data.meter_fill_1_h, "visible", false) 
  1056. 		vint_set_property(meter_data.meter_bg_h, "visible", false) 
  1057. 	else 
  1058. 		--If the meter isn't at zero then make it visible 
  1059. 		vint_set_property(meter_data.meter_fill_0_h, "visible", true) 
  1060. 		vint_set_property(meter_data.meter_fill_1_h, "visible", true) 
  1061. 		vint_set_property(meter_data.meter_bg_h, "visible", true) 
  1062. 	end 
  1063.  
  1064. 	noto_data.cur_level = noto_level 
  1065. end 
  1066.  
  1067. function hud_noto_hide_icon(icon_h, status) 
  1068. 	 
  1069. 	--	debug_print("vint", "noto_hide_icon: " .. icon_h .. "\n") 
  1070. 	 
  1071. 	vint_object_destroy(status.bmp_clone_0) 
  1072. 	vint_object_destroy(status.bmp_clone_1) 
  1073. 	vint_object_destroy(status.anim_0) 
  1074. 	vint_object_destroy(status.anim_1) 
  1075. 	vint_object_destroy(status.anim_2) 
  1076. 	vint_object_destroy(status.anim_3) 
  1077.  
  1078. 	--ANIMATE: Fade Icon Away 
  1079. 	local anim_3 = vint_object_find("noto_anim_3") 
  1080. 	local anim_clone_3 = vint_object_clone(anim_3) 
  1081.  
  1082. 	--Targets 
  1083. 	local anim_3_alpha_tween = vint_object_find("noto_alpha_3", anim_clone_3) 
  1084. 	vint_set_property(anim_3_alpha_tween, "target_handle",	icon_h) 
  1085.  
  1086. 	--Reset Tween value 
  1087. 	local alpha_val = vint_get_property(icon_h, "alpha") 
  1088.  
  1089. 	vint_set_property_typed("float", anim_3_alpha_tween, "start_value", alpha_val) 
  1090.  
  1091. 	--Callback 
  1092. 	vint_set_property(anim_3_alpha_tween, "end_event",		"hud_noto_icon_hide_end") 
  1093.  
  1094. 	lua_play_anim(anim_clone_3, 0); 
  1095.  
  1096. 	status.bmp_clone_0 = 0 
  1097. 	status.bmp_clone_1 = 0 
  1098. 	status.anim_0 = 0 
  1099. 	status.anim_1 = 0 
  1100. 	status.anim_2 = 0 
  1101. 	status.anim_3 = anim_clone_3 
  1102. 	status.tween_end = anim_3_alpha_tween 
  1103. end 
  1104.  
  1105. function hud_noto_icon_hide_end(tween_h, event_name) 
  1106. 	-- search for indicated tween and clean up 
  1107. 	for k, v in Hud_noto_data do 
  1108. 		for key, value in v.icons do 
  1109. 			if value.tween_alpha_out == tween_h then 
  1110. 				vint_object_destroy(value.bmp_clone_0) 
  1111. 				vint_object_destroy(value.bmp_clone_1) 
  1112. 				vint_object_destroy(value.anim_0) 
  1113. 				vint_object_destroy(value.anim_1) 
  1114. 				vint_object_destroy(value.anim_2) 
  1115. 				vint_object_destroy(value.anim_3) 
  1116. 				value.bmp_clone_0 = 0 
  1117. 				value.bmp_clone_1 = 0 
  1118. 				value.anim_0 = 0 
  1119. 				value.anim_1 = 0 
  1120. 				value.anim_2 = 0 
  1121. 				value.anim_3 = 0 
  1122. 				value.tween_show = 0 
  1123. 				return 
  1124. 			end 
  1125. 		end 
  1126. 	end 
  1127. end 
  1128.  
  1129. function hud_noto_show_icon(icon_h, status) 
  1130. 	 
  1131. 	--debug_print("vint", "hud_noto_show_icon: " .. icon_h .. "\n") 
  1132. 	 
  1133. 	vint_set_property(icon_h, "visible", true) 
  1134.  
  1135. 	--Destroy all objects if there are any currently being animated 
  1136. 	vint_object_destroy(status.bmp_clone_0) 
  1137. 	vint_object_destroy(status.bmp_clone_1) 
  1138. 	vint_object_destroy(status.anim_0) 
  1139. 	vint_object_destroy(status.anim_1) 
  1140. 	vint_object_destroy(status.anim_2) 
  1141. 	vint_object_destroy(status.anim_3) 
  1142.  
  1143. 	--Create bitmap clones for animation 
  1144. 	local bmp_clone_0 = vint_object_clone(icon_h) 
  1145. 	local bmp_clone_1 = vint_object_clone(icon_h) 
  1146. 	vint_set_property(bmp_clone_0, "depth",	-1) 
  1147. 	vint_set_property(bmp_clone_1, "depth",	-2) 
  1148.  
  1149. 	--Clone the notoriety anim and adjust the childs targets 
  1150.  
  1151. 	--ANIMATION: Large to small 
  1152. 	local anim_0 = vint_object_find("noto_anim_0") 
  1153. 	local anim_clone_0 = vint_object_clone(anim_0) 
  1154.  
  1155. 	--Target Tweens 
  1156. 	local anim_0_alpha_tween = vint_object_find("noto_alpha_0", anim_clone_0) 
  1157. 	local anim_0_scale_tween = vint_object_find("noto_scale_0", anim_clone_0) 
  1158. 	vint_set_property(anim_0_alpha_tween, "target_handle",	bmp_clone_0) 
  1159. 	vint_set_property(anim_0_scale_tween, "target_handle",	bmp_clone_0) 
  1160. 	 
  1161. 	--ANIMATION: Small To Large 
  1162. 	local anim_1 = vint_object_find("noto_anim_1"); 
  1163. 	local anim_clone_1 = vint_object_clone(anim_1) 
  1164.  
  1165. 	--Target Tweens 
  1166. 	local anim_1_alpha_tween = vint_object_find("noto_alpha_1", anim_clone_1) 
  1167. 	local anim_1_scale_tween = vint_object_find("noto_scale_1", anim_clone_1) 
  1168. 	vint_set_property(anim_1_alpha_tween, "target_handle",	bmp_clone_1) 
  1169. 	vint_set_property(anim_1_scale_tween, "target_handle",	bmp_clone_1) 
  1170. 	 
  1171. 	--ANIMATION: BASIC FADE IN 
  1172. 	local anim_2 = vint_object_find("noto_anim_2") 
  1173. 	local anim_clone_2 = vint_object_clone(anim_2) 
  1174. 	 
  1175. 	--Target Tweens 
  1176. 	local anim_2_alpha_tween = vint_object_find("noto_alpha_2", anim_clone_2) 
  1177. 	vint_set_property(anim_2_alpha_tween, "target_handle",	icon_h) 
  1178. 	 
  1179. 	--Reset Properties to current value 
  1180. 	local alpha_val = vint_get_property(icon_h, "alpha") 
  1181. 	vint_set_property_typed("float", anim_2_alpha_tween, "start_value", alpha_val) 
  1182.  
  1183. 	--Setup callback 
  1184. 	vint_set_property(anim_0_scale_tween, "end_event",		"hud_noto_icon_show_end") 
  1185. 	 
  1186. 	--play anims 
  1187. 	lua_play_anim(anim_clone_0, 0); 
  1188. 	lua_play_anim(anim_clone_1, 0); 
  1189. 	lua_play_anim(anim_clone_2, 0); 
  1190.  
  1191. 	status.bmp_clone_0 = bmp_clone_0 
  1192. 	status.bmp_clone_1 = bmp_clone_1 
  1193. 	status.anim_0 = anim_clone_0 
  1194. 	status.anim_1 = anim_clone_1 
  1195. 	status.anim_2 = anim_clone_2 
  1196. 	status.anim_3 = 0 
  1197. 	status.tween_end = anim_0_scale_tween 
  1198.  
  1199. end 
  1200.  
  1201. function hud_noto_icon_show_end(tween_h, event_name) 
  1202. 	-- search for indicated tween and clean up 
  1203. 	for k, v in Hud_noto_data do 
  1204. 		for key, value in v.icons do 
  1205. 			if value.tween_end == tween_h then 
  1206.  
  1207. 				vint_object_destroy(value.bmp_clone_0) 
  1208. 				vint_object_destroy(value.bmp_clone_1) 
  1209. 				vint_object_destroy(value.anim_0) 
  1210. 				vint_object_destroy(value.anim_1) 
  1211. 				vint_object_destroy(value.anim_2) 
  1212.  
  1213. 				value.bmp_clone_0 = 0 
  1214. 				value.bmp_clone_1 = 0 
  1215. 				value.anim_0 = 0 
  1216. 				value.anim_1 = 0 
  1217. 				value.anim_2 = 0 
  1218. 				value.tween_show = 0 
  1219.  
  1220. 				return 
  1221. 			end 
  1222. 		end 
  1223. 	end 
  1224. end 
  1225.  
  1226. function hud_player_status_inf_change(di_h, event_name) 
  1227. 	 
  1228. 	local cash, max_followers, inventory_disabled, vehicle_logo, radio_station, cruise_control_active	= vint_dataitem_get(di_h) 
  1229. 	 
  1230. 	if inventory_disabled ~= Hud_player_status.inventory_disabled then 
  1231. 		if inventory_disabled == true and Hud_inventory.is_pressed == true then 
  1232. 			hud_inventory_hide() 
  1233. 		else 
  1234. 			if Hud_inventory.is_pressed == true then 
  1235. 				--button is pressed so open up the menu 
  1236. 				hud_inventory_show() 
  1237. 			end 
  1238. 		end 
  1239. 		Hud_player_status.inventory_disabled = inventory_disabled 
  1240. 	end	 
  1241. 	 
  1242. 	--Update cash (this gets read through hud_process() so it counts up nicely) 
  1243. 	Hud_player_status.cash = floor(cash) 
  1244. 	 
  1245. 	if vehicle_logo == nil then 
  1246. 		vehicle_logo = 0 
  1247. 	end 
  1248. 	 
  1249. 	if radio_station == nil then 
  1250. 		radio_station = 0 
  1251. 	end 
  1252. 	 
  1253. 	-- Display a new vehicle logo 
  1254. 	if Hud_current_veh_logo ~= vehicle_logo then 
  1255. 		if vehicle_logo == "__unloaded" or vehicle_logo == 0 then 
  1256. 			local o = vint_object_find("vehicle_logo") 
  1257. 			vint_set_property(o, "visible", false) 
  1258. 		else 
  1259. 			local o = vint_object_find("vehicle_logo") 
  1260. 			vint_set_property(o, "image", vehicle_logo) 
  1261. 			lua_play_anim(vint_object_find("vehicle_logo_anim_1"), 0) 
  1262. 			vint_set_property(o, "visible", true) 
  1263. 			 
  1264. 			-- Make sure radio station displays again any time we get into a new car, even if it uses the same station you had 
  1265. 			Hud_current_radio_station = -1 
  1266. 		end 
  1267. 	end 
  1268. 		 
  1269. 	-- Display a new radio station 
  1270. 	if Hud_current_radio_station ~= radio_station then 
  1271. 		if radio_station ~= 0 then 
  1272. 			vint_set_property(vint_object_find("radio_station"), "text_tag", radio_station) 
  1273. 			lua_play_anim(vint_object_find("radio_station_anim_1")) 
  1274. 		end 
  1275. 	end 
  1276. 	 
  1277. 	Hud_current_radio_station = radio_station 
  1278. 	Hud_current_veh_logo = vehicle_logo 
  1279. 	 
  1280. 	hud_cruise_control_update(cruise_control_active) 
  1281. end 
  1282.  
  1283. function hud_player_status_change(di_h, event_name) 
  1284.  
  1285. 	local sprint_enabled, health_pct, sprint_pct, is_sprinting, orientation	= vint_dataitem_get(di_h) 
  1286. 	 
  1287. 	--Health 
  1288. 	if health_pct ~= Hud_player_status.health_pct then 
  1289.  
  1290. 		local bar = Hud_player_status.health_bar 
  1291. 		local fill_end_angle = (bar.fill_end_angle - bar.fill_start_angle) * health_pct + bar.fill_start_angle  
  1292. 		local bg_end_angle = fill_end_angle + bar.angle_offset 
  1293. 		 
  1294. 		 
  1295. 		--if new health pct is less than current then do the animation of it dropping 
  1296. 		if health_pct < Hud_player_status.health_pct then 
  1297. 			 
  1298. 			--Decrease the health meter 
  1299. 			hud_player_health_decrease_anim(bar, fill_end_angle, bg_end_angle) 
  1300.  
  1301. 			if health_pct < .3 then 
  1302. 				--Full screen health effect gets even heavier if it drops below .3 
  1303. 				local vignette_alpha = .99 - health_pct 
  1304. 				hud_vignette_fade(vignette_alpha) 
  1305.  
  1306. 			elseif health_pct < .5 then 
  1307. 				--Full screen health effect if drops below .5 
  1308. 				local vignette_alpha = .75 - health_pct 
  1309. 				hud_vignette_fade(vignette_alpha) 
  1310. 			end 
  1311. 			Hud_player_status.health_recovering = false 
  1312. 		else 	 
  1313. 			--Increase the health meter 
  1314. 			hud_player_health_increase_anim(bar, fill_end_angle, bg_end_angle) 
  1315. 			 
  1316. 			if Hud_player_status.health_recovering == false then 
  1317. 				hud_vignette_fade(0) 
  1318. 				Hud_player_status.health_recovering = true 
  1319. 			end 
  1320. 		end 
  1321. 		 
  1322. 		--Hide bg of meter if sprint is empty. 
  1323. 		if health_pct == 0 then 
  1324. 			vint_set_property(bar.bg_h, "visible", false) 
  1325. 		else 
  1326. 			vint_set_property(bar.bg_h, "visible", true) 
  1327. 		end 
  1328.  
  1329. 		Hud_player_status.health_pct = health_pct 
  1330. 	end 
  1331.  
  1332. 	--Sprint 
  1333. 	if sprint_enabled == true and sprint_pct ~= Hud_player_status.sprint_pct then 
  1334. 		local bar = Hud_player_status.sprint_bar 
  1335. 		local fill_end_angle = (bar.fill_end_angle - bar.fill_start_angle) * sprint_pct + bar.fill_start_angle 
  1336. 		local bg_end_angle = fill_end_angle + bar.angle_offset 
  1337. 		 
  1338. 		--Update angles for the sprint meter 
  1339. 		vint_set_property(bar.bg_h, "end_angle", bg_end_angle) 
  1340. 		 
  1341. 		--Hide bg of meter if sprint is empty. 
  1342. 		if sprint_pct == 0 then 
  1343. 			vint_set_property(bar.bg_h, "visible", false) 
  1344. 		else 
  1345. 			vint_set_property(bar.bg_h, "visible", true) 
  1346. 		end 
  1347. 		 
  1348. 		vint_set_property(bar.fill_0_h, "end_angle", fill_end_angle) 
  1349. 		vint_set_property(bar.fill_1_h, "end_angle", fill_end_angle) 
  1350. 		Hud_player_status.sprint_pct = sprint_pct 
  1351. 	end 
  1352. 	 
  1353. 	if is_sprinting ~= Hud_player_status.is_sprinting then 
  1354. 		if is_sprinting == false then 
  1355. 		 
  1356. 			if Sprint_cool_down_thread ~= -1 then 
  1357. 				thread_kill(Sprint_cool_down_thread) 
  1358. 			end 
  1359.  
  1360. 			Sprint_cool_down_thread = thread_new("hud_player_sprint_cool_down") 
  1361. 		else  
  1362. 						 
  1363. 			--Lets kill the thread that resets everything 
  1364. 			if Sprint_cool_down_thread ~= -1 then 
  1365. 				thread_kill(Sprint_cool_down_thread) 
  1366. 			end 
  1367. 		 
  1368. 			--stop cooldown anim 
  1369. 			vint_set_property(vint_object_find("sprint_anim_1"), "is_paused", true) 
  1370. 			 
  1371. 			--If we aren't flashing then start flashing 
  1372. 			if Hud_player_status.sprint_bar.is_flashing == false then 
  1373. 				lua_play_anim(vint_object_find("sprint_anim_0"), 0) 
  1374. 				 
  1375. 				--Set flashing state to true 
  1376. 				Hud_player_status.sprint_bar.is_flashing = true 
  1377. 			end 
  1378. 			 
  1379. 		end 
  1380. 		 
  1381. 		Hud_player_status.is_sprinting = is_sprinting 
  1382. 	end 
  1383.  
  1384. 	-- not sure why we disable the sprint bar when we can just set it to zero but we live to serve 
  1385. 	if sprint_enabled ~= Hud_player_status.sprint_enabled then 
  1386. 		vint_set_property(Hud_player_status.sprint_bar.fill_0_h, "visible", sprint_enabled) 
  1387. 		vint_set_property(Hud_player_status.sprint_bar.fill_1_h, "visible", sprint_enabled) 
  1388. 		vint_set_property(Hud_player_status.sprint_bar.bg_h, "visible", sprint_enabled) 
  1389. 		Hud_player_status.sprint_enabled = sprint_enabled 
  1390. 	end 
  1391. 	 
  1392. 	if orientation ~= Hud_player_status.orientation then 
  1393. 		--Rotate Hit Indicators to player rotation 
  1394. 		orientation = 3.14 - orientation 
  1395. 		vint_set_property(Hud_hit_elements.main_h, "rotation", orientation) 
  1396. 		Hud_player_status.orientation = orientation 
  1397. 	end 
  1398. end 
  1399.  
  1400.  
  1401. function hud_player_sprint_cool_down() 
  1402. 	--Delay time to stop animation 
  1403. 	delay(.2) 
  1404. 	--If we haven't killed this thread by now we can 
  1405. 	 
  1406. 	--We stopped sprinting so lets stop the flashing 
  1407. 	local bar = Hud_player_status.sprint_bar 
  1408. 	 
  1409. 	--Pause Anim 
  1410. 	vint_set_property(vint_object_find("sprint_anim_0"), "is_paused", true) 
  1411. 	bar.is_flashing = false 
  1412.  
  1413. 	--play anim to cool down 
  1414. 	local color_0 = {[1] = -1, [2] = -1, [3] = -1} 
  1415. 	local color_1 = {[1] = -1, [2] = -1, [3] = -1} 
  1416. 	 
  1417. 	color_0[1], color_0[2], color_0[3] = vint_get_property(Hud_player_status.sprint_bar.fill_0_h, "tint") 
  1418. 	color_1[1], color_1[2], color_1[3] = vint_get_property(Hud_player_status.sprint_bar.fill_1_h, "tint") 
  1419.  
  1420. 	vint_set_property_typed("color", vint_object_find("sprint_flash_2_tween"), "start_value", color_0[1], color_0[2], color_0[3]) 
  1421. 	vint_set_property_typed("color", vint_object_find("sprint_flash_3_tween"), "start_value", color_1[1], color_1[2], color_1[3]) 
  1422. 	 
  1423. 	lua_play_anim(vint_object_find("sprint_anim_1"), 0) 
  1424. 	 
  1425. 	--Set flashing state to false 
  1426. 	Hud_player_status.sprint_bar.is_flashing = false 
  1427. 	 
  1428. 	--	Reset our  thread 
  1429. 	Sprint_cool_down_thread = -1 
  1430. end 
  1431.  
  1432.  
  1433. function hud_player_health_decrease_anim(bar, fill_end_angle, bg_end_angle) 
  1434.  
  1435. 	--Flash Health bar once 
  1436. 	local health_flash_anim = vint_object_find("health_anim_1") 
  1437. 	lua_play_anim(health_flash_anim, 0) 
  1438.  
  1439. 	--Setup Delay for animation 
  1440. 	if bar.anim ~= 0 then 
  1441. 		bar.anim_delay = bar.anim_delay -- * bar.anim_delay_decay 
  1442. 		if bar.anim_delay < 0 then 
  1443. 			 
  1444. 			bar.anim_delay = 0 
  1445. 		end 
  1446. 	else 
  1447. 	 
  1448. 		--Reset delay if we delayed the last animation finished 
  1449. 		bar.anim_delay = bar.anim_delay_start 
  1450. 	end 
  1451.  
  1452. 	--reset animation if its playing 
  1453. 	vint_object_destroy(bar.anim) 
  1454.  
  1455. 	--Pop beginning of second bar		 
  1456. 	local angle_original = vint_get_property(bar.fill_0_h, "end_angle") 
  1457. 	 
  1458. 	 
  1459. 	--Reset Bars 
  1460. 	vint_set_property(bar.fill_0_h, "end_angle", fill_end_angle) 
  1461. 	vint_set_property(bar.fill_1_h, "end_angle", fill_end_angle) 
  1462. 	vint_set_property(bar.fill_decay_h, "start_angle", fill_end_angle) 
  1463. 	 
  1464. 	---Play Animation 
  1465. 	local anim = vint_object_find("health_anim_0") 
  1466. 	local anim_clone = vint_object_clone(anim) 
  1467.  
  1468. 	local fill_tween = vint_object_find("health_fill_tween", anim_clone) 
  1469. 	vint_set_property_typed("float", fill_tween, "start_value", angle_original) 
  1470. 	vint_set_property_typed("float", fill_tween, "end_value", fill_end_angle) 
  1471.  
  1472. 	local bg_tween = vint_object_find("health_bg_tween", anim_clone) 
  1473. 	vint_set_property_typed("float", bg_tween, "start_value", angle_original + bar.angle_offset) 
  1474. 	vint_set_property_typed("float", bg_tween, "end_value", bg_end_angle ) 
  1475.  
  1476. 	--Callback 
  1477. 	vint_set_property(fill_tween, "end_event",	"hud_player_health_drop_anim_end") 
  1478. 	 
  1479. 	lua_play_anim(anim_clone, bar.anim_delay) 
  1480. 	 
  1481. 	--Reset delay if we are past our stop time 
  1482. 	if bar.anim_delay == 0 then 
  1483. 		bar.anim_delay = bar.anim_delay_start 
  1484. 	end 
  1485.  
  1486. 	--Store data for cleanup 
  1487. 	bar.anim = anim_clone 
  1488. end 
  1489.  
  1490. function hud_player_health_drop_anim_end(tween_h, event_name) 
  1491. 	 
  1492. 	--Destroy Animation 
  1493. 	local anim = Hud_player_status.health_bar.anim 
  1494. 	vint_object_destroy(anim) 
  1495. 	anim = 0 
  1496.  
  1497. end 
  1498.  
  1499. function hud_player_health_increase_anim(bar, fill_end_angle, bg_end_angle) 
  1500.  
  1501. 	--reset animation if its playing 
  1502. 	vint_object_destroy(bar.anim) 
  1503.  
  1504. 	--be sure to stop the flashing 
  1505. 	bar.is_flashing = false 
  1506. 	vint_set_property(bar.bg_h, "end_angle", bg_end_angle ) 
  1507. 	vint_set_property(bar.fill_0_h, "end_angle", fill_end_angle) 
  1508. 	vint_set_property(bar.fill_1_h, "end_angle", fill_end_angle) 
  1509. 	 
  1510. 	vint_set_property(bar.fill_decay_h, "start_angle", fill_end_angle) 
  1511.  
  1512. 	vint_set_property(bar.fill_decay_h, "end_angle", fill_end_angle) 
  1513.  
  1514. end 
  1515.  
  1516.  
  1517. --##################################################### 
  1518. --Weapon Changes 
  1519. --##################################################### 
  1520.  
  1521. function hud_player_weapon_change(di_h, event_name) 
  1522. --[[ 
  1523. --	            di->set_element(0, wpn_bmp_name);                                 // weapon image name 
  1524. --            di->set_element(1, ammo_ready);                                         // current ammo or < 0 if ammoless weapon 
  1525. --            di->set_element(2, ammo_reserve);                                 // ammo capacity 
  1526. --            di->set_element(3, wpn_ready);                                          // weapon ready 
  1527. --            di->set_element(4, dual_wield);                                         // secondary weapon 
  1528. --            di->set_element(5, ammoless_wpn);                                 // ammoless wpn 
  1529. --            di->set_element(6, ammo_infinite);                                // infinite ammo 
  1530. --            di->set_element(7, continuous_fire);                              // infinite ammo 
  1531. --            di->set_element(8, no_magazine);                                  // continuous fire (like water gun or flame thrower) 
  1532. --            di->set_element(9, pp->pflags.is_zoomed != 0);              // is the player vp zoomed (ala sniper rifle) 
  1533. --            di->set_element(10, cur_wpn_name);                                // name of weapon 
  1534. --           di->set_element(11, cur_wpn_category_name);                       // weapon category name 
  1535. --            di->set_element(12, reticle_highlight);                           // enemy / friendly / none  
  1536. --            di->set_element(13, cur_wpn_spread);                              // weapon spread 
  1537. 		 
  1538. ]]-- 
  1539. 	local wpn_bmp_name, rdy_ammo, rsv_ammo, wpn_rdy, dual_wield, no_ammo, inf_ammo, cont_fire, no_mag, sniper_visible, wpn_name, wpn_category, reticule_highlight, wpn_spread, wpn_slot, y_screen_coord  = vint_dataitem_get(di_h)	 
  1540. 	 
  1541. 	if wpn_bmp_name == nil then 
  1542. 		wpn_bmp_name = "ui_hud_inv_w_fist" 
  1543. 	end 
  1544.  
  1545. 	if dual_wield ~= Hud_weapon_status.dual_wield or wpn_bmp_name ~= Hud_weapon_status.wpn_icon_name then 
  1546. 		if dual_wield == true then 
  1547. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_1_h, "image", wpn_bmp_name) 
  1548. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_2_h, "image", wpn_bmp_name) 
  1549. 		else 
  1550. 			vint_set_property(Hud_weapon_status.single_wpn_icon_h, "image", wpn_bmp_name) 
  1551. 		end 
  1552. 		Hud_weapon_status.wpn_icon_name = wpn_bmp_name 
  1553. 	end 
  1554.  
  1555. 	if dual_wield ~= Hud_weapon_status.dual_wield then 
  1556. 		vint_set_property(Hud_weapon_status.dual_wpn_icon_1_h, "visible", dual_wield) 
  1557. 		vint_set_property(Hud_weapon_status.dual_wpn_icon_2_h, "visible", dual_wield) 
  1558. 		vint_set_property(Hud_weapon_status.single_wpn_icon_h, "visible", not dual_wield) 
  1559. 		Hud_weapon_status.dual_wield = dual_wield 
  1560. 	end 
  1561. 	 
  1562. 	--debug ammo 
  1563. 	--[[ 
  1564. 	debug_print("vint", "\nAmmo Update\n") 
  1565. 	debug_print("vint", "wpn_bmp_name: " .. wpn_bmp_name .. "\n") 
  1566. 	debug_print("vint", "rdy_ammo: " .. rdy_ammo .. "\n") 
  1567. 	debug_print("vint", "rsv_ammo: " .. rsv_ammo .. "\n") 
  1568. 	debug_print("vint", "dual_wield: " .. var_to_string(dual_wield) .. "\n") 
  1569. 	debug_print("vint", "no_ammo: " .. var_to_string(no_ammo) .. "\n") 
  1570. 	debug_print("vint", "inf_ammo: " .. var_to_string(inf_ammo) .. "\n") 
  1571. 	debug_print("vint", "cont_fire: " .. var_to_string(cont_fire) .. "\n") 
  1572. 	debug_print("vint", "no_mag:" .. var_to_string(no_mag) .. "\n") 
  1573. 	debug_print("vint", "sniper_visible: " .. var_to_string(sniper_visible) .. "\n") 
  1574. 	]] 
  1575. 	 
  1576. 	--Update Ammo Count 
  1577. 	local ammo_string = "" 
  1578. 	if no_ammo == false then 
  1579. 		if no_mag == true then 
  1580. 			if inf_ammo == false then 
  1581. 				if cont_fire == false then 
  1582. 					ammo_string = "" .. rdy_ammo + rsv_ammo 
  1583. 				else 
  1584. 					ammo_string = "" .. rdy_ammo + rsv_ammo 
  1585. 				--Jeff H isn't sure what this does, if this is a problem for some sort of weapon then we need to look at the cont fire 
  1586. 				--	ammo_string = "" .. floor((rdy_ammo + rsv_ammo) / 100) 
  1587. 				end 
  1588. 			else 
  1589. 				ammo_string = "[image:ui_hud_infinity]" 
  1590. 			end 
  1591. 		else 
  1592. 			if inf_ammo == false then 
  1593. 				if cont_fire == false then 
  1594. 					ammo_string = rdy_ammo .. "/" .. rsv_ammo 
  1595. 				else 
  1596. 					--debug_print("vint", "this should fire for grenade") 
  1597. 					ammo_string = floor(rdy_ammo / 100) .. "/" .. floor(rsv_ammo / 100) 
  1598. 				end 
  1599. 			else 
  1600. 				if cont_fire == false then 
  1601. 					ammo_string = rdy_ammo .. "/[image:ui_hud_infinity]" 
  1602. 				else 
  1603. 					ammo_string = floor(rdy_ammo / 100) .. "/[image:ui_hud_infinity]" 
  1604. 				end 
  1605. 			end 
  1606. 		end 
  1607. 	end 
  1608.  
  1609. 	vint_set_property(Hud_weapon_status.ammo_text_h, "text_tag", ammo_string) 
  1610.  
  1611. 	--Dim Weapon if not ready 
  1612. 	if wpn_rdy ~= Hud_weapon_status.wpn_rdy then 
  1613. 		if wpn_rdy == true then 
  1614. 			--Show Weapon 
  1615. 			vint_set_property(Hud_weapon_status.ammo_text_h, "alpha", 1) 
  1616. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_1_h, "alpha", 1) 
  1617. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_2_h, "alpha", 1) 
  1618. 			vint_set_property(Hud_weapon_status.single_wpn_icon_h, "alpha", 1) 
  1619. 			 
  1620. 			if Hud_weapon_status.sniper_visible == false then 
  1621. 				--Show reticule 
  1622. 				vint_set_property(Hud_reticules.elements.reticule_h, "visible", true) 
  1623. 			end 
  1624. 		else 
  1625. 			--Dim Weapon 
  1626. 			vint_set_property(Hud_weapon_status.ammo_text_h, "alpha", .5) 
  1627. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_1_h, "alpha", .5) 
  1628. 			vint_set_property(Hud_weapon_status.dual_wpn_icon_2_h, "alpha", .5) 
  1629. 			vint_set_property(Hud_weapon_status.single_wpn_icon_h, "alpha", .5) 
  1630. 			 
  1631. 			--Hide reticule 
  1632. 			vint_set_property(Hud_reticules.elements.reticule_h, "visible", false) 
  1633. 		end 
  1634. 	end 
  1635. 	 
  1636. 	--If sniper rifle is on then show the sniper rifle and not the standard reticule 
  1637. 	if sniper_visible ~= Hud_weapon_status.sniper_visible then 
  1638. 		if sniper_visible == true then 
  1639. 			vint_set_property(Hud_reticules.elements.sniper_h, "visible", true) 
  1640. 			vint_set_property(Hud_reticules.elements.reticule_h, "visible", false) 
  1641. 		else 
  1642. 			vint_set_property(Hud_reticules.elements.sniper_h, "visible", false) 
  1643. 			vint_set_property(Hud_reticules.elements.reticule_h, "visible", true) 
  1644. 		end 
  1645. 		 
  1646. 		Hud_weapon_status.sniper_visible = sniper_visible 
  1647. 	end	 
  1648.  
  1649. 	--Change reticules if we have a different weapon 
  1650. 	if wpn_name ~= Hud_reticules.status.wpn_name or reticule_highlight ~= Hud_reticules.status.highlight  then 
  1651. 		Hud_reticule_update(wpn_name, wpn_category, reticule_highlight) 
  1652. 	end 
  1653.  
  1654. 	--Do Weapon Spread 
  1655. 	if wpn_spread ~= Hud_reticules.status.wpn_spread then 
  1656. 		hud_reticule_spread_update(wpn_spread, Hud_reticules.configs[Hud_reticules.status.config].spread) 
  1657. 	end 
  1658. 	 
  1659. 	--Weapon slot changes need to update the radial menu 
  1660. 	if wpn_slot ~= Hud_radial_menu.slot_selected then 
  1661. 		Hud_radial_menu_change_select(wpn_slot) 
  1662. 		Hud_radial_menu.slot_equipped = wpn_slot 
  1663. 	end 
  1664. 	 
  1665. 	--Change y screen coord of reticule 
  1666. 	hud_reticule_change_position(y_screen_coord) 
  1667. 	 
  1668. end 
  1669.  
  1670.  
  1671. function hud_player_weapon_freq_change(di_h) 
  1672. 	local ammo_ready, reticle_highlight, cur_wpn_spread, fine_aim_transition, water_pressure = vint_dataitem_get(di_h) 
  1673. 	if fine_aim_transition ~= Hud_weapon_status.fine_aim_transition then 
  1674. 		hud_reticule_spread_update(cur_wpn_spread, Hud_reticules.configs[Hud_reticules.status.config].spread) 
  1675. 		if fine_aim_transition == nil then 
  1676. 			fine_aim_transition  = 0 
  1677. 		end 
  1678. 		Hud_weapon_status.fine_aim_transition = fine_aim_transition 
  1679. 	end 
  1680. 	 
  1681. 	--Update pressure 
  1682. 	hud_reticule_update_pressure(water_pressure) 
  1683. end 
  1684.  
  1685. function hud_player_respect_change(di_h) 
  1686. 	--[[ 
  1687. 		current_respect	= current respect 
  1688. 		respect_needed		= respect points needed (for each/next mission?) 
  1689. 		respect_total		= total respect earned 
  1690. 	]]-- 
  1691.  
  1692. 	local current_respect, respect_needed, respect_total = vint_dataitem_get(di_h) 
  1693. 	 
  1694. 	--Respect needed changed somehow, If this ever happens we need to update the visuals immediatly. 
  1695. 	if Hud_player_status.respect_needed ~= respect_needed then 
  1696. 		Hud_player_status.respect_needed = respect_needed 
  1697. 		--TODO: Connect this with the standard updates somehow 
  1698. 	end 
  1699. 	 
  1700. 	if current_respect ~= Hud_player_status.respect or Hud_player_status.respect_needed ~= respect_needed then 
  1701. 		 
  1702. 		--Calculate respect values for screen data 
  1703. 		local respect_int, respect_bar_percent 
  1704. 		if respect_needed > 0 then 
  1705. 			local respect_divide = current_respect / respect_needed 
  1706. 			respect_int = floor(respect_divide) 
  1707. 			respect_bar_percent = respect_divide - respect_int 
  1708. 		else 
  1709. 			respect_int = 99 
  1710. 			respect_bar_percent = 1 
  1711. 		end 
  1712. 		 
  1713. 		--Calculate target values for elemenet properties 
  1714. 		local bar = Hud_player_status.respect_bar 
  1715. 		local fill_start_angle = (bar.fill_start_angle - bar.fill_end_angle) * respect_bar_percent + bar.fill_end_angle 
  1716. 		local bg_start_angle = fill_start_angle - bar.angle_offset 
  1717. 		 
  1718. 		--Update angles for the respect meter 
  1719. 		vint_set_property(bar.bg_h, "start_angle", bg_start_angle) 
  1720. 		 
  1721. 		--Hide bg of meter if respect is empty. 
  1722. 		if respect_bar_percent == 0 then 
  1723. 			vint_set_property(bar.bg_h, "visible", false) 
  1724. 		else 
  1725. 			vint_set_property(bar.bg_h, "visible", true) 
  1726. 		end 
  1727. 		 
  1728. 		vint_set_property(bar.fill_0_h, "start_angle", fill_start_angle) 
  1729. 		vint_set_property(bar.fill_1_h, "start_angle", fill_start_angle) 
  1730. 		 
  1731. 		if fill_start_angle < 0.1 then 
  1732. 			--Right Side Lock 
  1733. 			vint_set_property(bar.txt_grp, "rotation", 3.14 + .3 ) 
  1734. 			vint_set_property(bar.txt, "rotation", 3.14 - .3 ) 
  1735. 		elseif fill_start_angle > 2.9 then 
  1736. 			--Left Side Lock 
  1737. 			vint_set_property(bar.txt_grp, "rotation", 3.14 + 3.1 ) 
  1738. 			vint_set_property(bar.txt, "rotation", 3.14 - 3.1 ) 
  1739. 		else 
  1740. 			--Normal Update 
  1741. 			vint_set_property(bar.txt_grp, "rotation", 3.14 + fill_start_angle + .2) 
  1742. 			vint_set_property(bar.txt, "rotation", 3.14 - fill_start_angle - .2) 
  1743. 		end 
  1744. 	 
  1745. 		--Update Respect Level Text 
  1746. 		if MP_enabled == false then 
  1747. 			if respect_int == 99 then 
  1748. 				vint_set_property(bar.txt, "text_tag", "[scale:1][image:ui_hud_base_smcirc_infinite]") 
  1749. 			else  
  1750. 				vint_set_property(bar.txt, "text_tag", "x" .. respect_int) 
  1751. 			end 
  1752. 			 
  1753. 			--Hide the level text if we don't have any filled bars. 
  1754. 			if respect_int <= 0  then 
  1755. 				vint_set_property(bar.txt, "visible", false) 
  1756. 			else 
  1757. 				vint_set_property(bar.txt, "visible", true) 
  1758. 			end 
  1759. 			 
  1760. 		else 
  1761. --			debug_print("vint", "my respect level:" .. current_respect .. "\n") 
  1762. 			vint_set_property(bar.txt, "text_tag", " " .. current_respect) 
  1763. 			vint_set_property(bar.txt, "visible", true) 
  1764. 		end 
  1765.  
  1766. 	end 
  1767. 	 
  1768. end 
  1769.  
  1770. function hud_player_followers_change(di_h) 
  1771. 	local slot, head_img_name, hlth_pct, revive_time, slot_visible = vint_dataitem_get(di_h) 
  1772.  
  1773. 	--No slots other than 1 to 3 allowed. 
  1774. 	if slot < 1 or slot > 3 then 
  1775. 		return 
  1776. 	end 
  1777. 	 
  1778. 	--Show or hide slot 
  1779. 	if slot_visible ~= Hud_followers.slot_objects[slot].visible then 
  1780. 		vint_set_property(Hud_followers.slot_objects[slot].group_h, "visible", slot_visible) 
  1781. 		Hud_followers.slot_objects[slot].visible = slot_visible 
  1782. 	end 
  1783. 	 
  1784. 	local data = Hud_followers.follower_data[slot] 
  1785. 	local objects = Hud_followers.slot_objects[slot] 
  1786. 	 
  1787. 	if head_img_name ~= data.head_img_name then 
  1788. 		if head_img_name == nil then 
  1789. 			--No homie head 
  1790. 			--hide the icon in the homie slot by playing the close animation 
  1791. 			vint_set_property(objects.anim_0, "is_paused", true) 
  1792. 			lua_play_anim(objects.anim_1, 0) 
  1793. 			 
  1794. 			--Be sure the timer is hidden too 
  1795. 			vint_set_property(objects.revive_timer_h, "visible", false) 
  1796. 		else 
  1797. 			if data.head_img_name == nil then 
  1798. 				vint_set_property(objects.anim_1, "is_paused", true) 
  1799. 				lua_play_anim(objects.anim_0, 0) 
  1800. 			end 
  1801. 			 
  1802. 			--Reset the head image  
  1803. 			vint_set_property(objects.head_img_h, "image", head_img_name) 
  1804. 			 
  1805. 			end 
  1806. 		data.head_img_name = head_img_name 
  1807. 	end 
  1808. 	 
  1809. 	--Update Health 
  1810. 	if hlth_pct ~= data.hlth_pct then 
  1811. 		local end_angle = 1.63 + (1.57 * hlth_pct) 
  1812. 		vint_set_property(objects.health_img_fill_h, "end_angle", end_angle ) 
  1813. 		data.hlth_pct = hlth_pct 
  1814. 	end 
  1815.  
  1816. 	--Revives (This is the counter that shows up over the homie heads) 
  1817. 	revive_time = floor(revive_time) 
  1818. 	if revive_time ~= data.revive_time then 
  1819. 		if revive_time == 0 and data.revive_time ~= 0 then 
  1820. 			vint_set_property(objects.revive_timer_h, "visible", false) 
  1821. 			vint_set_property(vint_object_find("follow_rev_anim_0"),"is_paused", true) 
  1822. 		elseif revive_time ~= 0 and data.revive_time == 0 then 
  1823. 			vint_set_property(objects.revive_timer_h, "visible", true) 
  1824. 			vint_set_property(vint_object_find("follow_rev_anim_0"),"is_paused", false) 
  1825. 			vint_set_property(objects.health_img_fill_h, "end_angle", 1.57 ) 
  1826. 		end 
  1827.  
  1828. 		--Update Revive Time 
  1829. 		vint_set_property(objects.revive_timer_h, "text_tag", revive_time) 
  1830. 		data.revive_time = revive_time 
  1831. 	end 
  1832. end 
  1833.  
  1834. function hud_balance_meter_change(di_h) 
  1835.  
  1836. 	--	active		bool		is the meter active? 
  1837. 	--	position		float		-1 to 1 indicating the position on the meter	 
  1838. 	local active, position = vint_dataitem_get(di_h) 
  1839. 	local force_update = false 
  1840. --	debug_print("vint", "active: " .. var_to_string(active) .. "| position: " .. position .. "\n") 
  1841. 	 
  1842. 	--Update visibility 
  1843. 	if Hud_balance_status.active ~= active then 
  1844. 		if active == true then 
  1845. 			vint_set_property(Hud_balance_status.balance_grp_h, "visible", true) 
  1846. 		else 
  1847. 			vint_set_property(Hud_balance_status.balance_grp_h, "visible", false) 
  1848. 		end 
  1849. 		force_update = true 
  1850. 		Hud_balance_status.active = active 
  1851. 	end 
  1852. 	 
  1853. 	--Update Position and Color 
  1854. 	if Hud_balance_status.position ~= position or force_update == true then 
  1855. 		 
  1856. 		--Calculate Angle 
  1857. 		local angle = position * Hud_balance_status.max_angle 
  1858. 		 
  1859. 		--Calculate Color 
  1860. 		local color_r, color_g, color_b 
  1861. 		local p_val = 0  
  1862. 		if position < 0 then  
  1863. 			p_val = position * -1 
  1864. 		else  
  1865. 			p_val = position 
  1866. 		end 
  1867. 		 
  1868. 		color_r = Hud_balance_status.color_base[1] - p_val * (Hud_balance_status.color_base[1] - Hud_balance_status.color_alarm[1]) 
  1869. 		color_g = Hud_balance_status.color_base[2] - p_val * (Hud_balance_status.color_base[2] - Hud_balance_status.color_alarm[2]) 
  1870. 		color_b = Hud_balance_status.color_base[3] - p_val * (Hud_balance_status.color_base[3] - Hud_balance_status.color_alarm[3]) 
  1871. 			 
  1872. 		--Set Props 
  1873. 		vint_set_property(Hud_balance_status.arrow_image_h, "rotation", angle) 
  1874. 		vint_set_property(Hud_balance_status.base_grp_h, "tint", color_r, color_g, color_b) 
  1875. 		 
  1876. 		Hud_balance_status.position = position  
  1877. 	end 
  1878. end 
  1879.  
  1880. --Health Vignette 
  1881. function hud_vignette_fade(target_alpha) 
  1882. 	local current_alpha = vint_get_property(Hud_vignettes.health.grp_h, "alpha") 
  1883. 	vint_set_property(Hud_vignettes.health.fade_twn_h, "start_value", current_alpha) 
  1884. 	vint_set_property(Hud_vignettes.health.fade_twn_h, "end_value", target_alpha) 
  1885. 	lua_play_anim(Hud_vignettes.health.fade_anim_h, 0) 
  1886. end 
  1887.  
  1888.  
  1889. --======================================================== 
  1890. --HUD Hits 
  1891. --Things around the reticule 
  1892. --======================================================== 
  1893. function Hud_hit_add(di_h) 
  1894. 	local hit_index = di_h 
  1895. 	local direction, strength = vint_dataitem_get(di_h) 
  1896. 	local hit_bmp_h, hit_anim_h, hit_twn_h, fade_time, stick_time 
  1897.  
  1898. 	--Check if major/minor hit 
  1899. 	if strength > .3 then 
  1900. 		hit_bmp_h = vint_object_clone(Hud_hit_elements.major_h) 
  1901. 		stick_time = .5 
  1902. 		fade_time = .5 
  1903. 	else 
  1904. 		hit_bmp_h = vint_object_clone(Hud_hit_elements.minor_h) 
  1905. 		stick_time = .25 
  1906. 		fade_time = .25 
  1907. 	end 
  1908. 	 
  1909. 	vint_set_property(hit_bmp_h, "visible", true) 
  1910. 	vint_set_property(hit_bmp_h, "rotation", direction) 
  1911. 	 
  1912. 	--Tween Fade out, Set Callback 
  1913. 	hit_anim_h = vint_object_clone(Hud_hit_elements.anim_h)	 
  1914. 	hit_twn_h =  vint_object_find("hit_twn", hit_anim_h) 
  1915. 	vint_set_property(hit_twn_h, "target_handle", hit_bmp_h) 
  1916. 	vint_set_property(hit_twn_h, "duration", fade_time) 
  1917. 	vint_set_property(hit_twn_h, "end_event", "hud_hit_fade_end") 
  1918. 	 
  1919. 	lua_play_anim(hit_anim_h, stick_time) 
  1920. 	 
  1921. 	--Store Reticule Information for further processing 
  1922. 	Reticule_hits[hit_index] = { 
  1923. 		hit_bmp_h = hit_bmp_h, 
  1924. 		hit_twn_h = hit_twn_h, 
  1925. 		hit_anim_h = hit_anim_h, 
  1926. 		direction = direction, 
  1927. 		strength = strength, 
  1928. 	} 
  1929. end 
  1930.  
  1931. function hud_hit_fade_end(twn_h, event_name) 
  1932. 	--Clean up reticule hits 
  1933. 	for index, value in Reticule_hits do 
  1934. 		if value.hit_twn_h == twn_h then 
  1935. 			vint_object_destroy(value.hit_anim_h) 
  1936. 			vint_object_destroy(value.hit_twn_h) 
  1937. 			vint_object_destroy(value.hit_bmp_h) 
  1938. 			Reticule_hits[index] = nil 
  1939. 		end 
  1940. 	end 
  1941. end 
  1942.  
  1943. function hud_hits_updates_pos(y_screen_coord) 
  1944. 	--y screen coordinate 
  1945. 	local x, y = vint_get_property(Hud_hit_elements.main_h, "anchor") 
  1946. 	vint_set_property(Hud_hit_elements.main_h, "anchor", x, y_screen_coord) 
  1947. end 
  1948.  
  1949. --Clears all indicators if called, designed to be called via C++ 
  1950. function hud_hit_clear_all() 
  1951. 	for index, value in Reticule_hits do 
  1952. 		vint_object_destroy(value.hit_anim_h) 
  1953. 		vint_object_destroy(value.hit_twn_h) 
  1954. 		vint_object_destroy(value.hit_bmp_h) 
  1955. 	end 
  1956. 	Reticule_hits = {} 
  1957. end 
  1958.  
  1959. --#####################################################################  
  1960. --Radial Menu  
  1961. --##################################################################### 
  1962. function hud_radial_menu_update(di_h) 
  1963. 	--[[ 
  1964. 		slot_num:		Slot number of item 
  1965. 		availability:	Is the item available and can it be equipped? 
  1966. 		item_name_crc:	crc for the item name (if nil then the item is empty 
  1967. 		bmp_name:		bitmap representing the item 
  1968. 		ammo_cur:		current ammo for the item (Weapons Only) 
  1969. 		ammo_max:		max ammo for the item (Weapons Only) 
  1970. 		dual_wield:		bool (Weapons Only) 
  1971. 		ammo_infinite:	bool (Weapons Only) 
  1972. 	]] 
  1973. 	local slot_num, availability, item_name_crc, bmp_name, ammo_cur, ammo_max, dual_wield, ammo_infinite, is_current_wpn  = vint_dataitem_get(di_h)  
  1974. 	local slot = Hud_radial_menu.slots[slot_num] 
  1975. 	if slot_num < 8 and slot_num > -1 then 
  1976. 		--Weapon Slot 
  1977. 		--New weapon 
  1978. 		if item_name_crc ~= slot.item_name_crc or dual_wield ~= slot.dual_wield then 
  1979. 			--if bitmap is null slot is empty 
  1980. 			local item_element_h = -1 
  1981. 			--Clear out old slot icon 
  1982. 			if slot.item_element_h ~= -1 then 
  1983. 				vint_object_destroy(slot.item_element_h) 
  1984. 			end 
  1985. 			 
  1986. 			--If slot Zero bitmap name is nil then use the fist 
  1987. 			if slot_num == 0 and bmp_name == nil then 
  1988. 				bmp_name = "ui_hud_inv_w_fist" 
  1989. 			end 
  1990. 			 
  1991. 			if bmp_name == nil then 
  1992. 				--Hide the other elements 
  1993. 				vint_set_property(slot.infinite_h, "visible", false) 
  1994. 				vint_set_property(slot.ammo_bar_fill_h, "visible", false) 
  1995. 				vint_set_property(slot.ammo_bar_bg_h , "visible", false) 
  1996. 			else 
  1997. 				--Check if Dual wielding for formating differences 
  1998. 				if dual_wield == true then	 
  1999. 					item_element_h = vint_object_clone(vint_object_find("inv_dual_wield_tmp", Hud_radial_menu.radial_grp_h), slot.grp_h) 
  2000. 					local item1_h = vint_object_find("inv_icon_0", item_element_h) 
  2001. 					local item2_h = vint_object_find("inv_icon_1", item_element_h) 
  2002. 					vint_set_property(item1_h,"image", bmp_name) 
  2003. 					vint_set_property(item2_h,"image", bmp_name) 
  2004. 				else 
  2005. 					local inv_h = vint_object_find("inv_icon_tmp") 
  2006. 					item_element_h = vint_object_clone(inv_h, slot.grp_h) 
  2007. 					vint_set_property(item_element_h,"image", bmp_name) 
  2008. 				end 
  2009. 				--Reposition/scale weapon icon 
  2010. 				vint_set_property(item_element_h, "visible", true) 
  2011. 				vint_set_property(item_element_h, "anchor", 0,0) 
  2012. 				vint_set_property(item_element_h, "scale", .75,.75)	 
  2013. 			end 
  2014. 			 
  2015. 			if bmp_name == "ui_hud_inv_w_ar50grenade" or bmp_name == "ui_hud_inv_w_minigun" or bmp_name == "ui_hud_inv_w_flamethrower" then 
  2016. 				vint_set_property(item_element_h, "depth", -250) 
  2017. 			end 
  2018.  
  2019. 			slot.bmp_name = bmp_name 
  2020. 			slot.item_element_h = item_element_h 
  2021. 			slot.item_name_crc = item_name_crc  
  2022. 		end 
  2023.  
  2024.  
  2025. 		 
  2026. 		--[[ 
  2027. 		debug_print("vint", "------------------------------------\n") 
  2028. 		debug_print("vint", "Hud_radial_menu.slot_selected: " .. var_to_string(Hud_radial_menu.slot_selected) .. "\n") 
  2029. 		debug_print("vint", "slot_num: " .. var_to_string(slot_num) .. "\n") 
  2030. 		debug_print("vint", "availability: " .. var_to_string(availability) .. "\n") 
  2031. 		 
  2032. 		 
  2033. 		debug_print("vint", "Hud_radial_menu.slot_selected: " .. var_to_string(Hud_radial_menu.slot_selected) .. "\n") 
  2034. 		debug_print("vint", "slot_num: " .. var_to_string(slot_num) .. "\n") 
  2035. 		debug_print("vint", "availability: " .. var_to_string(availability) .. "\n") 
  2036. 		debug_print("vint", "------------------------------------\n\n") 
  2037. 		]] 
  2038. 		 
  2039. 		--Weapon Availability 
  2040. 	--	if availability ~= slot.availability then 
  2041. 		if slot.item_element_h ~= -1 then 
  2042. 			if availability == true then 
  2043. 				vint_set_property(slot.item_element_h, "tint", 1, 1, 1) 
  2044. 			else 
  2045. 				vint_set_property(slot.item_element_h, "tint", .25, .25, .25) 
  2046. 			end 
  2047. 		end 
  2048. 		slot.availability = availability 
  2049. --		end 
  2050. 		 
  2051. 		if is_current_wpn == true then 
  2052. 			Hud_radial_menu.slot_equipped = slot_num 
  2053. 		end	 
  2054. 		 
  2055. 		if Hud_radial_menu.slot_selected == slot_num and availability == true then 
  2056. 			hud_radial_menu_text_update(slot_num) 
  2057. 		end 
  2058. 		 
  2059. 		 
  2060. 		--Weapon Ammo 
  2061. 		if ammo_cur ~= slot.ammo_cur or ammo_max ~= slot.ammo_max or ammo_infinite ~= slot.ammo_infinite then 
  2062. 			if ammo_max == 0 then 
  2063. 				--No ammo clip, don't render ammo bar or infinity symbol 
  2064. 				vint_set_property(slot.infinite_h, "visible", false) 
  2065. 				vint_set_property(slot.ammo_bar_fill_h, "visible", false) 
  2066. 				vint_set_property(slot.ammo_bar_bg_h , "visible", false) 
  2067. 			else 
  2068. 				--Ammo Bar Fill 
  2069. 				local ammo_percent = ammo_cur/ammo_max 
  2070. 				local angle = Hud_radial_menu.ammo_angle_empty + (Hud_radial_menu.ammo_angle_full - Hud_radial_menu.ammo_angle_empty) * ammo_percent 
  2071. 				vint_set_property(slot.ammo_bar_fill_h, "start_angle", angle) 
  2072. 				 
  2073. 				--debug_print("vint", "slot: " .. slot_num .. " | bmp_name: " .. var_to_string(bmp_name) .. " | ammo_cur: " .. ammo_cur .. " | ammo_max: " .. ammo_max .. " | percent: " .. ammo_percent .. "\n") 
  2074. 						 
  2075. 				--Infinity Symbol or Ammo bar? 
  2076. 				if ammo_infinite == true then 
  2077. 					vint_set_property(slot.infinite_h, "visible", true) 
  2078. 					vint_set_property(slot.ammo_bar_fill_h, "visible", false) 
  2079. 					vint_set_property(slot.ammo_bar_bg_h , "visible", false) 
  2080. 				else	 
  2081. 					vint_set_property(slot.infinite_h, "visible", false) 
  2082. 					vint_set_property(slot.ammo_bar_fill_h, "visible", true) 
  2083. 					vint_set_property(slot.ammo_bar_bg_h , "visible", true) 
  2084. 				end	 
  2085. 			end	 
  2086. 			slot.ammo_cur = ammo_cur 
  2087. 			slot.ammo_max = ammo_max 
  2088. 			slot.ammo_infinite = ammo_infinite 
  2089. 		end 
  2090. 	 
  2091. 	elseif slot_num > 7 then 
  2092. 		--Food Slot 
  2093. 		local item_element_h = slot.item_element_h 
  2094. 		if item_name_crc ~= slot.item_name_crc then 
  2095. 			if bmp_name == nil then 
  2096. 				vint_set_property(item_element_h, "visible", false) 
  2097. 			else  
  2098. 				vint_set_property(item_element_h, "visible", true) 
  2099. 				vint_set_property(item_element_h, "image", bmp_name) 
  2100. 			end 
  2101. 			slot.bmp_name = bmp_name 
  2102. 			slot.item_name_crc = item_name_crc  
  2103. 		end 
  2104. 		--Is the food item available? 
  2105. 		if availability ~= slot.availability then 
  2106. 			if availability == true then 
  2107. 				vint_set_property(slot.item_element_h, "tint", 1, 1, 1) 
  2108. 			else 
  2109. 				vint_set_property(slot.item_element_h, "tint", .25, .25, .25) 
  2110. 			end 
  2111. 			slot.availability = availability 
  2112. 		end 
  2113. 	end 
  2114. end 
  2115.  
  2116. function Hud_radial_menu_change_select(slot_num, is_liquor_store) 
  2117. 	local selector_h = Hud_radial_menu.selector_h 
  2118. 	 
  2119. 	if slot_num > 7 and is_liquor_store ~= true then 
  2120. 		if Hud_radial_menu.slots[slot_num].item_name_crc == 0 then 
  2121. 			--Food slot is empty so exit early and do not highlight anything. 
  2122. 			return 
  2123. 		elseif Hud_radial_menu.slots[slot_num].availability == false then 
  2124. 			--Food slot is unavailable so do not highlight it. 
  2125. 			return 
  2126. 		end 
  2127. 	end 
  2128.  
  2129. 	local selector_x, selector_y = vint_get_property(Hud_radial_menu.slots[slot_num].grp_h,"anchor") 
  2130. 	vint_set_property(selector_h, "anchor", selector_x, selector_y) 
  2131. 	 
  2132. 	hud_radial_menu_slot_scales_reset() 
  2133. 	 
  2134. 	--Then make groups bigger based on his current selection 
  2135. 	if slot_num ~= nil then 
  2136. 		if slot_num < 8 then 
  2137. 			vint_set_property(Hud_radial_menu.slots[slot_num].grp_h, "scale", 1.2, 1.2) 
  2138. 			vint_set_property(selector_h, "scale", 1.2, 1.2) 
  2139. 		else 
  2140. 			vint_set_property(Hud_radial_menu.slots[slot_num].grp_h, "scale", 1, 1) 
  2141. 			vint_set_property(selector_h, "scale", .9, .9) 
  2142. 		end 
  2143. 	end	 
  2144. 	 
  2145. 	if is_liquor_store == true then 
  2146. 		return 
  2147. 	end 
  2148. 	 
  2149. 	--Move/Rotate dpad highlight if food 
  2150. 	if slot_num > 7 then 
  2151. 		if slot_num == 8 then 
  2152. 			--Up 
  2153. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "anchor", -64, -67) 
  2154. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "rotation", 0) 
  2155. 		elseif slot_num == 9 then 
  2156. 			--Right 
  2157. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "anchor", -59, -61) 
  2158. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "rotation", 1.571) 
  2159. 		elseif slot_num == 10 then 
  2160. 			--Down 
  2161. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "anchor", -65, -54) 
  2162. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "rotation", 3.142) 
  2163. 		elseif slot_num == 11 then 
  2164. 			--Left 
  2165. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "anchor", -69, -61) 
  2166. 			vint_set_property(Hud_radial_menu.dpad_highlight_h, "rotation", 4.712) 
  2167. 		end 
  2168. 		lua_play_anim(Hud_radial_menu.dpad_highlight_anim_h, 0) 
  2169. 	end 
  2170. 	 
  2171. 	hud_radial_menu_text_update(slot_num) 
  2172. 	 
  2173. 	if slot_num ~= Hud_radial_menu.slot_selected then 
  2174. 		local radial_is_visible = vint_get_property(Hud_radial_menu.radial_grp_h, "visible") 
  2175. 		 
  2176. 		if radial_is_visible then 
  2177. 			audio_play(Hud_sounds.radial_select) 
  2178. 		end 
  2179. 		 
  2180. 		Hud_radial_menu.slot_selected = slot_num 
  2181. 	end 
  2182. end 
  2183.  
  2184.  
  2185. function hud_radial_menu_text_update(slot_num) 
  2186. 	--Update text on radial menu	 
  2187. 	local item_name_crc = Hud_radial_menu.slots[slot_num].item_name_crc 
  2188. 	local item_availability = Hud_radial_menu.slots[slot_num].availability 
  2189. 	 
  2190. 	--Set property of center bg 
  2191. 	if item_name_crc == 0 then  
  2192. 		vint_set_property(Hud_radial_menu.slot_desc_h, "visible", false) 
  2193. 	else 
  2194. 		vint_set_property(Hud_radial_menu.slot_desc_h, "text_tag_crc", item_name_crc) 
  2195. 		vint_set_property(Hud_radial_menu.slot_desc_h, "visible", true) 
  2196. 		 
  2197. 		if item_availability == false then 
  2198. 			vint_set_property(Hud_radial_menu.slot_desc_h, "alpha", .5) 
  2199. 			vint_set_property(Hud_radial_menu.slot_desc_h, "tint", .1,.1,.1) 
  2200. 			vint_set_property(Hud_radial_menu.slot_desc_h, "font", "thin") 
  2201. 		else 
  2202. 			vint_set_property(Hud_radial_menu.slot_desc_h, "alpha", 1) 
  2203. 			vint_set_property(Hud_radial_menu.slot_desc_h, "tint", 1,1,1) 
  2204. 			vint_set_property(Hud_radial_menu.slot_desc_h, "font", "thin_overlay") 
  2205. 		end 
  2206. 	end 
  2207. end 
  2208.  
  2209. function hud_radial_menu_slot_scales_reset() 
  2210. 	--Resets all the scales for all slots 
  2211. 	for i = 0, 7 do 
  2212. 		vint_set_property(Hud_radial_menu.slots[i].grp_h, "scale", 1, 1) 
  2213. 	end 
  2214. 	for i = 8, 11 do 
  2215. 		vint_set_property(Hud_radial_menu.slots[i].grp_h, "scale", .8, .8) 
  2216. 	end 
  2217. end 
  2218.  
  2219. --#####################################################################  
  2220. --Showing/Hiding the hud 
  2221. --##################################################################### 
  2222.  
  2223. Hud_element_groups = { 
  2224. 	["HEALTH"] = { 
  2225. 		[0] = "health_grp" 
  2226. 	}, 
  2227. 	["MAP"] = { 
  2228. 		[0] = "map_grp" 
  2229. 	}, 
  2230. 	["CASH"] = { 
  2231. 		[0] = "cash" 
  2232. 	}, 
  2233. 	["FOLLOWERS"] = { 
  2234. 		[0] = "followers" 
  2235. 	}, 
  2236. 	["GSI"] = { 
  2237. 		[0] = "gsi_base_grp" 
  2238. 	}, 
  2239. 	["RETICULE"] = { 
  2240. 		[0] = "hits", 
  2241. 		[1] = "reticules", 
  2242. 		[2] = "sniper", 
  2243. 	}, 
  2244. 	["RADIAL"] = { 
  2245. 		[0] = "radial_grp" 
  2246. 	}, 
  2247. 	["MISC"] = { 
  2248. 		[0] = "balance_meter", 
  2249. 		[1] = "mayhem_grp", 
  2250. 		[2] = "combo_grp", 
  2251. 		[3] = "vignettes" 
  2252. 	}, 
  2253. 	["DEMODERBY"] = { 
  2254. 		[0] = "coop_grp", 
  2255. 		[1] = "health_grp", 
  2256. 	}, 
  2257. 	["MESSAGES"] = { 
  2258. 		[0] = "msg_debug_anchor", 
  2259. 		[1] = "msg_diversion_anchor", 
  2260. 		[2] = "msg_help_anchor", 
  2261. 		[3] = "msg_multi_action_anchor", 
  2262. 		[4] = "msg_multi_chat_anchor", 
  2263. 		[5] = "msg_multi_subtitle_anchor", 
  2264. 	}, 
  2265. 	["MP_HUD"] = { 
  2266. 		[0] = "perk_grp", 
  2267. 		[1] = "tagging_progress_grp", 
  2268. 		[2] = "voip_grp" 
  2269. 	} 
  2270. } 
  2271.  
  2272. Hud_elements = { 
  2273. 	[0] = "HEALTH", 
  2274. 	[1] = "MISC", 
  2275. 	[2] = "MAP", 
  2276. 	[3] = "CASH", 
  2277. 	[4] = "FOLLOWERS", 
  2278. 	[5] = "GSI", 
  2279. 	[6] = "RETICULE", 
  2280. 	[7] = "RADIAL", 
  2281. 	[8] = "DEMODERBY", 
  2282. 	[9] = "MESSAGES", 
  2283. 	[10] = "MP_HUD", 
  2284. 	 
  2285. } 
  2286.  
  2287. Hud_element_tweens = {} 
  2288.  
  2289. --Fades a particular element 
  2290. function hud_element_fade(element_id, fade, duration) 
  2291. 	if duration == nil then 
  2292. 		duration = -1 
  2293. 	end 
  2294. 	--fade: 0 = hidden,	1 = transparent, 2 = visible 
  2295. 	local element_group 
  2296. 	local target_document_name = -1 
  2297. 	local element_id_type = type(element_id) 
  2298. 	local grp_name 
  2299. 	if element_id_type == "number" then 
  2300. 		grp_name = Hud_elements[element_id] 
  2301. 		element_group = Hud_element_groups[Hud_elements[element_id]] 
  2302. 		 
  2303. 		if element_id == 8 then 
  2304. 			--Hack for demo derby 
  2305. 			target_document_name = "hud_demo_derby" 
  2306. 		elseif element_id == 9 then 
  2307. 			--Hack for hud messages 
  2308. 			target_document_name = "hud_msg" 
  2309. 		elseif element_id == 10 then 
  2310. 			--Hack for MP HUD 
  2311. 			target_document_name = "mp_hud" 
  2312. 		end 
  2313. 		 
  2314. 	elseif element_id_type == "string" then 
  2315. 		grp_name = element_id 
  2316.       element_group = Hud_element_groups[element_id] 
  2317. 		 
  2318. 		if element_id == "DEMODERBY" then 
  2319. 			--Hack for demo derby 
  2320. 			target_document_name = "hud_demo_derby" 
  2321. 		elseif element_id == "MESSAGES" then 
  2322. 			--Hack for hud messages 
  2323. 			target_document_name = "hud_msg" 
  2324. 		elseif element_id == "MP_HUD" then 
  2325. 			--Hack for MP HUD 
  2326. 			target_document_name = "mp_hud" 
  2327. 		end 
  2328. 	end 
  2329. 	 
  2330. 	--Set alpha based on fade 
  2331. 	local target_alpha 
  2332. 	if fade == 0 then 
  2333. 		target_alpha = 0 
  2334. 	elseif fade == 1 then 
  2335. 		target_alpha = .35 
  2336. 	else 
  2337. 		target_alpha = 1 
  2338. 	end 
  2339. 	 
  2340. 	local grp_h, current_alpha, twn_h 
  2341. 	 
  2342. 	--Figure out which document the elements exist in 
  2343. 	local target_doc_h = HUD_DOC_HANDLE 
  2344. 	if target_document_name ~= -1 then 
  2345. 		target_doc_h = vint_document_find(target_document_name) 
  2346. 		if target_doc_h == 0 then 
  2347. 			--This document is not loaded for whatever reason exit 
  2348. 			return 
  2349. 		end 
  2350. 	end 
  2351. 	 
  2352. 	if duration == -1 then 
  2353. 		duration = .25 
  2354. 	end 
  2355. 	 
  2356. 	local mp_enabled = mp_is_enabled() 
  2357. 		 
  2358. 	--Loop through the group and create tweens 
  2359. 	for idx, val in element_group do 
  2360. 		if mp_enabled == true and (val == "msg_diversion_anchor" or val == "msg_help_anchor") then 
  2361. 			--In MP Mode always show the Death kills and help text. 
  2362. 		else 
  2363. 			--get the group object to fade 
  2364. 			grp_h = vint_object_find(val, nil, target_doc_h) 
  2365. 			 
  2366. 			--Verify that we aren't already fading something 
  2367. 			for idx, val in Hud_element_tweens do 
  2368. 				if grp_h == val.grp_h then 
  2369. 					--tween exist so delete the tween 
  2370. 					vint_object_destroy(idx) 
  2371. 					Hud_element_tweens[idx] = nil 
  2372. 				end 
  2373. 			end 
  2374. 			 
  2375. 			--Get Current Alpha of object 
  2376. 			current_alpha = vint_get_property(grp_h, "alpha") 
  2377. 			 
  2378. 			local hud_root_animation =  vint_object_find("root_animation", nil, target_doc_h) 
  2379. 			 
  2380. 			--Create Tween and set values 
  2381. 			twn_h = vint_object_create("hud_fade_tweens", "tween", hud_root_animation, target_doc_h) 
  2382. 			 
  2383. 			vint_set_property(twn_h, "duration", duration)	--Fade time 
  2384. 			vint_set_property(twn_h, "target_handle", grp_h) 
  2385. 			vint_set_property(twn_h, "target_property", "alpha") 
  2386. 			vint_set_property(twn_h, "start_value", current_alpha) 
  2387. 			vint_set_property(twn_h, "end_value", target_alpha) 
  2388. 			vint_set_property(twn_h, "start_time",	vint_get_time_index(target_doc_h)) 
  2389. 			vint_set_property(twn_h, "is_paused", false) 
  2390. 			 
  2391. 			--Set callback 
  2392. 			vint_set_property(twn_h, "end_event", "hud_element_fade_end") 
  2393. 		 
  2394. 			--Store for cleanup 
  2395. 			Hud_element_tweens[twn_h] = { 
  2396. 				grp_h = grp_h 
  2397. 			} 
  2398. 		end 
  2399. 	end 
  2400. end 
  2401.  
  2402. --Fades all HUD Elements 
  2403. function hud_element_fade_all(fade, duration) 
  2404. 	if duration == nil then 
  2405. 		duration = -1 
  2406. 	end 
  2407. 	for idx, val in Hud_elements do 
  2408. 		hud_element_fade(val, fade, duration) 
  2409. 	end 
  2410. end 
  2411.  
  2412. function hud_element_fade_end(tween_h, event_name) 
  2413. 	--Delete all fade tweens and references 
  2414. 	vint_object_destroy(tween_h) 
  2415. 	Hud_element_tweens[tween_h] = nil 
  2416. end 
  2417.  
  2418. function hud_fade_out(duration) 
  2419. 	if duration == nil then 
  2420. 		duration = -1 
  2421. 	end 
  2422. 	hud_element_fade_all(0, duration) 
  2423. end 
  2424.  
  2425. function hud_fade_in(duration) 
  2426. 	if duration == nil then 
  2427. 		duration = -1 
  2428. 	end 
  2429. 	hud_element_fade_all(2, duration) 
  2430. end 
  2431.  
  2432. function hud_fade_half(duration) 
  2433. 	if duration == nil then 
  2434. 		duration = -1 
  2435. 	end 
  2436. 	hud_element_fade_all(1, duration) 
  2437. end 
  2438.  
  2439. ---------[ BUSTED/SMOKED ]--------- 
  2440.  
  2441. function hud_busted_init() 
  2442. 	Hud_smoked_busted.handles = {} 
  2443. 	 
  2444. 	Hud_smoked_busted.handles.grp = vint_object_find("smoked_busted") 
  2445. 	vint_set_property(Hud_smoked_busted.handles.grp, "visible", false) 
  2446. 	 
  2447. 	--Fade In animations 
  2448. 	Hud_smoked_busted.handles.fade_in_anim = vint_object_find("sb_fade_in") 
  2449. 	vint_set_property(Hud_smoked_busted.handles.fade_in_anim , "is_paused", true) 
  2450. end 
  2451.  
  2452. function hud_busted_complete() 
  2453. end 
  2454.  
  2455. function hud_busted_fade_in(smoked, delay, fade_time) 
  2456. 	local msg, effect, color 
  2457. 	if smoked == true then 
  2458. 		msg = "GAMEPLAY_SMOKED" 
  2459. 		effect = "smoked" 
  2460. 		color = {r = .9, g = .9, b = .9} 
  2461. 	else 
  2462. 		msg = "GAMEPLAY_BUSTED" 
  2463. 		effect = "busted" 
  2464. 		color = {r = .9, g = .9, b = .9} 
  2465. 	end 
  2466. 	 
  2467. 	--Show Smoked busted text 
  2468. 	vint_set_property(Hud_smoked_busted.handles.grp, "visible", true) 
  2469. 	vint_set_property(Hud_smoked_busted.handles.grp, "alpha", 0) 
  2470. 	vint_set_property(Hud_smoked_busted.handles.grp, "tint", color.r, color.g, color.b) 
  2471. 	 
  2472. 	-- Hide activity stuff 
  2473. 	local h = vint_object_find("collection_anim") 
  2474. 	h = vint_object_find("collection_msg_alpha_twn_2", h) 
  2475. 	vint_set_property(h, "start_value", 0) 
  2476. 	vint_set_property(vint_object_find("collection_msg"), "alpha", 0) 
  2477. 	 
  2478. 	--Fade out HUD 
  2479. 	hud_fade_out() 
  2480.  
  2481. 	--Busted/Smoked text fade in 
  2482. 	vint_set_property(vint_object_find("sb_text"), "text_tag", msg) 
  2483. 	lua_play_anim(Hud_smoked_busted.handles.fade_in_anim) 
  2484. 	 
  2485. 	--Start Interface effect 
  2486. 	interface_effect_begin(effect, 1, .5) 
  2487. end 
  2488.  
  2489. function hud_effect_smoked() 
  2490. 	interface_effect_begin("smoked", 1, 1) 
  2491. end 
  2492.  
  2493. function hud_effect_busted() 
  2494. 	interface_effect_begin("busted", 1, 1) 
  2495. end 
  2496.  
  2497. function hud_effect_pause() 
  2498. 	interface_effect_begin("pause", 1, 1) 
  2499. end 
  2500.  
  2501. function hud_effect_end() 
  2502. 	interface_effect_end() 
  2503. end 
  2504.  
  2505. function hud_player_reset_complete() 
  2506. 	--Reset the busted state 
  2507. 	interface_effect_end(0, false) 
  2508. 	--Hide Smoked busted text 
  2509. 	vint_set_property(Hud_smoked_busted.handles.grp, "visible", false) 
  2510. 	hud_fade_in() 
  2511. end 
  2512.  
  2513. ---------[ COLLECTION MESSAGES ]--------- 
  2514.  
  2515. Hud_collection_msgs = { num_msgs = 0 } 
  2516.  
  2517. -- you can also call this to clear any existing messages 
  2518. function hud_collection_msg_init() 
  2519. 	Hud_collection_msgs = { num_msgs = 0 } 
  2520. 	vint_set_property(vint_object_find("collection_msg"), "alpha", 0) 
  2521. 	vint_set_property(vint_object_find("collection_msg"), "visible", true) 
  2522. 	vint_set_property(vint_object_find("collection_anim"), "is_paused", true) 
  2523. 	vint_set_property(vint_object_find("collection_msg_alpha_twn_2"), "end_event", "hud_collection_msg_end") 
  2524. 	 
  2525. 	Hud_collection_msgs.ornate_right_h = vint_object_find("col_ornate_right") 
  2526. 	Hud_collection_msgs.ornate_left_h = vint_object_find("col_ornate_left") 
  2527. 	Hud_collection_msgs.ornate_x, Hud_collection_msgs.ornate_y = vint_get_property(Hud_collection_msgs.ornate_right_h, "anchor") 
  2528. end 
  2529.  
  2530. function hud_collection_msg_show(m) 
  2531.  
  2532. 	local header_text_h = vint_object_find("collection_header_text") 
  2533. 	local body_text_h = vint_object_find("collection_body_text") 
  2534. 	 
  2535. 	vint_set_property(header_text_h , "text_tag", m.header) 
  2536. 	 
  2537. 	 
  2538. 	local y_ornate_offset = 0 
  2539. 	if m.body ~= nil then 
  2540. 		vint_set_property(body_text_h, "text_tag", m.body) 
  2541. 		vint_set_property(body_text_h, "visible", true) 
  2542. 	else 
  2543. 		vint_set_property(body_text_h, "visible", false)	 
  2544. 		--No body text so adjust the ornate 
  2545. 		y_ornate_offset = -10 
  2546. 	end 
  2547. 	 
  2548. 	--Tint body if Win(For MP) 
  2549. 	if m.win_status == -1 then 
  2550. 		--Normal 
  2551. 		vint_set_property(body_text_h, "tint", 0.8980, 0.8941, 0.874) 
  2552. 	elseif m.win_status == 0 then 
  2553. 		--Win 
  2554. 		vint_set_property(body_text_h, "tint", 0.2667, 0.5059, 0.844) 
  2555. 	elseif m.win_status == 1 then 
  2556. 		--Lose 
  2557. 		vint_set_property(body_text_h, "tint", 0.6863, 0.0000, 0.004) 
  2558. 	elseif m.win_status == 2 then 
  2559. 		--Tie 
  2560. 		vint_set_property(body_text_h, "tint", 0.623, 0.635, 0.644) 
  2561. 	end 
  2562. 	 
  2563. 	--Adjust ornate trim 
  2564. 	local width, height = element_get_actual_size(header_text_h) 
  2565. 	local y = Hud_collection_msgs.ornate_y + y_ornate_offset 
  2566.  
  2567. 	--Offset header animation and body if line wraps 
  2568. 	local collection_msg_anchor_twn_h = vint_object_find("collection_msg_anchor_twn_1") 
  2569. 	if height > 50 then 
  2570. 		--Header has \n in it so we need format for wrapping 
  2571. 		vint_set_property(collection_msg_anchor_twn_h, "start_value", 0, -35) 
  2572. 		vint_set_property(collection_msg_anchor_twn_h, "end_value", 0, -15) 
  2573. 		vint_set_property(body_text_h, "anchor", 0, 33) 
  2574. 	else 
  2575. 		--Header does not wrap 
  2576. 		vint_set_property(collection_msg_anchor_twn_h, "start_value", 0, -12) 
  2577. 		vint_set_property(collection_msg_anchor_twn_h, "end_value", 0, 12) 
  2578. 		vint_set_property(body_text_h, "anchor", 0, 26) 
  2579. 	end 
  2580. 	 
  2581. 	-- Hide the stuff about getting smoked like Thanksgiving turkey 
  2582. 	vint_set_property(Hud_smoked_busted.handles.fade_in_anim , "is_paused", true) 
  2583. 	vint_set_property(Hud_smoked_busted.handles.grp, "visible", false) 
  2584. 	vint_set_property(Hud_smoked_busted.handles.grp, "alpha", 0) 
  2585. 	 
  2586. 	-- Fix the tween if we were interrupted last time by dying 
  2587. 	local h = vint_object_find("collection_anim") 
  2588. 	h = vint_object_find("collection_msg_alpha_twn_2", h) 
  2589. 	vint_set_property(h, "start_value", 1) 
  2590. 	 
  2591. 	-- Animate the new stuff 
  2592. 	vint_set_property(Hud_collection_msgs.ornate_right_h, "anchor", width * .5, y) 
  2593. 	vint_set_property(Hud_collection_msgs.ornate_left_h , "anchor", -width * .5, y) 
  2594. 	lua_play_anim(vint_object_find("collection_anim")) 
  2595.  
  2596. 	if m.audio >= 0 then 
  2597. 		audio_play(m.audio, "foley", true) 
  2598. 	end 
  2599. end 
  2600.  
  2601. function hud_collection_msg_end() 
  2602. 	if Hud_collection_msgs.num_msgs > 0 then 
  2603. 		-- remove element 0 and push others up 
  2604. 		for i = 0, Hud_collection_msgs.num_msgs - 2 do 
  2605. 			Hud_collection_msgs[i] = Hud_collection_msgs[i + 1] 
  2606. 		end 
  2607. 		 
  2608. 		Hud_collection_msgs[Hud_collection_msgs.num_msgs - 1] = nil 
  2609. 		Hud_collection_msgs.num_msgs = Hud_collection_msgs.num_msgs - 1 
  2610. 		 
  2611. 		if Hud_collection_msgs.num_msgs > 0 then 
  2612. 			hud_collection_msg_show(Hud_collection_msgs[0]) 
  2613. 		end 
  2614. 	end 
  2615. end 
  2616.  
  2617. function hud_collection_msg_new(header, body, audio, win_status) 
  2618. 	--TODO: ADD Header/Body/Win Status support (the body can be nil) 
  2619.  
  2620. 	local m = { header = header, body = body, win_status = win_status, audio = audio } 
  2621. 	Hud_collection_msgs[Hud_collection_msgs.num_msgs] = m 
  2622. 	Hud_collection_msgs.num_msgs = Hud_collection_msgs.num_msgs + 1 
  2623.  
  2624. 	if Hud_collection_msgs.num_msgs == 1 then 
  2625. 		hud_collection_msg_show(m) 
  2626. 	end 
  2627. end 
  2628.  
  2629.  
  2630. --=================================================== 
  2631. --Cruise Control 
  2632. --=================================================== 
  2633. function hud_cruise_control_update(is_active) 
  2634. 	local h = vint_object_find("cruise_text", Hud_player_status.cruise_control_h) 
  2635. 	if is_active ~= Hud_player_status.cruise_control_active then 
  2636. 		if is_active == true then 
  2637. 			--Show Cruise Control Status and let it fade with the animation. 
  2638. 			vint_set_property(Hud_player_status.cruise_control_h, "visible", true) 
  2639. 			vint_set_property(Hud_player_status.cruise_control_h, "alpha", .8) 
  2640. 			lua_play_anim(Hud_player_status.cruise_control_anim, 0) 
  2641. 		else 
  2642. 			--Hide status 
  2643. 			vint_set_property(Hud_player_status.cruise_control_h, "visible", false) 
  2644. 		end 
  2645. 	Hud_player_status.cruise_control_active = is_active 
  2646. 	end 
  2647. end 
  2648.  
  2649. function hud_cruise_control_update_pos(y_pos) 
  2650. 	local x, y = vint_get_property(Hud_player_status.cruise_control_h, "anchor") 
  2651. 	vint_set_property(Hud_player_status.cruise_control_h, "anchor", x, y_pos) 
  2652. end 
  2653.  
  2654.  
  2655. --=================================================== 
  2656. --Player Lockon 
  2657. --=================================================== 
  2658. function hud_player_lockon_update(di_h) 
  2659. 	local x, y, width, rotation, is_locked, is_visible = vint_dataitem_get(di_h) 
  2660.  
  2661. 	vint_set_property(Hud_lockon.lock_h, "anchor", x, y) 
  2662.  
  2663. 	if is_visible == true then 
  2664. 		--Scale 
  2665. 		local scale = width/Hud_lockon.base_pixel_size 
  2666. 		 
  2667. 		vint_set_property(Hud_lockon.lock_h, "anchor", x, y) 
  2668. 		vint_set_property(Hud_lockon.lock_h, "scale", scale, scale) 
  2669. 		vint_set_property(Hud_lockon.lock_h, "rotation", rotation) 
  2670. 			 
  2671. 		local lock_inner_width = Hud_lockon.lock_base_width / scale 
  2672. 		local lock_inner_height = Hud_lockon.lock_base_height / scale 
  2673. 		 
  2674. 		--Rescale Innards 
  2675. 		vint_set_property(Hud_lockon.lock1_h, "scale",Hud_lockon.lock_base_width, lock_inner_height) 
  2676. 		vint_set_property(Hud_lockon.lock2_h, "scale", Hud_lockon.lock_base_width, lock_inner_height) 
  2677. 		vint_set_property(Hud_lockon.lock3_h, "scale", Hud_lockon.lock_base_width, lock_inner_height) 
  2678. 		vint_set_property(Hud_lockon.lock4_h, "scale", Hud_lockon.lock_base_width, lock_inner_height) 
  2679. 		 
  2680. 		--Tint lockon 
  2681. 		local color 
  2682. 		if is_locked == true then 
  2683. 			color = Hud_lockon.color_locked 
  2684. 		else 
  2685. 			color = Hud_lockon.color_unlocked	 
  2686. 		end 
  2687. 		vint_set_property(Hud_lockon.lock_h, "tint", color.r, color.g, color.b) 
  2688. 		 
  2689. 		--Show lockon 
  2690. 		vint_set_property(Hud_lockon.lock_h, "visible", true) 
  2691. 	else 
  2692. 		vint_set_property(Hud_lockon.lock_h, "visible", false) 
  2693. 	end 
  2694. end 
  2695.