/// <summary> /// Checks whether the given operation absolutely requires a confirmation from the user. /// True when there are dependencies to remove. /// </summary> /// <param name="operation">The operation.</param> /// <returns></returns> public static bool RequiresWindow(IPlanOperation operation) { if (operation?.Type != PlanOperations.Suppression) return false; return operation.SkillsToRemove.Count() != operation.AllEntriesToRemove.Count(); }
/// <summary> /// Updates a regular "Plan to X" menu : text, tag, enable/disable. /// </summary> /// <param name="plan">The plan.</param> /// <param name="menu">The menu.</param> /// <param name="skill">The skill.</param> /// <param name="level">The level.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">menu /// or /// plan</exception> public static bool UpdatesRegularPlanToMenu(this Plan plan, ToolStripItem menu, Skill skill, int level) { menu.ThrowIfNull(nameof(menu)); plan.ThrowIfNull(nameof(plan)); menu.Text = level == 0 ? "Remove" : $"Level {level}"; menu.Enabled = plan.EnablePlanTo(skill, level); if (menu.Enabled) { IPlanOperation operation = plan.TryPlanTo(skill, level); menu.Tag = operation; if (RequiresWindow(operation)) { menu.Text += @"..."; } } ToolStripMenuItem menuItem = menu as ToolStripMenuItem; if (menuItem != null) { menuItem.Checked = plan.GetPlannedLevel(skill) == level; } return(menu.Enabled); }
/// <summary> /// Treeview's context menu > Plan "(selection)". /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmAddToPlan_Click(object sender, EventArgs e) { var masteryLevel = treeView.SelectedNode.Tag as Mastery; var certLevel = treeView.SelectedNode.Tag as CertificateLevel; IPlanOperation operation = null; if (masteryLevel != null) { operation = m_plan.TryPlanTo(masteryLevel); } else if (certLevel != null) { operation = m_plan.TryPlanTo(certLevel); } else { var prereq = treeView.SelectedNode.Tag as SkillLevel; if (prereq != null) { operation = m_plan.TryPlanTo(prereq.Skill, prereq.Level); } } if (operation != null) { var planWindow = ParentForm as PlanWindow; if (planWindow != null) { PlanHelper.SelectPerform(new PlanToOperationWindow(operation), planWindow, operation); } } }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options. /// </summary> /// <param name="operation"></param> /// <returns></returns> public static bool Perform(Form parentForm, IPlanOperation operation) { using (var window = new PlanToOperationForm(operation)) { var result = window.ShowDialog(parentForm); return(result == DialogResult.OK); } }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options. /// </summary> /// <param name="operation"></param> /// <returns></returns> public static bool Perform(Form parentForm, IPlanOperation operation) { using (var window = new PlanToOperationForm(operation)) { var result = window.ShowDialog(parentForm); return result == DialogResult.OK; } }
/// <summary> /// Checks whether the given operation absolutely requires a confirmation from the user. /// True when there are dependencies to remove. /// </summary> /// <param name="operation">The operation.</param> /// <returns></returns> public static bool RequiresWindow(IPlanOperation operation) { if (operation?.Type != PlanOperations.Suppression) { return(false); } return(operation.SkillsToRemove.Count() != operation.AllEntriesToRemove.Count()); }
/// <summary> /// Handler for a plan item click on the plan's context menu. /// Add a skill to the plan. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuPlanItem_Click(object sender, EventArgs e) { var planItem = (ToolStripMenuItem)sender; var tag = (Pair <Plan, SkillLevel>)planItem.Tag; IPlanOperation operation = tag.A.TryPlanTo(tag.B.Skill, tag.B.Level); PlanHelper.SelectPerform(operation); }
/// <summary> /// Constructor for use in-code. /// </summary> /// <param name="operation"></param> public PlanToOperationForm(IPlanOperation operation) : this() { if (operation.Type == PlanOperations.None) { throw new ArgumentException("This window doesn't support empty operations.", "operation"); } m_operation = operation; rootMultiPanel.SelectedPage = additionPage; }
/// <summary> /// Selects which type of Perform will be called according to user settings. /// </summary> /// <param name="operation"></param> /// <returns></returns> public static bool SelectPerform(IPlanOperation operation) { if (Settings.UI.PlanWindow.UseAdvanceEntryAddition && operation.Type == PlanOperations.Addition) { return(Perform(operation)); } else { return(PerformSilently(operation)); } }
/// <summary> /// Selects which type of Perform will be called according to user settings. /// </summary> /// <param name="operationForm">The operation form.</param> /// <param name="parentForm">The parent form.</param> /// <param name="operation">The operation.</param> public static void SelectPerform(Form operationForm, IWin32Window parentForm, IPlanOperation operation) { if (operation == null) return; if (Settings.UI.PlanWindow.UseAdvanceEntryAddition && operation.Type == PlanOperations.Addition) { Perform(operationForm, parentForm); return; } PerformSilently(operationForm, parentForm, operation); }
/// <summary> /// Constructor for use in-code. /// </summary> /// <param name="operation">The operation.</param> /// <exception cref="System.ArgumentException">@This window doesn't support empty operations.;operation</exception> /// <exception cref="System.ArgumentNullException">operation</exception> public PlanToOperationWindow(IPlanOperation operation) : this() { operation.ThrowIfNull(nameof(operation)); if (operation.Type == PlanOperations.None) { throw new ArgumentException(@"This window doesn't support empty operations.", nameof(operation)); } m_operation = operation; rootMultiPanel.SelectedPage = additionPage; }
/// <summary> /// Shared context menu - add ship/item/blueprint to plan. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsAddEntityToPlan_Click(object sender, EventArgs e) { Item entity = GetSelectedItem(); if (entity == null) { return; } List <string> listOfActivities = GetSelectedItemActivities(entity); IPlanOperation operation = m_planWindow.Plan.TryAddSet(entity.Prerequisites.Where(x => listOfActivities.Contains(x.Activity.GetDescription())), entity.Name); PlanHelper.Perform(operation); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options, in a silent way whenever possible. /// </summary> /// <param name="parentForm"></param> /// <param name="operation"></param> /// <returns></returns> public static bool PerformSilently(Form parentForm, IPlanOperation operation) { if (operation == null) { return(false); } // A window is required if (RequiresWindow(operation)) { return(Perform(parentForm, operation)); } // Silent way operation.Perform(); return(operation.Type == PlanOperations.None); }
/// <summary> /// Context menu > Plan to N / Remove. /// Toolbar > Plan to... > Level N / Remove. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void planToMenu_Click(object sender, EventArgs e) { IPlanOperation operation = ((ToolStripMenuItem)sender).Tag as IPlanOperation; if (operation == null) { return; } PlanWindow planWindow = ParentForm as PlanWindow; if (planWindow == null) { return; } PlanHelper.SelectPerform(new PlanToOperationWindow(operation), planWindow, operation); }
/// <summary> /// When the user clicks the "plan" button, we add the prerqs to the plan and refresh the display. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlan_Click(object sender, EventArgs e) { IPlanOperation operation = m_plan.TryAddSet(m_prerequisites, m_selectedLoadout.Name); if (operation == null) { return; } PlanWindow planWindow = PlanWindow.ShowPlanWindow(plan: operation.Plan); if (planWindow == null) { return; } PlanHelper.Perform(new PlanToOperationWindow(operation), planWindow); UpdatePlanningControls(); }
/// <summary> /// Adds the required skills to the Plan specified by the Plan property. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlan_Click(object sender, EventArgs e) { IPlanOperation operation = m_plan.TryAddSet(m_skillsToAdd, m_loadoutInfo.Loadouts.First().Name); if (operation == null) { return; } PlanWindow planWindow = PlanWindow.ShowPlanWindow(plan: operation.Plan); if (planWindow == null) { return; } PlanHelper.Perform(new PlanToOperationWindow(operation), planWindow); planWindow.ShowPlanEditor(); UpdatePlanStatus(); }
/// <summary> /// Handler for a plan item click on the plan's context menu. /// Add a skill to the plan. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void menuPlanItem_Click(object sender, EventArgs e) { ToolStripMenuItem planItem = (ToolStripMenuItem)sender; KeyValuePair <Plan, SkillLevel> tag = (KeyValuePair <Plan, SkillLevel>)planItem.Tag; IPlanOperation operation = tag.Key.TryPlanTo(tag.Value.Skill, tag.Value.Level); if (operation == null) { return; } PlanWindow planWindow = PlanWindow.ShowPlanWindow(plan: operation.Plan); if (planWindow == null) { return; } PlanHelper.SelectPerform(new PlanToOperationWindow(operation), planWindow, operation); }
/// <summary> /// Set the planned level to the given one, lowering it if it's higher than the targetted one. /// When the skill is not planned already, the prerequisites are automatically added. /// Note this method won't remove entries other entries depend of. /// </summary> /// <param name="skill">The skill we want to plan</param> /// <param name="level">The level we want to train to</param> /// <param name="priority">The priority.</param> /// <param name="noteForNewEntries">The reason we want to train this skill</param> public void PlanTo(StaticSkill skill, long level, int priority, string noteForNewEntries) { int plannedLevel = GetPlannedLevel(skill); if (level == plannedLevel) { return; } using (SuspendingEvents()) { // We may either have to add or remove entries. First, we assume we have to add ones if (level > plannedLevel) { List <StaticSkillLevel> skillsToAdd = new List <StaticSkillLevel> { new StaticSkillLevel(skill, level) }; // None added ? Then return IPlanOperation operation = TryAddSet(skillsToAdd, noteForNewEntries); operation.PerformAddition(priority); } else { level = Math.Max(level, GetMinimumLevel(skill)); // If we reach this point, then we have to remove entries for (int i = 5; i > level; i--) { PlanEntry entry = GetEntry(skill, i); if (entry == null) { continue; } RemoveCore(Items.IndexOf(entry)); } } } }
/// <summary> /// Event handler method for Add Skills button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddSkills_Click(object sender, EventArgs e) { // Add skills to plan IPlanOperation operation = m_plan.TryAddSet(m_object.Prerequisites.Where(x => x.Activity.Equals(Activity)), m_object.Name); if (operation == null) { return; } PlanWindow planWindow = ParentForm as PlanWindow; if (planWindow == null) { return; } PlanHelper.Perform(new PlanToOperationWindow(operation), planWindow); // Refresh display to reflect plan changes UpdateDisplay(); }
/// <summary> /// Skill context menu > Plan to level /// theres a menu item for each level, each one is tagged with a /// string representing level number. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsAddLevel_Click(object sender, EventArgs e) { IPlanOperation operation = ((ToolStripMenuItem)sender).Tag as IPlanOperation; PlanHelper.SelectPerform(operation); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options, in a silent way whenever possible. /// </summary> /// <param name="parentForm"></param> /// <param name="operation"></param> /// <returns></returns> public static bool PerformSilently(IPlanOperation operation) { var window = WindowsFactory<PlanWindow>.GetByTag(operation.Plan); return PerformSilently(window, operation); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options, in a silent way whenever possible. /// </summary> /// <param name="parentForm"></param> /// <param name="operation"></param> /// <returns></returns> public static bool PerformSilently(Form parentForm, IPlanOperation operation) { if (operation == null) return false; // A window is required if (RequiresWindow(operation)) { return Perform(parentForm, operation); } // Silent way operation.Perform(); return (operation.Type == PlanOperations.None); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options. /// </summary> /// <param name="operation"></param> /// <returns></returns> public static bool Perform(IPlanOperation operation) { var window = WindowsFactory <PlanWindow> .GetByTag(operation.Plan); return(Perform(window, operation)); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options, in a silent way whenever possible. /// </summary> /// <param name="operationForm">The operation form.</param> /// <param name="parentForm">The parent form.</param> /// <param name="operation">The operation.</param> private static void PerformSilently(Form operationForm, IWin32Window parentForm, IPlanOperation operation) { if (operation == null) return; // A window is required if (RequiresWindow(operation) && Perform(operationForm, parentForm) != DialogResult.OK) return; // Silent way operation.Perform(); }
/// <summary> /// Performs the action for the "Plan To N" and "Remove" menu options, in a silent way whenever possible. /// </summary> /// <param name="operationForm">The operation form.</param> /// <param name="parentForm">The parent form.</param> /// <param name="operation">The operation.</param> private static void PerformSilently(Form operationForm, IWin32Window parentForm, IPlanOperation operation) { if (operation == null) { return; } // A window is required if (RequiresWindow(operation) && Perform(operationForm, parentForm) != DialogResult.OK) { return; } // Silent way operation.Perform(); }
/// <summary> /// Selects which type of Perform will be called according to user settings. /// </summary> /// <param name="operation"></param> /// <returns></returns> public static bool SelectPerform(IPlanOperation operation) { if (Settings.UI.PlanWindow.UseAdvanceEntryAddition && operation.Type == PlanOperations.Addition) { return Perform(operation); } else { return PerformSilently(operation); } }
/// <summary> /// Selects which type of Perform will be called according to user settings. /// </summary> /// <param name="operationForm">The operation form.</param> /// <param name="parentForm">The parent form.</param> /// <param name="operation">The operation.</param> public static void SelectPerform(Form operationForm, IWin32Window parentForm, IPlanOperation operation) { if (operation == null) { return; } if (Settings.UI.PlanWindow.UseAdvanceEntryAddition && operation.Type == PlanOperations.Addition) { Perform(operationForm, parentForm); return; } PerformSilently(operationForm, parentForm, operation); }