示例#1
0
 /** <summary> Adds the specified menu item to the list of menu items. </summary> */
 public DebugMenuItem AddItem(DebugMenuItem item)
 {
     item.Root  = this;
     item.Index = items.Count;
     items.Add(item);
     return(item);
 }
示例#2
0
        /** <summary> Selects the previous menu item. </summary> */
        private void SelectPreviousItem()
        {
            int n = currentItem.Root.Items.Count;

            currentPath[currentPath.Count - 1] = (currentPath[currentPath.Count - 1] + n - 1) % n;
            currentItem = CurrentMenu.Items[currentPath[currentPath.Count - 1]];
        }
示例#3
0
 /** <summary> Steps into the sub menu of the menu item. </summary> */
 private void StepIntoSubMenu()
 {
     if (currentItem.Items.Count > 0)
     {
         currentItem = currentItem.Items[0];
         currentPath.Add(0);
     }
 }
示例#4
0
 /** <summary> Steps out of the sub menu of the menu item. </summary> */
 private void StepOutOfSubMenu()
 {
     if (CurrentMenu.Root != null)
     {
         currentItem = CurrentMenu;
         currentPath.RemoveAt(currentPath.Count - 1);
     }
 }
示例#5
0
 public void Open()
 {
     currentPath.Clear();
     currentPath.Add(0);
     currentItem    = menu.Items[0];
     mouseHoverItem = null;
     open           = true;
 }
        /** <summary> Constructs a menu item with the specified text, action, and hotkey. </summary> */
        public DebugMenuItem(string text, HotKey hotkey, MenuItemAction action)
        {
            this.root			= null;

            this.text			= text;
            this.index			= 0;
            this.hotkey			= hotkey ?? new HotKey();
            this.action			= action;
            this.items			= new List<DebugMenuItem>();
        }
示例#7
0
        //========= CONSTRUCTORS =========
        #region Constructors

        /** <summary> Constructs a menu item with the specified text. </summary> */
        public DebugMenuItem(string text)
        {
            this.root = null;

            this.text   = text;
            this.index  = 0;
            this.hotkey = new HotKey();
            this.action = null;
            this.items  = new List <DebugMenuItem>();
        }
        /** <summary> Constructs a menu item with the specified text. </summary> */
        public DebugMenuItem(string text)
        {
            this.root			= null;

            this.text			= text;
            this.index			= 0;
            this.hotkey			= new HotKey();
            this.action			= null;
            this.items			= new List<DebugMenuItem>();
        }
示例#9
0
        /** <summary> Constructs a menu item with the specified text, action, and hotkey. </summary> */
        public DebugMenuItem(string text, HotKey hotkey, MenuItemAction action)
        {
            this.root = null;

            this.text   = text;
            this.index  = 0;
            this.hotkey = hotkey ?? new HotKey();
            this.action = action;
            this.items  = new List <DebugMenuItem>();
        }
示例#10
0
 /** <summary> Checks for pressed hotkeys. </summary> */
 public void CheckHotkeys(DebugMenuItem item)
 {
     for (int i = 0; i < item.Items.Count; ++i)
     {
         if (item.Items[i].HotKey.Pressed())
         {
             item.Items[i].Press();
         }
         CheckHotkeys(item.Items[i]);
     }
 }
示例#11
0
        //=========== DRAWING ============
        #region Drawing

        /** <summary> Draws the debug menus. </summary> */
        public void Draw(Graphics2D g)
        {
            mouseHover = false;

            DrawMenu(g, menu, 0, Point2I.Zero);

            if (!mouseHover)
            {
                mouseHoverItem = null;
            }
        }
示例#12
0
        /** <summary> The sprite sheet used for the menu items. </summary> */
        //internal SpriteAtlas debugMenuSprites;

        #endregion
        //========= CONSTRUCTORS =========
        #region Constructors

        /** <summary> Constructs the main debug menu. </summary> */
        public DebugMenu()
        {
            this.menu = new DebugMenuItem("root");

            this.currentPath    = new List <int>();
            this.currentItem    = null;
            this.mouseHoverItem = null;
            this.mouseHover     = false;
            this.controlMode    = MenuControlMode.Keyboard;

            this.open = false;

            this.debugMenuFont     = null;
            this.debugMenuFontBold = null;
            this.debugMenuSprites  = null;
        }
