private void AddColor_Click(object sender, RoutedEventArgs e) { var color = ColorPicker.SelectedColor; var name = EffectTextBox.Text; if (UserSettings.Settings.CustomEffects != null && UserSettings.Settings.CustomEffects.Any(effect => effect.EffectName == name)) { PopupCreator.Error(Options.Resources.NameTaken); return; } if (string.IsNullOrWhiteSpace(name)) { PopupCreator.Error(Options.Resources.NoNameProvided); return; } if (color == null) { PopupCreator.Error(Options.Resources.NoColorSelected); return; } var customEffect = new UserCustomColorEffect() { Color = Color.FromArgb(color.Value.A, color.Value.R, color.Value.G, color.Value.B), EffectName = name }; if (OptionsViewModel.CustomColorEffects == null) { OptionsViewModel.CustomColorEffects = new List <UserCustomColorEffect>(); } // Add color in settings. OptionsViewModel.CustomColorEffects.Add(customEffect); // Add color to UI. ColorList.Children.Add(new ColorUserControl(this, customEffect.EffectName, customEffect.Color)); }
public string GetName() { return(UserCustomColorEffect.DisplayName(_effectName)); }
private void Save_Click(object sender, RoutedEventArgs e) { #region LatLong double latitude = 0; double longitude = 0; try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude)) { latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLatitude); return; } try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude)) { longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLongitude); return; } if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0)) { var client = new SunsetSunriseClient(); try { var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult(); UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute); } catch { PopupCreator.Error(Options.Resources.SunsetSunriseError); return; } UserSettings.Settings.Latitude = latitude; UserSettings.Settings.Longitude = longitude; } #endregion #region StartAtWindowsStartup if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp) { if (OptionsViewModel.StartAtWindowsStartUp) { //Replace .dll with .exe since in .net core 3 the current executing assembly is the dll _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe")} -s"); } else { _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false); } _startupKey.Close(); UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp; } #endregion #region ScreenMirror foreach (var device in UserSettings.Settings.Devices) { device.ScreenMirrorAlgorithm = OptionsViewModel.AlgorithmPerDevice[device.Name]; } UserSettings.Settings.ScreenMirrorMonitorIndex = Array.IndexOf(_monitorNames.ToArray(), OptionsViewModel.SelectedMonitor); UserSettings.Settings.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerSecond; #endregion #region Language if (OptionsViewModel.SelectedLanguage != null) { UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage]; } #endregion #region MinimizeToSystemTray UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray; #endregion #region Colors var deletedColors = UserSettings.Settings.CustomEffects?.Except(OptionsViewModel.CustomColorEffects).ToList(); UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects; //Remove invalid triggers from the schedules if (deletedColors?.Any() == true) { UserSettings.Settings.DeleteTriggers(deletedColors.Select(color => UserCustomColorEffect.DisplayName(color.EffectName))); } #endregion Colors UserSettings.Settings.SaveSettings(); //Reload the orchestrator so custom effects are reloaded. OrchestratorCollection.ResetOrchestrators(); //Reload effects such that custom effects are updated in the view _mainWindow.ReloadEffectsInView(); Close(); }