-- Items to use
-- 14_button

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/Minigames/13_lock.lua', 'quest', 'data/Scenes/13_Crimeplace_Main.lua')
    
    AddNoteToNotebook('ENTRYWAY_2');
    
    CreateGrid();
    FillGrid();
    
    local btn_12 = play_field:GetObject('btn_12');
    btn_12:SetVisible(false);
    
    play_field:GetObject('area_empty_cell'):SetXY(btn_12:GetX(), btn_12:GetY());
    play_field:GetObject('area_empty_cell'):SetZ(153);
    
    RegisterToolApplyInfo('14_button', 'area_empty_cell', nil, nil, function(tool_name)
                                                                        play_field:GetObject('area_empty_cell'):SetVisible(false);
                                                                        play_field:GetObject('btn_12'):SetVisible(true);
                                                                        
                                                                        game_state.grid.active = true;
                                                                        
                                                                        PlaySound('13_PlaceCell');
                                                                        
                                                                        level_mode = 'mini_game';
	                                                                    play_field:GetLevelScreen():GetPanel():SetMode(PM_MINIGAME)
	                                                                    ShowMonolog('C_13_MG_LOCK_TOOL_APPLIED', 'C_13_MG_LOCK_TOOL_APPLIED')
                                                                    end,
                                                                    function(tool_name)
                                                                        play_field:GetObject('area_empty_cell'):SetVisible(false);
                                                                        play_field:GetObject('btn_12'):SetVisible(true);
                                                                        
                                                                        game_state.grid.active = true;
                                                                        
                                                                        level_mode = 'mini_game';
	                                                                    play_field:GetLevelScreen():GetPanel():SetMode(PM_MINIGAME)
	                                                                    ShowMonolog('C_13_MG_LOCK_TOOL_APPLIED', 'C_13_MG_LOCK_TOOL_APPLIED')
                                                                    end);
    ------------------------------------------------------------------------------------------------------                                                                    
    if game_state.grid.active == false then
        if HasGameState('ToolFound', "14_button") == false then
            ShowMonolog('C_13_MG_LOCK_TOOL_NOT_APPLIED', 'C_13_MG_LOCK_TOOL_NOT_APPLIED')
        else
            ShowMonolog('C_13_MG_LOCK_TOOL_FOUND', 'C_13_MG_LOCK_TOOL_FOUND')
        end
    end
    
    if HasGameState('ActionCompleted', game_state.scene_path.."(13_lock_all_cells_hided)") then
        game_state.all_cells_hided = true;
        StartOpenLockAnimation();
    else
        game_state.grid.check_win()
    end
end

function CreatePlayEffector(obj, angle, anim_time)
	local eff = CreateAnimationEffector()
    eff:AttachTo(obj)
    eff:SetMode(_ANIM_FWD)
    
    eff:SetKey(_TRACK_A, 0, obj:GetAngle())
    eff:SetKey(_TRACK_A, anim_time, obj:GetAngle() + angle)
    eff:Play()
end

function StartOpenLockAnimation()
    local anim_time = 2;
    
    PlaySound('13_OpenLock');
    
    -------------- TODO: create open lock effectors
    --[[if not HasGameState('ToolFound', '14_button') then
		FindTool('14_button')
	end]]
    
    local zamok = play_field:GetObject('zamok')
    zamok:Move(-70, 0, anim_time)
    
    CreatePlayEffector(play_field:GetObject('zvezda_1'), - M_PI_OVER_4, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_1_shadow'), - M_PI_OVER_4, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_2'), M_PI_OVER_2 - 0.15, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_2_shadow'), M_PI_OVER_2 - 0.15, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_3'), M_PI_OVER_4 * 1.3, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_3_shadow'), M_PI_OVER_4 * 1.3, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_4'), M_PI_OVER_4 * 1.3, anim_time)
    CreatePlayEffector(play_field:GetObject('zvezda_4_shadow'), M_PI_OVER_4 * 1.3, anim_time)
    
    local mehanizm = play_field:GetObject('mehanizm_1')
    eff = CreateAnimationEffector()
    eff:AttachTo(mehanizm)
    eff:SetMode(_ANIM_LOOP)
	
	eff:SetKey(_TRACK_A, 0, mehanizm:GetAngle())
	eff:SetKey(_TRACK_A, 0.4, mehanizm:GetAngle() - M_PI / 36)
	eff:SetKey(_TRACK_A, 0.5, mehanizm:GetAngle())
	eff:Play()
	TimerDoString("eff:Stop()", anim_time, play_field:GetTimer());
        
    --------------
        
    TimerDoString("RegisterCompleteMiniGame();", anim_time, play_field:GetTimer());
