2016-03-26 22:07:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.ApiHawk
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class holds a converter for BizHawk joypad buttons (which is a simple <see cref="string"/>
|
|
|
|
|
/// It allows you to convert it to a <see cref="JoypadButton"/> value and vice versa
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>I made it this way just in case one day we need it for WPF (DependencyProperty binding). Just uncomment :IValueConverter implementation
|
|
|
|
|
/// I didn't implemented it because of mono compatibility
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public sealed class JoypadStringToEnumConverter //:IValueConverter
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert BizHawk button <see cref="string"/> to <see cref="JoypadButton"/> value
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"><see cref="string"/> you want to convert</param>
|
|
|
|
|
/// <param name="targetType">The type of the binding target property</param>
|
|
|
|
|
/// <param name="parameter">The converter parameter to use; null in our case</param>
|
|
|
|
|
/// <param name="cultureInfo">The culture to use in the converter</param>
|
|
|
|
|
/// <returns>A <see cref="JoypadButton"/> that is equivalent to BizHawk <see cref="string"/> button</returns>
|
|
|
|
|
/// <exception cref="IndexOutOfRangeException">Thrown when SystemId hasn't been found</exception>
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
|
|
|
|
|
{
|
|
|
|
|
switch (((string)value).ToUpper())
|
|
|
|
|
{
|
|
|
|
|
case "A":
|
|
|
|
|
return JoypadButton.A;
|
|
|
|
|
|
|
|
|
|
case "B":
|
2016-04-06 20:10:36 +00:00
|
|
|
|
return JoypadButton.B;
|
|
|
|
|
|
|
|
|
|
case "B1":
|
|
|
|
|
return JoypadButton.B1;
|
|
|
|
|
|
|
|
|
|
case "B2":
|
|
|
|
|
return JoypadButton.B2;
|
|
|
|
|
|
|
|
|
|
case "C":
|
|
|
|
|
return JoypadButton.C;
|
|
|
|
|
|
|
|
|
|
case "C UP":
|
|
|
|
|
return JoypadButton.CUp;
|
|
|
|
|
|
|
|
|
|
case "C DOWN":
|
|
|
|
|
return JoypadButton.CDown;
|
|
|
|
|
|
|
|
|
|
case "C LEFT":
|
|
|
|
|
return JoypadButton.CLeft;
|
|
|
|
|
|
|
|
|
|
case "C RIGHT":
|
|
|
|
|
return JoypadButton.CRight;
|
|
|
|
|
|
|
|
|
|
case "X":
|
|
|
|
|
return JoypadButton.X;
|
|
|
|
|
|
|
|
|
|
case "Y":
|
|
|
|
|
return JoypadButton.Y;
|
|
|
|
|
|
|
|
|
|
case "Z":
|
|
|
|
|
return JoypadButton.Z;
|
2016-03-26 22:07:44 +00:00
|
|
|
|
|
|
|
|
|
case "START":
|
|
|
|
|
return JoypadButton.Start;
|
|
|
|
|
|
|
|
|
|
case "SELECT":
|
|
|
|
|
return JoypadButton.Select;
|
|
|
|
|
|
|
|
|
|
case "UP":
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case "DPAD U":
|
2016-03-26 22:07:44 +00:00
|
|
|
|
return JoypadButton.Up;
|
|
|
|
|
|
|
|
|
|
case "DOWN":
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case "DPAD D":
|
2016-03-26 22:07:44 +00:00
|
|
|
|
return JoypadButton.Down;
|
|
|
|
|
|
|
|
|
|
case "LEFT":
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case "DPAD L":
|
2016-03-26 22:07:44 +00:00
|
|
|
|
return JoypadButton.Left;
|
|
|
|
|
|
|
|
|
|
case "RIGHT":
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case "DPAD R":
|
2016-03-26 22:07:44 +00:00
|
|
|
|
return JoypadButton.Right;
|
|
|
|
|
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case "L":
|
|
|
|
|
return JoypadButton.L;
|
|
|
|
|
|
|
|
|
|
case "R":
|
|
|
|
|
return JoypadButton.R;
|
|
|
|
|
|
2016-03-26 22:07:44 +00:00
|
|
|
|
default:
|
|
|
|
|
throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert BizHawk button <see cref="string"/> to <see cref="JoypadButton"/> value
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"><see cref="string"/> you want to convert</param>
|
|
|
|
|
/// <returns>A <see cref="JoypadButton"/> that is equivalent to BizHawk <see cref="string"/> button</returns>
|
|
|
|
|
/// <exception cref="IndexOutOfRangeException">Thrown when SystemId hasn't been found</exception>
|
|
|
|
|
public JoypadButton Convert(string value)
|
|
|
|
|
{
|
|
|
|
|
return (JoypadButton)Convert(value, null, null, CultureInfo.CurrentCulture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a <see cref="JoypadButton"/> value to BizHawk <see cref="string"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"><see cref="JoypadButton"/> you want to convert</param>
|
|
|
|
|
/// <param name="targetType">The type of the binding target property</param>
|
|
|
|
|
/// <param name="parameter">In our case, we pass the <see cref="SystemInfo"/></param>
|
|
|
|
|
/// <param name="cultureInfo">The culture to use in the converter</param>
|
|
|
|
|
/// <returns>A <see cref="string"/> that is used by BizHawk</returns>
|
|
|
|
|
/// <exception cref="IndexOutOfRangeException">Thrown when <see cref="JoypadButton"/> hasn't been found</exception>
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
|
|
|
|
|
{
|
|
|
|
|
switch ((JoypadButton)value)
|
|
|
|
|
{
|
|
|
|
|
case JoypadButton.A:
|
|
|
|
|
return "A";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.B:
|
|
|
|
|
return "B";
|
|
|
|
|
|
2016-04-06 20:10:36 +00:00
|
|
|
|
case JoypadButton.B1:
|
|
|
|
|
return "B1";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.B2:
|
|
|
|
|
return "B2";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.C:
|
|
|
|
|
return "C";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.CUp:
|
|
|
|
|
return "C Up";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.CDown:
|
|
|
|
|
return "C Down";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.CLeft:
|
|
|
|
|
return "C Left";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.CRight:
|
|
|
|
|
return "C Right";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.X:
|
|
|
|
|
return "X";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.Y:
|
|
|
|
|
return "Y";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.Z:
|
|
|
|
|
return "Z";
|
|
|
|
|
|
2016-03-26 22:07:44 +00:00
|
|
|
|
case JoypadButton.Start:
|
|
|
|
|
return "Start";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.Select:
|
|
|
|
|
return "Select";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.Up:
|
2016-04-06 20:10:36 +00:00
|
|
|
|
if (((SystemInfo)parameter) == SystemInfo.N64)
|
|
|
|
|
{
|
|
|
|
|
return "Dpad U";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Up";
|
|
|
|
|
}
|
2016-03-26 22:07:44 +00:00
|
|
|
|
|
|
|
|
|
case JoypadButton.Down:
|
2016-04-06 20:10:36 +00:00
|
|
|
|
if (((SystemInfo)parameter) == SystemInfo.N64)
|
|
|
|
|
{
|
|
|
|
|
return "Dpad D";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Down";
|
|
|
|
|
}
|
2016-03-26 22:07:44 +00:00
|
|
|
|
|
|
|
|
|
case JoypadButton.Left:
|
2016-04-06 20:10:36 +00:00
|
|
|
|
if (((SystemInfo)parameter) == SystemInfo.N64)
|
|
|
|
|
{
|
|
|
|
|
return "Dpad L";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Left";
|
|
|
|
|
}
|
2016-03-26 22:07:44 +00:00
|
|
|
|
|
|
|
|
|
case JoypadButton.Right:
|
2016-04-06 20:10:36 +00:00
|
|
|
|
if (((SystemInfo)parameter) == SystemInfo.N64)
|
|
|
|
|
{
|
|
|
|
|
return "Dpad R";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return "Right";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case JoypadButton.L:
|
|
|
|
|
return "L";
|
|
|
|
|
|
|
|
|
|
case JoypadButton.R:
|
|
|
|
|
return "R";
|
2016-03-26 22:07:44 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new IndexOutOfRangeException(string.Format("{0} is missing in convert list", value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convert a <see cref="JoypadButton"/> value to BizHawk <see cref="string"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="button"><see cref="JoypadButton"/> you want to convert</param>
|
|
|
|
|
/// <param name="system">Current <see cref="SystemInfo"/></param>
|
|
|
|
|
/// <returns>A <see cref="string"/> that is used by BizHawk</returns>
|
|
|
|
|
/// <exception cref="IndexOutOfRangeException">Thrown when <see cref="JoypadButton"/> hasn't been found</exception>
|
|
|
|
|
public string ConvertBack(JoypadButton button, SystemInfo system)
|
|
|
|
|
{
|
|
|
|
|
return (string)ConvertBack(button, null, system, CultureInfo.CurrentCulture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|