diff --git a/pkNX.Randomization/Randomizers/Personal/PersonalRandSettings.cs b/pkNX.Randomization/Randomizers/Personal/PersonalRandSettings.cs
index e6fef48c..973441ea 100644
--- a/pkNX.Randomization/Randomizers/Personal/PersonalRandSettings.cs
+++ b/pkNX.Randomization/Randomizers/Personal/PersonalRandSettings.cs
@@ -1,4 +1,5 @@
-using System.ComponentModel;
+using System;
+using System.ComponentModel;
using pkNX.Structures;
namespace pkNX.Randomization
@@ -6,6 +7,7 @@ namespace pkNX.Randomization
///
/// Randomization settings when randomizing a .
///
+ [Serializable]
public class PersonalRandSettings : RandSettings
{
private const string Moves = nameof(Moves);
diff --git a/pkNX.Randomization/Randomizers/Settings/LearnSettings.cs b/pkNX.Randomization/Randomizers/Settings/LearnSettings.cs
index 00d263b1..3b828fc3 100644
--- a/pkNX.Randomization/Randomizers/Settings/LearnSettings.cs
+++ b/pkNX.Randomization/Randomizers/Settings/LearnSettings.cs
@@ -1,7 +1,9 @@
+using System;
using System.ComponentModel;
namespace pkNX.Randomization
{
+ [Serializable]
public class LearnSettings
{
private const string General = nameof(General);
@@ -9,11 +11,13 @@ public class LearnSettings
[Category(General), Description("Expands the learnset to the specified count.")]
public bool Expand { get; set; } = true;
+
[Category(General), Description("Count to expand the learnset to.")]
public int ExpandTo { get; set; } = 25;
[Category(General), Description("Evenly spreads learned moves out from level 1 to the specified end level.")]
public bool Spread { get; set; } = true;
+
[Category(General), Description("Level to end learning level up moves.")]
public int SpreadTo { get; set; } = 75;
diff --git a/pkNX.Randomization/Randomizers/Settings/MovesetRandSettings.cs b/pkNX.Randomization/Randomizers/Settings/MovesetRandSettings.cs
index 1e6115a5..a2ef55ad 100644
--- a/pkNX.Randomization/Randomizers/Settings/MovesetRandSettings.cs
+++ b/pkNX.Randomization/Randomizers/Settings/MovesetRandSettings.cs
@@ -4,6 +4,7 @@
namespace pkNX.Randomization
{
+ [Serializable]
public class MovesetRandSettings
{
private const string Damage = nameof(Damage);
diff --git a/pkNX.Randomization/Randomizers/Settings/SpeciesSettings.cs b/pkNX.Randomization/Randomizers/Settings/SpeciesSettings.cs
index 4caf9b5d..c9cc47f1 100644
--- a/pkNX.Randomization/Randomizers/Settings/SpeciesSettings.cs
+++ b/pkNX.Randomization/Randomizers/Settings/SpeciesSettings.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using pkNX.Structures;
@@ -8,6 +9,7 @@ namespace pkNX.Randomization
///
/// Settings for what Species are permitted during randomization.
///
+ [Serializable]
public class SpeciesSettings : RandSettings
{
private const string General = nameof(General);
diff --git a/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs b/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs
index 56643063..9de4c006 100644
--- a/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs
+++ b/pkNX.Randomization/Randomizers/Settings/TrainerRandSettings.cs
@@ -1,7 +1,9 @@
+using System;
using System.ComponentModel;
namespace pkNX.Randomization
{
+ [Serializable]
public class TrainerRandSettings
{
private const string General = nameof(General);
diff --git a/pkNX.WinForms/Main.cs b/pkNX.WinForms/Main.cs
index b2826ed9..e36fcb27 100644
--- a/pkNX.WinForms/Main.cs
+++ b/pkNX.WinForms/Main.cs
@@ -67,6 +67,7 @@ private void Main_FormClosing(object sender, FormClosingEventArgs e)
return;
Editor.Close();
+ EditUtil.SaveSettings(Editor.Game);
Settings.Default.Language = CB_Lang.SelectedIndex;
Settings.Default.GamePath = TB_Path.Text;
Settings.Default.Save();
@@ -133,6 +134,8 @@ private void LoadROM(EditorBase editor)
Text = $"{nameof(pkNX)} - {Editor.Game}";
TB_Path.Text = Editor.Location;
+ EditUtil.LoadSettings(Editor.Game);
+ EditUtil.SaveSettings(Editor.Game);
System.Media.SystemSounds.Asterisk.Play();
}
}
diff --git a/pkNX.WinForms/MainEditor/EditUtil.cs b/pkNX.WinForms/MainEditor/EditUtil.cs
index 11381d09..659f9d6a 100644
--- a/pkNX.WinForms/MainEditor/EditUtil.cs
+++ b/pkNX.WinForms/MainEditor/EditUtil.cs
@@ -1,13 +1,75 @@
-using pkNX.Randomization;
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Windows.Forms;
+using System.Xml.Serialization;
+using pkNX.Randomization;
+using pkNX.Structures;
namespace pkNX.WinForms
{
+ [Serializable]
+ public class SharedSettings
+ {
+ public PersonalRandSettings Personal { get; set; } = new PersonalRandSettings();
+ public SpeciesSettings Species { get; set; } = new SpeciesSettings();
+ public TrainerRandSettings Trainer { get; set; } = new TrainerRandSettings();
+ public MovesetRandSettings Move { get; set; } = new MovesetRandSettings();
+ public LearnSettings Learn { get; set; } = new LearnSettings();
+ }
+
public static class EditUtil
{
- public static PersonalRandSettings Personal { get; set; } = new PersonalRandSettings();
- public static SpeciesSettings Species { get; set; } = new SpeciesSettings();
- public static TrainerRandSettings Trainer { get; set; } = new TrainerRandSettings();
- public static MovesetRandSettings Move { get; set; } = new MovesetRandSettings();
- public static LearnSettings Learn { get; set; } = new LearnSettings();
+ public static SharedSettings Settings { get; set; }
+
+ public static void LoadSettings(GameVersion game)
+ {
+ string path = GetSettingsFileName(game);
+ if (!File.Exists(path))
+ {
+ Settings = new SharedSettings();
+ return;
+ }
+
+ using (var file = File.OpenRead(path))
+ {
+ var reader = new XmlSerializer(typeof(SharedSettings));
+ try
+ {
+ Settings = (SharedSettings) reader.Deserialize(file);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine(e.Message);
+ }
+ }
+ }
+
+ public static void SaveSettings(GameVersion game)
+ {
+ string path = GetSettingsFileName(game);
+ using (var file = File.Create(path))
+ {
+ var writer = new XmlSerializer(typeof(SharedSettings));
+ try
+ {
+ writer.Serialize(file, Settings);
+ }
+ catch (Exception e)
+ {
+ Debug.WriteLine(e.Message);
+ if (!File.Exists(path))
+ return;
+ file.Close();
+ File.Delete(path);
+ }
+ }
+ }
+
+ private static string GetSettingsFileName(GameVersion game)
+ {
+ var path = Path.GetDirectoryName(Application.ExecutablePath);
+ return Path.Combine(path, $"randsetting{game}.xml");
+ }
}
}
diff --git a/pkNX.WinForms/Subforms/BTTE.cs b/pkNX.WinForms/Subforms/BTTE.cs
index a7a95ba7..f01ef61e 100644
--- a/pkNX.WinForms/Subforms/BTTE.cs
+++ b/pkNX.WinForms/Subforms/BTTE.cs
@@ -67,9 +67,9 @@ public BTTE(GameManager game, TrainerEditor editor)
CB_TrainerID.SelectedIndex = 0;
- PG_Moves.SelectedObject = EditUtil.Move;
- PG_RTrainer.SelectedObject = EditUtil.Trainer;
- PG_Species.SelectedObject = EditUtil.Species;
+ PG_Moves.SelectedObject = EditUtil.Settings.Move;
+ PG_RTrainer.SelectedObject = EditUtil.Settings.Trainer;
+ PG_Species.SelectedObject = EditUtil.Settings.Species;
}
public bool Modified { get; set; }
diff --git a/pkNX.WinForms/Subforms/GGWE.cs b/pkNX.WinForms/Subforms/GGWE.cs
index 507dbe06..e95c1695 100644
--- a/pkNX.WinForms/Subforms/GGWE.cs
+++ b/pkNX.WinForms/Subforms/GGWE.cs
@@ -40,7 +40,7 @@ public GGWE(GameManager rom, string json)
EL_Old.OverworldSpawn = EL_Good.OverworldSpawn = EL_Super.OverworldSpawn = false;
L_Rank.Visible = NUD_RankMin.Visible = NUD_RankMax.Visible = false;
- PG_Species.SelectedObject = EditUtil.Species;
+ PG_Species.SelectedObject = EditUtil.Settings.Species;
Tables = obj;
LoadFile(locs);
@@ -334,6 +334,7 @@ private void B_RandAll_Click(object sender, EventArgs e)
{
SaveEntry(entry);
var settings = (SpeciesSettings)PG_Species.SelectedObject;
+ settings.Gen2 = settings.Gen3 = settings.Gen4 = settings.Gen5 = settings.Gen6 = settings.Gen7 = false;
var rand = new SpeciesRandomizer(ROM.Info, ROM.Data.PersonalData);
rand.Initialize(settings);
RandomizeWild(rand, CHK_FillEmpty.Checked, CHK_WildMega.Checked);
diff --git a/pkNX.WinForms/Subforms/PokeDataUI.cs b/pkNX.WinForms/Subforms/PokeDataUI.cs
index 9cc5b87a..ffb178d4 100644
--- a/pkNX.WinForms/Subforms/PokeDataUI.cs
+++ b/pkNX.WinForms/Subforms/PokeDataUI.cs
@@ -50,9 +50,9 @@ public PokeDataUI(PokeEditor editor, GameManager rom)
CB_Species.SelectedIndex = 1;
- PG_Personal.SelectedObject = EditUtil.Personal;
- PG_Evolution.SelectedObject = EditUtil.Species;
- PG_Learn.SelectedObject = EditUtil.Learn;
+ PG_Personal.SelectedObject = EditUtil.Settings.Personal;
+ PG_Evolution.SelectedObject = EditUtil.Settings.Species;
+ PG_Learn.SelectedObject = EditUtil.Settings.Learn;
}
public GameManager ROM { get; set; }
@@ -474,7 +474,7 @@ private void B_RandLearn_Click(object sender, EventArgs e)
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
var moves = ROM.Data.MoveData.LoadAll();
int[] banned = Legal.GetBannedMoves(ROM.Info.Game, moves);
- rand.Initialize(moves, settings, EditUtil.Move, banned);
+ rand.Initialize(moves, settings, EditUtil.Settings.Move, banned);
rand.Execute();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();
@@ -490,7 +490,7 @@ private void B_LearnExpand_Click(object sender, EventArgs e)
return;
}
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
- rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Move);
+ rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Settings.Move);
rand.ExecuteExpandOnly();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();
@@ -500,7 +500,7 @@ private void B_LearnMetronome_Click(object sender, EventArgs e)
{
var settings = (LearnSettings)PG_Learn.SelectedObject;
var rand = new LearnsetRandomizer(ROM.Info, Editor.Learn.LoadAll(), Editor.Personal);
- rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Move);
+ rand.Initialize(ROM.Data.MoveData.LoadAll(), settings, EditUtil.Settings.Move);
rand.ExecuteMetronome();
LoadIndex(CB_Species.SelectedIndex);
System.Media.SystemSounds.Asterisk.Play();