GameScreen.textures_path = "graphics/screens/01_ward/location/"

GameScreen.hint_table = {
    {obj = {"door_hint", 644, 320}, fun = function() if(GetState(CURRENT_SCREEN, "ho") == "completed") then return true end end}
}

function GameScreen:RestoreScreen()
    ------------------------------------------------------------------------------------------------------------------------------ 
    --Первая загрузка екрана
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "") then
        --стартовый диалог        
        DelayedExec(1.0, function()
            local comics_finish = function()
                local end_tutor_fun = function()    
                    ItemSetType("crystal_01", OBJ_TYPE.ACTIVE_ALL)
                    SetState(CURRENT_SCREEN, "ho", "active")
                end 
                
                self:StartHO();     
                ItemSetType("crystal_01", OBJ_TYPE.NO_ACTIVE)
                
                DelayedExec(1.0, function()
                    self:ShowTutorial(0, end_tutor_fun);
                end, 113) 
            end
            local comics = clScreenManager:add_screen("001_eve_dlg") 	
            comics.on_finish = comics_finish;
            --comics:FadeOut(0.8);
        end, 113)
    end
    ------------------------------------------------------------------------------------------------------------------------------ 
    --ХО
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "active") then
        self:StartHO();
    end
    ------------------------------------------------------------------------------------------------------------------------------ 
    --после ХО
    ------------------------------------------------------------------------------------------------------------------------------ 
    if(GetState(CURRENT_SCREEN, "ho") == "completed") then
        self:CreateLocationPortal("door_hand", "mg_001_patch", "hand")
    end
  
    if(GetState("screen_mg_001_patch", "completed") == "true") then
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ward_return", self.textures_path.."ward_return", 520, 624);
        self:CreateObj(OBJ_TYPE.TRIGGER, "door_hand2", self.textures_path.."door_hand", 663, 338);
        self:CreateLocationPortal("door_hand2", "002_hall", "hand")
        ItemRemove(self.name, "door_hand")
    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 
   
    self:CreateWallpaperPortal("note_in_the_table", "note_01_full", 429, 216)
    self:SetItemCursor("note_in_the_table", "eye")
    self:SetItemCursor("note_01", "eye")
end

function GameScreen:InitScreen()
    self:LoadScreen()
   
    ------------------------------------------------------------------------------------------------------------------------------ 
    --OTHER      
    for i = 1, 5 do
        self:SetItemSound("bottle_0"..i, "sound/bottle_0"..i..".ogg")
    end  
    self:SetItemSound("lamp_hit", "sound/lamp_hit.ogg");
    self:SetItemSound("ward_can", "sound/ward_can.ogg");
    self:SetItemSound("xray_01", "sound/xray_01.ogg");
    self:SetItemSound("xray_02", "sound/xray_02.ogg");
    self:SetItemSound("bedpan", "sound/bedpan.ogg");
    
    CreateZoneParticles(self, "background", "gfx/01_dust.lua");
    
    self:UpdateRay();
    
    MusicPlay({"sound/music/hospital.ogg", "sound/ambient/01_04_31_ambient.ogg"} , 1) 
    
    self:RestoreScreen()
    
    self.items_for_wrong_click = {"drawer_eye", "background", "bottle_01", "bottle_02", "bottle_03", "bottle_04",
                                    "bottle_05", "lamp_hit", "ward_can", "xray_01", "xray_02", "door_hand"}
                                    
end
------------------------------------------------------------------------------------------------------
function GameScreen:is_wrong_item(item_name)
    for key, value in pairs(self.items_for_wrong_click) do
        if(item_name == value) then
            return true;
        end
    end
    
    return false
