function GameScreen:InitScreen()
    self:LoadScreen()
    
    self.disable = false;
    ItemSetOpacity("hud", 0.0)
    ItemSetOpacity("menu_button", 0.0)
    ItemSetOpacity("inventory", 0.0)
   
    clApplication.game_pause = true;
    
    self:update_welcome();
    
    if(self.music_menu == nil) then
        --self.music_menu = true;
        --PlayMenuMusic("sound/music/plagium.ogg", false)
        --MusicPause(true);
    end
    
    HintTest:Remove()
    Tip:Remove()
    
    self:FadeOut(0.0);
    
    cpp_application_add_window("hide_screen");
    cpp_create_sprite("hide_screen", OBJ_TYPE.ACTIVE_ALL, "wp_back_trigger", "graphics/trigger", 0, 0);
    cpp_item_set_size("wp_back_trigger", WINDOW_WIDTH, WINDOW_HEIGHT);
    ItemChangeOpacity("wp_back_trigger", 0.0, 0.8)
    
    DelayedExec(0.8, function()
        cpp_application_remove_window("hide_screen");
    end)
    
    StopSound(generator_sound, 0.3)
    StopSound(generator_sound2, 0.3)  
    StopSound(pc_sound, 0.3)
    StopSound(pc_sound_mg, 0.3)
    
    clScreenManager:remove_screen_by_name("tool_found_screen")
    
    clScreenManager:remove_screen(CurrentScreen);
    if(current_comics) then
        clScreenManager:remove_screen(current_comics);
    end
end

function GameScreen:ShowLogo()
    ItemSetPosition("logo_text", 334, 684)
    ItemSetOpacity("logo_hands", 1.0)
    self.disable = true;
    DelayedExec(4.0, function()
        ItemChangeOpacity("logo_hands", 0.0, 1.5)
    end)
    DelayedExec(5.5, function()
        ItemMoveTo("logo_text", 334, 13, 1.0)
    end)
    ItemSetOpacity("exit", 0.0)
    ItemSetOpacity("credits", 0.0)
    ItemSetOpacity("options", 0.0)
    ItemSetOpacity("change_player", 0.0)
    ItemSetOpacity("play", 0.0)
    ItemSetOpacity("welcome_text", 0.0)
    ItemSetOpacity("main_menu_background", 0.0)
    
    DelayedExec(6.5, function()
        self.disable = false;
        ItemChangeOpacity("exit", 1.0, 0.3)
        ItemChangeOpacity("credits", 1.0, 0.3)
        ItemChangeOpacity("options", 1.0, 0.3)
        ItemChangeOpacity("change_player", 1.0, 0.3)
        ItemChangeOpacity("play", 1.0, 0.3)
        ItemChangeOpacity("welcome_text", 1.0, 0.3)
        ItemChangeOpacity("main_menu_background", 1.0, 0.3)
    end)
end

local __start_game = function()
    MusicPause(false);
    StopMenuMusic();
    

    DelayedExec(0.7, function()
        clApplication.game_pause = false;
        ItemSetOpacity("menu_button", 1.0)
        ItemSetOpacity("inventory", 1.0)
        HUDScreen:Show()
        --if(DragObject and DragObject.active) then
	    --    SetVisibleCursor(false)
	    --end
        
        CurrentScreen:UnPauseScreen()
        
        local last_level = "000_before"
        if(GetState("GLOBAL", "last_screen") ~= "") then
            last_level = GetState("GLOBAL", "last_screen");
        end
        
        clApplication:LoadLocation(last_level, true)
    end)
end

