GameScreen.textures_path = "graphics/screens/19_attic/location/"

GameScreen.hint_table = {
    {obj = {"door_hint", 315, 1015}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "mg") then return true end end},
    {obj = {"door_hint", 315, 1015}, fun = function() if(GetState(CURRENT_SCREEN, "state") == "house") then return true end end}
}

function GameScreen:RestoreScene()
    if(GetState(CURRENT_SCREEN, "state") == "") then
        SetState(CURRENT_SCREEN, "state", "ho")
        local tip_end = function()
        end
        self:StartHO();

        HUDScreen:ShowTips({path = "graphics/screens/19_attic/location/Text_19", x = 314, y = 1112, end_fun = tip_end})
    elseif(GetState(CURRENT_SCREEN, "state") == "ho") then
        self:StartHO();
    elseif(GetState(CURRENT_SCREEN, "state") == "mg") then   
        self:CreateObj(OBJ_TYPE.TRIGGER, "door_eye", "graphics/screens/19_attic/location/door_eye", 326, 1030);
        self:CreateLocationPortal("door_eye", "mg_019_door", "eye")
    elseif(GetState(CURRENT_SCREEN, "state") == "finish") then 
        ItemRemove(self.name, "door_cover")
    elseif(GetState(CURRENT_SCREEN, "state") == "house") then   
        self:CreateObj(OBJ_TYPE.TRIGGER, "door_eye", "graphics/screens/19_attic/location/door_eye", 326, 1030);
        self:CreateLocationPortal("door_eye", "019_house", "eye")
        ItemRemove(self.name, "door_cover")
        --clApplication:LoadLocation("020_wizard")
    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")
		if(found_item == "headscarf") then
		    ItemSetOpacity("headscarf_shadow1", 1.0)
		end
    end 
end


function GameScreen:InitScreen()
    self:LoadScreen()       
         
    self:RestoreScene();
    
    self:AddHiddenCrystal("crystal_19_part")
    
    self:SetItemSound("glass", "sound/bottle_01.ogg");
    self:SetItemSound("bottle_01", "sound/bottle_04.ogg");
    self:SetItemSound("bottle_02", "sound/bottle_05.ogg");
    self:SetItemSound("bottle_03", "sound/bottle_06.ogg");
    
    MusicPlay({"sound/ambient/19_ambient.ogg", "sound/music/past.ogg"} , 19) 
end

---------------------------------------------------------------------
function GameScreen:StartHO()
    local ho_end = function()  
        self.mini_game = nil;
        SetState(CURRENT_SCREEN, "state", "mg") 
        
        clApplication.curret_win = clScreenManager:add_screen("tool_found_screen") 
        clApplication.curret_win._resource = "graphics/screens/19_attic/location/object_found_19"
        clApplication.curret_win.end_fun = function()
            Inventory:ToolFound("wooden_circle_019", 800, 600)
            self:CreateObj(OBJ_TYPE.TRIGGER, "door_eye", "graphics/screens/19_attic/location/door_eye", 326, 1030);
            self:CreateLocationPortal("door_eye", "mg_019_door", "eye")
            --DelayedExec(1.0, function()
            --    HUDScreen:ShowTips({path = "graphics/screens/19_attic/location/Text_19a", x = 742, y = 1131})
            --end, 113)
        end
    end

    local headscarf_found = function()
         SoundPlay("sound/interface/found.ogg")
        
        local item_name = "headscarf"
        local is_obj = self:CreateObj(OBJ_TYPE.ACTIVE, item_name.."_full", self.textures_path..item_name.."_full", 500, 500);    
        ItemRemove(self.name, item_name.."_text", 0.2)
            
        if(is_obj == true) then
            ItemRemove(self.name, item_name)
            
            item_name = item_name.."_full";
            ItemSetPosition(item_name, 816, 90)
        end
        
        EffectorPlay(item_found_eff, item_name, false)

        DelayedExec(1.5, function()
            self:RemoveItem(item_name, 0.3)
        end, 113)
        
        ItemChangeOpacity("headscarf_shadow1", 1.0, 0.2)
        self.mini_game:AfterTakeItem();
    end
    
    self.item_list = {
        {obj = {"skirt", {x = 815, y = 429}}, },
        {obj = {"headwear", {x = 452, y = 649}}, },
        {obj = {"shirt", {x = 431, y = 748}}, },
        {obj = {"headscarf", {x = 816, y = 90}}, finding_fun = headscarf_found},
        {obj = {"brooch", {x = 1190, y = 1073}}, },
        {obj = {"shoe_01", {x = 644, y = 408}}, },
        {obj = {"shoe_02", {x = 532, y = 550}}, },
        {obj = {"handkerchief", {x = 899, y = 962}},},
        {obj = {"basket", {x = 1074, y = 889}}, },
        {obj = {"ribbon", {x = 689, y = 753}}, },
        {obj = {"fan", {x = 590, y = 645}}, },
        {obj = {"wooden_circle", {x = 1008, y = 580}}, zoom = {"019_attic_zoom", "chest_hint", 1035, 785}},
        
        {obj = {"money_pouch", {x = 750, y = 401}}, zoom = {"019_attic_zoom", "chest_hint", 1035, 785}},
    }

    self:SetMiniGame(mgt_hidden_object)   
    self.mini_game:Init(self.item_list, ho_end);
    self:ZoomZoneLink("chest_eye", "019_attic_zoom");