end
------------------------------------------------------------------------------------------------------
function GameScreen:StartHO()     
    self.click_calc = true
    self.click_amount = 0;
    
    if(GetState(CURRENT_SCREEN, "click_calc") == "false") then
        self.click_calc = false
    else
        self.click_calc = true
        self.click_amount = 0;
    end
    
    local crystal_found = function(this1, end_fun)
        SetState("GLOBAL", "crystal", "1")
        SoundPlay("sound/interface/crystal.ogg")
        ItemRemove(self.name, "crystal_01")
        
        local is_obj = HUDScreen:CreateObj(OBJ_TYPE.NO_ACTIVE, "crystal_full", "graphics/interface/hud/crystal_full", 512, 384);    
            
        if(is_obj == true) then            
            ItemSetPosition("crystal_full", WINDOW_WIDTH / 2 - ItemGetWidth("crystal_full") / 2, WINDOW_HEIGHT / 2 - ItemGetHeight("crystal_full") / 2)
        end

        ItemAttachChild(HUDScreen:GetName(), "crystal_full")
        EffectorPlay(item_found_eff, "crystal_full", false)
        
        DelayedExec(0.8, function()
            CurrentScreen:RemoveItem("crystal_full", 0.3)
        end, 113)
        
        DelayedExec(0.8, function()
            self:ShowTutorial(4, end_fun);
        end, 113)
    end
    
    local screwdriver_found = function(this1, end_fun)
        SoundPlay("sound/interface/found.ogg")
        
        HUDScreen:CreateObj(OBJ_TYPE.ACTIVE, "screwdriver_full", "graphics/screens/01_ward/zoom1/screwdriver_full", 500, 500);    
        --ItemRemove(self.name, item_name)    
        
        ItemSetPosition("screwdriver_full", WINDOW_WIDTH / 2 - ItemGetWidth("screwdriver_full") / 2, WINDOW_HEIGHT / 2 - ItemGetHeight("screwdriver_full") / 2)
        
        ItemAttachChild(HUDScreen:GetName(), "screwdriver_full")
        
        EffectorPlay(item_found_eff, "screwdriver_full", false)
        
        DelayedExec(1.5, function()
            local end_tutor = function()
                Inventory:ToolFound("screwdriver_001", WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0.7)
                end_fun();
            end 
            
            self:ShowTutorial(2, end_tutor);
            HUDScreen:RemoveItem("screwdriver_full")
        end, 113)
        
        CurrentScreen:ZoomDisable()
    end
    
    self.item_list = {
        {obj = {"pill", {x = 420, y = 1134}}},
        {obj = {"belt", {x = 120, y = 261}}},
        {obj = {"sneaker_02", {x = 134, y = 542}}, },
        {obj = {"sneaker_01", {x = 635, y = 949}}, },
        {obj = {"jacket", {x = 905, y = 766}}, },
        {obj = {"syringe", {x = 559, y = 522}}, },
        {obj = {"wallet", {x = 940, y = 1006}}, },
        {obj = {"cellphone", {x = 997, y = 209}}, },
        {obj = {"watch", {x = 786, y = 150}}, },
        {obj = {"jeans", {x = 977, y = 6}}, },
        {obj = {"note_01", {x = 260, y = 751}}, wallpaper = {"note_01_full", 429, 216}},
        {obj = {"crystal_01", {x = 1305, y = 400}}, finding_fun = crystal_found},
        {obj = {"screwdriver", {x = 558, y = 422}},  zoom = {"001_ward_zoom_table", "drawer_hint", 466, 726}, inv = "screwdriver_001"},
    }
    
    local on_finish = function()
        SetState(CURRENT_SCREEN, "ho", "completed");
        Inventory:save_tool("screwdriver_001", true)
       
        clApplication.curret_win = clScreenManager:add_screen("tool_found_screen") 
        clApplication.curret_win._resource = "graphics/screens/01_ward/location/object_found_01"
        clApplication.curret_win.end_fun = function()
            Inventory:ToolFound("screwdriver_001", 800, 600)
            DelayedExec(2.0, function()
                local end_tutor = function()
                    DelayedExec(1.0, function()
                        self:CreateLocationPortal("door_hand", "mg_001_patch", "hand");
                        self.mini_game = nil;

                        HUDScreen:ShowTips({path = self.textures_path.."text_01", x = 627, y = 1131})
                    end, 113)
                end 
                self:ShowTutorial(2, end_tutor);
             end, 113)
        end
    end       
                      
    self:SetMiniGame(mgt_hidden_object)   
    self.mini_game:Init(self.item_list, on_finish);
    self:ZoomZoneLink("drawer_eye", "001_ward_zoom_table");
  