示例#13
0
        /** <summary> Reconstructs the menu item path. </summary> */
        private void ReconstructPath(DebugMenuItem item)
        {
            DebugMenuItem menu = item.Root;

            if (menu == null)
            {
                return;
            }

            for (int i = 0; i < menu.Items.Count; ++i)
            {
                DebugMenuItem subItem = menu.Items[i];

                if (subItem == item)
                {
                    currentPath.Insert(0, i);
                    ReconstructPath(menu);
                }
            }
        }
示例#14
0
        /** <summary> Updates the debug menu with mouse controls. </summary> */
        private void UpdateMouseControls()
        {
            // Open submenus when highlighted.
            if (mouseHoverItem != CurrentMenu && mouseHoverItem != null)
            {
                currentItem = mouseHoverItem;
                if (mouseHoverItem.Items.Count > 0)
                {
                    StepIntoSubMenu();
                }
            }

            if (currentItem != null)
            {
                // Create path from highlighted item.
                currentPath.Clear();
                ReconstructPath(currentItem);

                // [Left] Click on the item and then close the menu.
                if (Mouse.IsButtonPressed(MouseButtons.Left) && mouseHoverItem != null)
                {
                    if (currentItem.Items.Count == 0)
                    {
                        currentItem.Press();
                        Close();
                    }
                }

                // [Right] Click on the item without closing the menu.
                else if (Mouse.IsButtonPressed(MouseButtons.Right) && mouseHoverItem != null)
                {
                    if (currentItem.Items.Count == 0)
                    {
                        currentItem.Press();
                    }
                }
            }
        }
示例#15
0
 /** <summary> Steps out of the sub menu of the menu item. </summary> */
 private void StepOutOfSubMenu()
 {
     if (CurrentMenu.Root != null) {
     currentItem = CurrentMenu;
     currentPath.RemoveAt(currentPath.Count - 1);
     }
 }
示例#16
0
 /** <summary> Steps into the sub menu of the menu item. </summary> */
 private void StepIntoSubMenu()
 {
     if (currentItem.Items.Count > 0) {
     currentItem = currentItem.Items[0];
     currentPath.Add(0);
     }
 }
示例#17
0
 /** <summary> Selects the previous menu item. </summary> */
 private void SelectPreviousItem()
 {
     int n = currentItem.Root.Items.Count;
     currentPath[currentPath.Count - 1] = (currentPath[currentPath.Count - 1] + n - 1) % n;
     currentItem = CurrentMenu.Items[currentPath[currentPath.Count - 1]];
 }
示例#18
0
        /** <summary> Reconstructs the menu item path. </summary> */
        private void ReconstructPath(DebugMenuItem item)
        {
            DebugMenuItem menu = item.Root;
            if (menu == null)
            return;

            for (int i = 0; i < menu.Items.Count; ++i) {
            DebugMenuItem subItem = menu.Items[i];

            if (subItem == item) {
                currentPath.Insert(0, i);
                ReconstructPath(menu);
            }
            }
        }
