Hud_msg_doc = 0 
 
 
 
-- Has to match the enum in hud_message.h 
 
HUD_REGION_DEBUG				= 0 
 
HUD_REGION_HELP				= 1 
 
HUD_REGION_DIVERSION			= 2 
 
HUD_REGION_SUBTITLES			= 3 
 
HUD_REGION_CUTSCENE_HELP	= 4 
 
HUD_REGION_USE_MSGS 			= 5 
 
HUD_REGION_NEW_GAMEPLAY		= 6 
 
HUD_REGION_CRITICAL_TIMER	= 7 
 
HUD_REGION_USE_MSGS_ALT		= 8 
 
HUD_NUM_REGIONS				= 9 
 
 
 
HUD_MSG_DIR_UP			= 0 
 
HUD_MSG_DIR_DOWN		= 1 
 
HUD_MSG_DIR_CENTER	= 2 
 
 
 
Hud_msg_std_text 		= { scale = 0.6, wrap_width = 0, leading = -5}  
Hud_msg_help_text		= { scale = 0.7, wrap_width = 390, leading = -5} 	  
Hud_msg_subtitle_text	= { scale = 0.7, wrap_width = 0, leading = -5}	-- Needs to match subtitles.cpp  
 
 
-- HUD Message Icon Enum... action_message_icon in  
 
-- 
 
-- ...\src\game\interface\interface_enums.h  
 
HUD_MSG_ICON_NONE = 0  
 
HUD_MSG_ICON_Y = 1 
 
HUD_MSG_ICON_X = 2 
 
HUD_MSG_ICON_A = 3 
 
HUD_MSG_ICON_BACK = 4 
 
HUD_MSG_ICON_DPAD_LEFT = 5 
 
HUD_MSG_ICON_DPAD_RIGHT = 6 
 
HUD_MSG_ICON_DPAD_DOWN = 7 
 
HUD_MSG_ICON_DPAD_UP = 8 
 
HUD_MSG_ICON_SHOP = 9 
 
HUD_MSG_ICON_MISSION = 10 
 
HUD_MSG_ICON_HUMANSHIELD = 11 
 
HUD_MSG_ICON_MECHANIC = 12 
 
HUD_MSG_ICON_GARAGE = 13 
 
HUD_MSG_ICON_CRIB = 14 
 
HUD_MSG_ICON_LEFT_BUMPER = 15 
 
HUD_MSG_ICON_RIGHT_BUMPER = 16 
 
 
 
-- Used to tell the HUB to go directly to the quest log 
 
Hud_msg_new_quest_displayed = false 
 
 
 
--Alternate and standard use message indexes. 
 
local HUD_MSG_INDEX_STANDARD 	= 0 
 
local HUD_MSG_INDEX_ALT 		= 1 
 
 
 
Hud_msg_icons = {  
	[HUD_MSG_ICON_NONE] = {  
		bmp = "ui_blank", 
 
	}, 
 
	[HUD_MSG_ICON_SHOP] = {  
		bmp = "ui_hud_use_shopping", 
 
		color = {R = 201/255, G = 186/255, B = 44/255},  
		x = -34, 
 
		y = -39,  
 
	}, 
 
	[HUD_MSG_ICON_Y] = {  
		bmp = CTRL_BUTTON_Y, 
 
	}, 
 
	[HUD_MSG_ICON_X] = {  
		bmp = CTRL_BUTTON_X, 
 
	},	 
 
	[HUD_MSG_ICON_A] = {  
		bmp = get_a_button(true), 
 
	},	 
 
	[HUD_MSG_ICON_DPAD_LEFT] = {  
		bmp = CTRL_BUTTON_DPAD_LEFT, 
 
	}, 
 
	[HUD_MSG_ICON_DPAD_RIGHT] = {  
		bmp = CTRL_BUTTON_DPAD_RIGHT, 
 
	},	 
 
	[HUD_MSG_ICON_DPAD_DOWN] = {  
		bmp = CTRL_BUTTON_DPAD_DOWN, 
 
	},	 
 
	[HUD_MSG_ICON_DPAD_UP] = {  
		bmp = CTRL_BUTTON_DPAD_UP, 
 
	},	 
 
	[HUD_MSG_ICON_BACK] = {  
		bmp = CTRL_MENU_BUTTON_BACK, 
 
	}, 
 
	[HUD_MSG_ICON_MISSION] = {  
		bmp = "ui_hud_icon_new_mission", 
 
	}, 
 
	[HUD_MSG_ICON_HUMANSHIELD] = {  
		bmp = "ui_hud_use_human_shield", 
 
		color = {R = 201/255, G = 186/255, B = 44/255},  
		x = -30, 
 
		y = -55,  
 
	}, 
 
	[HUD_MSG_ICON_MECHANIC] = {  
		bmp = "ui_hud_use_wrench", 
 
		color = {R = 201/255, G = 186/255, B = 44/255},  
		x = -34, 
 
		y = -39,  
 
	}, 
 
	[HUD_MSG_ICON_GARAGE] = {  
		bmp = "ui_hud_use_garage", 
 
		color = {R = 201/255, G = 186/255, B = 44/255},  
		x = -34, 
 
		y = -39,  
 
	}, 
 
	[HUD_MSG_ICON_CRIB] = {  
		bmp = "ui_hud_use_crib", 
 
		color = {R = 201/255, G = 186/255, B = 44/255},  
		x = -34, 
 
		y = -39,  
 
	}, 
 
	[HUD_MSG_ICON_LEFT_BUMPER] = {  
		bmp = CTRL_BUTTON_LB, 
 
	}, 
 
	[HUD_MSG_ICON_RIGHT_BUMPER] = {  
		bmp = CTRL_BUTTON_RB, 
 
	},	 
 
} 
 
 
 
local Hud_msg_use_h 
 
local Hud_msg_use_btn 
 
local Hud_msg_use_alt_btn 
 
local Hud_msg_use_btn_meter_grp_h 
 
local Hud_msg_use_start_x = 0 
 
local Hud_msg_use_start_y = 0 
 
local Hud_msg_use_text_start_x = 0 
 
local Hud_msg_use_text_start_y = 0 
 
local Hud_msg_tiers_text_start_x = 0 
 
local Hud_msg_tiers_text_start_y = 0 
 
 
 
local Hud_msg_new_gameplay_h 
 
local Hud_msg_gameplay_btn 
 
local Hud_msg_gameplay_start_x = 0 
 
local Hud_msg_gameplay_start_y = 0 
 
 
 
local Hud_msg_use_alt_h 
 
local Hud_use_msg_alt_fade_in_h  
 
local Hud_use_msg_alt_fade_out_h  
 
 
 
local Hud_msg_critical = {}  
 
 
local Hud_msg_current_use_msg_id = 0 
 
local Hud_msg_current_use_alt_msg_id = 0 
 
local Hud_msg_current_critical_msg_id = 0 
 
local Hud_msg_current_critical_msg_visible = false 
 
 
 
local Hud_msg_quest_anim_h = 0 
 
local Hud_msg_quest_out_anim_h = 0 
 
local Hud_msg_quest_new_only_h = 0 
 
local Hud_msg_quest_out_new_only_h = 0 
 
local Hud_msg_obj_anim_h = 0 
 
local Hud_msg_coop_anim_h = 0 
 
local Hud_msg_coop_out_anim_h = 0 
 
local Hud_msg_base_anim_h = 0 
 
local Hud_msg_base_out_anim_h = 0 
 
local Hud_msg_quest_grp_h = 0 
 
 
 
local Hud_msg_voice_msg_h = 0 -- HVS_TJW 
 
 
 
local Hud_msg_objective_complete_listener_h = 0 
 
 
 
local HUD_QUEST_COMPLETE_MAX_WIDTH = 360 
 
 
 
local HUD_MSG_USE_ALT_OFFSET_VERTICAL = 33	--Offset of standard use message... 
 
 
 
Hud_msg_regions = {  
	[HUD_REGION_DEBUG]		= {  
		text_fmt = Hud_msg_std_text, 
 
		direction = HUD_MSG_DIR_CENTER,	max_msgs = 10, 
 
		anchor = "msg_debug_anchor", 
 
		msgs = { num_msgs = 0 }  
	}, 
 
	 
 
	[HUD_REGION_HELP]		= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_DOWN, 
 
		max_msgs = 3, 
 
		anchor = "msg_help_anchor", 
 
		msgs = { num_msgs = 0 }  
	}, 
 
	 
 
	[HUD_REGION_DIVERSION]	= {  
		text_fmt = Hud_msg_std_text, 
 
		direction = HUD_MSG_DIR_UP, 
 
		max_msgs = 7, 
 
		anchor = "msg_diversion_anchor", 
 
		msgs = { num_msgs = 0 }  
	}, 
 
 
 
	[HUD_REGION_SUBTITLES]	= {  
		text_fmt = Hud_msg_subtitle_text, 
 
		direction = HUD_MSG_DIR_CENTER, 
 
		max_msgs = 3, 
 
		anchor = "msg_subtitle_anchor", 
 
		msgs = { num_msgs = 0 }  
	}, 
 
 
 
	[HUD_REGION_CUTSCENE_HELP]	= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_CENTER, 
 
		max_msgs = 2, 
 
		anchor = "cs_help_anchor", 
 
		msgs = { num_msgs = 0 }  
	}, 
 
	[HUD_REGION_USE_MSGS]	= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_DOWN, 
 
		max_msgs = 2, 
 
		anchor = "msg_help_anchor", 
 
		msgs = { num_msgs = 0 },  
	}, 
 
	[HUD_REGION_NEW_GAMEPLAY]	= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_DOWN, 
 
		max_msgs = 1, 
 
		anchor = "msg_help_anchor", 
 
		msgs = { num_msgs = 0 },  
	}, 
 
	[HUD_REGION_CRITICAL_TIMER]	= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_DOWN, 
 
		max_msgs = 1, 
 
		anchor = "msg_help_anchor", 
 
		msgs = { num_msgs = 0 },  
	},	 
 
	[HUD_REGION_USE_MSGS_ALT]	= {  
		text_fmt = Hud_msg_help_text, 
 
		direction = HUD_MSG_DIR_DOWN, 
 
		max_msgs = 1, 
 
		anchor = "msg_help_anchor", 
 
		msgs = { num_msgs = 0 },  
	},	 
 
} 
 
 
 
