Skip to content

Commit

Permalink
initial read/write of pinball x games in game manager
Browse files Browse the repository at this point in the history
auto backups of game manager xml upon edits
  • Loading branch information
xantari committed Jan 20, 2021
1 parent eed66db commit 57e2d22
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 322 deletions.
453 changes: 185 additions & 268 deletions PinCab.Configurator/AddEditGameForm.Designer.cs

Large diffs are not rendered by default.

82 changes: 72 additions & 10 deletions PinCab.Configurator/AddEditGameForm.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using PinCab.Utils.Extensions;
using PinCab.Utils;
using PinCab.Utils.Extensions;
using PinCab.Utils.Models;
using PinCab.Utils.Utils;
using PinCab.Utils.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -15,23 +17,83 @@ namespace PinCab.Configurator
{
public partial class AddEditGameForm : Form
{
private VpinMameRomSetting _setting { get; set; }
public AddEditGameForm(VpinMameRomSetting setting)
private FrontEndGameViewModel _setting { get; set; }
private FrontEndManager _manager { get; set; }
public AddEditGameForm(FrontEndGameViewModel setting, FrontEndManager manager)
{
InitializeComponent();
_setting = setting;
_manager = manager;
LoadForm();
}

private void LoadForm()
{

txtTableName.Text = _setting.FileName;
txtDisplayName.Text = _setting.Description;
txtManufacturer.Text = _setting.Manufacturer;
txtYear.Text = _setting.Year;
txtTheme.Text = _setting.Theme;
txtAuthor.Text = _setting.Author;
txtVersion.Text = _setting.Version;
txtIpdb.Text = _setting.IPDBNumber;
txtType.Text = _setting.Type;
txtRom.Text = _setting.Rom;
txtPlayers.Text = _setting.Players;
txtPlayCount.Text = _setting.TimesPlayed.ToString();
txtSeconds.Text = _setting.SecondsPlayed.ToString();
txtAdded.Text = _setting.DateAdded.ToString();
txtModified.Text = _setting.DateModified.ToString();
txtAlternateExe.Text = _setting.AlternateExe;
txtComment.Text = _setting.Comment;
txtGameUrl.Text = _setting.TableFileUrl;
chkHideBackglass.Checked = _setting.HideBackglass;
chkHideDmd.Checked = _setting.HideDmd;
chkHideTopper.Checked = _setting.HideTopper;
chkEnabled.Checked = _setting.Enabled;
chkFavorite.Checked = _setting.Favorite;
}

//private VpinMameRomSetting GetSettingFromControls()
//{

//}
private FrontEndGameViewModel GetSettingFromControls()
{
_setting.FileName = txtTableName.Text.IfEmptyThenNull();
_setting.Description = txtDisplayName.Text.IfEmptyThenNull();
_setting.Manufacturer = txtManufacturer.Text.IfEmptyThenNull();
_setting.Year = txtYear.Text.IfEmptyThenNull();
_setting.Theme = txtTheme.Text.IfEmptyThenNull();
_setting.Author = txtAuthor.Text.IfEmptyThenNull();
_setting.Version = txtVersion.Text.IfEmptyThenNull();
_setting.IPDBNumber = txtIpdb.Text.IfEmptyThenNull();
_setting.Type = txtType.Text.IfEmptyThenNull();
_setting.Rom = txtRom.Text.IfEmptyThenNull();
_setting.Players = txtPlayCount.Text.IfEmptyThenNull();
_setting.TimesPlayed = Convert.ToInt32(txtPlayCount.Text);
_setting.SecondsPlayed = Convert.ToInt32(txtSeconds.Text);
if (!string.IsNullOrEmpty(txtAdded.Text))
{
DateTime result;
var success = DateTime.TryParse(txtAdded.Text, out result);
if (success)
_setting.DateAdded = result;

}
if (!string.IsNullOrEmpty(txtModified.Text))
{
DateTime result;
var success = DateTime.TryParse(txtModified.Text, out result);
if (success)
_setting.DateModified = result;
}

_setting.AlternateExe = txtAlternateExe.Text.IfEmptyThenNull();
_setting.Comment = txtComment.Text.IfEmptyThenNull();
_setting.TableFileUrl = txtGameUrl.Text.IfEmptyThenNull();
_setting.HideBackglass = chkHideBackglass.Checked;
_setting.HideDmd = chkHideDmd.Checked;
_setting.HideTopper = chkHideTopper.Checked;

return _setting;
}

private void btnCancel_Click(object sender, EventArgs e)
{
Expand All @@ -40,8 +102,8 @@ private void btnCancel_Click(object sender, EventArgs e)

private void btnSave_Click(object sender, EventArgs e)
{
//var result = GetSettingFromControls();
//_util.SaveRomModelToRegsitry(result);
var result = GetSettingFromControls();
_manager.SaveGame(result);
Close();
}

Expand Down
59 changes: 24 additions & 35 deletions PinCab.Configurator/GameManagerForm.Designer.cs

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

38 changes: 35 additions & 3 deletions PinCab.Configurator/GameManagerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,24 @@ private void cmbFrontEnd_SelectedIndexChanged(object sender, EventArgs e)
}
}

private void editToolStripMenuItem_Click(object sender, EventArgs e)
private FrontEndGameViewModel GetActiveRow()
{
var data = dataGridViewGameList.DataSource as BindingSource;
return data.Current as FrontEndGameViewModel;
}

private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
var row = GetActiveRow();
if (row != null)
{
var mediaAuditForm = new AddEditGameForm(row, _manager);
var result = mediaAuditForm.ShowDialog();
if (result == DialogResult.OK)
{
RefreshGameGrid();
}
}
}