end

function RegisterCompleteMiniGame()
    AddGameState('MiniGameCompleted', '13_lock');
    AddGameState('ClosedScene', game_state.scene_path);
    
    StartLevel(game_state.parent_scene);
end

function CreateGrid()
    local grid = {};
    grid = {}
    grid.cols = 7       -- колличество столбцов в сетке
    grid.rows = 6       -- колличество строк в сетке
    grid.x = 327;       -- координата первой ячейки по X
    grid.y = 189;       -- координата первой ячейки по Y
    grid.dx = 81        -- расстояние между соседними ячейками по X
    grid.dy = 61        -- расстояние между соседними ячейками по Y
    grid.delay = 0.7;   -- задержка времени перед проверкой соответствия двух ячеек
    grid.hide_time = 0.5;
    grid.focus_cell = nil;
    grid.cells = {};
    grid.active = false;
    grid.wait_for_check = false;
    
    grid.obj_name1 = nil;
    grid.obj_name2 = nil;
    
    grid.add_cell = function(name, group, xi, yi)
        local info = {}
        
        info.obj    = play_field:GetObject(name);
        info.group  = group;
        info.xi     = xi;
        info.yi     = yi;
        info.hide   = false;
        
        info.obj:SetX(grid.x + (info.xi - 1) * grid.dx)
        info.obj:SetY(grid.y + (info.yi - 1) * grid.dy)
        info.obj:SetZ(110 + info.xi*info.yi)
        
        grid.cells[name] = info;
    end
    
    grid.shift_cells = function()
        local buf = {};
        local count = 0;
        
        for name, info in pairs(grid.cells) do
            count = count + 1
            buf[count] = name
        end
        
        for i=1, count do
            local ii = math.random(count);
            local info1 = grid.cells[buf[i]]
            local info2 = grid.cells[buf[ii]]
            
            info1.xi, info2.xi = info2.xi, info1.xi
            info1.yi, info2.yi = info2.yi, info1.yi
        end
        
        for name, info in pairs(grid.cells) do
            info.obj:SetX(grid.x + (info.xi - 1) * grid.dx)
            info.obj:SetY(grid.y + (info.yi - 1) * grid.dy)
            info.obj:SetZ(110 + info.xi*info.yi)
        end
    end
    
    grid.save_cells_position = function()
        for name, info in pairs(grid.cells) do
            if HasGameState('MG_13_LOCK_CELL_XI_'..name) then
                RemoveGameState('MG_13_LOCK_CELL_XI_'..name)
            end
            AddGameState('MG_13_LOCK_CELL_XI_'..name, ''..info.xi)
            
            if HasGameState('MG_13_LOCK_CELL_YI_'..name) then
                RemoveGameState('MG_13_LOCK_CELL_YI_'..name)
            end
            AddGameState('MG_13_LOCK_CELL_YI_'..name, ''..info.yi)
        end
    end
    
    grid.load_cells_position = function()
        local is_load = false;
        
        for name, info in pairs(grid.cells) do
            if HasGameState('MG_13_LOCK_CELL_XI_'..name) then
                info.xi = 0 + GetGameState('MG_13_LOCK_CELL_XI_'..name):Get(0);
                is_load = true;
            end
            
            if HasGameState('MG_13_LOCK_CELL_YI_'..name) then
                info.yi = 0 + GetGameState('MG_13_LOCK_CELL_YI_'..name):Get(0);
                is_load = true;
            end
            
            info.obj:SetX(grid.x + (info.xi - 1) * grid.dx)
            info.obj:SetY(grid.y + (info.yi - 1) * grid.dy)
            info.obj:SetZ(110 + info.xi*info.yi)
        end
        
        return is_load;
    end
    
    grid.load_cells_hide_state = function()
        for name, info in pairs(grid.cells) do
            local value = game_state.scene_path.."("..name..")"

            if HasGameState('MG_13_LOCK_CELL_HIDE', value) then
                info.hide = true;
                info.obj:SetOpacity(0);
            end
        end
    end
    
    grid.set_cell_select = function(cell_name, select)
        local info = grid.cells[cell_name]
        
        if info then
            if select then
                info.obj:GetAnimation():SetColor('0xFFA0A0A0');
            else
                info.obj:GetAnimation():SetColor('0xFFFFFFFF');
            end
        end
    end
    
    grid.hide_cell = function(cell_name)
        local info = grid.cells[cell_name]
        
        if info then
            info.obj:ChangeOpacity(1, 0, grid.hide_time);
            info.hide = true;
            
            local value = game_state.scene_path.."("..cell_name..")"
            
            if not HasGameState('MG_13_LOCK_CELL_HIDE', value) then
                AddGameState('MG_13_LOCK_CELL_HIDE', value)
            end
        end
    end
    
    grid.check_pair = function()
        if grid.obj_name1 and grid.obj_name2 then
        
            local info1 = grid.cells[ grid.obj_name1 ];
            local info2 = grid.cells[ grid.obj_name2 ];
            
            if info1.group == info2.group then
                grid.hide_cell( grid.obj_name1 );
                grid.hide_cell( grid.obj_name2 );
                
                if grid.focus_cell == grid.obj_name1
                or grid.focus_cell == grid.obj_name2
                then
                    SetCursor('CursorDefault');
                end
                
                grid.obj_name1 = nil;
                grid.obj_name2 = nil;
                
                global_grid = grid;
                TimerDoString("global_grid.check_win();", global_grid.hide_time, play_field:GetTimer())
            else
                grid.set_cell_select(grid.obj_name1, false);
                grid.set_cell_select(grid.obj_name2, false);
                
                if grid.focus_cell == grid.obj_name1
                or grid.focus_cell == grid.obj_name2
                then
                    SetCursor('CursorActive');
                end
                
                grid.obj_name1 = nil;
                grid.obj_name2 = nil;
            end
            
            grid.wait_for_check = false;
        end
    end
    
    grid.check_win = function()
        local all_hidden = true;
        
        for name, info in pairs(grid.cells) do
            if not info.hide then
                 all_hidden = false;
                 break;
            end
        end
        
        if all_hidden then
           AddGameState('ActionCompleted', game_state.scene_path.."(13_lock_all_cells_hided)");
           game_state.all_cells_hided = true;
           
           StartOpenLockAnimation();
        end
    end
    
    grid.OnObjectClick = function(obj_name)
        if grid.wait_for_check then
            return;
        end
        
        if not grid.cells[obj_name] or grid.cells[obj_name].hide then
            return;
        end
        
        if not game_state.grid.active then
            ShowMonolog('C_13_MG_LOCK_TOOL_NOT_APPLIED', 'C_13_MG_LOCK_TOOL_NOT_APPLIED');
            return;
        end
        
        if not grid.obj_name1 then
            grid.obj_name1 = obj_name;
            grid.set_cell_select(obj_name, true);
            
            PlaySound('13_CellSelect');
            
        elseif (not grid.obj_name2) and (obj_name ~= grid.obj_name1) then 
            grid.wait_for_check = true;
            grid.obj_name2      = obj_name;
            grid.set_cell_select(obj_name, true);
            
            PlaySound('13_CellSelect');
            
            global_grid = grid;
            TimerDoString("global_grid.check_pair();", global_grid.delay, play_field:GetTimer())
            
        elseif grid.obj_name1 == obj_name then
            grid.set_cell_select(obj_name, false);
            grid.obj_name1 = nil
            
            PlaySound('13_CellSelect');
        end
    end
    
    grid.OnObjectEnter = function(obj_name)
        if not game_state.grid.active then
            return;
        end
        
        local info = grid.cells[obj_name]
        
        if info and not info.hide then
            grid.focus_cell = obj_name;
            SetCursor('CursorActive');
        end
    end
    
    grid.OnObjectLeave = function(obj_name)
        if not game_state.grid.active then
            return;
        end
        
        local info = grid.cells[obj_name]
        
        if info
            and obj_name ~= grid.obj_name1
            and obj_name ~= grid.obj_name2
        then
            grid.focus_cell = nil;
            SetCursor('CursorDefault');
        end
    end
    
    game_state.grid = grid;
