pMap = GetBoolParam("map", true)
pQuicksave = GetBoolParam("quicksave", true)

hintDt = 0.0167

function init()
	time = 0
	mapTime = 0
	
	usedMap = false
	
	mapNotification = false
	saveNotification = false
end


function notify(str)
	SetString("hud.notification", str)
	SetInt("hud.notification.numicons", 0)
end

function notifyIcon1(fmt, str)
	SetString("hud.notification", fmt)
	SetInt("hud.notification.numicons", 1)
	SetString("hud.notification.icon1", str)
end

function notifyIcon4(fmt, str1, str2, str3, str4)
	SetString("hud.notification", fmt)
	SetInt("hud.notification.numicons", 4)
	SetString("hud.notification.icon1", str1)
	SetString("hud.notification.icon2", str2)
	SetString("hud.notification.icon3", str3)
	SetString("hud.notification.icon4", str4)
end

function tick(dt)
	local missionDone = (time > 60 * hintDt and not GetBool("level.alarm") and GetBool("level.complete"))
	local alarm = GetBool("level.alarm")

	--Track game state
	if not usedMap and GetBool("game.map.enabled") then 
		usedMap = true 
	end
	if GetBool("game.paused") then
		return
	end
	
	--Generic hints. Only show if no other notifications are showing.
	if pMap then
		if not GetBool("hud.hasnotification") then
			if (math.floor(time / hintDt) % 1500 == 300) and not usedMap and not missionDone and not alarm then
				local s = GetString("game.input.map.icon")
				if s ~= "" then
					notifyIcon1(GetTranslatedStringByKey("PRESS_TO_TOGGLE,#"), s)
				else
					s = string.upper(GetString("game.input.map"))
					notify(GetTranslatedStringByKey("PRESS_TO_TOGGLE," .. s))
				end
			end
		end
	end

	if pQuicksave and not GetBool("hud.hasnotification") then
		if (time > 4000 * hintDt) and usedMap and not saveNotification and not missionDone and not alarm then
			local s = GetString("game.input.pause.icon")
			if s ~= "" then
				notifyIcon1(GetTranslatedStringByKey("SAVE_YOUR_PROGRESS,#"), s)
			else
				s = string.upper(GetString("game.input.pause"))
				notify(GetTranslatedStringByKey("SAVE_YOUR_PROGRESS," .. s))
			end
			saveNotification = true
		end
	end
	
	if GetBool("game.map.enabled") then
		mapTime = mapTime + dt
		if mapTime > 60 * hintDt and not mapNotification then
			local s1 = GetString("game.input.rmb.icon")
			local s2 = GetString("game.input.lmb.icon")
			local s3 = "$gamepad_right_stick"
			if s1 ~= "" and s2 ~= "" then
				notifyIcon4(GetTranslatedStringByKey("DRAG_AND_ZOOM,#"), s1, s2, s3, "")
			else
				notify(GetTranslatedStringByKey("DRAG_AND_ZOOM,loc@TXT_MOUSE"))
			end
			mapNotification = true
		end
	end

	if missionDone and not GetBool("game.map.enabled") then
		if math.floor(time / hintDt) % 600 == 0 then
			notify(GetTranslatedStringByKey("MISSION_ACCOMPLISHED"))
		end
	end
end


function update(dt)
	if GetBool("game.paused") or GetBool("game.map.enabled") then
		return
	end
	time = time + dt
end