end
------------------------------------------------------------------------------------------------------
function GameScreen:onObjectClick(item_name)
    if(item_name == "door_hand" and GetState(CURRENT_SCREEN, "ho") ~= "completed") then
        SoundPlay("sound/ward_door.ogg")
    end
    
    if(GetState("GLOBAL", "click_calc") == "" and GetState(CURRENT_SCREEN, "ho") ~= "") then
        if(self.click_amount) then
            if(item_name == "background") then
                self.click_amount = self.click_amount + 1
                if(self.click_amount >= 3) then
                    self:ShowTutorial(5);
                    SetState("GLOBAL", "click_calc", "false")
                    self.click_calc = false;
                end
            else
                self.click_amount = 0
            end
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:tool_for_found(item_name)
    for key, value in pairs(self.item_list) do
        if(item_name == value.obj[1]) then
            return true;
        end
    end
    
    return false
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:UpdateRay()
    local time = math.random(200) / 100 + 0.5;
    ItemChangeOpacity("rays_1", math.random(200) / 1000 + 0.2, time)
    
    DelayedExec(time, function()
        if(CurrentScreen.name ~= "001_ward") then return end
        self:UpdateRay()
    end, 113)
end
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "background", self.textures_path.."01_ward", 0, 0);

    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_01", self.textures_path.."bottle_01", 133, 556);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_02", self.textures_path.."bottle_02", 362, 645);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_03", self.textures_path.."bottle_03", 583, 663);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_04", self.textures_path.."bottle_04", 252, 965);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_05", self.textures_path.."bottle_05", 179, 729);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "lamp_hit", self.textures_path.."lamp_hit", 784, 209);
    self:CreateObj(OBJ_TYPE.TRIGGER, "ward_can", self.textures_path.."ward_can", 220, 513);
    self:CreateObj(OBJ_TYPE.TRIGGER, "xray_01", self.textures_path.."xray_01", 952, 365);
    self:CreateObj(OBJ_TYPE.TRIGGER, "xray_02", self.textures_path.."xray_02", 327, 1001);
self:CreateObj(OBJ_TYPE.TRIGGER, "bedpan", self.textures_path.."bedpan", 290, 1137);
  
    self:CreateObj(OBJ_TYPE.TRIGGER, "door_hand", self.textures_path.."door_hand", 663, 338);
    self:CreateObj(OBJ_TYPE.ACTIVE, "pill", self.textures_path.."pill_part", 463, 1162);
    self:CreateObj(OBJ_TYPE.ACTIVE, "belt", self.textures_path.."belt_part", 225, 288);
    self:CreateObj(OBJ_TYPE.ACTIVE, "sneaker_02", self.textures_path.."sneaker_02_part", 163, 555);
    self:CreateObj(OBJ_TYPE.ACTIVE, "sneaker_01", self.textures_path.."sneaker_01_part", 644, 972);
    self:CreateObj(OBJ_TYPE.ACTIVE, "sneaker_01_shadow", self.textures_path.."sneaker_01_shadow", 644, 1007);
    self:CreateObj(OBJ_TYPE.ACTIVE, "jacket_shadow", self.textures_path.."jacket_shadow", 1003, 748);
    self:CreateObj(OBJ_TYPE.ACTIVE, "jacket", self.textures_path.."jacket_part", 1012, 884);
    self:CreateObj(OBJ_TYPE.ACTIVE, "syringe", self.textures_path.."syringe_part", 576, 585);
    self:CreateObj(OBJ_TYPE.ACTIVE, "wallet", self.textures_path.."wallet_part", 979, 1045);
    self:CreateObj(OBJ_TYPE.ACTIVE, "cellphone", self.textures_path.."cellphone_part", 1016, 332);
    self:CreateObj(OBJ_TYPE.ACTIVE, "watch", self.textures_path.."watch_part", 845, 188);
    self:CreateObj(OBJ_TYPE.ACTIVE, "jeans", self.textures_path.."jeans_part", 995, 26);
    
    self:CreateObj(OBJ_TYPE.ACTIVE, "note_in_the_table", self.textures_path.."note_01_part", 230, 765);
 
    self:CreateObj(OBJ_TYPE.ACTIVE, "note_01", self.textures_path.."note_01_part", 230, 765);
    self:CreateObj(OBJ_TYPE.ACTIVE, "crystal_01", self.textures_path.."crystal_01_part", 1365, 459);
 
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "rays_1", self.textures_path.."ray_1", 97, 135);
    ItemSetOpacity("rays_1", 0.4)
 
    self:CreateObj(OBJ_TYPE.TRIGGER, "drawer_eye", self.textures_path.."drawer_eye", 544, 740);
    
    clScreenManager:add_screen("hud")   
end