-- all messages are stored here with the data item handle as index 
 
Hud_msgs = { }  
 
 
function hud_msg_init() 
 
	Hud_msg_doc = vint_document_find("hud_msg")  
	 
 
	-- resolve the anchors out to handles 
 
	for i, v in pairs(Hud_msg_regions) do 
 
		v.anchor = vint_object_find(v.anchor) 
 
	end 
 
 
 
	--Resize help region if we are in hd 
 
	if vint_is_std_res() == false then 
 
		--HD mode 
 
		Hud_msg_help_text.wrap_width = 635 
 
	end 
 
	 
 
	if game_get_language() == "JP" then 
 
		Hud_msg_subtitle_text.leading = -3 
 
	elseif game_get_language() == "SK" then 
 
		Hud_msg_subtitle_text.scale = 0.9 
 
		Hud_msg_subtitle_text.leading = -3 
 
	end 
 
	 
 
	--Store center for centering later... 
 
	Hud_msg_use_h = vint_object_find("use_msg")  
	Hud_msg_use_start_x, Hud_msg_use_start_y = vint_get_property(Hud_msg_use_h, "anchor") 
 
	local use_text_h = vint_object_find("use_text", Hud_msg_use_h)  
	Hud_msg_use_text_start_x, Hud_msg_use_text_start_y = vint_get_property(use_text_h, "anchor") 
 
	local tiers_text_h = vint_object_find("tiers_text", Hud_msg_use_h)  
	Hud_msg_tiers_text_start_x, Hud_msg_tiers_text_start_y = vint_get_property(tiers_text_h, "anchor") 
 
	 
 
	--Creates our alternate use message via script. 
 
	hud_msg_create_use_alt() 
 
	 
 
	--Store off the buttons for later use 
 
	Hud_msg_use_btn = Vdo_hint_button:new("use_btn", Hud_msg_use_h)  
	Hud_msg_use_alt_btn = Vdo_hint_button:new("use_btn", Hud_msg_use_alt_h)  
	Hud_msg_gameplay_btn = Vdo_hint_button:new("new_gameplay_btn")  
	 
 
	Hud_msg_use_btn_meter_grp_h = vint_object_find("use_btn_meter_grp")  
	vint_set_property(Hud_msg_use_btn_meter_grp_h, "visible", false) 
 
	 
 
	--Hide Use Message... 
 
	vint_set_property(Hud_msg_use_h, "alpha", 0) 
 
	vint_set_property(Hud_msg_use_alt_h, "alpha", 0) 
 
	 
 
	--Store center for centering later... 
 
	Hud_msg_new_gameplay_h = vint_object_find("new_gameplay_msg")  
	Hud_msg_gameplay_start_x, Hud_msg_gameplay_start_y = vint_get_property(Hud_msg_new_gameplay_h, "anchor") 
 
	 
 
	--Store voice chat message handle 
 
	Hud_msg_voice_msg_h = vint_object_find("coop_voice_msg")  
	 
 
	--Hide New Gameplay Message... 
 
	vint_set_property(Hud_msg_new_gameplay_h, "alpha", 0) 
 
	 
 
	--Critical Timer 
 
	Hud_msg_critical.grp_h 					= vint_object_find("critical_timer")  
	Hud_msg_critical.timer_grp_h 			= vint_object_find("timer_grp", Hud_msg_critical.grp_h)  
	Hud_msg_critical.timer_txt_h  		= vint_object_find("critical_time_txt", Hud_msg_critical.grp_h)  
	Hud_msg_critical.timer_bmp_h  		= vint_object_find("timer_bmp", Hud_msg_critical.grp_h)  
	Hud_msg_critical.timer_desc_txt_h 	= vint_object_find("critical_timer_desc_txt", Hud_msg_critical.grp_h)  
	Hud_msg_critical.critical_bg_h 		= vint_object_find("critical_bg", Hud_msg_critical.grp_h)  
	Hud_msg_critical.fade_in_anim_h 		= vint_object_find("critical_timer_fade_in")		   
	Hud_msg_critical.fade_out_anim_h 	= vint_object_find("critical_timer_fade_out")	   
 
 
	--Store centering information for the timer. 
 
	Hud_msg_critical.timer_grp_x, Hud_msg_critical.timer_grp_y  	= vint_get_property(Hud_msg_critical.timer_grp_h, "anchor") 
 
	 
 
	--Hide Critical Timer... 
 
	vint_set_property(Hud_msg_critical.grp_h, "alpha", 0) 
 
	 
 
	--Hide quest grp 
 
	Hud_msg_quest_grp_h = vint_object_find("quest_update_grp", 0, Hud_msg_doc)  
	Hud_msg_quest_anim_h = vint_object_find("quest_update_anim", 0)  
	Hud_msg_quest_out_anim_h = vint_object_find("quest_update_out_anim", 0)	  
	Hud_msg_quest_new_only_h = vint_object_find("quest_update_solo", 0)  
	Hud_msg_quest_out_new_only_h = vint_object_find("quest_update_out_solo", 0)  
	 
 
	vint_set_property(Hud_msg_quest_grp_h, "visible", false) 
 
	 
 
	--Quest/Coop/Objective Animations... 
 
	Hud_msg_obj_anim_h = vint_object_find("objective_cmp_anim", 0)	  
	Hud_msg_base_anim_h = vint_object_find("quest_base_anim", 0)	  
	Hud_msg_base_out_anim_h = vint_object_find("quest_base_out_anim", 0)		  
	Hud_msg_coop_anim_h = vint_object_find("quest_coop_anim", 0)		  
	Hud_msg_coop_out_anim_h = vint_object_find("quest_coop_out_anim", 0)		  
	 
 
 
 
	--Setup callback for Quest objective complete anim... 
 
	local objective_cmp_end_twn_h = vint_object_find("objective_cmp_end_twn", Hud_msg_obj_anim_h)  
	vint_set_property(objective_cmp_end_twn_h, "start_event", "hud_msg_quest_obj_fade_out")	 
 
	 
 
	--Setup callback for Quest complete anim... 
 
	--local quest_out_end_event_twn_h = vint_object_find("end_event", Hud_msg_quest_out_anim_h)  
	--vint_set_property(quest_out_end_event_twn_h, "start_event", "hud_msg_quest_hide") 
 
	 
 
	--Setup callback for Quest complete anim... 
 
	local quest_out_new_end_event_twn_h = vint_object_find("end_event", Hud_msg_quest_out_new_only_h)  
	vint_set_property(quest_out_new_end_event_twn_h, "start_event", "hud_msg_quest_new_hide") 
 
		 
 
	--Subscribe to data... 
 
	vint_datagroup_add_subscription("hud_messages", "insert", "hud_msg_new_message")  
	vint_datagroup_add_subscription("hud_messages", "update", "hud_msg_update_message")  
	vint_datagroup_add_subscription("hud_messages", "remove", "hud_msg_remove_message")  
	 
 
	-- quest objective listener 
 
	Hud_msg_objective_complete_listener_h = vint_scriptevent_listen( "quest_objective_complete", "hud_msg_update_quest" ) 
 
end 
 
 
 
function hud_msg_cleanup() 
 
	vint_scriptevent_stop_listening( Hud_msg_objective_complete_listener_h ) 
 
end 
 
 
 
function hud_msg_process() 
 
	for i, region in pairs(Hud_msg_regions) do 
 
		if region.is_dirty == true then 
 
			hud_msg_update_region(region, i) 
 
			region.is_dirty = false 
 
		end 
 
	end 
 
end 
 
 
 
