GameScreen.textures_path = "graphics/screens/22_soup/location/"

function GameScreen:RestoreScreen()
    ------------------------------------------------------------------------------------------------------------------------------ 
    --Первая загрузка екрана
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "") then
        --стартовый диалог
        clScreenManager:add_screen("hud")   
        ItemSetOpacity(HUDScreen.name, 0.0)
    
        local comics_finish = function()
            SetState(CURRENT_SCREEN, "ho", "active")
            ItemChangeOpacity(HUDScreen.name, 1.0, 0.5)
            DelayedExec(1.0, function()
                self:StartHO();
            end, 113)
        end
        local comics = clScreenManager:add_screen("022_cook_dlg") 	
        comics.on_finish = comics_finish;
    end
    ------------------------------------------------------------------------------------------------------------------------------ 
    --ХО
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "active") then
        self:StartHO();
    end
    ------------------------------------------------------------------------------------------------------------------------------ 
    --после ХО
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "completed") then
        clApplication:LoadLocation("023_wine")
    end
  
    for found_item in string.gmatch(GetState(CURRENT_SCREEN, "found_obj"), "[_%a%d]+") do
		ItemRemove(self.name, found_item)
		ItemRemove(self.name, found_item.."_shadow")
    end 
end

function GameScreen:InitScreen()
    self:LoadScreen()
   
    ------------------------------------------------------------------------------------------------------------------------------ 
    --OTHER       
    self:SetItemSound("knife", "sound/big_knife.ogg");
    self:SetItemSound("jug", "sound/ceramic_pot_01.ogg");
    self:SetItemSound("green_pot", "sound/green_pot.ogg");
    self:SetItemSound("metal_pot", "sound/pot_hit.ogg");
    self:SetItemSound("bottle_01", "sound/bottle_05.ogg");
    self:SetItemSound("big_black_pot", "sound/big_black_pot.ogg");
    
    --self.music_id = SoundPlay("sound/ambient/22_24_26_ambient.ogg", true)
    --MusicPlay({"sound/ambient/kitchen_fire.ogg", "sound/music/past.ogg"} , 22) 
    
    MusicPlay({"sound/ambient/22_24_26_ambient.ogg", "sound/music/past.ogg"} , 22) 
    --self:sound_loop();
    
    self:AddHiddenCrystal("crystal_22_part")
    
    self:RestoreScreen()
end

function GameScreen:sound_loop()
    self.music_id = SoundPlay("sound/ambient/kitchen_fire.ogg", true)
    local len = GetSoundLenght(self.music_id)
    DelayedExec(len, function()
        self.music_id2 = SoundPlay("sound/music/past.ogg", true)
        local len2 = GetSoundLenght(self.music_id2)
        DelayedExec(len, function()
            self:sound_loop();
        end, 113)
    end, 113)
end

function GameScreen:StartHO()    
    self.item_list = {
        {obj = {"salt", {x = 398, y = 581}}},
        {obj = {"cucumber", {x = 1019, y = 933}}},
        {obj = {"cabbage", {x = 1437, y = 876}}, hint = {x = 1495, y = 876}},
        {obj = {"potato", {x = 459, y = 722}}},
        {obj = {"carrot", {x = 1448, y = 361}}},
        {obj = {"bellpepper", {x = 777, y = 927}}},
        {obj = {"mushroom", {x = 4, y = 638}}},
        {obj = {"onion", {x = 1275, y = 966}}},
        {obj = {"dill", {x = 181, y = 74}}}, 
        {obj = {"beet", {x = 1176, y = 705}}},
        {obj = {"cheese", {x = 79, y = 99}}},
        {obj = {"bread", {x = 560, y = 165}}},
     }
    
    local on_finish = function()
        HUDScreen:SetInvntoryOnlyMode()
        SetState(CURRENT_SCREEN, "ho", "completed");
        self.mini_game = nil;
        local tip_end = function()
            DelayedExec(1.0, function()
                clApplication:LoadLocation("023_wine")
            end, 113)
        end
        DelayedExec(1.0, function()
            HUDScreen:ShowTips({path = self.textures_path.."Text_22", x = 311, y = 1112, end_fun = tip_end})
        end, 113)
    end       
    
    clScreenManager:add_screen("hud")                  
    self:SetMiniGame(mgt_hidden_object)   
    self.mini_game:Init(self.item_list, on_finish);
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:UnLoadScreen()
    StopSound(self.music_id)
	cpp_application_remove_window(self.name);
	self.win = false;
end
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "22_soup", "graphics/screens/22_soup/location/22_soup", 0, 0);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "knife", "graphics/screens/22_soup/location/knife", 879, 598);
    self:CreateObj(OBJ_TYPE.TRIGGER, "jug", "graphics/screens/22_soup/location/jug", 1148, 579);
    self:CreateObj(OBJ_TYPE.TRIGGER, "green_pot", "graphics/screens/22_soup/location/green_pot", 973, 509);
    self:CreateObj(OBJ_TYPE.TRIGGER, "metal_pot", "graphics/screens/22_soup/location/metal_pot", 911, 637);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_01", "graphics/screens/22_soup/location/bottle_01", 758, 641);
    self:CreateObj(OBJ_TYPE.TRIGGER, "big_black_pot", "graphics/screens/22_soup/location/big_black_pot", 113, 440);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_22_part", "graphics/screens/22_soup/location/crystal_22_part", 514, 1060);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cucumber", "graphics/screens/22_soup/location/cucumber_part", 1074, 965);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cabbage", "graphics/screens/22_soup/location/cabbage_part", 1515, 886);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bread", "graphics/screens/22_soup/location/bread_part", 595, 202);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cheese", "graphics/screens/22_soup/location/cheese_part", 107, 115);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "dill", "graphics/screens/22_soup/location/dill_part", 214, 117);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "onion", "graphics/screens/22_soup/location/onion_part", 1291, 988);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mushroom", "graphics/screens/22_soup/location/mushroom_part", 58, 669);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bellpepper", "graphics/screens/22_soup/location/bellpepper_part", 820, 951);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "carrot", "graphics/screens/22_soup/location/carrot_part", 1446, 405);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "potato", "graphics/screens/22_soup/location/potato_part", 482, 746);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "salt", "graphics/screens/22_soup/location/salt_part", 443, 639);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "beet", "graphics/screens/22_soup/location/beet_part", 1238, 730);
    
    --clScreenManager:add_screen("hud") 
end