Skip to content

Commit

Permalink
Update json settings logic, splash window and names format
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurits committed Apr 5, 2022
1 parent 8ccc29e commit f720616
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 171 deletions.
53 changes: 43 additions & 10 deletions MemoryNumbers/JsonSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,21 @@

namespace MemoryNumbers;

partial class frmMain
partial class FrmMain
{
/// <summary>
/// Loads all settings from file _sett.FileName into class instance _settings
/// Shows MessageBox error if unsuccessful
/// </summary>
private void LoadProgramSettingsJSON()
/// <returns><see langword="True"/> if successful, <see langword="false"/> otherwise</returns>
private bool LoadProgramSettingsJSON()
{
bool result = false;
try
{
var jsonString = File.ReadAllText(_settings.FileName);
_settings = JsonSerializer.Deserialize<ClassSettings>(jsonString) ?? _settings;

if (_settings.WindowPosition)
{
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.DesktopLocation = new Point(_settings.WindowLeft, _settings.WindowTop);
this.ClientSize = new Size(_settings.WindowWidth, _settings.WindowHeight);
}
this.splitStats.SplitterDistance = _settings.SplitterDistance;
result = true;
}
catch (FileNotFoundException)
{
Expand All @@ -42,6 +37,7 @@ private void LoadProgramSettingsJSON()
MessageBoxIcon.Error);
}
}
return result;
}

/// <summary>
Expand All @@ -67,5 +63,42 @@ private void SaveProgramSettingsJSON()
File.WriteAllText(_settings.FileName, jsonString);
}

/// <summary>
/// Update UI with settings
/// </summary>
/// <param name="WindowSettings"><see langword="True"/> if the window position and size should be applied. <see langword="False"/> if omitted</param>
private void ApplySettingsJSON(bool WindowPosition = false)
{
if (WindowPosition)
{
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.DesktopLocation = new Point(_settings.WindowLeft, _settings.WindowTop);
this.ClientSize = new Size(_settings.WindowWidth, _settings.WindowHeight);
}
this.splitStats.SplitterDistance = _settings.SplitterDistance;

// Game configuration
this._game.MinimumLength = _settings.MinimumLength;
this._game.MaximumAttempts = _settings.MaximumAttempts;
this._game.MaximumDigit = _settings.MaximumDigit;
this._game.MinimumDigit = _settings.MinimumDigit;
this._game.PlayMode = (PlayMode)Enum.Parse(typeof(PlayMode), _settings.PlayMode.ToString());
this._game.Time = _settings.Time;
this._game.TimeIncrement = _settings.TimeIncrement;

// Board configuration
this.board1.BorderRatio = _settings.BorderRatio;
this.board1.CountDownRatio = _settings.CountDownRatio;
this.board1.NumbersRatio = _settings.NumbersRatio;
this.board1.FontRatio = _settings.FontRatio;
this.board1.ResultRatio = _settings.ResultsRatio;
this.board1.BackColor = Color.FromArgb(_settings.BackColor);
this.board1.Font = new Font(_settings.FontFamilyName, board1.Font.SizeInPoints);

// Toolstrip status
this.toolStripMain_Sound.Checked = _settings.Sound;
this.toolStripMain_Stats.Checked = _settings.Stats;
this.board1.PlaySounds = !this.toolStripMain_Sound.Checked;
}
}

