cleanup NDS Settings dialog code
This commit is contained in:
parent
8161066632
commit
85fcb99717
BizHawk.Client.EmuHawk
BizHawk.Emulation.Cores/Consoles/Nintendo/NDS
|
@ -25,6 +25,7 @@ using BizHawk.Emulation.Cores.Computers.Commodore64;
|
|||
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
||||
using BizHawk.Emulation.Cores.Computers.SinclairSpectrum;
|
||||
using BizHawk.Emulation.Cores.Computers.AmstradCPC;
|
||||
using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS;
|
||||
using BizHawk.Emulation.Cores.Intellivision;
|
||||
using BizHawk.Emulation.Cores.Sony.PSX;
|
||||
|
||||
|
@ -2027,13 +2028,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void NDSSettingsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult result = new NDSSettings().ShowDialog();
|
||||
if (result == DialogResult.OK)
|
||||
GlobalWin.OSD.AddMessage("Settings saved.");
|
||||
else if (result == DialogResult.Yes)
|
||||
FlagNeedsReboot();
|
||||
else
|
||||
GlobalWin.OSD.AddMessage("Settings aborted.");
|
||||
if (Emulator is MelonDS ds)
|
||||
{
|
||||
using var form = new NdsSettings(this, ds.GetSyncSettings().Clone());
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
partial class NDSSettings
|
||||
partial class NdsSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
|
@ -71,7 +71,7 @@
|
|||
this.btnCancel.TabIndex = 1;
|
||||
this.btnCancel.Text = "Cancel";
|
||||
this.btnCancel.UseVisualStyleBackColor = true;
|
||||
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
|
||||
this.btnCancel.Click += new System.EventHandler(this.CancelBtn_Click);
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
|
@ -82,7 +82,7 @@
|
|||
this.btnSave.TabIndex = 1;
|
||||
this.btnSave.Text = "Save";
|
||||
this.btnSave.UseVisualStyleBackColor = true;
|
||||
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
|
||||
this.btnSave.Click += new System.EventHandler(this.SaveBtn_Click);
|
||||
//
|
||||
// txtName
|
||||
//
|
||||
|
@ -206,7 +206,7 @@
|
|||
this.btnDefault.TabIndex = 1;
|
||||
this.btnDefault.Text = "Default";
|
||||
this.btnDefault.UseVisualStyleBackColor = true;
|
||||
this.btnDefault.Click += new System.EventHandler(this.btnDefault_Click);
|
||||
this.btnDefault.Click += new System.EventHandler(this.DefaultBtn_Click);
|
||||
//
|
||||
// dtpStartupTime
|
||||
//
|
||||
|
@ -248,7 +248,7 @@
|
|||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.MinimumSize = new System.Drawing.Size(251, 249);
|
||||
this.Name = "NDSSettings";
|
||||
this.Name = "NdsSettings";
|
||||
this.ShowIcon = false;
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "NDS Settings";
|
||||
|
|
|
@ -1,60 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
public partial class NDSSettings : Form
|
||||
public partial class NdsSettings : Form
|
||||
{
|
||||
public NDSSettings()
|
||||
private readonly MainForm _mainForm;
|
||||
private readonly MelonDS.MelonSyncSettings _syncSettings;
|
||||
|
||||
public NdsSettings(
|
||||
MainForm mainForm,
|
||||
MelonDS.MelonSyncSettings syncSettings)
|
||||
{
|
||||
_mainForm = mainForm;
|
||||
_syncSettings = syncSettings;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
MelonDS.MelonSyncSettings syncSettings;
|
||||
|
||||
private void NDSSettings_Load(object sender, EventArgs e)
|
||||
{
|
||||
syncSettings = Global.Config.GetCoreSyncSettings<MelonDS>() as MelonDS.MelonSyncSettings;
|
||||
|
||||
chkBootToFirmware.Checked = syncSettings.bootToFirmware;
|
||||
txtName.Text = syncSettings.nickname;
|
||||
cbxFavColor.SelectedIndex = syncSettings.favoriteColor;
|
||||
numBirthDay.Value = syncSettings.birthdayDay;
|
||||
numBirthMonth.Value = syncSettings.birthdayMonth;
|
||||
dtpStartupTime.Value = DateTimeOffset.FromUnixTimeSeconds(syncSettings.timeAtBoot).UtcDateTime;
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
syncSettings.bootToFirmware = chkBootToFirmware.Checked;
|
||||
syncSettings.nickname = txtName.Text;
|
||||
syncSettings.favoriteColor = (byte)cbxFavColor.SelectedIndex;
|
||||
syncSettings.birthdayDay = (byte)numBirthDay.Value;
|
||||
syncSettings.birthdayMonth = (byte)numBirthMonth.Value;
|
||||
// Converting to local time is necessary, because user-set values are "unspecified" which ToUnixTimeSeconds assumes are local.
|
||||
// But ToLocalTime assumes these are UTC. So here we are adding and then subtracting the UTC-to-local offset.
|
||||
syncSettings.timeAtBoot = (uint)new DateTimeOffset(dtpStartupTime.Value.ToLocalTime()).ToUnixTimeSeconds();
|
||||
|
||||
Global.Config.PutCoreSyncSettings<MelonDS>(syncSettings);
|
||||
bool reboot = (Global.Emulator as MelonDS).PutSyncSettings(syncSettings);
|
||||
DialogResult = reboot ? DialogResult.Yes : DialogResult.OK;
|
||||
Close();
|
||||
chkBootToFirmware.Checked = _syncSettings.bootToFirmware;
|
||||
txtName.Text = _syncSettings.nickname;
|
||||
cbxFavColor.SelectedIndex = _syncSettings.favoriteColor;
|
||||
numBirthDay.Value = _syncSettings.birthdayDay;
|
||||
numBirthMonth.Value = _syncSettings.birthdayMonth;
|
||||
dtpStartupTime.Value = DateTimeOffset.FromUnixTimeSeconds(_syncSettings.timeAtBoot).UtcDateTime;
|
||||
}
|
||||
|
||||
private void numBirthMonth_ValueChanged(object sender, EventArgs e)
|
||||
|
@ -82,14 +54,36 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void btnDefault_Click(object sender, EventArgs e)
|
||||
private void CancelBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Revert to and save default settings?", "default settings", MessageBoxButtons.OKCancel) == DialogResult.OK)
|
||||
_mainForm.AddOnScreenMessage("Core emulator settings aborted");
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void SaveBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
_syncSettings.bootToFirmware = chkBootToFirmware.Checked;
|
||||
_syncSettings.nickname = txtName.Text;
|
||||
_syncSettings.favoriteColor = (byte)cbxFavColor.SelectedIndex;
|
||||
_syncSettings.birthdayDay = (byte)numBirthDay.Value;
|
||||
_syncSettings.birthdayMonth = (byte)numBirthMonth.Value;
|
||||
|
||||
// Converting to local time is necessary, because user-set values are "unspecified" which ToUnixTimeSeconds assumes are local.
|
||||
// But ToLocalTime assumes these are UTC. So here we are adding and then subtracting the UTC-to-local offset.
|
||||
_syncSettings.timeAtBoot = (uint)new DateTimeOffset(dtpStartupTime.Value.ToLocalTime()).ToUnixTimeSeconds();
|
||||
|
||||
_mainForm.PutCoreSyncSettings(_syncSettings);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void DefaultBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Revert to and save default settings?", "default settings", MessageBoxButtons.OKCancel).IsOk())
|
||||
{
|
||||
bool reboot = (Global.Emulator as MelonDS).PutSyncSettings(null);
|
||||
syncSettings = (Global.Emulator as MelonDS).GetSyncSettings();
|
||||
Global.Config.PutCoreSyncSettings<MelonDS>(syncSettings);
|
||||
DialogResult = reboot ? DialogResult.Yes : DialogResult.OK;
|
||||
_mainForm.PutCoreSyncSettings(new MelonDS.MelonSyncSettings());
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
|||
userSettings = new byte[userSettingsLength];
|
||||
}
|
||||
|
||||
public MelonSyncSettings Clone() => (MelonSyncSettings)MemberwiseClone();
|
||||
|
||||
public bool bootToFirmware = false;
|
||||
public uint timeAtBoot = 946684800; // 2000-01-01 00:00:00 (earliest date possible on a DS)
|
||||
public byte[] userSettings;
|
||||
|
@ -91,19 +93,23 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
|||
get => userSettings[2];
|
||||
set { userSettings[2] = value; }
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public byte birthdayMonth
|
||||
{
|
||||
get => userSettings[3];
|
||||
set { userSettings[3] = value; }
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public byte birthdayDay
|
||||
{
|
||||
get => userSettings[4];
|
||||
set { userSettings[4] = value; }
|
||||
}
|
||||
|
||||
const int maxNicknameLength = 10;
|
||||
|
||||
[JsonIgnore]
|
||||
public string nickname
|
||||
{
|
||||
|
@ -125,6 +131,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
|||
userSettings[0x1A] = (byte)value.Length;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public short nicknameLength => userSettings[0x1A];
|
||||
|
||||
|
@ -132,7 +139,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
|
|||
public long rtcOffset
|
||||
{
|
||||
get => BitConverter.ToInt64(userSettings, 0x68);
|
||||
set { BitConverter.GetBytes(value).CopyTo(userSettings, 0x68); }
|
||||
set => BitConverter.GetBytes(value).CopyTo(userSettings, 0x68);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue