improved advanced search feature

This commit is contained in:
AdAstra-LD
2021-01-31 19:51:48 +01:00
parent 62fabf509c
commit a8dd93ff38
9 changed files with 91 additions and 127 deletions

View File

@@ -132,6 +132,7 @@
this.Controls.Add(this.interiorCheckBox);
this.Controls.Add(this.buildingEditorBldListBox);
this.Name = "BuildingEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Building Editor";
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();

View File

@@ -28,11 +28,6 @@
this.explanationLabel = new System.Windows.Forms.Label();
this.operator1ComboBox = new System.Windows.Forms.ComboBox();
this.value1TextBox = new System.Windows.Forms.TextBox();
this.value2TextBox = new System.Windows.Forms.TextBox();
this.operator2ComboBox = new System.Windows.Forms.ComboBox();
this.fieldToSearch2ComboBox = new System.Windows.Forms.ComboBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.startSearchButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
@@ -48,9 +43,9 @@
this.fieldToSearch1ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fieldToSearch1ComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.fieldToSearch1ComboBox.FormattingEnabled = true;
this.fieldToSearch1ComboBox.Location = new System.Drawing.Point(39, 42);
this.fieldToSearch1ComboBox.Location = new System.Drawing.Point(63, 37);
this.fieldToSearch1ComboBox.Name = "fieldToSearch1ComboBox";
this.fieldToSearch1ComboBox.Size = new System.Drawing.Size(165, 24);
this.fieldToSearch1ComboBox.Size = new System.Drawing.Size(205, 24);
this.fieldToSearch1ComboBox.TabIndex = 6;
this.fieldToSearch1ComboBox.SelectedIndexChanged += new System.EventHandler(this.fieldToSearch1ComboBox_SelectedIndexChanged);
//
@@ -58,7 +53,7 @@
//
this.explanationLabel.AutoSize = true;
this.explanationLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.explanationLabel.Location = new System.Drawing.Point(18, 13);
this.explanationLabel.Location = new System.Drawing.Point(10, 8);
this.explanationLabel.Name = "explanationLabel";
this.explanationLabel.Size = new System.Drawing.Size(307, 15);
this.explanationLabel.TabIndex = 7;
@@ -69,73 +64,24 @@
this.operator1ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.operator1ComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.operator1ComboBox.FormattingEnabled = true;
this.operator1ComboBox.Location = new System.Drawing.Point(210, 42);
this.operator1ComboBox.Location = new System.Drawing.Point(63, 68);
this.operator1ComboBox.Name = "operator1ComboBox";
this.operator1ComboBox.Size = new System.Drawing.Size(176, 24);
this.operator1ComboBox.Size = new System.Drawing.Size(205, 24);
this.operator1ComboBox.TabIndex = 8;
this.operator1ComboBox.SelectedIndexChanged += new System.EventHandler(this.operator1ComboBox_SelectedIndexChanged);
//
// value1TextBox
//
this.value1TextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.value1TextBox.Location = new System.Drawing.Point(392, 42);
this.value1TextBox.Location = new System.Drawing.Point(63, 100);
this.value1TextBox.Name = "value1TextBox";
this.value1TextBox.Size = new System.Drawing.Size(117, 22);
this.value1TextBox.Size = new System.Drawing.Size(205, 22);
this.value1TextBox.TabIndex = 9;
//
// value2TextBox
//
this.value2TextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.value2TextBox.Location = new System.Drawing.Point(392, 97);
this.value2TextBox.Name = "value2TextBox";
this.value2TextBox.Size = new System.Drawing.Size(117, 22);
this.value2TextBox.TabIndex = 12;
//
// operator2ComboBox
//
this.operator2ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.operator2ComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.operator2ComboBox.FormattingEnabled = true;
this.operator2ComboBox.Location = new System.Drawing.Point(210, 97);
this.operator2ComboBox.Name = "operator2ComboBox";
this.operator2ComboBox.Size = new System.Drawing.Size(176, 24);
this.operator2ComboBox.TabIndex = 11;
this.operator2ComboBox.SelectedIndexChanged += new System.EventHandler(this.operator2ComboBox_SelectedIndexChanged);
//
// fieldToSearch2ComboBox
//
this.fieldToSearch2ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.fieldToSearch2ComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.fieldToSearch2ComboBox.FormattingEnabled = true;
this.fieldToSearch2ComboBox.Location = new System.Drawing.Point(39, 96);
this.fieldToSearch2ComboBox.Name = "fieldToSearch2ComboBox";
this.fieldToSearch2ComboBox.Size = new System.Drawing.Size(165, 24);
this.fieldToSearch2ComboBox.TabIndex = 10;
this.fieldToSearch2ComboBox.SelectedIndexChanged += new System.EventHandler(this.fieldToSearch2ComboBox_SelectedIndexChanged);
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(12, 46);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(15, 14);
this.checkBox1.TabIndex = 13;
this.checkBox1.UseVisualStyleBackColor = true;
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(12, 101);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(15, 14);
this.checkBox2.TabIndex = 14;
this.checkBox2.UseVisualStyleBackColor = true;
//
// startSearchButton
//
this.startSearchButton.Image = global::DSPRE.Properties.Resources.wideLensImage;
this.startSearchButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.startSearchButton.Location = new System.Drawing.Point(39, 142);
this.startSearchButton.Location = new System.Drawing.Point(112, 133);
this.startSearchButton.Name = "startSearchButton";
this.startSearchButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.startSearchButton.Size = new System.Drawing.Size(106, 43);
@@ -150,13 +96,8 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(556, 188);
this.ClientSize = new System.Drawing.Size(329, 188);
this.Controls.Add(this.startSearchButton);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.value2TextBox);
this.Controls.Add(this.operator2ComboBox);
this.Controls.Add(this.fieldToSearch2ComboBox);
this.Controls.Add(this.value1TextBox);
this.Controls.Add(this.operator1ComboBox);
this.Controls.Add(this.explanationLabel);
@@ -165,7 +106,8 @@
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "HeaderSearch";
this.Text = "ROM Toolbox";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Advanced Header Search (Experimental)";
this.ResumeLayout(false);
this.PerformLayout();
@@ -177,11 +119,6 @@
private System.Windows.Forms.Label explanationLabel;
private System.Windows.Forms.ComboBox operator1ComboBox;
private System.Windows.Forms.TextBox value1TextBox;
private System.Windows.Forms.TextBox value2TextBox;
private System.Windows.Forms.ComboBox operator2ComboBox;
private System.Windows.Forms.ComboBox fieldToSearch2ComboBox;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Button startSearchButton;
}
}

