
.namespace area_clsp

g_reloadtime=120

function OnEnable()
	--Area.OnEnable()
	if UserData.IsEqual("expertMode",false) then
		self.g_reloadtime = Gameplay.RELOADING_SKIP
	else
		self.g_reloadtime = Gameplay.RELOADING_SKIP_EXPERT
	end
	
	now2=0
	first=0
	second=0
	counter=0
	areaclsptime=0
	areaclspstart=0
	local lang = DebugOptions.curlanguage
	skip_btn.Image = "media/common/graph/interface/close-up/skip_active_"..lang..".png|media/common/graph/interface/close-up/skip_inactive_"..lang..".png"
--	exit_bubble.Image = "media/common/graph/interface/close-up/exit_"..lang..".png"
--	rules_bubble.Image = "media/common/graph/interface/close-up/rules_"..lang..".png"
--	reload_bubble.Image = "media/common/graph/interface/close-up/reload_"..lang..".png"
	exit_bubble_txt.Text =  GlobalFunctions.GetText("int_pzl_close")
	rules_bubble_txt.Text = GlobalFunctions.GetText("int_pzl_rules")
	reload_bubble_txt.Text = GlobalFunctions.GetText("int_pzl_retry")
	no_exit_s = {	"s06_c01", "s10_c01", "s10_c02", "s13_c01"	}
	no_exit = false
	close_up_exit.Color.a = 255
	i=1
	for i=i,4 do
		if GetCurrentManager().Name == no_exit_s[i] then
			no_exit = true
			close_up_exit.Color.a = 100
		end
	end
	
	
end

function OnWbpMouseLUp()
	if not self.CanClickOn() then
		return
	end
	OPLog.Log("onactivate "..self.Name)
	
	if self.Name == "close_up_exit" then 
		if no_exit == true then
			return
		end	
		NavigationManager.RestorePreviousManager()
		interfaceclsp.Enabled = false
		exit_bubble.Flags_Visible = false
		rules_bubble.Flags_Visible = false
		reload_bubble.Flags_Visible = false	
		self.Image = "media/common/graph/interface/close-up/close-up_exit.png"
		
	end
	if self.Name == "close_up_rules" then 
		SequencePlayer.PlaySequence("AI_"..GetCurrentManager().Name,self,nil,"help")
	end	
	if gamestart==true then
		
		if self.Name == "skip_btn" and skip_progress.Position_X >= 0 then --and fond_crayon.Scale_X > 1.4 then
				PopupManager.OpenPopupYN("msg_ig_skip",nil)
				

			end
		end
		
		
		if self.Name == "close_up_reload" then
			GetCurrentManager().Reset()

	end
end

function OnMouseOn()
	if not self.CanClickOn() then
		return
	end
	if self.Name == "close_up_exit" then 
		if no_exit == true then
			return
		end	
		self.Image = "media/common/graph/interface/close-up/close-up_exit_hl.png"
		exit_bubble.Flags_Visible = true
	end
	if self.Name == "close_up_rules" then 
		rules_bubble.Flags_Visible = true
		self.Image = "media/common/graph/interface/close-up/close-up_rules_hl.png"
	end
	if self.Name == "close_up_reload" then 
		reload_bubble.Flags_Visible = true
		self.Image = "media/common/graph/interface/close-up/close-up_reset_hl.png"	
	end	
end
function OnMouseOff()

	if self.Name == "close_up_exit" then 
		if no_exit == true then
			return
		end	
		exit_bubble.Flags_Visible = false
		self.Image = "media/common/graph/interface/close-up/close-up_exit.png"
	end
	if self.Name == "close_up_rules" then 
		rules_bubble.Flags_Visible = false
		self.Image = "media/common/graph/interface/close-up/close-up_rules.png"
	end
	if self.Name == "close_up_reload" then 
		reload_bubble.Flags_Visible = false	
		self.Image = "media/common/graph/interface/close-up/close-up_reset.png"
	end	
end
function OnUpdate(dt)
	
	if gamestart==false then
		skip_btn.SetFrame(1)
	end
	
	if gamestart==true then
		
		if areaclspstart == 0 then
			areaclsptimestart = OPTime.GetTime()
			areaclspstart = 1
		elseif areaclspstart == 1 then
			areaclsptime = OPTime.GetTime() - areaclsptimestart
		end
		
		--counter = counter + dt
		if skip_progress.Position_X < 1 then
			skip_progress.Position_X=-154+(154/self.g_reloadtime)*areaclsptime
			skip_btn.SetFrame(1)
		else
			skip_btn.SetFrame(0)
		end
		-- if first==0 then
			-- close_up_reset.Enabled = true
			-- fond_skip.Enabled = true
			-- fond_crayon.Scale_X=0
			-- first=1
		-- end
		
		-- if fond_crayon.Scale_X < 1.4 and deltatime < 1 then
			-- fond_crayon.Scale_X=fond_crayon.Scale_X + ((1.4*deltatime)/45)
		-- end
	end
end



function GetSpecificCursor()
	return CURSOR_AREA
end

function CanClickOn()
	return IsEqualVariables("CurrentGamePhase","SearchSite") 
	or IsEqualVariables("CurrentGamePhase","Closeup") 
	or (IsEqualVariables("CurrentGamePhase","Tutorial") and NewTutorialManager.g_state == "waitopenlocation")
end

