Add drop-down menu item that shows up when we are in replay mode for the regression testing window

This commit is contained in:
Tim Young 2018-09-21 09:58:22 -05:00
parent 64b9f558c4
commit fcde8a1c5b
3 changed files with 182 additions and 150 deletions

View File

@ -111,6 +111,7 @@ namespace EduNetworkBuilder
}
if(mode == LBContents.regressiontest)
{
MyMode = LBContents.regressiontest;
//Regression testing. Similar to listing all the puzzles.
Text = NB.Translate("LBW_Regression_Testing"); //Regression Testing
//

View File

@ -37,6 +37,8 @@
this.logoutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.replayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.storeReplayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveReplayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -65,6 +67,7 @@
this.solvedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toSolveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.randomToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.regressionTestingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.panelChoices = new System.Windows.Forms.Panel();
this.lbMessages = new System.Windows.Forms.ListBox();
this.lblStatus = new System.Windows.Forms.Label();
@ -79,8 +82,6 @@
this.myProgressBar = new System.Windows.Forms.ProgressBar();
this.cbLineColor = new System.Windows.Forms.ComboBox();
this.cbFillColor = new System.Windows.Forms.ComboBox();
this.storeReplayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveReplayToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.msMainMenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pbNetworkView)).BeginInit();
this.HelpPanel.SuspendLayout();
@ -168,6 +169,20 @@
this.replayToolStripMenuItem.Text = "Replay";
this.replayToolStripMenuItem.Click += new System.EventHandler(this.replayToolStripMenuItem_Click);
//
// storeReplayToolStripMenuItem
//
this.storeReplayToolStripMenuItem.Name = "storeReplayToolStripMenuItem";
this.storeReplayToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
this.storeReplayToolStripMenuItem.Text = "Store Replay";
this.storeReplayToolStripMenuItem.Click += new System.EventHandler(this.storeReplayToolStripMenuItem_Click);
//
// saveReplayToolStripMenuItem
//
this.saveReplayToolStripMenuItem.Name = "saveReplayToolStripMenuItem";
this.saveReplayToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
this.saveReplayToolStripMenuItem.Text = "Save Replay";
this.saveReplayToolStripMenuItem.Click += new System.EventHandler(this.saveReplayToolStripMenuItem_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -350,37 +365,46 @@
this.puzzlesToolStripMenuItem,
this.solvedToolStripMenuItem,
this.toSolveToolStripMenuItem,
this.randomToolStripMenuItem});
this.randomToolStripMenuItem,
this.regressionTestingToolStripMenuItem});
this.samplesToolStripMenuItem.Name = "samplesToolStripMenuItem";
this.samplesToolStripMenuItem.Size = new System.Drawing.Size(77, 24);
this.samplesToolStripMenuItem.Text = "Samples";
this.samplesToolStripMenuItem.DropDownOpening += new System.EventHandler(this.samplesToolStripMenuItem_DropDownOpening);
//
// puzzlesToolStripMenuItem
//
this.puzzlesToolStripMenuItem.Name = "puzzlesToolStripMenuItem";
this.puzzlesToolStripMenuItem.Size = new System.Drawing.Size(140, 26);
this.puzzlesToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.puzzlesToolStripMenuItem.Text = "Puzzles";
this.puzzlesToolStripMenuItem.Click += new System.EventHandler(this.puzzlesToolStripMenuItem_Click);
//
// solvedToolStripMenuItem
//
this.solvedToolStripMenuItem.Name = "solvedToolStripMenuItem";
this.solvedToolStripMenuItem.Size = new System.Drawing.Size(140, 26);
this.solvedToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.solvedToolStripMenuItem.Text = "Solved";
//
// toSolveToolStripMenuItem
//
this.toSolveToolStripMenuItem.Name = "toSolveToolStripMenuItem";
this.toSolveToolStripMenuItem.Size = new System.Drawing.Size(140, 26);
this.toSolveToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.toSolveToolStripMenuItem.Text = "To Solve";
//
// randomToolStripMenuItem
//
this.randomToolStripMenuItem.Name = "randomToolStripMenuItem";
this.randomToolStripMenuItem.Size = new System.Drawing.Size(140, 26);
this.randomToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.randomToolStripMenuItem.Text = "Random";
this.randomToolStripMenuItem.Click += new System.EventHandler(this.randomToolStripMenuItem_Click);
//
// regressionTestingToolStripMenuItem
//
this.regressionTestingToolStripMenuItem.Name = "regressionTestingToolStripMenuItem";
this.regressionTestingToolStripMenuItem.Size = new System.Drawing.Size(207, 26);
this.regressionTestingToolStripMenuItem.Text = "Regression Testing";
this.regressionTestingToolStripMenuItem.Click += new System.EventHandler(this.regressionTestingToolStripMenuItem_Click);
//
// panelChoices
//
this.panelChoices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -547,20 +571,6 @@
this.cbFillColor.Size = new System.Drawing.Size(80, 24);
this.cbFillColor.TabIndex = 13;
//
// storeReplayToolStripMenuItem
//
this.storeReplayToolStripMenuItem.Name = "storeReplayToolStripMenuItem";
this.storeReplayToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
this.storeReplayToolStripMenuItem.Text = "Store Replay";
this.storeReplayToolStripMenuItem.Click += new System.EventHandler(this.storeReplayToolStripMenuItem_Click);
//
// saveReplayToolStripMenuItem
//
this.saveReplayToolStripMenuItem.Name = "saveReplayToolStripMenuItem";
this.saveReplayToolStripMenuItem.Size = new System.Drawing.Size(181, 26);
this.saveReplayToolStripMenuItem.Text = "Save Replay";
this.saveReplayToolStripMenuItem.Click += new System.EventHandler(this.saveReplayToolStripMenuItem_Click);
//
// BuilderWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
@ -651,6 +661,7 @@
private System.Windows.Forms.ToolStripMenuItem replayToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem storeReplayToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveReplayToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem regressionTestingToolStripMenuItem;
}
}

