2018-09-02 18:31:34 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-22 05:31:11 +00:00
|
|
|
|
using System.Drawing;
|
2018-04-21 23:31:41 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using PKHeX.Core;
|
2018-04-22 05:31:11 +00:00
|
|
|
|
using PKHeX.WinForms.Properties;
|
2018-04-21 23:31:41 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms.Controls
|
|
|
|
|
{
|
2018-05-24 01:29:30 +00:00
|
|
|
|
public sealed class BoxMenuStrip : ContextMenuStrip
|
2018-04-21 23:31:41 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
private readonly SAVEditor SAV;
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private readonly List<ItemVisibility> CustomItems = new();
|
2018-09-02 18:31:34 +00:00
|
|
|
|
private readonly BoxManipulator Manipulator;
|
2018-05-24 01:29:30 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
public BoxMenuStrip(SAVEditor sav)
|
2018-04-21 23:31:41 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
Manipulator = new BoxManipulatorWF(sav);
|
|
|
|
|
SAV = sav;
|
|
|
|
|
var categories = BoxManipUtil.ManipCategories;
|
|
|
|
|
var names = BoxManipUtil.ManipCategoryNames;
|
|
|
|
|
for (int i = 0; i < categories.Length; i++)
|
2018-04-21 23:31:41 +00:00
|
|
|
|
{
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var category = categories[i];
|
2018-09-02 18:31:34 +00:00
|
|
|
|
var sprite = TopLevelImages[i];
|
2020-06-17 02:46:22 +00:00
|
|
|
|
var name = names[i];
|
2018-09-02 18:31:34 +00:00
|
|
|
|
var parent = new ToolStripMenuItem {Name = $"mnu_{name}", Text = name, Image = sprite};
|
2020-06-17 02:46:22 +00:00
|
|
|
|
foreach (var item in category)
|
|
|
|
|
AddItem(sav, parent, item);
|
2018-09-02 18:31:34 +00:00
|
|
|
|
Items.Add(parent);
|
2018-05-01 00:32:23 +00:00
|
|
|
|
}
|
2018-05-24 01:29:30 +00:00
|
|
|
|
}
|
2018-04-21 23:31:41 +00:00
|
|
|
|
|
2020-06-17 02:46:22 +00:00
|
|
|
|
private void AddItem(ISaveFileProvider sav, ToolStripDropDownItem parent, IBoxManip item)
|
2018-05-24 01:29:30 +00:00
|
|
|
|
{
|
2018-09-02 18:31:34 +00:00
|
|
|
|
var name = item.Type.ToString();
|
|
|
|
|
ManipTypeImage.TryGetValue(item.Type, out var img);
|
|
|
|
|
var tsi = new ToolStripMenuItem { Name = $"mnu_{name}", Text = name, Image = img };
|
2020-06-17 02:46:22 +00:00
|
|
|
|
tsi.Click += (s, e) => Manipulator.Execute(item, sav.CurrentBox, All, Reverse);
|
2018-09-02 18:31:34 +00:00
|
|
|
|
parent.DropDownItems.Add(tsi);
|
|
|
|
|
CustomItems.Add(new ItemVisibility(tsi, item));
|
2018-05-24 01:29:30 +00:00
|
|
|
|
}
|
2018-05-01 00:32:23 +00:00
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private static readonly Dictionary<BoxManipType, Image> ManipTypeImage = new()
|
2018-09-02 18:31:34 +00:00
|
|
|
|
{
|
|
|
|
|
[BoxManipType.DeleteAll] = Resources.nocheck,
|
|
|
|
|
[BoxManipType.DeleteEggs] = Resources.about,
|
|
|
|
|
[BoxManipType.DeletePastGen] = Resources.bak,
|
2019-02-19 01:00:16 +00:00
|
|
|
|
[BoxManipType.DeleteForeign] = Resources.language,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
[BoxManipType.DeleteUntrained] = Resources.gift,
|
|
|
|
|
[BoxManipType.DeleteItemless] = Resources.main,
|
|
|
|
|
[BoxManipType.DeleteIllegal] = Resources.export,
|
2019-02-19 01:00:16 +00:00
|
|
|
|
[BoxManipType.DeleteClones] = Resources.users,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
|
|
|
|
|
[BoxManipType.SortSpecies] = Resources.numlohi,
|
|
|
|
|
[BoxManipType.SortSpeciesReverse] = Resources.numhilo,
|
|
|
|
|
[BoxManipType.SortLevel] = Resources.vallohi,
|
|
|
|
|
[BoxManipType.SortLevelReverse] = Resources.valhilo,
|
|
|
|
|
[BoxManipType.SortDate] = Resources.date,
|
|
|
|
|
[BoxManipType.SortName] = Resources.alphaAZ,
|
2018-11-14 03:21:33 +00:00
|
|
|
|
[BoxManipType.SortFavorite] = Resources.heart,
|
2018-11-23 07:02:57 +00:00
|
|
|
|
[BoxManipType.SortParty] = Resources.users,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
[BoxManipType.SortShiny] = Resources.showdown,
|
|
|
|
|
[BoxManipType.SortRandom] = Resources.wand,
|
|
|
|
|
|
|
|
|
|
[BoxManipType.SortUsage] = Resources.heart,
|
|
|
|
|
[BoxManipType.SortPotential] = Resources.numhilo,
|
|
|
|
|
[BoxManipType.SortTraining] = Resources.showdown,
|
|
|
|
|
[BoxManipType.SortOwner] = Resources.users,
|
|
|
|
|
[BoxManipType.SortType] = Resources.main,
|
|
|
|
|
[BoxManipType.SortVersion] = Resources.numlohi,
|
|
|
|
|
[BoxManipType.SortBST] = Resources.vallohi,
|
2018-11-14 03:21:33 +00:00
|
|
|
|
[BoxManipType.SortCP] = Resources.vallohi,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
[BoxManipType.SortLegal] = Resources.export,
|
2019-02-18 23:34:55 +00:00
|
|
|
|
[BoxManipType.SortEncounterType] = Resources.about,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
|
|
|
|
|
[BoxManipType.ModifyHatchEggs] = Resources.about,
|
2020-02-18 03:28:20 +00:00
|
|
|
|
[BoxManipType.ModifyMaxFriendship] = Resources.users,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
[BoxManipType.ModifyMaxLevel] = Resources.showdown,
|
|
|
|
|
[BoxManipType.ModifyResetMoves] = Resources.date,
|
|
|
|
|
[BoxManipType.ModifyRandomMoves] = Resources.wand,
|
|
|
|
|
[BoxManipType.ModifyHyperTrain] = Resources.vallohi,
|
2022-02-05 01:36:51 +00:00
|
|
|
|
[BoxManipType.ModifyGanbaru] = Resources.vallohi,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
[BoxManipType.ModifyRemoveNicknames] = Resources.alphaAZ,
|
|
|
|
|
[BoxManipType.ModifyRemoveItem] = Resources.gift,
|
2020-02-18 03:28:20 +00:00
|
|
|
|
[BoxManipType.ModifyHeal] = Resources.heart,
|
2018-09-02 18:31:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-05-24 01:29:30 +00:00
|
|
|
|
private sealed class ItemVisibility
|
|
|
|
|
{
|
|
|
|
|
private readonly ToolStripItem Item;
|
2018-09-02 18:31:34 +00:00
|
|
|
|
private readonly IBoxManip Manip;
|
2018-04-21 23:31:41 +00:00
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
public ItemVisibility(ToolStripItem toolStripItem, IBoxManip visible)
|
2018-04-21 23:31:41 +00:00
|
|
|
|
{
|
2018-05-24 01:29:30 +00:00
|
|
|
|
Item = toolStripItem;
|
2018-09-02 18:31:34 +00:00
|
|
|
|
Manip = visible;
|
2018-04-21 23:31:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 02:30:50 +00:00
|
|
|
|
public void SetVisibility(SaveFile s) => Item.Visible = Manip.Usable(s);
|
2018-05-24 01:29:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleVisibility()
|
|
|
|
|
{
|
|
|
|
|
foreach (var s in CustomItems)
|
2020-06-17 02:46:22 +00:00
|
|
|
|
s.SetVisibility(SAV.SAV);
|
2018-05-24 01:29:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
private static readonly Image[] TopLevelImages =
|
2018-05-01 00:32:23 +00:00
|
|
|
|
{
|
2018-09-02 18:31:34 +00:00
|
|
|
|
Resources.nocheck,
|
|
|
|
|
Resources.swapBox,
|
|
|
|
|
Resources.settings,
|
|
|
|
|
Resources.wand,
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-19 23:59:33 +00:00
|
|
|
|
public void Clear() => Manipulator.Execute(BoxManipType.DeleteAll, SAV.CurrentBox, All);
|
|
|
|
|
public void Sort() => Manipulator.Execute(BoxManipType.SortSpecies, SAV.CurrentBox, All);
|
2018-05-24 01:29:30 +00:00
|
|
|
|
|
|
|
|
|
private static bool All => (ModifierKeys & Keys.Shift) != 0;
|
|
|
|
|
private static bool Reverse => (ModifierKeys & Keys.Control) != 0;
|
2018-09-02 18:31:34 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implementation of a WinForms box manipulator (using MessageBox prompts)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class BoxManipulatorWF : BoxManipulator
|
|
|
|
|
{
|
|
|
|
|
private readonly SAVEditor Editor;
|
|
|
|
|
protected override SaveFile SAV => Editor.SAV;
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2018-09-02 18:31:34 +00:00
|
|
|
|
public BoxManipulatorWF(SAVEditor editor)
|
2018-05-24 01:29:30 +00:00
|
|
|
|
{
|
2018-09-02 18:31:34 +00:00
|
|
|
|
Editor = editor;
|
2018-05-24 01:29:30 +00:00
|
|
|
|
}
|
2018-08-13 02:27:11 +00:00
|
|
|
|
|
2019-02-21 01:59:54 +00:00
|
|
|
|
protected override void FinishBoxManipulation(string message, bool all, int count) => Editor.FinishBoxManipulation(message, all, count);
|
2018-09-02 18:31:34 +00:00
|
|
|
|
|
|
|
|
|
protected override bool CanManipulateRegion(int start, int end, string prompt, string fail)
|
2018-05-24 01:29:30 +00:00
|
|
|
|
{
|
2020-01-18 21:27:48 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(prompt) && WinFormsUtil.Prompt(MessageBoxButtons.YesNo, prompt) != DialogResult.Yes)
|
2018-09-02 18:31:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
bool canModify = base.CanManipulateRegion(start, end, prompt, fail);
|
2020-01-18 21:27:48 +00:00
|
|
|
|
if (!canModify && !string.IsNullOrEmpty(fail))
|
2018-09-02 18:31:34 +00:00
|
|
|
|
WinFormsUtil.Alert(fail);
|
|
|
|
|
return canModify;
|
2018-05-01 00:32:23 +00:00
|
|
|
|
}
|
2018-04-21 23:31:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|