Exemplo n.º 1
0
        public ResolutionMenu(WarGame game)
            : base(game)
        {
            backgroundImage = game.menuBackgroundTexture;

            int x_position;
            string label;
            int y_position = 0;
            MenuItem item;
            MenuItem.ItemActions action;

            foreach (DisplayMode d in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
                availableResoultions.Add(new Vector2(d.Width, d.Height));

            List<Vector2> highestResolutions = new List<Vector2>();

            do
            {
                Vector2 maxValue = new Vector2(float.MinValue, float.MinValue);

                foreach (Vector2 v in availableResoultions)
                {
                    if (v.X + v.Y > maxValue.X + maxValue.Y)
                        maxValue = v;
                }

                availableResoultions.Remove(maxValue);

                if (!highestResolutions.Contains(maxValue))
                    highestResolutions.Add(maxValue);

            } while (highestResolutions.Count < numberOfResolutions);

            availableResoultions = highestResolutions;

            foreach (Vector2 v in availableResoultions)
            {
                label = v.X.ToString() + " X " + v.Y.ToString();
                x_position = x_position = game.Window.ClientBounds.Width / 2 - (int)game.menuFont.MeasureString(label).X / 2;
                y_position += 50;
                action = MenuItem.ItemActions.SetResolution;
                item = new MenuItem(game, this, new Vector2(x_position, y_position), label, action);
                SceneComponents.Add(item);
            }

            activeItemNumber = 0;
            (SceneComponents[activeItemNumber] as MenuItem).Activate();
            game.Components.Add(this);
            game.SetResolution((int)availableResoultions[activeItemNumber].X, (int)availableResoultions[activeItemNumber].Y);

            Hide();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor of the main Menu.
        /// </summary>
        /// <param name="game">Game where the main Menu is used</param>
        public MainMenu(WarGame game)
            : base(game)
        {
            backgroundImage = game.menuBackgroundTexture;

            int x_position;
            string label;
            int y_position;
            MenuItem item;
            MenuItem.ItemActions action;

            label = "New Game";
            x_position = game.Window.ClientBounds.Width / 2 - (int)game.menuFont.MeasureString(label).X / 2;
            y_position = 50;
            action = MenuItem.ItemActions.NewGame;
            item = new MenuItem(game, this, new Vector2(x_position, y_position), label, action);
            item.Activate();
            activeItemNumber = 0;
            SceneComponents.Add(item);

            label = "Settings";
            x_position = game.Window.ClientBounds.Width / 2 - (int)game.menuFont.MeasureString(label).X / 2;
            y_position = 100;
            action = MenuItem.ItemActions.GoToResolutionMenu;
            item = new MenuItem(game, this, new Vector2(x_position, y_position), label, action);
            SceneComponents.Add(item);

            label = "Exit";
            x_position = game.Window.ClientBounds.Width / 2 - (int)game.menuFont.MeasureString(label).X / 2;
            y_position = 150;
            action = MenuItem.ItemActions.Exit;
            item = new MenuItem(game, this, new Vector2(x_position, y_position), label, action);
            SceneComponents.Add(item);

            game.Components.Add(this);
            resMenu = new ResolutionMenu(game);
            resMenu.baseScene = this;
        }