View File

@ -21,9 +21,9 @@ namespace EduNetworkBuilder
public Random GameRandomGen = new Random();
public NBSettings OurSettings = new NBSettings(NB.IsRunningOnMono()); //This will auto-load the settings
private int LastPacketID=1;
private int LastPacketID = 1;
public DebugPausePoint DebugSetting = DebugPausePoint.none;
// public DebugPausePoint DebugSetting = DebugPausePoint.all | DebugPausePoint.dump;
// public DebugPausePoint DebugSetting = DebugPausePoint.all | DebugPausePoint.dump;
public Network myNetwork = new Network("");
private Network InvisibleNetwork = null;
private List<Control> Buttons = new List<Control>();
@ -64,7 +64,7 @@ namespace EduNetworkBuilder
private List<Network> storedNetworkStates = new List<Network>(); //for ctrl-z going back in time to past state
private List<Network> ForwardstoredNetworkStates = new List<Network>(); //for ctrl-y going forward to a ctrl-y state
public BuilderWindow(string FirstArg="")
public BuilderWindow(string FirstArg = "")
{
InitializeComponent();
@ -74,7 +74,7 @@ namespace EduNetworkBuilder
HelpURLs = NB.LoadObjectFromXmlFile<List<HelpURL>>("URLs");
if(!OurSettings.LanguageHasBeenChosen)
if (!OurSettings.LanguageHasBeenChosen)
NB.ChangeLanguage(OurSettings);
LanguagifyComponents();
//I never implimented cut/copy/paste/undo. So we will remove them since they do nothing anyway
@ -107,7 +107,7 @@ namespace EduNetworkBuilder
ColorNames.Sort();
cbFillColor.Items.Clear();
cbLineColor.Items.Clear();
foreach(string ColorName in ColorNames)
foreach (string ColorName in ColorNames)
{
cbFillColor.Items.Add(ColorName);
cbLineColor.Items.Add(ColorName);
@ -129,7 +129,7 @@ namespace EduNetworkBuilder
KeyPreview = true;
CreateSolvedUnsolvedToolstripItems();
LoadPuzzleInfo();
LoadPuzzleInfo();
}
private void Tick(object sender, EventArgs e)
@ -141,7 +141,7 @@ namespace EduNetworkBuilder
}
myNetwork.Tick(false);
}
private void LanguagifyComponents()
{
msMainMenuStrip.Text = NB.Translate("NB_msMainMenuStrip", OurSettings);
@ -179,13 +179,13 @@ namespace EduNetworkBuilder
submitHomeworkToolStripMenuItem.Text = NB.Translate("NB_SubmitClasswork");
updateClassworkToolStripMenuItem.Text = NB.Translate("NB_UpdateClasswork");
markAsGradedToolStripMenuItem.Text = NB.Translate("NB_MarkGraded");
Text = NB.Translate("NB_Form", OurSettings);
}
public ResourceManager GetResource()
{
if(LanguageResources == null)
if (LanguageResources == null)
{
System.Reflection.Assembly MyAssembly;
MyAssembly = this.GetType().Assembly;
@ -196,7 +196,7 @@ namespace EduNetworkBuilder
public CultureInfo GetCulture()
{
if(LanguageCulture == null)
if (LanguageCulture == null)
{
string CL = OurSettings.ChosenLanguage;
if (CL != ChosenLanguage) ChosenLanguage = CL;
@ -227,13 +227,13 @@ namespace EduNetworkBuilder
pbNetworkView_Delete_Click(sender, e);
ItemClickedOn = null;
}
if(e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
{
doSave(true);
}
if (e.KeyCode == Keys.Z && e.Modifiers == Keys.Control)
{
if(storedNetworkStates.Count > 0)
if (storedNetworkStates.Count > 0)
{
ForwardstoredNetworkStates.Insert(0, myNetwork);//So we can ctrl-y to this state. Undo the undo
ChangeToPastState(storedNetworkStates[0]);
@ -256,10 +256,10 @@ namespace EduNetworkBuilder
{
if (storedNetworkStates.Count > 0 && toStore.Equals(storedNetworkStates[0]))
return; //The states are identical. Do not store this state.
storedNetworkStates.Insert(0,Network.DeepClone(toStore));
storedNetworkStates.Insert(0, Network.DeepClone(toStore));
ForwardstoredNetworkStates.Clear();
int maxCount = 30;
if(storedNetworkStates.Count > maxCount)
if (storedNetworkStates.Count > maxCount)
{
storedNetworkStates.RemoveRange(maxCount, storedNetworkStates.Count - maxCount);
}
@ -302,7 +302,7 @@ namespace EduNetworkBuilder
/// <returns>The control, or null if no control is found</returns>
public Control GetControlNamed(string Name)
{
Control[] tList = Controls.Find(Name, true);
Control[] tList = Controls.Find(Name, true);
if (tList.Count() > 0) return tList[0]; //return the first one
return null; //return nothing
}
@ -311,7 +311,7 @@ namespace EduNetworkBuilder
{
Button tButton;
this.SuspendLayout();
foreach(Control tCont in HelpTopicButtons)
foreach (Control tCont in HelpTopicButtons)
{
tCont.Click -= btnRead_Click;
Controls.Remove(tCont); //remove them all
@ -321,7 +321,7 @@ namespace EduNetworkBuilder
HelpTopicButtons.Clear(); //They are all gone.
//Make a bunch of new buttons.
int count=0;
int count = 0;
int offset = btnHelp.Height + 3;
if (myNetwork.NetURL.GetText() != "")
{
@ -350,7 +350,7 @@ namespace EduNetworkBuilder
tButton.Height = btnHelp.Height;
tButton.Click += btnRead_Click;
tButton.Name = HT.ToString();
if(URL != "")
if (URL != "")
{
//We have a URL for this.
tButton.BackgroundImage = Properties.Resources.VidImage;
@ -366,9 +366,9 @@ namespace EduNetworkBuilder
HelpTopicButtons.Add(tButton);
count++;
}
foreach(NetTest nt in myNetwork.NetTests)
foreach (NetTest nt in myNetwork.NetTests)
{
if(nt.TheTest == NetTestType.ReadContextHelp)
if (nt.TheTest == NetTestType.ReadContextHelp)
{
nt.ColorItemsIfNeeded(true);
}
@ -376,13 +376,13 @@ namespace EduNetworkBuilder
this.ResumeLayout();
}
string URLFromHelpTopic(HelpTopics what, string lang="")
string URLFromHelpTopic(HelpTopics what, string lang = "")
{
string topic = what.ToString();
if (lang == "") lang = ChosenLanguage;
foreach(HelpURL one in HelpURLs)
foreach (HelpURL one in HelpURLs)
{
if(one.HelpTopicString == topic && one.LangTag == lang)
if (one.HelpTopicString == topic && one.LangTag == lang)
{
return one.URL;
}
@ -433,7 +433,7 @@ namespace EduNetworkBuilder
}
}
private void myTooltip_Popup(Object sender, PopupEventArgs e)
{
@ -502,7 +502,7 @@ namespace EduNetworkBuilder
int x, y;
foreach (Button btn in Buttons)
{
if(what.Contains(btn.Name))
if (what.Contains(btn.Name))
{
x = (count % 2) * size;
y = (count / 2) * size;
@ -510,7 +510,7 @@ namespace EduNetworkBuilder
btn.Visible = true;
count++;
}
}
}
@ -523,9 +523,9 @@ namespace EduNetworkBuilder
{
lbMessages.Items.Add(msg);
}
if(lbMessages.Items.Count > 0)
lbMessages.SelectedIndex = lbMessages.Items.Count-1;
if (lbMessages.Items.Count > 0)
lbMessages.SelectedIndex = lbMessages.Items.Count - 1;
}
@ -562,7 +562,7 @@ namespace EduNetworkBuilder
updateClassworkToolStripMenuItem.Visible = false;
}
markAsGradedToolStripMenuItem.Visible = false;
if(CurrentUser != null)
if (CurrentUser != null)
{
if (CurrentUser.isAdmin)
{
@ -593,7 +593,7 @@ namespace EduNetworkBuilder
List<string> tLoadList = new List<string>();
loadToolStripMenuItem.DropDownItems.Clear();
if(OurSettings != null)
if (OurSettings != null)
{
foreach (string one in OurSettings.GetRecentFiles())
{
@ -670,7 +670,7 @@ namespace EduNetworkBuilder
rbHelp3.Visible = false;
rbHelp4.Visible = false;
}
switch(myNetwork.HintsToDisplay)
switch (myNetwork.HintsToDisplay)
{
case NetTestVerbosity.full:
rbHelp4.Checked = true;
@ -686,20 +686,20 @@ namespace EduNetworkBuilder
break;
}
UpdateHelpTopicButtons();
processing = false;
processing = false;
}
private void LayoutButtons()
{
List<string> what = new List<string>();
foreach(Button btn in Buttons)
foreach (Button btn in Buttons)
{
what.Add(btn.Name);
}
LayoutButtons(what);
}
private void LoadPuzzleInfo()
{
XmlDocument xmlDoc = new XmlDocument();
@ -716,7 +716,7 @@ namespace EduNetworkBuilder
foreach (string str in Enum.GetNames(typeof(PuzzleNames)))
{
byte[] item = (byte[])myManager.GetObject(str);
if(item == null)
if (item == null)
{
MessageBox.Show(String.Format(NB.Translate("NB_LoadPuzInfo"), str));
continue;
@ -729,22 +729,22 @@ namespace EduNetworkBuilder
PuzzleList.Add(newPuzzle);
//Console.WriteLine("Puzzle: " + str + " " + newPuzzle.PuzzleTitle);
}
PuzzleList = PuzzleList.OrderBy( c=> c.Level).ThenBy(c => c.SortOrder).ThenBy(c=> c.PuzzleName).ToList();
PuzzleList = PuzzleList.OrderBy(c => c.Level).ThenBy(c => c.SortOrder).ThenBy(c => c.PuzzleName).ToList();
}
public PuzzleInfo PuzzleInfoFromName(string PuzzleName)
{
foreach(PuzzleInfo pi in PuzzleList)
foreach (PuzzleInfo pi in PuzzleList)
{
if (pi.PuzzleName == PuzzleName)
return pi;
}
return null;
}
public bool PuzzleLevelHasUnsolved(string LevelName)
{
foreach (PuzzleInfo pi in PuzzleList)
{
if ("Level_" + pi.Level.ToString() == LevelName)
@ -769,11 +769,11 @@ namespace EduNetworkBuilder
List<string> LevelTags = new List<string>();
foreach (PuzzleInfo pi in PuzzleList)
{
foreach(string str in pi.PuzzleTags)
foreach (string str in pi.PuzzleTags)
{
//string What = NB.Translate("NB_Level");
string What = "^Level";
if (Regex.IsMatch(str,What))
if (Regex.IsMatch(str, What))
{
if (!LevelTags.Contains(str, StringComparer.OrdinalIgnoreCase))
LevelTags.Add(str);
@ -805,19 +805,20 @@ namespace EduNetworkBuilder
{
bool doupdate = false;
if (selectedButton == "btnShapes") doupdate = true;
foreach(Control btn in Buttons)
foreach (Control btn in Buttons)
{
if(btn == sender)
if (btn == sender)
{
//This is the selected item
btn.BackColor = Color.LightGreen;
selectedButton = btn.Name;
lblStatus.Text = myTooltip.GetToolTip(btn);
myNetwork.InShapeEditMode = true;
if (selectedButton == "btnShapes") {
if (selectedButton == "btnShapes")
{
myNetwork.InShapeEditMode = true;
if (CurrentShape == NetShapeType.none) CurrentShape = NetShapeType.rectangle;
if(doupdate)
if (doupdate)
{
//The shape was already selected. Toggle it
if (CurrentShape == NetShapeType.rectangle) CurrentShape = NetShapeType.circle;
@ -838,7 +839,8 @@ namespace EduNetworkBuilder
btn.BackColor = Button.DefaultBackColor;
}
}
if (doupdate) {
if (doupdate)
{
UpdateForm();
}
}
@ -851,8 +853,8 @@ namespace EduNetworkBuilder
selectedButton = "";
CurrentShape = NetShapeType.none;
btn.BackColor = Button.DefaultBackColor;
if(btn.Name == "btnShapes")
{
if (btn.Name == "btnShapes")
{
if (CurrentShape == NetShapeType.rectangle) btn.BackgroundImage = Properties.Resources.Square;
if (CurrentShape == NetShapeType.circle) btn.BackgroundImage = Properties.Resources.Circle;
if (CurrentShape == NetShapeType.none) btn.BackgroundImage = Properties.Resources.Shapes;
@ -883,7 +885,7 @@ namespace EduNetworkBuilder
}
private void pbNetworkView_RightMouseUp(NetworkDevice ReleasedOn, MouseEventArgs e)
{
{
int index = 0;
bool LockedOut = false;
bool PoweredOff = false;
@ -895,7 +897,7 @@ namespace EduNetworkBuilder
if (ReleasedOn != null) PoweredOff = ReleasedOn.PowerOff;
pbNetworkView.ContextMenuStrip.Items.Clear();
if(myNetwork.InShapeEditMode && ShapeForEditing != null)
if (myNetwork.InShapeEditMode && ShapeForEditing != null)
{
//context menu for shape
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
@ -1016,23 +1018,23 @@ namespace EduNetworkBuilder
pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("NB_NetViewRmLnkStr"), host));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_RemoveLink_Click;
}
if(ReleasedOn.PowerOff)
if (ReleasedOn.PowerOff)
{
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_PowerOn"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_PowerOn_Click;
}
else if(ReleasedOn.ForwardsPackets() || ReleasedOn.RoutesPackets())
else if (ReleasedOn.ForwardsPackets() || ReleasedOn.RoutesPackets())
{
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_PowerOff"));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_PowerOff_Click;
}
if (myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceBlowsUpWithPower) ||
myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceNICSprays) ||
if (myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceBlowsUpWithPower) ||
myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceNICSprays) ||
ReleasedOn.IsBurned)
{
bool toDo = false;
if (ReleasedOn.IsBurned) toDo = true;
if(myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceBlowsUpWithPower))
if (myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceBlowsUpWithPower))
toDo = !myNetwork.ItemTestIsComplete(ReleasedOn.hostname, NetTestType.DeviceBlowsUpWithPower);
if (myNetwork.ItemHasTest(ReleasedOn.hostname, NetTestType.DeviceNICSprays))
{
@ -1063,7 +1065,7 @@ namespace EduNetworkBuilder
pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("NB_Reset")));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Reset_Click;
}
if (ReleasedOn != null && (Form.ModifierKeys & Keys.Control) == Keys.Control ) //We control-click on it
if (ReleasedOn != null && (Form.ModifierKeys & Keys.Control) == Keys.Control) //We control-click on it
{
int MenuIndex = pbNetworkView.ContextMenuStrip.Items.Count;
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_Hide"));
@ -1073,14 +1075,14 @@ namespace EduNetworkBuilder
{
int MenuIndex = pbNetworkView.ContextMenuStrip.Items.Count;
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("NB_ColorStr"));
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Blue"),null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Blue"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Purple"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Yellow"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Green"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Orange"), null, pbNetworkView_Color_Click);
(pbNetworkView.ContextMenuStrip.Items[MenuIndex] as ToolStripMenuItem).DropDownItems.Add(NB.Translate("NB_Cyan"), null, pbNetworkView_Color_Click);
}
if ((!myNetwork.InShapeEditMode && ReleasedOn == null && ItemsSelected.Count == 0) || (myNetwork.InShapeEditMode && ShapeForEditing == null))
if ((!myNetwork.InShapeEditMode && ReleasedOn == null && ItemsSelected.Count == 0) || (myNetwork.InShapeEditMode && ShapeForEditing == null))
{
pbNetworkView.ContextMenuStrip.Visible = false;
}
@ -1100,7 +1102,7 @@ namespace EduNetworkBuilder
}
pbNetworkView.ContextMenuStrip.Items.Clear();
int index=0;
int index = 0;
//We need to make sure the item is not critical before we delete it.
pbNetworkView.ContextMenuStrip.Items.Add(NB.Translate("_Delete"));
@ -1145,15 +1147,15 @@ namespace EduNetworkBuilder
bool BlowUpOnce = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceBlowsUpWithPower);
bool BlowUpMultiple = myNetwork.ItemHasTest(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS) && !myNetwork.ItemTestIsComplete(ItemClickedOn.hostname, NetTestType.DeviceNeedsUPS);
if (BlowUpOnce || BlowUpMultiple)
{
Rectangle Where = new Rectangle(ItemClickedOn.myLocation().X,
{
Rectangle Where = new Rectangle(ItemClickedOn.myLocation().X,
ItemClickedOn.myLocation().Y - ((ItemClickedOn.Size * 2) / 3), ItemClickedOn.Size, ItemClickedOn.Size);
if (ItemClickedOn.IsBurned)
{
int which = GameRandomGen.Next(3);
if (which == 0)
myNetwork.AddAnimation(AnimationName.Spark1, Where);
else if(which == 1)
else if (which == 1)
myNetwork.AddAnimation(AnimationName.Lightning1, Where);
else
myNetwork.AddAnimation(AnimationName.Smoke1, Where);
@ -1248,9 +1250,9 @@ namespace EduNetworkBuilder
private void pbNetworkView_Color_Click(object sender, EventArgs e)
{
ToolStripMenuItem TSMI = (ToolStripMenuItem)sender;
if(ItemsSelected.Count > 0)
if (ItemsSelected.Count > 0)
{
foreach(NetworkDevice nd in ItemsSelected)
foreach (NetworkDevice nd in ItemsSelected)
{
ColorizeDevice(nd, TSMI.Text);
}
@ -1390,7 +1392,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_DeleteShape_Click(object sender, EventArgs e)
{
if(ShapeForEditing != null)
if (ShapeForEditing != null)
{
myNetwork.RemoveShape(ShapeForEditing);
ShapeForEditing = null;
@ -1424,7 +1426,7 @@ namespace EduNetworkBuilder
}
}
pbNetworkView.Image = null;
ItemsSelected.Clear();
ItemsSelected.Clear();
UpdateLinks();
myNetwork.TestForCompletion(true);
UpdateVisuals();
@ -1435,8 +1437,8 @@ namespace EduNetworkBuilder
bool todo = true;
if (ItemClickedOn == null) return; //we do not have something chosen to ping from
NB_IPAddress destination = new NB_IPAddress(NB.ZeroIPString, NB.ZeroIPString, IPAddressType.ip_only);
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping"),true);
if(todo)
todo = destination.Edit(ItemClickedOn, this, NB.Translate("_Ping"), true);
if (todo)
{
//ItemClickedOn.PingFromHere(destination);
NB.DoActionPingDevice(ItemClickedOn.GetUniqueIdentifier, destination);
@ -1469,7 +1471,7 @@ namespace EduNetworkBuilder
string dest = (string)Pressed.Tag;
NB_IPAddress destination;
destination = myNetwork.DNSLookup(ItemClickedOn, dest);
if(destination == null || destination.GetIPString == NB.ZeroIPString)
if (destination == null || destination.GetIPString == NB.ZeroIPString)
destination = new NB_IPAddress(dest);
//ItemClickedOn.PingFromHere(destination);
NB.DoActionPingDevice(ItemClickedOn.GetUniqueIdentifier, destination);
@ -1539,9 +1541,9 @@ namespace EduNetworkBuilder
Point ClickLocation = myNetwork.clickedPos(e.Location);
NetworkDevice ReleasedOn = myNetwork.ItemAtPosition(ClickLocation);
NetworkLink ReleasedOnLink = null;
if(ReleasedOn == null && !myNetwork.InShapeEditMode)
if (ReleasedOn == null && !myNetwork.InShapeEditMode)
ReleasedOnLink = myNetwork.LinkAtPosition(ClickLocation);
LastBackgroundImage = null;
pbNetworkView.Image = null; //erase old highlight area
LastMouseMovePos = new Point(-1, -1);
@ -1550,7 +1552,7 @@ namespace EduNetworkBuilder
TimeSpan duration;
duration = DateTime.Now - LastClick;
if(ReleasedOnLink != null && e.Button == MouseButtons.Right)
if (ReleasedOnLink != null && e.Button == MouseButtons.Right)
{
//Right-click on a line. Make a special context menu for that.
// delete
@ -1616,12 +1618,12 @@ namespace EduNetworkBuilder
UpdateVisuals();
return;
}
if (MouseIsDown && ItemClickedOn == null && (swidth > 4 || sheight>4))
if (MouseIsDown && ItemClickedOn == null && (swidth > 4 || sheight > 4))
{
//We just finished dragging a select box
//Put them all into the drag box.
ItemsSelected.Clear();
//Now we have a rectangle, but need to exchange numbers for numbers on the image
Point topCorner = myNetwork.clickedPos(new Point(sx, sy));
Point botCorner = myNetwork.clickedPos(new Point(sx + swidth, sy + sheight));
@ -1651,11 +1653,11 @@ namespace EduNetworkBuilder
if (LineColor.Name != "Empty" || FillColor.Name != "Empty")
{
if (ShapeForEditing == null)
{
NetShape NS = new NetShape(CurrentShape, selectbox, FillColor, LineColor);
{
NetShape NS = new NetShape(CurrentShape, selectbox, FillColor, LineColor);
myNetwork.AddShape(NS);
UpdateForm();
myNetwork.AddShape(NS);
UpdateForm();
}
else
{
@ -1819,7 +1821,7 @@ namespace EduNetworkBuilder
{
ItemClickedOn = null;
ShapeForEditing = myNetwork.ShapeAtPoint(location);
if(ShapeForEditing != null && e.Button == MouseButtons.Left)
if (ShapeForEditing != null && e.Button == MouseButtons.Left)
{
//we set the drag-point for the opposite corner
ClickedLocation = ShapeForEditing.OppositePoint(location);
@ -1829,12 +1831,12 @@ namespace EduNetworkBuilder
cbLineColor.Text = ShapeForEditing.LineColor.Name;
btnUpdateShape(); //Change the shape to what we are editing
}
else if(ShapeForEditing != null && e.Button == MouseButtons.Right)
else if (ShapeForEditing != null && e.Button == MouseButtons.Right)
{
//Right-clicking the shape. Context menu to come at button release!
}
}
if(e.Button == MouseButtons.Left)
if (e.Button == MouseButtons.Left)
MouseIsDown = true;
LastMouseDown = DateTime.UtcNow;
//Make a duplicate of the old background image.
@ -1851,7 +1853,7 @@ namespace EduNetworkBuilder
Point oldpoint = toMove.myLocation();
Rectangle oldrec = new Rectangle(oldpoint.X, oldpoint.Y, toMove.Size, toMove.Size);
Graphics.FromImage(pbNetworkView.BackgroundImage).DrawImage(LastBackgroundImage, oldrec, oldrec,GraphicsUnit.Pixel);
Graphics.FromImage(pbNetworkView.BackgroundImage).DrawImage(LastBackgroundImage, oldrec, oldrec, GraphicsUnit.Pixel);
myNetwork.Invalidate(oldrec);
//set it to the new pos
@ -1894,15 +1896,15 @@ namespace EduNetworkBuilder
else if (MouseIsDown && LastBackgroundImage != null && ItemClickedOn != null && ItemsSelected.Count == 0) //We are trying to drag something
{
//find where we are
TimeSpan HowLong = DateTime.UtcNow - LastMouseDown;
if(HowLong.TotalMilliseconds > 100 && !ItemClickedOn.IsLockedInLocation())
TimeSpan HowLong = DateTime.UtcNow - LastMouseDown;
if (HowLong.TotalMilliseconds > 100 && !ItemClickedOn.IsLockedInLocation())
DragItemToNewLocation(ItemClickedOn, CenteredLocation);
}
else if (MouseIsDown && ItemsSelected.Count >0) //dragging multiple items around
}
else if (MouseIsDown && ItemsSelected.Count > 0) //dragging multiple items around
{
//Track the difference between the last redraw and this re-draw
//Move every item by that amount.
int xdif = CenteredLocation.X - OrigClickPoint.X ;
int xdif = CenteredLocation.X - OrigClickPoint.X;
int ydif = CenteredLocation.Y - OrigClickPoint.Y;
if (xdif != 0 || ydif != 0)
{
@ -1926,7 +1928,7 @@ namespace EduNetworkBuilder
int sy;
int swidth;
int sheight;
if(ClickedLocation.X > MouseLocation.X )
if (ClickedLocation.X > MouseLocation.X)
{
sx = MouseLocation.X;
swidth = ClickedLocation.X - sx;
@ -1946,10 +1948,10 @@ namespace EduNetworkBuilder
sy = ClickedLocation.Y;
sheight = MouseLocation.Y - sy;
}
Rectangle selectbox = new Rectangle(sx,sy,swidth,sheight);
Rectangle selectbox = new Rectangle(sx, sy, swidth, sheight);
Color tColor = Color.LightGreen;
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128,tColor.R,tColor.G,tColor.B));
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(128, tColor.R, tColor.G, tColor.B));
tGraphics.FillRectangle(semiTransBrush, selectbox);
pbNetworkView.Image = tImage;
pbNetworkView.Invalidate();
@ -1967,7 +1969,7 @@ namespace EduNetworkBuilder
else
newtooltip = NB.Translate("NB_LockedOut");
}
if(oldtooltip != newtooltip)
if (oldtooltip != newtooltip)
{
myTooltip.SetToolTip(pbNetworkView, newtooltip);
}
@ -1981,7 +1983,7 @@ namespace EduNetworkBuilder
myNetwork.RegisterDisplayArea(pbNetworkView);
GC.Collect();
RTFWindow myWin = (RTFWindow)Application.OpenForms["RTFWindow"];
if (myWin != null)
if (myWin != null)
{
myWin.Close();
}
@ -2000,7 +2002,7 @@ namespace EduNetworkBuilder
mydialog.AddExtension = true;
//If we have a user loaded, we can open homework files
string filter = "EduNet File (*.enbx, *enbu)|*.enbx; *.enbu";
if(NB.GetUser() != null)
if (NB.GetUser() != null)
filter = "EduNet File (*.enbx, *enbu, *enbh)|*.enbx; *.enbu; *.enbh";
mydialog.Filter = filter;
mydialog.Multiselect = false;
@ -2009,7 +2011,7 @@ namespace EduNetworkBuilder
DialogResult result = mydialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel) return;
string extension = Path.GetExtension(mydialog.FileName).ToString();
if(extension != ".enbx" && extension != ".enbu" && extension != ".enbh")
if (extension != ".enbx" && extension != ".enbu" && extension != ".enbh")
{
MessageBox.Show(NB.Translate("_LoadErr"));
return;
@ -2110,10 +2112,10 @@ namespace EduNetworkBuilder
private void lbMessages_DoubleClick(object sender, EventArgs e)
{
if(lbMessages.SelectedIndex < 0) return; //nothing to do
if(lbMessages.SelectedIndex > myNetwork.CountMessages()) return; //invalid. Do nothing
if (lbMessages.SelectedIndex < 0) return; //nothing to do
if (lbMessages.SelectedIndex > myNetwork.CountMessages()) return; //invalid. Do nothing
PacketMessage newMessage = myNetwork.GetMessageAtIndex(lbMessages.SelectedIndex);
if(newMessage == null) return; //Not sure how we could get to this, but break out just in case
if (newMessage == null) return; //Not sure how we could get to this, but break out just in case
ListBoxWindow newwindow = new ListBoxWindow(newMessage);
newwindow.ShowDialog();
}
@ -2185,7 +2187,7 @@ namespace EduNetworkBuilder
//myString = System.Text.Encoding.Default.GetString(item);
xmlDoc.LoadXml(myString);
PrepForLoad();
myNetwork.Load(xmlDoc,resource, true);//Load it from resource. Set the bool saying it was from resource
myNetwork.Load(xmlDoc, resource, true);//Load it from resource. Set the bool saying it was from resource
UpdateMenu();
UpdateForm();
}
@ -2228,10 +2230,10 @@ namespace EduNetworkBuilder
private void CreateSolvedUnsolvedToolstripItems()
{
foreach(SolvedNetworkNames one in Enum.GetValues(typeof(SolvedNetworkNames)))
foreach (SolvedNetworkNames one in Enum.GetValues(typeof(SolvedNetworkNames)))
{
//add a solved one
ToolStripMenuItem tsmi = new ToolStripMenuItem(NB.Translate("NB_"+one.ToString()));
ToolStripMenuItem tsmi = new ToolStripMenuItem(NB.Translate("NB_" + one.ToString()));
tsmi.Name = one.ToString();
tsmi.Click += MenuItemLoadSolved;
solvedToolStripMenuItem.DropDownItems.Add(tsmi);
@ -2266,7 +2268,7 @@ namespace EduNetworkBuilder
OptionsWindow tWindow = new OptionsWindow(myNetwork);
tWindow.ShowDialog();
myNetwork.UpdateDeviceSizes();
UpdateForm();
}
@ -2280,7 +2282,7 @@ namespace EduNetworkBuilder
}
if (!File.Exists(filename))
{
MessageBox.Show(string.Format(NB.Translate("NB_NoSuchFile"),filename));
MessageBox.Show(string.Format(NB.Translate("NB_NoSuchFile"), filename));
//Close();
return;
}
@ -2298,7 +2300,7 @@ namespace EduNetworkBuilder
}
else if (extension == ".enbu")
{
if(CurrentUser != null && !CurrentUser.isAdmin)
if (CurrentUser != null && !CurrentUser.isAdmin)
{
MessageBox.Show(NB.Translate("NB_LogOutFirst"));
return;
@ -2310,14 +2312,14 @@ namespace EduNetworkBuilder
while (counter < 4)
{
string tPass = "";
if(counter > 0) //First try an empty password
if (counter > 0) //First try an empty password
tPass = NB.TextPromptBox("Enter a password", Properties.Resources.NBIco, true);
string tUserName = Path.GetFileNameWithoutExtension(filename);
string PasToUse = tUserName + tPass;
tUser = PersonClass.TryLoad(filename, PasToUse);
if (tUser != null) break;
counter++;
}
}
if (tUser == null)
{
//failed to load.
@ -2336,17 +2338,17 @@ namespace EduNetworkBuilder
CurrentUser = PPF.Edit(); //This does the form as dialog. When we come back, update the menu.
UpdateMenu();
}
else if(CurrentUser != null && CurrentUser.isAdmin)
else if (CurrentUser != null && CurrentUser.isAdmin)
{
//We want to import the student information for this one student
string user = Path.GetFileNameWithoutExtension(filename);
//Dig up the corresponding user.
PersonClass CurrentStudentUser = CurrentUser.StudentWithTheUserName(user);
if(CurrentStudentUser == null)
if (CurrentStudentUser == null)
{
//This means we do not have a user with that name in this class.
//More importantly, we do not have an alt-password set up so we can import them.
MessageBox.Show(string.Format(NB.Translate("NB_TeacherUnableToLoadUserNoAcct"),user));
MessageBox.Show(string.Format(NB.Translate("NB_TeacherUnableToLoadUserNoAcct"), user));
return;
}
//Use the alt password for that user to load the file
@ -2365,7 +2367,7 @@ namespace EduNetworkBuilder
}
else if (extension == ".enbh")
{
if(NB.GetUser() == null || CurrentUser == null)
if (NB.GetUser() == null || CurrentUser == null)
{
MessageBox.Show(NB.Translate("NB_LoadUserFirst"));
return;
@ -2408,8 +2410,8 @@ namespace EduNetworkBuilder
}
//If we started by clicking on a using a one_click installer, load that file
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Any())
{
string[] activationData = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
@ -2424,7 +2426,7 @@ namespace EduNetworkBuilder
}
}
if (InitialFileLoad != "") //This is set when we are installed by msi and we click a file
{
{
if (File.Exists(InitialFileLoad))
{
LoadInitialFile(InitialFileLoad);
@ -2476,7 +2478,7 @@ namespace EduNetworkBuilder
UpdateForm();
}
}
private void rbHelp2_CheckedChanged(object sender, EventArgs e)
{
if (processing) return;
@ -2532,24 +2534,24 @@ namespace EduNetworkBuilder
int max = (int)(total * 100);
myProgressBar.Maximum = max;
int distance = (int)(HowFar * 100);
if(distance > max) distance = max;
if (distance > max) distance = max;
myProgressBar.Value = distance;
}
private void changeLanguageToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult answer = MessageBox.Show(NB.Translate("NB_ChngLngClose"),NB.Translate("NB_ChngLngSure"),MessageBoxButtons.YesNoCancel);
if (answer == System.Windows.Forms.DialogResult.Yes)
{
OurSettings.LanguageHasBeenChosen = false; //So we choose the language on restart
//System.Diagnostics.Process.Start(Application.ExecutablePath); // to start new instance of application
this.Close(); //to turn off current app
}
DialogResult answer = MessageBox.Show(NB.Translate("NB_ChngLngClose"), NB.Translate("NB_ChngLngSure"), MessageBoxButtons.YesNoCancel);
if (answer == System.Windows.Forms.DialogResult.Yes)
{
OurSettings.LanguageHasBeenChosen = false; //So we choose the language on restart
//System.Diagnostics.Process.Start(Application.ExecutablePath); // to start new instance of application
this.Close(); //to turn off current app
}
}
private void cbViewTitles_CheckedChanged(object sender, EventArgs e)
{
if(!processing)
if (!processing)
{
//myNetwork.ShowLabelsHere = cbViewTitles.Checked;
bool didsomething = myNetwork.NoteActionDone(NetTestType.HelpRequest, "", "ViewButton");
@ -2682,7 +2684,7 @@ namespace EduNetworkBuilder
{
if (CurrentUser == null) return; //Nobody to logout
DialogResult answer = MessageBox.Show(NB.Translate("NB_Logout"), NB.Translate("NB_Logout"),MessageBoxButtons.YesNoCancel);
DialogResult answer = MessageBox.Show(NB.Translate("NB_Logout"), NB.Translate("NB_Logout"), MessageBoxButtons.YesNoCancel);
if (answer != DialogResult.Yes) return;
//Save current user
@ -2715,7 +2717,7 @@ namespace EduNetworkBuilder
}
public bool ProcessingInvisibleNet()
{
if(InvisibleNetwork == null) return false;
if (InvisibleNetwork == null) return false;
return true;
}
@ -2755,7 +2757,7 @@ namespace EduNetworkBuilder
}
private void LoadSolvedRandomMap(string what, bool FromResource, int difficulty)
{
{
if (FromResource)
LoadSolvedResource(what);
else
@ -2774,7 +2776,7 @@ namespace EduNetworkBuilder
while (Devices.Count > 2 && count < 5)
{
TraversalClass tc = myNetwork.NonVisualPingOneHost(Devices[0], Devices[1]);
if(tc != null)
if (tc != null)
TraversalCollection.Add(tc);
Devices.RemoveAt(1);
Devices.RemoveAt(0);
@ -2794,7 +2796,7 @@ namespace EduNetworkBuilder
//loop through the traversalinfos
//randomly choose a way to break it
BreakList = NB.Randomize<HowToBreak>(BreakList);
HowHard += myNetwork.BreakNetworkPath(TraversalCollection[TraversalIndex],BreakList[0]);
HowHard += myNetwork.BreakNetworkPath(TraversalCollection[TraversalIndex], BreakList[0]);
count++;
TraversalIndex++;
if (TraversalIndex >= TraversalCollection.Count)
@ -2886,7 +2888,7 @@ namespace EduNetworkBuilder
if (OurSettings != null && OurSettings.ReplayMode)
{
ActionCollection AC = OurSettings.GetUserActionCollection();
if(AC.CurrentNeedsStoring)
if (AC.CurrentNeedsStoring)
{
AC.PushActionToList();
}
@ -2916,5 +2918,23 @@ namespace EduNetworkBuilder
{
SaveReplayFile();
}
private void regressionTestingToolStripMenuItem_Click(object sender, EventArgs e)
{
ListBoxWindow LBW = new ListBoxWindow(null, LBContents.regressiontest);
LBW.ShowDialog();
}
private void samplesToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
if (OurSettings != null && OurSettings.ReplayMode)
{
regressionTestingToolStripMenuItem.Visible = true;
}
else
{
regressionTestingToolStripMenuItem.Visible = false;
}
}
}
}