function hud_msg_update_region(region, region_index) 
 
	local pos_x, pos_y = 0, 0 
 
	local msgs_displayed = 0 
 
 
 
	if region_index == HUD_REGION_USE_MSGS then 
 
		--Use messages... 
 
		for msg_i = 0, region.msgs.num_msgs - 1 do 
 
			if msgs_displayed >= region.max_msgs then 
 
			else 
 
				local msg = region.msgs[msg_i] 
 
				local msg_id = msg.di_h 
 
				hud_msg_update_use(msg) 
 
				if Hud_msg_current_use_msg_id ~= msg.di_h then					 
 
					--New message we should always fade in... 
 
					local h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc)  
					vint_set_property(h, "is_paused", true) 
 
					h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc)  
					lua_play_anim(h, 0, Hud_msg_doc) 
 
				end 
 
				if Hud_msg_current_use_msg_id == msg.di_h then 
 
					if msg.fade_time ~= 0 then 
 
						--old message with a fade time, lets fade out... 
 
						local h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc)  
						vint_set_property(h, "is_paused", true) 
 
						h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc)  
						lua_play_anim(h, 0, Hud_msg_doc) 
 
						msg_id = -1 
 
					end 
 
				end 
 
 				Hud_msg_current_use_msg_id = msg_id 
 
			end 
 
			msgs_displayed = msgs_displayed + 1 
 
		end 
 
		if region.msgs.num_msgs == 0 and Hud_msg_current_use_msg_id ~= -1 then 
 
			--Fade out if there are no more messages left in the queue.. 
 
			local h = vint_object_find("use_msg_fade_in", 0, Hud_msg_doc)  
			vint_set_property(h, "is_paused", true) 
 
			h = vint_object_find("use_msg_fade_out", 0, Hud_msg_doc)  
			lua_play_anim(h, 0, Hud_msg_doc) 
 
			Hud_msg_current_use_msg_id = -1 
 
		end 
 
	elseif region_index == HUD_REGION_USE_MSGS_ALT then 
 
		--Use messages... 
 
		for msg_i = 0, region.msgs.num_msgs - 1 do 
 
			if msgs_displayed >= region.max_msgs then 
 
			else 
 
				local msg = region.msgs[msg_i] 
 
				local msg_id = msg.di_h 
 
				hud_msg_update_use_alt(msg) 
 
				if Hud_msg_current_use_alt_msg_id ~= msg.di_h then					 
 
					--New message we should always fade in... 
 
					vint_set_property(Hud_use_msg_alt_fade_out_h, "is_paused", true) 
 
					lua_play_anim(Hud_use_msg_alt_fade_in_h, 0, Hud_msg_doc) 
 
				end 
 
				if Hud_msg_current_use_alt_msg_id == msg.di_h then 
 
					if msg.fade_time ~= 0 then 
 
						--old message with a fade time, lets fade out... 
 
						vint_set_property(Hud_use_msg_alt_fade_in_h, "is_paused", true) 
 
						lua_play_anim(Hud_use_msg_alt_fade_out_h, 0, Hud_msg_doc) 
 
						msg_id = -1 
 
					end 
 
				end 
 
 				Hud_msg_current_use_alt_msg_id = msg_id 
 
			end 
 
			msgs_displayed = msgs_displayed + 1 
 
		end 
 
		if region.msgs.num_msgs == 0 and Hud_msg_current_use_alt_msg_id ~= -1 then 
 
			--Fade out if there are no more messages left in the queue.. 
 
			vint_set_property(Hud_use_msg_alt_fade_in_h, "is_paused", true) 
 
			lua_play_anim(Hud_use_msg_alt_fade_out_h, 0, Hud_msg_doc) 
 
			Hud_msg_current_use_alt_msg_id = -1 
 
		end 
 
	elseif region_index == HUD_REGION_CRITICAL_TIMER then 
 
	 
 
		--Critical Timer messages... 
 
		for msg_i = 0, region.msgs.num_msgs - 1 do 
 
			if msgs_displayed < region.max_msgs then 
 
				local msg = region.msgs[msg_i] 
 
				local msg_id = msg.di_h 
 
				hud_msg_update_critical(msg) 
 
				if Hud_msg_current_critical_msg_id ~= msg.di_h and msg.di_h ~= -1 then 
 
					if Hud_msg_current_critical_msg_visible == false then 
 
						--New message we should always fade in... 
 
						vint_set_property(Hud_msg_critical.fade_out_anim_h, "is_paused", true) 
 
						lua_play_anim(Hud_msg_critical.fade_in_anim_h, 0, Hud_msg_doc) 
 
						Hud_msg_current_critical_msg_visible = true 
 
					end 
 
				end 
 
				if Hud_msg_current_critical_msg_id == msg.di_h then 
 
					if Hud_msg_current_critical_msg_visible == true then 
 
						if msg.fade_time ~= 0 then 
 
							--old message with a fade time, lets fade out... 
 
							vint_set_property(Hud_msg_critical.fade_in_anim_h, "is_paused", true) 
 
							lua_play_anim(Hud_msg_critical.fade_out_anim_h, 0, Hud_msg_doc) 
 
							Hud_msg_current_critical_msg_visible = false 
 
						end 
 
					end 
 
				end 
 
 				Hud_msg_current_critical_msg_id = msg_id 
 
			end 
 
			msgs_displayed = msgs_displayed + 1 
 
		end 
 
			 
 
		if region.msgs.num_msgs == 0 and Hud_msg_current_critical_msg_id ~= -1 then 
 
			if Hud_msg_current_critical_msg_visible == true then 
 
				--Fade out if there are no more messages left in the queue.. 
 
				vint_set_property(Hud_msg_critical.fade_in_anim_h, "is_paused", true) 
 
				lua_play_anim(Hud_msg_critical.fade_out_anim_h, 0, Hud_msg_doc) 
 
				Hud_msg_current_critical_msg_id = -1 
 
				Hud_msg_current_critical_msg_visible = false 
 
			end 
 
		end 
 
	else 
 
		--Standard Help message... 
 
		for msg_i = 0, region.msgs.num_msgs - 1 do 
 
			local msg = region.msgs[msg_i] 
 
			local o = msg.text_obj_h 
 
			 
 
			if msgs_displayed >= region.max_msgs then 
 
				if o ~= 0 then 
 
					vint_object_destroy(o) 
 
				end 
 
				msg.text_obj_h = 0 
 
			else 
 
 
 
				-- create a text item if needed 
 
				if o == 0 then 
 
					o = vint_object_create("hud_msg", "text", region.anchor)  
					if o == 0 then 
 
						debug_print("vint", "Problem: hud_msg cannot be created!\n")  
						return 
 
					end 
 
					vint_set_property(o, "text_tag", msg.text) 
 
					vint_set_property(o, "font", "thin_overlay") 
 
					vint_set_property(o, "text_scale", region.text_fmt.scale, region.text_fmt.scale) 
 
					vint_set_property(o, "tint", 0.862, 0.862, 0.862)	--(220,220,220) 
 
					vint_set_property(o, "leading", region.text_fmt.leading) 
 
					 
 
					local auto_offset, halign 
 
					if region.direction == HUD_MSG_DIR_CENTER then 
 
						auto_offset = "n" 
 
						halign = "center" 
 
					elseif region.direction == HUD_MSG_DIR_UP then 
 
						auto_offset = "sw" 
 
						halign = "left" 
 
					else	-- HUD_MSG_DIR_DOWN 
 
						auto_offset = "nw" 
 
						halign = "left" 
 
					end 
 
					 
 
					if region.text_fmt.wrap_width > 0 then 
 
						vint_set_property(o, "word_wrap", true) 
 
						vint_set_property(o, "wrap_width", region.text_fmt.wrap_width) 
 
					end 
 
					 
 
					vint_set_property(o, "auto_offset", auto_offset) 
 
					vint_set_property(o, "horz_align", halign) 
 
					vint_set_property(o, "shadow_enabled", true) 
 
					vint_set_property(o, "shadow_offset", 2, 2) 
 
					vint_set_property(o, "shadow_alpha", .6) 
 
					vint_set_property(o, "shadow_tint", 0,0,0) 
 
					 
 
					if msg.audio_id ~= -1 then 
 
						game_audio_play(msg.audio_id, msg.audio_type) 
 
					end 
 
				 
 
					msg.text_obj_h = o 
 
				end 
 
				 
 
				-- place the text 
 
				vint_set_property(o, "anchor", pos_x, pos_y) 
 
				 
 
				local w, h = vint_get_property(o, "unscaled_size") 
 
				 
 
				if h ~= nil then 
 
					-- figure position of next element 
 
					if region.direction == HUD_MSG_DIR_UP then 
 
						pos_y = pos_y - h 
 
					else	-- HUD_MSG_DIR_DOWN or HUD_MSG_DIR_CENTER 
 
						pos_y = pos_y + h 
 
					end 
 
				else 
 
					debug_print("vint", "Problem: hud_msg region has no height!\n")  
				end 
 
			end 
 
			 
 
			msgs_displayed = msgs_displayed + 1 
 
		end 
 
	end 
 
end 
 
 
 
 
 
 
 
function hud_msg_new_message(di_h) 
 
	local region_index, priority, text, modifier, extra_text, fade_time, audio_type, audio_id, icon1, icon2, pc_key, timer_value, message_index = vint_dataitem_get(di_h) 
 
	 
 
	-- index is (so far) only used for use messages, 0 for normal or 1 for alternate 
 
	 
 
	--Fake the region index if its a use message and using the alternate message index... 
 
	if message_index == HUD_MSG_INDEX_ALT and region_index == HUD_REGION_USE_MSGS then 
 
		region_index = HUD_REGION_USE_MSGS_ALT 
 
	end 
 
	 
 
	local region = Hud_msg_regions[region_index] 
 
	 
 
	if region == nil then 
 
		debug_print("vint", "Message placed in invalid region, discarding. Region Index: " .. var_to_string(region_index) .."\n")  
		return 
 
	end 
 
	 
 
	-- initialize message 
 
	local msg = {  
		di_h = di_h, 
 
		fade_time = fade_time, 
 
		region_index = region_index, 
 
		priority = priority, 
 
		text = text, 
 
		modifier = modifier, 
 
		extra_text = extra_text, 
 
		audio_type = audio_type, 
 
		icon1 = icon1, 
 
		icon2 = icon2, 
 
		pc_key = pc_key, 
 
		audio_id = audio_id, 
 
		text_obj_h = 0, 
 
		timer_value = timer_value, 
 
		message_index = message_index, 
 
	} 
 
	 
 
	--Process special cases for special regions first... 
 
	if region_index == HUD_REGION_NEW_GAMEPLAY then 
 
		hud_msg_update_gameplay_msg(di_h) 
 
	else 
 
		--Standard region... 
 
		 
 
		-- insert in region list in priority order 
 
		local	insert_index = region.msgs.num_msgs 
 
		for i = 0, region.msgs.num_msgs - 1 do 
 
			local m = region.msgs[i] 
 
			if m.priority < priority then 
 
				insert_index = i 
 
				break 
 
			end 
 
		end 
 
 
 
		-- shift the list down 
 
		for i = region.msgs.num_msgs, insert_index + 1, -1  do 
 
			region.msgs[i] = region.msgs[i - 1] 
 
		end 
 
		 
 
		-- insert new msg 
 
		region.msgs[insert_index] = msg 
 
		region.msgs.num_msgs = region.msgs.num_msgs + 1 
 
		Hud_msgs[di_h] = msg 
 
		region.is_dirty = true 
 
		 
 
 
 
		--process fades differently for use messages... 
 
		if msg.region_index ~= HUD_REGION_USE_MSGS and msg.region_index ~= HUD_REGION_CRITICAL_TIMER and msg.region_index ~= HUD_REGION_USE_MSGS_ALT then 
 
			hud_msg_fade_process(msg, fade_time) 
 
		end 
 
	end 
 
