Get replay working from dropdown menu. (right now everyone has the replay button. We will hide it for most cases later on)
This commit is contained in:
parent
d5a04c9d77
commit
e7856a9d3e
@ -13,8 +13,11 @@ namespace EduNetworkBuilder
|
|||||||
public List<NetworkAction> NetActions = new List<NetworkAction>();
|
public List<NetworkAction> NetActions = new List<NetworkAction>();
|
||||||
NetworkAction CurrentNetAction = null;
|
NetworkAction CurrentNetAction = null;
|
||||||
|
|
||||||
|
public Network GetNet { get { return StartingState; } }
|
||||||
|
|
||||||
public void RegisterNet(Network starting)
|
public void RegisterNet(Network starting)
|
||||||
{
|
{
|
||||||
|
StartingState = Network.DeepClone(starting);
|
||||||
CurrentNetAction = new NetworkAction(starting);
|
CurrentNetAction = new NetworkAction(starting);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +32,17 @@ namespace EduNetworkBuilder
|
|||||||
CurrentNetAction.Add(What);
|
CurrentNetAction.Add(What);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RunAction(int WhichIndex)
|
||||||
|
{
|
||||||
|
if (CurrentNetAction == null) return false;
|
||||||
|
if (WhichIndex < CurrentNetAction.Actions.Count)
|
||||||
|
{
|
||||||
|
CurrentNetAction.Actions[WhichIndex].DoAction();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Take the current actionlist and save it to the stored actionlists.
|
/// Take the current actionlist and save it to the stored actionlists.
|
||||||
/// We use this when we have successfully solved a network and want to store
|
/// We use this when we have successfully solved a network and want to store
|
||||||
|
@ -380,6 +380,8 @@ namespace EduNetworkBuilder
|
|||||||
|
|
||||||
public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,.";
|
public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,.";
|
||||||
public static string AllowedUsernameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._";
|
public static string AllowedUsernameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890._";
|
||||||
|
|
||||||
|
public static int MillisecondsBetweenReplays = 500;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Find the global random number generator.
|
/// Find the global random number generator.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -496,6 +498,9 @@ namespace EduNetworkBuilder
|
|||||||
myWin.UnregisterInvisibleNet();
|
myWin.UnregisterInvisibleNet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure we update the visuals when we have the opportunity to do so
|
||||||
|
/// </summary>
|
||||||
public static void MarkToUpdate()
|
public static void MarkToUpdate()
|
||||||
{
|
{
|
||||||
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
||||||
|
@ -81,6 +81,10 @@ namespace EduNetworkBuilder
|
|||||||
|
|
||||||
private List<AnimationClass> Animations = new List<AnimationClass>();
|
private List<AnimationClass> Animations = new List<AnimationClass>();
|
||||||
|
|
||||||
|
public bool ReplayInProgress = false;
|
||||||
|
public DateTime NextReplayAction = DateTime.UtcNow;
|
||||||
|
public int NextReplayIndex = -1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WhatFrom: If we are launched from a homework, we remember it here.
|
/// WhatFrom: If we are launched from a homework, we remember it here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -1642,6 +1646,28 @@ namespace EduNetworkBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(ReplayInProgress && myPackets.Count == 0)
|
||||||
|
{
|
||||||
|
if(DateTime.UtcNow >= NextReplayAction)
|
||||||
|
{
|
||||||
|
//We are doing a replay and enough time has passed from the last replay...
|
||||||
|
NBSettings Settings = NB.GetSettings();
|
||||||
|
ActionCollection AC = Settings.GetUserActionCollection();
|
||||||
|
bool Success = AC.RunAction(NextReplayIndex++);
|
||||||
|
|
||||||
|
NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays);
|
||||||
|
if(Success)
|
||||||
|
{
|
||||||
|
//we did something. keep replaying
|
||||||
|
NB.MarkToUpdate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//replay finished
|
||||||
|
ReplayInProgress = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//if (myPackets.Count > 50)
|
//if (myPackets.Count > 50)
|
||||||
//Console.WriteLine("Packets: " + myPackets.Count.ToString());
|
//Console.WriteLine("Packets: " + myPackets.Count.ToString());
|
||||||
if (myPackets.Count > 0)
|
if (myPackets.Count > 0)
|
||||||
|
24
EduNetworkBuilder/NetworkBuilder.Designer.cs
generated
24
EduNetworkBuilder/NetworkBuilder.Designer.cs
generated
@ -78,6 +78,7 @@
|
|||||||
this.myProgressBar = new System.Windows.Forms.ProgressBar();
|
this.myProgressBar = new System.Windows.Forms.ProgressBar();
|
||||||
this.cbLineColor = new System.Windows.Forms.ComboBox();
|
this.cbLineColor = new System.Windows.Forms.ComboBox();
|
||||||
this.cbFillColor = new System.Windows.Forms.ComboBox();
|
this.cbFillColor = new System.Windows.Forms.ComboBox();
|
||||||
|
this.replayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.msMainMenuStrip.SuspendLayout();
|
this.msMainMenuStrip.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pbNetworkView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pbNetworkView)).BeginInit();
|
||||||
this.HelpPanel.SuspendLayout();
|
this.HelpPanel.SuspendLayout();
|
||||||
@ -107,7 +108,8 @@
|
|||||||
this.reloadToolStripMenuItem,
|
this.reloadToolStripMenuItem,
|
||||||
this.saveToolStripMenuItem,
|
this.saveToolStripMenuItem,
|
||||||
this.logoutToolStripMenuItem,
|
this.logoutToolStripMenuItem,
|
||||||
this.exitToolStripMenuItem});
|
this.exitToolStripMenuItem,
|
||||||
|
this.replayToolStripMenuItem});
|
||||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(44, 24);
|
this.fileToolStripMenuItem.Size = new System.Drawing.Size(44, 24);
|
||||||
this.fileToolStripMenuItem.Text = "File";
|
this.fileToolStripMenuItem.Text = "File";
|
||||||
@ -115,42 +117,42 @@
|
|||||||
// newToolStripMenuItem
|
// newToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
|
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
|
||||||
this.newToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.newToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.newToolStripMenuItem.Text = "New";
|
this.newToolStripMenuItem.Text = "New";
|
||||||
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
|
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// loadToolStripMenuItem
|
// loadToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.loadToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.loadToolStripMenuItem.Text = "Load";
|
this.loadToolStripMenuItem.Text = "Load";
|
||||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// reloadToolStripMenuItem
|
// reloadToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.reloadToolStripMenuItem.Name = "reloadToolStripMenuItem";
|
this.reloadToolStripMenuItem.Name = "reloadToolStripMenuItem";
|
||||||
this.reloadToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.reloadToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.reloadToolStripMenuItem.Text = "Reload";
|
this.reloadToolStripMenuItem.Text = "Reload";
|
||||||
this.reloadToolStripMenuItem.Click += new System.EventHandler(this.reloadToolStripMenuItem_Click);
|
this.reloadToolStripMenuItem.Click += new System.EventHandler(this.reloadToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// saveToolStripMenuItem
|
// saveToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.saveToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.saveToolStripMenuItem.Text = "Save";
|
this.saveToolStripMenuItem.Text = "Save";
|
||||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// logoutToolStripMenuItem
|
// logoutToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.logoutToolStripMenuItem.Name = "logoutToolStripMenuItem";
|
this.logoutToolStripMenuItem.Name = "logoutToolStripMenuItem";
|
||||||
this.logoutToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.logoutToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.logoutToolStripMenuItem.Text = "Logout";
|
this.logoutToolStripMenuItem.Text = "Logout";
|
||||||
this.logoutToolStripMenuItem.Click += new System.EventHandler(this.logoutToolStripMenuItem_Click);
|
this.logoutToolStripMenuItem.Click += new System.EventHandler(this.logoutToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// exitToolStripMenuItem
|
// exitToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(131, 26);
|
this.exitToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
this.exitToolStripMenuItem.Text = "Exit";
|
this.exitToolStripMenuItem.Text = "Exit";
|
||||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
@ -533,6 +535,13 @@
|
|||||||
this.cbFillColor.Size = new System.Drawing.Size(80, 24);
|
this.cbFillColor.Size = new System.Drawing.Size(80, 24);
|
||||||
this.cbFillColor.TabIndex = 13;
|
this.cbFillColor.TabIndex = 13;
|
||||||
//
|
//
|
||||||
|
// replayToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.replayToolStripMenuItem.Name = "replayToolStripMenuItem";
|
||||||
|
this.replayToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
|
||||||
|
this.replayToolStripMenuItem.Text = "Replay";
|
||||||
|
this.replayToolStripMenuItem.Click += new System.EventHandler(this.replayToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// BuilderWindow
|
// BuilderWindow
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||||
@ -620,6 +629,7 @@
|
|||||||
private System.Windows.Forms.Button btnCaptions;
|
private System.Windows.Forms.Button btnCaptions;
|
||||||
private System.Windows.Forms.ComboBox cbLineColor;
|
private System.Windows.Forms.ComboBox cbLineColor;
|
||||||
private System.Windows.Forms.ComboBox cbFillColor;
|
private System.Windows.Forms.ComboBox cbFillColor;
|
||||||
|
private System.Windows.Forms.ToolStripMenuItem replayToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ namespace EduNetworkBuilder
|
|||||||
UpdateVisuals();
|
UpdateVisuals();
|
||||||
NeedsUpdate = false;
|
NeedsUpdate = false;
|
||||||
}
|
}
|
||||||
myNetwork.Tick();
|
myNetwork.Tick(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LanguagifyComponents()
|
private void LanguagifyComponents()
|
||||||
@ -1419,7 +1419,8 @@ namespace EduNetworkBuilder
|
|||||||
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping"),true);
|
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping"),true);
|
||||||
if(todo)
|
if(todo)
|
||||||
{
|
{
|
||||||
ItemClickedOn.PingFromHere(destination);
|
//ItemClickedOn.PingFromHere(destination);
|
||||||
|
NB.DoActionPingDevice(ItemClickedOn.GetUniqueIdentifier, destination);
|
||||||
myNetwork.ProcessPackets();
|
myNetwork.ProcessPackets();
|
||||||
UpdateMessages();
|
UpdateMessages();
|
||||||
}
|
}
|
||||||
@ -1433,7 +1434,8 @@ namespace EduNetworkBuilder
|
|||||||
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Traceroute"), true);
|
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Traceroute"), true);
|
||||||
if (todo)
|
if (todo)
|
||||||
{
|
{
|
||||||
ItemClickedOn.TracerouteFromHere(destination);
|
//ItemClickedOn.TracerouteFromHere(destination);
|
||||||
|
NB.DoActionTracertDevice(ItemClickedOn.GetUniqueIdentifier, destination);
|
||||||
myNetwork.ProcessPackets();
|
myNetwork.ProcessPackets();
|
||||||
UpdateMessages();
|
UpdateMessages();
|
||||||
}
|
}
|
||||||
@ -2794,5 +2796,32 @@ namespace EduNetworkBuilder
|
|||||||
|
|
||||||
|
|
||||||
#endregion Random Map Stuff
|
#endregion Random Map Stuff
|
||||||
|
|
||||||
|
private void replayToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//Prepare for replay
|
||||||
|
// reset to original map
|
||||||
|
// Go through each step and do the actions again in order
|
||||||
|
NBSettings ourSettings = NB.GetSettings();
|
||||||
|
if (OurSettings == null) return; //nothing to do
|
||||||
|
ActionCollection actions = OurSettings.GetUserActionCollection();
|
||||||
|
if (actions == null) return; //nothing to do
|
||||||
|
|
||||||
|
if (actions.GetNet == null) return; //Nothing to do
|
||||||
|
//If we get here, we have a valid network in the current state.
|
||||||
|
|
||||||
|
ChangeToPastState(actions.GetNet);
|
||||||
|
//Make a boolean that says we are in a replaying state
|
||||||
|
//make an index that shows the index we are to replay
|
||||||
|
//make a time for when the next replay happens (.5 sec from now or after all packets are gone)
|
||||||
|
// On tick. If we are in replay mode.
|
||||||
|
// Check to see if we need to replay an action
|
||||||
|
// If so, do it.
|
||||||
|
// If not, keep ticking
|
||||||
|
//Disable menuitems & right-click if in replay mode
|
||||||
|
myNetwork.ReplayInProgress = true;
|
||||||
|
myNetwork.NextReplayIndex = 0;
|
||||||
|
myNetwork.NextReplayAction = DateTime.UtcNow.AddMilliseconds(NB.MillisecondsBetweenReplays);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user