class 'l_04_Gazebo_Z_Tool_box' (ZoomZone)

function l_04_Gazebo_Z_Tool_box:__init(name, mode, PlayField)
	ZoomZone.__init(self, name, mode, PlayField)
	
	self:entityHide('area_bbt_zt_need_code', 'area_click_zt_button_1', 'area_click_zt_button_2', 'area_click_zt_button_3', 'area_find_zt_guitar_wrench', 'area_bbt_zt_tools')
	
	self:entityHide('zt_box_open', 'zt_button_1', 'zt_button_2', 'zt_button_3')
	
	self.type_unlocked_counter = 2

	local function on_find_zt_paper(e)
	    self:entityHide(e.target)
	    
	    self:entityHide('zt_paper')
	end
	self:registerToolFindInfo('04_paper', 'area_find_zt_paper', on_find_zt_paper)
	
	local function on_apply_zt_number_keys(e)
	    self:entityHide(e.target)
	    self:entityShow('area_bbt_zt_need_code')
	    
	    self:setCodeIsKnown()

	    local node = path_manager:findNode(NodeType.TOOL_APPLY, '04_number_key_3')
	    if node then
	    	node:trigger()
	    end

	    node = path_manager:findNode(NodeType.TOOL_APPLY, '02_number_key_2')
	    if node then
	    	node:trigger()
	    end
	    
	    for i=1,3 do
	        if not e.save then
	        	self:playSound('04_apply_zt_number_keys')
	            self:entityFadeShow('zt_button_'..i)
	        else
	            self:entityShow('zt_button_'..i)
	        end
	    end	    	    
	end
	self:registerToolApplyInfo('01_number_key_1', 'area_apply_zt_number_keys', on_apply_zt_number_keys, 'BBT_04_NEED_NUMBER_KEYS')
	
	self:registerBBT('area_bbt_zt_need_code', 'BBT_04_NEED_CODE')
	
	local correct_code = {3, 4, 6}
	local typed_code = {0, 0, 0}
	
	if HasGameState(self.name..'_Typed_Code') then
	    typed_code = Helpers.RestoreObjectFromGameState(self.name..'_Typed_Code')
	else
	    Helpers.SaveObjectToGameState(self.name..'_Typed_Code', typed_code)
	end
	
	local function load_buttons_state()
	    for i=1,3 do
	        for j=0,9 do
	            if typed_code[i] ~= j then
	                self:entityHide('zt_'..i..'_'..j)
	            end
	        end
	    end
	end
	
	local function check_lock_open(save)
	    for i=1,#correct_code do
	        if correct_code[i] ~= typed_code[i] then
	            return
	        end
	    end
	    
	    AddUniqueGameState(self.name..'_Lock_Open', 'true')

	    self.playfield:getHint():removeAdditionalHintObject('area_click_zt_button_1')
		self.playfield:getHint():removeAdditionalHintObject('area_click_zt_button_2')
		self.playfield:getHint():removeAdditionalHintObject('area_click_zt_button_3')
	
	    for i=1,3 do
	        self:entityHide('area_click_zt_button_'..i)
	    end
        self:entityShow('area_find_zt_guitar_wrench', 'area_bbt_zt_tools')
	    
	    if not save then
	    	if not HasGameState('box_open_04') then
		    	self:playSound('04_zt_open_box')
		    	SetGameState('box_open_04','true')
		    end

	        self:entityFadeHide('zt_box_closed')
	        self:entityFadeShow('zt_box_open')
	        
	        self.playfield:entityFadeShow('box_open')
	    else
	        self:entityHide('zt_box_closed')
	        self:entityShow('zt_box_open')
	        
	        self.playfield:entityShow('box_open')
	    end
	end
	
	load_buttons_state()
	check_lock_open()
	
	local function on_click_zt_button(e)
	    local i = tonumber(string.sub(e.target, -1))
	    
	    if not e.save then
	    	self:playSound('04_click_button')
	        self:entityHide('zt_'..i..'_'..typed_code[i])
	        
	        typed_code[i] = typed_code[i] + 1
	        typed_code[i] = typed_code[i] < 10 and typed_code[i] or 0
	        
	        Helpers.SaveObjectToGameState(self.name..'_Typed_Code', typed_code)
	        
	        self:entityShow('zt_'..i..'_'..typed_code[i])
	        
	        check_lock_open()
	    end
	end
	for i=1,3 do
	    self:registerActiveObject('area_click_zt_button_'..i, on_click_zt_button, true)
	end
	
	self:registerBBT('area_bbt_zt_tools', 'BBT_04_TOOLS')
	
	local function on_find_zt_guitar_wrench(e)
	    self:entityHide(e.target)
	    self:entityHide('zt_guitar_wrench')
	    
	    self:closeAndDisable()
	end
	self:registerToolFindInfo('04_guitar_wrench', 'area_find_zt_guitar_wrench', on_find_zt_guitar_wrench)
end

function l_04_Gazebo_Z_Tool_box:setCodeIsKnown()
    self.type_unlocked_counter = self.type_unlocked_counter - 1
    
    if self.type_unlocked_counter>0 then
        return
    end

    self:entityHide('area_bbt_zt_need_code')

    if not HasGameState(self.name..'_Lock_Open') then
        for i=1,3 do
            self:entityShow('area_click_zt_button_'..i)    
        end

        self.playfield:getHint():setAdditionalHintObject('area_click_zt_button_1', 1500)
		self.playfield:getHint():setAdditionalHintObject('area_click_zt_button_2', 1500)
		self.playfield:getHint():setAdditionalHintObject('area_click_zt_button_3', 1500)
    end    
end