end 
 
 
 
function hud_msg_update_message(di_h) 
 
	local region_index, priority, text, modifier, extra_text, fade_time, audio_type, audio_id, icon1, icon2, pc_key, timer_value, message_index = vint_dataitem_get(di_h) 
 
	local msg = Hud_msgs[di_h] 
 
	 
 
	 
 
	--Fake the region index if its a use message and using the alternate message index... 
 
	if message_index == HUD_MSG_INDEX_ALT and region_index == HUD_REGION_USE_MSGS then 
 
		region_index = HUD_REGION_USE_MSGS_ALT 
 
	end 
 
	 
 
	if msg == nil then 
 
		-- we have no record of this data item 
 
		hud_msg_new_message(di_h) 
 
		return 
 
	end 
 
	 
 
	if region_index == HUD_REGION_NEW_GAMEPLAY then 
 
		hud_msg_update_gameplay_msg(di_h) 
 
	else 
 
		--Standard Msg Region... 
 
		local region = Hud_msg_regions[msg.region_index] 
 
		 
 
		-- update the text item if it's changed 
 
		if msg.text ~= text or msg.timer_value ~= timer_value then 
 
			msg.text = text 
 
			if msg.text_obj_h ~= 0 then 
 
				vint_set_property(msg.text_obj_h, "text_tag", text) 
 
			elseif msg.region_index == HUD_REGION_USE_MSGS or msg.region_index == HUD_REGION_CRITICAL_TIMER or msg.region_index == HUD_REGION_USE_MSGS_ALT then 
 
				-- the whole message has to be updated 
 
				-- find msg in region 
 
				local region = Hud_msg_regions[msg.region_index] 
 
				local msg_index = -1 
 
				for i = 0, region.msgs.num_msgs - 1 do 
 
					if di_h == region.msgs[i].di_h then 
 
						msg_index = i 
 
						break 
 
					end 
 
				end 
 
			 
 
				-- remove it 
 
				if msg_index > -1 then 
 
					for i = msg_index + 1, region.msgs.num_msgs - 1 do 
 
						region.msgs[i - 1] = region.msgs[i] 
 
					end 
 
				 
 
					region.msgs.num_msgs = region.msgs.num_msgs - 1 
 
					region.is_dirty = true 
 
				end 
 
				Hud_msgs[di_h] = nil 
 
				hud_msg_new_message(di_h) 
 
			end 
 
		end 
 
		 
 
		--Update fade time... 
 
		msg.fade_time = fade_time 
 
 
 
		-- Use messages fade differently 
 
		if msg.region_index ~= HUD_REGION_USE_MSGS and msg.region_index ~= HUD_REGION_CRITICAL_TIMER and msg.region_index ~= HUD_REGION_USE_MSGS_ALT then 
 
			hud_msg_fade_process(msg, fade_time) 
 
		end 
 
		 
 
		region.is_dirty = true 
 
	end 
 
end 
 
 
 
function hud_msg_remove_message(di_h) 
 
	 
 
	local region_index, priority, text, modifier, extra_text, fade_time, audio_type, audio_id, icon1, icon2, pc_key, unused_timer, message_index = vint_dataitem_get(di_h) 
 
 
 
		--Fake the region index if its a use message and using the alternate message index... 
 
	if message_index == HUD_MSG_INDEX_ALT and region_index == HUD_REGION_USE_MSGS then 
 
		region_index = HUD_REGION_USE_MSGS_ALT 
 
	end 
 
	 
 
	if region_index == HUD_REGION_NEW_GAMEPLAY then 
 
		local h = vint_object_find("gameplay_msg_fade_out")  
		vint_set_property(h, "is_paused", true) 
 
		h = vint_object_find("gameplay_msg_fade_in")  
		vint_set_property(h, "is_paused", true) 
 
		vint_set_property(Hud_msg_new_gameplay_h, "alpha", 0) 
 
	else 
 
		local msg = Hud_msgs[di_h] 
 
		if msg ~= nil then 
 
			-- clean up any existing fade tween 
 
			if msg.fade_tween_h ~= nil then 
 
				vint_object_destroy(msg.fade_tween_h) 
 
			end 
 
 
 
			-- destroy text object 
 
			if msg.text_obj_h ~= 0 then 
 
				vint_object_destroy(msg.text_obj_h) 
 
			end 
 
			 
 
			-- find msg in region 
 
			local region = Hud_msg_regions[msg.region_index] 
 
			local msg_index = -1 
 
			for i = 0, region.msgs.num_msgs - 1 do 
 
				if di_h == region.msgs[i].di_h then 
 
					msg_index = i 
 
					break 
 
				end 
 
			end 
 
			 
 
			-- remove it 
 
			if msg_index > -1 then 
 
				for i = msg_index + 1, region.msgs.num_msgs - 1 do 
 
					region.msgs[i - 1] = region.msgs[i] 
 
				end 
 
				 
 
				region.msgs.num_msgs = region.msgs.num_msgs - 1 
 
				region.is_dirty = true 
 
			end 
 
		end 
 
		 
 
		Hud_msgs[di_h] = nil 
 
	end 
 
end 
 
 
 
function hud_msg_fade_process(msg, new_fade) 
 
	local is_fading = (msg.fade_time ~= nil and msg.fade_time ~= 0) 
 
	local should_be_fading = (new_fade > 0) 
 
	 
 
	if is_fading ~= should_be_fading then 
 
		-- clean up any existing tween 
 
		if msg.fade_tween_h ~= nil then 
 
			vint_object_destroy(msg.fade_tween_h) 
 
		end 
 
		 
 
		if should_be_fading == true then 
 
			-- start fading 
 
			local o = vint_object_create("msg_fade", "tween", vint_object_find("root_animation"))  
			vint_set_property(o, "target_handle", msg.text_obj_h) 
 
			vint_set_property(o, "target_property", "alpha") 
 
			vint_set_property(o, "duration", new_fade) 
 
			vint_set_property(o, "start_value", 1) 
 
			vint_set_property(o, "end_value", 0) 
 
			vint_set_property(o, "start_time", vint_get_time_index()) 
 
			msg.fade_tween_h = o 
 
		else 
 
			-- stop fading 
 
			vint_set_property(msg.text_obj_h, "alpha", 1) 
 
		end 
 
	end 
 
	 
 
	msg.fade_time = new_fade 
 
end 
 
 
 
function hud_msg_hide_region(region, hide) 
 
	local region = Hud_msg_regions[region] 
 
	 
 
	if region ~= nil then 
 
		vint_set_property(region.anchor, "visible", hide == false) 
 
	end 
 
end 
 
 
 
function hud_msg_update_use(msg) 
 
	--get data out of table... 
 
	local text = msg.text 
 
	local extra_text = msg.extra_text 
 
	local modifier = msg.modifier 
 
	local icon1 = msg.icon1 
 
	local icon2 = msg.icon2 
 
	local pc_key = msg.pc_key 
 
	 
 
	--pop in message 
 
	vint_set_property(Hud_msg_use_h, "visible", true) 
 
	vint_set_property(Hud_msg_use_h, "alpha", 1) 
 
	 
 
	local bg_h = vint_object_find("use_bg", Hud_msg_use_h)  
	local use_icon_h = vint_object_find("use_icon", Hud_msg_use_h)  
	local use_txt_h = vint_object_find("use_text", Hud_msg_use_h)  
	local use_mod_txt_h = vint_object_find("use_modifier_text", Hud_msg_use_h)  
	local use_mod_txt_bg_h = vint_object_find("use_modifier_bg", Hud_msg_use_h)  
	local tiers_txt_h = vint_object_find("tiers_text", Hud_msg_use_h)  
	 
 
	--Set text for use message... 
 
	vint_set_property(use_txt_h, "text_tag", text) 
 
	 
 
	--Set text for tiers message... 
 
	if extra_text ~= "" and extra_text ~= nil then 
 
		vint_set_property(tiers_txt_h, "text_tag", extra_text) 
 
	end 
 
	 
 
	--Add modifier button if needed... (HOLD) + message... 
 
	local mod_width = 0 
 
	if modifier ~= "" then 
 
		vint_set_property(use_mod_txt_h, "text_tag", modifier)	 
 
		vint_set_property(use_mod_txt_h, "visible", true)	 
 
		vint_set_property(use_mod_txt_bg_h, "visible", true)	 
 
		 
 
		--set backgorund size of left button... 
 
		local w, h = element_get_actual_size(use_mod_txt_h) 
 
		local bg_width, bg_height = element_get_actual_size(use_mod_txt_bg_h) 
 
		mod_width = w + 14 
 
		element_set_actual_size(use_mod_txt_bg_h, mod_width, bg_height) 
 
	else  
 
		--Hide modifier action... 
 
		vint_set_property(use_mod_txt_h, "visible", false)	 
 
		vint_set_property(use_mod_txt_bg_h, "visible", false)	 
 
	end 
 
	 
 
	--Icon1 is the button image... so set it.. 
 
	local button_width = 0 
 
	if icon1 ~= HUD_MSG_ICON_NONE then 
 
		local icon_bmp = Hud_msg_icons[icon1].bmp 
 
		Hud_msg_use_btn:set_button(icon_bmp, pc_key) 
 
		Hud_msg_use_btn:set_visible(true) 
 
		local h_w, h_h = Hud_msg_use_btn:get_size() 
 
		button_width = h_w 
 
		local button_x = (button_width * 0.5) + 5 
 
		Hud_msg_use_btn:set_anchor(button_x, 0) 
 
		vint_set_property(Hud_msg_use_btn_meter_grp_h, "anchor", button_x, 0) 
 
		local h_x,h_y = Hud_msg_use_btn:get_anchor() 
 
		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) 
 
		vint_set_property(tiers_txt_h, "anchor", Hud_msg_tiers_text_start_x, Hud_msg_tiers_text_start_y) 
 
	else 
 
		Hud_msg_use_btn:set_visible(false) 
 
		--offset text from left... 
 
		vint_set_property(use_txt_h, "anchor", 8, Hud_msg_use_text_start_y) 
 
	end	 
 
		 
 
	--Target positions for centers... 
 
	local target_x = Hud_msg_use_start_x 
 
	local target_y = Hud_msg_use_start_y 
 
	 
 
	--Icon2 is the action image... 
 
	if icon2 ~= HUD_MSG_ICON_NONE then 
 
		local icon_bmp = Hud_msg_icons[icon2].bmp 
 
		local color = Hud_msg_icons[icon2].color 
 
		 
 
		--Set color if it is defined... 
 
		if color then 
 
			vint_set_property(use_icon_h, "tint", color.R, color.G, color.B) 
 
		else 
 
			--No specified color... 
 
			vint_set_property(use_icon_h, "tint", 1,1,1) 
 
		end 
 
		 
 
		vint_set_property(use_icon_h, "image", Hud_msg_icons[icon2].bmp) 
 
		vint_set_property(use_icon_h, "visible", true) 
 
		vint_set_property(bg_h, "visible", false) 
 
		vint_set_property(use_txt_h, "visible", false) 
 
		vint_set_property(tiers_txt_h, "visible", false) 
 
		 
 
		local w, h = element_get_actual_size(use_icon_h) 
 
		target_x = Hud_msg_use_start_x - w/2 - 10 
 
	else 
 
		vint_set_property(use_icon_h, "visible", false) 
 
		vint_set_property(use_txt_h, "visible", true) 
 
		vint_set_property(tiers_txt_h, "visible", true) 
 
		vint_set_property(bg_h, "visible", true) 
 
		 
 
		--Update background size and center to screen... 
 
		local h_w, h_h = element_get_actual_size(use_txt_h) 
 
		local w = button_width + h_w + 17 
 
				 
 
		--set background size of button... 
 
		local bg_width, bg_height = element_get_actual_size(bg_h) 
 
		element_set_actual_size(bg_h, w, bg_height) 
 
			 
 
		--Center object to screen... 
 
		local scale_x, scale_y = vint_get_property(Hud_msg_use_h, "scale")	-- get scale of the box so we can center it appropriatly.. 
 
		target_x = (Hud_msg_use_start_x - ((w - mod_width) / 2) * scale_x) 
 
	end 
 
	 
 
	if extra_text ~= nil and extra_text ~= "" then 
 
		vint_set_property(tiers_txt_h, "visible", true) 
 
	else 
 
		vint_set_property(tiers_txt_h, "visible", false) 
 
	end 
 
	 
 
	--Set Position... 
 
	vint_set_property(Hud_msg_use_h, "anchor", target_x, target_y)	 
 
