GameScreen.textures_path = "graphics/screens/03_chief/location/"

GameScreen.hint_table = {
    {obj = {"books_hint", 413, 422}, fun = function() if(GetState("screen_mg_003_books", "state") ~= "finish2" and GetState(CURRENT_SCREEN, "ho") == "completed") then return true end end},
    {obj = {"secret_enter_hint", 431, 475}, fun = function() if(GetState(CURRENT_SCREEN, "book_case") == "moved" and GetState("screen_003_chief", "hint") ~= "true") then return true end end},
    {obj = {"hall_hint", 0, 327}, fun = function() if(GetState("screen_003_chief", "hint") == "true") then return true end end},
}

function GameScreen:RestoreScene()
      if(GetState(CURRENT_SCREEN, "ho") ~= "completed") then
        ------------------------------------------------------------------------------------------------------------------------------ 
        --список возможных предметов для ХО
        local bookcase_click = function()
            SoundPlay("sound/bookcase_door.ogg")
            SetState(CURRENT_SCREEN, "bookcase_door_opened", "true")
            self:RemoveItem("bookcase_door");
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bookcase_door_open", "graphics/screens/03_chief/location/bookcase_door_open", 601, 549);
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "framed_photo_shadow", "graphics/screens/03_chief/location/framed_photo_shadow", 601, 551);
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "framed_photo", "graphics/screens/03_chief/location/framed_photo_part", 612, 592);
        end

        local photo_found = function(this1, _end_fun)
            local wallpaper = clScreenManager:add_screen("wallpaper") 
            wallpaper.no_sound = true;
            wallpaper:ShowWallpaper(self.textures_path.."framed_photo_full", 432, 50)
            ItemRemove(self.name, "framed_photo", 0.2)
            ItemRemove(self.name, "framed_photo_shadow", 0.2)
            HUDScreen:ShowTips({path = "graphics/screens/03_chief/location/text_03c", x = 434, y = 1131, end_fun = _end_fun})
        end

        self.item_list = {
            {obj = {"matches", {x = 761, y = 865}}, inv = "matches_003"},
            {obj = {"cd", {x = 689, y = 1066}}, inv = "cd_003"},
            {obj = {"hand_magnifier", {x = 602, y = 645}}, },
            {obj = {"dictaphone", {x = 342, y = 368}}, },
            {obj = {"camera", {x = 1042, y = 520}}, },
            {obj = {"charger", {x = 313, y = 836}}, },
            {obj = {"compass", {x = 962, y = 753}}, },
            {obj = {"battery", {x = 1408, y = 885}}, },
            {obj = {"bottle_of_pills", {x = 1088, y = 223}}, },
            {obj = {"telephone", {x = 1056, y = 775}}, },
            {obj = {"framed_photo", {x = 605, y = 584}, true}, intaractive = {"bookcase_door", "bookcase_door_hint", 578, 530, bookcase_click}, finding_fun = photo_found},
            {obj = {"penknife", {x = 1078, y = 938}}, },
        }

        local end_fun = function()  
            Inventory:save_tool("matches_003", true)
            Inventory:save_tool("cd_003", true)
            SetState(CURRENT_SCREEN, "ho", "completed")
            
            clApplication.curret_win = clScreenManager:add_screen("tool_found_screen") 
            clApplication.curret_win._resource = "graphics/screens/03_chief/location/object_found_03"
            clApplication.curret_win.end_fun = function()
                Inventory:ToolFound("matches_003", 800, 600)
                DelayedExec(0.5, function()
                    Inventory:ToolFound("cd_003", 800, 600)
                end, 113)                
                HUDScreen:ShowTips({path = "graphics/screens/03_chief/location/text_03a", x = 470, y = 1131})
                self:CreateLocationPortal("books_eye", "mg_003_books", "eye")
            end
        end
        
        DelayedExec(2.0, function()
            self:SetItemCursor("bookcase_door", "eye")
            self:SetMiniGame(mgt_hidden_object)   
            self.mini_game:Init(self.item_list, end_fun);
        end, 113)
        
        HUDScreen:ShowTips({path = "graphics/screens/03_chief/location/text_03", x = 627, y = 1130})
        
        if(GetState(CURRENT_SCREEN, "bookcase_door_opened") == "true") then
            self:RemoveItem("bookcase_door");
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bookcase_door_open", "graphics/screens/03_chief/location/bookcase_door_open", 601, 549);
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "framed_photo_shadow", "graphics/screens/03_chief/location/framed_photo_shadow", 601, 551);
            self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "framed_photo", "graphics/screens/03_chief/location/framed_photo_part", 612, 592);
        end
    end
    
    if(GetState(CURRENT_SCREEN, "ho") == "completed") then
        self:CreateLocationPortal("books_eye", "mg_003_books", "eye")
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bookcase_door_open", "graphics/screens/03_chief/location/bookcase_door_open", 601, 549);
    end
    
    if(GetState(CURRENT_SCREEN, "book_case") == "moved") then
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "secret_light", "graphics/screens/03_chief/location/secret_light", 342, 908);
        ItemSetDepthByOther("secret_light", "bookcase_cover")
        ItemSetDepth("secret_light", LAYERS.ONE_LOWER)
        ItemRemove(self.name, "books_eye")
        ItemSetPosition("bookcase", 590, 267)
        ItemSetPosition("bookcase_door_open", 904, 549)
        self:CreateLocationPortal("secret_enter_eye", "004_secretroom", "eye")
    end
    
    if(GetState("screen_mg_003_books", "state") == "finish") then
        SoundPlay("sound/secret_door.ogg")
        SetState("screen_mg_003_books", "state", "finish2")
        SetState(CURRENT_SCREEN, "book_case", "moved")
        ItemRemove(self.name, "books_eye")
        ItemMove("bookcase", 300, 0, 3.0)
        ItemMove("bookcase_door_open", 300, 0, 3.0)
        self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "secret_light", "graphics/screens/03_chief/location/secret_light", 342, 908);
        ItemSetDepthByOther("secret_light", "bookcase_cover")
        ItemSetDepth("secret_light", LAYERS.ONE_LOWER)
        ItemSetOpacity("secret_light", 0.0)
        ItemChangeOpacity("secret_light", 1.0, 3.0)
        DelayedExec(3.0, function()
            HUDScreen:ShowTips({path = "graphics/screens/03_chief/location/text_03b", x = 671, y = 1130})
            self:CreateLocationPortal("secret_enter_eye", "004_secretroom", "eye")
        end, 113)
    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()
    
    self:RestoreScene()
    
    self:AddHiddenCrystal("crystal_03_part")
    self:SetItemCursor("note_03_part", "eye")
    self:CreateWallpaperPortal("note_03_part", "note_03_full", 430, 228)
    self:SetItemSound("bottle_01", "sound/bottle_06.ogg");
    self:SetItemSound("bottle_02", "sound/bottle_07.ogg");
    self:SetItemSound("stapler", "sound/stapler.ogg");
    self:SetItemSound("printer", "sound/printer.ogg");
    self:SetItemSound("lamp", "sound/lamp_hit_01.ogg");
    self:SetItemSound("clock", "sound/clock_chimes.ogg");
    
    self:CreateLocationPortal("hall_hand", "002_hall", "hand")

    MusicPlay({"sound/ambient/03_ambient.ogg", "sound/music/hospital.ogg"}, 3) 
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "background", "graphics/screens/03_chief/location/03_chief", 0, 0);

    self:CreateObj(OBJ_TYPE.TRIGGER, "secret_enter_eye", "graphics/screens/03_chief/location/secret_enter_eye", 447, 491);
     self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bookcase", "graphics/screens/03_chief/location/bookcase", 287, 267);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bookcase_cover", "graphics/screens/03_chief/location/bookcase_cover", 253, 295);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bookcase_door", "graphics/screens/03_chief/location/bookcase_door_eye", 602, 553);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "books_eye", "graphics/screens/03_chief/location/books_eye", 429, 438);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_02", "graphics/screens/03_chief/location/bottle_02", 1343, 534);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_01", "graphics/screens/03_chief/location/bottle_01", 1288, 572);
    self:CreateObj(OBJ_TYPE.TRIGGER, "stapler", "graphics/screens/03_chief/location/stapler", 1173, 911);
    self:CreateObj(OBJ_TYPE.TRIGGER, "printer", "graphics/screens/03_chief/location/printer", 1018, 765);
    self:CreateObj(OBJ_TYPE.TRIGGER, "clock", "graphics/screens/03_chief/location/clock", 1128, 188);
    self:CreateObj(OBJ_TYPE.TRIGGER, "lamp", "graphics/screens/03_chief/location/lamp", 1185, 717);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "penknife", "graphics/screens/03_chief/location/penknife_part", 1179, 962);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "telephone", "graphics/screens/03_chief/location/telephone_part", 1140, 830);    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "bottle_of_pills", "graphics/screens/03_chief/location/bottle_of_pills_part", 1115, 257);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "battery", "graphics/screens/03_chief/location/battery_part", 1431, 922);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "compass", "graphics/screens/03_chief/location/compass_part", 993, 809);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "charger", "graphics/screens/03_chief/location/charger_part", 371, 881);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "camera", "graphics/screens/03_chief/location/camera_part", 1093, 574);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "dictaphone", "graphics/screens/03_chief/location/dictaphone_part", 382, 404);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "hand_magnifier", "graphics/screens/03_chief/location/hand_magnifier_part", 628, 668);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cd_shadow", "graphics/screens/03_chief/location/cd_shadow", 749, 1091);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "cd", "graphics/screens/03_chief/location/cd_part", 757, 1106);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "matches", "graphics/screens/03_chief/location/matches_part", 813, 903);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_03_part", "graphics/screens/03_chief/location/crystal_03_part", 1253, 667);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "note_03_part", "graphics/screens/03_chief/location/note_03_part", 869, 980);

    self:CreateObj(OBJ_TYPE.TRIGGER, "hall_hand", "graphics/screens/03_chief/location/hall_hand", 0, 341);
    clScreenManager:add_screen("hud") 
end