require( "scripts/style.lua" );
require( "scripts/ui/controls.lua" );
require( "scripts/ui/style_text.lua" );
require( "scripts/quitverify.lua" );
require( "scripts/game_sector_loading.lua" );

require ('facebook/common/facebook_functions.lua');
require ('facebook/common/facebook_friendfeed.lua');

PlaySound("audio/sfx/main_menu/screenswitch.ogg");

CopyrightFont = {
    standardFont,
    18,
    WhiteColor,
};

MainButtonGraphics = {
    "main_menu/main_btn/button",
    "main_menu/main_btn/button_p",
    "main_menu/main_btn/button_a",
};
PlayerButtonGraphics = {
    "main_menu/player_btn/player",
    "main_menu/player_btn/player_p",
    "main_menu/player_btn/player_a",
};
QuitMoreButtonGraphics = {
    "main_menu/quit_more_btn/quit",
    "main_menu/quit_more_btn/quit_p",
    "main_menu/quit_more_btn/quit_a",
};

function CheckUsers()
    if (GetNumUsers() == 0) then
        gEnterNameValue = "";
        name = DoModal("scripts/entername.lua");
        if (not(name == nil)) then
            CreateNewUser(name);
			SetWelcomeName();
            return true ;
        end
        return false ;
    else
        return true;
    end
end


