GameScreen.textures_path = "graphics/screens/02_hall/location/"

GameScreen.hint_table = {
    --{obj = {"ward_number_hint", 1410, 285}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "first_visit") then return true end end},
    {obj = {"stand_hint", 953, 278}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "mg") then return true end end},
    {obj = {"card_reader_hint", 218, 497}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "chief1") then return true end end, tool = "card_002"},    
    {obj = {"chief_door_hint", 14, 117}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "chief2") then return true end end},
    {obj = {"security_door_hint", 344, 291}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "security") then return true end end, tool = "security_key_004"},
    {obj = {"elevator_button_hint", 826, 492}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "elevator" and GetState(CURRENT_SCREEN, "button_click") ~= "true") then return true end end},
    {obj = {"elevator_hint", 538, 340}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "open_lift") then return true end end},
}
	
	indicator_eff = {
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 0.0, time = 0.5, end_value = 0.2},
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 0.5, time = 0.5, end_value = 0.8},
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 1.0, time = 0.5, end_value = 0.2},
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 1.5, time = 0.5, end_value = 0.8},
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 2.0, time = 0.5, end_value = 0.2},
	    {key=EFFECTOR_MODIFIER.KEY_OPACITY, start_time = 2.5, time = 0.5, end_value = 0.8},
    }


