public void SetBot(BotWindowData bot) { LoadingUi = true; Bot = bot; authBox.SelectedItem = Bot.GlobalSettings.Auth.AuthType; if (Bot.GlobalSettings.Auth.AuthType == AuthType.Google) { loginBox.Text = Bot.GlobalSettings.Auth.GoogleUsername; passwordBox.Password = Bot.GlobalSettings.Auth.GooglePassword; } else { loginBox.Text = Bot.GlobalSettings.Auth.PtcUsername; passwordBox.Password = Bot.GlobalSettings.Auth.PtcPassword; } foreach (var uiElem in settings_grid.GetLogicalChildCollection <TextBox>()) { string val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), Bot.GlobalSettings, out val)) { uiElem.Text = val; } } foreach (var uiElem in settings_grid.GetLogicalChildCollection <PasswordBox>()) { string val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), Bot.GlobalSettings, out val)) { uiElem.Password = val; } } foreach (var uiElem in settings_grid.GetLogicalChildCollection <CheckBox>()) { bool val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), Bot.GlobalSettings, out val)) { uiElem.IsChecked = val; } } foreach (var uiElem in settings_grid.GetLogicalChildCollection <ComboBox>()) { Enum val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), Bot.GlobalSettings, out val)) { var valType = val.GetType(); uiElem.ItemsSource = Enum.GetValues(valType); uiElem.SelectedItem = val; } } CustomRouteComboBox.SelectedItem = _globalSettings.Routes.FirstOrDefault(x => x.Name == Bot.GlobalSettings.LocationSettings.CustomRouteName); LoadingUi = false; }
private void ElementPropertyChanged(object sender, EventArgs e) { if (_loadingUi) { return; } UiHandlers.HandleUiElementChangedEvent(sender, _tlgrmSettings); }
private void BotPropertyChanged(object sender, EventArgs e) { if (Bot == null || LoadingUi) { return; } UiHandlers.HandleUiElementChangedEvent(sender, Bot.GlobalSettings); }
private void LoadSettings() { _loadingUi = true; PokemonList.ItemsSource = _tlgrmSettings.AutoReportPokemon; OwnerBox.ItemsSource = _tlgrmSettings.Owners; foreach (var uiElem in TlgrmGrid.GetLogicalChildCollection <TextBox>()) { string val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), _tlgrmSettings, out val)) { uiElem.Text = val; } } foreach (var uiElem in TlgrmGrid.GetLogicalChildCollection <PasswordBox>()) { string val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), _tlgrmSettings, out val)) { uiElem.Password = val; } } foreach (var uiElem in TlgrmGrid.GetLogicalChildCollection <CheckBox>()) { bool val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), _tlgrmSettings, out val)) { uiElem.IsChecked = val; } } foreach (var uiElem in TlgrmGrid.GetLogicalChildCollection <ComboBox>()) { Enum val; if (UiHandlers.GetValueByName(uiElem.Name.Substring(2), _tlgrmSettings, out val)) { var valType = val.GetType(); uiElem.ItemsSource = Enum.GetValues(valType); uiElem.SelectedItem = val; } } _loadingUi = false; }
public void CheckForAction() { if (GlobalSettings.Schedule == null || !GlobalSettings.Schedule.UseSchedule || GlobalSettings.Schedule.ActionList == null) { return; } var currentH = DateTime.Now.Hour; if (_lastH == currentH) { return; } var currentDay = DateTime.Now.DayOfWeekToInt(); _lastH = currentH; var currentAction = GlobalSettings.Schedule.ActionList.Where(x => x.Day == currentDay && x.Hour == currentH).ToList(); foreach (var action in currentAction) { try { if (action.ActionArgs == null || action.ActionArgs.Length == 0) { continue; } switch (action.ActionType) { case ScheduleActionType.ChangeRoute: var newRoute = MainWindow.BotWindow.GlobalCatchemSettings.Routes.FirstOrDefault( x => string.Equals(x.Name, action.ActionArgs[0], StringComparison.CurrentCultureIgnoreCase)); if (newRoute != null) { GlobalSettings.LocationSettings.CustomRoute = newRoute.Route; GlobalSettings.LocationSettings.CustomRouteName = newRoute.Name; } break; case ScheduleActionType.ChangeLocation: if (!Started) { UiHandlers.SetValueByName("DefaultLatitude", action.ActionArgs[0], GlobalSettings.LocationSettings); UiHandlers.SetValueByName("DefaultLongitude", action.ActionArgs[1], GlobalSettings.LocationSettings); } else { double lat, lng; if (action.ActionArgs[0].GetVal(out lat) && action.ActionArgs[1].GetVal(out lng)) { if (ForceMoveMarker == null) { Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { ForceMoveMarker = new GMapMarker(new PointLatLng(lat, lng)) { Shape = Properties.Resources.force_move.ToImage("Force Move To"), Offset = new Point(-24, -48), ZIndex = int.MaxValue }; })); } else { ForceMoveMarker.Position = new PointLatLng(lat, lng); } Session.StartForceMove(lat, lng); } } break; case ScheduleActionType.ChangeSettings: UiHandlers.SetValueByName(action.ActionArgs[0], action.ActionArgs[1], GlobalSettings); break; } Session.EventDispatcher.Send(new NoticeEvent { Message = Session.Translation.GetTranslation(TranslationString.ScheduleAction, action.ActionType, action.Args) }); } catch (Exception ex) { Session.EventDispatcher.Send(new WarnEvent { Message = Session.Translation.GetTranslation(TranslationString.ScheduleActionFailed, action.ActionType, action.Args) }); Logger.Write($"[ScheduleActionFAILED] Error: {ex.Message}"); } } }