/// <summary>
        /// Title screen constructor.
        /// </summary>
        public OptionsScreen(GameMain parent)
        {
            _list = new ComponentList();

            SelectionBox resolution = new SelectionBox("Resolution");

            resolution.AddOption("800x600");
            resolution.AddOption("1280x720");
            resolution.AddOption("1920x1080");
            resolution.SelectOption(OptionsManager.CurrentOptions.ResolutionWidth + "x" + OptionsManager.CurrentOptions.ResolutionHeight);
            _list.AddComponent(resolution);

            SelectionBox fullscreen = new SelectionBox("Fullscreen");

            fullscreen.AddOption("On");
            fullscreen.AddOption("Off");
            fullscreen.SelectOption(OptionsManager.CurrentOptions.Fullscreen ? "On" : "Off");
            _list.AddComponent(fullscreen);

            SelectionBox inverted = new SelectionBox("Inverted Aim");

            inverted.AddOption("On");
            inverted.AddOption("Off");
            inverted.SelectOption(OptionsManager.CurrentOptions.InvertAim ? "On" : "Off");
            _list.AddComponent(inverted);

            _list.ValueChanged += new ValueChangeDelegate(() =>
            {
                string res = _list.GetValue("Resolution");
                string ful = _list.GetValue("Fullscreen");
                string aim = _list.GetValue("Inverted Aim");

                OptionsManager.CurrentOptions.ResolutionWidth  = Convert.ToInt32(res.Split('x')[0]);
                OptionsManager.CurrentOptions.ResolutionHeight = Convert.ToInt32(res.Split('x')[1]);
                OptionsManager.CurrentOptions.Fullscreen       = (ful == "On");
                OptionsManager.CurrentOptions.InvertAim        = (aim == "On");
            });

            _list.AddComponent(new Button("Delete All Save Data", new SelectDelegate(() =>
            {
                GameStateManager.DeleteAllSaves();
            })));

            _list.AddComponent(new Button("Save", new SelectDelegate(() =>
            {
                OptionsManager.SaveOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _window = Rectangle.Empty;

            _parent = parent;
        }
Esempio n. 2
0
        public TitleScreen(string background, int width, int height)
        {
            #region Title Screen Assets initialization

            _bounds     = new Rectangle(0, 0, width, height);
            _background = GameContent.LoadContent <Texture2D>(background);
            _logo       = GameContent.LoadContent <Texture2D>("Images/Logo");
            _font       = GameContent.LoadContent <SpriteFont>("Fonts/SmallFont");

            Vector2 bg_center     = new Vector2(_logo.Width / 2.0f, _logo.Height / 2.0f);
            Vector2 screen_center = new Vector2(width / 2.0f, height / 2.0f);
            _titlePosition = new Rectangle((int)(screen_center.X - bg_center.X),
                                           (int)(screen_center.Y * 0.5 - bg_center.Y),
                                           (int)(_logo.Width),
                                           (int)(_logo.Height));

            _startMessage = "Press START or ENTER to start the game";
            Vector2 startSize = _font.MeasureString(_startMessage);
            _startOrigin   = new Vector2(startSize.X / 2, startSize.Y / 2);
            _startPosition = new Vector2(screen_center.X, screen_center.Y * 1.7f);

            _transparency     = 0.9f;
            _transparencyDiff = 0.001f;

            #endregion Title Screen Assets initialization

            #region Options Initialization

            _options = new ComponentList();

            SelectionBox controller = new SelectionBox("Use Keyboard?");
            controller.AddOption("Yes");
            controller.AddOption("No");
            controller.SelectOption(GameMain.UseKeyboard ? "Yes" : "No");
            _options.AddComponent(controller);

            SelectionBox players = new SelectionBox("Players");
            players.AddOption("2");
            players.AddOption("3");
            players.AddOption("4");

            /*players.AddOption("5");
            *  players.AddOption("6");
            *  players.AddOption("7");
            *  players.AddOption("8");*/
            players.SelectOption(GameMain.PlayerCount.ToString());
            _options.AddComponent(players);

            _options.ValueChanged += () =>
            {
                string useKeyboard  = _options.GetValue("Use Keyboard?");
                string playersCount = _options.GetValue("Players");

                GameMain.UseKeyboard = (useKeyboard == "Yes");
                GameMain.PlayerCount = int.Parse(playersCount.Replace('*', '\0'));

                if (GameMain.PlayerCount > 2)
                {
                    _options.GetComponent <Button>("Search For Game").Visible = false;
                    _options.GetComponent <Button>("Host Game").Visible       = false;
                }
                else
                {
                    _options.GetComponent <Button>("Search For Game").Visible = true;
                    _options.GetComponent <Button>("Host Game").Visible       = true;
                }
            };

            _options.AddComponent(new Button("Play Local", () =>
            {
                _showOptions = false;
                GameMain.ChangeState(GameState.PlayingLocal);
            }));

            _options.AddComponent(new Button("Search For Game", () =>
            {
                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.SearchingGame);
            }));

            _options.AddComponent(new Button("Host Game", () =>
            {
                if (GameMain.CurrentState != GameState.TitleScreen)
                {
                    return;
                }

                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.CreatingHost);
            }));

            _options.Position = new Rectangle(30, 200, width - 60, height - 220);
            _showOptions      = false;
            #endregion Options Initialization

            _firstKeyUp = false;
        }