/// <summary> /// Executes the provided <see cref="manip"/> with the provided parameters. /// </summary> /// <param name="manip">Manipulation to perform on the <see cref="SAV"/> box data.</param> /// <param name="box">Single box to modify; if <see cref="allBoxes"/> is set, this param is ignored.</param> /// <param name="allBoxes">Indicates if all boxes are to be manipulated, or just one box.</param> /// <param name="reverse">Manipulation action should be inverted (criteria) or reversed (sort).</param> /// <returns>True if operation succeeded, false if no changes made.</returns> public bool Execute(IBoxManip manip, int box, bool allBoxes, bool reverse = false) { bool usable = manip.Usable.Invoke(SAV); if (!usable) { return(false); } var start = allBoxes ? 0 : box; var stop = allBoxes ? SAV.BoxCount - 1 : box; var param = new BoxManipParam(start, stop, reverse); var prompt = manip.GetPrompt(allBoxes); var fail = manip.GetFail(allBoxes); if (!CanManipulateRegion(param.Start, param.Stop, prompt, fail)) { return(false); } var result = manip.Execute(SAV, param); if (result <= 0) { return(false); } var success = manip.GetSuccess(allBoxes); FinishBoxManipulation(success, allBoxes, result); return(true); }
/// <summary> /// Gets the corresponding name from <see cref="ManipCategoryNames"/> for the requested <see cref="manip"/>. /// </summary> /// <param name="manip">Manipulation type.</param> /// <returns>Category Name</returns> public static string GetManipCategoryName(this IBoxManip manip) { for (int i = 0; i < ManipCategories.Length; i++) { if (ManipCategories[i].Any(z => z == manip)) { return(ManipCategoryNames[i]); } } return(null); }
private void AddItem(ISaveFileProvider SAV, ToolStripDropDownItem parent, IBoxManip item) { var name = item.Type.ToString(); ManipTypeImage.TryGetValue(item.Type, out var img); var tsi = new ToolStripMenuItem { Name = $"mnu_{name}", Text = name, Image = img }; tsi.Click += (s, e) => Manipulator.Execute(item, SAV.CurrentBox, All, Reverse); parent.DropDownItems.Add(tsi); CustomItems.Add(new ItemVisibility(tsi, item)); }
public ItemVisibility(ToolStripItem toolStripItem, IBoxManip visible) { Item = toolStripItem; Manip = visible; }