6 changes: 6 additions & 0 deletions MemoryNumbers/MemoryNumbers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
<Folder Include="localization\" />
</ItemGroup>
<ItemGroup>
<None Update="images\Memory numbers splash.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="images\MemoryNumbers splash.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="MemoryNumbers launcher.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion MemoryNumbers/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmMain());
Application.Run(new FrmMain());
}
}
}
6 changes: 3 additions & 3 deletions MemoryNumbers/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("Winddows 10 x64")]
[assembly: AssemblyCompany("Alf Interactive Entertainment Ltd.")]
[assembly: AssemblyProduct("MemoryNumbers")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2020 - 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// Puede especificar todos los valores o utilizar los números de compilación y de revisión predeterminados
// mediante el carácter '*', como se muestra a continuación:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
2 changes: 1 addition & 1 deletion MemoryNumbers/UpdatePlots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;

namespace MemoryNumbers;
partial class frmMain
partial class FrmMain
{
/// <summary>
/// Cleans and updates the chartStatsNumbers with the data returned from _game.GetStats
Expand Down
93 changes: 93 additions & 0 deletions MemoryNumbers/UserInteractionGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Windows.Forms;
using Utils;

namespace MemoryNumbers;

partial class FrmMain
{
private void Exit_Click(object sender, EventArgs e)
{
Close();
}

private async void Start_Click(object sender, EventArgs e)
{
// Commute visibility of the strip buttons
this.toolStripMain_Start.Enabled = false;
this.toolStripMain_Settings.Enabled = false;
this.toolStripMain_Stats.Checked = false;
this.toolStripMain_Stats.Enabled = false;

// Show the board
this.tabGame.SelectedIndex = 0;

// Always reset before starting a new game
_game.ReSet();

// Show the score in the status bar
this.toolStripStatusLabel_Secuence.Text = _game.CurrentScore.ToString();
this.toolStripStatusLabel_Secuence.Invalidate();

if (_game.Start())
{
board1.Visible = true;
if (await board1.Start(_game.GetSequence, _game.TimeTotal) == false)
{
Stop_Click(null, null);
using (new CenterWinDialog(this))
MessageBox.Show("Could not place the buttons on the screen.\nPlease, try reducing the 'numbers ratio' paremeter in\nthe Settings (between 0.25 - 0.30).", "Error placing numbers", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
using (new CenterWinDialog(this))
MessageBox.Show("Could not start the game.\nUnexpected error.", "Error StartClick", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void Stop_Click(object sender, EventArgs e)
{
board1.ClearBoard();
this.toolStripStatusLabel_Secuence.Text = "";
this.toolStripStatusLabel_Secuence.Invalidate();

// Commute visibility of the strip buttons
this.toolStripMain_Start.Enabled = true;
this.toolStripMain_Settings.Enabled = true;
this.toolStripMain_Stats.Enabled = true;

// Update the charts
ChartStatsNumbers_Update();
ChartStatsTime_Update();
}

private void Sound_CheckedChanged(object sender, EventArgs e)
{
this.board1.PlaySounds = !toolStripMain_Sound.Checked;
}

private void Stats_CheckedChanged(object sender, EventArgs e)
{
this.tabGame.SelectedIndex = toolStripMain_Stats.Checked ? 1 : 0;
}

private void Settings_Click(object sender, EventArgs e)
{
FrmSettings form = new(_settings);
form.ShowDialog(this);
if (form.DialogResult == DialogResult.OK)
{
_settings = form.Settings;
ApplySettingsJSON();
}
}

private void About_Click(object sender, EventArgs e)
{
FrmAbout form = new();
form.ShowDialog(this);
}

}
10 changes: 5 additions & 5 deletions MemoryNumbers/clsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public class ClassSettings
[JsonIgnore]
public string FileName { get; set; } = "configuration.json";

/// <summary>
/// Remember window position on start up
/// </summary>
[JsonPropertyName("Window position")]
public bool WindowPosition { get; set; } = true; // Remember window position
/// <summary>
/// Window top-left x coordinate
/// </summary>
Expand Down Expand Up @@ -110,11 +115,6 @@ public class ClassSettings
[JsonPropertyName("Playing mode")]
public int PlayMode { get; set; } = 9; //Fixed time (1) & random sequence (8)
/// <summary>
/// Remember window position on start up
/// </summary>
[JsonPropertyName("Window position")]
public bool WindowPosition { get; set; } = true; // Remember windows position
/// <summary>
/// Sound ToolStrip button cheched?
/// </summary>
[JsonPropertyName("Sound checked")]
Expand Down
2 changes: 1 addition & 1 deletion MemoryNumbers/frmAbout.Designer.cs

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

8 changes: 4 additions & 4 deletions MemoryNumbers/frmAbout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MemoryNumbers;

partial class frmAbout : Form
partial class FrmAbout : Form
{

#region Descriptores de acceso de atributos de ensamblado
Expand All @@ -23,7 +23,7 @@ public string AssemblyTitle
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location);
}
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public string AssemblyCompany

#endregion

public frmAbout()
public FrmAbout()
{
InitializeComponent();
// this.Text = String.Format("About {0}", AssemblyTitle);
Expand All @@ -107,7 +107,7 @@ public frmAbout()
if (System.IO.File.Exists(path + @"\images\[email protected]")) this.logoPictureBox.Image = new Bitmap(path + @"\images\[email protected]");
}

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
//[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override void WndProc(ref Message m)
{
const int WM_PARENTNOTIFY = 0x210;
Expand Down
4 changes: 2 additions & 2 deletions MemoryNumbers/frmMain.Designer.cs

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

Loading

0 comments on commit f720616

Please sign in to comment.