------------------------------------------------------------------------------
-- 
ACTIVE_ZONES_GLOW_ENABLED = false;

------------------------------------------------------------------------------
-- 
function AssignActiveZonesGlow(...)
    activeZoneGlow = {};	--// {zoneName, {GlowName1st, {GlowName1st, GlowName2nd, GlowName3rd, ...}, ...}, ...}
    activeZoneFnF = {};		--// {zoneName, {GlowName1st, {activityFunctor, effector}}, ...}
	for i,v in ipairs({...}) do
	    local activityFunctor = v[1];
	    local actZoneName = v[2];
	    local firstGlow = v[3];

		assert(table.getn(v) > 2);
		if (activeZoneGlow[actZoneName] == nil) then
	        activeZoneGlow[actZoneName] = {};
	        activeZoneFnF[actZoneName] = {};
        end
	    assert(activeZoneGlow[actZoneName][firstGlow] == nil);
	    activeZoneGlow[actZoneName][firstGlow] = {};

	    activeZoneFnF[actZoneName][firstGlow] = {};
		activeZoneFnF[actZoneName][firstGlow][1] = activityFunctor;
		for j = 3,table.getn(v) do
		    playField:GetObject(v[j]):SetOpacity(0.0);
		    playField:IgnoreOnTestPoint(v[j]);
		    table.insert(activeZoneGlow[actZoneName][firstGlow], v[j]);
		end
	end

	--// (!) ToDo: Move to apropriate place! 8)
	local panelComingUpDelay = 1.0;
	TimerDoString('playField:GetLevelScreen():GetGamePanel():ShowPanel()', panelComingUpDelay, playField:GetTimer());
end

------------------------------------------------------------------------------
-- 
function ActivateActiveZoneGlow(actZoneName)
if (ACTIVE_ZONES_GLOW_ENABLED == false) then
	return;
end

    if (activeZoneGlow == nil) then
        Log("WARNING: Lua: ActivateActiveZoneGlow(): Active zone glows hadn't been defined by AssignActiveZonesGlow() function call");
        return;
    end

    if (activeZoneGlow[actZoneName] == nil) then
		return;
	end
	local zoneGlowGroup = activeZoneGlow[actZoneName];

	for i,glowObjs in pairs(zoneGlowGroup) do
        assert(table.getn(glowObjs) >= 1);
	    local firstGlow = glowObjs[1];
	    
    	for j = 1, table.getn(glowObjs) do
	        assert(activeZoneFnF[actZoneName][firstGlow][1] ~= nil);
	        if (activeZoneFnF[actZoneName][firstGlow][1]() == false ) then --// if glow must be shown
                local glow = playField:GetObject(glowObjs[j]);
			    if (activeZoneFnF[actZoneName][firstGlow][2] == nil) then
    				activeZoneFnF[actZoneName][firstGlow][2] = CreateAnimationEffector();
			    end
                local eff = activeZoneFnF[actZoneName][firstGlow][2];
			    assert(eff ~= nil);
    	        local opacity = glow:GetOpacity();
    	        local duration = 0.75;
			    eff:EraseAllKeys();
                eff:AttachTo(glow);
                eff:SetKey(_TRACK_O, 0.0, 	   (1.0 - opacity) * opacity);
                eff:SetKey(_TRACK_O, duration, 1.0);
                eff:Play();
    	    end
        end
   end --// for i,glowObjs ...
end

------------------------------------------------------------------------------
-- 
function DeactivateActiveZoneGlow(actZoneName)
if (ACTIVE_ZONES_GLOW_ENABLED == false) then
	return;
end

    if (activeZoneGlow == nil) then
        Log("WARNING: Lua: DeactivateActiveZoneGlow(): Active zone glows hadn't been defined by AssignActiveZonesGlow() function call");
        return;
    end

    local fadeDuration = 0.6;
    auxFadeActiveZoneAllGlows(actZoneName, fadeDuration);
end

------------------------------------------------------------------------------
-- 
function DeactivateActiveZoneDeactivatedGlow(actZoneName)
if (ACTIVE_ZONES_GLOW_ENABLED == false) then
	return;
end

    if (activeZoneGlow == nil) then
        Log("WARNING: Lua: DeactivateActiveZoneDeactivatedGlow(): Active zone glows hadn't been defined by AssignActiveZonesGlow() function call");
        return;
    end

    local fadeDuration = 0.6;
    auxFadeActiveZoneDeactivatedGlow(actZoneName, fadeDuration);

	--// tool applying sound
	PlaySound('L99S14');
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- 
function auxFadeActiveZoneAllGlows(actZoneName, duration)
    local zoneGlowGroup = activeZoneGlow[actZoneName];
    if (zoneGlowGroup ~= nil) then
        for i,glowObjs in pairs(zoneGlowGroup) do
            if (glowObjs ~= nil) then
    	        assert(table.getn(glowObjs) >= 1);
    	        local firstGlow = glowObjs[1];
    	        for j = 1, table.getn(glowObjs) do
    	            if (activeZoneFnF[actZoneName][firstGlow][2] ~= nil) then --// if glow was shown ...
            	        local glow = playField:GetObject(glowObjs[j]);
	                    assert(glow ~= nil and activeZoneFnF[actZoneName][firstGlow][2] ~= nil);
                        local eff = activeZoneFnF[actZoneName][firstGlow][2];
			            local opacity = glow:GetOpacity();
			            eff:EraseAllKeys();
    	                eff:SetMode(_ANIM_NOLOOP);
                        eff:AttachTo(glow);
                        eff:SetKey(_TRACK_O, 0.0, 		opacity);
                        eff:SetKey(_TRACK_O, duration,	0.0);
                        eff:Play();
                    end
                end --// for j = ...
            end
        end --// for g = ...
    end --// if (zoneGlowGroup ...
end

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- 
function auxFadeActiveZoneDeactivatedGlow(actZoneName, duration)
    local zoneGlowGroup = activeZoneGlow[actZoneName];
    if (zoneGlowGroup ~= nil) then
        for i,glowObjs in pairs(zoneGlowGroup) do
            if (glowObjs ~= nil) then
    	        assert(table.getn(glowObjs) >= 1);
    	        local firstGlow = glowObjs[1];
    	        for j = 1, table.getn(glowObjs) do
           	        local glow = playField:GetObject(glowObjs[j]);
    	            if (activeZoneFnF[actZoneName][firstGlow][2] ~= nil and
						glow:GetOpacity() > 0.0 and activeZoneFnF[actZoneName][firstGlow][1]() == true) then  --// if glow was shown and now 
																											  --// it's visible but must be hidden...
	                    assert(glow ~= nil and activeZoneFnF[actZoneName][firstGlow][2] ~= nil);
                        local eff = activeZoneFnF[actZoneName][firstGlow][2];
			            local opacity = glow:GetOpacity();
			            eff:EraseAllKeys();
    	                eff:SetMode(_ANIM_NOLOOP);
                        eff:AttachTo(glow);
                        eff:SetKey(_TRACK_O, 0.0, 		opacity);
                        eff:SetKey(_TRACK_O, duration,	0.0);
                        eff:Play();
                    end
                end --// for j = ...
            end
        end --// for g = ...
    end --// if (zoneGlowGroup ...
end
