BizHawk/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs

320 lines
8.2 KiB
C#
Raw Normal View History

2014-07-09 23:04:22 +00:00
using System;
using System.Drawing;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio
{
// Input Painting
2014-07-11 16:26:19 +00:00
private string _startBoolDrawColumn = string.Empty;
private string _startFloatDrawColumn = string.Empty;
private bool _boolPaintState;
2014-07-11 16:26:19 +00:00
private float _floatPaintState;
private bool _startMarkerDrag;
private bool _startFrameDrag;
public static Color CurrentFrame_FrameCol = Color.FromArgb(0xCFEDFC);
public static Color CurrentFrame_InputLog = Color.FromArgb(0xB5E7F7);
2014-07-16 00:10:37 +00:00
public static Color GreenZone_FrameCol = Color.FromArgb(0xDDFFDD);
public static Color GreenZone_InputLog = Color.FromArgb(0xC4F7C8);
2014-07-16 00:10:37 +00:00
public static Color LagZone_FrameCol = Color.FromArgb(0xFFDCDD);
public static Color LagZone_InputLog = Color.FromArgb(0xF0D0D2);
2014-07-16 00:10:37 +00:00
public static Color NoState_GreenZone_FrameCol = Color.FromArgb(0xF9FFF9);
public static Color NoState_GreenZone_InputLog = Color.FromArgb(0xE0FBE0);
2014-07-16 00:10:37 +00:00
public static Color NoState_LagZone_FrameCol = Color.FromArgb(0xFFE9E9);
public static Color NoState_LagZone_InputLog = Color.FromArgb(0xF0D0D2);
2014-07-16 00:10:37 +00:00
public static Color Marker_FrameCol = Color.FromArgb(0xF7FFC9);
2014-07-16 00:10:37 +00:00
2014-07-09 23:04:22 +00:00
#region Query callbacks
private void TasView_QueryItemBkColor(int index, int column, ref Color color)
{
var columnName = TasView.Columns[column].Name;
2014-07-16 00:10:37 +00:00
// Marker Column is white regardless
2014-07-16 00:10:37 +00:00
if (columnName == MarkerColumnName)
2014-07-09 23:04:22 +00:00
{
2014-07-16 00:10:37 +00:00
color = Color.White;
return;
}
// "pending" frame logic
if (index == Global.Emulator.Frame && index == _tas.InputLogLength)
{
if (columnName == FrameColumnName)
{
color = CurrentFrame_FrameCol;
}
color = CurrentFrame_InputLog;
return;
2014-07-09 23:04:22 +00:00
}
var record = _tas[index];
if (columnName == FrameColumnName)
2014-07-09 23:04:22 +00:00
{
2014-07-16 00:10:37 +00:00
if (Global.Emulator.Frame == index)
{
color = CurrentFrame_FrameCol;
}
else if (_tas.Markers.IsMarker(index))
{
color = Marker_FrameCol;
}
else if (record.Lagged.HasValue)
{
if (record.Lagged.Value)
{
2014-07-16 00:10:37 +00:00
color = record.HasState ? GreenZone_FrameCol : NoState_GreenZone_FrameCol;
}
else
{
2014-07-16 00:10:37 +00:00
color = record.HasState ? LagZone_FrameCol : NoState_LagZone_InputLog;
}
}
else
{
2014-07-16 00:10:37 +00:00
color = Color.White;
}
}
else
{
if (Global.Emulator.Frame == index)
{
color = CurrentFrame_InputLog;
}
else
{
if (record.Lagged.HasValue)
{
if (record.Lagged.Value)
{
color = record.HasState ? GreenZone_InputLog : NoState_GreenZone_InputLog;
}
else
{
color = record.HasState ? LagZone_InputLog : NoState_LagZone_InputLog;
}
}
else
{
color = (columnName == MarkerColumnName || columnName == FrameColumnName) ?
Color.White :
SystemColors.ControlLight;
}
}
2014-07-09 23:04:22 +00:00
}
}
private void TasView_QueryItemText(int index, int column, out string text)
{
try
{
text = string.Empty;
2014-07-09 23:04:22 +00:00
var columnName = TasView.Columns[column].Name;
if (columnName == MarkerColumnName)
{
2014-07-10 20:15:46 +00:00
text = Global.Emulator.Frame == index ? ">" : string.Empty;
2014-07-09 23:04:22 +00:00
}
else if (columnName == FrameColumnName)
{
2014-07-10 20:15:46 +00:00
text = (index).ToString().PadLeft(5, '0');
2014-07-09 23:04:22 +00:00
}
else
{
if (index < _tas.InputLogLength)
{
text = _tas.DisplayValue(index, columnName);
}
else if (Global.Emulator.Frame == _tas.InputLogLength) // In this situation we have a "pending" frame for the user to click
{
text = TasMovie.CreateDisplayValueForButton(
Global.ClickyVirtualPadController,
columnName);
}
2014-07-09 23:04:22 +00:00
}
}
catch (Exception ex)
{
text = string.Empty;
MessageBox.Show("oops\n" + ex);
}
}
#endregion
#region Events
private void TasView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Middle)
{
TogglePause();
return;
}
2014-07-09 23:04:22 +00:00
if (TasView.PointedCell.Row.HasValue && !string.IsNullOrEmpty(TasView.PointedCell.Column))
{
if (e.Button == MouseButtons.Left)
2014-07-09 23:04:22 +00:00
{
if (TasView.PointedCell.Column == MarkerColumnName)
{
_startMarkerDrag = true;
GoToFrame(TasView.PointedCell.Row.Value - 1);
}
else if (TasView.PointedCell.Column == FrameColumnName)
{
_startFrameDrag = true;
}
2014-07-11 16:26:19 +00:00
else
{
var frame = TasView.PointedCell.Row.Value;
var buttonName = TasView.PointedCell.Column;
if (Global.MovieSession.MovieControllerAdapter.Type.BoolButtons.Contains(buttonName))
{
ToggleBoolState(TasView.PointedCell.Row.Value, TasView.PointedCell.Column);
GoToLastEmulatedFrameIfNecessary(TasView.PointedCell.Row.Value);
TasView.Refresh();
_startBoolDrawColumn = TasView.PointedCell.Column;
_boolPaintState = _tas.BoolIsPressed(frame, buttonName);
}
else
{
_startFloatDrawColumn = TasView.PointedCell.Column;
_floatPaintState = _tas.GetFloatValue(frame, buttonName);
}
2014-07-11 16:26:19 +00:00
}
2014-07-09 23:04:22 +00:00
}
}
}
private void TasView_MouseUp(object sender, MouseEventArgs e)
{
_startMarkerDrag = false;
_startFrameDrag = false;
2014-07-11 16:26:19 +00:00
_startBoolDrawColumn = string.Empty;
_startFloatDrawColumn = string.Empty;
_floatPaintState = 0;
2014-07-09 23:04:22 +00:00
}
private void TasView_MouseWheel(object sender, MouseEventArgs e)
{
if (TasView.RightButtonHeld && TasView.PointedCell.Row.HasValue)
{
if (e.Delta < 0)
{
GoToFrame(Global.Emulator.Frame + 1);
}
else
{
GoToFrame(Global.Emulator.Frame - 1);
}
}
}
private void TasView_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (TasView.PointedCell.Row.HasValue &&
!string.IsNullOrEmpty(TasView.PointedCell.Column) &&
TasView.PointedCell.Column == FrameColumnName)
{
CallAddMarkerPopUp(TasView.PointedCell.Row.Value);
}
}
2014-07-09 23:04:22 +00:00
private void TasView_PointedCellChanged(object sender, TasListView.CellEventArgs e)
{
int startVal, endVal;
if (e.OldCell.Row.Value < e.NewCell.Row.Value)
{
startVal = e.OldCell.Row.Value;
endVal = e.NewCell.Row.Value;
}
else
{
startVal = e.NewCell.Row.Value;
endVal = e.OldCell.Row.Value;
}
2014-07-09 23:04:22 +00:00
if (_startMarkerDrag)
{
if (e.NewCell.Row.HasValue)
{
2014-07-18 19:22:10 +00:00
GoToFrame(e.NewCell.Row.Value);
2014-07-09 23:04:22 +00:00
}
}
else if (_startFrameDrag)
{
if (e.OldCell.Row.HasValue && e.NewCell.Row.HasValue)
{
for (var i = startVal + 1; i <= endVal; i++)
{
TasView.SelectItem(i, true);
}
}
}
2014-07-11 16:26:19 +00:00
else if (TasView.IsPaintDown && e.NewCell.Row.HasValue && !string.IsNullOrEmpty(_startBoolDrawColumn))
{
if (e.OldCell.Row.HasValue && e.NewCell.Row.HasValue)
{
for (var i = startVal; i < endVal; i++)
{
SetBoolState(i, _startBoolDrawColumn, _boolPaintState); // Notice it uses new row, old column, you can only paint across a single column
2014-07-13 17:41:30 +00:00
GoToLastEmulatedFrameIfNecessary(TasView.PointedCell.Row.Value);
2014-07-11 16:26:19 +00:00
}
TasView.Refresh();
}
}
else if (TasView.IsPaintDown && e.NewCell.Row.HasValue && !string.IsNullOrEmpty(_startFloatDrawColumn))
2014-07-09 23:04:22 +00:00
{
if (e.OldCell.Row.HasValue && e.NewCell.Row.HasValue)
{
for (var i = startVal; i < endVal; i++)
{
if (i < _tas.InputLogLength) // TODO: how do we really want to handle the user setting the float state of the pending frame?
{
_tas.SetFloatState(i, _startFloatDrawColumn, _floatPaintState); // Notice it uses new row, old column, you can only paint across a single column
GoToLastEmulatedFrameIfNecessary(TasView.PointedCell.Row.Value);
}
}
2014-07-11 16:26:19 +00:00
TasView.Refresh();
}
2014-07-09 23:04:22 +00:00
}
}
private void TasView_SelectedIndexChanged(object sender, EventArgs e)
{
SetSplicer();
}
private void TasView_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Left) // Ctrl + Left
{
GoToPreviousMarker();
}
else if (e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Right) // Ctrl + Left
{
GoToNextMarker();
}
}
2014-07-09 23:04:22 +00:00
#endregion
}
}