Tastudio - implement Floating window and refactor to use ToolDialogSettings object

This commit is contained in:
adelikat 2014-02-01 15:44:51 +00:00
parent 89f9cfc711
commit 50a879dd05
3 changed files with 110 additions and 82 deletions

View File

@ -445,14 +445,9 @@ namespace BizHawk.Client.Common
#endregion
// TAStudio Dialog
public bool TAStudioSaveWindowPosition = true;
public ToolDialogSettings TAStudioSettings = new ToolDialogSettings();
public bool AutoloadTAStudio = false;
public bool AutoloadTAStudioProject = false;
public bool TAStudioTopMost = false;
public int TASWndx = -1;
public int TASWndy = -1;
public int TASWidth = -1;
public int TASHeight = -1;
public bool TAStudioDrawInput = true;
public RecentFiles RecentTas = new RecentFiles(8);

View File

@ -107,6 +107,7 @@ namespace BizHawk.Client.EmuHawk
this.SplicerStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.TasPlaybackBox = new BizHawk.Client.EmuHawk.PlaybackBox();
this.TasBookmarksBranchesBox = new BizHawk.Client.EmuHawk.BookmarksBranchesBox();
this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.TASMenu.SuspendLayout();
this.TasStatusStrip.SuspendLayout();
this.SuspendLayout();
@ -166,7 +167,7 @@ namespace BizHawk.Client.EmuHawk
this.SaveTASMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
this.SaveTASMenuItem.Size = new System.Drawing.Size(186, 22);
this.SaveTASMenuItem.Text = "&Save";
this.SaveTASMenuItem.Click += new System.EventHandler(this.SaveTASMenuItem_Click);
this.SaveTASMenuItem.Click += new System.EventHandler(this.SaveTasMenuItem_Click);
//
// SaveAsTASMenuItem
//
@ -175,7 +176,7 @@ namespace BizHawk.Client.EmuHawk
| System.Windows.Forms.Keys.S)));
this.SaveAsTASMenuItem.Size = new System.Drawing.Size(186, 22);
this.SaveAsTASMenuItem.Text = "Save As";
this.SaveAsTASMenuItem.Click += new System.EventHandler(this.SaveAsTASMenuItem_Click);
this.SaveAsTASMenuItem.Click += new System.EventHandler(this.SaveAsTasMenuItem_Click);
//
// RecentSubMenu
//
@ -581,6 +582,7 @@ namespace BizHawk.Client.EmuHawk
this.AutoloadProjectMenuItem,
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem,
this.toolStripSeparator12,
this.RestoreDefaultSettingsMenuItem});
this.SettingsSubMenu.Name = "SettingsSubMenu";
@ -657,11 +659,12 @@ namespace BizHawk.Client.EmuHawk
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(155, 22);
this.aboutToolStripMenuItem.Text = "&About";
//
// TASView
// TasView
//
this.TasView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TasView.BlazingFast = false;
this.TasView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Frame,
this.Log});
@ -671,15 +674,15 @@ namespace BizHawk.Client.EmuHawk
this.TasView.InputPaintingMode = false;
this.TasView.ItemCount = 0;
this.TasView.Location = new System.Drawing.Point(8, 27);
this.TasView.Name = "TASView";
this.TasView.Name = "TasView";
this.TasView.selectedItem = -1;
this.TasView.Size = new System.Drawing.Size(288, 471);
this.TasView.TabIndex = 1;
this.TasView.UseCompatibleStateImageBehavior = false;
this.TasView.View = System.Windows.Forms.View.Details;
this.TasView.SelectedIndexChanged += new System.EventHandler(this.TASView_SelectedIndexChanged);
this.TasView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TASView_MouseDown);
this.TasView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TASView_MouseUp);
this.TasView.SelectedIndexChanged += new System.EventHandler(this.TasView_SelectedIndexChanged);
this.TasView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseDown);
this.TasView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseUp);
//
// Frame
//
@ -730,6 +733,13 @@ namespace BizHawk.Client.EmuHawk
this.TasBookmarksBranchesBox.Size = new System.Drawing.Size(204, 343);
this.TasBookmarksBranchesBox.TabIndex = 7;
//
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22);
this.FloatingWindowMenuItem.Text = "Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
//
// TAStudio
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -834,5 +844,6 @@ namespace BizHawk.Client.EmuHawk
private PlaybackBox TasPlaybackBox;
private BookmarksBranchesBox TasBookmarksBranchesBox;
private System.Windows.Forms.ToolStripStatusLabel SplicerStatusLabel;
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
}
}