function GameScreen:RestoreScreen()
    
    if(GetState(CURRENT_SCREEN, "state") ~= "")then
        self:SetItemCursor("note_02_part", "eye")
        self:CreateWallpaperPortal("note_02_part", "note_02_full", 430, 18)
        self:AddHiddenCrystal("crystal_02_part")
        MusicPlay({"sound/ambient/02_ambient.ogg", "sound/music/hospital.ogg"}, 2) 
    else
        MusicPlay({"sound/ambient/02_intro.ogg"}, 2.1) 
        DelayedExec(10.0, function()
            MusicPlay({"sound/ambient/02_ambient.ogg", "sound/music/hospital.ogg"}, 2) 
        end, 113)
    end
    
    if(GetState(CURRENT_SCREEN, "state") ~= "") then
        self:CreateLocationPortal("ward_door_hand", "001_ward", "hand")
    end
    if(GetState(CURRENT_SCREEN, "state") == "") then
       --[[ self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "for_comics", "graphics/trigger", 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
        ItemSetOpacity("for_comics", 0.01)
        
        SetState(CURRENT_SCREEN, "state", "first_visit")
        local tip_end = function()
            ItemRemove(self.name, "for_comics")
            comics_finish = function()
                self.comics = nil;
                self:SetItemCursor("ward_number_eye", "eye")
                self:CreateWallpaperPortal("note_02_part", "note_02_full", 430, 18)
                self:AddHiddenCrystal("crystal_02_part")
            end
            self.comics = clScreenManager:add_screen("002_eve_dlg") 	
            self.comics.on_finish = comics_finish;
        end
        
        HUDScreen:ShowTips({path = self.textures_path.."text_02", x = 325, y = 1130, end_fun = tip_end})--]]
        comics_finish = function()
            SetState(CURRENT_SCREEN, "state", "mg")
            self:SetItemCursor("note_02_part", "eye")
            self:CreateWallpaperPortal("note_02_part", "note_02_full", 430, 18)
            self:AddHiddenCrystal("crystal_02_part")
            ItemRemove(self.name, "ward_number_eye")
            DelayedExec(1.0, function()
                self:CreateLocationPortal("stand_eye", "mg_002_stand", "eye")
                self:CreateLocationPortal("ward_door_hand", "001_ward", "hand")
            end, 113)
        end
        local comics = clScreenManager:add_screen("002_eve_dlg") 
        comics.on_finish = comics_finish;
    --elseif(GetState(CURRENT_SCREEN, "state") == "first_visit") then
    --    self:SetItemCursor("ward_number_eye", "eye")
    elseif(GetState(CURRENT_SCREEN, "state") == "mg") then
        self:CreateLocationPortal("stand_eye", "mg_002_stand", "eye")
    elseif(GetState(CURRENT_SCREEN, "state") == "chief1") then
        self:CreateObj(OBJ_TYPE.TRIGGER, "card_reader_eye", "graphics/screens/02_hall/location/card_reader_eye", 228, 459);
        ItemSetScale("card_reader_eye", 2.0, 2.0)
        --self:SetItemCursor("card_reader_eye", "eye")
        local card_apply = function()
            SetState(CURRENT_SCREEN, "state", "chief2")
            ItemRemove(self.name, "card_reader_eye")
            Inventory:ActiveToolApply()
            PlaySfx("sound/beep.ogg")
            SetState(CURRENT_SCREEN, "chief", "open")
            self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
            self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
        end
         self:AddToolApplyZone("card_reader_eye", "card_002", card_apply, true);
            
        --self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
    elseif(GetState(CURRENT_SCREEN, "state") == "chief2") then
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
    elseif(GetState(CURRENT_SCREEN, "state") == "security") then
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
            
        HUDScreen:ShowTips({path = self.textures_path.."text_02b", x = 317, y = 1130})
        
        if(GetState(CURRENT_SCREEN, "security") == "open") then
            self:RemoveItem("security_door_hand")
            self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
        else
            self:SetItemCursor("security_door_hand", "hand")
            local key_apply = function()
                Inventory:ActiveToolApply()
                ItemSetPosition("security_door_hand", 1000, 1000)
                --self:RemoveItem("security_door_hand")
                PlaySfx("sound/security_key.ogg")
                SetState(CURRENT_SCREEN, "security", "open")
                self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
            end
            self:AddToolApplyZone("security_door_hand", "security_key_004", key_apply, true);
        end
    elseif(GetState(CURRENT_SCREEN, "state") == "elevator") then
        self:RemoveItem("security_door_hand")
        self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
            
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_indicator", "graphics/screens/02_hall/location/elevator_indicator", 619, 254)
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_button_on", "graphics/screens/02_hall/location/elevator_button_on", 844, 545);
        self:CreateObj(OBJ_TYPE.TRIGGER, "elevator_button_hand", "graphics/screens/02_hall/location/elevator_button_hand", 834, 500);
        self:SetItemCursor("elevator_button_hand", "hand")
        EffectorPlay(indicator_eff, "elevator_indicator", true)
        
    --[[elseif(GetState(CURRENT_SCREEN, "state") == "finish") then
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_indicator", "graphics/screens/02_hall/location/elevator_indicator", 619, 254)
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_button_on", "graphics/screens/02_hall/location/elevator_button_on", 844, 545);
        self:CreateObj(OBJ_TYPE.TRIGGER, "elevator_button_hand", "graphics/screens/02_hall/location/elevator_button_hand", 834, 500);
        self:SetItemCursor("elevator_button_hand", "hand")
        EffectorPlay(indicator_eff, "elevator_indicator", true)--]]
    elseif(GetState(CURRENT_SCREEN, "state") == "open_lift") then
        self:RemoveItem("security_door_hand")
        self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
            
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_indicator", "graphics/screens/02_hall/location/elevator_indicator", 619, 254);
        self:CreateLocationPortal("elevator_hand", "002_elevator", "hand")
        EffectorPlay(indicator_eff, "elevator_indicator", true)
        ItemSetPosition("elevator_door_left", 549-100, 348)
        ItemSetPosition("elevator_door_right", 665+100, 349)
        ItemSetPosition("elevator_open", 552, 748 - 400)
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
    elseif(GetState(CURRENT_SCREEN, "state") == "elev_closing") then
        self:RemoveItem("security_door_hand")
        self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
            
        ItemRemove(self.name, "elevator_hand")
        ItemSetPosition("elevator_door_left", 549-100, 348)
        ItemSetPosition("elevator_door_right", 665+100, 349)
        ItemSetPosition("elevator_open", 552, 748 - 400)
        ItemMoveTo("elevator_door_left", 549, 348, 2.0)
        ItemMoveTo("elevator_door_right", 665, 348, 2.0)
        
        ItemRemove(self.name, "security_door_hand2")
        ItemRemove(self.name, "chief_door_hand")
        ItemRemove(self.name, "ward_door_hand")
        ItemRemove(self.name, "note_02_part")

        DelayedExec(3.0, function()
            SoundPlay("sound/elevator_movement.ogg")
            ItemMoveTo("elevator_open", 552, 538, 3.0)
            SetState(CURRENT_SCREEN, "state", "finish")
            DelayedExec(2.0, function()
                SetState("screen_chapters_screen", "current_chapter", "2")
                clApplication:LoadLocation("chapters_screen")
            end, 113)
        end, 113)
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
    elseif(GetState(CURRENT_SCREEN, "state") == "finish") then
        self:RemoveItem("security_door_hand")
        self:CreateLocationPortal("security_door_hand2", "005_security", "hand")
            
        self:CreateLocationPortal("chief_door_hand", "003_chief", "hand")
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "green_light", "graphics/screens/02_hall/location/green_light", 241, 514);
        clApplication:LoadLocation("chapters_screen")
    end
end
	