示例#19
0
        /** <summary> Draws the debug menu. </summary> */
        private void DrawMenu(Graphics2D g, DebugMenuItem item, int pathIndex, Point2I position)
        {
            if (pathIndex >= currentPath.Count)
            return;

            int itemWidth  = 32;
            int itemHeight = 28;
            int offset = 32;
            int textOffset   = 0;
            int hotkeyOffset = 0;
            int hotkeyColumnWidth = 0;
            int textColumnWidth = 0;
            int rightPading = 24;
            //int padding = 20;
            int hotkeyColumnPadding = 20;
            if (pathIndex == 0) {
            offset = 6;
            rightPading = 8;
            hotkeyColumnPadding = 0;
            }

            // Measure the width to draw the menu at.
            for (int i = 0; i < item.Items.Count; ++i) {
            DebugMenuItem subItem = item.Items[i];

            Rectangle2I r1 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.Text, Align.Left);
            Rectangle2I r2 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.HotKey.Name, Align.Left);
            hotkeyOffset = GMath.Max(hotkeyOffset, r1.Width + offset + 10);
            itemWidth = GMath.Max(itemWidth, r1.Width + r2.Width + offset + rightPading);
            textColumnWidth   = GMath.Max(textColumnWidth, r1.Width);
            hotkeyColumnWidth = GMath.Max(hotkeyColumnWidth, r2.Width);
            }
            hotkeyOffset = offset + textColumnWidth + hotkeyColumnPadding;
            textOffset = offset;
            itemWidth = offset + textColumnWidth + hotkeyColumnPadding + hotkeyColumnWidth + rightPading;

            // Draw outline.
            Rectangle2I menuRect = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight * item.Items.Count);
            if (pathIndex == 0) {
            menuRect.Width = itemWidth * item.Items.Count;
            menuRect.Height = itemHeight;
            }
            g.DrawRectangle(menuRect, 1.0f, colorOutline);

            // Draw background.
            menuRect.Inflate(-1, -1);
            g.FillRectangle(menuRect, colorBackground);

            // Draw item list.
            for (int i = 0; i < item.Items.Count; ++i) {
            Rectangle2I r = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight);

            if (pathIndex == 0) {
                r.Inflate(0, -1);
                if (i == 0) {
                    r.X += 1;
                    r.Width -= 1;
                }
                if (i == item.Items.Count - 1)
                    r.Width -= 1;
            }
            else {
                r.Inflate(-1, 0);
                if (i == 0) {
                    r.Y += 1;
                    r.Height -= 1;
                }
                if (i == item.Items.Count - 1)
                    r.Height -= 1;
            }

            DebugMenuItem subItem = item.Items[i];

            // Draw highlight.
            if (currentPath[pathIndex] == i) {
                Rectangle2F sr = (Rectangle2I)r;
                sr.Inflate(-2, -2);
                if (controlMode == MenuControlMode.Keyboard || controlMode == MenuControlMode.GamePad || pathIndex < currentPath.Count - 1)
                    g.FillRectangle(sr, colorBackgroundHighlight);
            }
            Point2I ms = (Point2I)Mouse.GetPosition();
            if (r.Contains(ms)) {
                mouseHover = true;
                mouseHoverItem = subItem;
                Rectangle2F sr = (Rectangle2I)r;
                sr.Inflate(-2, -2);
                if (controlMode == MenuControlMode.Mouse)
                    g.FillRectangle(sr, colorBackgroundHighlight);
            }

            // Draw text label.
            string text   = subItem.Text;
            string hotkey = subItem.HotKey.Name;
            g.DrawRealString(debugMenuFont, text, new Point2I(r.Min.X + textOffset, (int)r.Center.Y), Align.Left | Align.Int, colorText);
            g.DrawRealString(debugMenuFont, hotkey, new Point2I(r.Min.X + hotkeyOffset, (int)r.Center.Y), Align.Left | Align.Int, colorHotkey);

            // Draw toggle check.
            if (subItem is ToggleMenuItem) {
                bool enabled = ((ToggleMenuItem)subItem).IsEnabled;
                SpriteEx spr = debugMenuSprites["checkbox_disabled"];
                if (enabled)
                    spr = debugMenuSprites["checkbox_enabled"];
                if (subItem is RadioButtonMenuItem) {
                    spr = debugMenuSprites["radiobutton_disabled"];
                    if (enabled)
                        spr = debugMenuSprites["radiobutton_enabled"];
                }
                g.DrawSpriteEx(spr, new Vector2F(r.Min.X + 6, r.Min.Y + 6), colorText);
            }

            // Draw submenu arrow.
            if (item != menu && subItem.Items.Count > 0) {
                g.DrawSpriteEx(debugMenuSprites["submenu_arrow"], new Vector2F(r.Max.X - 18, r.Min.Y + 6), colorArrow);
            }

            // Draw nested menu.
            if (currentPath[pathIndex] == i) {
                Point2I p = position;
                if (pathIndex == 0)
                    p.Y += itemHeight - 1;
                else
                    p.X += itemWidth - 1;

                DrawMenu(g, subItem, pathIndex + 1, p);
            }

            // Move current position.
            if (pathIndex == 0)
                position.X += itemWidth;
            else
                position.Y += itemHeight;
            }
        }
