function GameScreen:RestoreScene()

    if(GetState(CURRENT_SCREEN, "state") == "choose") then
        HUDScreen:SetInvntoryOnlyMode()
        self:RemoveCounter()
        self:show_choose();
    end
    
    for i = 1, 15 do
        if(GetState(CURRENT_SCREEN, "zone"..i) == "1") then
            ItemSetOpacity("diff_"..i, 1.0)
            ItemRemove(self.name, "diff_zone_"..i)
        else
            ItemSetOpacity("diff_"..i, 0.0)
        end
    end
end

function GameScreen:InitScreen()
    self:LoadScreen()       
    
    self.active = true
    
    self:CreateCounter()
    HUDScreen:SetMiniGameMode()
    
    self:RestoreScene()
end
------------------------------------------------------------------------------------------------------
function GameScreen:get_zone_id_by_name(item_name)
    for i = 1, 15 do
        if(item_name == "diff_zone_"..i) then
            return i;
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:onObjectClick(item_name)   
    if(not self.active) then return end    
    
    local id = self:get_zone_id_by_name(item_name)
    
    if(id and GetState(CURRENT_SCREEN, "zone"..id) ~= "1") then
        SetState(CURRENT_SCREEN, "zone"..id, "1")
        ItemChangeOpacity("diff_"..id, 1.0, 0.2)
        ItemRemove(self.name, "diff_zone_"..id)
        SoundPlay("sound/interface/found.ogg")
        
        if(self:InMinigameCompleted()) then
            SetState(CURRENT_SCREEN, "state", "choose")
            self:show_choose()
        end
    end
    
    self:UpdateCounter()
    
    if("choose_right" == item_name) then
        SetState("screen_029_studio", "choose", "2")
        self:OnFinish()
    end
    if("choose_left" == item_name) then
        SetState("screen_029_studio", "choose", "1")
        self:OnFinish()
    end
end

------------------------------------------------------------------------------------------------------
function GameScreen:show_choose()
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "choose_right", "graphics/interface/hud/choose",819, 1104);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "choose_left", "graphics/interface/hud/choose",18, 1104);
    ItemChangeOpacity("choose_right", 1.0, 0.2)
    ItemChangeOpacity("choose_left", 1.0, 0.2)
    HUDScreen:SetInvntoryOnlyMode()
    self:RemoveCounter()
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnSkip()
    if(self.active == false) then return end
    
    for i = 1, 15 do
        if(GetState(CURRENT_SCREEN, "zone"..i) ~= "1") then
            SetState(CURRENT_SCREEN, "zone"..i, "1")
            ItemChangeOpacity("diff_"..i, 1.0, 0.2)
            ItemRemove(self.name, "diff_zone_"..i)
            SoundPlay("sound/interface/found.ogg")
            
            if(self:InMinigameCompleted()) then
                self:show_choose()
            end
        end
    end
end

function GameScreen:OnFinish()
    if(self.active == false) then return end
    
    ItemRemove(self.name, "choose_right")
    ItemRemove(self.name, "choose_left")
    
    HUDScreen:SetInvntoryOnlyMode()
    self:RemoveCounter()
    SetState(CURRENT_SCREEN, "state", "choose")
    SetState("screen_029_studio", "state", "dialog")
    
    DelayedExec(1.0, function()
        clApplication:LoadLocation("029_studio")
    end, 113)
end

function GameScreen:InMinigameCompleted()    
    for id = 1, 15 do
        if(GetState(CURRENT_SCREEN, "zone"..id) ~= "1") then
            return false;
        end
    end
    
    return true
end

------------------------------------------------------------------------------------------------------
function GameScreen:get_dif_count()
    local counter = 0
    for id = 1, 15 do
        if(GetState(CURRENT_SCREEN, "zone"..id) ~= "1") then
            counter = counter + 1
        end
    end
    return counter;
