
require( "scripts/style.lua" );

kButtonSpacing = 45;
kButtonY = 90;
kButtonYFirstStart = 85;
kButtonX = 29;

MakeDialog
{
	-- Name the modal dialog
	name="topmodal",
  MainMenu
	{
		name = "mainmenu",
		image_background_left  = "backgrounds/main_menu/background_left",
		image_background_right = "backgrounds/main_menu/background_right",
		image_foreground_left  = "backgrounds/main_menu/foreground_left",
		image_foreground_right = "backgrounds/main_menu/foreground_right",
		image_scrolling_left   = "backgrounds/main_menu/image_scrolling_left",
		image_scrolling_right  = "backgrounds/main_menu/image_scrolling_right",
    
    scrolling_speed = 0, -- en pixels par seconde
    
		--fit=true;
	    x=0,
	    y=0,
		
    -- First Start Layout
    Bitmap
    {
      x=kCenter,
      y=kCenter + 111,
    
      name = "menu_selection_background_first_start",
      
      image = "backgrounds/background_menu_selection",
      
      Text
      {
        font = BookAntiquaTitle28Font,
        name = "welcome_message",
        label = "welcome_message",
        x = 10, 
        y = kButtonYFirstStart - 20,
        w=280,
        h=55,
        flags = kVAlignCenter + kHAlignCenter,
      },
      
      SetStyle( MenuButtonStyle ),
      Button
      {
        x= kButtonX,
        y= kButtonYFirstStart + (kButtonSpacing * 1),
        rolloversound = "sounds/gui/rollover/menu_1.ogg",
        name="first_play",
        --MenuButtonLabel("play"),
        label = "play",
        
        type = kPush,
        command=
          function()
            -- Switch to the appropriate screen
            name = DoModal("scripts/entername.lua");
          if( not( name == nil ) ) then
            CreateNewTribe( name );
            Start();
            SwapToModal("scripts/cinematic_1.lua");
          end
            --end
          end
      },
      
      Button
      {
        x= kButtonX,
        y= kButtonYFirstStart + (kButtonSpacing * 2),
        rolloversound = "sounds/gui/rollover/menu_2.ogg",
        name="options",
        --MenuButtonLabel("options"),
        label = "options",
        type = kPush,
        command=
          function()
            DoModal("scripts/options.lua");
          end
      },

      Button
      {
        x= kButtonX,
        y= kButtonYFirstStart + (kButtonSpacing * 3),
        rolloversound = "sounds/gui/rollover/menu_3.ogg",
        name="highscores",
        label = "highscores",
        type = kPush,
        command=
          function()
            --SwapToModal("scripts/hiscore.lua");
            --@ToDo
          end
      },
      
      Button
      {
        x= kButtonX,
        y= kButtonYFirstStart + (kButtonSpacing * 4),
        rolloversound = "sounds/gui/rollover/menu_4.ogg",
        name="credits",
        label = "credits",
        type = kPush,
        command=
            function()
              DoModal("scripts/credits.lua");            
            end
      },

      Button
      {
        x= kButtonX,
        y= kButtonYFirstStart + (kButtonSpacing * 5),
        rolloversound = "sounds/gui/rollover/menu_5.ogg",
        name="quit",
        --MenuButtonLabel("quit"),
        label = "quit",
        type = kPush,
        command=
          function()
            result = DisplayDialog {
              "scripts/yesno.lua",
              body ="quitconfirm",
              title = "quittitle"
            };
            if (result=='yes') then
              PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
            end
          end
      },
    },
    
    -- Standard Layout
		Bitmap
	  {
		  x=kCenter,
		  y= 251,
	
		  name = "menu_selection_background",
		
		  image = "backgrounds/background_menu_selection",     
      
      Text
      {
        font = BookAntiquaTitle28Font,
        name = "welcome_message",
        label = "welcome_message",
        x = 10, 
        y = kButtonY - 50,
        w=280,
        h=55,
        flags = kVAlignCenter + kHAlignCenter,
      },
		
       -- Current tribe name
      Bitmap
      {
        x = kCenter,
        y = kButtonY - 5,
        image="buttons/main_menu_player_bouton.png",
        name = "current_tribe_name_window",
        
        Text
        {
          font = BookAntiquaLegend24Font,
          name = "current_tribe_name",
          x=kCenter, y=kCenter,
          w=150,h=kMax,
          flags = kVAlignCenter + kHAlignCenter,
        },
        
        SetStyle( SwitchPlayerButtonStyle ),
        Button
        {
          x= 15, y=kCenter,
          name= "switch_player_left",
          command = 
            function()
              SelectNextTribe( true );
            end
        },
       
        Button
        {
          x= 195, y=kCenter,
          name= "switch_player_right",
          hflip = true,
          command = 
            function()
              SelectNextTribe( false );
            end
        },
      },
    
		  SetStyle( MenuButtonStyle ),      
			Button
			{
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 1),
				rolloversound = "sounds/gui/rollover/menu_1.ogg",
				name="play",
				--MenuButtonLabel("play"),
				label = "continue",
				
				type = kPush,
				command=
					function()
  					-- Switch to the appropriate screen
					  Continue();
						SwapToModal( "scripts/game.lua" );
						--end
					end
			},
      
      Bitmap
			{
				name = "fake_play",
				x = kButtonX,
				y = kButtonY + (kButtonSpacing * 1),
				
				image = "buttons/main_menu_button_off.png",
				
				Text
				{
					flags = kVAlignCenter + kHAlignCenter,
					label = "continue",
					x = 22,
					y = 5,
				},
			},
			
      Button
      {
        x=kButtonX,
        y=kButtonY + (kButtonSpacing * 2),
        rolloversound = "sounds/gui/rollover/menu_2.ogg",
        name="startover",
        --MenuButtonLabel("startover"),
        label = "startover",
        type = kPush,
        command=
          function()
            -- Switch to the appropriate screen
            if( IsCurrentSaveFileExist() ) then
              result = DisplayDialog {
                "scripts/yesno.lua",
                body ="startoverconfirm",
                title = "startovertitle"
              };
              if(result == 'yes') then
                Restart();
                SwapToModal("scripts/cinematic_1.lua");
              end
            else
              Start();
              SwapToModal("scripts/cinematic_1.lua");
            end
          end
      },
        
      Button
      {
        x=kButtonX,
        y=kButtonY + (kButtonSpacing * 3),
        rolloversound = "sounds/gui/rollover/menu_3.ogg",
        name="changetribe",
        --MenuButtonLabel("changetribe"),
        label = "modifytribe",
        type = kPush,
        command=
          function()
            name = DoModal( "scripts/choosetribe.lua" );
            if( not( name == nil ) ) then
              CreateNewTribe( name );
              Start();
              SwapToModal("scripts/cinematic_1.lua");
            end
          end
      },

      Button
      {
        x=kButtonX,
        y=kButtonY + (kButtonSpacing * 4),
        rolloversound = "sounds/gui/rollover/menu_4.ogg",
        name="options",
        label = "options",
        type = kPush,
        command=
          function()
            DoModal("scripts/options.lua");
          end
      },

      Button
      {
        x=kButtonX,
        y=kButtonY + (kButtonSpacing * 5),
        rolloversound = "sounds/gui/rollover/menu_5.ogg",
        name="highscores",
        label = "highscores",
        type = kPush,
        command=
          function()
            DoModal("scripts/hiscore.lua");
          end
      },
      
	  Bitmap
			{
				name = "fake_highscores",
				x=kButtonX,
				y=kButtonY + (kButtonSpacing * 5),
				
				image = "buttons/main_menu_button_off.png",
				
				Text
				{
					flags = kVAlignCenter + kHAlignCenter,
					label = "highscores",
					x = 22,
					y = 5,
				},
			},
			
      Button
      {
        x= kButtonX,
        y= kButtonY + (kButtonSpacing * 6),
        rolloversound = "sounds/gui/rollover/menu_6.ogg",
        name="credits",
        label = "credits",
        type = kPush,
        command=
            function()
              DoModal("scripts/credits.lua");
            end
      },
      
      Button
      {
        x=kButtonX,
        y=kButtonY + (kButtonSpacing * 7),
        rolloversound = "sounds/gui/rollover/menu_7.ogg",
        name="quit",
        --MenuButtonLabel("quit"),
        label = "quit",
        type = kPush,
        command=
          function()
            result = DisplayDialog {
              "scripts/yesno.lua",
              body ="quitconfirm",
              title = "quittitle"
            };
            if (result=='yes') then
              PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
            end
          end
      },		
	  },
    
   
    
    -- Title
	  Bitmap
    {
    name = "title",
     x=kCenter ,
     y=kCenter - 300,
    --name = "font_tempo"
     image = "backgrounds/font_temporaire" ,
    },
		
    -- Logo GOA
		Bitmap
	  {
     name = "logo_goa",
     x=kCenter + 465,
     y=kCenter + 335,
     
     image = "backgrounds/logo_orange" ,
	  },
	  
	  -- Logo Oberion
		Bitmap
	  {
     name = "logo_goa",
     x=kCenter + 390,
     y=kCenter + 335,
     
     image = "backgrounds/oberon_logo_54x61" ,
	  },
		
    -- Logo Kylotonn + credits
		Bitmap
		{
			x = kCenter + 315,
			y = kCenter + 335,
			name="credits",
			image = "backgrounds/logo_kylotonn",

		},
	}
}
