public SettingsViewModel(IUILanguageProvider uiLanguageProvider, SidekickSettings sidekickSettings, INativeKeyboard nativeKeyboard, ILeagueDataService leagueDataService, IKeybindEvents keybindEvents) { this.uiLanguageProvider = uiLanguageProvider; this.sidekickSettings = sidekickSettings; this.nativeKeyboard = nativeKeyboard; this.keybindEvents = keybindEvents; this.leagueDataService = leagueDataService; Settings = new SidekickSettings(); AssignValues(sidekickSettings, Settings); Keybinds.Clear(); Settings.GetType() .GetProperties() .Where(x => x.Name.StartsWith("Key")) .ToList() .ForEach(x => Keybinds.Add(x.Name, x.GetValue(Settings).ToString())); WikiOptions.Add("POE Wiki", WikiSetting.PoeWiki.ToString()); WikiOptions.Add("POE Db", WikiSetting.PoeDb.ToString()); this.leagueDataService.Leagues.ForEach(x => LeagueOptions.Add(x.Id, x.Text)); uiLanguageProvider.AvailableLanguages.ForEach(x => UILanguageOptions.Add(x.NativeName.First().ToString().ToUpper() + x.NativeName.Substring(1), x.Name)); nativeKeyboard.OnKeyDown += NativeKeyboard_OnKeyDown; }
private void AssignValues(SidekickSettings src, SidekickSettings dest) { // iterates through src Settings (properties) and copies them to dest settings (properties) // If there ever comes a time, where some properties do not have to be copied, we can add attributes to exclude them src.GetType().GetProperties().ToList().ForEach(x => x.SetValue(dest, x.GetValue(src))); }