View File

@ -12,30 +12,29 @@ namespace BizHawk.Client.EmuHawk
public partial class TAStudio : Form, IToolForm
{
// TODO: UI flow that conveniently allows to start from savestate
private const string MarkerColumnName = "MarkerColumn";
private const string FrameColumnName = "FrameColumn";
private readonly MarkerList _markers = new MarkerList();
private readonly List<TasClipboardEntry> _tasClipboard = new List<TasClipboardEntry>();
private int _defaultWidth;
private int _defaultHeight;
private TasMovie _tas;
private MarkerList _markers = new MarkerList();
private List<TasClipboardEntry> TasClipboard = new List<TasClipboardEntry>();
// Input Painting
private string StartDrawColumn = String.Empty;
private bool StartOn = false;
private bool StartMarkerDrag = false;
private bool StartFrameDrag = false;
private string _startDrawColumn = string.Empty;
private bool _startOn;
private bool _startMarkerDrag;
private bool _startFrameDrag;
#region API
public TAStudio()
{
InitializeComponent();
TasView.QueryItemText += TASView_QueryItemText;
TasView.QueryItemBkColor += TASView_QueryItemBkColor;
TasView.QueryItemText += TasView_QueryItemText;
TasView.QueryItemBkColor += TasView_QueryItemBkColor;
TasView.VirtualMode = true;
Closing += (o, e) =>
{
@ -55,9 +54,9 @@ namespace BizHawk.Client.EmuHawk
}
};
TopMost = Global.Config.TAStudioTopMost;
TopMost = Global.Config.TAStudioSettings.TopMost;
TasView.InputPaintingMode = Global.Config.TAStudioDrawInput;
TasView.PointedCellChanged += TASView_PointedCellChanged;
TasView.PointedCellChanged += TasView_PointedCellChanged;
}
public bool AskSave()
@ -69,7 +68,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Sound.StartSound();
if (result == DialogResult.Yes)
{
SaveTASMenuItem_Click(null, null);
SaveTasMenuItem_Click(null, null);
}
else if (result == DialogResult.No)
{
@ -80,7 +79,6 @@ namespace BizHawk.Client.EmuHawk
{
return false;
}
}
return true;
@ -119,7 +117,7 @@ namespace BizHawk.Client.EmuHawk
#endregion
private void TASView_QueryItemBkColor(int index, int column, ref Color color)
private void TasView_QueryItemBkColor(int index, int column, ref Color color)
{
var record = _tas[index];
if (_markers.CurrentFrame == index + 1)
@ -136,7 +134,7 @@ namespace BizHawk.Client.EmuHawk
}
}
private void TASView_QueryItemText(int index, int column, out string text)
private void TasView_QueryItemText(int index, int column, out string text)
{
try
{
@ -254,23 +252,23 @@ namespace BizHawk.Client.EmuHawk
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.TAStudioSaveWindowPosition && Global.Config.TASWndx >= 0 && Global.Config.TASWndy >= 0)
if (Global.Config.TAStudioSettings.UseWindowPosition)
{
Location = new Point(Global.Config.TASWndx, Global.Config.TASWndy);
Location = Global.Config.TAStudioSettings.WindowPosition;
}
if (Global.Config.TASWidth >= 0 && Global.Config.TASHeight >= 0)
if (Global.Config.TAStudioSettings.UseWindowSize)
{
Size = new Size(Global.Config.TASWidth, Global.Config.TASHeight);
Size = Global.Config.TAStudioSettings.WindowSize;
}
}
private void SaveConfigSettings()
{
Global.Config.TASWndx = Location.X;
Global.Config.TASWndy = Location.Y;
Global.Config.TASWidth = Right - Left;
Global.Config.TASHeight = Bottom - Top;
Global.Config.TAStudioSettings.Wndx = Location.X;
Global.Config.TAStudioSettings.Wndy = Location.Y;
Global.Config.TAStudioSettings.Width = Right - Left;
Global.Config.TAStudioSettings.Height = Bottom - Top;
}
public void LoadFileFromRecent(string path)
@ -293,12 +291,11 @@ namespace BizHawk.Client.EmuHawk
private void GoToFrame(int frame)
{
//If past greenzone, emulate and capture states
//if past greenzone AND movie, record input and capture states
//If in greenzone, loadstate
//If near a greenzone item, load and emulate
//Do capturing and recording as needed
// If past greenzone, emulate and capture states
// If past greenzone AND movie, record input and capture states
// If in greenzone, loadstate
// If near a greenzone item, load and emulate
// Do capturing and recording as needed
if (_tas[frame - 1].HasState) // Go back 1 frame and emulate
{
_tas.SwitchToPlay();
@ -310,7 +307,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
//Find the earliest frame before this state
// Find the earliest frame before this state
}
}
@ -318,30 +315,35 @@ namespace BizHawk.Client.EmuHawk
{
// TODO: columns selected
// TODO: clipboard
ListView.SelectedIndexCollection list = TasView.SelectedIndices;
string message = String.Empty;
var list = TasView.SelectedIndices;
var message = string.Empty;
if (list.Count > 0)
{
message = list.Count.ToString() + " rows, 0 col, clipboard: ";
message = list.Count + " rows, 0 col, clipboard: ";
}
else
{
message = list.Count.ToString() + " selected: none, clipboard: ";
message = list.Count + " selected: none, clipboard: ";
}
message += TasClipboard.Any() ? TasClipboard.Count.ToString() : "empty";
message += _tasClipboard.Any() ? _tasClipboard.Count.ToString() : "empty";
SplicerStatusLabel.Text = message;
}
private void RefreshFloatingWindowControl()
{
Owner = Global.Config.TAStudioSettings.FloatingWindow ? null : GlobalWin.MainForm;
}
#region Events
#region File Menu
private void FileSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveTASMenuItem.Enabled = !String.IsNullOrWhiteSpace(_tas.Filename);
SaveTASMenuItem.Enabled = !string.IsNullOrWhiteSpace(_tas.Filename);
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
@ -374,11 +376,11 @@ namespace BizHawk.Client.EmuHawk
}
}
private void SaveTASMenuItem_Click(object sender, EventArgs e)
private void SaveTasMenuItem_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(_tas.Filename))
if (string.IsNullOrEmpty(_tas.Filename))
{
SaveAsTASMenuItem_Click(sender, e);
SaveAsTasMenuItem_Click(sender, e);
}
else
{
@ -387,7 +389,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: inform the user it happened somehow
}
private void SaveAsTASMenuItem_Click(object sender, EventArgs e)
private void SaveAsTasMenuItem_Click(object sender, EventArgs e)
{
var file = ToolHelpers.GetTasProjSaveFileFromUser(_tas.Filename);
if (file != null)
@ -420,11 +422,11 @@ namespace BizHawk.Client.EmuHawk
private void CopyMenuItem_Click(object sender, EventArgs e)
{
TasClipboard.Clear();
ListView.SelectedIndexCollection list = TasView.SelectedIndices;
for (int i = 0; i < list.Count; i++)
_tasClipboard.Clear();
var list = TasView.SelectedIndices;
for (var i = 0; i < list.Count; i++)
{
TasClipboard.Add(new TasClipboardEntry(list[i], _tas[i].Buttons));
_tasClipboard.Add(new TasClipboardEntry(list[i], _tas[i].Buttons));
}
SetSplicer();
@ -436,10 +438,11 @@ namespace BizHawk.Client.EmuHawk
private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveWindowPositionMenuItem.Checked = Global.Config.TAStudioSaveWindowPosition;
SaveWindowPositionMenuItem.Checked = Global.Config.TAStudioSettings.SaveWindowPosition;
AutoloadMenuItem.Checked = Global.Config.AutoloadTAStudio;
AutoloadProjectMenuItem.Checked = Global.Config.AutoloadTAStudioProject;
AlwaysOnTopMenuItem.Checked = Global.Config.TAStudioTopMost;
AlwaysOnTopMenuItem.Checked = Global.Config.TAStudioSettings.TopMost;
FloatingWindowMenuItem.Checked = Global.Config.TAStudioSettings.FloatingWindow;
}
private void AutoloadMenuItem_Click(object sender, EventArgs e)
@ -454,20 +457,29 @@ namespace BizHawk.Client.EmuHawk
private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TAStudioSaveWindowPosition ^= true;
Global.Config.TAStudioSettings.SaveWindowPosition ^= true;
}
private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TAStudioTopMost ^= true;
Global.Config.TAStudioSettings.TopMost ^= true;
}
private void FloatingWindowMenuItem_Click(object sender, EventArgs e)
{
Global.Config.TAStudioSettings.FloatingWindow ^= true;
RefreshFloatingWindowControl();
}
private void RestoreDefaultSettingsMenuItem_Click(object sender, EventArgs e)
{
Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.TAStudioSaveWindowPosition = true;
Global.Config.TAStudioTopMost = true;
Global.Config.TAStudioSettings.SaveWindowPosition = true;
Global.Config.TAStudioSettings.TopMost = false;
Global.Config.TAStudioSettings.FloatingWindow = false;
RefreshFloatingWindowControl();
}
#endregion
@ -476,50 +488,50 @@ namespace BizHawk.Client.EmuHawk
private void OnMovieChanged(object sender, MovieRecord.InputEventArgs e)
{
//TODO: move logic needs to go here
// TODO: move logic needs to go here
TasView.ItemCount = _tas.InputLogLength;
}
private void TASView_MouseDown(object sender, MouseEventArgs e)
private void TasView_MouseDown(object sender, MouseEventArgs e)
{
if (TasView.PointedCell.Row.HasValue && !String.IsNullOrEmpty(TasView.PointedCell.Column))
if (TasView.PointedCell.Row.HasValue && !string.IsNullOrEmpty(TasView.PointedCell.Column))
{
if (TasView.PointedCell.Column == MarkerColumnName)
{
StartMarkerDrag = true;
_startMarkerDrag = true;
}
else if (TasView.PointedCell.Column == FrameColumnName)
{
StartFrameDrag = true;
_startFrameDrag = true;
}
else
{
_tas.ToggleButton(TasView.PointedCell.Row.Value, TasView.PointedCell.Column);
TasView.Refresh();
StartDrawColumn = TasView.PointedCell.Column;
StartOn = _tas.IsPressed(TasView.PointedCell.Row.Value, TasView.PointedCell.Column);
_startDrawColumn = TasView.PointedCell.Column;
_startOn = _tas.IsPressed(TasView.PointedCell.Row.Value, TasView.PointedCell.Column);
}
}
}
private void TASView_MouseUp(object sender, MouseEventArgs e)
private void TasView_MouseUp(object sender, MouseEventArgs e)
{
StartMarkerDrag = false;
StartFrameDrag = false;
StartDrawColumn = String.Empty;
_startMarkerDrag = false;
_startFrameDrag = false;
_startDrawColumn = string.Empty;
}
private void TASView_PointedCellChanged(object sender, TasListView.CellEventArgs e)
private void TasView_PointedCellChanged(object sender, TasListView.CellEventArgs e)
{
if (StartMarkerDrag)
if (_startMarkerDrag)
{
if (e.NewCell.Row.HasValue)
{
GoToFrame(e.NewCell.Row.Value);
}
}
else if (StartFrameDrag)
else if (_startFrameDrag)
{
if (e.OldCell.Row.HasValue && e.NewCell.Row.HasValue)
{
@ -541,20 +553,30 @@ namespace BizHawk.Client.EmuHawk
}
}
}
else if (TasView.IsPaintDown && e.NewCell.Row.HasValue && !String.IsNullOrEmpty(StartDrawColumn))
else if (TasView.IsPaintDown && e.NewCell.Row.HasValue && !string.IsNullOrEmpty(_startDrawColumn))
{
_tas.SetButton(e.NewCell.Row.Value, StartDrawColumn, StartOn); //Notice it uses new row, old column, you can only paint across a single column
_tas.SetButton(e.NewCell.Row.Value, _startDrawColumn, _startOn); // Notice it uses new row, old column, you can only paint across a single column
TasView.Refresh();
}
}
private void TASView_SelectedIndexChanged(object sender, EventArgs e)
private void TasView_SelectedIndexChanged(object sender, EventArgs e)
{
SetSplicer();
}
#endregion
#region Dialog Events
protected override void OnShown(EventArgs e)
{
RefreshFloatingWindowControl();
base.OnShown(e);
}
#endregion
#endregion
#region Classes
@ -562,7 +584,7 @@ namespace BizHawk.Client.EmuHawk
public class TasClipboardEntry
{
private readonly Dictionary<string, bool> _buttons;
private int _frame;
private readonly int _frame;
public TasClipboardEntry(int frame, Dictionary<string, bool> buttons)
{