예제 #1
0
        protected override void LoadContent()
        {
            ContentManager Content = GameRef.Content;
            backgroundImage = Content.Load<Texture2D>(@"Backgrounds\titlescreen");
            base.LoadContent();

            startLabel = new LinkLabel();
            startLabel.Position = new Vector2(350, 600);
            startLabel.Text = "Press ENTER to begin";
            startLabel.Color = Color.White;
            startLabel.TabStop = true;
            startLabel.HasFocus = true;
            startLabel.Selected += new EventHandler(startLabel_Selected);
            ControlManager.Add(startLabel);
        }
예제 #2
0
        protected override void LoadContent()
        {
            // have to call first so that the ControlManager exists
            base.LoadContent();

            ContentManager Content = Game.Content;
            // the Picture for the Background
            backgroundImage = new PictureBox(
                Content.Load<Texture2D>(@"Backgrounds\titlescreen"),
                GameRef.ScreenRectangle);
            // add the PictureBox to the ControlManager how will add the control to the
            ControlManager.Add(backgroundImage);

            Texture2D arrowTexture = Content.Load<Texture2D>(@"GUI\leftarrowUp");

            arrowImage = new PictureBox(
                arrowTexture,
                new Rectangle(
                    0,
                    0,
                    arrowTexture.Width,
                    arrowTexture.Height));
            ControlManager.Add(arrowImage);

            startGame = new LinkLabel();
            startGame.Text = "Start xy \na new cool line";
            // size it to the Size of the text with that SpriteFont
            startGame.Size = startGame.SpriteFont.MeasureString(startGame.Text);
            // that will handle the Selected event of all menu items.
            startGame.Selected += new EventHandler(menuItem_Selected);

            ControlManager.Add(startGame);

            loadGame = new LinkLabel();
            loadGame.Text = "Load xy";
            loadGame.Size = loadGame.SpriteFont.MeasureString(loadGame.Text);
            loadGame.Selected += menuItem_Selected;

            ControlManager.Add(loadGame);

            Label advice = new Label();
            advice.Text = "A big advice for the Game";
            advice.Size = advice.SpriteFont.MeasureString(advice.Text);
            advice.Position = new Vector2(25f, 25f);

            ControlManager.Add(advice);

            exitGame = new LinkLabel();
            exitGame.Text = "xy exit";
            exitGame.Size = exitGame.SpriteFont.MeasureString(exitGame.Text);
            exitGame.Selected += menuItem_Selected;

            ControlManager.Add(exitGame);

            ControlManager.NextControl();

            ControlManager.FocusChanged += new EventHandler(ControlManager_FocusChanged);
            Vector2 position = new Vector2(350, 500);

            // In the loop I check to see if the control is a
            // LinkLabel. If it is I compare the X property of its size with maxItemWidth field. If it is greater I set
            // maxItemWidth to that value. I then set the Position property of the control to the Vector2 I created. I
            // then increase the Y property of the Vector2 by the Y property of the Size property of the control plus
            // five pixels.
            foreach (Control c in ControlManager)
            {
                if (c is LinkLabel)
                {
                    if (c.Size.X > maxItemWidth)
                        maxItemWidth = c.Size.X;

                    c.Position = position;
                    position.Y += c.Size.Y + 5f;

                }
            }
            // I call the FocusChanged event handler passing in the startGame control and
            // null. What this does is call the code that positions the arrow to the right of the sender. In this case, the
            // arrow will be to the right of the startGame item.
            ControlManager_FocusChanged(startGame, null);
        }