Skip to content

Commit

Permalink
add game feature
Browse files Browse the repository at this point in the history
fuzzy string matching updates
ipdb browser additional visible fields
  • Loading branch information
xantari committed Jan 25, 2021
1 parent fc3a2d9 commit 2de7d3b
Show file tree
Hide file tree
Showing 12 changed files with 645 additions and 481 deletions.
26 changes: 26 additions & 0 deletions PinCab.Configurator/AddEditGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ public partial class AddEditGameForm : Form
private FrontEndManager _manager { get; set; }
private string _databaseFile { get; set; }
private IpdbBrowserForm _ipdbForm = null;
private bool isNewEntry = false;
public AddEditGameForm(FrontEndGameViewModel setting, string databaseFile, FrontEndManager manager, IpdbBrowserForm ipdbForm)
{
InitializeComponent();
_setting = setting;
_manager = manager;
_databaseFile = databaseFile;
_ipdbForm = ipdbForm;
if (string.IsNullOrEmpty(setting.Description))
isNewEntry = true;
if (_ipdbForm == null)
_ipdbForm = new IpdbBrowserForm(txtTableName.Text, true);
LoadForm();
Expand Down Expand Up @@ -124,6 +127,17 @@ private void btnCancel_Click(object sender, EventArgs e)
private void btnSave_Click(object sender, EventArgs e)
{
var result = GetSettingFromControls();
if (string.IsNullOrEmpty(result.Description))
{
MessageBox.Show("Description is a required field");
return;
}
if (string.IsNullOrEmpty(result.FileName))
{
MessageBox.Show("File Name is a required field");
return;
}

_manager.SaveGame(result);
Close();
}
Expand All @@ -134,6 +148,11 @@ private void btnSelectFile_Click(object sender, EventArgs e)
{
fileDialog.Filter = "All files (*.*)|*.*|VPX Files|*.vpx|FPT Files|*.fpx|VPT Files|*.vpt";
fileDialog.FilterIndex = 1;
if (_setting.FrontEnd.System == FrontEndSystem.PinballX)
{
var system = _manager.PinballXSystems.FirstOrDefault(c => c.DatabaseFiles.Contains(_databaseFile));
fileDialog.InitialDirectory = system.TablePath;
}
fileDialog.RestoreDirectory = true;
var result = fileDialog.ShowDialog(this);
if (result == DialogResult.OK)
Expand All @@ -142,6 +161,11 @@ private void btnSelectFile_Click(object sender, EventArgs e)
var endIndex = fi.Name.LastIndexOf(fi.Extension);
originalFileName = txtTableName.Text;
txtTableName.Text = fi.Name.Substring(0, endIndex);
if (isNewEntry)
{
txtModified.Text = fi.LastWriteTime.ToString();
txtAdded.Text = fi.CreationTime.ToString();
}
}
}
}
Expand All @@ -155,6 +179,8 @@ private void btnIpdbUrl_Click(object sender, EventArgs e)
private void btnFillFromIpdb_Click(object sender, EventArgs e)
{
_ipdbForm.SearchText(txtTableName.Text);
if (isNewEntry)
_ipdbForm.chkOverrideDisplayName.Checked = true;
var result = _ipdbForm.ShowDialog(this);
if (result == DialogResult.OK)
{
Expand Down
28 changes: 7 additions & 21 deletions PinCab.Configurator/DatabaseBrowserForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 37 additions & 6 deletions PinCab.Configurator/DatabaseBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Close();
}

public void SearchByText(string text, DateTime startDate, DateTime endDate, List<string> tags, bool fuzzyMatch = true, string typeFilter = "All", string databaseFilter = "All")
public void SearchByText(string text, DateTime startDate, DateTime endDate, List<string> tags, string typeFilter = "All", string databaseFilter = "All")
{
_loading = true; //Don't cause excessive rebinds
dateTimePickerEnd.Value = endDate;
Expand All @@ -166,7 +166,6 @@ public void SearchByText(string text, DateTime startDate, DateTime endDate, List
}
cmbType.SelectedItem = typeFilter;
cmbDatabase.SelectedItem = databaseFilter;
chkFuzzyMatch.Checked = fuzzyMatch;
_loading = false;
txtSearch.Text = text;
}
Expand All @@ -179,10 +178,9 @@ private void txtSearch_TextChanged(object sender, EventArgs e)
private List<DatabaseBrowserEntry> GetEntriesByFilterCriteria()
{
IEnumerable<DatabaseBrowserEntry> list;
if (chkFuzzyMatch.Checked)
list = _dbManager.Entries.Where(p => p.Title.FuzzyMatch(txtSearch.Text) > .5); //Search by text
else
list = _dbManager.Entries.Where(p => p.Title.ToLower().Contains(txtSearch.Text.ToLower())); //Search by text
list = _dbManager.Entries.Where(p => (p.Title.FuzzyMatch(txtSearch.Text) > .5)
|| p.Title.ToLower().Contains(txtSearch.Text.ToLower())
); //Search by text
list = list.Where(p => p.LastUpdated <= dateTimePickerEnd.Value.EndOfDay()
&& p.LastUpdated >= dateTimePickerBegin.Value.BeginningOfDay());

Expand All @@ -208,12 +206,16 @@ private List<DatabaseBrowserEntry> GetEntriesByFilterCriteria()

private void RebindGridUsingFilter()
{
//Stopwatch watch = new Stopwatch();
//watch.Start();
var list = GetEntriesByFilterCriteria();
vpinDatabaseSettingBindingSource.DataSource = list.ToSortableBindingList();
var tags = _dbManager.GetAllTags(list.ToList(), false).OrderBy(c => c).ToList();
tags.Insert(0, "(Select Tag)");
cmbTags.DataSource = tags;
UpdateToolstripStatus();
//watch.Stop();
//Debug.WriteLine("Rebind took: " + watch.Elapsed);
}

//private void contextMenuStripGridActions_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
Expand Down Expand Up @@ -308,6 +310,14 @@ private void backgroundWorkerProgressBar_RunWorkerCompleted(object sender, RunWo
var tags = result.Result as List<string>;
cmbTags.DataSource = tags;
}
//else if (result.FunctionExecuted == DatabaseManagerBackgroundProgressAction.RebindDatabaseBrowserGrid.ToString())
//{
// var list = vpinDatabaseSettingBindingSource.DataSource as SortableBindingList<DatabaseBrowserEntry>;
// var tags = _dbManager.GetAllTags(list.ToList(), false).OrderBy(c => c).ToList();
// tags.Insert(0, "(Select Tag)");
// cmbTags.DataSource = tags;
// UpdateToolstripStatus();
//}
UpdateToolstripStatus();
}

Expand All @@ -328,6 +338,27 @@ private void backgroundWorkerProgressBar_DoWork(object sender, DoWorkEventArgs e
{
e.Result = LoadTags();
}
//else if (arg.Action == DatabaseManagerBackgroundProgressAction.RebindDatabaseBrowserGrid)
//{
// RebindGridUsingFilter();
// var toolResult = new ToolResult()
// {
// IsValid = true,
// };
// toolResult.ToolName = DatabaseManager.ToolName;
// toolResult.MessageType = ValidationMessageType.ToolMessage;
// toolResult.FunctionExecuted = DatabaseManagerBackgroundProgressAction.RebindDatabaseBrowserGrid.ToString();
// e.Result = toolResult;
//}
}

private BackgroundWorker CreateBackgroundWorker()
{
var bw = new BackgroundWorker();
bw.WorkerSupportsCancellation = true;
bw.DoWork += backgroundWorkerProgressBar_DoWork;
bw.RunWorkerCompleted += backgroundWorkerProgressBar_RunWorkerCompleted;
return bw;
}

private ToolResult DownloadAndLoadDatabase()
Expand Down
Loading

0 comments on commit 2de7d3b

Please sign in to comment.