function GameScreen:InitScreen()
    self:LoadScreen()
    SetVisibleCursor(true)
    
    self:RestoreScreen();
    --[[
    local ward_click = function()
        if(GetState(CURRENT_SCREEN, "state") == "first_visit") then
            SetState(CURRENT_SCREEN, "state", "mg")
            ItemRemove(self.name, "ward_number_eye")
            self:CreateLocationPortal("stand_eye", "mg_002_stand", "eye")
            self.comics = clScreenManager:add_screen("002_eve_dlg2")
            self.comics.on_finish = comics_finish;
        end
    end
    self:ItemSetAction("ward_number_eye", ward_click)--]]

    local button_click = function()
        SetState(CURRENT_SCREEN, "button_click", "true")
        ItemRemove(self.name, "elevator_button_hand")
        ItemMoveTo("elevator_open", 552, 348, 3.0)
        SoundPlay("sound/elevator_button.ogg")
        SetState(CURRENT_SCREEN, "state", "open_lift")
        DelayedExec(0.5, function()
            SoundPlay("sound/elevator_movement.ogg")
        end, 113)
        DelayedExec(5.0, function()
            ItemMoveTo("elevator_door_left", 449, 348, 2.0)
            ItemMoveTo("elevator_door_right", 765, 348, 2.0)
            SoundPlay("sound/elevator_arrive.ogg")
            DelayedExec(3.0, function()
                self:CreateLocationPortal("elevator_hand", "002_elevator", "hand")
                --self:CreateObj(OBJ_TYPE.TRIGGER, "elevator_hand", "graphics/screens/02_hall/location/elevator_hand", 546, 348);
                --self:SetItemCursor("elevator_hand", "hand")
            end, 113)
        end, 113)
    end    
    self:ItemSetAction("elevator_button_hand", button_click)
        --[[
    local elevator_click = function()
        ItemRemove(self.name, "elevator_hand")
        ItemMoveTo("elevator_door_left", 549, 348, 2.0)
        ItemMoveTo("elevator_door_right", 665, 348, 2.0)

        DelayedExec(3.0, function()
            SoundPlay("sound/elevator_movement.ogg")
            ItemMoveTo("elevator_open", 552, 538, 3.0)
            DelayedExec(2.0, function()
                SetState("screen_chapters_screen", "current_chapter", "2")
                clApplication:LoadLocation("chapters_screen")
            end, 113)
        end, 113)
    end    
    self:ItemSetAction("elevator_hand", elevator_click)
        --]]
    
    self:SetItemSound("glass", "sound/glass_tap.ogg");
    self:SetItemSound("bedpan", "sound/bedpan.ogg");
        
    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.click_calc = true
    self.click_amount = 0;
end

function GameScreen:onObjectClick(item_name)
    if(item_name == "security_door_hand") then
        if(GetState(CURRENT_SCREEN, "security") ~= "open")then
            SoundPlay("sound/security_door.ogg")
            HUDScreen:ShowTips({path = "graphics/screens/02_hall/location/Text_02e", x = 783, y = 1129})
        else
            SoundPlay("sound/chief_door_open.ogg")
        end
    end
    if(item_name == "chief_door_hand") then
        if(GetState(CURRENT_SCREEN, "chief") ~= "open")then
            SoundPlay("sound/door_handle_02.ogg")
            HUDScreen:ShowTips({path = "graphics/screens/02_hall/location/Text_02c", x = 316, y = 1129})
        else
            SoundPlay("sound/chief_door_open.ogg")
        end
    end
    
    if(item_name == "elevator_hand") then
        if(GetState("screen_005_security", "state") ~= "finish")then 
            HUDScreen:ShowTips({path = "graphics/screens/02_hall/location/Text_02d", x = 592, y = 1129})
        end
    end
     
    if(GetState("GLOBAL", "click_calc") == "") then
        if(item_name == "background") then
            self.click_amount = self.click_amount + 1
            if(self.click_amount >= 3) then
                SetState("GLOBAL", "click_calc", "false")
                self:ShowTutorial(5);
                self.click_calc = false;
            end
        else
            self.click_amount = 0
        end
    end
end 
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "background", "graphics/screens/02_hall/location/02_hall", 0, 0);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "stand_eye", "graphics/screens/02_hall/location/stand_eye", 967, 292);
	self:CreateObj(OBJ_TYPE.TRIGGER, "glass", "graphics/screens/02_hall/location/glass", 290, 279);
	self:CreateObj(OBJ_TYPE.TRIGGER, "bedpan", "graphics/screens/02_hall/location/bedpan", 848, 879);
	--self:CreateObj(OBJ_TYPE.TRIGGER, "ward_number_eye", "graphics/screens/02_hall/location/ward_number_eye", 1425, 300);
	self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_open", "graphics/screens/02_hall/location/elevator_open", 552, 748);
	self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_door_right", "graphics/screens/02_hall/location/elevator_door_right", 665, 349);
	self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_door_left", "graphics/screens/02_hall/location/elevator_door_left", 549, 348);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "security_door_hand2", "graphics/screens/02_hall/location/security_door_hand", 343, 292);
	self:CreateObj(OBJ_TYPE.TRIGGER, "security_door_hand", "graphics/screens/02_hall/location/security_door_hand", 343, 292);
	
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "chief_door_hand", "graphics/screens/02_hall/location/chief_door_hand", 30, 133);
	
	self:CreateObj(OBJ_TYPE.NO_ACTIVE, "elevator_cover", "graphics/screens/02_hall/location/elevator_cover", 420, 339);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "note_02_part", "graphics/screens/02_hall/location/note_02_part", 302, 128);
	
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_02_part", "graphics/screens/02_hall/location/crystal_02_part", 902, 720);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "ward_door_hand", "graphics/screens/02_hall/location/ward_door_hand", 1297, 294);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "elevator_hand", "graphics/screens/02_hall/location/elevator_hand", 546, 348);
	
    clScreenManager:add_screen("hud") 
end