GameScreen.textures_path = "graphics/screens/05_security/location/"

GameScreen.hint_table = {
    {obj = {"switchboard_hint", 1232, 167}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "" or GetState(CURRENT_SCREEN, "state") == "mg1") then return true end end},
    {obj = {"control_panel_hint", 493, 578}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "mg2") then return true end end}, 
    {obj = {"door_hint", 0, 189}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "finish") then return true end end}, 
}
function GameScreen:RestoreScene()
    if(GetState(CURRENT_SCREEN, "state") == "") then
        --SetState(CURRENT_SCREEN, "state", "mg")
        HUDScreen:ShowTips({path = self.textures_path.."text_05", x = 315, y = 1114})
        self:CreateLocationPortal("switchboard_eye", "mg_005_switchboard", "eye")      
    elseif(GetState(CURRENT_SCREEN, "state") == "ho") then
        self.item_list = {
            {obj = {"fuse_14", {x = 1184, y = 1131}}, },
            {obj = {"fuse_13", {x = 274, y = 1096}}, },
            {obj = {"fuse_12", {x = 1181, y = 949}}, },
            {obj = {"fuse_11", {x = 807, y = 1006}}, },
            {obj = {"fuse_10", {x = 299, y = 736}}, },
            {obj = {"fuse_09", {x = 1356, y = 767}}, },
            {obj = {"fuse_08", {x = 650, y = 542}}, },
            {obj = {"fuse_07", {x = 1024, y = 475}}, },
            {obj = {"fuse_06", {x = 1283, y = 516}}, },
            {obj = {"fuse_05", {x = 837, y = 331}}, },
            {obj = {"fuse_04", {x = 1029, y = 229}}, },
            {obj = {"fuse_03", {x = 1395, y = 106}}, },--
            {obj = {"fuse_02", {x = 553, y = 126}}, },
            {obj = {"fuse_01", {x = 196, y = 137}}, },
            {obj = {"fuse_15", {x = 978, y = 554}}, zoom = {"005_security_zoom_panel", "fuse_door_hint", 503, 801}},
        }
        
        local end_ho = function()
            self.mini_game = nil
            SetState(CURRENT_SCREEN, "state", "mg1")
            SetState("screen_mg_005_switchboard", "switchboard", "active")
            self:CreateLocationPortal("switchboard_eye", "mg_005_switchboard", "eye")  
        end
        
        if(GetState(CURRENT_SCREEN, "ho_tip") == "")then
            SetState(CURRENT_SCREEN, "ho_tip", "showed")
            self:SetMiniGame(mgt_hidden_object)   
            self.mini_game:Init(self.item_list, end_ho, true);
            local start_ho = function()
            end
            HUDScreen:ShowHintText({path = self.textures_path.."hint_05", x = 689, y = 1128, end_fun = start_ho})
        else
            self:SetMiniGame(mgt_hidden_object)   
            self.mini_game:Init(self.item_list, end_ho, true);
        end
        
        self:ZoomZoneLink("fuse_door_eye", "005_security_zoom_panel");
        self:CreateLocationPortal("switchboard_eye", "mg_005_switchboard", "eye")
    elseif(GetState(CURRENT_SCREEN, "state") == "mg1") then
        self:CreateLocationPortal("switchboard_eye", "mg_005_switchboard", "eye")  
    elseif(GetState(CURRENT_SCREEN, "state") == "mg2") then
        HUDScreen:ShowTips({path = self.textures_path.."Text_05c", x = 514, y = 1131})
        self:PanelLight()
        self:CreateLocationPortal("control_panel_eye", "mg_005_voltage", "eye")  
    elseif(GetState(CURRENT_SCREEN, "state") == "finish") then
        self:CreateObj(OBJ_TYPE.NO_ACTIVE, "voltage_on", "graphics/screens/05_security/location/voltage_on", 828, 613);
        HUDScreen:ShowTips({path = self.textures_path.."text_05b", x = 593, y = 1131})
        self:PanelLight()
        --SetState("screen_002_hall", "state", "finish")
    end
    
    for found_item in string.gmatch(GetState(CURRENT_SCREEN, "found_obj"), "[_%a%d]+") do
		ItemRemove(self.name, found_item)
    end 
    
    self:CreateLocationPortal("door_hand", "002_hall", "hand")  
end

function GameScreen:PanelLight()
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamps_triple", "graphics/screens/05_security/location/lamps_triple", 1147, 1110);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamp_green_round", "graphics/screens/05_security/location/lamp_green_round", 1072, 769);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamps_yellow", "graphics/screens/05_security/location/lamps_yellow", 1035, 812);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamp_red", "graphics/screens/05_security/location/lamp_red", 683, 852);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamp_green", "graphics/screens/05_security/location/lamp_green", 1157, 1149);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "lamp_yellow", "graphics/screens/05_security/location/lamp_yellow", 1242, 1113);
	self:panel_light_anim("lamps_triple")
	self:panel_light_anim("lamp_green_round")
	self:panel_light_anim("lamps_yellow")
	self:panel_light_anim("lamp_red")
	self:panel_light_anim("lamp_green")
	self:panel_light_anim("lamp_yellow")
