Exemplo n.º 1
0
        public override void ThrowPushEvent()
        {
            Menu menu = new Menu();

            MenuElement backMenuElement = new MenuElement();
            backMenuElement.SetThrowPushEvent(new Action(() => { Master.Pop(); }));
            backMenuElement.ActiveArea = new Rectangle(100,200,300,100);
            backMenuElement.ForegroundColor = Color.Aquamarine;
            backMenuElement.BackgroundColor = Color.Indigo;
            backMenuElement.MenuText = "Back";
            backMenuElement.Selectable = true;
            backMenuElement.Hidden = false;
            backMenuElement.SpriteFont = @"Fonts\MenuItem";

            MenuElement exitMenuElement = new MenuElement();
            exitMenuElement.SetThrowPushEvent(new Action(() => { Master.GetGame().Exit(); }));
            exitMenuElement.ActiveArea = new Rectangle(100, 450, 300, 100);
            exitMenuElement.ForegroundColor = Color.Azure;
            exitMenuElement.ActiveForegroundColor = Color.Gold;
            exitMenuElement.BackgroundColor = Color.AntiqueWhite;
            exitMenuElement.ActiveBackgroundColor = Color.LightCyan;
            exitMenuElement.Hidden = false;
            exitMenuElement.MenuText = "Exit Game";
            exitMenuElement.Selectable = true;
            exitMenuElement.SpriteFont = @"Fonts\MenuItem";
            exitMenuElement.Texture2D = @"Debug\Collision\collisionUnitA";

            List<MenuElement> menuElements = new List<MenuElement>();

            menuElements.Add(backMenuElement);
            menuElements.Add(exitMenuElement);

            menu.AddMenuElements(menuElements);

            XMLEngine<Menu>.SaveToFile("testSaveMenu-001.xml", menu);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a MenuElement to the end of the list.
 /// </summary>
 /// <param name="menuElement"></param>
 public void AddMenuElement(MenuElement menuElement)
 {
     this.MenuElements.Add(menuElement);
     this.Recache();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a MenuElement to the end of the list.
 /// </summary>
 /// <param name="menuElement"></param>
 public void AddMenuElement(MenuElement menuElement)
 {
     this.MenuElements.Add(menuElement);
     this.Recache();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Contains abstract Draw logic for the Menu.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch</param>
        protected internal void DrawMenu(SpriteBatch spriteBatch)
        {
            int i = 0;

            foreach (MenuElement element in this._menu.GetDrawableMenuElements())
            {
                //Draw in this order:
                //  BackgroundColor
                //  Texture
                //  Font
                if (element.BackgroundColor.PackedValue != 0)
                {
                    int   activeMenuIndex = _menu.GetActiveMenuIndex();
                    Color bgcolor;
                    bool  currentElementIsActive = this._menu.GetDrawableMenuElements()[i].Equals(this._menu.GetSelectableMenuElements()[activeMenuIndex]);
                    if (currentElementIsActive)
                    {
                        if (element.ActiveBackgroundColor.PackedValue != 0)
                        {
                            bgcolor = element.ActiveBackgroundColor;
                        }
                        else
                        {
                            bgcolor = element.BackgroundColor;
                        }
                    }
                    else
                    {
                        bgcolor = element.BackgroundColor;
                    }

                    _drawingHelper.DefaultDrawRectangle(ref spriteBatch, element.ActiveArea, ref blank, bgcolor);
                }

                if (element.GetTexture() != null)
                {
                    spriteBatch.Draw(element.GetTexture(), element.ActiveArea, Color.White);
                }

                if (element.GetFont() != null && !string.IsNullOrEmpty(element.MenuText))
                {
                    int   activeMenuIndex = _menu.GetActiveMenuIndex();
                    Color fgcolor;

                    MenuElement drawingElemTmp         = this._menu.GetDrawableMenuElements()[i];
                    MenuElement selectedElemTmp        = this._menu.GetSelectableMenuElements()[activeMenuIndex];
                    bool        currentElementIsActive = this._menu.GetDrawableMenuElements()[i].Equals(this._menu.GetSelectableMenuElements()[activeMenuIndex]);
                    if (currentElementIsActive)
                    {
                        if (element.ActiveForegroundColor.PackedValue != 0)
                        {
                            fgcolor = element.ActiveForegroundColor;
                        }
                        else
                        {
                            fgcolor = element.ForegroundColor;
                        }
                    }
                    else
                    {
                        fgcolor = element.ForegroundColor;
                    }

                    spriteBatch.DrawString(element.GetFont(), element.MenuText, new Vector2(element.ActiveArea.X, element.ActiveArea.Y), fgcolor);
                }
                i++;
            }
        }