2016-06-20 04:22:43 +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;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-04-11 00:00:28 +00:00
|
|
|
|
public sealed partial class SAV_EventFlags : Form
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
private readonly EventWorkspace Editor;
|
|
|
|
|
private readonly Dictionary<int, NumericUpDown> WorkDict = new();
|
|
|
|
|
private readonly Dictionary<int, CheckBox> FlagDict = new();
|
|
|
|
|
|
2021-05-29 22:31:47 +00:00
|
|
|
|
private bool editing;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public SAV_EventFlags(SaveFile sav)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-04-03 03:36:13 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var editor = Editor = new EventWorkspace(sav);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DragEnter += Main_DragEnter;
|
|
|
|
|
DragDrop += Main_DragDrop;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2021-05-29 22:31:47 +00:00
|
|
|
|
editing = true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
CB_Stats.Items.Clear();
|
2021-04-06 03:52:49 +00:00
|
|
|
|
for (int i = 0; i < editor.Values.Length; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
CB_Stats.Items.Add(i.ToString());
|
|
|
|
|
|
2016-07-24 22:04:04 +00:00
|
|
|
|
TLP_Flags.SuspendLayout();
|
|
|
|
|
TLP_Const.SuspendLayout();
|
2017-01-08 07:54:09 +00:00
|
|
|
|
TLP_Flags.Scroll += WinFormsUtil.PanelScroll;
|
|
|
|
|
TLP_Const.Scroll += WinFormsUtil.PanelScroll;
|
2016-07-31 03:57:45 +00:00
|
|
|
|
TLP_Flags.Controls.Clear();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
TLP_Const.Controls.Clear();
|
2021-04-06 03:52:49 +00:00
|
|
|
|
AddFlagList(editor.Labels, editor.Flags);
|
|
|
|
|
AddConstList(editor.Labels, editor.Values);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2016-07-24 22:04:04 +00:00
|
|
|
|
TLP_Flags.ResumeLayout();
|
|
|
|
|
TLP_Const.ResumeLayout();
|
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
Text = $"{Text} ({sav.Version})";
|
2016-11-14 13:31:33 +00:00
|
|
|
|
|
2017-09-24 05:13:48 +00:00
|
|
|
|
if (CB_Stats.Items.Count > 0)
|
2018-08-04 17:06:06 +00:00
|
|
|
|
{
|
2017-09-24 05:13:48 +00:00
|
|
|
|
CB_Stats.SelectedIndex = 0;
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
2017-09-24 05:13:48 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
L_Stats.Visible = CB_Stats.Visible = MT_Stat.Visible = false;
|
|
|
|
|
tabControl1.TabPages.Remove(GB_Constants);
|
|
|
|
|
}
|
2021-04-06 03:52:49 +00:00
|
|
|
|
NUD_Flag.Maximum = editor.Flags.Length - 1;
|
|
|
|
|
NUD_Flag.Value = 0;
|
|
|
|
|
c_CustomFlag.Checked = editor.Flags[0];
|
|
|
|
|
editing = false;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void B_Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
private void B_Save_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
Editor.Save();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
private void AddFlagList(EventLabelCollection list, bool[] values)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var labels = list.Flag;
|
|
|
|
|
if (labels.Count == 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
TLP_Flags.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Flags_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 18:25:14 +00:00
|
|
|
|
var hide = Main.Settings.Advanced.HideEventTypeBelow;
|
|
|
|
|
labels = labels.OrderByDescending(z => z.Type).ToList();
|
2021-04-06 03:52:49 +00:00
|
|
|
|
for (int i = 0; i < labels.Count; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-10-23 18:25:14 +00:00
|
|
|
|
var (name, index, type) = labels[i];
|
|
|
|
|
if (type < hide)
|
|
|
|
|
break;
|
|
|
|
|
|
2021-05-18 20:29:55 +00:00
|
|
|
|
var lbl = new Label { Text = name, Margin = Padding.Empty, AutoSize = true };
|
2016-06-20 04:22:43 +00:00
|
|
|
|
var chk = new CheckBox
|
|
|
|
|
{
|
|
|
|
|
CheckAlign = ContentAlignment.MiddleLeft,
|
|
|
|
|
Margin = Padding.Empty,
|
2021-05-18 20:29:55 +00:00
|
|
|
|
Checked = values[index],
|
2021-08-20 20:49:20 +00:00
|
|
|
|
AutoSize = true,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
};
|
2017-07-06 06:05:49 +00:00
|
|
|
|
lbl.Click += (sender, e) => chk.Checked ^= true;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
chk.CheckedChanged += (o, args) =>
|
|
|
|
|
{
|
2021-05-18 20:29:55 +00:00
|
|
|
|
values[index] = chk.Checked;
|
|
|
|
|
if (NUD_Flag.Value == index)
|
2021-04-06 03:52:49 +00:00
|
|
|
|
c_CustomFlag.Checked = chk.Checked;
|
|
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
TLP_Flags.Controls.Add(chk, 0, i);
|
|
|
|
|
TLP_Flags.Controls.Add(lbl, 1, i);
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2021-05-18 20:29:55 +00:00
|
|
|
|
FlagDict.Add(index, chk);
|
2021-04-06 03:52:49 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
private void AddConstList(EventLabelCollection list, ushort[] values)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var labels = list.Work;
|
|
|
|
|
if (labels.Count == 0)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2018-04-07 04:23:09 +00:00
|
|
|
|
TLP_Const.Controls.Add(new Label { Text = MsgResearchRequired, Name = "TLP_Const_Research", ForeColor = Color.Red, AutoSize = true }, 0, 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-23 18:25:14 +00:00
|
|
|
|
var hide = Main.Settings.Advanced.HideEventTypeBelow;
|
|
|
|
|
labels = labels.OrderByDescending(z => z.Type).ToList();
|
2021-04-06 03:52:49 +00:00
|
|
|
|
for (var i = 0; i < labels.Count; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var entry = labels[i];
|
2021-10-23 18:25:14 +00:00
|
|
|
|
if (entry.Type < hide)
|
|
|
|
|
break;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var lbl = new Label { Text = entry.Name, Margin = Padding.Empty, AutoSize = true };
|
2016-06-20 04:22:43 +00:00
|
|
|
|
var mtb = new NumericUpDown
|
|
|
|
|
{
|
2016-08-25 00:46:24 +00:00
|
|
|
|
Maximum = ushort.MaxValue,
|
|
|
|
|
Minimum = ushort.MinValue,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Margin = Padding.Empty,
|
2016-11-14 13:31:33 +00:00
|
|
|
|
Width = 50,
|
2016-06-20 04:22:43 +00:00
|
|
|
|
};
|
2016-11-14 13:31:33 +00:00
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var map = entry.PredefinedValues.Select(z => new ComboItem(z.Name, z.Value)).ToList();
|
2016-12-30 00:24:01 +00:00
|
|
|
|
var cb = new ComboBox
|
2016-11-14 13:31:33 +00:00
|
|
|
|
{
|
|
|
|
|
Margin = Padding.Empty,
|
2017-07-09 21:54:10 +00:00
|
|
|
|
Width = 150,
|
2016-11-14 13:31:33 +00:00
|
|
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
2019-02-19 22:19:09 +00:00
|
|
|
|
BindingContext = BindingContext,
|
2021-08-20 20:49:20 +00:00
|
|
|
|
DropDownWidth = Width + 100,
|
2016-11-14 13:31:33 +00:00
|
|
|
|
};
|
2019-02-12 06:04:47 +00:00
|
|
|
|
cb.InitializeBinding();
|
|
|
|
|
cb.DataSource = map;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
|
|
|
|
|
lbl.Click += (sender, e) => mtb.Value = 0;
|
|
|
|
|
bool updating = false;
|
2021-08-08 19:08:14 +00:00
|
|
|
|
mtb.ValueChanged += ChangeConstValue;
|
2021-08-13 22:37:21 +00:00
|
|
|
|
void ChangeConstValue(object? sender, EventArgs e)
|
2021-04-06 03:52:49 +00:00
|
|
|
|
{
|
|
|
|
|
if (updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
updating = true;
|
|
|
|
|
var value = (ushort) mtb.Value;
|
2021-05-18 20:29:55 +00:00
|
|
|
|
var (_, valueID) = map.Find(z => z.Value == value) ?? map[0];
|
|
|
|
|
if (WinFormsUtil.GetIndex(cb) != valueID)
|
|
|
|
|
cb.SelectedValue = valueID;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
|
|
|
|
|
Editor.Values[entry.Index] = value;
|
|
|
|
|
if (CB_Stats.SelectedIndex == entry.Index)
|
2021-05-18 20:29:55 +00:00
|
|
|
|
MT_Stat.Text = ((int)mtb.Value).ToString();
|
2021-04-06 03:52:49 +00:00
|
|
|
|
updating = false;
|
2021-08-08 19:08:14 +00:00
|
|
|
|
}
|
2021-04-06 03:52:49 +00:00
|
|
|
|
cb.SelectedValueChanged += (o, args) =>
|
|
|
|
|
{
|
|
|
|
|
if (editing || updating)
|
|
|
|
|
return;
|
|
|
|
|
var value = WinFormsUtil.GetIndex(cb);
|
2021-08-08 19:08:14 +00:00
|
|
|
|
mtb.Value = value == NamedEventConst.CustomMagicValue ? 0 : value;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mtb.Value = values[entry.Index];
|
2021-08-08 19:08:14 +00:00
|
|
|
|
if (mtb.Value == 0)
|
|
|
|
|
ChangeConstValue(this, EventArgs.Empty);
|
2021-04-06 03:52:49 +00:00
|
|
|
|
|
2016-11-14 13:31:33 +00:00
|
|
|
|
TLP_Const.Controls.Add(lbl, 0, i);
|
|
|
|
|
TLP_Const.Controls.Add(cb, 1, i);
|
|
|
|
|
TLP_Const.Controls.Add(mtb, 2, i);
|
2020-08-30 22:48:11 +00:00
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
WorkDict.Add(entry.Index, mtb);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomBool(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
editing = true;
|
2021-04-08 05:46:28 +00:00
|
|
|
|
var index = (int) NUD_Flag.Value;
|
|
|
|
|
Editor.Flags[index] = c_CustomFlag.Checked;
|
|
|
|
|
if (FlagDict.TryGetValue(index, out var chk))
|
2021-04-06 03:52:49 +00:00
|
|
|
|
chk.Checked = c_CustomFlag.Checked;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomFlag(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-12-30 00:24:01 +00:00
|
|
|
|
int flag = (int)NUD_Flag.Value;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
c_CustomFlag.Checked = Editor.Flags[flag];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private void ChangeCustomFlag(object sender, KeyEventArgs e) => ChangeCustomFlag(sender, (EventArgs)e);
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2021-04-06 03:52:49 +00:00
|
|
|
|
private void ChangeConstantIndex(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var constants = Editor.Values;
|
|
|
|
|
var index = CB_Stats.SelectedIndex;
|
|
|
|
|
MT_Stat.Text = constants[index].ToString();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeCustomConst(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (editing)
|
|
|
|
|
return;
|
|
|
|
|
editing = true;
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var index = CB_Stats.SelectedIndex;
|
|
|
|
|
var parse = ushort.TryParse(MT_Stat.Text, out var value) ? value : (ushort)0;
|
|
|
|
|
Editor.Values[index] = parse;
|
|
|
|
|
if (WorkDict.TryGetValue(index, out var mtb))
|
|
|
|
|
mtb.Value = parse;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
editing = false;
|
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ChangeSAV(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (TB_NewSAV.Text.Length > 0 && TB_OldSAV.Text.Length > 0)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
DiffSaves();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void OpenSAV(object sender, EventArgs e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var ofd = new OpenFileDialog();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
LoadSAV(sender, ofd.FileName);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void LoadSAV(object sender, string path)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-04-06 03:52:49 +00:00
|
|
|
|
var dest = sender == B_LoadOld ? TB_OldSAV : TB_NewSAV;
|
|
|
|
|
dest.Text = path;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void DiffSaves()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-19 01:10:48 +00:00
|
|
|
|
var diff = new EventBlockDiff(TB_OldSAV.Text, TB_NewSAV.Text);
|
2019-06-25 03:50:21 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(diff.Message))
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-19 01:10:48 +00:00
|
|
|
|
WinFormsUtil.Alert(diff.Message);
|
|
|
|
|
return;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 01:10:48 +00:00
|
|
|
|
TB_IsSet.Text = string.Join(", ", diff.SetFlags.Select(z => $"{z:0000}"));
|
|
|
|
|
TB_UnSet.Text = string.Join(", ", diff.ClearedFlags.Select(z => $"{z:0000}"));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-06-19 01:10:48 +00:00
|
|
|
|
if (diff.WorkDiff.Count == 0)
|
2017-03-09 07:31:22 +00:00
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert("No Event Constant diff found.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 22:37:21 +00:00
|
|
|
|
var promptCopy = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?");
|
|
|
|
|
if (promptCopy == DialogResult.Yes)
|
2019-11-23 05:23:00 +00:00
|
|
|
|
WinFormsUtil.SetClipboardText(string.Join(Environment.NewLine, diff.WorkDiff));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private static void Main_DragEnter(object? sender, DragEventArgs? e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data is null)
|
|
|
|
|
return;
|
2018-09-29 19:22:13 +00:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-08-04 17:06:06 +00:00
|
|
|
|
|
2021-12-05 06:29:51 +00:00
|
|
|
|
private void Main_DragDrop(object? sender, DragEventArgs? e)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2021-12-05 06:29:51 +00:00
|
|
|
|
if (e?.Data?.GetData(DataFormats.FileDrop) is not string[] { Length: not 0 } files)
|
|
|
|
|
return;
|
2018-09-29 19:22:13 +00:00
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, Name, "Yes: Old Save" + Environment.NewLine + "No: New Save");
|
|
|
|
|
var button = dr == DialogResult.Yes ? B_LoadOld : B_LoadNew;
|
|
|
|
|
LoadSAV(button, files[0]);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-06 03:52:49 +00:00
|
|
|
|
}
|