Get the basic replay fie to load when we hold the ctrl key and press the "file" menu item.

This commit is contained in:
Tim Young 2018-05-15 08:27:41 -05:00
parent dbc2ff139f
commit eab20232ca
3 changed files with 46 additions and 2 deletions

View File

@ -1372,6 +1372,43 @@ namespace EduNetworkBuilder
reader.Close();
}
}
/// <summary>
/// Reads an object instance from an XML resource.
/// <para>Object type must have a parameterless constructor.</para>
/// </summary>
/// <typeparam name="T">The type of object to read from the file.</typeparam>
/// <param name="filePath">The name of the resource to use.</param>
/// <returns>Returns a new instance of the object read from the XML resource.</returns>
public static T ReadFromXmlResource<T>(string resource) where T : new()
{
System.Reflection.Assembly MyAssembly;
BuilderWindow tWin = GetBuilderWin();
MyAssembly = tWin.GetType().Assembly;
// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new
System.Resources.ResourceManager("EduNetworkBuilder.Properties.Resources",
MyAssembly);
// Retrieves String and Image resources.
//System.String myString;
byte[] item = Encoding.UTF8.GetBytes((string)myManager.GetObject(resource));
// myString = new StreamReader(new MemoryStream(item), true).ReadToEnd(*/);
//myString = System.Text.Encoding.Default.GetString(item);
//TextReader reader = null;
try
{
var serializer = new XmlSerializer(typeof(T));
return (T)serializer.Deserialize(new MemoryStream(item));
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
return default(T);
}
#endregion
#region ActionFunctions

View File

@ -38,7 +38,7 @@ namespace EduNetworkBuilder
public string FormLastTransDir = "";
protected ActionCollection UserActions = new ActionCollection();
[XmlIgnore]
public bool ReplayMode = true; //Whether or not we are able to do replays
public bool ReplayMode = false; //Whether or not we are able to do replays
public NBSettings()
{
@ -96,7 +96,6 @@ namespace EduNetworkBuilder
if (!ToClass.RecentFiles.Contains(one))
ToClass.RecentFiles.Add(one);
}
}
public NBSettings(bool UsingMono)
@ -159,6 +158,12 @@ namespace EduNetworkBuilder
}
}
public void LoadReplays()
{
ReplayMode = true;
UserActions = NB.ReadFromXmlResource<ActionCollection>("EduNetworkReplay");
}
public bool CheckIfDone(string PuzzleName)
{
//we just mark it in the settings class

View File

@ -2856,6 +2856,8 @@ namespace EduNetworkBuilder
replayToolStripMenuItem.Visible = false;
storeReplayToolStripMenuItem.Visible = false;
saveReplayToolStripMenuItem.Visible = false;
if (OurSettings.ReplayMode == false && ModifierKeys == Keys.Control)
OurSettings.LoadReplays();
if (OurSettings != null && OurSettings.ReplayMode)
{