./hud_msg.lua

  1. Hud_msg_doc = 0 
  2.  
  3. -- Has to match the enum in hud_message.h 
  4. HUD_REGION_DEBUG				= 0 
  5. HUD_REGION_HELP				= 1 
  6. HUD_REGION_DIVERSION			= 2 
  7. HUD_REGION_SUBTITLES			= 3 
  8. HUD_REGION_CUTSCENE_HELP	= 4 
  9. HUD_REGION_USE_MSGS 			= 5 
  10. HUD_REGION_NEW_GAMEPLAY		= 6 
  11. HUD_REGION_CRITICAL_TIMER	= 7 
  12. HUD_NUM_REGIONS				= 8 
  13.  
  14. HUD_MSG_DIR_UP			= 0 
  15. HUD_MSG_DIR_DOWN		= 1 
  16. HUD_MSG_DIR_CENTER	= 2 
  17.  
  18. Hud_msg_std_text 		= { scale = 0.6, wrap_width = 0, leading = -5} 
  19. Hud_msg_help_text		= { scale = 0.7, wrap_width = 390, leading = -5} 	 
  20. Hud_msg_subtitle_text	= { scale = 0.7, wrap_width = 0, leading = -5}	-- Needs to match subtitles.cpp 
  21.  
  22. -- HUD Message Icon Enum... action_message_icon in  
  23. -- 
  24. -- d:\projects\sr3\main\sr3\src\game\control\control_gameplay.h  
  25. HUD_MSG_ICON_NONE = 0  
  26. HUD_MSG_ICON_Y = 1 
  27. HUD_MSG_ICON_X = 2 
  28. HUD_MSG_ICON_A = 3 
  29. HUD_MSG_ICON_BACK = 4 
  30. HUD_MSG_ICON_DPAD_LEFT = 5 
  31. HUD_MSG_ICON_DPAD_RIGHT = 6 
  32. HUD_MSG_ICON_DPAD_DOWN = 7 
  33. HUD_MSG_ICON_DPAD_UP = 8 
  34. HUD_MSG_ICON_SHOP = 9 
  35. HUD_MSG_ICON_MISSION = 10 
  36. HUD_MSG_ICON_HUMANSHIELD = 11 
  37. HUD_MSG_ICON_MECHANIC = 12 
  38. HUD_MSG_ICON_GARAGE = 13 
  39. HUD_MSG_ICON_CRIB = 14 
  40.  
  41. Hud_msg_icons = { 
  42. 	[HUD_MSG_ICON_NONE] = { 
  43. 		bmp = "ui_blank", 
  44. 	}, 
  45. 	[HUD_MSG_ICON_SHOP] = { 
  46. 		bmp = "ui_hud_use_shopping", 
  47. 		color = {R = 201/255, G = 186/255, B = 44/255}, 
  48. 		x = -34, 
  49. 		y = -39,  
  50. 	}, 
  51. 	[HUD_MSG_ICON_Y] = { 
  52. 		bmp = CTRL_BUTTON_Y, 
  53. 	}, 
  54. 	[HUD_MSG_ICON_X] = { 
  55. 		bmp = CTRL_BUTTON_X, 
  56. 	},	 
  57. 	[HUD_MSG_ICON_A] = { 
  58. 		bmp = CTRL_MENU_BUTTON_A, 
  59. 	},	 
  60. 	[HUD_MSG_ICON_DPAD_LEFT] = { 
  61. 		bmp = CTRL_BUTTON_DPAD_LEFT, 
  62. 	}, 
  63. 	[HUD_MSG_ICON_DPAD_RIGHT] = { 
  64. 		bmp = CTRL_BUTTON_DPAD_RIGHT, 
  65. 	},	 
  66. 	[HUD_MSG_ICON_DPAD_DOWN] = { 
  67. 		bmp = CTRL_BUTTON_DPAD_DOWN, 
  68. 	},	 
  69. 	[HUD_MSG_ICON_DPAD_UP] = { 
  70. 		bmp = CTRL_BUTTON_DPAD_UP, 
  71. 	},	 
  72. 	[HUD_MSG_ICON_BACK] = { 
  73. 		bmp = CTRL_MENU_BUTTON_BACK, 
  74. 	}, 
  75. 	[HUD_MSG_ICON_MISSION] = { 
  76. 		bmp = "ui_hud_icon_new_mission", 
  77. 	}, 
  78. 	[HUD_MSG_ICON_HUMANSHIELD] = { 
  79. 		bmp = "ui_hud_use_human_shield", 
  80. 		color = {R = 201/255, G = 186/255, B = 44/255}, 
  81. 		x = -30, 
  82. 		y = -55,  
  83. 	}, 
  84. 	[HUD_MSG_ICON_MECHANIC] = { 
  85. 		bmp = "ui_hud_use_wrench", 
  86. 		color = {R = 201/255, G = 186/255, B = 44/255}, 
  87. 		x = -34, 
  88. 		y = -39,  
  89. 	}, 
  90. 	[HUD_MSG_ICON_GARAGE] = { 
  91. 		bmp = "ui_hud_use_garage", 
  92. 		color = {R = 201/255, G = 186/255, B = 44/255}, 
  93. 		x = -34, 
  94. 		y = -39,  
  95. 	}, 
  96. 	[HUD_MSG_ICON_CRIB] = { 
  97. 		bmp = "ui_hud_use_crib", 
  98. 		color = {R = 201/255, G = 186/255, B = 44/255}, 
  99. 		x = -34, 
  100. 		y = -39,  
  101. 	}, 
  102. } 
  103.  
  104. local Hud_msg_use_msg_h 
  105. local Hud_msg_use_btn 
  106. local Hud_msg_use_start_x = 0 
  107. local Hud_msg_use_start_y = 0 
  108. local Hud_msg_use_text_start_x = 0 
  109. local Hud_msg_use_text_start_y = 0 
  110.  
  111. local Hud_msg_new_gameplay_h 
  112. local Hud_msg_gameplay_btn 
  113. local Hud_msg_gameplay_start_x = 0 
  114. local Hud_msg_gameplay_start_y = 0 
  115.  
  116. local Hud_msg_critical = {} 
  117.  
  118. local Hud_msg_current_use_msg_id = 0 
  119. local Hud_msg_current_critical_msg_id = 0 
  120. local Hud_msg_current_critical_msg_visible = false 
  121.  
  122. Hud_msg_regions = { 
  123. 	[HUD_REGION_DEBUG]		= { 
  124. 		text_fmt = Hud_msg_std_text, 
  125. 		direction = HUD_MSG_DIR_CENTER,	max_msgs = 10, 
  126. 		anchor = "msg_debug_anchor", 
  127. 		msgs = { num_msgs = 0 } 
  128. 	}, 
  129. 	 
  130. 	[HUD_REGION_HELP]		= { 
  131. 		text_fmt = Hud_msg_help_text, 
  132. 		direction = HUD_MSG_DIR_DOWN, 
  133. 		max_msgs = 3, 
  134. 		anchor = "msg_help_anchor", 
  135. 		msgs = { num_msgs = 0 } 
  136. 	}, 
  137. 	 
  138. 	[HUD_REGION_DIVERSION]	= { 
  139. 		text_fmt = Hud_msg_std_text, 
  140. 		direction = HUD_MSG_DIR_UP, 
  141. 		max_msgs = 7, 
  142. 		anchor = "msg_diversion_anchor", 
  143. 		msgs = { num_msgs = 0 } 
  144. 	}, 
  145.  
  146. 	[HUD_REGION_SUBTITLES]	= { 
  147. 		text_fmt = Hud_msg_subtitle_text, 
  148. 		direction = HUD_MSG_DIR_CENTER, 
  149. 		max_msgs = 3, 
  150. 		anchor = "msg_subtitle_anchor", 
  151. 		msgs = { num_msgs = 0 } 
  152. 	}, 
  153.  
  154. 	[HUD_REGION_CUTSCENE_HELP]	= { 
  155. 		text_fmt = Hud_msg_help_text, 
  156. 		direction = HUD_MSG_DIR_CENTER, 
  157. 		max_msgs = 2, 
  158. 		anchor = "cs_help_anchor", 
  159. 		msgs = { num_msgs = 0 } 
  160. 	}, 
  161. 	[HUD_REGION_USE_MSGS]	= { 
  162. 		text_fmt = Hud_msg_help_text, 
  163. 		direction = HUD_MSG_DIR_DOWN, 
  164. 		max_msgs = 1, 
  165. 		anchor = "msg_help_anchor", 
  166. 		msgs = { num_msgs = 0 }, 
  167. 	}, 
  168. 	[HUD_REGION_NEW_GAMEPLAY]	= { 
  169. 		text_fmt = Hud_msg_help_text, 
  170. 		direction = HUD_MSG_DIR_DOWN, 
  171. 		max_msgs = 1, 
  172. 		anchor = "msg_help_anchor", 
  173. 		msgs = { num_msgs = 0 }, 
  174. 	}, 
  175. 	[HUD_REGION_CRITICAL_TIMER]	= { 
  176. 		text_fmt = Hud_msg_help_text, 
  177. 		direction = HUD_MSG_DIR_DOWN, 
  178. 		max_msgs = 1, 
  179. 		anchor = "msg_help_anchor", 
  180. 		msgs = { num_msgs = 0 }, 
  181. 	},	 
  182. } 
  183.  
  184. -- all messages are stored here with the data item handle as index 
  185. Hud_msgs = { } 
  186.  
  187. function hud_msg_init() 
  188.  
  189. 	Hud_msg_doc = vint_document_find("hud_msg") 
  190. 	 
  191. 	-- resolve the anchors out to handles 
  192. 	for i, v in pairs(Hud_msg_regions) do 
  193. 		v.anchor = vint_object_find(v.anchor) 
  194. 	end 
  195.  
  196. 	--Resize help region if we are in hd 
  197. 	if vint_is_std_res() == false then 
  198. 		--HD mode 
  199. 		Hud_msg_help_text.wrap_width = 635 
  200. 	end 
  201. 	 
  202. 	if game_get_language() == "JP" then 
  203. 		Hud_msg_subtitle_text.leading = -3 
  204. 	elseif game_get_language() == "SK" then 
  205. 		Hud_msg_subtitle_text.scale = 0.9 
  206. 		Hud_msg_subtitle_text.leading = -3 
  207. 	end 
  208. 	 
  209. 	--Store center for centering later... 
  210. 	Hud_msg_use_msg_h = vint_object_find("use_msg") 
  211. 	Hud_msg_use_start_x, Hud_msg_use_start_y = vint_get_property(Hud_msg_use_msg_h, "anchor") 
  212. 	local use_text_h = vint_object_find("use_text", Hud_msg_use_msg_h) 
  213. 	Hud_msg_use_text_start_x, Hud_msg_use_text_start_y = vint_get_property(use_text_h, "anchor") 
  214.  
  215. 	--Store off the buttons for later use 
  216. 	Hud_msg_use_btn = Vdo_hint_button:new("use_btn") 
  217. 	Hud_msg_gameplay_btn = Vdo_hint_button:new("new_gameplay_btn") 
  218. 	 
  219. 	--Hide Use Message... 
  220. 	vint_set_property(Hud_msg_use_msg_h, "alpha", 0) 
  221. 	 
  222. 	--Store center for centering later... 
  223. 	Hud_msg_new_gameplay_h = vint_object_find("new_gameplay_msg") 
  224. 	Hud_msg_gameplay_start_x, Hud_msg_gameplay_start_y = vint_get_property(Hud_msg_new_gameplay_h, "anchor") 
  225. 	 
  226. 	--Hide New Gameplay Message... 
  227. 	vint_set_property(Hud_msg_new_gameplay_h, "alpha", 0) 
  228. 	 
  229. 	--Critical Timer 
  230. 	Hud_msg_critical.grp_h 					= vint_object_find("critical_timer") 
  231. 	Hud_msg_critical.timer_grp_h 			= vint_object_find("timer_grp", Hud_msg_critical.grp_h) 
  232. 	Hud_msg_critical.timer_txt_h  		= vint_object_find("critical_time_txt", Hud_msg_critical.grp_h) 
  233. 	Hud_msg_critical.timer_bmp_h  		= vint_object_find("timer_bmp", Hud_msg_critical.grp_h) 
  234. 	Hud_msg_critical.timer_desc_txt_h 	= vint_object_find("critical_timer_desc_txt", Hud_msg_critical.grp_h) 
  235. 	Hud_msg_critical.critical_bg_h 		= vint_object_find("critical_bg", Hud_msg_critical.grp_h) 
  236. 	Hud_msg_critical.fade_in_anim_h 		= vint_object_find("critical_timer_fade_in")		  
  237. 	Hud_msg_critical.fade_out_anim_h 	= vint_object_find("critical_timer_fade_out")	  
  238.  
  239. 	--Store centering information for the timer. 
  240. 	Hud_msg_critical.timer_grp_x, Hud_msg_critical.timer_grp_y  	= vint_get_property(Hud_msg_critical.timer_grp_h, "anchor") 
  241. 	 
  242. 	--Hide Critical Timer... 
  243. 	vint_set_property(Hud_msg_critical.grp_h, "alpha", 0) 
  244. 	 
  245. 	--Subscribe to data... 
  246. 	vint_datagroup_add_subscription("hud_messages", "insert", "hud_msg_new_message") 
  247. 	vint_datagroup_add_subscription("hud_messages", "update", "hud_msg_update_message") 
  248. 	vint_datagroup_add_subscription("hud_messages", "remove", "hud_msg_remove_message") 
  249. end 
  250.  
  251. function hud_msg_process() 
  252. 	for i, region in pairs(Hud_msg_regions) do 
  253. 		if region.is_dirty == true then 
  254. 			hud_msg_update_region(region, i) 
  255. 			region.is_dirty = false 
  256. 		end 
  257. 	end 
  258. end 
  259.  
  260. function hud_msg_update_region(region, region_index) 
  261. 	local pos_x, pos_y = 0, 0 
  262. 	local msgs_displayed = 0 
  263.  
  264. 	if region_index == HUD_REGION_USE_MSGS then 
  265. 		--Use messages... 
  266. 		for msg_i = 0, region.msgs.num_msgs - 1 do 
  267. 			if msgs_displayed >= region.max_msgs then 
  268. 			else 
  269. 				local msg = region.msgs[msg_i] 
  270. 				local msg_id = msg.di_h 
  271. 				hud_msg_update_use(msg) 
  272. 				if Hud_msg_current_use_msg_id ~= msg.di_h then					 
  273. 					--New message we should always fade in... 
  274. 					local h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc) 
  275. 					vint_set_property(h, "is_paused", true) 
  276. 					h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc) 
  277. 					lua_play_anim(h, 0, Hud_msg_doc) 
  278. 				end 
  279. 				if Hud_msg_current_use_msg_id == msg.di_h then 
  280. 					if msg.fade_time ~= 0 then 
  281. 						--old message with a fade time, lets fade out... 
  282. 						local h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc) 
  283. 						vint_set_property(h, "is_paused", true) 
  284. 						h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc) 
  285. 						lua_play_anim(h, 0, Hud_msg_doc) 
  286. 						msg_id = -1 
  287. 					end 
  288. 				end 
  289.  				Hud_msg_current_use_msg_id = msg_id 
  290. 			end 
  291. 			msgs_displayed = msgs_displayed + 1 
  292. 		end 
  293. 		if region.msgs.num_msgs == 0 and Hud_msg_current_use_msg_id ~= -1 then 
  294. 			--Fade out if there are no more messages left in the queue.. 
  295. 			local h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc) 
  296. 			vint_set_property(h, "is_paused", true) 
  297. 			h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc) 
  298. 			lua_play_anim(h, 0, Hud_msg_doc) 
  299. 			Hud_msg_current_use_msg_id = -1 
  300. 		end 
  301. 	elseif region_index == HUD_REGION_CRITICAL_TIMER then 
  302. 	 
  303. 		--Critical Timer messages... 
  304. 		for msg_i = 0, region.msgs.num_msgs - 1 do 
  305. 			if msgs_displayed < region.max_msgs then 
  306. 				local msg = region.msgs[msg_i] 
  307. 				local msg_id = msg.di_h 
  308. 				hud_msg_update_critical(msg) 
  309. 				if Hud_msg_current_critical_msg_id ~= msg.di_h and msg.di_h ~= -1 then 
  310. 					if Hud_msg_current_critical_msg_visible == false then 
  311. 						--New message we should always fade in... 
  312. 						vint_set_property(Hud_msg_critical.fade_out_anim_h, "is_paused", true) 
  313. 						lua_play_anim(Hud_msg_critical.fade_in_anim_h, 0, Hud_msg_doc) 
  314. 						Hud_msg_current_critical_msg_visible = true 
  315. 					end 
  316. 				end 
  317. 				if Hud_msg_current_critical_msg_id == msg.di_h then 
  318. 					if Hud_msg_current_critical_msg_visible == true then 
  319. 						if msg.fade_time ~= 0 then 
  320. 							--old message with a fade time, lets fade out... 
  321. 							vint_set_property(Hud_msg_critical.fade_in_anim_h, "is_paused", true) 
  322. 							lua_play_anim(Hud_msg_critical.fade_out_anim_h, 0, Hud_msg_doc) 
  323. 							Hud_msg_current_critical_msg_visible = false 
  324. 						end 
  325. 					end 
  326. 				end 
  327.  				Hud_msg_current_critical_msg_id = msg_id 
  328. 			end 
  329. 			msgs_displayed = msgs_displayed + 1 
  330. 		end 
  331. 			 
  332. 		if region.msgs.num_msgs == 0 and Hud_msg_current_critical_msg_id ~= -1 then 
  333. 			if Hud_msg_current_critical_msg_visible == true then 
  334. 				--Fade out if there are no more messages left in the queue.. 
  335. 				vint_set_property(Hud_msg_critical.fade_in_anim_h, "is_paused", true) 
  336. 				lua_play_anim(Hud_msg_critical.fade_out_anim_h, 0, Hud_msg_doc) 
  337. 				Hud_msg_current_critical_msg_id = -1 
  338. 				Hud_msg_current_critical_msg_visible = false 
  339. 			end 
  340. 		end 
  341. 	else 
  342. 		--Standard Help message... 
  343. 		for msg_i = 0, region.msgs.num_msgs - 1 do 
  344. 			local msg = region.msgs[msg_i] 
  345. 			local o = msg.text_obj_h 
  346. 			 
  347. 			if msgs_displayed >= region.max_msgs then 
  348. 				if o ~= 0 then 
  349. 					vint_object_destroy(o) 
  350. 				end 
  351. 				msg.text_obj_h = 0 
  352. 			else 
  353.  
  354. 				-- create a text item if needed 
  355. 				if o == 0 then 
  356. 					o = vint_object_create("hud_msg", "text", region.anchor) 
  357. 					if o == 0 then 
  358. 						debug_print("vint", "Problem: hud_msg cannot be created!\n") 
  359. 						return 
  360. 					end 
  361. 					vint_set_property(o, "text_tag", msg.text) 
  362. 					vint_set_property(o, "font", "thin_overlay") 
  363. 					vint_set_property(o, "text_scale", region.text_fmt.scale, region.text_fmt.scale) 
  364. 					vint_set_property(o, "tint", 0.862, 0.862, 0.862)	--(220,220,220) 
  365. 					vint_set_property(o, "leading", region.text_fmt.leading) 
  366. 					 
  367. 					local auto_offset, halign 
  368. 					if region.direction == HUD_MSG_DIR_CENTER then 
  369. 						auto_offset = "n" 
  370. 						halign = "center" 
  371. 					elseif region.direction == HUD_MSG_DIR_UP then 
  372. 						auto_offset = "sw" 
  373. 						halign = "left" 
  374. 					else	-- HUD_MSG_DIR_DOWN 
  375. 						auto_offset = "nw" 
  376. 						halign = "left" 
  377. 					end 
  378. 					 
  379. 					if region.text_fmt.wrap_width > 0 then 
  380. 						vint_set_property(o, "word_wrap", true) 
  381. 						vint_set_property(o, "wrap_width", region.text_fmt.wrap_width) 
  382. 					end 
  383. 					 
  384. 					vint_set_property(o, "auto_offset", auto_offset) 
  385. 					vint_set_property(o, "horz_align", halign) 
  386. 					vint_set_property(o, "shadow_enabled", true) 
  387. 					vint_set_property(o, "shadow_offset", 2, 2) 
  388. 					vint_set_property(o, "shadow_alpha", .6) 
  389. 					vint_set_property(o, "shadow_tint", 0,0,0) 
  390. 					 
  391. 					if msg.audio_id ~= -1 then 
  392. 						game_audio_play(msg.audio_id, msg.audio_type) 
  393. 					end 
  394. 				 
  395. 					msg.text_obj_h = o 
  396. 				end 
  397. 				 
  398. 				-- place the text 
  399. 				vint_set_property(o, "anchor", pos_x, pos_y) 
  400. 				 
  401. 				local w, h = vint_get_property(o, "unscaled_size") 
  402. 				 
  403. 				if h ~= nil then 
  404. 					-- figure position of next element 
  405. 					if region.direction == HUD_MSG_DIR_UP then 
  406. 						pos_y = pos_y - h 
  407. 					else	-- HUD_MSG_DIR_DOWN or HUD_MSG_DIR_CENTER 
  408. 						pos_y = pos_y + h 
  409. 					end 
  410. 				else 
  411. 					debug_print("vint", "Problem: hud_msg region has no height!\n") 
  412. 				end 
  413. 			end 
  414. 			 
  415. 			msgs_displayed = msgs_displayed + 1 
  416. 		end 
  417. 	end 
  418. end 
  419.  
  420. function hud_msg_new_message(di_h) 
  421. 	local region_index, priority, text, modifier, fade_time, audio_type, audio_id, icon1, icon2, pc_key, timer_value = vint_dataitem_get(di_h) 
  422. 	 
  423. 	local region = Hud_msg_regions[region_index] 
  424. 	 
  425. 	if region == nil then 
  426. 		debug_print("vint", "Message placed in invalid region, discarding. Region Index: " .. var_to_string(region_index) .."\n") 
  427. 		return 
  428. 	end 
  429. 	 
  430. 	-- initialize message 
  431. 	local msg = { 
  432. 		di_h = di_h, 
  433. 		fade_time = fade_time, 
  434. 		region_index = region_index, 
  435. 		priority = priority, 
  436. 		text = text, 
  437. 		modifier = modifier, 
  438. 		audio_type = audio_type, 
  439. 		icon1 = icon1, 
  440. 		icon2 = icon2, 
  441. 		pc_key = pc_key, 
  442. 		audio_id = audio_id, 
  443. 		text_obj_h = 0, 
  444. 		timer_value = timer_value, 
  445. 	} 
  446. 	 
  447. 	--Process special cases for special regions first... 
  448. 	if region_index == HUD_REGION_NEW_GAMEPLAY then 
  449. 		hud_msg_update_gameplay_msg(di_h) 
  450. 	else 
  451. 		--Standard region... 
  452. 		 
  453. 		-- insert in region list in priority order 
  454. 		local	insert_index = region.msgs.num_msgs 
  455. 		for i = 0, region.msgs.num_msgs - 1 do 
  456. 			local m = region.msgs[i] 
  457. 			if m.priority < priority then 
  458. 				insert_index = i 
  459. 				break 
  460. 			end 
  461. 		end 
  462.  
  463. 		-- shift the list down 
  464. 		for i = region.msgs.num_msgs, insert_index + 1, -1  do 
  465. 			region.msgs[i] = region.msgs[i - 1] 
  466. 		end 
  467. 		 
  468. 		-- insert new msg 
  469. 		region.msgs[insert_index] = msg 
  470. 		region.msgs.num_msgs = region.msgs.num_msgs + 1 
  471. 		Hud_msgs[di_h] = msg 
  472. 		region.is_dirty = true 
  473. 		 
  474.  
  475. 		--process fades differently for use messages... 
  476. 		if msg.region_index ~= HUD_REGION_USE_MSGS and msg.region_index ~= HUD_REGION_CRITICAL_TIMER  then 
  477. 			hud_msg_fade_process(msg, fade_time) 
  478. 		end 
  479. 	end 
  480. end 
  481.  
  482. function hud_msg_update_message(di_h) 
  483. 	local region_index, priority, text, modifier, fade_time, audio_type, audio_id, icon1, icon2, pc_key, timer_value = vint_dataitem_get(di_h) 
  484. 	local msg = Hud_msgs[di_h] 
  485. 	 
  486. 	if msg == nil then 
  487. 		-- we have no record of this data item 
  488. 		hud_msg_new_message(di_h) 
  489. 		return 
  490. 	end 
  491. 	 
  492. 	if region_index == HUD_REGION_NEW_GAMEPLAY then 
  493. 		hud_msg_update_gameplay_msg(di_h) 
  494. 	else 
  495. 		--Standard Msg Region... 
  496. 		local region = Hud_msg_regions[msg.region_index] 
  497. 		 
  498. 		-- update the text item if it's changed 
  499. 		if msg.text ~= text or msg.timer_value ~= timer_value then 
  500. 			msg.text = text 
  501. 			if msg.text_obj_h ~= 0 then 
  502. 				vint_set_property(msg.text_obj_h, "text_tag", text) 
  503. 			elseif msg.region_index == HUD_REGION_USE_MSGS or msg.region_index == HUD_REGION_CRITICAL_TIMER then 
  504. 				-- the whole message has to be updated 
  505. 				-- find msg in region 
  506. 				local region = Hud_msg_regions[msg.region_index] 
  507. 				local msg_index = -1 
  508. 				for i = 0, region.msgs.num_msgs - 1 do 
  509. 					if di_h == region.msgs[i].di_h then 
  510. 						msg_index = i 
  511. 						break 
  512. 					end 
  513. 				end 
  514. 			 
  515. 				-- remove it 
  516. 				if msg_index > -1 then 
  517. 					for i = msg_index + 1, region.msgs.num_msgs - 1 do 
  518. 						region.msgs[i - 1] = region.msgs[i] 
  519. 					end 
  520. 				 
  521. 					region.msgs.num_msgs = region.msgs.num_msgs - 1 
  522. 					region.is_dirty = true 
  523. 				end 
  524. 				Hud_msgs[di_h] = nil 
  525. 				hud_msg_new_message(di_h) 
  526. 			end 
  527. 		end 
  528. 		 
  529. 		--Update fade time... 
  530. 		msg.fade_time = fade_time 
  531.  
  532. 		-- Use messages fade differently 
  533. 		if msg.region_index ~= HUD_REGION_USE_MSGS and msg.region_index ~= HUD_REGION_CRITICAL_TIMER then 
  534. 			hud_msg_fade_process(msg, fade_time) 
  535. 		end 
  536. 		 
  537. 		region.is_dirty = true 
  538. 	end 
  539. end 
  540.  
  541. function hud_msg_remove_message(di_h) 
  542. 	 
  543. 	local region_index, priority, text, modifier, fade_time, audio_type, audio_id, icon1, icon2, pc_key, unused_timer, silent_kill = vint_dataitem_get(di_h) 
  544.  
  545. 	if region_index == HUD_REGION_NEW_GAMEPLAY then 
  546. 		local h = vint_object_find("gameplay_msg_fade_out") 
  547. 		vint_set_property(h, "is_paused", true) 
  548. 		h = vint_object_find("gameplay_msg_fade_in") 
  549. 		vint_set_property(h, "is_paused", true) 
  550. 		vint_set_property(Hud_msg_new_gameplay_h, "alpha", 0) 
  551. 	else 
  552. 		local msg = Hud_msgs[di_h] 
  553. 		if msg ~= nil then 
  554. 			-- clean up any existing fade tween 
  555. 			if msg.fade_tween_h ~= nil then 
  556. 				vint_object_destroy(msg.fade_tween_h) 
  557. 			end 
  558.  
  559. 			-- destroy text object 
  560. 			if msg.text_obj_h ~= 0 then 
  561. 				vint_object_destroy(msg.text_obj_h) 
  562. 			end 
  563. 			 
  564. 			-- find msg in region 
  565. 			local region = Hud_msg_regions[msg.region_index] 
  566. 			local msg_index = -1 
  567. 			for i = 0, region.msgs.num_msgs - 1 do 
  568. 				if di_h == region.msgs[i].di_h then 
  569. 					msg_index = i 
  570. 					break 
  571. 				end 
  572. 			end 
  573. 			 
  574. 			-- remove it 
  575. 			if msg_index > -1 then 
  576. 				for i = msg_index + 1, region.msgs.num_msgs - 1 do 
  577. 					region.msgs[i - 1] = region.msgs[i] 
  578. 				end 
  579. 				 
  580. 				region.msgs.num_msgs = region.msgs.num_msgs - 1 
  581. 				region.is_dirty = true 
  582. 			end 
  583. 		end 
  584. 		 
  585. 		Hud_msgs[di_h] = nil 
  586. 	end 
  587. end 
  588.  
  589. function hud_msg_fade_process(msg, new_fade) 
  590. 	local is_fading = (msg.fade_time ~= nil and msg.fade_time ~= 0) 
  591. 	local should_be_fading = (new_fade > 0) 
  592. 	 
  593. 	if is_fading ~= should_be_fading then 
  594. 		-- clean up any existing tween 
  595. 		if msg.fade_tween_h ~= nil then 
  596. 			vint_object_destroy(msg.fade_tween_h) 
  597. 		end 
  598. 		 
  599. 		if should_be_fading == true then 
  600. 			-- start fading 
  601. 			local o = vint_object_create("msg_fade", "tween", vint_object_find("root_animation")) 
  602. 			vint_set_property(o, "target_handle", msg.text_obj_h) 
  603. 			vint_set_property(o, "target_property", "alpha") 
  604. 			vint_set_property(o, "duration", new_fade) 
  605. 			vint_set_property(o, "start_value", 1) 
  606. 			vint_set_property(o, "end_value", 0) 
  607. 			vint_set_property(o, "start_time", vint_get_time_index()) 
  608. 			msg.fade_tween_h = o 
  609. 		else 
  610. 			-- stop fading 
  611. 			vint_set_property(msg.text_obj_h, "alpha", 1) 
  612. 		end 
  613. 	end 
  614. 	 
  615. 	msg.fade_time = new_fade 
  616. end 
  617.  
  618. function hud_msg_hide_region(region, hide) 
  619. 	local region = Hud_msg_regions[region] 
  620. 	 
  621. 	if region ~= nil then 
  622. 		vint_set_property(region.anchor, "visible", hide == false) 
  623. 	end 
  624. end 
  625.  
  626. function hud_msg_update_use(msg) 
  627. 	--get data out of table... 
  628. 	local text = msg.text 
  629. 	local modifier = msg.modifier 
  630. 	local icon1 = msg.icon1 
  631. 	local icon2 = msg.icon2 
  632. 	local pc_key = msg.pc_key 
  633. 	 
  634. 	--pop in message 
  635. 	vint_set_property(Hud_msg_use_msg_h, "visible", true) 
  636. 	vint_set_property(Hud_msg_use_msg_h, "alpha", 1) 
  637. 	 
  638. 	local bg_h = vint_object_find("use_bg", Hud_msg_use_msg_h) 
  639. 	local use_icon_h = vint_object_find("use_icon", Hud_msg_use_msg_h) 
  640. 	local use_txt_h = vint_object_find("use_text", Hud_msg_use_msg_h) 
  641. 	local use_mod_txt_h = vint_object_find("use_modifier_text", Hud_msg_use_msg_h) 
  642. 	local use_mod_txt_bg_h = vint_object_find("use_modifier_bg", Hud_msg_use_msg_h) 
  643. 	 
  644. 	--Set text for use message... 
  645. 	vint_set_property(use_txt_h, "text_tag", text) 
  646. 	 
  647. 	--Add modifier button if needed... (HOLD) + message... 
  648. 	local mod_width = 0 
  649. 	if modifier ~= "" then 
  650. 		vint_set_property(use_mod_txt_h, "text_tag", modifier)	 
  651. 		vint_set_property(use_mod_txt_h, "visible", true)	 
  652. 		vint_set_property(use_mod_txt_bg_h, "visible", true)	 
  653. 		 
  654. 		--set backgorund size of left button... 
  655. 		local w, h = element_get_actual_size(use_mod_txt_h) 
  656. 		local bg_width, bg_height = element_get_actual_size(use_mod_txt_bg_h) 
  657. 		mod_width = w + 14 
  658. 		element_set_actual_size(use_mod_txt_bg_h, mod_width, bg_height) 
  659. 	else  
  660. 		--Hide modifier action... 
  661. 		vint_set_property(use_mod_txt_h, "visible", false)	 
  662. 		vint_set_property(use_mod_txt_bg_h, "visible", false)	 
  663. 	end 
  664. 	 
  665. 	--Icon1 is the button image... so set it.. 
  666. 	local button_width = 0 
  667. 	if icon1 ~= HUD_MSG_ICON_NONE then 
  668. 		local icon_bmp = Hud_msg_icons[icon1].bmp 
  669. 		Hud_msg_use_btn:set_button(icon_bmp, pc_key) 
  670. 		Hud_msg_use_btn:set_visible(true) 
  671. 		local h_w, h_h = Hud_msg_use_btn:get_size() 
  672. 		button_width = h_w 
  673. 		local button_x = (button_width * 0.5) + 5 
  674. 		Hud_msg_use_btn:set_anchor(button_x, 0) 
  675. 		local h_x,h_y = Hud_msg_use_btn:get_anchor() 
  676. 		vint_set_property(use_txt_h, "anchor", h_x + button_x, Hud_msg_use_text_start_y)--Hud_msg_use_text_start_x, Hud_msg_use_text_start_y) 
  677. 	else 
  678. 		Hud_msg_use_btn:set_visible(false) 
  679. 		--offset text from left... 
  680. 		vint_set_property(use_txt_h, "anchor", 8, Hud_msg_use_text_start_y) 
  681. 	end 
  682. 		 
  683. 	--Target positions for centers... 
  684. 	local target_x = Hud_msg_use_start_x 
  685. 	local target_y = Hud_msg_use_start_y 
  686. 	 
  687. 	--Icon2 is the action image... 
  688. 	if icon2 ~= HUD_MSG_ICON_NONE then 
  689. 		local icon_bmp = Hud_msg_icons[icon2].bmp 
  690. 		local color = Hud_msg_icons[icon2].color 
  691. 		 
  692. 		--Set color if it is defined... 
  693. 		if color then 
  694. 			vint_set_property(use_icon_h, "tint", color.R, color.G, color.B) 
  695. 		else 
  696. 			--No specified color... 
  697. 			vint_set_property(use_icon_h, "tint", 1,1,1) 
  698. 		end 
  699. 		 
  700. 		vint_set_property(use_icon_h, "image", Hud_msg_icons[icon2].bmp) 
  701. 		vint_set_property(use_icon_h, "visible", true) 
  702. 		vint_set_property(bg_h, "visible", false) 
  703. 		vint_set_property(use_txt_h, "visible", false) 
  704. 		 
  705. 		local w, h = element_get_actual_size(use_icon_h) 
  706. 		target_x = Hud_msg_use_start_x - w/2 - 10 
  707. 	else 
  708. 		vint_set_property(use_icon_h, "visible", false) 
  709. 		vint_set_property(use_txt_h, "visible", true) 
  710. 		vint_set_property(bg_h, "visible", true) 
  711. 		 
  712. 		--Update background size and center to screen... 
  713. 		local h_w, h_h = element_get_actual_size(use_txt_h) 
  714. 		local w = button_width + h_w + 17 
  715. 				 
  716. 		--set background size of button... 
  717. 		local bg_width, bg_height = element_get_actual_size(bg_h) 
  718. 		element_set_actual_size(bg_h, w, bg_height) 
  719. 			 
  720. 		--Center object to screen... 
  721. 		local scale_x, scale_y = vint_get_property(Hud_msg_use_msg_h, "scale")	-- get scale of the box so we can center it appropriatly.. 
  722. 		target_x = (Hud_msg_use_start_x - ((w - mod_width) / 2) * scale_x) 
  723. 	end 
  724. 	 
  725. 	--Set Position... 
  726. 	vint_set_property(Hud_msg_use_msg_h, "anchor", target_x, target_y)	 
  727. end 
  728.  
  729. function hud_msg_update_critical(msg) 
  730.  
  731. 	--get data out of table... 
  732. 	local text = msg.text 
  733. 	local modifier = msg.modifier 
  734. 	local timer_value = msg.timer_value 
  735. 	 
  736. 	local timer_grp_h 	= Hud_msg_critical.timer_grp_h 			 
  737. 	local timer_txt_h 	= Hud_msg_critical.timer_txt_h  
  738. 	local timer_bmp_h 	= Hud_msg_critical.timer_bmp_h	 
  739. 	local timer_desc_txt = Hud_msg_critical.timer_desc_txt_h  		 
  740. 	local critical_bg_h 	= Hud_msg_critical.critical_bg_h 
  741.  
  742. 	---Format the time 
  743. 	local minutes = floor(timer_value / 60) 
  744. 	local seconds =  timer_value % 60 
  745. 	--Pad the seconds for the timer 
  746. 	if seconds < 1 then 
  747. 		-- Fixing a case where we had negative 0 
  748. 		seconds = "00" 
  749. 	elseif seconds < 10 then 
  750. 		seconds = "0" .. seconds 
  751. 	end 
  752. 	 
  753. 	local time_formatted 
  754. 	if minutes < 1 then 
  755. 		time_formatted = ":" .. seconds 
  756. 	else 
  757. 		time_formatted = minutes .. ":" .. seconds 
  758. 	end 
  759. 	 
  760. 	--Set Text values... 
  761. 	vint_set_property(timer_txt_h, "text_tag", time_formatted) 
  762. 	vint_set_property(timer_desc_txt, "text_tag", text) 
  763.  
  764. 	--center timer with text 
  765. 	local timer_width, timer_height = element_get_actual_size(timer_txt_h) 
  766. 	local timer_bmp_width, timer_bmp_height = element_get_actual_size(timer_bmp_h) 
  767. 	timer_width = timer_width + timer_bmp_width 
  768. 	local x = - timer_width / 2 
  769. 	vint_set_property(timer_grp_h, "anchor", x, Hud_msg_critical.timer_grp_y) 
  770. 	 
  771. 	--Update background size and center to screen... 
  772. 	local timer_desc_width, timer_desc_height = element_get_actual_size(timer_desc_txt) 
  773. 	local width = timer_desc_width + 20 
  774. 	width = max(width, timer_width) 
  775. 	local critical_bg_width, critical_bg_height = element_get_actual_size(critical_bg_h) 
  776. 	element_set_actual_size(critical_bg_h, width, critical_bg_height) 
  777. end 
  778.  
  779.  
  780.  
  781. function hud_msg_update_gameplay_msg(di_h) 
  782.  
  783. 	local region_index, priority, text, modifier, fade_time, audio_type, audio_id, icon1, icon2, pc_key = vint_dataitem_get(di_h) 
  784. 	 
  785. 	if fade_time == 0 then 
  786. 		local h = vint_object_find("gameplay_msg_fade_out") 
  787. 		vint_set_property(h, "is_paused", true) 
  788. 		lua_play_anim(vint_object_find("gameplay_msg_fade_in")) 
  789. 	else  
  790.  
  791. 		lua_play_anim(vint_object_find("gameplay_msg_fade_out")) 
  792. 	end 
  793. 	 
  794. 	local use_txt_h = vint_object_find("new_gameplay_txt", Hud_msg_new_gameplay_h) 
  795. 	local use_bmp_h = vint_object_find("gameplay_icon", Hud_msg_new_gameplay_h) 
  796.  
  797. 	--Icon1 is the button image... so set it.. 
  798. 	if icon1 ~= HUD_MSG_ICON_NONE then 
  799. 		local icon_bmp = Hud_msg_icons[icon1].bmp 
  800. 		Hud_msg_gameplay_btn:set_button(icon_bmp, pc_key) 
  801. 	end 
  802. 	 
  803. 	if icon2 == HUD_MSG_ICON_NONE then 
  804. 		vint_set_property(use_bmp_h, "visible", false) 
  805. 	else 
  806. 		local icon_data = Hud_msg_icons[icon2] 
  807. 		vint_set_property(use_bmp_h, "image", icon_data.bmp) 
  808. 		vint_set_property(use_bmp_h, "visible", true) 
  809. 	end 
  810.  
  811. 	vint_set_property(use_txt_h, "text_tag", text) 
  812. 	vint_set_property(use_txt_h, "visible", true) 
  813. 	 
  814. 	local button_x = 0 
  815. 	local h_w, h_h = Hud_msg_gameplay_btn:get_size() 
  816. 	local new_button_x = button_x + (h_w * 0.5) + 5 
  817. 	 
  818. 	--Update background size and center to screen... 
  819. 	local w = 0 
  820. 	local img_w, img_h = element_get_actual_size(use_bmp_h) 
  821. 	w = w + h_w 
  822. 	 
  823. 	Hud_msg_gameplay_btn:set_anchor(new_button_x, 0) 
  824. 	vint_set_property(use_bmp_h, "anchor", new_button_x + (h_w * 0.5) + (img_w * 0.5) + 3, 0) 
  825. 	vint_set_property(use_txt_h, "anchor", new_button_x + (h_w * 0.5) + img_w + 5, 0) 
  826. 	 
  827. 	h_w, h_h = element_get_actual_size(use_txt_h) 
  828. 	w = w + h_w + img_w + 20 
  829. 	 
  830. 	--set backgorund size of button... 
  831. 	local bg_h = vint_object_find("new_gameplay_bg") 
  832. 	local bg_width, bg_height = element_get_actual_size(bg_h) 
  833. 	element_set_actual_size(bg_h, w, bg_height) 
  834. 	 
  835. 	--Center object to screen... 
  836. 	local scale_x, scale_y = vint_get_property(Hud_msg_new_gameplay_h, "scale")	-- get scale of the box so we can center it appropriatly.. 
  837. 	vint_set_property(Hud_msg_new_gameplay_h, "anchor", Hud_msg_gameplay_start_x - ((w / 2) * scale_x) , Hud_msg_gameplay_start_y) 
  838. end 
  839.  
  840.  
  841. ------------------------------------------------------------------------------- 
  842. -- Moves subtitle messages to top of screen 
  843. -- 
  844. function hud_msg_subtitle_top() 
  845. 	local anchor_x,anchor_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor") 
  846. 	local scale_x,scale_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "scale") 
  847. 	anchor_y = 94 * scale_x 
  848. 	vint_set_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor", anchor_x, anchor_y) 
  849. end 
  850.  
  851. ------------------------------------------------------------------------------- 
  852. -- Moves subtitle messages to bottom of screen 
  853. -- 
  854. function hud_msg_subtitle_bottom() 
  855. 	local anchor_x,anchor_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor") 
  856. 	local scale_x,scale_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "scale") 
  857. 	anchor_y = 561 * scale_x 
  858. 	vint_set_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor", anchor_x, anchor_y) 
  859. end 
  860.