--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function l_04_Gazebo_Z_Tool_box:CreateLoaderTable()
	local objects =
	{
		{ name = 'zt_bg',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_bg.jpg',  width = 640,  height = 480,  },
		{ name = 'zt_paper',  entityType = 'SpriteEntity',  x = 314,  y = 280,  order = 1,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_paper.png',  width = 244,  height = 136,  },
		{ name = 'zt_tools',  entityType = 'SpriteEntity',  x = 369,  y = 392,  order = 5,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_tools.png',  width = 146,  height = 142,  },
		{ name = 'zt_guitar_wrench',  entityType = 'SpriteEntity',  x = 594,  y = 437,  order = 5,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_guitar_wrench.png',  width = 80,  height = 48,  },
		{ name = 'zt_button_1',  entityType = 'SpriteEntity',  x = 441,  y = 505,  order = 20,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_button_1.png',  width = 44,  height = 48,  },
		{ name = 'zt_1_0',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_0.png',  width = 16,  height = 22,  },
		{ name = 'zt_1_1',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_1.png',  width = 16,  height = 22,  },
		{ name = 'zt_1_2',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_2.png',  width = 16,  height = 22,  },
		{ name = 'zt_1_3',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_3.png',  width = 12,  height = 20,  },
		{ name = 'zt_1_4',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_4.png',  width = 16,  height = 20,  },
		{ name = 'zt_1_5',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_5.png',  width = 14,  height = 18,  },
		{ name = 'zt_1_6',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_6.png',  width = 16,  height = 18,  },
		{ name = 'zt_1_7',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_7.png',  width = 16,  height = 18,  },
		{ name = 'zt_1_8',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_8.png',  width = 14,  height = 18,  },
		{ name = 'zt_1_9',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_9.png',  width = 14,  height = 20,  },
		{ name = 'area_click_zt_button_1',  entityType = 'SpriteEntity',  parentName = 'zt_button_1',  x = 0,  y = 0,  order = 0,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 35,  height = 40,  },
		{ name = 'zt_button_2',  entityType = 'SpriteEntity',  x = 493,  y = 505,  order = 20,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_button_2.png',  width = 44,  height = 48,  },
		{ name = 'zt_2_0',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_0.png',  width = 16,  height = 22,  },
		{ name = 'zt_2_1',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_1.png',  width = 16,  height = 22,  },
		{ name = 'zt_2_2',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_2.png',  width = 16,  height = 22,  },
		{ name = 'zt_2_3',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_3.png',  width = 12,  height = 20,  },
		{ name = 'zt_2_4',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_4.png',  width = 16,  height = 20,  },
		{ name = 'zt_2_5',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_5.png',  width = 14,  height = 18,  },
		{ name = 'zt_2_6',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_6.png',  width = 16,  height = 18,  },
		{ name = 'zt_2_7',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_7.png',  width = 16,  height = 18,  },
		{ name = 'zt_2_8',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_8.png',  width = 14,  height = 18,  },
		{ name = 'zt_2_9',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_9.png',  width = 14,  height = 20,  },
		{ name = 'area_click_zt_button_2',  entityType = 'SpriteEntity',  parentName = 'zt_button_2',  x = 0,  y = 0,  order = 0,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 35,  height = 40,  },
		{ name = 'zt_button_3',  entityType = 'SpriteEntity',  x = 542,  y = 505,  order = 20,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_button_3.png',  width = 42,  height = 46,  },
		{ name = 'zt_3_0',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_0.png',  width = 16,  height = 22,  },
		{ name = 'zt_3_1',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_1.png',  width = 16,  height = 22,  },
		{ name = 'zt_3_2',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_2.png',  width = 16,  height = 22,  },
		{ name = 'zt_3_3',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_3.png',  width = 12,  height = 20,  },
		{ name = 'zt_3_4',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_4.png',  width = 16,  height = 20,  },
		{ name = 'zt_3_5',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_5.png',  width = 14,  height = 18,  },
		{ name = 'zt_3_6',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_6.png',  width = 16,  height = 18,  },
		{ name = 'zt_3_7',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_7.png',  width = 16,  height = 18,  },
		{ name = 'zt_3_8',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_8.png',  width = 14,  height = 18,  },
		{ name = 'zt_3_9',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_9.png',  width = 14,  height = 20,  },
		{ name = 'area_click_zt_button_3',  entityType = 'SpriteEntity',  parentName = 'zt_button_3',  x = 0,  y = 0,  order = 0,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 35,  height = 40,  },
		{ name = 'zt_box_closed',  entityType = 'SpriteEntity',  x = 491,  y = 389,  order = 40,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_box_closed.png',  width = 470,  height = 182,  },
		{ name = 'zt_box_open',  entityType = 'SpriteEntity',  x = 497,  y = 240,  order = 30,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Z_Tool_box/zt_box_open.png',  width = 426,  height = 164,  },
		{ name = 'area_find_zt_guitar_wrench',  entityType = 'SpriteEntity',  x = 597,  y = 437,  order = 100,  scaleX = 1,  scaleY = 0.7,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_zt_number_keys',  entityType = 'SpriteEntity',  x = 491,  y = 506,  order = 100,  scaleX = 1.6,  scaleY = 0.7,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_bbt_zt_tools',  entityType = 'SpriteEntity',  x = 361,  y = 390,  order = 100,  scale = 1.4,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_bbt_zt_need_code',  entityType = 'SpriteEntity',  x = 491,  y = 506,  order = 100,  scaleX = 1.6,  scaleY = 0.7,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_find_zt_paper',  entityType = 'SpriteEntity',  x = 303,  y = 277,  order = 100,  scaleX = 2.2,  scaleY = 1.4,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
	}
	return objects
end