示例#20
0
        /** <summary> Updates the debug menu with gamepad controls. </summary> */
        private void UpdateGamePadControls()
        {
            /*Keys keyNextItem = Keys.Down;
            *  Keys keyPrevItem = Keys.Up;
            *  Keys keyStepInto = Keys.Right;
            *  Keys keyStepOut  = Keys.Left;*/

            Buttons buttonNextItem  = Buttons.DPadDown;
            Buttons buttonNextItem2 = Buttons.LeftStickDown;
            Buttons buttonPrevItem  = Buttons.DPadUp;
            Buttons buttonPrevItem2 = Buttons.LeftStickUp;
            Buttons buttonStepInto  = Buttons.DPadRight;
            Buttons buttonStepInto2 = Buttons.LeftStickRight;
            Buttons buttonStepOut   = Buttons.DPadLeft;
            Buttons buttonStepOut2  = Buttons.LeftStickLeft;

            if (currentItem.Root.Root == null)
            {
                /*keyNextItem = Keys.Right;
                 * keyPrevItem = Keys.Left;
                 * keyStepInto = Keys.Down;
                 * keyStepOut  = Keys.Up;*/
                buttonNextItem  = Buttons.DPadRight;
                buttonNextItem2 = Buttons.LeftStickRight;
                buttonPrevItem  = Buttons.DPadLeft;
                buttonPrevItem2 = Buttons.LeftStickLeft;
                buttonStepInto  = Buttons.DPadDown;
                buttonStepInto2 = Buttons.LeftStickDown;
                buttonStepOut   = Buttons.DPadUp;
                buttonStepOut2  = Buttons.LeftStickUp;
            }

            // Select next root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadRight) || GamePad.IsButtonPressed(Buttons.LeftStickRight)) && currentItem.Items.Count == 0 && CurrentMenu != menu)
            {
                int index = currentPath[0];
                currentItem = menu.Items[index];
                currentPath.Clear();
                currentPath.Add(index);
                SelectNextItem();
                StepIntoSubMenu();
            }

            // Step into a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepInto) || GamePad.IsButtonPressed(buttonStepInto2))
            {
                StepIntoSubMenu();
            }

            // Select previous root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadLeft) || GamePad.IsButtonPressed(Buttons.LeftStickLeft)) && CurrentMenu.Root == menu)
            {
                currentItem = CurrentMenu;
                currentPath.RemoveAt(currentPath.Count - 1);
                SelectPreviousItem();
                StepIntoSubMenu();
            }
            // Step out of a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepOut) || GamePad.IsButtonPressed(buttonStepOut2))
            {
                StepOutOfSubMenu();
            }

            // Select next item.
            if (GamePad.IsButtonPressed(buttonNextItem) || GamePad.IsButtonPressed(buttonNextItem2))
            {
                SelectNextItem();
            }

            // Select previous item.
            if (GamePad.IsButtonPressed(buttonPrevItem) || GamePad.IsButtonPressed(buttonPrevItem2))
            {
                SelectPreviousItem();
            }

            // Step out of a sub-menu.
            if (GamePad.IsButtonPressed(Buttons.B) || GamePad.IsButtonPressed(Buttons.Back))
            {
                StepOutOfSubMenu();
            }

            // Press item.
            if (GamePad.IsButtonPressed(Buttons.A) || GamePad.IsButtonPressed(Buttons.Start) || GamePad.IsButtonPressed(Buttons.Y))
            {
                if (currentItem.Items.Count == 0)
                {
                    currentItem.Press();
                    if (!GamePad.IsButtonPressed(Buttons.Y))
                    {
                        Close();
                    }
                }
                else
                {
                    StepIntoSubMenu();
                }
            }
        }
