private void Load(DewritoSettings settings)
 {
     _player = new PlayerSettingsViewModel(settings.Player ?? new DewritoPlayerSettings());
     _video  = new VideoSettingsViewModel(settings.Video ?? new DewritoVideoSettings());
     _host   = new HostSettingsViewModel(settings.Host ?? new DewritoHostSettings());
     _input  = new InputSettingsViewModel(settings.Input ?? new DewritoInputSettings());
 }
 public void Save(DewritoSettings settings)
 {
     if (settings.Player == null)
     {
         settings.Player = new DewritoPlayerSettings();
     }
     if (settings.Video == null)
     {
         settings.Video = new DewritoVideoSettings();
     }
     if (settings.Host == null)
     {
         settings.Host = new DewritoHostSettings();
     }
     if (settings.Input == null)
     {
         settings.Input = new DewritoInputSettings();
     }
     _player.Save(settings.Player);
     _video.Save(settings.Video);
     _host.Save(settings.Host);
     _input.Save(settings.Input);
 }
예제 #3
0
        private void LoadSettings()
        {
            // Load settings from the YAML file
            settings = null;
            try
            {
                using (var stream = File.OpenText(SettingsFileName))
                {
                    var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
                    settings = deserializer.Deserialize <DewritoSettings>(stream);
                }
            }
            catch (IOException)
            {
            }
            catch (YamlException)
            {
            }
            if (settings == null)
            {
                settings = new DewritoSettings(); // Use defaults if an error occurred
            }
            // Create the view model and listen for changes
            settingsViewModel = new SettingsViewModel(settings);
            settingsViewModel.PropertyChanged               += SettingsChanged;
            settingsViewModel.Player.PropertyChanged        += SettingsChanged;
            settingsViewModel.Player.Armor.PropertyChanged  += SettingsChanged;
            settingsViewModel.Player.Colors.PropertyChanged += SettingsChanged;
            settingsViewModel.Video.PropertyChanged         += SettingsChanged;
            settingsViewModel.Host.PropertyChanged          += SettingsChanged;
            settingsViewModel.Input.PropertyChanged         += SettingsChanged;

            // Set the data context for the settings tabs
            Customization.DataContext = settingsViewModel;
            Settings.DataContext      = settingsViewModel;
        }
 public SettingsViewModel(DewritoSettings settings)
 {
     Load(settings);
 }