Movies 2.0 - some progress towards supporting floats
This commit is contained in:
parent
a6176d09e8
commit
f714093b23
|
@ -21,6 +21,8 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsFloat { get { return true; } }
|
||||
|
||||
public void Add(string key, char value)
|
||||
{
|
||||
_controllerMnemonics.Add(key, value);
|
||||
|
|
|
@ -21,12 +21,14 @@ namespace BizHawk.Client.Common
|
|||
bool IsEmpty { get; }
|
||||
string MnemonicString { get; }
|
||||
|
||||
bool IsFloat { get; } // Float or Boolean
|
||||
|
||||
/// <summary>
|
||||
/// Gets a string that represents an empty or default mnemonic
|
||||
/// </summary>
|
||||
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>
|
||||
/// Parses a segment of a full mnemonic string (the content between pipes)
|
||||
/// Note: this assume the pipes are not being passed in!
|
||||
|
|
|
@ -34,11 +34,8 @@ namespace BizHawk.Client.Common
|
|||
|
||||
Dictionary<string, bool> ParseMnemonicString(string mnemonicStr);
|
||||
|
||||
// Analog TODO: this assume the generators are boolean
|
||||
Dictionary<string, bool> GetBoolButtons();
|
||||
|
||||
// TODO: this shouldn't be required, refactor MovieRecord
|
||||
string GenerateMnemonicString(Dictionary<string, bool> buttons);
|
||||
Dictionary<string, float> GetFloatButtons();
|
||||
|
||||
string EmptyMnemonic { get; }
|
||||
|
||||
|
|
|
@ -8,7 +8,10 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
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;
|
||||
_isFds = fds;
|
||||
|
@ -33,6 +36,15 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region IMnemonicPorts Implementation
|
||||
|
||||
public string EmptyMnemonic
|
||||
{
|
||||
get
|
||||
{
|
||||
var blah = AvailableGenerators.Select(x => x.EmptyMnemonicString);
|
||||
return "|" + string.Join("|", blah) + "|";
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return _isFourscore ? 4 : 2; }
|
||||
|
@ -47,7 +59,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
yield return ConsoleControls;
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
yield return _controllerPorts[i];
|
||||
}
|
||||
|
@ -99,9 +111,9 @@ namespace BizHawk.Client.Common
|
|||
public Dictionary<string, bool> ParseMnemonicString(string mnemonicStr)
|
||||
{
|
||||
var segments = mnemonicStr.Split('|');
|
||||
var kvps = new List<KeyValuePair<string,bool>>();
|
||||
var kvps = new List<KeyValuePair<string, bool>>();
|
||||
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]));
|
||||
}
|
||||
|
@ -111,48 +123,18 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public Dictionary<string, bool> GetBoolButtons()
|
||||
{
|
||||
List<IMnemonicGenerator> generators = AvailableGenerators.ToList();
|
||||
|
||||
return generators
|
||||
return AvailableGenerators
|
||||
.Where(g => g.IsFloat)
|
||||
.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 string GenerateMnemonicString(Dictionary<string, bool> buttons)
|
||||
public Dictionary<string, float> GetFloatButtons()
|
||||
{
|
||||
var mnemonics = AvailableMnemonics;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append('|');
|
||||
|
||||
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) + "|";
|
||||
}
|
||||
return AvailableGenerators
|
||||
.Where(g => !g.IsFloat)
|
||||
.SelectMany(mc => mc.AvailableMnemonics)
|
||||
.ToDictionary(kvp => kvp.Key, kvp => Source.GetFloat(kvp.Key));
|
||||
}
|
||||
|
||||
// TODO: refactor me!
|
||||
|
@ -178,9 +160,6 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Privates
|
||||
|
||||
private bool _isFds;
|
||||
private bool _isFourscore;
|
||||
|
||||
private static readonly Dictionary<string, char> _basicController = new Dictionary<string, char>
|
||||
{
|
||||
{ "Up", 'U' },
|
||||
|
@ -202,7 +181,7 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
)
|
||||
{
|
||||
ControllerPrefix = String.Empty
|
||||
ControllerPrefix = string.Empty
|
||||
};
|
||||
|
||||
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 =
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
|
||||
|
@ -16,7 +13,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
base.OnKeyPress(e);
|
||||
|
||||
NumberFormatInfo numberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
|
||||
var numberFormatInfo = CultureInfo.CurrentCulture.NumberFormat;
|
||||
string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;
|
||||
string groupSeparator = numberFormatInfo.NumberGroupSeparator;
|
||||
string negativeSign = numberFormatInfo.NegativeSign;
|
||||
|
|
|
@ -1334,11 +1334,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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.ShowHawkDialog();
|
||||
|
||||
if (inputPrompt.UserOK && InputValidate.IsHex(inputPrompt.UserText))
|
||||
if (inputPrompt.UserOk && InputValidate.IsHex(inputPrompt.UserText))
|
||||
{
|
||||
GoToAddress(int.Parse(inputPrompt.UserText, NumberStyles.HexNumber));
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
this.OK.TabIndex = 2;
|
||||
this.OK.Text = "&Ok";
|
||||
this.OK.UseVisualStyleBackColor = true;
|
||||
this.OK.Click += new System.EventHandler(this.OK_Click);
|
||||
this.OK.Click += new System.EventHandler(this.Ok_Click);
|
||||
//
|
||||
// Cancel
|
||||
//
|
||||
|
|
|
@ -11,23 +11,19 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
PromptLabel.Text = message;
|
||||
|
@ -50,61 +46,67 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Cancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
UserOK = false;
|
||||
UserOk = false;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void PromptBox_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
switch (itype)
|
||||
switch (TextInputType)
|
||||
{
|
||||
default:
|
||||
case InputType.TEXT:
|
||||
case InputType.Text:
|
||||
break;
|
||||
case InputType.HEX:
|
||||
case InputType.Hex:
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (!InputValidate.IsHex(e.KeyChar))
|
||||
|
||||
if (!InputValidate.IsHex(e.KeyChar))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case InputType.SIGNED:
|
||||
case InputType.Signed:
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (!InputValidate.IsUnsigned(e.KeyChar))
|
||||
|
||||
if (!InputValidate.IsUnsigned(e.KeyChar))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case InputType.UNSIGNED:
|
||||
case InputType.Unsigned:
|
||||
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (!InputValidate.IsSigned(e.KeyChar))
|
||||
|
||||
if (!InputValidate.IsSigned(e.KeyChar))
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1039,7 +1039,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
InputPrompt gotodialog = new InputPrompt();
|
||||
gotodialog.FormClosing += (s, a) =>
|
||||
{
|
||||
if (gotodialog.UserOK)
|
||||
if (gotodialog.UserOk)
|
||||
{
|
||||
int x;
|
||||
|
||||
|
|
|
@ -280,10 +280,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
var prompt = new InputPrompt();
|
||||
prompt.SetMessage("Max lines to display in the window");
|
||||
prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString());
|
||||
prompt.TextInputType = InputPrompt.InputType.UNSIGNED;
|
||||
prompt._Location = GetPromptPoint();
|
||||
prompt.TextInputType = InputPrompt.InputType.Unsigned;
|
||||
prompt.StartLocation = GetPromptPoint();
|
||||
prompt.ShowDialog();
|
||||
if (prompt.UserOK)
|
||||
if (prompt.UserOk)
|
||||
{
|
||||
var max = int.Parse(prompt.UserText);
|
||||
if (max > 0)
|
||||
|
|
|
@ -898,11 +898,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
private void GoToSpecifiedAddress()
|
||||
{
|
||||
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.ShowHawkDialog();
|
||||
|
||||
if (prompt.UserOK)
|
||||
if (prompt.UserOk)
|
||||
{
|
||||
if (InputValidate.IsHex(prompt.UserText))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue