Search capbility for puzzles

This commit is contained in:
Tim Young 2017-03-10 14:18:17 +03:00
parent 708ff2372f
commit bd1ca9fdf2
2 changed files with 73 additions and 9 deletions

View File

@ -35,6 +35,7 @@
this.btnAdd = new System.Windows.Forms.Button(); this.btnAdd = new System.Windows.Forms.Button();
this.cbLoadPuzzlesAtStart = new System.Windows.Forms.CheckBox(); this.cbLoadPuzzlesAtStart = new System.Windows.Forms.CheckBox();
this.btnReset = new System.Windows.Forms.Button(); this.btnReset = new System.Windows.Forms.Button();
this.tbSearchBox = new System.Windows.Forms.TextBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// lbWindowData // lbWindowData
@ -78,7 +79,7 @@
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.lblInstructions.Location = new System.Drawing.Point(12, 195); this.lblInstructions.Location = new System.Drawing.Point(12, 195);
this.lblInstructions.Name = "lblInstructions"; this.lblInstructions.Name = "lblInstructions";
this.lblInstructions.Size = new System.Drawing.Size(576, 38); this.lblInstructions.Size = new System.Drawing.Size(469, 38);
this.lblInstructions.TabIndex = 3; this.lblInstructions.TabIndex = 3;
this.lblInstructions.Text = "label1"; this.lblInstructions.Text = "label1";
// //
@ -115,12 +116,21 @@
this.btnReset.UseVisualStyleBackColor = true; this.btnReset.UseVisualStyleBackColor = true;
this.btnReset.Click += new System.EventHandler(this.btnReset_Click); this.btnReset.Click += new System.EventHandler(this.btnReset_Click);
// //
// tbSearchBox
//
this.tbSearchBox.Location = new System.Drawing.Point(487, 195);
this.tbSearchBox.Name = "tbSearchBox";
this.tbSearchBox.Size = new System.Drawing.Size(100, 22);
this.tbSearchBox.TabIndex = 7;
this.tbSearchBox.TextChanged += new System.EventHandler(this.tbSearchBox_TextChanged);
//
// ListBoxWindow // ListBoxWindow
// //
this.AcceptButton = this.btnOK; this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(601, 381); this.ClientSize = new System.Drawing.Size(601, 381);
this.Controls.Add(this.tbSearchBox);
this.Controls.Add(this.cbLoadPuzzlesAtStart); this.Controls.Add(this.cbLoadPuzzlesAtStart);
this.Controls.Add(this.btnReset); this.Controls.Add(this.btnReset);
this.Controls.Add(this.btnAdd); this.Controls.Add(this.btnAdd);
@ -145,5 +155,6 @@
private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.CheckBox cbLoadPuzzlesAtStart; private System.Windows.Forms.CheckBox cbLoadPuzzlesAtStart;
private System.Windows.Forms.Button btnReset; private System.Windows.Forms.Button btnReset;
private System.Windows.Forms.TextBox tbSearchBox;
} }
} }

View File

@ -22,6 +22,7 @@ namespace EduNetworkBuilder
PacketMessage myPacketMessage; PacketMessage myPacketMessage;
int EditableCount = -1; int EditableCount = -1;
bool processing = false; bool processing = false;
string FilterString = "";
/// <summary> /// <summary>
/// Instantiate a ListBoxWindow for use in choosing a network to load /// Instantiate a ListBoxWindow for use in choosing a network to load
@ -39,6 +40,7 @@ namespace EduNetworkBuilder
lblInstructions.Text = NB.Translate("LBW_LBWFilter"); lblInstructions.Text = NB.Translate("LBW_LBWFilter");
panelCheckboxes.SuspendLayout(); panelCheckboxes.SuspendLayout();
string SelectedTag = GetSelectedTag(); string SelectedTag = GetSelectedTag();
tbSearchBox.Visible = true;
if (SelectedTag == NB.Translate("_All")) if (SelectedTag == NB.Translate("_All"))
Text = Text + NB.Translate("_AllS"); Text = Text + NB.Translate("_AllS");
foreach (string str in NB.GetPuzzleTags()) foreach (string str in NB.GetPuzzleTags())
@ -70,6 +72,7 @@ namespace EduNetworkBuilder
{ {
InitializeComponent(); InitializeComponent();
LanguagifyComponents(); LanguagifyComponents();
tbSearchBox.Visible = false;
if (mode == LBContents.routes) if (mode == LBContents.routes)
{ {
MyMode = LBContents.routes; MyMode = LBContents.routes;
@ -226,19 +229,54 @@ namespace EduNetworkBuilder
if (Puzzles == null) return; if (Puzzles == null) return;
foreach (string str in Puzzles) foreach (string str in Puzzles)
{ {
pi = NB.GetPuzzleInfoFromName(str); if (FilterString == "")
shown_name = pi.PuzzleName;
if (Properties.Settings.Default.ScoreList.Contains(str))
shown_name = "* " + shown_name;
foreach(string tag in pi.PuzzleTags)
{ {
if(isChecked(tag)) pi = NB.GetPuzzleInfoFromName(str);
shown_name = pi.PuzzleName;
if (Properties.Settings.Default.ScoreList.Contains(str))
shown_name = "* " + shown_name;
foreach (string tag in pi.PuzzleTags)
{ {
if (isChecked(tag))
{
lbWindowData.Items.Add(shown_name);
break;
}
}
}else
{
//We are filtering stuff
pi = NB.GetPuzzleInfoFromName(str);
shown_name = pi.PuzzleName;
bool added = false;
string localFilter = ".*" + FilterString + ".*";
if (Properties.Settings.Default.ScoreList.Contains(str))
shown_name = "* " + shown_name;
if (!added && pi.PuzzleName != null && Regex.IsMatch(pi.PuzzleName, localFilter, RegexOptions.IgnoreCase))
{
added = true;
lbWindowData.Items.Add(shown_name); lbWindowData.Items.Add(shown_name);
break; }
if (!added && pi.PuzzleDescription!= null && Regex.IsMatch(pi.PuzzleDescription, localFilter, RegexOptions.IgnoreCase))
{
added = true;
lbWindowData.Items.Add(shown_name);
}
if (!added && pi.PuzzleTitle != null && Regex.IsMatch(pi.PuzzleTitle, localFilter,RegexOptions.IgnoreCase))
{
added = true;
lbWindowData.Items.Add(shown_name);
}
foreach (string tag in pi.PuzzleTags)
{
if (!added && pi.PuzzleTitle != null && Regex.IsMatch(tag, localFilter, RegexOptions.IgnoreCase))
{
lbWindowData.Items.Add(shown_name);
break;
}
} }
} }
} }
if(selected != null && selected != "") if(selected != null && selected != "")
{ {
if (lbWindowData.Items.Contains(selected)) if (lbWindowData.Items.Contains(selected))
@ -472,5 +510,20 @@ namespace EduNetworkBuilder
} }
} }
private void tbSearchBox_TextChanged(object sender, EventArgs e)
{
//If there are more than 2 characters, then we start to see if we can filter it
if (tbSearchBox.Text.Length > 2)
{
//Now we filter the results
FilterString = tbSearchBox.Text;
UpdateForm();
}
else
{
FilterString = "";
UpdateForm();
}
}
} }
} }