private void PulseTasks() { if (!Tasks.Any()) { return; } // reset tasks if they're all complete if (Tasks.All(t => t.IsDone)) { foreach (var task in Tasks) { task.Reset(); } } // get the 1st task that isn't done and pulse it. CurrentTask = Tasks.FirstOrDefault(t => !t.IsDone); if (CurrentTask != null) { if (!CurrentTask.IsRunning) { CurrentTask.Start(); } CurrentTask.Pulse(); if (CurrentTask is WaitTask && CurrentTask.IsRunning) { Profile.TaskTooltip = CurrentTask.ToolTip; } else if (!string.IsNullOrEmpty(Profile.TaskTooltip)) { Profile.TaskTooltip = null; } } }
void TaskPropertyChanged(object sender, EventArgs e) { BMTask task = ((dynamic)((Control)sender).Tag).Task; PropertyInfo pi = ((dynamic)((Control)sender).Tag).Property; if (sender is ComboBox) { pi.SetValue(task, ((ComboBox)sender).SelectedValue, null); } else if (sender is TextBox) { string str = ((TextBox)sender).Text; try { object val = Convert.ChangeType(str, pi.PropertyType); pi.SetValue(task, val, null); } // in case the type conversion fails fall back to default value. catch (FormatException) { object defaultValue = GetDefaultValue(pi.PropertyType); pi.SetValue(task, defaultValue, null); } } ((RoutedEventArgs)e).Handled = true; }
public void SkipCurrentTask(string profileName) { CharacterProfile profile = GetProfileByName(profileName); if (profile != null) { if (!profile.IsRunning || profile.IsPaused) { profile.Log("Could not skip current task because profile is not running or is paused."); return; } BMTask currentTask = profile.TaskManager.CurrentTask; if (currentTask == null) { profile.Log("Could not skip current task because there is no task running."); } else { currentTask.Stop(); profile.Log("Skipping the \"{0}\" task.", currentTask.Name); } } else { Log.Write("Could not find a profile with the name: {0}", profileName); } }
private void DataGridRowContextMenuOpening(object sender, ContextMenuEventArgs e) { var row = (DataGridRow)sender; var profile = (CharacterProfile)row.Item; var hbManager = profile.TaskManager.HonorbuddyManager; var wowManager = profile.TaskManager.WowManager; // only show the skip task menu item if profile has > 1 task and startup sequence is complete var skipTaskMenuItem = (MenuItem)row.ContextMenu.Items[0]; BMTask task = profile.TaskManager.Tasks.FirstOrDefault(t => t.IsRunning); if (profile.TaskManager.Tasks.Count > 1 && profile.TaskManager.StartupSequenceIsComplete && task != null) { skipTaskMenuItem.Visibility = Visibility.Visible; } else { skipTaskMenuItem.Visibility = Visibility.Collapsed; } //only show the 'Bring HB to Foreground' task menu item if hb is running. var bringHbToForegroundTaskMenuItem = (MenuItem)row.ContextMenu.Items[1]; var killHBMenu = (MenuItem)row.ContextMenu.Items[2]; if (hbManager.IsRunning && hbManager.BotProcess != null && !hbManager.BotProcess.HasExitedSafe()) { bringHbToForegroundTaskMenuItem.Visibility = Visibility.Visible; killHBMenu.Visibility = Visibility.Visible; } else { bringHbToForegroundTaskMenuItem.Visibility = Visibility.Collapsed; killHBMenu.Visibility = Visibility.Collapsed; } }
private void SkipTaskMenuItem_Click(object sender, RoutedEventArgs e) { var profile = (CharacterProfile)((MenuItem)sender).Tag; BMTask currentTask = profile.TaskManager.Tasks.FirstOrDefault(t => !t.IsDone); if (currentTask != null) { currentTask.Stop(); } }
void SourceChanged(object source) { if (!(source is BMTask)) { throw new InvalidOperationException("Can only assign a BMTask derived class to Source"); } BMTask task = (BMTask)source; List <PropertyInfo> propertyList = task.GetType().GetProperties(). Where(pi => pi.GetCustomAttributesData().All(cad => cad.Constructor.DeclaringType != typeof(XmlIgnoreAttribute))).ToList(); PropertyGrid.Children.Clear(); PropertyGrid.RowDefinitions.Clear(); for (int index = 0; index < propertyList.Count; index++) { PropertyGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(22) }); var propNameText = new TextBlock() { Text = SpacifierConverter.GetSpaciousString(propertyList[index].Name), Margin = new Thickness(2, 0, 2, 0) }; Grid.SetRow(propNameText, index); PropertyGrid.Children.Add(propNameText); Control propEdit; // check if the property has CustomTaskEditControl attribute attached CustomTaskEditControlAttribute customControlAttr = (CustomTaskEditControlAttribute)propertyList[index].GetCustomAttributes(typeof(CustomTaskEditControlAttribute), false).FirstOrDefault(); if (customControlAttr != null) { propEdit = (Control)Activator.CreateInstance(customControlAttr.ControlType); if (!(propEdit is ICustomTaskEditControlDataBound)) { throw new InvalidOperationException("CustomTaskEditControl must implement the ICustomTaskEditControlDataBound interface"); } ((ICustomTaskEditControlDataBound)propEdit).SetValue(propertyList[index].GetValue(task, null)); ((ICustomTaskEditControlDataBound)propEdit).SetBinding(task, propertyList[index].Name); } else // no custom controls attached to property so load the default control for the property type { propEdit = GetControlForType(propertyList[index].PropertyType, propertyList[index].GetValue(task, null)); } propEdit.Margin = new Thickness(0, 1, 0, 1); propEdit.Tag = new { Task = task, Property = propertyList[index] }; Grid.SetColumn((UIElement)propEdit, 1); Grid.SetRow((UIElement)propEdit, index); PropertyGrid.Children.Add((UIElement)propEdit); } }
public void SkipCurrentTask(string profileName) { CharacterProfile profile = GetProfileByName(profileName); if (profile != null) { BMTask currentTask = profile.Tasks.FirstOrDefault(t => !t.IsDone); if (currentTask != null) { currentTask.Stop(); } } }
private void ProfileTaskList_Drop(object sender, DragEventArgs e) { if (MainWindow.Instance.AccountGrid.SelectedItem != null) { CharacterProfile profile = (CharacterProfile)MainWindow.Instance.AccountGrid.SelectedItem; DataObject dObj = (DataObject)e.Data; BMTask task = null; bool removeSource = false; // drop originated from the left side 'TaskList' if (dObj.GetDataPresent("PersistentObject")) { Type taskType = (Type)dObj.GetData("PersistentObject"); task = (BMTask)Activator.CreateInstance(taskType); task.SetProfile(profile); } else if (sender == ProfileTaskList)// drop originated from itself. { task = (BMTask)dObj.GetData(dObj.GetFormats().FirstOrDefault()); removeSource = true; } if (task == null) { return; } ListBoxItem targetItem = FindParent <ListBoxItem>((DependencyObject)e.OriginalSource); if (targetItem != null) { BMTask targetTask = (BMTask)targetItem.Content; for (int i = ProfileTaskList.Items.Count - 1; i >= 0; i--) { if (ProfileTaskList.Items[i].Equals(targetTask)) { if (removeSource) { profile.Tasks.Remove(task); } profile.Tasks.Insert(i, task); break; } } } else if (!removeSource) { profile.Tasks.Add(task); } _isDragging = false; e.Handled = true; } }
public void Pulse() { if (WowManager.IsRunning) { WowManager.Pulse(); if (WowManager.InGame && !HonorbuddyManager.IsRunning) { if (!StartupSequenceIsComplete) { HonorbuddyManager.SetSettings(Profile.Settings.HonorbuddySettings); } HonorbuddyManager.Start(); } if (HonorbuddyManager.IsRunning) { HonorbuddyManager.Pulse(); } } // only pulse tasks if StartupSequenceIsComplete is true. if (StartupSequenceIsComplete) { // reset tasks if they're all complete if (Tasks.Count > 0 && Tasks.All(t => t.IsDone)) { foreach (var task in Tasks) { task.Reset(); } } // get the 1st task that isn't done and pulse it. BMTask currentTask = Tasks.FirstOrDefault(t => !t.IsDone); if (currentTask != null) { if (!currentTask.IsRunning) { currentTask.Start(); } currentTask.Pulse(); if (currentTask is WaitTask && currentTask.IsRunning) { Profile.TaskTooltip = currentTask.ToolTip; } else if (!string.IsNullOrEmpty(Profile.TaskTooltip)) { Profile.TaskTooltip = null; } } } }
public AccountConfigUserControl() { InitializeComponent(); IsEditing = false; // Get list of tasks via reflection List <Type> taskTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(BMTask).IsAssignableFrom(t) && t != typeof(BMTask)).ToList(); foreach (var type in taskTypes) { ListBoxItem item = new ListBoxItem(); BMTask task = (BMTask)Activator.CreateInstance(type); item.Content = task.Name; item.Tag = type; item.ToolTip = task.Help; TaskList.Items.Add(item); } ProfileTaskList.ContextMenuOpening += (sender, e) => { if (ProfileTaskList.SelectedItem == null) { e.Handled = true; } }; RegionCombo.ItemsSource = Enum.GetValues(typeof(WowSettings.WowRegion)); }