2014-07-09 23:04:22 +00:00
using System ;
using System.Drawing ;
2014-07-28 16:43:47 +00:00
using System.Linq ;
2014-07-09 23:04:22 +00:00
using System.Windows.Forms ;
using BizHawk.Client.Common ;
2014-07-28 16:43:47 +00:00
using BizHawk.Client.EmuHawk.WinFormExtensions ;
2014-07-09 23:04:22 +00:00
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio
{
2014-07-11 16:08:47 +00:00
// Input Painting
2014-07-11 16:26:19 +00:00
private string _startBoolDrawColumn = string . Empty ;
private string _startFloatDrawColumn = string . Empty ;
2014-07-11 16:08:47 +00:00
private bool _boolPaintState ;
2014-07-11 16:26:19 +00:00
private float _floatPaintState ;
2014-07-11 16:08:47 +00:00
private bool _startMarkerDrag ;
private bool _startFrameDrag ;
2014-07-21 02:23:47 +00:00
public static Color CurrentFrame_FrameCol = Color . FromArgb ( 0xCFEDFC ) ;
public static Color CurrentFrame_InputLog = Color . FromArgb ( 0xB5E7F7 ) ;
2014-07-16 00:10:37 +00:00
2014-07-21 02:23:47 +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
2014-07-21 02:23:47 +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
2014-07-21 02:23:47 +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
2014-07-21 02:23:47 +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
2014-07-21 02:23:47 +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 )
{
2014-07-11 19:58:24 +00:00
var columnName = TasView . Columns [ column ] . Name ;
2014-07-16 00:10:37 +00:00
2014-07-16 23:04:56 +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 ;
2014-07-16 23:04:56 +00:00
return ;
}
// "pending" frame logic
2014-08-19 19:24:17 +00:00
if ( index = = Global . Emulator . Frame & & index = = _currentTasMovie . InputLogLength )
2014-07-16 23:04:56 +00:00
{
if ( columnName = = FrameColumnName )
{
color = CurrentFrame_FrameCol ;
}
color = CurrentFrame_InputLog ;
return ;
2014-07-09 23:04:22 +00:00
}
2014-07-16 23:04:56 +00:00
2014-08-19 19:24:17 +00:00
var record = _currentTasMovie [ index ] ;
2014-07-16 23:04:56 +00:00
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 ;
}
2014-08-19 19:24:17 +00:00
else if ( _currentTasMovie . Markers . IsMarker ( index ) )
2014-07-16 00:10:37 +00:00
{
color = Marker_FrameCol ;
}
else if ( record . Lagged . HasValue )
2014-07-10 19:24:21 +00:00
{
if ( record . Lagged . Value )
{
2014-07-16 00:10:37 +00:00
color = record . HasState ? GreenZone_FrameCol : NoState_GreenZone_FrameCol ;
2014-07-10 19:24:21 +00:00
}
else
{
2014-07-16 00:10:37 +00:00
color = record . HasState ? LagZone_FrameCol : NoState_LagZone_InputLog ;
2014-07-10 19:24:21 +00:00
}
}
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-10 19:24:21 +00:00
}
2014-07-09 23:04:22 +00:00
}
}
private void TasView_QueryItemText ( int index , int column , out string text )
{
try
{
2014-07-16 23:04:56 +00:00
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
{
2014-08-19 19:24:17 +00:00
if ( index < _currentTasMovie . InputLogLength )
2014-07-16 23:04:56 +00:00
{
2014-08-19 19:24:17 +00:00
text = _currentTasMovie . DisplayValue ( index , columnName ) ;
2014-07-16 23:04:56 +00:00
}
2014-08-19 19:24:17 +00:00
else if ( Global . Emulator . Frame = = _currentTasMovie . InputLogLength ) // In this situation we have a "pending" frame for the user to click
2014-07-16 23:04:56 +00:00
{
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
2014-07-28 16:43:47 +00:00
private void TasView_ColumnClick ( object sender , ColumnClickEventArgs e )
{
if ( TasView . SelectedIndices ( ) . Any ( ) )
{
var columnName = TasView . Columns [ e . Column ] . Name ;
if ( columnName = = FrameColumnName )
{
// TODO: add marker to LastSelectedIndex
}
else if ( columnName ! = MarkerColumnName ) // TODO: what about float?
{
foreach ( var index in TasView . SelectedIndices ( ) )
{
ToggleBoolState ( index , columnName ) ;
}
RefreshDialog ( ) ;
}
}
}
2014-07-09 23:04:22 +00:00
private void TasView_MouseDown ( object sender , MouseEventArgs e )
{
2014-07-17 20:35:12 +00:00
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 ) )
{
2014-07-14 01:49:37 +00:00
if ( e . Button = = MouseButtons . Left )
2014-07-09 23:04:22 +00:00
{
2014-07-14 01:49:37 +00:00
if ( TasView . PointedCell . Column = = MarkerColumnName )
2014-07-10 20:40:50 +00:00
{
2014-07-14 01:49:37 +00:00
_startMarkerDrag = true ;
2014-08-20 19:52:01 +00:00
GoToFrame ( TasView . PointedCell . Row . Value ) ;
2014-07-14 01:49:37 +00:00
}
else if ( TasView . PointedCell . Column = = FrameColumnName )
{
_startFrameDrag = true ;
2014-07-10 20:40:50 +00:00
}
2014-07-11 16:26:19 +00:00
else
{
2014-07-14 01:49:37 +00:00
var frame = TasView . PointedCell . Row . Value ;
var buttonName = TasView . PointedCell . Column ;
if ( Global . MovieSession . MovieControllerAdapter . Type . BoolButtons . Contains ( buttonName ) )
{
2014-07-16 23:04:56 +00:00
ToggleBoolState ( TasView . PointedCell . Row . Value , TasView . PointedCell . Column ) ;
2014-07-14 01:49:37 +00:00
GoToLastEmulatedFrameIfNecessary ( TasView . PointedCell . Row . Value ) ;
TasView . Refresh ( ) ;
_startBoolDrawColumn = TasView . PointedCell . Column ;
2014-08-19 19:24:17 +00:00
_boolPaintState = _currentTasMovie . BoolIsPressed ( frame , buttonName ) ;
2014-07-14 01:49:37 +00:00
}
else
{
_startFloatDrawColumn = TasView . PointedCell . Column ;
2014-08-19 19:24:17 +00:00
_floatPaintState = _currentTasMovie . GetFloatValue ( frame , buttonName ) ;
2014-07-14 01:49:37 +00:00
}
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
}
2014-07-16 01:37:50 +00:00
private void TasView_MouseWheel ( object sender , MouseEventArgs e )
{
2014-07-18 00:04:29 +00:00
if ( TasView . RightButtonHeld & & TasView . PointedCell . Row . HasValue )
2014-07-16 01:37:50 +00:00
{
if ( e . Delta < 0 )
{
2014-07-17 23:55:10 +00:00
GoToFrame ( Global . Emulator . Frame + 1 ) ;
2014-07-16 01:37:50 +00:00
}
else
{
2014-07-17 23:55:10 +00:00
GoToFrame ( Global . Emulator . Frame - 1 ) ;
2014-07-16 01:37:50 +00:00
}
}
}
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 )
{
2014-07-11 16:08:47 +00:00
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 + + )
{
2014-07-16 23:04:56 +00:00
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
{
2014-07-11 16:08:47 +00:00
if ( e . OldCell . Row . HasValue & & e . NewCell . Row . HasValue )
{
for ( var i = startVal ; i < endVal ; i + + )
{
2014-08-19 19:24:17 +00:00
if ( i < _currentTasMovie . InputLogLength ) // TODO: how do we really want to handle the user setting the float state of the pending frame?
2014-07-16 23:04:56 +00:00
{
2014-08-19 19:24:17 +00:00
_currentTasMovie . SetFloatState ( i , _startFloatDrawColumn , _floatPaintState ) ; // Notice it uses new row, old column, you can only paint across a single column
2014-07-16 23:04:56 +00:00
GoToLastEmulatedFrameIfNecessary ( TasView . PointedCell . Row . Value ) ;
}
2014-07-11 16:08:47 +00:00
}
2014-07-11 16:26:19 +00:00
2014-07-11 16:08:47 +00:00
TasView . Refresh ( ) ;
}
2014-07-09 23:04:22 +00:00
}
}
private void TasView_SelectedIndexChanged ( object sender , EventArgs e )
{
SetSplicer ( ) ;
}
2014-07-17 19:57:44 +00:00
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-25 01:02:24 +00:00
else if ( e . Control & & ! e . Shift & & ! e . Alt & & e . KeyCode = = Keys . Up ) // Ctrl + Up
{
GoToPreviousFrame ( ) ;
}
else if ( e . Control & & ! e . Shift & & ! e . Alt & & e . KeyCode = = Keys . Down ) // Ctrl + Down
{
GoToNextFrame ( ) ;
}
2014-07-17 19:57:44 +00:00
}
2014-07-09 23:04:22 +00:00
#endregion
}
}