From f0425f3cc5d862f05964492f6a8afcb1d905874e Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 10 Jul 2014 20:40:50 +0000 Subject: [PATCH] TAStudio - input painting for boolean input --- .../movie/bk2/Bk2ControllerAdapter.cs | 13 ++++++- .../movie/bk2/Bk2Movie.InputLog.cs | 2 +- .../movie/tasproj/TasMovie.cs | 39 +++++++++++++++++++ .../tools/TAStudio/TAStudio.ListView.cs | 17 +++++--- .../tools/TAStudio/TAStudio.cs | 2 +- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs index 7b913b16c5..e8a8b7a070 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2ControllerAdapter.cs @@ -41,7 +41,18 @@ namespace BizHawk.Client.Common public bool this[string button] { - get { return MyBoolButtons[button]; } + get + { + return MyBoolButtons[button]; + } + + set + { + if (MyBoolButtons.ContainsKey(button)) + { + MyBoolButtons[button] = value; + } + } } public bool IsPressed(string button) diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs index 8448f08eaf..3b8f4adbb5 100644 --- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs +++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs @@ -8,7 +8,7 @@ namespace BizHawk.Client.Common { public partial class Bk2Movie { - private readonly List _log = new List(); + protected readonly List _log = new List(); private string _logKey = string.Empty; public string GetInputLog() diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 4f01a7fcdd..88dc90513f 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -84,5 +84,44 @@ namespace BizHawk.Client.Common return "!"; } + + public void ToggleBoolState(int frame, string buttonName) + { + if (frame < _log.Count) + { + var adapter = GetInputState(frame) as Bk2ControllerAdapter; + adapter[buttonName] = !adapter.IsPressed(buttonName); + + var lg = LogGeneratorInstance(); + lg.SetSource(adapter); + _log[frame] = lg.GenerateLogEntry(); + Changes = true; + } + } + + public void SetBoolState(int frame, string buttonName, bool val) + { + if (frame < _log.Count) + { + var adapter = GetInputState(frame) as Bk2ControllerAdapter; + var old = adapter[buttonName]; + adapter[buttonName] = val; + + var lg = LogGeneratorInstance(); + lg.SetSource(adapter); + _log[frame] = lg.GenerateLogEntry(); + + if (old != val) + { + Changes = true; + } + } + } + + public bool BoolIsPressed(int frame, string buttonName) + { + var adapter = GetInputState(frame) as Bk2ControllerAdapter; + return adapter.IsPressed(buttonName); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 277b00c63d..b55efe9d2c 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -82,11 +82,18 @@ namespace BizHawk.Client.EmuHawk } else { - //_tas.ToggleButton(TasView.PointedCell.Row.Value, TasView.PointedCell.Column); - TasView.Refresh(); + var frame = TasView.PointedCell.Row.Value; + var buttonName = TasView.PointedCell.Column; - _startDrawColumn = TasView.PointedCell.Column; - //_startOn = _tas.IsPressed(TasView.PointedCell.Row.Value, TasView.PointedCell.Column); + // TODO: if float, store the original value and copy that on cell chaned + if (Global.MovieSession.MovieControllerAdapter.Type.BoolButtons.Contains(buttonName)) + { + _tas.ToggleBoolState(TasView.PointedCell.Row.Value, TasView.PointedCell.Column); + TasView.Refresh(); + + _startDrawColumn = TasView.PointedCell.Column; + _startOn = _tas.BoolIsPressed(frame, buttonName); + } } } } @@ -131,7 +138,7 @@ namespace BizHawk.Client.EmuHawk } else if (TasView.IsPaintDown && e.NewCell.Row.HasValue && !string.IsNullOrEmpty(_startDrawColumn)) { - //_tas.SetBoolButton(e.NewCell.Row.Value, _startDrawColumn, /*_startOn*/ false); // Notice it uses new row, old column, you can only paint across a single column + _tas.SetBoolState(e.NewCell.Row.Value, _startDrawColumn, _startOn); // Notice it uses new row, old column, you can only paint across a single column TasView.Refresh(); } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index dba41bd96a..6b0056023d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -24,7 +24,7 @@ namespace BizHawk.Client.EmuHawk // Input Painting private string _startDrawColumn = string.Empty; - //private bool _startOn; + private bool _startOn; private bool _startMarkerDrag; private bool _startFrameDrag;