示例#21
0
        /** <summary> Updates the debug menu with keyboard controls. </summary> */
        private void UpdateKeyboardControls()
        {
            Keys keyNextItem = Keys.Down;
            Keys keyPrevItem = Keys.Up;
            Keys keyStepInto = Keys.Right;
            Keys keyStepOut  = Keys.Left;

            if (currentItem.Root.Root == null)
            {
                keyNextItem = Keys.Right;
                keyPrevItem = Keys.Left;
                keyStepInto = Keys.Down;
                keyStepOut  = Keys.Up;
            }

            // Select next root menu item.
            if (Keyboard.IsKeyPressed(Keys.Right) && currentItem.Items.Count == 0 && CurrentMenu != menu)
            {
                int index = currentPath[0];
                currentItem = menu.Items[index];
                currentPath.Clear();
                currentPath.Add(index);
                SelectNextItem();
                StepIntoSubMenu();
            }

            // Step into a sub-menu.
            else if (Keyboard.IsKeyPressed(keyStepInto))
            {
                StepIntoSubMenu();
            }

            // Select previous root menu item.
            if (Keyboard.IsKeyPressed(Keys.Left) && CurrentMenu.Root == menu)
            {
                currentItem = CurrentMenu;
                currentPath.RemoveAt(currentPath.Count - 1);
                SelectPreviousItem();
                StepIntoSubMenu();
            }
            // Step out of a sub-menu.
            else if (Keyboard.IsKeyPressed(keyStepOut))
            {
                StepOutOfSubMenu();
            }

            // Select next item.
            if (Keyboard.IsKeyPressed(keyNextItem))
            {
                SelectNextItem();
            }

            // Select previous item.
            if (Keyboard.IsKeyPressed(keyPrevItem))
            {
                SelectPreviousItem();
            }

            // Step out of a sub-menu.
            if (Keyboard.IsKeyPressed(Keys.X) || Keyboard.IsKeyPressed(Keys.Escape))
            {
                StepOutOfSubMenu();
            }

            // Press item.
            if (Keyboard.IsKeyPressed(Keys.Enter) || Keyboard.IsKeyPressed(Keys.Z) || Keyboard.IsKeyPressed(Keys.Space))
            {
                if (currentItem.Items.Count == 0)
                {
                    currentItem.Press();
                    if (!Keyboard.IsKeyPressed(Keys.Space))
                    {
                        Close();
                    }
                }
                else
                {
                    StepIntoSubMenu();
                }
            }
        }
示例#22
0
        /** <summary> Updates the debug menu with mouse controls. </summary> */
        private void UpdateMouseControls()
        {
            // Open submenus when highlighted.
            if (mouseHoverItem != CurrentMenu && mouseHoverItem != null) {
            currentItem = mouseHoverItem;
            if (mouseHoverItem.Items.Count > 0)
                StepIntoSubMenu();

            }

            if (currentItem != null) {
            // Create path from highlighted item.
            currentPath.Clear();
            ReconstructPath(currentItem);

            // [Left] Click on the item and then close the menu.
            if (Mouse.IsButtonPressed(MouseButtons.Left) && mouseHoverItem != null) {
                if (currentItem.Items.Count == 0) {
                    currentItem.Press();
                    Close();
                }
            }

            // [Right] Click on the item without closing the menu.
            else if (Mouse.IsButtonPressed(MouseButtons.Right) && mouseHoverItem != null) {
                if (currentItem.Items.Count == 0)
                    currentItem.Press();
            }
            }
        }
