dofile('data/Scripts/Scenes/Common.lua');

------------------------------------------------------------------------------
--
function OnSceneLoad(restoringFromSave)
	InitGameState();

	play_field = playField;
    LoadData();
	play_field = nil;

    RootZoomZone = CreateZoomZone('RootZoomZone', nil, 
                                   nil, 0.0, 
                                   nil, 0.0,
							{'RootBackground'},

							{});


	SetZoneVisible(RootZoomZone, true, false);

	do
	    playField:IgnoreOnTestPoint('ToBeContinued');
		do
		    local text = CreateTextEntity('GUIFont','');
		    text:SetText(GetTextString('END_OF_SURVEY_BUILD'));
		    text:AttachTo(playField:GetObject('ToBeContinued'));
		    text:SetXY(0.0, --[[SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0]] - 135.0);
		    text:SetZ(1.0);
		end
		do
		    local text = CreateTextEntity('GUIFont','');
		    text:SetText(GetTextString('END_OF_SURVEY_BUILD'));
		    text:AttachTo(playField:GetObject('ToBeContinued'));
		    text:SetXY(0.0, --[[SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0]] - 135.0);
			text:SetColor('0xFFFFDD00');
		    text:SetZ(2.0);

		    local duration = 2.0;
		    local eff = CreateAnimationEffector();
		    eff:AttachTo(text);
		    eff:SetMode(HGEANIM_FWD + HGEANIM_LOOP);
		    eff:SetKey(_TRACK_O,  duration*0.0,		1.0);
		    eff:SetKey(_TRACK_O,  duration*0.25,	0.5);
		    eff:SetKey(_TRACK_O,  duration*0.5,		0.05);
		    eff:SetKey(_TRACK_O,  duration*0.75,	0.5);
		    eff:SetKey(_TRACK_O,  duration*1.0,		1.0);  
		    eff:Play();
		end
		CreateCloseAppButton(playField:GetObject('ToBeContinued'));
	end
end

------------------------------------------------------------------------------
--
function OnSceneFree()
    FreeData()
end

--// Local auxiliary functions - - - - - - - - - - - - - - - - - - - - - - - -
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
--
function OnDialogButtonPress(name, param)
end

------------------------------------------------------------------------------
--
function OnUpdate(dt)
    DefaultOnUpdate(dt);
end

------------------------------------------------------------------------------
--
function OnWin()
--	DefaultOnWin();
end

------------------------------------------------------------------------------
--
function OnObjectMouseEnter(object)
    local objectName = object:GetName();

    DefaultOnObjectMouseEnter(object);
	ActivateActiveZoneGlow(objectName);
end

------------------------------------------------------------------------------
--
function OnObjectMouseLeave(object)
    local objectName = object:GetName();

    DefaultOnObjectMouseLeave(object);
    DeactivateActiveZoneGlow(objectName);
end

------------------------------------------------------------------------------
--
function OnObjectMouseDown(object)
    local objectName = object:GetName();
    local isWrongClick = true;

	assert(gameState.activeZone ~= nil and gameState.locker:GetNReferences() > 0);

    if (gameState.lockedObjects[objectName] ~= true) then
        if (gameState.activeZone.HasObject(objectName)) then
            isWrongClick = DefaultOnZoomZoneActiveObjectClick(objectName);

			--// ...

	        if (isWrongClick == true and playField:GetLevelScreen():IsTaskObject(objectName)) then
	            auxAttachInPlace(object, playField);
				object:ResetClippingRect();
				--// remove object from zoom-zone which contents it
				assert(gameState.activeZone.objects[objectName] ~= nil);
				gameState.activeZone.objects[objectName] = nil;

                playField:OnObjectFound(object);
                isWrongClick = false;
            end
        else
--			assert(gameState.activeZone ~= RootZoomZone and 
--				   gameState.locker:GetNReferences() > 1 and
--				   'Attempt to close root scene - you have clicked on an object which hasn`t been added to any zoom-zone');
            if (gameState.activeZone ~= RootZoomZone and gameState.locker:GetNReferences() > 1) then
                if (gameState.lockedObjects[gameState.activeZone.activeObject] == nil) then
                    SetZoneVisible(gameState.activeZone, false);
                end
            else
                Log('Lua: OnObjectMouseDown(\''..objectName..'\'): Was made click on object which hasn`t been attached to any zoom-zone');
            end
        end --// if (gameState.activeZone.HasObject(...
    end --// if (gameState.lockedObjects[...

	--// Tips - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
--	if (objectName == 'actZoneSarcophagusKey2') then
--	    playField:GetLevelScreen():ShowTip(GetTextString('LEVEL1_SARCOPHAGUS_TIP1'), ...);
--	elseif (objectName == 'ZoomGateLockBackground') then
--		...
--	else
--	    playField:GetLevelScreen():HideTip();
--	end
	--//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    DefaultOnObjectClick(object, isWrongClick, not playField:GetLevelScreen():IsTipShown());
    DefaultOnObjectMouseEnter(object);
end

------------------------------------------------------------------------------
--
function OnObjectMouseUp(object)
end

------------------------------------------------------------------------------
--
function OnObjectFound(object)
    local objectName = object:GetName();
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	local objectMustBeHighlighted = DefaultOnObjectFound(object);
	return objectMustBeHighlighted;
end

------------------------------------------------------------------------------
--
function OnToolFound(tool)
end

------------------------------------------------------------------------------
--
function CanToolBeApplied(tool, object)
	local toolName = tool:GetName();
	local objName = object:GetName();
    local canToolBeApplied = true;
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	canToolBeApplied = DefaultCanToolBeApplied(tool, object);
	return canToolBeApplied;
end

------------------------------------------------------------------------------
--
function OnToolApply(tool, object)
	local toolName = tool:GetName();
	local objName = object:GetName();
    local toolApplied = false;

	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    DefaultOnObjectMouseEnter(object);
	if (toolApplied == true) then
	    DeactivateActiveZoneDeactivatedGlow(object:GetName());
	end
	return toolApplied;
end

------------------------------------------------------------------------------
--
function OnObjectReachPanel(object)
    local objectName = object:GetName();
end

------------------------------------------------------------------------------
--
function OnButtonPress(zoneName)
	if (zoneName == 'MSG_CLOSE_APPLICATION') then
		GetGameApp():Shutdown(true);
	end
    DefaultOnButtonPress(zoneName);
end

------------------------------------------------------------------------------
--
function OnMouseMove(prevMousePos, currentMousePos)
end

------------------------------------------------------------------------------
--
function OnSetTool(tool)
end

------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData()
	local anim = CreateAnimation('data/Texture/Scenes/06_AtCollapsedAirship/Layers/background.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('RootBackground',anim,512,384,99,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/ToBeContinued.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	play_field:CreateObject('ToBeContinued',anim,512,384,1999,0,1,1)
end

function FreeData()
end
-- CLEAR_ON_SAVE_END
