GameScreen.textures_path = "graphics/screens/16_tunnel/location/"

function GameScreen:RestoreScene()
    if(GetState(CURRENT_SCREEN, "state") == "") then
        SetState(CURRENT_SCREEN, "state", "ho")
        local tip_end = function()
            self:StartHO();
        end
        HUDScreen:ShowHintText({path = "graphics/screens/16_tunnel/location/Hint_16", x =  406, y = 1128, end_fun = tip_end, loop = true})
    elseif(GetState(CURRENT_SCREEN, "state") == "ho") then
        local tip_end = function()
            self:StartHO();
        end
        HUDScreen:ShowHintText({path = "graphics/screens/16_tunnel/location/Hint_16", x =  406, y = 1128, end_fun = tip_end, loop = true})
    elseif(GetState(CURRENT_SCREEN, "state") == "completed") then   
        clApplication:LoadLocation("017_city")
    end
    
    for found_item in string.gmatch(GetState(CURRENT_SCREEN, "found_obj"), "[_%a%d]+") do
		ItemRemove(self.name, found_item)
		local object = self:get_item_by_name(found_item);
		if(object) then
		    self:CreateObj(OBJ_TYPE.NO_ACTIVE, object.affix[1], self.textures_path..object.affix[1], object.affix[2].x, object.affix[2].y); 
		end
    end 
end

------------------------------------------------------------------------------------------------------
function GameScreen:get_item_by_name(item_name)
    for key, value in pairs(self.item_list) do
        if(value.obj[1] == item_name) then
            return value
        end
    end
    
    return nil;
end

function GameScreen:InitScreen()
    self:LoadScreen()       
    
    local ball_apply_fun = function()
    end 
     
    self.item_list = {
        {obj = {"tree", {x = 12, y = 543}}, affix = {"tree_affix", {x = 1127, y = 31}}, where = "grass_zone"},
        {obj = {"football", {x = 693, y = 428}}, affix = {"football_affix", {x = 646, y = 67}}, where = "grass_zone"},
        {obj = {"fish", {x = 0, y = 752}}, affix = {"fish_affix", {x = 862, y = 1128}}, where = {"water_zone"}},
        {obj = {"banana", {x = 94, y = 675}}, affix = {"banana_affix", {x = 101, y = 788}}},
        {obj = {"wheel", {x = 487, y = 840}}, affix = {"wheel_affix", {x = 1148, y = 853}}},
        {obj = {"flowers", {x = 1068, y = 733}}, affix = {"flowers_affix", {x = 983, y = 33}}, where = "grass_zone"},
        {obj = {"satellite", {x = 127, y = 49}}, affix = {"satellite_affix", {x = 153, y = 14}}, where = "space_zone"},
        {obj = {"rabbit", {x = 1483, y = 544}}, affix = {"rabbit_affix", {x = 743, y = 6}}, where = "grass_zone"},
        {obj = {"shovel", {x = 57, y = 149}}, affix = {"shovel_affix", {x = 807, y = 41}}, where = "grass_zone"},
        {obj = {"tennis", {x = 514, y = 1064}}, affix = {"tennis_affix", {x = 966, y = 24}}, where = "grass_zone"},
        {obj = {"moon", {x = 1320, y = 795}}, affix = {"moon_affix", {x = 35, y = 68}}, where = "space_zone"},
        {obj = {"lifebuoy", {x = 298, y = 49}}, affix = {"lifebuoy_affix", {x = 922, y = 954}}, where = {"water_zone"}},
    }

            
    self:RestoreScene();
    
    self:AddHiddenCrystal("crystal_16_part")
    
    self:SetItemSound("car", "sound/engine_start.ogg");
    self:SetItemSound("train", "sound/train.ogg");
    self:SetItemSound("water_zone", "sound/creek_splash.ogg");
    
    MusicPlay({"sound/ambient/16_ambient.ogg", "sound/music/surreal.ogg"} , 16) 
end

function GameScreen:StartHO()
    local ho_end = function()
        HintTest:RemoveLoop()
        Tip:RemoveLoop()
        SetState(CURRENT_SCREEN, "state", "handle_push") 
        HUDScreen:SetInvntoryOnlyMode()
        DelayedExec(1.5, function()
            clApplication:LoadLocation("017_city")
        end, 113)
    end
        
        
    self:SetMiniGame(mgt_find_and_apply)  
    mgt_find_and_apply:SetSuccessSound("sound/interface/found.ogg")
    mgt_find_and_apply:SetFailSound("sound/interface/wrong.ogg") 
    self.mini_game:Init(self.item_list, ho_end, true);
end

function GameScreen:OnFinish()
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "16_tunnel", "graphics/screens/16_tunnel/location/16_tunnel", 0, 0);
    self:CreateObj(OBJ_TYPE.TRIGGER, "car", "graphics/screens/16_tunnel/location/car", 1158, 527);
    self:CreateObj(OBJ_TYPE.TRIGGER, "train", "graphics/screens/16_tunnel/location/train", 575, 491);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "space_zone", "graphics/screens/16_tunnel/location/space_zone", 0, 0);
    self:CreateObj(OBJ_TYPE.TRIGGER, "water_zone", "graphics/screens/16_tunnel/location/water_zone", 132, 867);
    self:CreateObj(OBJ_TYPE.TRIGGER, "grass_zone", "graphics/screens/16_tunnel/location/grass_zone",452, 0);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_16_part", "graphics/screens/16_tunnel/location/crystal_16_part", 1396, 915);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "tree", "graphics/screens/16_tunnel/location/tree_part", 156, 105);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fish", "graphics/screens/16_tunnel/location/fish_part", 31, 537);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "banana", "graphics/screens/16_tunnel/location/banana_part", 105, 684);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "wheel_shadow", "graphics/screens/16_tunnel/location/wheel_shadow", 1194, 905);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "wheel", "graphics/screens/16_tunnel/location/wheel_part", 618, 924);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "flowers", "graphics/screens/16_tunnel/location/flowers_part", 1094, 747);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "satellite", "graphics/screens/16_tunnel/location/satellite_part", 1034, 947);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "rabbit", "graphics/screens/16_tunnel/location/rabbit_part", 1508, 571);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "shovel", "graphics/screens/16_tunnel/location/shovel_part", 2, 223);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "tennis", "graphics/screens/16_tunnel/location/tennis_part", 531, 1083);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "moon", "graphics/screens/16_tunnel/location/moon_part", 1342, 816);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lifebuoy", "graphics/screens/16_tunnel/location/lifebuoy_part", 309, 61);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "football", "graphics/screens/16_tunnel/location/football_part", 710, 444);


    self:CreateObj(OBJ_TYPE.TRIGGER, "banana_where", "graphics/screens/16_tunnel/location/banana_affix", 101, 788);
    self:CreateObj(OBJ_TYPE.TRIGGER, "wheel_where", "graphics/screens/16_tunnel/location/wheel_affix",1148, 853);

    clScreenManager:add_screen("hud")    
end   