示例#23
0
        /** <summary> Updates the debug menu with gamepad controls. </summary> */
        private void UpdateGamePadControls()
        {
            /*Keys keyNextItem = Keys.Down;
            Keys keyPrevItem = Keys.Up;
            Keys keyStepInto = Keys.Right;
            Keys keyStepOut  = Keys.Left;*/

            Buttons buttonNextItem	= Buttons.DPadDown;
            Buttons buttonNextItem2	= Buttons.LeftStickDown;
            Buttons buttonPrevItem	= Buttons.DPadUp;
            Buttons buttonPrevItem2	= Buttons.LeftStickUp;
            Buttons buttonStepInto	= Buttons.DPadRight;
            Buttons buttonStepInto2	= Buttons.LeftStickRight;
            Buttons buttonStepOut	= Buttons.DPadLeft;
            Buttons buttonStepOut2	= Buttons.LeftStickLeft;

            if (currentItem.Root.Root == null) {
            /*keyNextItem = Keys.Right;
            keyPrevItem = Keys.Left;
            keyStepInto = Keys.Down;
            keyStepOut  = Keys.Up;*/
            buttonNextItem	= Buttons.DPadRight;
            buttonNextItem2	= Buttons.LeftStickRight;
            buttonPrevItem	= Buttons.DPadLeft;
            buttonPrevItem2	= Buttons.LeftStickLeft;
            buttonStepInto	= Buttons.DPadDown;
            buttonStepInto2	= Buttons.LeftStickDown;
            buttonStepOut	= Buttons.DPadUp;
            buttonStepOut2	= Buttons.LeftStickUp;
            }

            // Select next root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadRight) || GamePad.IsButtonPressed(Buttons.LeftStickRight)) && currentItem.Items.Count == 0 && CurrentMenu != menu) {
            int index = currentPath[0];
            currentItem = menu.Items[index];
            currentPath.Clear();
            currentPath.Add(index);
            SelectNextItem();
            StepIntoSubMenu();
            }

            // Step into a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepInto) || GamePad.IsButtonPressed(buttonStepInto2))
            StepIntoSubMenu();

            // Select previous root menu item.
            if ((GamePad.IsButtonPressed(Buttons.DPadLeft) || GamePad.IsButtonPressed(Buttons.LeftStickLeft)) && CurrentMenu.Root == menu) {
            currentItem = CurrentMenu;
            currentPath.RemoveAt(currentPath.Count - 1);
            SelectPreviousItem();
            StepIntoSubMenu();
            }
            // Step out of a sub-menu.
            else if (GamePad.IsButtonPressed(buttonStepOut) || GamePad.IsButtonPressed(buttonStepOut2))
            StepOutOfSubMenu();

            // Select next item.
            if (GamePad.IsButtonPressed(buttonNextItem) || GamePad.IsButtonPressed(buttonNextItem2))
            SelectNextItem();

            // Select previous item.
            if (GamePad.IsButtonPressed(buttonPrevItem) || GamePad.IsButtonPressed(buttonPrevItem2))
            SelectPreviousItem();

            // Step out of a sub-menu.
            if (GamePad.IsButtonPressed(Buttons.B) || GamePad.IsButtonPressed(Buttons.Back))
            StepOutOfSubMenu();

            // Press item.
            if (GamePad.IsButtonPressed(Buttons.A) || GamePad.IsButtonPressed(Buttons.Start) || GamePad.IsButtonPressed(Buttons.Y)) {
            if (currentItem.Items.Count == 0) {
                currentItem.Press();
                if (!GamePad.IsButtonPressed(Buttons.Y))
                    Close();
            }
            else {
                StepIntoSubMenu();
            }
            }
        }
