/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { this._gameSettings = SettingsIO.LoadGameSettings(); this._spriteBatch = new SpriteBatch(GraphicsDevice); this._debugText = Content.Load <SpriteFont>(Constants.Fonts.TelegramaSmall); this.IsMouseVisible = false; this.Window.IsBorderless = _gameSettings.Borderless; this.Window.AllowUserResizing = false; this._currentState = new TitleState(Content); this._graphics.PreferredBackBufferWidth = (int)_gameSettings.Resolution.X; this._graphics.PreferredBackBufferHeight = (int)_gameSettings.Resolution.Y; this.IsFixedTimeStep = this._gameSettings.Vsync; this._graphics.SynchronizeWithVerticalRetrace = this._gameSettings.Vsync; this._graphics.ApplyChanges(); this._camera = new Camera(GraphicsDevice.Viewport, GraphicsDevice.Viewport.Bounds.Center.ToVector2(), 0f, 1f); }
public IState UpdateState(ref GameSettings gameSettings, GameTime gameTime, Camera camera, KeyboardState currentKey, KeyboardState prevKey, MouseState currentMouse, MouseState prevMouse) { if (currentKey.IsKeyDown(Keys.Escape) && prevKey.IsKeyUp(Keys.Escape)) { return(this._prevState); } if (currentKey.IsKeyDown(Keys.Up) && prevKey.IsKeyUp(Keys.Up)) { _selectedOption -= 1; if (_selectedOption < 0) { _selectedOption = Enum.GetNames(typeof(Options)).Length - 1; } if (_selectedOption > Enum.GetNames(typeof(Options)).Length - 1) { _selectedOption = 0; } } if (currentKey.IsKeyDown(Keys.Down) && prevKey.IsKeyUp(Keys.Down)) { _selectedOption += 1; if (_selectedOption < 0) { _selectedOption = Enum.GetNames(typeof(Options)).Length - 1; } if (_selectedOption > Enum.GetNames(typeof(Options)).Length - 1) { _selectedOption = 0; } } if (currentKey.IsKeyDown(Keys.Left) && prevKey.IsKeyUp(Keys.Left) && _optionItems[_selectedOption].OptionsCollection != null) { _optionItems[_selectedOption].Selection -= 1; if (_optionItems[_selectedOption].Selection < 0) { _optionItems[_selectedOption].Selection = _optionItems[_selectedOption].OptionsCollection.Count - 1; } if (_optionItems[_selectedOption].Selection >= _optionItems[_selectedOption].OptionsCollection.Count) { _optionItems[_selectedOption].Selection = 0; } } if (currentKey.IsKeyDown(Keys.Right) && prevKey.IsKeyUp(Keys.Right) && _optionItems[_selectedOption].OptionsCollection != null) { _optionItems[_selectedOption].Selection += 1; if (_optionItems[_selectedOption].Selection < 0) { _optionItems[_selectedOption].Selection = _optionItems[_selectedOption].OptionsCollection.Count - 1; } if (_optionItems[_selectedOption].Selection >= _optionItems[_selectedOption].OptionsCollection.Count) { _optionItems[_selectedOption].Selection = 0; } } if (currentKey.IsKeyDown(Keys.Enter) && prevKey.IsKeyUp(Keys.Enter)) { switch (_selectedOption) { case (int)Options.ACCEPT_CHANGES: this._gameSettings.Resolution = (Vector2)_optionItems[(int)Options.RESOLUTION].OptionsCollection[_optionItems[(int)Options.RESOLUTION].Selection]; this._gameSettings.Borderless = (bool)_optionItems[(int)Options.BORDERLESS_WINDOW].OptionsCollection[_optionItems[(int)Options.BORDERLESS_WINDOW].Selection]; this._gameSettings.Vsync = (bool)_optionItems[(int)Options.VSYNC].OptionsCollection[_optionItems[(int)Options.VSYNC].Selection]; SettingsIO.SaveGameSettings(ref this._gameSettings); return(this._prevState); case (int)Options.DEFAULT_SETTINGS: SettingsIO.ResetGameSettings(); gameSettings = SettingsIO.LoadGameSettings(); return(new SettingsState(ref gameSettings, this._content, this._prevState)); case (int)Options.CANCEL: return(this._prevState); } } return(this); }