2018-03-23 06:04:04 +00:00
|
|
|
|
using System;
|
2019-03-24 02:05:35 +00:00
|
|
|
|
using System.IO;
|
2018-03-23 06:04:04 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class SettingsEditor : Form
|
|
|
|
|
{
|
2021-10-22 05:13:21 +00:00
|
|
|
|
public bool BlankChanged { get; private set; }
|
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
public SettingsEditor(object obj)
|
2018-03-23 06:04:04 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-04-12 01:09:54 +00:00
|
|
|
|
LoadSettings(obj);
|
2018-03-23 06:04:04 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (obj is PKHeXSettings s)
|
2019-01-05 23:42:20 +00:00
|
|
|
|
{
|
2019-01-15 00:25:54 +00:00
|
|
|
|
var noSelectVersions = new[] {GameVersion.GO};
|
2019-01-05 23:42:20 +00:00
|
|
|
|
CB_Blank.InitializeBinding();
|
2019-01-15 00:25:54 +00:00
|
|
|
|
CB_Blank.DataSource = GameInfo.VersionDataSource.Where(z => !noSelectVersions.Contains((GameVersion)z.Value)).ToList();
|
2021-04-12 01:09:54 +00:00
|
|
|
|
CB_Blank.SelectedValue = (int) s.Startup.DefaultSaveVersion;
|
|
|
|
|
CB_Blank.SelectedValueChanged += (_, __) => s.Startup.DefaultSaveVersion = (GameVersion)WinFormsUtil.GetIndex(CB_Blank);
|
2021-10-22 05:13:21 +00:00
|
|
|
|
CB_Blank.SelectedIndexChanged += (_, __) => BlankChanged = true;
|
2019-03-24 02:05:35 +00:00
|
|
|
|
B_Reset.Click += (x, e) => DeleteSettings();
|
2019-01-05 23:42:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FLP_Blank.Visible = false;
|
2019-03-24 02:05:35 +00:00
|
|
|
|
B_Reset.Visible = false;
|
2019-01-05 23:42:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 05:37:33 +00:00
|
|
|
|
this.CenterToForm(FindForm());
|
2018-03-23 06:04:04 +00:00
|
|
|
|
}
|
2019-01-05 23:42:20 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
private void LoadSettings(object obj)
|
2018-03-23 06:04:04 +00:00
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var type = obj.GetType();
|
2019-01-28 05:57:26 +00:00
|
|
|
|
var props = ReflectUtil.GetPropertiesCanWritePublicDeclared(type);
|
2018-03-23 06:04:04 +00:00
|
|
|
|
foreach (var p in props)
|
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var state = ReflectUtil.GetValue(obj, p);
|
|
|
|
|
if (state is null)
|
|
|
|
|
continue;
|
2019-01-05 23:42:20 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var tab = new TabPage(p);
|
|
|
|
|
var pg = new PropertyGrid { SelectedObject = state, Dock = DockStyle.Fill };
|
|
|
|
|
tab.Controls.Add(pg);
|
|
|
|
|
tabControl1.TabPages.Add(tab);
|
|
|
|
|
}
|
2018-03-23 06:04:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 23:08:14 +00:00
|
|
|
|
private void SettingsEditor_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.W && ModifierKeys == Keys.Control)
|
|
|
|
|
Close();
|
|
|
|
|
}
|
2019-03-24 02:05:35 +00:00
|
|
|
|
|
|
|
|
|
private static void DeleteSettings()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Resetting settings requires the program to exit.", MessageStrings.MsgContinue);
|
|
|
|
|
if (dr != DialogResult.Yes)
|
|
|
|
|
return;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var path = Main.ConfigPath;
|
2019-03-24 02:05:35 +00:00
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
File.Delete(path);
|
2020-07-25 16:51:56 +00:00
|
|
|
|
System.Diagnostics.Process.Start(Application.ExecutablePath);
|
2019-03-24 02:05:35 +00:00
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Error("Failed to delete settings.", ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-23 06:04:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|