示例#24
0
        /** <summary> Draws the debug menu. </summary> */
        private void DrawMenu(Graphics2D g, DebugMenuItem item, int pathIndex, Point2I position)
        {
            if (pathIndex >= currentPath.Count)
            {
                return;
            }

            int itemWidth         = 32;
            int itemHeight        = 28;
            int offset            = 32;
            int textOffset        = 0;
            int hotkeyOffset      = 0;
            int hotkeyColumnWidth = 0;
            int textColumnWidth   = 0;
            int rightPading       = 24;
            //int padding = 20;
            int hotkeyColumnPadding = 20;

            if (pathIndex == 0)
            {
                offset              = 6;
                rightPading         = 8;
                hotkeyColumnPadding = 0;
            }

            // Measure the width to draw the menu at.
            for (int i = 0; i < item.Items.Count; ++i)
            {
                DebugMenuItem subItem = item.Items[i];

                Rectangle2I r1 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.Text, Align.Left);
                Rectangle2I r2 = (Rectangle2I)debugMenuFont.MeasureStringBounds(subItem.HotKey.Name, Align.Left);
                hotkeyOffset      = GMath.Max(hotkeyOffset, r1.Width + offset + 10);
                itemWidth         = GMath.Max(itemWidth, r1.Width + r2.Width + offset + rightPading);
                textColumnWidth   = GMath.Max(textColumnWidth, r1.Width);
                hotkeyColumnWidth = GMath.Max(hotkeyColumnWidth, r2.Width);
            }
            hotkeyOffset = offset + textColumnWidth + hotkeyColumnPadding;
            textOffset   = offset;
            itemWidth    = offset + textColumnWidth + hotkeyColumnPadding + hotkeyColumnWidth + rightPading;


            // Draw outline.
            Rectangle2I menuRect = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight * item.Items.Count);

            if (pathIndex == 0)
            {
                menuRect.Width  = itemWidth * item.Items.Count;
                menuRect.Height = itemHeight;
            }
            g.DrawRectangle(menuRect, 1.0f, colorOutline);

            // Draw background.
            menuRect.Inflate(-1, -1);
            g.FillRectangle(menuRect, colorBackground);

            // Draw item list.
            for (int i = 0; i < item.Items.Count; ++i)
            {
                Rectangle2I r = new Rectangle2I(position.X, position.Y, itemWidth, itemHeight);

                if (pathIndex == 0)
                {
                    r.Inflate(0, -1);
                    if (i == 0)
                    {
                        r.X     += 1;
                        r.Width -= 1;
                    }
                    if (i == item.Items.Count - 1)
                    {
                        r.Width -= 1;
                    }
                }
                else
                {
                    r.Inflate(-1, 0);
                    if (i == 0)
                    {
                        r.Y      += 1;
                        r.Height -= 1;
                    }
                    if (i == item.Items.Count - 1)
                    {
                        r.Height -= 1;
                    }
                }

                DebugMenuItem subItem = item.Items[i];

                // Draw highlight.
                if (currentPath[pathIndex] == i)
                {
                    Rectangle2F sr = (Rectangle2I)r;
                    sr.Inflate(-2, -2);
                    if (controlMode == MenuControlMode.Keyboard || controlMode == MenuControlMode.GamePad || pathIndex < currentPath.Count - 1)
                    {
                        g.FillRectangle(sr, colorBackgroundHighlight);
                    }
                }
                Point2I ms = (Point2I)Mouse.GetPosition();
                if (r.Contains(ms))
                {
                    mouseHover     = true;
                    mouseHoverItem = subItem;
                    Rectangle2F sr = (Rectangle2I)r;
                    sr.Inflate(-2, -2);
                    if (controlMode == MenuControlMode.Mouse)
                    {
                        g.FillRectangle(sr, colorBackgroundHighlight);
                    }
                }

                // Draw text label.
                string text   = subItem.Text;
                string hotkey = subItem.HotKey.Name;
                g.DrawRealString(debugMenuFont, text, new Point2I(r.Min.X + textOffset, (int)r.Center.Y), Align.Left | Align.Int, colorText);
                g.DrawRealString(debugMenuFont, hotkey, new Point2I(r.Min.X + hotkeyOffset, (int)r.Center.Y), Align.Left | Align.Int, colorHotkey);

                // Draw toggle check.
                if (subItem is ToggleMenuItem)
                {
                    bool     enabled = ((ToggleMenuItem)subItem).IsEnabled;
                    SpriteEx spr     = debugMenuSprites["checkbox_disabled"];
                    if (enabled)
                    {
                        spr = debugMenuSprites["checkbox_enabled"];
                    }
                    if (subItem is RadioButtonMenuItem)
                    {
                        spr = debugMenuSprites["radiobutton_disabled"];
                        if (enabled)
                        {
                            spr = debugMenuSprites["radiobutton_enabled"];
                        }
                    }
                    g.DrawSpriteEx(spr, new Vector2F(r.Min.X + 6, r.Min.Y + 6), colorText);
                }

                // Draw submenu arrow.
                if (item != menu && subItem.Items.Count > 0)
                {
                    g.DrawSpriteEx(debugMenuSprites["submenu_arrow"], new Vector2F(r.Max.X - 18, r.Min.Y + 6), colorArrow);
                }

                // Draw nested menu.
                if (currentPath[pathIndex] == i)
                {
                    Point2I p = position;
                    if (pathIndex == 0)
                    {
                        p.Y += itemHeight - 1;
                    }
                    else
                    {
                        p.X += itemWidth - 1;
                    }

                    DrawMenu(g, subItem, pathIndex + 1, p);
                }

                // Move current position.
                if (pathIndex == 0)
                {
                    position.X += itemWidth;
                }
                else
                {
                    position.Y += itemHeight;
                }
            }
        }
