Exemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="panel">Panel hosting this collection</param>
 public ScreenComponentCollection(PanelScreenComponent panel)
 {
     this.panel = panel;
     components = new List <BaseScreenComponent>();
 }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            // Load textures
            Texture2D backgroundTexture = Game.Content.Load <Texture2D>("Textures/solid225-tiling");

            // Load fonts
            SpriteFont menuFont2 = Game.Content.Load <SpriteFont>("Fonts/MenuFont2");

            // Create gui manager
            gui = new InterfaceManager(core);

            // Add a stack panel for menu items
            PanelScreenComponent panel = new PanelScreenComponent(core, Vector2.Zero, new Vector2(400, 200));

            panel.HorizontalAlignment     = HorizontalAlignment.Center;
            panel.VerticalAlignment       = VerticalAlignment.Middle;
            panel.BackgroundTexture       = backgroundTexture;
            panel.BackgroundTextureLayout = TextureLayout.Tile;
            panel.TopMargin    = 20;
            panel.LeftMargin   = 20;
            panel.RightMargin  = 20;
            panel.BottomMargin = 10;

            // Set panel borders
            panel.SetBorderTextures(
                Game.Content.Load <Texture2D>("Textures/top-left"),
                Game.Content.Load <Texture2D>("Textures/top"),
                Game.Content.Load <Texture2D>("Textures/top-right"),
                Game.Content.Load <Texture2D>("Textures/left"),
                Game.Content.Load <Texture2D>("Textures/right"),
                Game.Content.Load <Texture2D>("Textures/bottom-left"),
                Game.Content.Load <Texture2D>("Textures/bottom"),
                Game.Content.Load <Texture2D>("Textures/bottom-right"));
            panel.EnableBorder = true;

            // Add stack panel to gui
            gui.Components.Add(panel);

            // Exit game text
            TextItemScreenComponent exitGameText = new TextItemScreenComponent(core, menuFont2, "Exit Game?");

            exitGameText.HorizontalAlignment = HorizontalAlignment.Center;
            exitGameText.VerticalAlignment   = VerticalAlignment.Top;
            exitGameText.EnableOutline       = true;
            exitGameText.OutlineColor        = Color.Black;
            exitGameText.ShadowColor         = Color.Black;
            exitGameText.ShadowVector        = new Vector2(3, 3);

            // Continue button
            TextItemScreenComponent continueButton = new TextItemScreenComponent(core, menuFont2, "Back");

            continueButton.HorizontalAlignment = HorizontalAlignment.Left;
            continueButton.VerticalAlignment   = VerticalAlignment.Bottom;
            continueButton.EnableOutline       = false;
            continueButton.OutlineColor        = Color.Goldenrod;

            // Exit button
            TextItemScreenComponent exitButton = new TextItemScreenComponent(core, menuFont2, "Exit");

            exitButton.HorizontalAlignment = HorizontalAlignment.Right;
            exitButton.VerticalAlignment   = VerticalAlignment.Bottom;
            exitButton.EnableOutline       = false;
            exitButton.OutlineColor        = Color.Goldenrod;

            // Wire up events
            continueButton.OnMouseEnter += new EventHandler(OnMouseEnter);
            continueButton.OnMouseLeave += new EventHandler(OnMouseLeave);
            continueButton.OnMouseClick += new EventHandler(ContinueButton_OnMouseClick);
            exitButton.OnMouseEnter     += new EventHandler(OnMouseEnter);
            exitButton.OnMouseLeave     += new EventHandler(OnMouseLeave);
            exitButton.OnMouseClick     += new EventHandler(ExitButton_OnMouseClick);

            // Add items to stack panel
            panel.Components.Add(exitGameText);
            panel.Components.Add(exitButton);
            panel.Components.Add(continueButton);
        }