end 
 
 
 
function hud_msg_update_use_alt(msg) 
 
	--get data out of table... 
 
	local text = msg.text 
 
	local extra_text = msg.extra_text 
 
	local modifier = msg.modifier 
 
	local icon1 = msg.icon1 
 
	local icon2 = msg.icon2 
 
	local pc_key = msg.pc_key 
 
	 
 
	--pop in message 
 
	vint_set_property(Hud_msg_use_alt_h, "visible", true) 
 
	vint_set_property(Hud_msg_use_alt_h, "alpha", 1) 
 
	 
 
	local bg_h = vint_object_find("use_bg", Hud_msg_use_alt_h)  
	local use_icon_h = vint_object_find("use_icon", Hud_msg_use_alt_h)  
	local use_txt_h = vint_object_find("use_text", Hud_msg_use_alt_h)  
	local use_mod_txt_h = vint_object_find("use_modifier_text", Hud_msg_use_alt_h)  
	local use_mod_txt_bg_h = vint_object_find("use_modifier_bg", Hud_msg_use_alt_h)  
	local tiers_txt_h = vint_object_find("tiers_text", Hud_msg_use_alt_h)  
	 
 
	--Set text for use message... 
 
	vint_set_property(use_txt_h, "text_tag", text) 
 
	 
 
	--Set text for tiers message... 
 
	if extra_text ~= "" and extra_text ~= nil then 
 
		vint_set_property(tiers_txt_h, "text_tag", extra_text) 
 
	end 
 
	 
 
	--Add modifier button if needed... (HOLD) + message... 
 
	local mod_width = 0 
 
	if modifier ~= "" then 
 
		vint_set_property(use_mod_txt_h, "text_tag", modifier)	 
 
		vint_set_property(use_mod_txt_h, "visible", true)	 
 
		vint_set_property(use_mod_txt_bg_h, "visible", true)	 
 
		 
 
		--set backgorund size of left button... 
 
		local w, h = element_get_actual_size(use_mod_txt_h) 
 
		local bg_width, bg_height = element_get_actual_size(use_mod_txt_bg_h) 
 
		mod_width = w + 14 
 
		element_set_actual_size(use_mod_txt_bg_h, mod_width, bg_height) 
 
	else  
 
		--Hide modifier action... 
 
		vint_set_property(use_mod_txt_h, "visible", false)	 
 
		vint_set_property(use_mod_txt_bg_h, "visible", false)	 
 
	end 
 
	 
 
	--Icon1 is the button image... so set it.. 
 
	local button_width = 0 
 
	if icon1 ~= HUD_MSG_ICON_NONE then 
 
		local icon_bmp = Hud_msg_icons[icon1].bmp 
 
		Hud_msg_use_alt_btn:set_button(icon_bmp, pc_key) 
 
		Hud_msg_use_alt_btn:set_visible(true) 
 
		local h_w, h_h = Hud_msg_use_alt_btn:get_size() 
 
		button_width = h_w 
 
		local button_x = (button_width * 0.5) + 5 
 
		Hud_msg_use_alt_btn:set_anchor(button_x, 0) 
 
		vint_set_property(Hud_msg_use_btn_meter_grp_h, "anchor", button_x, 0) 
 
		local h_x,h_y = Hud_msg_use_alt_btn:get_anchor() 
 
		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) 
 
		vint_set_property(tiers_txt_h, "anchor", Hud_msg_tiers_text_start_x, Hud_msg_tiers_text_start_y) 
 
	else 
 
		Hud_msg_use_alt_btn:set_visible(false) 
 
		--offset text from left... 
 
		vint_set_property(use_txt_h, "anchor", 8, Hud_msg_use_text_start_y) 
 
	end	 
 
		 
 
	--Target positions for centers... 
 
	local target_x = Hud_msg_use_start_x 
 
	local target_y = Hud_msg_use_start_y + vint_to_std_res(HUD_MSG_USE_ALT_OFFSET_VERTICAL) 
 
	 
 
	--Icon2 is the action image... 
 
	if icon2 ~= HUD_MSG_ICON_NONE then 
 
		local icon_bmp = Hud_msg_icons[icon2].bmp 
 
		local color = Hud_msg_icons[icon2].color 
 
		 
 
		--Set color if it is defined... 
 
		if color then 
 
			vint_set_property(use_icon_h, "tint", color.R, color.G, color.B) 
 
		else 
 
			--No specified color... 
 
			vint_set_property(use_icon_h, "tint", 1,1,1) 
 
		end 
 
		 
 
		vint_set_property(use_icon_h, "image", Hud_msg_icons[icon2].bmp) 
 
		vint_set_property(use_icon_h, "visible", true) 
 
		vint_set_property(bg_h, "visible", false) 
 
		vint_set_property(use_txt_h, "visible", false) 
 
		vint_set_property(tiers_txt_h, "visible", false) 
 
		 
 
		local w, h = element_get_actual_size(use_icon_h) 
 
		target_x = Hud_msg_use_start_x - w/2 - 10 
 
	else 
 
		vint_set_property(use_icon_h, "visible", false) 
 
		vint_set_property(use_txt_h, "visible", true) 
 
		vint_set_property(tiers_txt_h, "visible", true) 
 
		vint_set_property(bg_h, "visible", true) 
 
		 
 
		--Update background size and center to screen... 
 
		local h_w, h_h = element_get_actual_size(use_txt_h) 
 
		local w = button_width + h_w + 17 
 
				 
 
		--set background size of button... 
 
		local bg_width, bg_height = element_get_actual_size(bg_h) 
 
		element_set_actual_size(bg_h, w, bg_height) 
 
			 
 
		--Center object to screen... 
 
		local scale_x, scale_y = vint_get_property(Hud_msg_use_alt_h, "scale")	-- get scale of the box so we can center it appropriatly.. 
 
		target_x = (Hud_msg_use_start_x - ((w - mod_width) / 2) * scale_x) 
 
	end 
 
	 
 
	if extra_text ~= nil and extra_text ~= "" then 
 
		vint_set_property(tiers_txt_h, "visible", true) 
 
	else 
 
		vint_set_property(tiers_txt_h, "visible", false) 
 
	end 
 
	 
 
	--Set Position... 
 
	vint_set_property(Hud_msg_use_alt_h, "anchor", target_x, target_y)	 
 
end 
 
 
 