MakeDialog
{
    -- Name the modal dialog
    MainMenu
    {
        name="mainmenu",
        fit=true;
        w = 1024, h = 768,
        
        Bitmap
        {
            image = "main_menu/moon",
            x = kCenter, y = 0,
        },
        Bitmap
        {
            image = "main_menu/mountain",
            x = 0, y = 0,
        },
        WndTextureScroller
        {
            name = "clouds",
            x = 0,
            y = 0,
            w = 1024,
            h = 340,
            tex_name = "main_menu/cloud",
            scroll_speed = "64,0",
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },
        WndFxSprite
        {
            name = "sun_glow_fx",
            x = 0,
            y = 0,
            w = 1024,
            h = 768,
            effect_position = "800,-40",
            file_name = "fx/main_menu/sun_glow.lua",
            start_activate = true,
            advance = 50,
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },

        Bitmap
        {
            image = "main_menu/house",
            x = 414, y = 0,

            WndFxSprite
            {
                name = "boiler_fx",
                x = 0,
                y = 0,
                w = 512,
                h = 768,
                effect_position = "447,615",
                file_name = "fx/main_menu/boiler.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "left_lamp_firebugs_fx",
                x = 0,
                y = 0,
                w = 512,
                h = 768,
                effect_position = "116,645",
                file_name = "fx/main_menu/lamp_firebugs.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "right_lamp_firebugs_fx",
                x = 0,
                y = 0,
                w = 600,
                h = 768,
                effect_position = "570,665",
                file_name = "fx/main_menu/lamp_firebugs.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "left_lamp_light_fx",
                x = 0,
                y = 0,
                w = 512,
                h = 768,
                effect_position = "116,645",
                file_name = "fx/main_menu/lamp_light.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },

            WndFxSprite
            {
                name = "right_lamp_light_fx",
                x = 0,
                y = 0,
                w = 600,
                h = 768,
                effect_position = "570,665",
                file_name = "fx/main_menu/lamp_light.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },
            Bitmap
            {
                image = "main_menu/gate",
                x = 194, y = 426,
            },
        },

        Bitmap
        {
            image = "main_menu/tree",
            x = 0, y = 0,
        },
        Bitmap
        {
            image = "main_menu/flower",
            x = 0, y = 544,
        },
        
        Bitmap
        {
            image = "main_menu/mirror",
            x = 62, y = 252,
            
            WndFxSprite
            {
                name = "mirror_fx",
                x = 0,
                y = 0,
                w = 400,
                h = 400,
                effect_position = "150,180",
                file_name = "fx/main_menu/mirror.lua",
                start_activate = true,
                advance = 50,
                timer_settings = {
                    name = "ui",
                    category = "UI",
                },
            },
            
            MenuMirrorButton
            {
                x = kCenter, y = 90,
                name = "start",
                label = "start",
                graphics = MainButtonGraphics,
                sound = kMenuButtonSound,
                rolloversound = kMenuRolloverSound,
                type = kPush,
                font = CreateNamedFont(LucidaSymbolSet, 24, WhiteColor),
                mask = "main_menu/main_btn/button_alpha",
                command = function()
                    if CheckUsers() then
                        PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                        kQuitConfirmShowed = true;
                        if (GetCount("cutscene_1_showed") == 0) then
                            local function Func()
                                SetDefaultStyle(FlashComicStyle);
                                DisplaySplash("cutscenes/scene_1.swf", "", 4000);
                                SwapToModal("scripts/map.lua");
                            end
                            SetItemCount("cutscene_1_showed", 1);
                            table.insert(gCommandQueue, Func);
                        else
                            SwapToModal("scripts/map.lua");
                        end;
                    end;
                end,
            },
            MenuMirrorButton
            {
                x = kCenter,
                y = 130,
                name = "highscores",
                label = "highscores",
                type = kPush,
                graphics = MainButtonGraphics,
                sound = kMenuButtonSound,
                rolloversound = kMenuRolloverSound,
                font = CreateNamedFont(LucidaSymbolSet, 24, WhiteColor),
                mask = "main_menu/main_btn/button_alpha",
                command = function()
                    PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                    DoModal("scripts/hiscore.lua");
                end,
            },
            MenuMirrorButton
            {
                x = kCenter,
                y = 170,
                name = "medals",
                label = "medals",
                type = kPush,
                graphics = MainButtonGraphics,
                sound = kMenuButtonSound,
                rolloversound = kMenuRolloverSound,
                font = CreateNamedFont(LucidaSymbolSet, 24, WhiteColor),
                mask = "main_menu/main_btn/button_alpha",
                command = function()
                    PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                    SwapToModal("scripts/trophies.lua");
                end,
            },
            MenuMirrorButton
            {
                x = kCenter, y = 210,
                name = "options",
                label = "options",
                graphics = MainButtonGraphics,
                sound = kMenuButtonSound,
                rolloversound = kMenuRolloverSound,
                mask = "main_menu/main_btn/button_alpha",
                type = kPush,
                font = CreateNamedFont(LucidaSymbolSet, 24, WhiteColor),
                command = function()
                    --PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                    DoModal("scripts/options_main.lua");
                end
            },
            MenuMirrorButton
            {
                x = kCenter, y = 250,
                name = "help",
                label = "help",
                type = kPush,
                graphics=MainButtonGraphics,
                sound = kMenuButtonSound,
                rolloversound = kMenuRolloverSound,
                mask = "main_menu/main_btn/button_alpha",
                font = CreateNamedFont(LucidaSymbolSet, 24, WhiteColor),
                command = function()
                    PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                    DoModal("scripts/help.lua");
                end
            },
        },
        
        Bitmap
        {
            image = "main_menu/logo",
            x = kCenter, y = 0,
        },
        
        Button
        {
            x = 10, y = 658,
            name = "quit",
            type = kPush,
            graphics=QuitMoreButtonGraphics,
            sound = kMenuButtonSound,
            rolloversound = kMenuRolloverSound,
            mask = "main_menu/quit_more_btn/quit_alpha",
            command = function()
                PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                ShowQuitConfirmDlg();
            end,
            SetStyle(TextStyle),
            CreateMinionText(22, CaptionBrown, kCenter+5, kCenter+6, "#"..GetString("caption_outline", GetString("quit")), 160, 22),
            CreateMinionText(22, CaptionYellow, kCenter+4, kCenter+5, "#"..GetString("caption_outline", GetString("quit")), 160, 22),
        },

        Button
        {
            x = 240, y = 658,
            name = "changeplayer",
            type = kPush,
            graphics=PlayerButtonGraphics,
            sound = kMenuButtonSound,
            rolloversound = kMenuRolloverSound,
            mask = "main_menu/player_btn/player_alpha",
            command = function()
                PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                DoModal("scripts/chooseplayer.lua");
            end,
            SetStyle(TextStyle),
            CreateMinionText(20, CaptionBrown, kCenter-6, kCenter+6, "#"..GetString("caption_outline", GetString("changeplayer")), 160, 22),
            CreateMinionText(20, CaptionYellow, kCenter-7, kCenter+5, "#"..GetString("caption_outline", GetString("changeplayer")), 160, 22),
        },

        Button
        {
            x = 830, y = 658,
            name = "moregames",
            graphics=QuitMoreButtonGraphics,
            sound = kMenuButtonSound,
            rolloversound = kMenuRolloverSound,
            hflip = true,
            mask = "main_menu/quit_more_btn/quit_alpha",
            command = function()
                PlaySound("audio/sfx/main_menu/screenswitch.ogg");
                CR_HideEffect();
                DoModal("xsell/xsell.lua");
                CR_ShowEffect();
            end,
            SetStyle(TextStyle),
            CreateMinionText(22, CaptionBrown, kCenter-5, kCenter+6, "#"..GetString("caption_outline", GetString("moregames")), 160, 22),
            CreateMinionText(22, CaptionYellow, kCenter-6, kCenter+5, "#"..GetString("caption_outline", GetString("moregames")), 160, 22),
        },

        CreateShadowText(16, WhiteColor, 20, 15, "copyright", 1000, 18),
        
        SetStyle({flags = kVAlignCenter + kHAlignCenter,}),
        CreateMinionNamedShadowText(20, WhiteColor, 95, 660, "welcome", 450, 24, "welcome"),
        
       
        --------------------------------------------------------------------------------------------
        -- FX
        --------------------------------------------------------------------------------------------

        WndFxSprite
        {
            name = "falling_leaves_fx",
            x = 0,
            y = 0,
            w = 1024,
            h = 768,
            effect_position = "256,192",
            file_name = "fx/main_menu/falling_leaves.lua",
            start_activate = true,
            advance = 50,
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },

        WndFxSprite
        {
            name = "light_rays_fx",
            x = 0,
            y = 0,
            w = 1024,
            h = 768,
            effect_position = "256,192",
            file_name = "fx/main_menu/light_rays.lua",
            start_activate = true,
            advance = 50,
            param_1 = {
                type = "float",
                name = "dTotalAlpha",
                value = "1"
            },
            timer_settings = {
                name = "ui",
                category = "UI",
            },
        },
        -- top left corner
        Bitmap
        {
            image="map/rama_top",
            x = 32, y = 0,
        },
        Bitmap
        {
            image="map/rama_left",
            x = 0, y = 0,
        },
        -- top right corner
        Bitmap
        {
            image="map/rama_top",
            x = 512, y = 0,
            hflip = true,
        },
        
        Bitmap
        {
            image="map/rama_left",
            x = 992, y = 0,
            hflip = true,
        },
        -- bottom left corner
        Bitmap
        {
            image="map/rama_top",
            x = 32, y = 736,
            vflip = true,
        },
        Bitmap
        {
            image="map/rama_left",
            x = 0, y = 384,
            vflip = true,
        },
        -- bottom right corner
        Bitmap
        {
            image="map/rama_top",
            x = 512, y = 736,
            vflip = true,
            hflip = true,
        },
        Bitmap
        {
            image="map/rama_left",
            x = 992, y = 384,
            vflip = true,
            hflip = true,
        },
        SetStyle({}),
        CreateFriendFeed(CheckUsers, FBConnectPress);
        CreateFriendFeedPopup();
    },
}