end

function GameScreen:panel_light_anim(item_name)
    ItemChangeOpacity(item_name, 1.0, 0.2)
    ItemChangeOpacity(item_name, 0.0, 0.2, 0.2)
    
    DelayedExec(1.0 + math.random(200) / 100, function()
        if(CurrentScreen.name ~= "005_security") then return end
        self:panel_light_anim(item_name)
    end, 113)
end

function GameScreen:InitScreen()
    self:LoadScreen()
    
    self:RestoreScene()
    
    self:AddHiddenCrystal("crystal_05_part")
    self:CreateWallpaperPortal("note_05_part", "note_05_full", 430, 138)
    self:SetItemCursor("note_05_part", "eye")
    
    self:SetItemSound("security_phone", "sound/security_phone.ogg");
    self:SetItemSound("walkie_02", {"sound/walkie_03.ogg", "sound/walkie_02.ogg"});
    self:SetItemSound("walkie_01", "sound/walkie_01.ogg");
    self:SetItemSound("shocker", "sound/shocker.ogg");
    self:SetItemSound("clock", "sound/clock_alarm.ogg");
    self:SetItemSound("glass", "sound/glass_tap.ogg");
    self:SetItemSound("megaphone", "sound/megaphone.ogg");
    
    MusicPlay({"sound/ambient/05_ambient.ogg", "sound/music/hospital.ogg"}, 5) 
end

function GameScreen:onObjectClick(item_name)
    if(item_name == "door_hand") then
        if(GetState(CURRENT_SCREEN, "state")  == "finish")then
            SoundPlay("sound/door_handle.ogg")
        else
            SoundPlay("sound/security_door.ogg")
        end
    end
    if(item_name == "switchboard_eye" and (GetState(CURRENT_SCREEN, "state") == "mg1" or GetState(CURRENT_SCREEN, "state") == "")) then
        SoundPlay("sound/switchboard_door.ogg")
    end
end 

------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "background", "graphics/screens/05_security/location/05_security", 0, 0);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "security_phone", "graphics/screens/05_security/location/security_phone", 401, 908);
	self:CreateObj(OBJ_TYPE.TRIGGER, "door_hand", "graphics/screens/05_security/location/door_hand", 0, 205);
	self:CreateObj(OBJ_TYPE.TRIGGER, "note_05_part", "graphics/screens/05_security/location/note_05_part", 899, 1002);
	self:CreateObj(OBJ_TYPE.TRIGGER, "walkie_02", "graphics/screens/05_security/location/walkie_02", 933, 896);
    
	self:CreateObj(OBJ_TYPE.TRIGGER, "shocker", "graphics/screens/05_security/location/shocker", 1160, 405);
	self:CreateObj(OBJ_TYPE.TRIGGER, "clock", "graphics/screens/05_security/location/clock", 567, 510);
	self:CreateObj(OBJ_TYPE.TRIGGER, "glass", "graphics/screens/05_security/location/glass", 405, 213);
	self:CreateObj(OBJ_TYPE.TRIGGER, "megaphone", "graphics/screens/05_security/location/megaphone", 295, 367);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "fuse_door_eye", "graphics/screens/05_security/location/fuse_door_eye", 452, 593);
	self:CreateObj(OBJ_TYPE.TRIGGER, "control_panel_eye", "graphics/screens/05_security/location/control_panel_eye", 504, 589);
	
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_05_part", "graphics/screens/05_security/location/crystal_05_part", 1032, 960);
	
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_14", "graphics/screens/05_security/location/fuse_14_part", 1214,1137);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_13", "graphics/screens/05_security/location/fuse_13_part", 309, 1099);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_12", "graphics/screens/05_security/location/fuse_12_part", 1210, 954);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_11", "graphics/screens/05_security/location/fuse_11_part", 840, 1011);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_10", "graphics/screens/05_security/location/fuse_10_part", 331, 745);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_09", "graphics/screens/05_security/location/fuse_09_part", 1390, 775);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_08", "graphics/screens/05_security/location/fuse_08_part", 689, 552);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_07", "graphics/screens/05_security/location/fuse_07_part", 1060, 484);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_06", "graphics/screens/05_security/location/fuse_06_part", 1314, 524);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_05", "graphics/screens/05_security/location/fuse_05_part", 875, 343);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_04", "graphics/screens/05_security/location/fuse_04_part", 1062, 236);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_03", "graphics/screens/05_security/location/fuse_03_part", 1401, 142);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_02", "graphics/screens/05_security/location/fuse_02_part", 598, 138);
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fuse_01", "graphics/screens/05_security/location/fuse_01_part", 227, 141);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "switchboard_eye", "graphics/screens/05_security/location/switchboard_eye", 1247, 184);
	
	self:CreateObj(OBJ_TYPE.TRIGGER, "walkie_01", "graphics/screens/05_security/location/walkie_01", 601, 807);
	
    clScreenManager:add_screen("hud") 
end