end

function FillGrid()
    local grid = game_state.grid;
    local xi = 1
    local yi = 1
    
    for i=1, 21 do
        local name = "btn_"..i;
        
        grid.add_cell(name, i, xi, yi);
        
        if xi == grid.cols then
            xi = 1
            yi = yi + 1
        else
            xi = xi + 1
        end
        
        grid.add_cell(name.."_a", i, xi, yi);
        
        if xi == grid.cols then
            xi = 1
            yi = yi + 1
        else
            xi = xi + 1
        end
    end
    
    if not grid.load_cells_position() then
        grid.shift_cells();
        grid.save_cells_position();
    else
        grid.load_cells_hide_state();
    end
end

function SkipMiniGame()
    if game_state.all_cells_hided or game_state.mini_game_skiped then
        return;
    end
    
    game_state.mini_game_skiped = true;
    
    for name, info in pairs(game_state.grid.cells) do
        if not info.hide then
            game_state.grid.hide_cell(name);
        end
    end
    
    global_grid = game_state.grid;
    TimerDoString("global_grid.check_win();", game_state.grid.hide_time, play_field:GetTimer());
end

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    game_state.grid.OnObjectEnter(object:GetName());
    
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    game_state.grid.OnObjectLeave(object:GetName());
    
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field
    
    game_state.grid.OnObjectClick(obj_name);
    
    if obj_name == 'area_empty_cell' then
        ShowMonolog('C_13_MG_LOCK_TOOL_NOT_APPLIED', 'C_13_MG_LOCK_TOOL_NOT_APPLIED');
    end
    
    DefaultOnObjectMouseDownProcessed(is_wrong_click);
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)
end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_1.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_1',anim,95,380,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_1_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_1_a',anim,175,71,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_2.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_2',anim,304,55,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_2_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_2_a',anim,98,317,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_3.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_3',anim,477,92,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_3_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_3_a',anim,194,330,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_4.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_4',anim,567,35,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_4_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_4_a',anim,128,286,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_5.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_5',anim,662,53,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_5_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_5_a',anim,217,392,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_6.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_6',anim,217,388,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_6_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_6_a',anim,249,386,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_7.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_7',anim,268,380,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_7_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_7_a',anim,223,353,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_8.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_8',anim,249,331,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_8_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_8_a',anim,228,285,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_9_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_9_a',anim,114,283,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_9.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_9',anim,178,359,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_10.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_10',anim,425,67,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_10_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_10_a',anim,168,474,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_11.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_11',anim,201,455,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_11_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_11_a',anim,160,382,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_12.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_12',anim,118,274,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_12_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_12_a',anim,105,310,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_13.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_13',anim,152,302,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_13_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_13_a',anim,245,258,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_14.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_14',anim,169,323,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_14_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_14_a',anim,146,262,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_15.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_15',anim,183,406,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_15_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_15_a',anim,215,460,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_16.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_16',anim,240,459,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_16_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_16_a',anim,188,466,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_17.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_17',anim,81,510,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_17_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_17_a',anim,176,165,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_18.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_18',anim,119,365,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_18_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_18_a',anim,140,477,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_19.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_19',anim,254,453,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_19_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_19_a',anim,173,307,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_20.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_20',anim,120,310,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_20_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_20_a',anim,129,317,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_21.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_21',anim,214,287,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Buttons/btn_21_a.png',0,0,80,63,1,0)
	anim:SetHotSpot(40,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('btn_21_a',anim,256,380,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_empty_cell',anim,135,645,120,0,20,15)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zamok.png',0,0,667,330,1,0)
	anim:SetHotSpot(333,165)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zamok',anim,551,376,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_1.png',0,0,138,141,1,0)
	anim:SetHotSpot(69,70)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_1',anim,581,354,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_1_shadow.png',0,0,140,142,1,0)
	anim:SetHotSpot(70,71)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_1_shadow',anim,568,366,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_2.png',0,0,52,54,1,0)
	anim:SetHotSpot(26,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_2',anim,499,321,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_2_shadow.png',0,0,54,56,1,0)
	anim:SetHotSpot(27,28)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_2_shadow',anim,492,330,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_3.png',0,0,85,85,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_3',anim,498,420,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_3_4_shadow.png',0,0,87,87,1,0)
	anim:SetHotSpot(43,43)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_3_shadow',anim,668,401,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_4.png',0,0,85,85,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_4',anim,681,387,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/zvezda_3_4_shadow.png',0,0,87,87,1,0)
	anim:SetHotSpot(43,43)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_4_shadow',anim,490,428,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/mehanizm_1.png',0,0,149,66,1,0)
	anim:SetHotSpot(50,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mehanizm_1',anim,533,219,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/13_lock/Top.png',0,0,819,373,1,0)
	anim:SetHotSpot(409,186)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Top',anim,538,344,103,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
