class 'ToolFoundScreenBase' (BaseScreen)

function ToolFoundScreenBase:__init(name)
	BaseScreen.__init(self, name)

	self.toolInfo	= nil
	self.icon		= nil
	self.iconScale	= 0.8
	self.pGameScene	= current_scene
	self.affectedPF	= nil
	self.bNeedHideZoomFade = false

	self:getWindow():getHotkeySignal(ERSK_ESCAPE):add(createInGameMenu)
	self:setupButtons()
	
	self.pGameScene:setToolFoundScreen(self)
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:setupButtons()
	local okButton = self:getEntityNamed('OKButton')
	local onPress  = bind(self.onPress, self)

	okButton.onPress:add(onPress)
	okButton:setSFXTrackOnPress(getCommonSoundEntity('ButtonClick'))

	self.fadeObject:setRespondable(true)
	self.fadeObject.onPress:add(onPress)
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:setToolInfo(toolInfo)
	self.toolInfo = toolInfo

	local iconAnchor = self:getEntityNamed('ToolAnchor')
	local textEntity = self:getEntityNamed('MessageTxt')

	self.icon = toolInfo:createInfoIconEntity()
	self.icon:attachTo( iconAnchor )
	self.icon:setScale( self.iconScale )
	
	textEntity:setText( toolInfo:getInfoText() )
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:setAffectedPlayfield(playfield)
	if playfield then
		if (not self.affectedPF) or (not rawequal(self.affectedPF, playfield)) then
			self.affectedPF = playfield
			self.affectedPF:getMouseBlocker():push()
			self.affectedPF:hideZoomZones()
		end
	else
		if self.affectedPF then
			self.affectedPF:showHiddenZoomZones()
			self.affectedPF:getMouseBlocker():pop()
			self.affectedPF = nil
		end
	end
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:show(time)
	local playfield = self.pGameScene:getPlayField()
	local zoomFade	= playfield:getZoomFade()
	local zoomFadeOpacity = zoomFade:getOpacity()

	BaseScreen.show(self, time)
	self.pGameScene:go()

	playCommonSound('ToolFound')
	self:setAffectedPlayfield( playfield )

	if zoomFadeOpacity > 0 then
		zoomFade:setVisible(true)
		zoomFade:setOpacity(zoomFadeOpacity)
		zoomFade:destroyEffectors()

		self.bNeedHideZoomFade = true
	end
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:_activateMe()
	BaseScreen._activateMe(self)

	if self.bNeedHideZoomFade then
		self.bNeedHideZoomFade = false

		local zoomFade = self.affectedPF:getZoomFade()
		if zoomFade:isVisible() then
			local eff = zoomFade:ChangeOpacity(nil, 0, self.defaultShowHideTime)

			eff.onFinish:add(function()
								zoomFade:setVisible(false)
							 end)
		end
	end
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:destroyScreen()
	if self.bNeedHideZoomFade then
		self.bNeedHideZoomFade = false
		
		local zoomFade = self.affectedPF:getZoomFade()
		if zoomFade:isVisible() then
			zoomFade:setOpacity(0)
			zoomFade:setVisible(false)
		end
	end

	BaseScreen.destroyScreen(self)
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:go()
	BaseScreen.go(self)
	self.pGameScene:go()
end
-------------------------------------------------------------------------------

function ToolFoundScreenBase:stop()
	BaseScreen.stop(self)
	self.pGameScene:stop()
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- EVENTS ---------------------------------------------------------------------
-------------------------------------------------------------------------------

function ToolFoundScreenBase:onPress(target, screenFocus)
	PopUpScreensMgr:pop()
	self.pGameScene:setToolFoundScreen(nil)
	self:setAffectedPlayfield( nil )

	local inventory = self.pGameScene:getInventory()
	inventory:moveInfoIconToInventory(self.icon, self.toolInfo)

	local soundName = string.format('ObjectFly_%d', math.random(2))
	playCommonSound(soundName)

	if self.toolInfo.on_tool_window_close then
		self.toolInfo.on_tool_window_close()
	end
end
-------------------------------------------------------------------------------