end

function GameScreen:OnFinish()
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "19_attic", "graphics/screens/19_attic/location/19_attic", 0, 0);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "door_cover", "graphics/screens/19_attic/location/door_cover", 327, 1016);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "chest_eye", "graphics/screens/19_attic/location/chest_eye", 1045, 794);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "glass", "graphics/screens/19_attic/location/glass", 657, 653);
    self:CreateObj(OBJ_TYPE.TRIGGER, "door_eye", "graphics/screens/19_attic/location/door_eye", 326, 1030);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_02", "graphics/screens/19_attic/location/bottle_02", 1057, 1110);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_03", "graphics/screens/19_attic/location/bottle_03", 1375, 910);
    self:CreateObj(OBJ_TYPE.TRIGGER, "bottle_01", "graphics/screens/19_attic/location/bottle_01", 81, 781);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "crystal_19_part", "graphics/screens/19_attic/location/crystal_19_part", 453, 714);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "skirt", "graphics/screens/19_attic/location/skirt_part", 861, 489);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "headwear_shadow", "graphics/screens/19_attic/location/headwear_shadow", 477, 711);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "headwear", "graphics/screens/19_attic/location/headwear_part", 496, 692);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "shirt", "graphics/screens/19_attic/location/shirt_part", 441, 814);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "headscarf_shadow1", "graphics/screens/19_attic/location/headscarf_shadow", 0, 0);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "headscarf", "graphics/screens/19_attic/location/headscarf_part", 921, 68);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "brooch", "graphics/screens/19_attic/location/brooch_part", 1234, 1144);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "shoe_01", "graphics/screens/19_attic/location/shoe_01_part", 654, 410);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "shoe_02", "graphics/screens/19_attic/location/shoe_02_part", 556, 589);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "handkerchief", "graphics/screens/19_attic/location/handkerchief_part", 919, 988);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "basket_shadow", "graphics/screens/19_attic/location/basket_shadow", 997, 930);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "basket", "graphics/screens/19_attic/location/basket_part", 1111, 930);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ribbon", "graphics/screens/19_attic/location/ribbon_part", 766, 773);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fan_shadow", "graphics/screens/19_attic/location/fan_shadow", 657, 658);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "fan", "graphics/screens/19_attic/location/fan_part", 628, 658);
    
    ItemSetOpacity("headscarf_shadow1", 0.0)
    clScreenManager:add_screen("hud") 
end