function GameScreen:OnClick(item_name)
    if(self.disable) then return end

    if("play" == item_name and GetState("GLOBAL", "finish") == "true") then
        local old_name = cpp_get_cur_player()
        cpp_add_player("temp_"..old_name)
        cpp_remove_player(old_name);
        cpp_add_player(old_name)
        cpp_set_current_player(old_name)
        cpp_save_players()
        cpp_remove_player("temp_"..old_name);
        
        self.disable = true
        SoundPlay("sound/interface/button.ogg")

        clScreenManager:remove_screen(self); 
        ItemSetOpacity("background", 0.0)
        SetState("GLOBAL", "is_played", "1")
            
        clApplication.curret_win = clScreenManager:add_screen("interactive_help")
        clApplication.curret_win.end_fun = function()
            --__start_game();
            MusicPause(false);
            StopMenuMusic();
            DelayedExec(0.5, function()
                clApplication.game_pause = false;
                clApplication:LoadLocation("chapters_screen")
            end)
        end
    elseif("play" == item_name and GetState("GLOBAL", "finish") ~= "true") then
        self.disable = true
        SoundPlay("sound/interface/button.ogg")
        if(GetState("GLOBAL", "is_played") == "") then
            clScreenManager:remove_screen(self); 
            --ItemSetOpacity("background", 0.0)
            SetState("GLOBAL", "is_played", "1")
            --self:FadeIn(0.5);
        
            old_player_name = cpp_get_cur_player();
            if(old_player_name == "NewPlayer") then
                clApplication.curret_win = clScreenManager:add_screen("rename_player_screen")
                clApplication.curret_win.old_name = cpp_get_cur_player();
                clApplication.curret_win.end_fun = function()
                    clApplication.curret_win = clScreenManager:add_screen("interactive_help")
                    clApplication.curret_win.end_fun = function()
                        --__start_game();
                        MusicPause(false);
                        StopMenuMusic();
                        DelayedExec(0.5, function()
                            clApplication.game_pause = false;
                            ItemSetOpacity("menu_button", 1.0)
                            ItemSetOpacity("inventory", 1.0)
                            HUDScreen:Show()
                            clApplication:LoadLocation("chapters_screen")
                        end)
                    end
                end
             else
                clApplication.curret_win = clScreenManager:add_screen("interactive_help")
                clApplication.curret_win.end_fun = function()
                    --__start_game();
                    MusicPause(false);
                    StopMenuMusic();
                    DelayedExec(0.5, function()
                        clApplication.game_pause = false;
                        ItemSetOpacity("menu_button", 1.0)
                        ItemSetOpacity("inventory", 1.0)
                        HUDScreen:Show()
                        clApplication:LoadLocation("chapters_screen")
                    end)
                end
             end
        else
            self.disable = true;
            ItemSetPosition(self.name, 1600, 1600)
           -- self:FadeIn(0.5);
           --  DelayedExec(0.7, function()
                clScreenManager:remove_screen(self); 
           -- end)
            __start_game();
        end
    elseif("options" == item_name) then
        self.disable = true
        SoundPlay("sound/interface/button.ogg")
        self:HideMenuButtons(0.5);
        clApplication.curret_win = clScreenManager:add_screen("options_screen") 
        clApplication.curret_win.end_fun = function()
            self.disable = false
            clApplication.curret_win = nil;
            self:ShowMenuButtons(0.5);
        end
    elseif("credits" == item_name) then
        self.disable = true
        SoundPlay("sound/interface/button.ogg")
        self:HideMenuButtons(0.5);
        clApplication.curret_win = clScreenManager:add_screen("credits_screen") 
        clApplication.curret_win.end_fun = function()
            self.disable = false
            clApplication.curret_win = nil;
            self:ShowMenuButtons(0.5);
        end
     elseif("change_player" == item_name) then
        self.disable = true
        SoundPlay("sound/interface/button.ogg")
        self:HideMenuButtons(0.5);
        clApplication.curret_win = clScreenManager:add_screen("change_player_screen") 
        clApplication.curret_win.end_fun = function()
            self:update_welcome();
            self:ShowMenuButtons(0.5)
            clApplication.curret_win = nil;
            self.disable = false
        end   
    elseif("exit" == item_name) then
        if(GetState("OPTIONS", "custom_cursor") == "1") then
            ToggleCustomCursor();
        end
        PostMessage( CreateNamedMessage( kQuitNow, "quit" ) );
    end
end

function GameScreen:HideMenuButtons(time)
    ItemChangeOpacity("credits", 0.0, time)
    ItemChangeOpacity("options", 0.0, time)
    ItemChangeOpacity("change_player", 0.0, time)
    ItemChangeOpacity("play", 0.0, time)
    ItemChangeOpacity("exit", 0.0, time)
    ItemChangeOpacity("welcome_text", 0.0, time)
    ItemChangeOpacity("logo_text", 0.0, time)
    
    DelayedExec(time, function()
        ItemSetPosition("credits", 270, -400)
        ItemSetPosition("options", 270, -400)
        ItemSetPosition("change_player", 270, -400)
        ItemSetPosition("paly", 270, -400)
        ItemSetPosition("exit", 270, -400)
    end)
 end

function GameScreen:ShowMenuButtons(time)
    ItemSetPosition("credits", 635, 865)
    ItemSetPosition("options", 627, 753)
    ItemSetPosition("change_player", 529, 640)
    ItemSetPosition("play", 688, 528)
    ItemSetPosition("exit", 693, 978)
    
    DelayedExec(time, function()
        ItemChangeOpacity("logo_text", 1.0, time)
        ItemChangeOpacity("credits", 1.0, time)
        ItemChangeOpacity("options", 1.0, time)
        ItemChangeOpacity("change_player", 1.0, time)
        ItemChangeOpacity("play", 1.0, time)
        ItemChangeOpacity("exit", 1.0, time)
        ItemChangeOpacity("welcome_text", 1.0, time)
    end)
end

function GameScreen:update_welcome()
    SetLabelText("welcome_text", "Welcome, "..cpp_get_cur_player().."!")
    ItemSetPosition("welcome_text", WINDOW_WIDTH / 2 - ItemGetWidth("welcome_text") / 2, 450)
end

function GameScreen:LoadScreen()
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "mm2", "graphics/interface/menu/mm2", 0, 0);

    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "main_menu_background", "graphics/interface/menu/main_menu_background", 0, 0);
    
    --self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "main_menu_back_trigger", "graphics/trigger", 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    --ItemSetOpacity("main_menu_back_trigger", 0.85)
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "logo_text", "graphics/interface/menu/logo_text", 334, 17);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "logo_hands", "graphics/interface/menu/logo_hands", 534, 51);
    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "exit", "graphics/interface/menu/exit", 693, 978);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "credits", "graphics/interface/menu/credits_mm", 635, 865);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "options", "graphics/interface/menu/options_mm", 627, 753);    
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "change_player", "graphics/interface/menu/change_player", 529, 640);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "play", "graphics/interface/menu/play", 688, 528);
    
    
    self:CreateLabel("welcome_text", "", 0, 450, 60, FONT_QUICKSAND)
    --SetLabelAlign("welcome_text", TEXT_ALIGN.H_CENTER)
    ItemSetSize("welcome_text", 1326, 30)
    ItemSetPosition("welcome_text", WINDOW_WIDTH / 2 - ItemGetWidth("welcome_text") / 2, 450)
    ItemSetColor("welcome_text", 1.0, 1.0, 1.0, 1.0)
        
    ItemSetOpacity("logo_hands", 0.0)
end