示例#25
0
        /** <summary> Updates the debug menu with keyboard controls. </summary> */
        private void UpdateKeyboardControls()
        {
            Keys keyNextItem = Keys.Down;
            Keys keyPrevItem = Keys.Up;
            Keys keyStepInto = Keys.Right;
            Keys keyStepOut  = Keys.Left;

            if (currentItem.Root.Root == null) {
            keyNextItem = Keys.Right;
            keyPrevItem = Keys.Left;
            keyStepInto = Keys.Down;
            keyStepOut  = Keys.Up;
            }

            // Select next root menu item.
            if (Keyboard.IsKeyPressed(Keys.Right) && currentItem.Items.Count == 0 && CurrentMenu != menu) {
            int index = currentPath[0];
            currentItem = menu.Items[index];
            currentPath.Clear();
            currentPath.Add(index);
            SelectNextItem();
            StepIntoSubMenu();
            }

            // Step into a sub-menu.
            else if (Keyboard.IsKeyPressed(keyStepInto))
            StepIntoSubMenu();

            // Select previous root menu item.
            if (Keyboard.IsKeyPressed(Keys.Left) && CurrentMenu.Root == menu) {
            currentItem = CurrentMenu;
            currentPath.RemoveAt(currentPath.Count - 1);
            SelectPreviousItem();
            StepIntoSubMenu();
            }
            // Step out of a sub-menu.
            else if (Keyboard.IsKeyPressed(keyStepOut))
            StepOutOfSubMenu();

            // Select next item.
            if (Keyboard.IsKeyPressed(keyNextItem))
            SelectNextItem();

            // Select previous item.
            if (Keyboard.IsKeyPressed(keyPrevItem))
            SelectPreviousItem();

            // Step out of a sub-menu.
            if (Keyboard.IsKeyPressed(Keys.X) || Keyboard.IsKeyPressed(Keys.Escape))
            StepOutOfSubMenu();

            // Press item.
            if (Keyboard.IsKeyPressed(Keys.Enter) || Keyboard.IsKeyPressed(Keys.Z) || Keyboard.IsKeyPressed(Keys.Space)) {
            if (currentItem.Items.Count == 0) {
                currentItem.Press();
                if (!Keyboard.IsKeyPressed(Keys.Space))
                    Close();
            }
            else
                StepIntoSubMenu();
            }
        }
示例#26
0
 /** <summary> Checks for pressed hotkeys. </summary> */
 public void CheckHotkeys(DebugMenuItem item)
 {
     for (int i = 0; i < item.Items.Count; ++i) {
     if (item.Items[i].HotKey.Pressed())
         item.Items[i].Press();
     CheckHotkeys(item.Items[i]);
     }
 }
示例#27
0
 /** <summary> Adds the specified menu item to the list of menu items. </summary> */
 public DebugMenuItem AddItem(DebugMenuItem item)
 {
     item.Root  = this;
     item.Index = items.Count;
     items.Add(item);
     return item;
 }
示例#28
0
        /** <summary> Draws the debug menus. </summary> */
        public void Draw(Graphics2D g)
        {
            mouseHover = false;

            DrawMenu(g, menu, 0, Point2I.Zero);

            if (!mouseHover) {
            mouseHoverItem = null;
            }
        }
示例#29
0
        /** <summary> Constructs the main debug menu. </summary> */
        public DebugMenu()
        {
            this.menu				= new DebugMenuItem("root");

            this.currentPath		= new List<int>();
            this.currentItem		= null;
            this.mouseHoverItem		= null;
            this.mouseHover			= false;
            this.controlMode		= MenuControlMode.Keyboard;

            this.open				= false;

            this.debugMenuFont		= null;
            this.debugMenuFontBold	= null;
            this.debugMenuSprites	= null;
        }
示例#30
0
 public void Open()
 {
     currentPath.Clear();
     currentPath.Add(0);
     currentItem = menu.Items[0];
     mouseHoverItem = null;
     open = true;
 }