2016-07-16 22:52:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-08 07:54:09 +00:00
|
|
|
|
using PKHeX.Core;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing;
|
2016-07-16 22:52:33 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class RibbonEditor : Form
|
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public RibbonEditor(PKM pk)
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
2017-05-23 04:55:05 +00:00
|
|
|
|
pkm = pk;
|
2016-07-16 22:52:33 +00:00
|
|
|
|
InitializeComponent();
|
2018-08-14 02:24:49 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
riblist = RibbonInfo.GetRibbonInfo(pkm);
|
2016-07-16 22:52:33 +00:00
|
|
|
|
int vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
|
|
|
|
|
TLP_Ribbons.Padding = FLP_Ribbons.Padding = new Padding(0, 0, vertScrollWidth, 0);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-07-17 02:59:53 +00:00
|
|
|
|
// Updating a Control display with autosized elements on every row addition is cpu intensive. Disable layout updates while populating.
|
|
|
|
|
TLP_Ribbons.SuspendLayout();
|
2017-01-08 07:54:09 +00:00
|
|
|
|
FLP_Ribbons.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
TLP_Ribbons.Scroll += WinFormsUtil.PanelScroll;
|
2017-06-23 04:56:41 +00:00
|
|
|
|
PopulateRibbons();
|
2016-07-17 02:59:53 +00:00
|
|
|
|
TLP_Ribbons.ResumeLayout();
|
2021-02-10 21:34:49 +00:00
|
|
|
|
|
2021-11-20 17:04:09 +00:00
|
|
|
|
if (pk is G8PKM pk8)
|
2021-02-10 21:34:49 +00:00
|
|
|
|
{
|
|
|
|
|
var names = Enum.GetNames(typeof(RibbonIndex));
|
|
|
|
|
var values = (RibbonIndex[])Enum.GetValues(typeof(RibbonIndex));
|
|
|
|
|
var items = names.Select((z, i) => new ComboItem(RibbonStrings.GetName("Ribbon"+z), (int) values[i])).OrderBy(z => z.Text);
|
|
|
|
|
var ds = new List<ComboItem> {new(GameInfo.GetStrings(Main.CurrentLanguage).Move[0], -1)};
|
|
|
|
|
ds.AddRange(items.ToArray());
|
|
|
|
|
CB_Affixed.InitializeBinding();
|
|
|
|
|
CB_Affixed.DataSource = ds;
|
|
|
|
|
CB_Affixed.SelectedValue = (int)pk8.AffixedRibbon;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CB_Affixed.Visible = false;
|
|
|
|
|
}
|
2016-07-16 22:52:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-29 23:39:15 +00:00
|
|
|
|
private readonly IReadOnlyList<RibbonInfo> riblist;
|
2017-05-23 04:55:05 +00:00
|
|
|
|
private readonly PKM pkm;
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
private const string PrefixNUD = "NUD_";
|
|
|
|
|
private const string PrefixLabel = "L_";
|
|
|
|
|
private const string PrefixCHK = "CHK_";
|
|
|
|
|
private const string PrefixPB = "PB_";
|
|
|
|
|
|
2018-07-29 23:39:15 +00:00
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Save();
|
2016-07-16 22:52:33 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void PopulateRibbons()
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
|
|
|
|
TLP_Ribbons.ColumnCount = 2;
|
|
|
|
|
TLP_Ribbons.RowCount = 0;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
// Add Ribbons
|
|
|
|
|
foreach (var rib in riblist)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
AddRibbonSprite(rib);
|
2017-06-29 16:03:56 +00:00
|
|
|
|
foreach (var rib in riblist.OrderBy(z => RibbonStrings.GetName(z.Name)))
|
2017-06-18 01:37:19 +00:00
|
|
|
|
AddRibbonChoice(rib);
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
// Force auto-size
|
2020-10-18 18:02:39 +00:00
|
|
|
|
foreach (var style in TLP_Ribbons.RowStyles.OfType<RowStyle>())
|
2016-07-16 22:52:33 +00:00
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
foreach (var style in TLP_Ribbons.ColumnStyles.OfType<ColumnStyle>())
|
2016-07-16 22:52:33 +00:00
|
|
|
|
style.SizeType = SizeType.AutoSize;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddRibbonSprite(RibbonInfo rib)
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
2017-07-06 06:05:49 +00:00
|
|
|
|
var name = rib.Name;
|
2018-07-29 23:39:15 +00:00
|
|
|
|
var pb = new PictureBox { AutoSize = false, Size = new Size(40,40), BackgroundImageLayout = ImageLayout.Center, Visible = false, Name = PrefixPB + name };
|
2018-07-21 04:32:33 +00:00
|
|
|
|
var img = SpriteUtil.GetRibbonSprite(name);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
pb.BackgroundImage = img;
|
2016-07-16 22:52:33 +00:00
|
|
|
|
|
2017-07-06 06:05:49 +00:00
|
|
|
|
var display = RibbonStrings.GetName(name);
|
|
|
|
|
pb.MouseEnter += (s, e) => tipName.SetToolTip(pb, display);
|
2016-07-16 22:52:33 +00:00
|
|
|
|
FLP_Ribbons.Controls.Add(pb);
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddRibbonChoice(RibbonInfo rib)
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
|
|
|
|
// Get row we add to
|
|
|
|
|
int row = TLP_Ribbons.RowCount;
|
|
|
|
|
TLP_Ribbons.RowCount++;
|
|
|
|
|
|
|
|
|
|
var label = new Label
|
|
|
|
|
{
|
|
|
|
|
Anchor = AnchorStyles.Left,
|
|
|
|
|
Name = PrefixLabel + rib.Name,
|
2017-06-23 04:56:41 +00:00
|
|
|
|
Text = RibbonStrings.GetName(rib.Name),
|
2016-07-16 22:52:33 +00:00
|
|
|
|
Padding = Padding.Empty,
|
2016-07-29 15:31:02 +00:00
|
|
|
|
Margin = Padding.Empty,
|
2016-07-16 22:52:33 +00:00
|
|
|
|
AutoSize = true,
|
|
|
|
|
};
|
|
|
|
|
TLP_Ribbons.Controls.Add(label, 1, row);
|
|
|
|
|
|
|
|
|
|
if (rib.RibbonCount >= 0) // numeric count ribbon
|
2017-06-18 01:37:19 +00:00
|
|
|
|
AddRibbonNumericUpDown(rib, row);
|
|
|
|
|
else // boolean ribbon
|
|
|
|
|
AddRibbonCheckBox(rib, row, label);
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddRibbonNumericUpDown(RibbonInfo rib, int row)
|
|
|
|
|
{
|
|
|
|
|
var nud = new NumericUpDown
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Anchor = AnchorStyles.Right,
|
|
|
|
|
Name = PrefixNUD + rib.Name,
|
|
|
|
|
Minimum = 0,
|
|
|
|
|
Width = 35,
|
|
|
|
|
Increment = 1,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
Margin = Padding.Empty,
|
2018-07-29 23:39:15 +00:00
|
|
|
|
Maximum = rib.MaxCount,
|
2017-06-18 01:37:19 +00:00
|
|
|
|
};
|
2016-07-16 22:52:33 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
nud.ValueChanged += (sender, e) =>
|
|
|
|
|
{
|
2018-07-29 23:39:15 +00:00
|
|
|
|
FLP_Ribbons.Controls[PrefixPB + rib.Name].Visible = (rib.RibbonCount = (int)nud.Value) > 0;
|
|
|
|
|
FLP_Ribbons.Controls[PrefixPB + rib.Name].BackgroundImage = SpriteUtil.GetRibbonSprite(rib.Name, (int)nud.Maximum, (int)nud.Value);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
};
|
|
|
|
|
nud.Value = rib.RibbonCount > nud.Maximum ? nud.Maximum : rib.RibbonCount;
|
|
|
|
|
TLP_Ribbons.Controls.Add(nud, 0, row);
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddRibbonCheckBox(RibbonInfo rib, int row, Control label)
|
|
|
|
|
{
|
|
|
|
|
var chk = new CheckBox
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
Anchor = AnchorStyles.Right,
|
|
|
|
|
Name = PrefixCHK + rib.Name,
|
|
|
|
|
AutoSize = true,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
|
};
|
|
|
|
|
chk.CheckedChanged += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
rib.HasRibbon = chk.Checked;
|
|
|
|
|
FLP_Ribbons.Controls[PrefixPB + rib.Name].Visible = rib.HasRibbon;
|
|
|
|
|
};
|
|
|
|
|
chk.Checked = rib.HasRibbon;
|
|
|
|
|
TLP_Ribbons.Controls.Add(chk, 0, row);
|
2016-07-29 15:31:02 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
label.Click += (s, e) => chk.Checked ^= true;
|
2016-07-16 22:52:33 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
private void Save()
|
2016-07-16 22:52:33 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var rib in riblist)
|
2021-06-03 19:04:19 +00:00
|
|
|
|
ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : rib.RibbonCount);
|
2021-02-10 21:34:49 +00:00
|
|
|
|
|
2021-11-23 00:14:10 +00:00
|
|
|
|
if (pkm is G8PKM pk8)
|
2021-02-10 21:34:49 +00:00
|
|
|
|
pk8.AffixedRibbon = (sbyte)WinFormsUtil.GetIndex(CB_Affixed);
|
2016-07-16 22:52:33 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
private void B_All_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
|
|
|
|
{
|
|
|
|
|
RibbonApplicator.RemoveAllValidRibbons(pkm);
|
|
|
|
|
RibbonApplicator.SetAllValidRibbons(pkm);
|
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = true;
|
|
|
|
|
foreach (var n in TLP_Ribbons.Controls.OfType<NumericUpDown>())
|
|
|
|
|
n.Value = n.Maximum;
|
|
|
|
|
}
|
2018-07-29 23:39:15 +00:00
|
|
|
|
|
2016-07-16 22:52:33 +00:00
|
|
|
|
private void B_None_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (ModifierKeys == Keys.Shift)
|
|
|
|
|
{
|
|
|
|
|
RibbonApplicator.RemoveAllValidRibbons(pkm);
|
2021-11-23 00:14:10 +00:00
|
|
|
|
if (pkm is G8PKM pk8)
|
2021-04-22 02:19:58 +00:00
|
|
|
|
pk8.AffixedRibbon = -1;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-22 02:19:58 +00:00
|
|
|
|
CB_Affixed.SelectedValue = -1;
|
2016-07-16 22:52:33 +00:00
|
|
|
|
foreach (var c in TLP_Ribbons.Controls.OfType<CheckBox>())
|
|
|
|
|
c.Checked = false;
|
|
|
|
|
foreach (var n in TLP_Ribbons.Controls.OfType<NumericUpDown>())
|
|
|
|
|
n.Value = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|