Esempio n. 1
0
 private void Apply()
 {
     _place.MetersRadious = int.Parse(tbRadious.Text);
     _place.Name          = tbPlaceName.Text;
     PlacesManager.Save();
     SettingsApplied?.Invoke(this, new EventsArgs <GeolocationPlace>(_place));
 }
Esempio n. 2
0
        public void UpdateSettings(SettingsModel settingsModel)
        {
            SettingsModel = settingsModel;
            SettingsApplied?.Invoke(SettingsModel);

            var serializeObject = JsonConvert.SerializeObject(settingsModel, Formatting.None);

            PlayerPrefs.SetString(SettingsModel.PlayerPrefsKey, serializeObject);
            PlayerPrefs.Save();
        }
Esempio n. 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);
            }
        }