Пример #1
0
        public NewGameViewModel(GameSettings settings, bool isNewGame, Action <GameSettings> callback)
        {
            Settings = settings?.Clone() ?? new GameSettings();

            IsNewGame = isNewGame;

            Accepted = false;
            Callback = callback;
        }
Пример #2
0
        // Applies the video settings
        private void Apply()
        {
            GameSettings originalSettings = _settingsManager.GetSettingsCopy();
            GameSettings newSettings      = originalSettings.Clone();

            newSettings.Video.Resolution = (Vector2)_resolutionsItem.SelectedValue;
            newSettings.Video.VSync      = (bool)_vSyncItem.SelectedValue;
            newSettings.Video.FullScreen = (bool)_fullScreenItem.SelectedValue;

            // Simply close the page when nothing has changed
            if (originalSettings.Video.Equals(newSettings.Video))
            {
                Close();
                return;
            }

            _settingsManager.ApplySettings(newSettings);

            // Setup and open the confirmation page and revert the changes when no confirmation has been given

            ConfirmationMenuPage confirmationPage = new ConfirmationMenuPage();

            confirmationPage.Confirm += (sender, args) =>
            {
                _settingsManager.SaveSettings();
                Close();
            };

            confirmationPage.Cancel += (sender, args) =>
            {
                _settingsManager.ApplySettings(originalSettings);
                _settingsManager.SaveSettings();
                Close();
            };

            OpenSubPage(confirmationPage);
        }
Пример #3
0
        /// <summary>
        /// Sanitizes and applies a <see cref="GameSettings"/> object so that the settings will be available throughout the game.
        /// </summary>
        /// <param name="newSettings">The settings to apply.</param>
        /// <exception cref="ArgumentNullException"><paramref name="newSettings"/> is null.</exception>
        public void ApplySettings(GameSettings newSettings)
        {
            if (newSettings == null)
            {
                throw new ArgumentNullException("newSettings");
            }

            GameSettings oldSettings = _settings;

            SanitizeSettings(newSettings);
            _settings = newSettings.Clone();

            // Check which types of settings have been changed
            bool audioSettingsChanged    = oldSettings == null || !_settings.Audio.Equals(oldSettings.Audio);
            bool videoSettingsChanged    = oldSettings == null || !_settings.Video.Equals(oldSettings.Video);
            bool gamePlaySettingsChanged = oldSettings == null || !_settings.Gameplay.Equals(oldSettings.Gameplay);
            bool controlSettingsChanged  = oldSettings == null || !_settings.Controls.Equals(oldSettings.Controls);

            if (videoSettingsChanged)
            {
                // Apply graphics changes
                GraphicsDeviceManager graphics = _graphics.Value;
                graphics.SynchronizeWithVerticalRetrace = _settings.Video.VSync;
                graphics.PreferredBackBufferWidth       = (int)_settings.Video.Resolution.X;
                graphics.PreferredBackBufferHeight      = (int)_settings.Video.Resolution.Y;
                graphics.IsFullScreen = _settings.Video.FullScreen;
                graphics.ApplyChanges();

                // If windowed and the resolution changed, reposition the window on the screen
                if (!_settings.Video.FullScreen && (oldSettings == null || oldSettings.Video.FullScreen || oldSettings.Video.Resolution != _settings.Video.Resolution))
                {
                    Rectangle   windowBounds       = _game.Window.ClientBounds;
                    DisplayMode currentDisplayMode = graphics.GraphicsDevice.Adapter.CurrentDisplayMode;

                    // Window is larger than the screen, position it top-left
                    if (windowBounds.Width >= currentDisplayMode.Width || windowBounds.Height >= currentDisplayMode.Height)
                    {
                        _game.Window.Position = new Point(0, 0);
                    }
                    // Window is smaller than the screen, center it
                    else
                    {
                        _game.Window.Position = new Point(
                            currentDisplayMode.Width / 2 - windowBounds.Width / 2,
                            currentDisplayMode.Height / 2 - windowBounds.Height / 2);
                    }
                }
            }

            // Inform event handlers that the settings have been applied
            if (SettingsApplied != null)
            {
                SettingsAppliedEventArgs eventArgs = new SettingsAppliedEventArgs(
                    audioSettingsChanged,
                    videoSettingsChanged,
                    gamePlaySettingsChanged,
                    controlSettingsChanged);

                SettingsApplied.Invoke(this, eventArgs);
            }
        }