function hud_msg_update_critical(msg) 
 
 
 
	--get data out of table... 
 
	local text = msg.text 
 
	local modifier = msg.modifier 
 
	local timer_value = msg.timer_value 
 
	 
 
	local timer_grp_h 	= Hud_msg_critical.timer_grp_h 			 
 
	local timer_txt_h 	= Hud_msg_critical.timer_txt_h  
 
	local timer_bmp_h 	= Hud_msg_critical.timer_bmp_h	 
 
	local timer_desc_txt = Hud_msg_critical.timer_desc_txt_h  		 
 
	local critical_bg_h 	= Hud_msg_critical.critical_bg_h 
 
 
 
	---Format the time 
 
	local minutes = floor(timer_value / 60) 
 
	local seconds =  timer_value % 60 
 
	--Pad the seconds for the timer 
 
	if seconds < 1 then 
 
		-- Fixing a case where we had negative 0 
 
		seconds = "00" 
 
	elseif seconds < 10 then 
 
		seconds = "0" .. seconds 
 
	end 
 
	 
 
	local time_formatted 
 
	if minutes < 1 then 
 
		time_formatted = ":" .. seconds 
 
	else 
 
		time_formatted = minutes .. ":" .. seconds 
 
	end 
 
	 
 
	--Set Text values... 
 
	vint_set_property(timer_txt_h, "text_tag", time_formatted) 
 
	vint_set_property(timer_desc_txt, "text_tag", text) 
 
 
 
	--center timer with text 
 
	local timer_width, timer_height = element_get_actual_size(timer_txt_h) 
 
	local timer_bmp_width, timer_bmp_height = element_get_actual_size(timer_bmp_h) 
 
	timer_width = timer_width + timer_bmp_width 
 
	local x = - timer_width / 2 
 
	vint_set_property(timer_grp_h, "anchor", x, Hud_msg_critical.timer_grp_y) 
 
	 
 
	--Update background size and center to screen... 
 
	local timer_desc_width, timer_desc_height = element_get_actual_size(timer_desc_txt) 
 
	local width = timer_desc_width + 20 
 
	width = max(width, timer_width) 
 
	local critical_bg_width, critical_bg_height = element_get_actual_size(critical_bg_h) 
 
	element_set_actual_size(critical_bg_h, width, critical_bg_height) 
 
end 
 
 
 
function hud_msg_update_voice_msg(b_visible, b_active, s_name) 
 
	--Update voice chat message 
 
	local voice_msg = vint_object_find("voice_msg", Hud_msg_voice_msg_h)  
	local voice_bg = vint_object_find("bg", Hud_msg_voice_msg_h)  
	local voice_bg_msg = vint_object_find("party_msg", Hud_msg_voice_msg_h)  
	vint_set_property(voice_msg, "text_tag", s_name) 
 
	vint_set_property(voice_msg, "visible", b_visible) 
 
	vint_set_property(voice_bg, "visible", b_visible) 
 
	vint_set_property(voice_bg_msg, "text_tag", "VOICE_CHAT") 
 
	vint_set_property(voice_bg_msg, "visible", b_visible) 
 
	if b_active == true then 
 
		vint_set_property(voice_msg, "tint", 255/255, 147/255, 42/255) 
 
	else 
 
		vint_set_property(voice_msg, "tint", 1, 1, 1) 
 
	end 
 
end 
 
 
 
function hud_msg_update_gameplay_msg(di_h) 
 
 
 
	local region_index, priority, text, modifier, fade_time, audio_type, audio_id, icon1, icon2, pc_key = vint_dataitem_get(di_h) 
 
	 
 
	if fade_time == 0 then 
 
		local h = vint_object_find("gameplay_msg_fade_out")  
		vint_set_property(h, "is_paused", true) 
 
		lua_play_anim(vint_object_find("gameplay_msg_fade_in"))  
	else  
 
 
 
		lua_play_anim(vint_object_find("gameplay_msg_fade_out"))  
	end 
 
	 
 
	local use_txt_h = vint_object_find("new_gameplay_txt", Hud_msg_new_gameplay_h)  
	local use_bmp_h = vint_object_find("gameplay_icon", Hud_msg_new_gameplay_h)  
 
 
	--Icon1 is the button image... so set it.. 
 
	if icon1 ~= HUD_MSG_ICON_NONE then 
 
		local icon_bmp = Hud_msg_icons[icon1].bmp 
 
		Hud_msg_gameplay_btn:set_button(icon_bmp, pc_key) 
 
	end 
 
	 
 
	if icon2 == HUD_MSG_ICON_NONE then 
 
		vint_set_property(use_bmp_h, "visible", false) 
 
	else 
 
		local icon_data = Hud_msg_icons[icon2] 
 
		vint_set_property(use_bmp_h, "image", icon_data.bmp) 
 
		vint_set_property(use_bmp_h, "visible", true) 
 
	end 
 
 
 
	vint_set_property(use_txt_h, "text_tag", text) 
 
	vint_set_property(use_txt_h, "visible", true) 
 
	 
 
	local button_x = 0 
 
	local h_w, h_h = Hud_msg_gameplay_btn:get_size() 
 
	local new_button_x = button_x + (h_w * 0.5) + 5 
 
	 
 
	--Update background size and center to screen... 
 
	local w = 0 
 
	local img_w, img_h = element_get_actual_size(use_bmp_h) 
 
	w = w + h_w 
 
	 
 
	Hud_msg_gameplay_btn:set_anchor(new_button_x, 0) 
 
	vint_set_property(use_bmp_h, "anchor", new_button_x + (h_w * 0.5) + (img_w * 0.5) + 3, 0) 
 
	vint_set_property(use_txt_h, "anchor", new_button_x + (h_w * 0.5) + img_w + 5, 0) 
 
	 
 
	h_w, h_h = element_get_actual_size(use_txt_h) 
 
	w = w + h_w + img_w + 20 
 
	 
 
	--set backgorund size of button... 
 
	local bg_h = vint_object_find("new_gameplay_bg")  
	local bg_width, bg_height = element_get_actual_size(bg_h) 
 
	element_set_actual_size(bg_h, w, bg_height) 
 
	 
 
	--Center object to screen... 
 
	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.. 
 
	vint_set_property(Hud_msg_new_gameplay_h, "anchor", Hud_msg_gameplay_start_x - ((w / 2) * scale_x) , Hud_msg_gameplay_start_y) 
 
end 
 
 
 
 
 
-- Test functions 
 
function hud_msg_update_quest_test() 
 
	vint_scriptevent_post( "quest_objective_complete" ,421421, 232, false, false, false) 
 
end 
 
 
 
function hud_msg_update_quest_test2() 
 
	vint_scriptevent_post( "quest_objective_complete" ,421421, 232, false, false, true, true) 
 
end 
 
 
 
function hud_msg_update_quest_test3() 
 
	vint_scriptevent_post( "quest_objective_complete" ,421421, 232, true, false, false) 
 
end 
 
 
 
function hud_msg_update_quest_test4() 
 
	vint_scriptevent_post( "quest_objective_complete" ,421421, 232, false, false, true, false) 
 
end 
 
 
 
function hud_msg_update_quest(cmp_obj_crc, quest_title_crc, quest_completed, show_new_quest_only, coop_new_quest, coop_quest_is_available) 
 
	local q_type 
 
	 
 
	if coop_new_quest == true then 
 
		q_type = HUD_MSG_BACK_COOP_QUEST 
 
	else 
 
		q_type = HUD_MSG_BACK_QUEST_LOG 
 
	end 
 
 
 
	if q_type == HUD_MSG_BACK_QUEST_LOG and show_new_quest_only == false then 
 
		return 
 
	end 
 
	 
 
	hud_msg_back_add( q_type, { cmp_obj_crc, quest_title_crc, quest_completed, show_new_quest_only, coop_new_quest, coop_quest_is_available } )  
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Function hud_msg_update_quest() 
 
-- 
 
-- Displays unique banner on the hud for the following instances: 
 
--		1. Quest complete 
 
--		2. Objective complete 
 
--		3. Coop player started a quest 
 
-- 
 
-- @param cmp_obj_crc					--title of objective that was completed		 
 
-- @param quest_title_crc				--quest title 
 
-- @param quest_completed				--is the entire quest complete? 
 
-- @param show_new_quest_only			--only show the new quest available prompt 
 
-- @param coop_new_quest				--coop player started a new quest 
 
-- @param coop_quest_is_available	--local player can start the coop quest 
 
-- 
 
------------------------------------------------------------------------------- 
 
