class 'l_fish' (ZoomEventHandler)

function l_fish:__init(name)
    ZoomEventHandler.__init(self, name)
    
    self.scales = {}
    self.scale_angles = {['cancer']=0.89, ['owl']=0.89, ['deer']=0.89, ['sun']=1, ['horse']=1,
						['seadragon']=1.17, ['rose']=1.17, ['conch']=1.17, ['shell']=1.22, ['tree']=1.22,
						['crow']=1.22, ['fish']=1.78, ['tulip']=1.78, ['crown']=1.52, ['crab']=1.78,
						['eagle']=1.62, ['fishes']=1.72, ['turtle']=2.22, ['star']=2.22, ['dragon']=2.20}
	self.current_scale = ''
    
    local scale_vector = ParseDirectory(PATH_SCALES)
    
    for i = 0, scale_vector:size() - 1 do
		local name = string.sub(ExtractFileName(scale_vector:get(i)), 7, -1)
		Object('fmg_'..name):Hide()
		self.level.custom_cursors['fmg_'..name] = 'CursorActive'
		table.insert(self.scales, name)
    end
end

function l_fish:OnOpen()
	-- hides not founded scales ---------------------------------------
	local vecTools = ParseDirectory(PATH_SCALES)
	for scale in each(self.scales) do
		if IsScaleFound(scale) then
			Object('fmg_'..scale):Show()
		end
	end

    if not self.close_button then
        self.close_button = ScriptCreateButton(Object('fmg_bttn_close'), 'CloseButton', play_field:GetLevelScreen())
        self.close_button:AttachTo(Object('fmg_background'))
        self.close_button:SetXY(425,-237)
        self.close_button:SetZ(2000)
    end    
    
    Object('fmg_bttn_close'):SetVisible(true)
    Object('fmg_bttn_close'):SetOpacity(.1)
end

function l_fish:OnClose()
end

function l_fish:OnUpdate()
end

function l_fish:OnButtonPress(title)
    if title == 'CloseButton' then
        self.zone:Close()
    end
end

function l_fish:OnDefaultMouseMove(previous_pos, current_pos)
    local distance = math.sqrt(math.abs(current_pos.x-118)^2+math.abs(current_pos.y-516)^2)
    Object('fmg_eyes'):SetOpacity(1-(distance/1200))
end

function l_fish:OnObjectMouseEnter(object)
    if object:GetName()=='fmg_bttn_close' or  object:GetName()=='fmg_jaw' then
        Object('fmg_jaw'):SetAngle(-.1)
    end
end

function l_fish:OnObjectMouseLeave(object)
    if object:GetName()=='fmg_bttn_close' or  object:GetName()=='fmg_jaw' then
        Object('fmg_jaw'):SetAngle(0)
    end
end

function l_fish:OnObjectMouseDown(object)
	if play_field:HasObject('zoomed_scale') then
		local eff = CreateAnimationEffector()
		eff:SetDestroysOnEnd(true)
		eff:AttachTo(play_field:GetObject('zoomed_scale'))
		eff:SetKey(_TRACK_SX, 0, 1.2)
		eff:SetKey(_TRACK_SY, 0, 1.2)
		eff:SetKey(_TRACK_SX, .2, .4)
		eff:SetKey(_TRACK_SY, .2, .4)
		eff:SetKey(_TRACK_A, 0, 0)
		eff:SetKey(_TRACK_A, .2, self.scale_angles[self.current_scale])
		eff:Play()
		
		self.timer:Add(function() play_field:DeleteObject('zoomed_scale') end, .2)

	elseif self.level.custom_cursors[object:GetName()] == 'CursorActive' then
		self.current_scale = string.sub(object:GetName(), 5, -1)
		
		local obj = play_field:CreateObject('zoomed_scale', CreateAnimationByTextureName(PATH_SCALES..'scale_'..self.current_scale..'.png'), object:GetX(), object:GetY()+70, 200, 0, 1, 1)
		obj:AttachTo(Object('fmg_background'))
		
		local eff = CreateAnimationEffector()
		eff:SetDestroysOnEnd(true)
		eff:AttachTo(obj)
		eff:SetKey(_TRACK_SX, 0, .4)
		eff:SetKey(_TRACK_SY, 0, .4)
		eff:SetKey(_TRACK_SX, .2, 1.2)
		eff:SetKey(_TRACK_SY, .2, 1.2)
		eff:SetKey(_TRACK_A, 0, self.scale_angles[self.current_scale])
		eff:SetKey(_TRACK_A, .2, 0)
		eff:Play()
		
		ShowBlackBar('SCALE_'..string.upper(self.current_scale))
	end
