update controls to support sticky buttons, & force-pressing buttons. implement Soft Reset menu item.

This commit is contained in:
beirich 2011-01-14 03:38:26 +00:00
parent 33f009395f
commit 0d088bb15b
6 changed files with 87 additions and 29 deletions

View File

@ -23,14 +23,14 @@ namespace BizHawk
get { return baseController.Type; }
}
public bool this[string name]
public bool this[string button]
{
get { return baseController[name]; }
get { return baseController[button]; }
}
public bool IsPressed(string name)
public bool IsPressed(string button)
{
return baseController[name];
return baseController[button];
}
public float GetFloat(string name)
@ -43,6 +43,11 @@ namespace BizHawk
baseController.UnpressButton(name);
}
public void ForceButton(string button)
{
baseController.ForceButton(button);
}
private int frame;
public int FrameNumber
{
@ -71,6 +76,16 @@ namespace BizHawk
writer.Seek(frame*2, SeekOrigin.Begin);
writer.Write((ushort)encodedValue);
}
public void SetSticky(string button, bool sticky)
{
baseController.SetSticky(button, sticky);
}
public bool IsSticky(string button)
{
return baseController.IsSticky(button);
}
}
public class InputPlayback : IController
@ -92,19 +107,19 @@ namespace BizHawk
get { return def; }
}
public bool this[string name]
public bool this[string button]
{
get { return IsPressed(name); }
get { return IsPressed(button); }
}
public bool IsPressed(string name)
public bool IsPressed(string button)
{
if (FrameNumber >= input.Length)
return false;
for (int i = 0; i < def.BoolButtons.Count; i++)
{
if (def.BoolButtons[i] == name)
if (def.BoolButtons[i] == button)
{
return (input[FrameNumber] & (1 << i)) != 0;
}
@ -118,6 +133,9 @@ namespace BizHawk
}
public void UnpressButton(string name) {}
public void ForceButton(string button) { }
public void SetSticky(string button, bool sticky) { }
public bool IsSticky(string button) { return false; }
public int FrameNumber { get; set; }
public bool MovieEnded { get { return FrameNumber >= input.Length; } }

View File

@ -3,12 +3,16 @@
public class NullController : IController
{
public ControllerDefinition Type { get { return null; } }
public bool this[string name] { get { return false; } }
public bool IsPressed(string name) { return false; }
public bool this[string button] { get { return false; } }
public bool IsPressed(string button) { return false; }
public float GetFloat(string name) { return 0f; }
public void UnpressButton(string name) { }
public void UnpressButton(string button) { }
public void ForceButton(string button) { }
public int FrameNumber { get; set; }
public void SetSticky(string button, bool sticky) { }
public bool IsSticky(string button) { return false; }
private static NullController nullController = new NullController();
public static NullController GetNullController() { return nullController; }
}

View File

@ -13,10 +13,15 @@ namespace BizHawk
{
ControllerDefinition Type { get; }
bool this[string name] { get; }
bool IsPressed(string name);
bool this[string button] { get; }
bool IsPressed(string button);
float GetFloat(string name);
void UnpressButton(string name);
void SetSticky(string button, bool sticky);
bool IsSticky(string button);
void UnpressButton(string button);
void ForceButton(string button);
int FrameNumber { get; set; }
}

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using BizHawk.Emulation.Sound;
namespace BizHawk.Emulation.Sound
{

View File

@ -7,14 +7,20 @@ namespace BizHawk.MultiClient
{
private ControllerDefinition type;
private Dictionary<string,List<string>> bindings = new Dictionary<string, List<string>>();
private Dictionary<string,bool> stickyButtons = new Dictionary<string, bool>();
private List<string> unpressedButtons = new List<string>();
private List<string> forcePressedButtons = new List<string>();
private List<string> removeFromForcePressedButtons = new List<string>();
public Controller(ControllerDefinition definition)
{
type = definition;
foreach (var b in type.BoolButtons)
{
bindings[b] = new List<string>();
stickyButtons[b] = false;
}
foreach (var f in type.FloatControls)
bindings[f] = new List<string>();
@ -37,31 +43,38 @@ namespace BizHawk.MultiClient
get { return type; }
}
public bool this[string name]
public bool this[string button]
{
get { return IsPressed(name); }
get { return IsPressed(button); }
}
public bool IsPressed(string name)
public bool IsPressed(string button)
{
if (unpressedButtons.Contains(name))
if (forcePressedButtons.Contains(button))
{
if (IsPressedActually(name) == false)
unpressedButtons.Remove(name);
removeFromForcePressedButtons.Add(button);
return true;
}
if (unpressedButtons.Contains(button))
{
if (IsPressedActually(button) == false)
unpressedButtons.Remove(button);
return false;
}
return IsPressedActually(name);
return IsPressedActually(button);
}
private bool IsPressedActually(string name)
private bool IsPressedActually(string button)
{
foreach (var control in bindings[name])
if (Input.IsPressed(control))
return true;
bool sticky = stickyButtons[button];
return false;
foreach (var control in bindings[button])
if (Input.IsPressed(control))
return sticky ? false : true;
return sticky ? true : false;
}
public float GetFloat(string name)
@ -87,9 +100,27 @@ namespace BizHawk.MultiClient
{
// update
unpressedButtons.RemoveAll(button => IsPressedActually(button) == false);
forcePressedButtons.RemoveAll(button => removeFromForcePressedButtons.Contains(button));
removeFromForcePressedButtons.Clear();
}
frameNumber = value;
}
}
public void SetSticky(string button, bool sticky)
{
stickyButtons[button] = sticky;
}
public bool IsSticky(string button)
{
return stickyButtons[button];
}
public void ForceButton(string button)
{
forcePressedButtons.Add(button);
}
}
}
}

View File

@ -395,7 +395,8 @@ namespace BizHawk.MultiClient
private void resetToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains("Reset"))
Global.Emulator.Controller.ForceButton("Reset");
}
private void pauseToolStripMenuItem_Click(object sender, EventArgs e)