Movies 2.0 - some progress towards supporting floats

This commit is contained in:
adelikat 2014-02-25 02:56:32 +00:00
parent a6176d09e8
commit f714093b23
11 changed files with 69 additions and 90 deletions

View File

@ -21,6 +21,8 @@ namespace BizHawk.Client.Common
} }
} }
public bool IsFloat { get { return true; } }
public void Add(string key, char value) public void Add(string key, char value)
{ {
_controllerMnemonics.Add(key, value); _controllerMnemonics.Add(key, value);

View File

@ -21,12 +21,14 @@ namespace BizHawk.Client.Common
bool IsEmpty { get; } bool IsEmpty { get; }
string MnemonicString { get; } string MnemonicString { get; }
bool IsFloat { get; } // Float or Boolean
/// <summary> /// <summary>
/// Gets a string that represents an empty or default mnemonic /// Gets a string that represents an empty or default mnemonic
/// </summary> /// </summary>
string EmptyMnemonicString { get; } string EmptyMnemonicString { get; }
// Analog TODO: this assumes the Generator is boolean // Analog TODO: this assumes the Generator is boolean, pass an object structure that contains both the boolean and float dictionaries
/// <summary> /// <summary>
/// Parses a segment of a full mnemonic string (the content between pipes) /// Parses a segment of a full mnemonic string (the content between pipes)
/// Note: this assume the pipes are not being passed in! /// Note: this assume the pipes are not being passed in!

View File

@ -34,11 +34,8 @@ namespace BizHawk.Client.Common
Dictionary<string, bool> ParseMnemonicString(string mnemonicStr); Dictionary<string, bool> ParseMnemonicString(string mnemonicStr);
// Analog TODO: this assume the generators are boolean
Dictionary<string, bool> GetBoolButtons(); Dictionary<string, bool> GetBoolButtons();
Dictionary<string, float> GetFloatButtons();
// TODO: this shouldn't be required, refactor MovieRecord
string GenerateMnemonicString(Dictionary<string, bool> buttons);
string EmptyMnemonic { get; } string EmptyMnemonic { get; }

View File

@ -8,7 +8,10 @@ namespace BizHawk.Client.Common
{ {
public class NesMnemonicGenerator : IMnemonicPorts public class NesMnemonicGenerator : IMnemonicPorts
{ {
public NesMnemonicGenerator(IController source, bool fds = false, bool isFourscore = false) private bool _isFds;
private bool _isFourscore;
public NesMnemonicGenerator(IController source, bool fds = false, bool isFourscore = false)
{ {
Source = source; Source = source;
_isFds = fds; _isFds = fds;
@ -33,6 +36,15 @@ namespace BizHawk.Client.Common
#region IMnemonicPorts Implementation #region IMnemonicPorts Implementation
public string EmptyMnemonic
{
get
{
var blah = AvailableGenerators.Select(x => x.EmptyMnemonicString);
return "|" + string.Join("|", blah) + "|";
}
}
public int Count public int Count
{ {
get { return _isFourscore ? 4 : 2; } get { return _isFourscore ? 4 : 2; }
@ -47,7 +59,7 @@ namespace BizHawk.Client.Common
{ {
yield return ConsoleControls; yield return ConsoleControls;
for (int i = 0; i < Count; i++) for (var i = 0; i < Count; i++)
{ {
yield return _controllerPorts[i]; yield return _controllerPorts[i];
} }
@ -99,9 +111,9 @@ namespace BizHawk.Client.Common
public Dictionary<string, bool> ParseMnemonicString(string mnemonicStr) public Dictionary<string, bool> ParseMnemonicString(string mnemonicStr)
{ {
var segments = mnemonicStr.Split('|'); var segments = mnemonicStr.Split('|');
var kvps = new List<KeyValuePair<string,bool>>(); var kvps = new List<KeyValuePair<string, bool>>();
var generators = AvailableGenerators.ToList(); var generators = AvailableGenerators.ToList();
for(int i = 0; i < mnemonicStr.Length; i++) for (var i = 0; i < mnemonicStr.Length; i++)
{ {
kvps.AddRange(generators[i].ParseMnemonicSegment(segments[i])); kvps.AddRange(generators[i].ParseMnemonicSegment(segments[i]));
} }
@ -111,48 +123,18 @@ namespace BizHawk.Client.Common
public Dictionary<string, bool> GetBoolButtons() public Dictionary<string, bool> GetBoolButtons()
{ {
List<IMnemonicGenerator> generators = AvailableGenerators.ToList(); return AvailableGenerators
.Where(g => g.IsFloat)
return generators
.SelectMany(mc => mc.AvailableMnemonics) .SelectMany(mc => mc.AvailableMnemonics)
.ToDictionary(kvp => kvp.Key, kvp => this.Source.IsPressed(kvp.Key)); .ToDictionary(kvp => kvp.Key, kvp => Source.IsPressed(kvp.Key));
} }
// TODO: this shouldn't be required, refactor MovieRecord public Dictionary<string, float> GetFloatButtons()
public string GenerateMnemonicString(Dictionary<string, bool> buttons)
{ {
var mnemonics = AvailableMnemonics; return AvailableGenerators
.Where(g => !g.IsFloat)
var sb = new StringBuilder(); .SelectMany(mc => mc.AvailableMnemonics)
sb.Append('|'); .ToDictionary(kvp => kvp.Key, kvp => Source.GetFloat(kvp.Key));
foreach (var generator in AvailableGenerators)
{
foreach (var blah in generator.AvailableMnemonics)
{
if (buttons.ContainsKey(blah.Key))
{
sb.Append(buttons[blah.Key] ? blah.Value : '.');
}
else
{
sb.Append('.');
}
}
}
sb.Append('|');
return sb.ToString();
}
public string EmptyMnemonic
{
get
{
var blah = AvailableGenerators.Select(x => x.EmptyMnemonicString);
return "|" + String.Join("|", blah) + "|";
}
} }
// TODO: refactor me! // TODO: refactor me!
@ -178,9 +160,6 @@ namespace BizHawk.Client.Common
#region Privates #region Privates
private bool _isFds;
private bool _isFourscore;
private static readonly Dictionary<string, char> _basicController = new Dictionary<string, char> private static readonly Dictionary<string, char> _basicController = new Dictionary<string, char>
{ {
{ "Up", 'U' }, { "Up", 'U' },
@ -202,7 +181,7 @@ namespace BizHawk.Client.Common
} }
) )
{ {
ControllerPrefix = String.Empty ControllerPrefix = string.Empty
}; };
private readonly BooleanControllerMnemonicGenerator _fdsConsoleControls = new BooleanControllerMnemonicGenerator( private readonly BooleanControllerMnemonicGenerator _fdsConsoleControls = new BooleanControllerMnemonicGenerator(
@ -217,7 +196,7 @@ namespace BizHawk.Client.Common
} }
) )
{ {
ControllerPrefix = String.Empty ControllerPrefix = string.Empty
}; };
private readonly List<IMnemonicGenerator> _controllerPorts = private readonly List<IMnemonicGenerator> _controllerPorts =

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
@ -16,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
{ {
base.OnKeyPress(e); base.OnKeyPress(e);
NumberFormatInfo numberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat; var numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
string decimalSeparator = numberFormatInfo.NumberDecimalSeparator; string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;
string groupSeparator = numberFormatInfo.NumberGroupSeparator; string groupSeparator = numberFormatInfo.NumberGroupSeparator;
string negativeSign = numberFormatInfo.NegativeSign; string negativeSign = numberFormatInfo.NegativeSign;

View File

@ -1334,11 +1334,11 @@ namespace BizHawk.Client.EmuHawk
private void GoToAddressMenuItem_Click(object sender, EventArgs e) private void GoToAddressMenuItem_Click(object sender, EventArgs e)
{ {
var inputPrompt = new InputPrompt { Text = "Go to Address", _Location = GetPromptPoint() }; var inputPrompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() };
inputPrompt.SetMessage("Enter a hexadecimal value"); inputPrompt.SetMessage("Enter a hexadecimal value");
inputPrompt.ShowHawkDialog(); inputPrompt.ShowHawkDialog();
if (inputPrompt.UserOK && InputValidate.IsHex(inputPrompt.UserText)) if (inputPrompt.UserOk && InputValidate.IsHex(inputPrompt.UserText))
{ {
GoToAddress(int.Parse(inputPrompt.UserText, NumberStyles.HexNumber)); GoToAddress(int.Parse(inputPrompt.UserText, NumberStyles.HexNumber));
} }

View File

@ -59,7 +59,7 @@
this.OK.TabIndex = 2; this.OK.TabIndex = 2;
this.OK.Text = "&Ok"; this.OK.Text = "&Ok";
this.OK.UseVisualStyleBackColor = true; this.OK.UseVisualStyleBackColor = true;
this.OK.Click += new System.EventHandler(this.OK_Click); this.OK.Click += new System.EventHandler(this.Ok_Click);
// //
// Cancel // Cancel
// //

View File

@ -11,23 +11,19 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
public partial class InputPrompt : Form public partial class InputPrompt : Form
{ {
public enum InputType { HEX, UNSIGNED, SIGNED, TEXT };
public bool UserOK; //Will be true if the user selects Ok
public string UserText = ""; //What the user selected
public Point _Location = new Point(-1, -1);
private InputType itype = InputType.TEXT;
public InputType TextInputType
{
get { return itype; }
set { itype = value; }
}
public InputPrompt() public InputPrompt()
{ {
InitializeComponent(); InitializeComponent();
UserText = string.Empty;
StartLocation = new Point(-1, -1);
} }
public enum InputType { Hex, Unsigned, Signed, Text }
public bool UserOk { get; set; } // Will be true if the user selects Ok
public string UserText { get; set; } // What the user selected
public Point StartLocation { get; set; }
public InputType TextInputType { get; set; }
public void SetMessage(string message) public void SetMessage(string message)
{ {
PromptLabel.Text = message; PromptLabel.Text = message;
@ -50,61 +46,67 @@ namespace BizHawk.Client.EmuHawk
private void InputPrompt_Load(object sender, EventArgs e) private void InputPrompt_Load(object sender, EventArgs e)
{ {
if (_Location.X > 0 && _Location.Y > 0) if (StartLocation.X > 0 && StartLocation.Y > 0)
{ {
Location = _Location; Location = StartLocation;
} }
} }
private void OK_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {
UserOK = true; UserOk = true;
UserText = PromptBox.Text; UserText = PromptBox.Text;
Close(); Close();
} }
private void Cancel_Click(object sender, EventArgs e) private void Cancel_Click(object sender, EventArgs e)
{ {
UserOK = false; UserOk = false;
Close(); Close();
} }
private void PromptBox_KeyPress(object sender, KeyPressEventArgs e) private void PromptBox_KeyPress(object sender, KeyPressEventArgs e)
{ {
switch (itype) switch (TextInputType)
{ {
default: default:
case InputType.TEXT: case InputType.Text:
break; break;
case InputType.HEX: case InputType.Hex:
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{ {
return; return;
} }
else if (!InputValidate.IsHex(e.KeyChar))
if (!InputValidate.IsHex(e.KeyChar))
{ {
e.Handled = true; e.Handled = true;
} }
break; break;
case InputType.SIGNED: case InputType.Signed:
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{ {
return; return;
} }
else if (!InputValidate.IsUnsigned(e.KeyChar))
if (!InputValidate.IsUnsigned(e.KeyChar))
{ {
e.Handled = true; e.Handled = true;
} }
break; break;
case InputType.UNSIGNED: case InputType.Unsigned:
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3) if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{ {
return; return;
} }
else if (!InputValidate.IsSigned(e.KeyChar))
if (!InputValidate.IsSigned(e.KeyChar))
{ {
e.Handled = true; e.Handled = true;
} }
break; break;
} }
} }

View File

@ -1039,7 +1039,7 @@ namespace BizHawk.Client.EmuHawk
InputPrompt gotodialog = new InputPrompt(); InputPrompt gotodialog = new InputPrompt();
gotodialog.FormClosing += (s, a) => gotodialog.FormClosing += (s, a) =>
{ {
if (gotodialog.UserOK) if (gotodialog.UserOk)
{ {
int x; int x;

View File

@ -280,10 +280,10 @@ namespace BizHawk.Client.EmuHawk
var prompt = new InputPrompt(); var prompt = new InputPrompt();
prompt.SetMessage("Max lines to display in the window"); prompt.SetMessage("Max lines to display in the window");
prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString()); prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString());
prompt.TextInputType = InputPrompt.InputType.UNSIGNED; prompt.TextInputType = InputPrompt.InputType.Unsigned;
prompt._Location = GetPromptPoint(); prompt.StartLocation = GetPromptPoint();
prompt.ShowDialog(); prompt.ShowDialog();
if (prompt.UserOK) if (prompt.UserOk)
{ {
var max = int.Parse(prompt.UserText); var max = int.Parse(prompt.UserText);
if (max > 0) if (max > 0)

View File

@ -898,11 +898,11 @@ namespace BizHawk.Client.EmuHawk
private void GoToSpecifiedAddress() private void GoToSpecifiedAddress()
{ {
WatchListView.SelectedIndices.Clear(); WatchListView.SelectedIndices.Clear();
var prompt = new InputPrompt { Text = "Go to Address", _Location = GetPromptPoint() }; var prompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() };
prompt.SetMessage("Enter a hexadecimal value"); prompt.SetMessage("Enter a hexadecimal value");
prompt.ShowHawkDialog(); prompt.ShowHawkDialog();
if (prompt.UserOK) if (prompt.UserOk)
{ {
if (InputValidate.IsHex(prompt.UserText)) if (InputValidate.IsHex(prompt.UserText))
{ {