end
--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_fish:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/GUI/Fish/background.jpg',0,0,889,515,1,0)
	anim:SetHotSpot(444,257)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_background',anim,512,317,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/frame.png',0,0,980,622,1,0)
	anim:SetHotSpot(490,311)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_frame',anim,517,331,102,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/eyes.png',0,0,22,12,1,0)
	anim:SetHotSpot(11,6)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_eyes',anim,118,516,200,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/jaw.png',0,0,50,34,1,0)
	anim:SetHotSpot(38,6)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_jaw',anim,924,94,200,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/bttn_close.png',0,0,62,66,3,0)
	anim:SetHotSpot(31,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_bttn_close',anim,930,86,230,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/shadow.png',0,0,228,246,1,0)
	anim:SetHotSpot(114,123)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_shadow',anim,650,318,150,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/cancer.png',0,0,107,108,1,0)
	anim:SetHotSpot(53,54)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_cancer',anim,655,297,135,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/conch.png',0,0,90,91,1,0)
	anim:SetHotSpot(45,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_conch',anim,564,463,127,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/crab.png',0,0,64,66,1,0)
	anim:SetHotSpot(32,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_crab',anim,374,397,119,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/crow.png',0,0,79,84,1,0)
	anim:SetHotSpot(39,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_crow',anim,494,479,124,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/crown.png',0,0,68,77,1,0)
	anim:SetHotSpot(34,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_crown',anim,430,478,121,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/deer.png',0,0,99,99,1,0)
	anim:SetHotSpot(49,49)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_deer',anim,571,269,130,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/eagle.png',0,0,67,74,1,0)
	anim:SetHotSpot(33,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_eagle',anim,377,461,120,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/fish.png',0,0,70,71,1,0)
	anim:SetHotSpot(35,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_fish',anim,401,349,120,-11,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/fishes.png',0,0,62,62,1,0)
	anim:SetHotSpot(31,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_fishes',anim,339,429,118,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/horse.png',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_horse',anim,631,435,130,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/owl.png',0,0,102,102,1,0)
	anim:SetHotSpot(51,51)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_owl',anim,689,382,133,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/rose.png',0,0,90,91,1,0)
	anim:SetHotSpot(45,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_rose',anim,535,396,128,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/seadragon.png',0,0,90,91,1,0)
	anim:SetHotSpot(45,45)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_seadragon',anim,514,322,127,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/seastar.png',0,0,59,60,1,0)
	anim:SetHotSpot(29,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_seastar',anim,327,389,116,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/shell.png',0,0,79,84,1,0)
	anim:SetHotSpot(39,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_shell',anim,457,357,124,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/dragon.png',0,0,54,55,1,0)
	anim:SetHotSpot(27,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_dragon',anim,307,347,115,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/sun.png',0,0,105,104,1,0)
	anim:SetHotSpot(52,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_sun',anim,600,350,132,6,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/tree.png',0,0,82,88,1,0)
	anim:SetHotSpot(41,44)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_tree',anim,474,420,125,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/tulip.png',0,0,70,77,1,0)
	anim:SetHotSpot(35,38)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_tulip',anim,415,413,123,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Fish/Layers/turtle.png',0,0,60,59,1,0)
	anim:SetHotSpot(30,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fmg_turtle',anim,357,339,117,-7,1.05,1.05)
	
end
-- CLEAR_ON_SAVE_END