function hud_msg_update_quest_do(cmp_obj_crc, quest_title_crc, quest_completed, show_new_quest_only, coop_new_quest, coop_quest_is_available) 
 
 
 
	local complete_objective_txt_h = vint_object_find("complete_objective_txt", 0, Hud_msg_doc)  
	local quest_title_txt_h = vint_object_find("quest_title_txt", Hud_msg_quest_grp_h, Hud_msg_doc)  
	local quest_update_txt_h = vint_object_find("quest_update_txt", 0, Hud_msg_doc)  
	local new_mission_txt_h = vint_object_find("new_mission_txt", 0, Hud_msg_doc)  
	local quest_title_label_h = vint_object_find("objective_complete_txt", 0, Hud_msg_doc)  
	local coop_grp_h = vint_object_find("coop_grp", 0, Hud_msg_doc)  
	local coop_join_txt_h = vint_object_find("coop_join_txt", 0, Hud_msg_doc)  
	local strike_img_h = vint_object_find("strike_img", 0, Hud_msg_doc)  
	local coop_btn_back = Vdo_hint_button:new("coop_btn_back", 0, Hud_msg_doc)  
	local press_back_txt_h = vint_object_find("press_back_txt", 0, Hud_msg_doc)  
		 
 
	-- Set coop join button to back button 
 
	coop_btn_back:set_button(CTRL_MENU_BUTTON_BACK) 
 
	 
 
	-- Hide objective complete elmeents 
 
	vint_set_property(complete_objective_txt_h, "visible", false) 
 
	vint_set_property(strike_img_h, "alpha", 0) 
 
	 
 
	-- Hide QUEST COMPLETE/OBJECTIVE COMPLETE text until needed 
 
	vint_set_property(quest_update_txt_h, "visible", false) 
 
	 
 
	-- Hide coop elements 
 
	vint_set_property(coop_grp_h, "visible", false) 
 
	vint_set_property(coop_join_txt_h, "visible", false) 
 
	coop_btn_back:set_visible(false) 
 
	coop_btn_back:set_alpha(0)	 
 
	 
 
	-- Localize and resize press text 
 
	vint_set_property(press_back_txt_h, "text_tag" ,"QUEST_HUD_PRESS") 
 
	resize_text_element(press_back_txt_h, 70)	 
 
	 
 
	-- Resize new msg bar based on new msg txt 
 
	local new_msg_bar_h = vint_object_find("new_msg_bar_img", 0, Hud_msg_doc)  
	local new_msg_txt_h = vint_object_find("new_msg_txt", 0, Hud_msg_doc)  
	local new_msg_bar_width, new_msg_bar_height = element_get_actual_size(new_msg_bar_h) 
 
	local new_msg_txt_width, new_msg_txt_height = element_get_actual_size(new_msg_txt_h) 
 
	local new_msg_txt_x, new_msg_txt_y = vint_get_property(new_msg_txt_h, "anchor") 
 
	local new_msg_bar_x, new_msg_bar_y = vint_get_property(new_msg_bar_h, "anchor") 
 
			 
 
	vint_set_property(new_msg_bar_h, "anchor", new_msg_txt_x + new_msg_txt_width, new_msg_bar_y) 
 
	element_set_actual_size(new_msg_bar_h, 390 - new_msg_txt_width, new_msg_bar_height)	 
 
	 
 
	local new_msg_bar_scale_x, new_msg_bar_scale_y = vint_get_property(new_msg_bar_h, "scale")			 
 
	local bar_anchor_twn_h = vint_object_find("bar_anchor_twn", Hud_msg_quest_anim_h)  
	local bar_scale_out_twn_h = vint_object_find("bar_scale_out_twn", Hud_msg_quest_anim_h)  
	local bar_scale_in_twn_h = vint_object_find("bar_scale_in_twn", Hud_msg_quest_anim_h)  
				 
 
	vint_set_property(bar_anchor_twn_h, "start_value", new_msg_txt_x + new_msg_txt_width + 10, new_msg_bar_y - 10) 
 
	vint_set_property(bar_anchor_twn_h, "end_value", new_msg_txt_x + new_msg_txt_width + 10, new_msg_bar_y) 
 
	vint_set_property(bar_scale_out_twn_h, "start_value", 0, new_msg_bar_scale_y) 
 
	vint_set_property(bar_scale_out_twn_h, "end_value", new_msg_bar_scale_x, new_msg_bar_scale_y) 
 
	vint_set_property(bar_scale_in_twn_h, "start_value", new_msg_bar_scale_x, new_msg_bar_scale_y) 
 
	vint_set_property(bar_scale_in_twn_h, "end_value", 0, new_msg_bar_scale_y) 
 
	 
 
	--Reset end event for each message 
 
	local end_event_twn_h = vint_object_find("coop_quest_end_event_twn", Hud_msg_base_anim_h)		  
	vint_set_property(end_event_twn_h, "end_event", nil) 
 
	 
 
	if coop_new_quest == true then 
 
	 
 
		--COOP PLAYER STARTING A NEW QUEST 
 
		 
 
		local gamertag_txt_h = vint_object_find("gamertag_txt", 0, Hud_msg_doc)  
		local coop_start_txt_h = vint_object_find("coop_start_txt", 0, Hud_msg_doc)  
		 
 
		--Set Gamertag text 
 
		vint_set_property(gamertag_txt_h, "text_tag", "{PARTNER_NAME}")  
		 
 
		--Set "starting new quest" text 
 
		vint_set_property(coop_start_txt_h, "text_tag", "QUEST_COOP_NEW_QUEST_START") 
 
		 
 
		--Set QUEST TITLE to "NOTICE" 
 
		vint_set_property(quest_title_label_h, "text_tag", "MENU_TITLE_NOTICE")	 
 
		 
 
		--Set "(BACK) JOIN GAMERTAG'S QUEST" 
 
		vint_set_property(coop_join_txt_h, "text_tag", "QUEST_COOP_QUEST_JOIN")		 
 
					 
 
		--Shrink text until it fits 
 
		resize_text_element(gamertag_txt_h, 360)						 
 
		resize_text_element(coop_start_txt_h, HUD_QUEST_COMPLETE_MAX_WIDTH)			 
 
		resize_text_element(coop_join_txt_h, 350)				 
 
		 
 
		--Turn on quest group and play anim 
 
		vint_set_property(Hud_msg_quest_grp_h, "visible", true) 
 
		vint_set_property(coop_grp_h, "visible", true) 
 
		 
 
		if game_get_in_progress_type() ~= -1 then 
 
			 
 
			--In active gameplay 
 
			--Play first part of animation then display a tutorial explaining why they can't join 
 
			local end_event_twn_h = vint_object_find("coop_quest_end_event_twn", Hud_msg_base_anim_h)		  
			vint_set_property(end_event_twn_h, "end_event", "hud_msg_quest_new_hide")			 
 
 
 
			game_tutorial_start("coop_quest_busy") 			  
		else 
 
		 
 
			-- It's available, play the full animation			 
 
			vint_set_property(coop_join_txt_h, "visible", true)							 
 
			coop_btn_back:set_visible(true)		 
 
		end 
 
 
 
		-- Play base anim and coop anim 
 
		vint_set_property(Hud_msg_quest_grp_h, "visible", true) 
 
		vint_set_property(Hud_msg_quest_grp_h, "alpha", 1)  
 
 
 
		vint_apply_start_values(Hud_msg_coop_anim_h) 
 
		vint_apply_start_values(Hud_msg_base_anim_h)		 
 
		 
 
		lua_play_anim(Hud_msg_coop_anim_h, 0)		 
 
		lua_play_anim(Hud_msg_base_anim_h, 0) 
 
		ui_audio_post_event("ui_objective_complete")  
 
 
		-- Don't need to start any more anims, return early 
 
		return 
 
	end		 
 
 
 
	-- Determine whether to show quest complete or objective complete	 
 
	if show_new_quest_only == true then 
 
	 
 
		--QUEST COMPLETE 
 
	 
 
		--Set QUEST COMPLETE to localized text		 
 
		vint_set_property(quest_update_txt_h, "text_tag", "QUEST_COMPLETE") 
 
		 
 
		--Set NEW QUEST to localized text 
 
		vint_set_property(new_mission_txt_h, "text_tag", "QUEST_NEW") 
 
		 
 
		--Set QUEST TITLE to localized text		 
 
		vint_set_property(quest_title_label_h, "text_tag", "QUEST_TITLE")	 
 
		 
 
		--Set current quest name 
 
		vint_set_property(complete_objective_txt_h, "text_tag_crc", quest_title_crc)	 
 
				 
 
		--Shrink quest title until it fits		 
 
		resize_text_element(quest_update_txt_h, 340)						 
 
		resize_text_element(complete_objective_txt_h, HUD_QUEST_COMPLETE_MAX_WIDTH)	 
 
		resize_text_element(new_mission_txt_h, 122)			 
 
 
 
		--Set button hint to HUB menu button 
 
		local btn_back = Vdo_hint_button:new("btn_back", 0, Hud_msg_doc)  
		btn_back:set_button(CTRL_MENU_BUTTON_BACK) 
 
		 
 
		local quest_anim_is_paused = vint_get_property(Hud_msg_quest_new_only_h, "is_paused") 
 
		 
 
		--Turn on quest group and play anim 
 
		 
 
		 
 
		-- Skip ahead to new quest tweens 
 
		if show_new_quest_only then 
 
			vint_set_property(Hud_msg_quest_grp_h, "visible", true) 
 
			vint_set_property(Hud_msg_quest_grp_h, "alpha", 1) 
 
			 
 
			local hud_quest_new_grp_h = vint_object_find("new_mission_group", Hud_msg_quest_grp_h, Hud_msg_doc)  
			vint_set_property(hud_quest_new_grp_h, "visible", true) 
 
			vint_set_property(hud_quest_new_grp_h, "alpha", 1) 
 
			 
 
			local hud_quest_obj_grp_h = vint_object_find("complete_group", Hud_msg_quest_grp_h, Hud_msg_doc)  
			vint_set_property(hud_quest_obj_grp_h, "visible", false) 
 
			vint_set_property(hud_quest_obj_grp_h, "alpha", 0) 
 
			 
 
			vint_set_property(complete_objective_txt_h, "visible", false) 
 
			vint_set_property(quest_update_txt_h, "visible", true) 
 
 
 
			--Set the "map" button to open the quest log 
 
			vint_apply_start_values(Hud_msg_quest_new_only_h) 
 
			lua_play_anim(Hud_msg_quest_new_only_h, 0) 
 
			 
 
			Hud_msg_new_quest_displayed = true 
 
		end 
 
	end 
 
end 
 
 
 
 
 
------------------------------------------------------------------------------- 
 
-- Fades out quest update (new quest message is displayed until code cancels it) 
 
-- (this is called via callback from code) 
 
-- 
 
function hud_msg_quest_fade_out() 
 
	--Hud_msg_new_quest_displayed = false 
 
	Hud_msg_back_current = -1 
 
 
 
	lua_play_anim(Hud_msg_quest_out_new_only_h, 0, Hud_msg_doc) 
 
end 
 
 
 
 
 
------------------------------------------------------------------------------- 
 
-- Fades out objective after objective text is displayed. 
 
-- (this is called via callback from tween) 
 
-- 
 
function hud_msg_quest_obj_fade_out() 
 
	lua_play_anim(Hud_msg_base_out_anim_h, 0, Hud_msg_doc) 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Fades out the coop message after objective text is displayed. 
 
-- (this is called via callback from code) 
 
-- 
 
function hud_msg_quest_coop_fade_out() 
 
	--Pause in anim 
 
	vint_set_property(Hud_msg_coop_anim_h, "is_paused", true) 
 
	 
 
	--Play coop and base out anim 
 
	lua_play_anim(Hud_msg_coop_out_anim_h, 0, Hud_msg_doc) 
 
	lua_play_anim(Hud_msg_base_out_anim_h, 0, Hud_msg_doc) 
 
	 
 
	vint_set_property( Hud_msg_quest_grp_h, "visible", false ) 
 
end 
 
 
 
 
 
------------------------------------------------------------------------------- 
 