View File

@@ -41,6 +41,8 @@ namespace DSPRE {
private List<string> intNames;
private ListBox headerListBox;
public string status = "Ready";
public HeaderSearch(ref List<string> internalNames, ListBox headerListBox) {
InitializeComponent();
searchableHeaderFields = searchableHeaderFieldsList.ToArray();
@@ -51,8 +53,6 @@ namespace DSPRE {
this.headerListBox = headerListBox;
fieldToSearch1ComboBox.Items.AddRange(searchableHeaderFields);
fieldToSearch2ComboBox.Items.AddRange(searchableHeaderFields);
fieldToSearch1ComboBox.SelectedIndex = 0;
operator1ComboBox.SelectedIndex = 0;
}
@@ -61,18 +61,6 @@ namespace DSPRE {
UpdateOperators(operator1ComboBox, fieldToSearch1ComboBox);
}
private void operator1ComboBox_SelectedIndexChanged(object sender, EventArgs e) {
}
private void fieldToSearch2ComboBox_SelectedIndexChanged(object sender, EventArgs e) {
UpdateOperators(operator2ComboBox, fieldToSearch2ComboBox);
}
private void operator2ComboBox_SelectedIndexChanged(object sender, EventArgs e) {
}
#region Helper Methods
private void UpdateOperators(ComboBox operatorComboBox, ComboBox fieldToSearchComboBox) {
operatorComboBox.Items.Clear();
@@ -116,21 +104,67 @@ namespace DSPRE {
string[] fieldSplit = fieldToSearch.Split();
fieldSplit[0] = fieldSplit[0].ToLower();
string property = String.Join("", fieldSplit);
var headerFieldEntry = typeof(Header).GetProperty(property).GetValue(Header.LoadFromARM9(i), null);
var headerField = typeof(Header).GetProperty(property).GetValue(Header.LoadFromARM9(i), null);
int headerField = int.Parse(headerFieldEntry.ToString());
int numToSearch = int.Parse(valToSearch);
if (headerField.ToString().Equals(valToSearch))
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
if (oper.Equals("Is Less than")) {
if (headerField < numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
} else if (oper.Equals("Equals")) {
if (headerField == numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
} else if (oper.Equals("Is Greater")) {
if (headerField > numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
} else if (oper.StartsWith("Is Less than or Equal")) {
if (headerField <= numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
} else if (oper.StartsWith("Is Greater than or Equal")) {
if (headerField >= numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
} else if (oper.StartsWith("Is Different")) {
if (headerField != numToSearch) {
result.Add(i.ToString("D3") + Header.nameSeparator + intNames[i]);
}
}
}
}
return result;
}
private void startSearchButton_Click(object sender, EventArgs e) {
headerListBox.Items.Clear();
List<string> result = advancedSearch(0, (short)intNames.Count, intNames, fieldToSearch1ComboBox.Text, operator1ComboBox.SelectedItem.ToString(), value1TextBox.Text);
List<string> result;
if (result != null) {
try {
result = advancedSearch(0, (short)intNames.Count, intNames, fieldToSearch1ComboBox.Text, operator1ComboBox.SelectedItem.ToString(), value1TextBox.Text);
} catch (FormatException) {
MessageBox.Show("Make sure the value to search is correct.", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
headerListBox.Items.Add("Search parameters are invalid");
headerListBox.Enabled = false;
return;
}
if (result == null) {
if (value1TextBox.Text == "") {
headerListBox.Items.Add("Value to search is empty");
} else {
headerListBox.Items.Add("No result for " + '"' + value1TextBox.Text + '"');
}
headerListBox.Enabled = false;
} else {
headerListBox.Items.AddRange(result.ToArray());
headerListBox.SelectedIndex = 0;
headerListBox.Enabled = true;
status = "Showing headers whose " + fieldToSearch1ComboBox.Text + " " + operator1ComboBox.Text.ToLower() + " " + '"' + value1TextBox.Text + '"';
this.Dispose();
}
}
}

View File

@@ -7421,7 +7421,7 @@
this.asmHacksToolStripMenuItem.Name = "asmHacksToolStripMenuItem";
this.asmHacksToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.asmHacksToolStripMenuItem.Text = "ROM Toolbox";
this.asmHacksToolStripMenuItem.Click += new System.EventHandler(this.asmHacksToolStripMenuItem_Click);
this.asmHacksToolStripMenuItem.Click += new System.EventHandler(this.romToolBoxToolStripMenuItem_Click);
//
// aboutToolStripMenuItem1
//
@@ -7570,7 +7570,7 @@
this.romToolboxButton.Size = new System.Drawing.Size(36, 36);
this.romToolboxButton.Text = "ROM Toolbox";
this.romToolboxButton.ToolTipText = "ROM Toolbox";
this.romToolboxButton.Click += new System.EventHandler(this.asmHacksToolStripMenuItem_Click);
this.romToolboxButton.Click += new System.EventHandler(this.romToolBoxToolStripMenuItem_Click);
//
// headerSearchToolStripButton
//

View File

@@ -712,13 +712,19 @@ namespace DSPRE {
unpack.WaitForExit();
}
#endregion
private void asmHacksToolStripMenuItem_Click(object sender, EventArgs e) {
private void romToolBoxToolStripMenuItem_Click(object sender, EventArgs e) {
using (ROMToolboxDialog window = new ROMToolboxDialog(romInfo)) {
window.ShowDialog();
if (ROMToolboxDialog.standardizedItems)
isItemRadioButton.Enabled = true;
}
}
private void headerSearchToolStripButton_Click(object sender, EventArgs e) {
using (HeaderSearch h = new HeaderSearch(ref internalNames, headerListBox)) {
h.ShowDialog();
statusLabel.Text = h.status;
}
}
private void buildingEditorButton_Click(object sender, EventArgs e) {
unpackBuildingEditorNARCs();
@@ -1157,8 +1163,8 @@ namespace DSPRE {
currentHeader.flags = flagVal;
}
private void headerListBox_SelectedIndexChanged(object sender, EventArgs e) {
if (disableHandlers)
return;
if (disableHandlers || headerListBox.SelectedIndex < 0)
return;
/* Obtain current header ID from listbox*/
short headerNumber = Int16.Parse(headerListBox.SelectedItem.ToString().Substring(0, internalNames.Count.ToString().Length));
@@ -1530,6 +1536,8 @@ namespace DSPRE {
searchLocationTextBox.Clear();
if (headerListBox.Items.Count < internalNames.Count)
resetHeaderSearchResults();
statusLabel.Text = "Ready";
}
private void resetHeaderSearchResults() {
@@ -5026,18 +5034,12 @@ namespace DSPRE {
return w;
}
private void updateLineNumbersScripts(object sender, EventArgs e) {
if (disableHandlers)
return;
AddLineNumbers(scriptTextBox, LineNumberTextBoxScript);
}
private void updateLineNumbersFunctions(object sender, EventArgs e) {
if (disableHandlers)
return;
AddLineNumbers(functionTextBox, LineNumberTextBoxFunc);
}
private void updateLineNumbersMovements(object sender, EventArgs e) {
if (disableHandlers)
return;
AddLineNumbers(functionTextBox, LineNumberTextBoxMov);
}
#endregion
@@ -6315,10 +6317,5 @@ namespace DSPRE {
MessageBox.Show("AreaData File imported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
private void headerSearchToolStripButton_Click(object sender, EventArgs e) {
HeaderSearch h = new HeaderSearch(ref internalNames, headerListBox);
h.Show();
}
}
}

View File

@@ -235,6 +235,7 @@
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ROMToolboxDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "ROM Toolbox";
this.ResumeLayout(false);
this.PerformLayout();

View File

@@ -16,6 +16,7 @@ namespace DSPRE {
public ROMToolboxDialog(RomInfo romInfo) {
InitializeComponent();
this.romInfo = romInfo;
DSUtils.UnpackNarc(12);

View File

@@ -19,15 +19,11 @@ namespace DSPRE
selectEncounterComboBox.Items.Add("Encounters File " + i.ToString());
foreach (TabPage page in mainTabControl.TabPages) {
foreach (Control g in page.Controls) {
GroupBox group = g as GroupBox;
if (group != null) {
foreach (Control c in group.Controls) {
ComboBox box = c as ComboBox;
if (box != null)
box.Items.AddRange(names);
foreach (Control grp in page.Controls) {
if (grp as GroupBox != null) {
foreach (Control c in grp.Controls) {
if (c as ComboBox != null)
(c as ComboBox).Items.AddRange(names);
}
}
}

View File

@@ -17,16 +17,13 @@ namespace DSPRE
encounterFileFolder = dirPath;
for (int i = 0; i < Directory.GetFiles(dirPath).Length; i++)
selectEncounterComboBox.Items.Add("Encounters File " + i.ToString());
foreach (TabPage page in mainTabControl.TabPages) {
foreach (Control g in page.Controls) {
GroupBox group = g as GroupBox;
if (group != null) {
foreach (Control c in group.Controls) {
ComboBox box = c as ComboBox;
if (box != null)
box.Items.AddRange(names);
foreach (TabPage page in mainTabControl.TabPages) {
foreach (Control g in page.Controls) {
if (g as GroupBox != null) {
foreach (Control c in g.Controls) {
if (c as ComboBox != null)
(c as ComboBox).Items.AddRange(names);
}
}
}