private void mediaAuditToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -118,7 +133,8 @@ private void RefreshGameGrid()
{
var frontEnd = cmbFrontEnd.SelectedItem as FrontEnd;
_fullGameListCache = _manager.GetGamesForFrontEndAndDatabase(frontEnd, cmbDatabase.SelectedItem.ToString());
dataGridViewGameList.DataSource = _fullGameListCache.ToSortableBindingList();
frontEndGameBindingSource.DataSource = _fullGameListCache.ToSortableBindingList();

if (frontEnd.System == FrontEndSystem.PinballX)
{
var system = _manager.PinballXSystems.FirstOrDefault(p => p.DatabaseFiles.Any(c => c.Contains(cmbDatabase.SelectedItem.ToString())));
Expand All @@ -127,7 +143,7 @@ private void RefreshGameGrid()
else
lblDatabaseStatus.Text = "Disabled";
}

}
}

Expand Down Expand Up @@ -183,5 +199,21 @@ private void dataGridViewGameList_DataBindingComplete(object sender, DataGridVie
{
dataGridViewGameList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}

private void dataGridViewGameList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex == -1)
return;
var row = GetActiveRow();
if (row != null)
{
var mediaAuditForm = new AddEditGameForm(row, _manager);
var result = mediaAuditForm.ShowDialog();
if (result == DialogResult.OK)
{
RefreshGameGrid();
}
}
}
}
}
4 changes: 2 additions & 2 deletions PinCab.Configurator/GameManagerForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
<value>15, 20</value>
</metadata>
<metadata name="backgroundWorkerProgressBar.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>256, 22</value>
<value>218, 20</value>
</metadata>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>463, 23</value>
<value>426, 23</value>
</metadata>
</root>
7 changes: 7 additions & 0 deletions PinCab.Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ public static string RemoveBlankLines(this string text, string delimiter)
}
return sb.ToString();
}

public static string IfEmptyThenNull(this string text)
{
if (string.IsNullOrEmpty(text))
return null;
return text;
}
}
}
8 changes: 7 additions & 1 deletion PinCab.Utils/Models/PinballX/PinballXGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PinballXGame
[XmlElement("rating")]
public double Rating { get; set; }

[XmlElement("AlternateExe")]
[XmlElement("alternateexe")]
public string AlternateExe { get; set; }

[XmlElement("SendKeysOnStart")]
Expand All @@ -89,6 +89,12 @@ public class PinballXGame
[XmlElement("datemodified")]
public string DateModified { get; set; }

/// <summary>
/// For tracking when updates occur to this game, track the original table URL
/// </summary>
[XmlElement("tablefileurl")]
public string TableFileUrl { get; set; }

// internal fields (not serialized)
// ----------------------------------
[XmlIgnore]
Expand Down
7 changes: 7 additions & 0 deletions PinCab.Utils/Models/PinballX/PinballXSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class PinballXSystem
public readonly string DefaultExecutableLabel = "<default>";
// from pinballx.ini
public string Name { get; set; }

public string StatsSectionName { get {
return Name.Replace(" ", "");
} }
public bool Enabled { get; set; }
public string WorkingPath { get; set; }
public string TablePath { get; set; }
Expand All @@ -36,6 +40,9 @@ public class PinballXSystem
public string PinballXIniFilePath { get; set; }
public string PinballXFolder { get; set; }
public Platform Type { get; set; }
/// <summary>
/// Games database, string is the database file string
/// </summary>
public Dictionary<string, List<PinballXGame>> Games { get; } = new Dictionary<string, List<PinballXGame>>();

public PinballXSystem(string pinballXIniFilePath)
Expand Down
Loading

0 comments on commit 57e2d22

Please sign in to comment.