-- Creates alternate use message by cloning the original use message and its animations. 
 
-- 
 
function hud_msg_create_use_alt() 
 
 
 
	--Clone use message stuff 
 
	Hud_msg_use_alt_h = vint_object_clone(Hud_msg_use_h) 
 
	vint_set_property(Hud_msg_use_alt_h, "visible", true) 
 
	vint_set_property(Hud_msg_use_alt_h, "alpha", 1) 
 
	local x, y = vint_get_property(Hud_msg_use_alt_h, "anchor") 
 
 
 
	--Delete Unused stuff out of the group 
 
	local temp_h = vint_object_find("use_btn_meter_grp", Hud_msg_use_alt_h)  
	vint_object_destroy(temp_h) 
 
	 
 
	temp_h = vint_object_find("tiers_text", Hud_msg_use_alt_h)  
	vint_object_destroy(temp_h) 
 
	 
 
	temp_h = vint_object_find("tiers_text", Hud_msg_use_alt_h)  
	vint_object_destroy(temp_h)	 
 
	 
 
	--temp_h = vint_object_find("use_icon", Hud_msg_use_alt_h)  
	--vint_object_destroy(temp_h) 
 
	 
 
	--shift it so its right below 
 
	vint_set_property(Hud_msg_use_alt_h, "anchor", x, y + HUD_MSG_USE_ALT_OFFSET_VERTICAL) 
 
	 
 
	--Clone animations and retarget... 
 
	Hud_use_msg_alt_fade_in_h = vint_object_clone( vint_object_find("use_msg_fade_in") )  
	Hud_use_msg_alt_fade_out_h = vint_object_clone( vint_object_find("use_msg_fade_out") )  
	 
 
	--Delete Unused fade in tweens 
 
	temp_h = vint_object_find("use_icon_alpha_twn", Hud_use_msg_alt_fade_in_h)  
	vint_object_destroy(temp_h) 
 
	 
 
	temp_h = vint_object_find("use_icon_anchor_twn", Hud_use_msg_alt_fade_in_h)  
	vint_object_destroy(temp_h) 
 
	 
 
	--Retarget animations to base group... 
 
	vint_set_property(Hud_use_msg_alt_fade_in_h, "target_handle", Hud_msg_use_alt_h) 
 
	vint_set_property(Hud_use_msg_alt_fade_out_h, "target_handle", Hud_msg_use_alt_h) 
 
	 
 
	--vint_set_property(Hud_msg_use_alt_h, "visible", false) 
 
end 
 
 
 
function hud_msg_quest_hide(tween_handle, reset_input) 
 
	 
 
	--Anim is done, allow "map" button to return to original action 
 
	Hud_msg_new_quest_displayed = false		 
 
	 
 
	--Stop anim so it's ready for next update	 
 
	vint_set_property(Hud_msg_quest_anim_h, "is_paused", true) 
 
	vint_set_property(Hud_msg_quest_grp_h, "visible", false) 
 
end 
 
 
 
function hud_msg_quest_new_hide(tween_handle, reset_input) 
 
	Hud_msg_new_quest_displayed = false 
 
	 
 
	vint_set_property(Hud_msg_quest_new_only_h, "is_paused", true) 
 
	vint_set_property(Hud_msg_quest_new_only_h, "visible", true) 
 
end  
 
 
 
 
 
------------------------------------------------------------------------------- 
 
-- Fill the circle meter around the button hint 
 
-- 
 
function hud_msg_use_meter_update(meter_pct) 
 
	if meter_pct ~= nil and meter_pct > 0 then 
 
		local use_meter_fill_circle_h = vint_object_find("use_meter_fill_circle")  
		vint_set_property(use_meter_fill_circle_h, "end_angle", meter_pct * 6.28) 
 
		vint_set_property(Hud_msg_use_btn_meter_grp_h, "is_visible", true) 
 
	else 
 
		vint_set_property(Hud_msg_use_btn_meter_grp_h, "is_visible", false) 
 
	end	 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Moves subtitle messages to top of screen 
 
-- 
 
function hud_msg_subtitle_top() 
 
	local anchor_x,anchor_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor") 
 
	local scale_x,scale_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "scale") 
 
	anchor_y = 94 * scale_x 
 
	vint_set_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor", anchor_x, anchor_y) 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Moves subtitle messages to bottom of screen 
 
-- 
 
function hud_msg_subtitle_bottom() 
 
	local anchor_x,anchor_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor") 
 
	local scale_x,scale_y = vint_get_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "scale") 
 
	anchor_y = 561 * scale_x 
 
	vint_set_property(Hud_msg_regions[HUD_REGION_SUBTITLES].anchor, "anchor", anchor_x, anchor_y) 
 
end 
 
 
 
function hud_msg_back_nothing() 
 
end 
 
 
 
HUD_MSG_BACK_QUEST_LOG = 1 
 
HUD_MSG_BACK_COOP_QUEST = 2 
 
HUD_MSG_BACK_REWARDS = 3 
 
 
 
Hud_msg_back_things = {  
	[ HUD_MSG_BACK_QUEST_LOG ]		= { start = hud_msg_update_quest_do, finish = hud_msg_quest_fade_out },  
	[ HUD_MSG_BACK_COOP_QUEST ]	= { start = hud_msg_update_quest_do, finish = hud_msg_quest_coop_fade_out },  
	[ HUD_MSG_BACK_REWARDS ]		= { start = hud_msg_back_nothing, finish = hud_msg_back_nothing },  
} 
 
 
 
Hud_msg_back_queue = { }  
Hud_msg_back_current = -1 
 
Hud_msg_back_thread_handle = -1 
 
Hud_msg_back_is_delayed = false 
 
 
 
function hud_msg_back_add( q_type, params ) 
 
	-- replace existing entry with this one on type match 
 
	local key = nil 
 
	for k,v in pairs( Hud_msg_back_queue ) do 
 
		if v.q_type == q_type then 
 
			key = k 
 
			break 
 
		end 
 
	end 
 
	 
 
	if key == nil then 
 
		key = #Hud_msg_back_queue + 1 
 
	end 
 
	 
 
	Hud_msg_back_queue[ key ] = { q_type = q_type, params = params }  
	 
 
	-- start the thread if needed 
 
	if Hud_msg_back_is_delayed == false and Hud_msg_back_thread_handle == -1 then 
 
		Hud_msg_back_thread_handle = thread_new( "hud_msg_back_thread" ) 
 
	end 
 
end 
 
 
 
function hud_msg_back_resume() 
 
	if Hud_msg_back_is_delayed == false then 
 
		return 
 
	end 
 
	 
 
	Hud_msg_back_is_delayed = false 
 
	 
 
	if Hud_msg_back_thread_handle ~= -1 then 
 
		thread_kill( Hud_msg_back_thread_handle ) 
 
		Hud_msg_back_thread_handle = -1 
 
	end 
 
 
 
	if #Hud_msg_back_queue ~= 0 then 
 
		Hud_msg_back_thread_handle = thread_new( "hud_msg_back_thread" ) 
 
	end 
 
end 
 
 
 
function hud_msg_back_delay() 
 
	if Hud_msg_back_is_delayed == true then 
 
		return 
 
	end 
 
 
 
	if Hud_msg_back_thread_handle ~= -1 then 
 
		thread_kill( Hud_msg_back_thread_handle ) 
 
		Hud_msg_back_thread_handle = -1 
 
	end 
 
 
 
	--HVS_RCK 5/27/14 - There are currently no other messages that get added here to my knowledge. This is causing a problem where it continually re-adds the back_current that tells it to play the anim 
 
	--					This causes the anim to play again every time you close the hub after jumping to challenges from the prompt. 
 
	if Hud_msg_back_current ~= -1 then 
 
		Hud_msg_back_things[ Hud_msg_back_current.q_type ].finish() 
 
	end 
 
 
 
	if Hud_msg_back_current ~= -1 then 
 
		for i = #Hud_msg_back_queue, 1, -1 do 
 
			Hud_msg_back_queue[ i + 1 ] = Hud_msg_back_queue[ i ] 
 
		end 
 
		 
 
		Hud_msg_back_queue[ 1 ] = Hud_msg_back_current 
 
		Hud_msg_back_current = -1 
 
	 end 
 
 
 
	Hud_msg_back_is_coop_join = false 
 
	Hud_msg_back_current = -1 
 
	Hud_msg_back_is_delayed = true 
 
end 
 
 
 
function hud_msg_back_thread() 
 
	while #Hud_msg_back_queue > 0 do 
 
		-- move the top item to the current global 
 
		Hud_msg_back_current = Hud_msg_back_queue[ 1 ] 
 
		Hud_msg_back_is_coop_join = ( Hud_msg_back_current.q_type == HUD_MSG_BACK_COOP_QUEST ) 
 
		 
 
		for i = 2, #Hud_msg_back_queue do 
 
			Hud_msg_back_queue[ i - 1 ] = Hud_msg_back_queue[ i ] 
 
		end 
 
		 
 
		Hud_msg_back_queue[ #Hud_msg_back_queue ] = nil 
 
		 
 
		Hud_msg_back_things[ Hud_msg_back_current.q_type ].start( unpack( Hud_msg_back_current.params ) ) 
 
		 
 
		-- minimum display time 
 
		delay( 6 ) 
 
		 
 
		-- interrupt if something comes up 
 
		-- local c = 17	-- 17 * 0.5 secs = 8.5 secs 
 
		-- while #Hud_msg_back_queue == 0 and c > 0 do 
 
			-- c = c - 1 
 
			-- delay( 0.5 ) 
 
		-- end 
 
		 
 
		Hud_msg_back_things[ Hud_msg_back_current.q_type ].finish() 
 
		Hud_msg_back_is_coop_join = false 
 
		Hud_msg_back_current = -1 
 
		 
 
		delay( 5 ) 
 
	end 
 
	 
 
	Hud_msg_back_thread_handle = -1 
 
end