Example #1
0
        // Allows the game to perform any initialization it needs to before starting to run.
        // This is where it can query for any required services and load any non-graphic
        // related content.  Calling base.Initialize will enumerate through any components
        // and initialize them as well.
        protected override void Initialize()
        {
            Console.WriteLine("Begin Initialize");

            Console.WriteLine("Initializing Input");
            Keyboard.Initialize();
            Mouse.Initialize();
            GamePad.Initialize();

            game = new GameManager(launchParameters);

            base.Initialize();

            if (!isContentLoaded)
            {
                // BAD STUFF.
                Exit();
                return;
            }

            // Create and initialize the game.
            game.Initialize(this);

            Window.ClientSizeChanged += OnClientSizeChanged;

            Console.WriteLine("End Initialize");
        }
Example #2
0
        //=========== UPDATING ===========
        #region Updating

        /** <summary> Updates the debug menu while it's open. </summary> */
        public void Update()
        {
            if (Mouse.IsMouseMoved())
            {
                if (Mouse.GetDistance().Length > 2.0 && mouseHoverItem != null)
                {
                    controlMode = MenuControlMode.Mouse;
                }
            }

            if (Keyboard.IsKeyPressed(Keys.Left) ||
                Keyboard.IsKeyPressed(Keys.Right) ||
                Keyboard.IsKeyPressed(Keys.Up) ||
                Keyboard.IsKeyPressed(Keys.Down) ||
                Keyboard.IsKeyPressed(Keys.X) ||
                Keyboard.IsKeyPressed(Keys.Z) ||
                Keyboard.IsKeyPressed(Keys.Space) ||
                Keyboard.IsKeyPressed(Keys.Enter) ||
                Keyboard.IsKeyPressed(Keys.Escape))
            {
                controlMode = MenuControlMode.Keyboard;
            }
            else if (GamePad.IsButtonPressed(Buttons.DPadLeft) ||
                     GamePad.IsButtonPressed(Buttons.DPadRight) ||
                     GamePad.IsButtonPressed(Buttons.DPadUp) ||
                     GamePad.IsButtonPressed(Buttons.DPadDown) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickLeft) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickRight) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickUp) ||
                     GamePad.IsButtonPressed(Buttons.LeftStickDown) ||
                     GamePad.IsButtonPressed(Buttons.A) ||
                     GamePad.IsButtonPressed(Buttons.B) ||
                     GamePad.IsButtonPressed(Buttons.Start) ||
                     GamePad.IsButtonPressed(Buttons.Back) ||
                     GamePad.IsButtonPressed(Buttons.Y))
            {
                controlMode = MenuControlMode.GamePad;
            }

            if (controlMode == MenuControlMode.Mouse)
            {
                UpdateMouseControls();
            }
            else if (controlMode == MenuControlMode.Keyboard)
            {
                UpdateKeyboardControls();
            }
            else
            {
                UpdateGamePadControls();
            }
        }
Example #3
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();
                    }
                }
            }
        }
Example #4
0
        //-----------------------------------------------------------------------------
        // Updating
        //-----------------------------------------------------------------------------

        // Allows the game to run logic such as updating the world,
        // checking for collisions, gathering input, and playing audio.
        protected override void Update(GameTime gameTime)
        {
            if (!isContentLoaded)
            {
                Exit();
                return;
            }

            // Update the fullscreen mode.
            UpdateFullScreen();

            if (windowSizeChanged)
            {
                game.ScreenResized();
                windowSizeChanged = false;
            }

            // Update the frame rate.
            UpdateFrameRate(gameTime);

            // Update the listeners.
            if (Form.Focused)
            {
                Keyboard.Enable();
                GamePad.Enable();
                Mouse.Enable();
                Keyboard.Update(gameTime);
                GamePad.Update(gameTime);
                Mouse.Update(gameTime, (IsFullScreen ? -new Vector2F(Window.ClientBounds.Location) : Vector2F.Zero));
            }
            else
            {
                Keyboard.Disable(false);
                GamePad.Disable(false);
                Mouse.Disable(false);
            }
            AudioSystem.Update(gameTime);

            // Update the game logic.
            //game.Update((float) gameTime.ElapsedGameTime.TotalSeconds);

            // DEBUG: Hold 1 to speed up the game.
            if (Keyboard.IsKeyDown(Keys.D1))
            {
                for (int i = 0; i < 16; i++)
                {
                    game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }
            // DEBUG: Hold 2 to slow down the game.
            else if (Keyboard.IsKeyDown(Keys.D2))
            {
                slowTimer++;
                if (slowTimer >= 10)
                {
                    slowTimer = 0;
                    game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
                }
            }
            else
            {
                // Update the game logic.
                game.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            base.Update(gameTime);

            // Update screenshot requests.
            UpdateScreenShot();

            //windowSizeChanged = false;
        }
Example #5
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;
                }
            }
        }
Example #6
0
 public override bool Up()
 {
     return(Mouse.IsButtonUp(ButtonCode));
 }
Example #7
0
 public override bool Down()
 {
     return(Mouse.IsButtonDown(ButtonCode));
 }
Example #8
0
 public override bool Released()
 {
     return(Mouse.IsButtonReleased(ButtonCode));
 }
Example #9
0
 public override bool Pressed()
 {
     return(Mouse.IsButtonPressed(ButtonCode));
 }