end
------------------------------------------------------------------------------------------------------
function GameScreen:CreateCounter()
    HUDScreen:CreateObj(OBJ_TYPE.NO_ACTIVE, "ho_panel", "graphics/interface/hud/counter", 18, 1104);
    local string = tostring(self:get_dif_count())
    HUDScreen:CreateLabel("counter_text", string, 35, 1117, 53, FONT_QUICKSAND)
    ItemSetPosition("counter_text", 55 - ItemGetWidth("counter_text") / 2, 1117)
    --SetLabelAlign("counter_text", TEXT_ALIGN.H_CENTER)
    ItemSetSize("counter_text", 65, 30)
    ItemSetColor("counter_text", 1.0, 1.0, 1.0, 1.0)
end
------------------------------------------------------------------------------------------------------
function GameScreen:UpdateCounter()
    local string = tostring(self:get_dif_count())
    SetLabelText("counter_text", string)
    ItemSetPosition("counter_text", 55 - ItemGetWidth("counter_text") / 2, 1117)
end
------------------------------------------------------------------------------------------------------
function GameScreen:RemoveCounter()
    ItemRemove(HUDScreen.name, "ho_panel", 0.2)
    ItemRemove(HUDScreen.name, "counter_text", 0.2)
end
------------------------------------------------------------------------------------------------------
function GameScreen:Update()
    --ItemSetPosition("cursor", messenger_table.mouse_X / 2, messenger_table.mouse_Y);
end
------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "29_portrait", "graphics/minigames/29_portrait/29_portrait",0, 0);
   
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_1", "graphics/minigames/29_portrait/diff_01",1, 92);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_2", "graphics/minigames/29_portrait/diff_02",92, 8);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_3", "graphics/minigames/29_portrait/diff_03",183, 1043);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_4", "graphics/minigames/29_portrait/diff_04",636, 309);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_5", "graphics/minigames/29_portrait/diff_05",97, 322);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_6", "graphics/minigames/29_portrait/diff_06",372, 424);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_7", "graphics/minigames/29_portrait/diff_07",117, 484);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_8", "graphics/minigames/29_portrait/diff_08",361, 492);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_9", "graphics/minigames/29_portrait/diff_09",325, 141);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_10", "graphics/minigames/29_portrait/diff_10",269, 713);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_11", "graphics/minigames/29_portrait/diff_11",212, 644);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_12", "graphics/minigames/29_portrait/diff_12",97, 634);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_13", "graphics/minigames/29_portrait/diff_13",36, 750);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_14", "graphics/minigames/29_portrait/diff_14",661, 760);
    self:CreateObj(OBJ_TYPE.NO_ACTIVE, "diff_15", "graphics/minigames/29_portrait/diff_15",551, 130);
    
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_1", "graphics/minigames/29_portrait/diff_zone_01",0, 95);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_2", "graphics/minigames/29_portrait/diff_zone_02",91, 28);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_3", "graphics/minigames/29_portrait/diff_zone_03",203, 1065);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_4", "graphics/minigames/29_portrait/diff_zone_04",668, 235);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_5", "graphics/minigames/29_portrait/diff_zone_05",98, 346);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_6", "graphics/minigames/29_portrait/diff_zone_06",391, 431);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_7", "graphics/minigames/29_portrait/diff_zone_07",147, 493);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_8", "graphics/minigames/29_portrait/diff_zone_08",340, 516);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_9", "graphics/minigames/29_portrait/diff_zone_09",330, 145);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_10", "graphics/minigames/29_portrait/diff_zone_10",274, 714);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_11", "graphics/minigames/29_portrait/diff_zone_11",222, 647);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_12", "graphics/minigames/29_portrait/diff_zone_12",104, 640);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_13", "graphics/minigames/29_portrait/diff_zone_13",37, 774);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_14", "graphics/minigames/29_portrait/diff_zone_14",642, 789);
    self:CreateObj(OBJ_TYPE.TRIGGER, "diff_zone_15", "graphics/minigames/29_portrait/diff_zone_15",561, 140);

    
    --self:CreateObj(OBJ_TYPE.NO_ACTIVE, "cursor", "graphics/minigames/29_portrait/cursor", -100, -100);
    --ItemSetScale("cursor", 1.6)
    
    clScreenManager:add_screen("hud") 
end

