2013-12-01 04:00:02 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Drawing ;
using System.IO ;
2013-12-05 19:18:20 +00:00
using System.Linq ;
2013-12-01 04:00:02 +00:00
using System.Windows.Forms ;
2013-12-01 20:55:52 +00:00
2013-12-01 04:00:02 +00:00
using BizHawk.Client.Common ;
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio : Form , IToolForm
{
2013-12-06 15:47:23 +00:00
private const string MarkerColumn = "" ;
private const string FrameColumn = "Frame#" ;
2013-12-01 04:00:02 +00:00
private int _defaultWidth ;
private int _defaultHeight ;
2013-12-05 19:18:20 +00:00
private TasMovie _tas ;
2013-12-01 04:00:02 +00:00
#region API
public TAStudio ( )
{
InitializeComponent ( ) ;
TASView . QueryItemText + = TASView_QueryItemText ;
TASView . QueryItemBkColor + = TASView_QueryItemBkColor ;
TASView . VirtualMode = true ;
Closing + = ( o , e ) = >
{
if ( AskSave ( ) )
{
SaveConfigSettings ( ) ;
2013-12-01 22:29:38 +00:00
GlobalWin . OSD . AddMessage ( "TAStudio Disengaged" ) ;
if ( Global . MovieSession . Movie is TasMovie )
{
Global . MovieSession . Movie = new Movie ( ) ;
}
2013-12-01 04:00:02 +00:00
}
else
{
e . Cancel = true ;
}
} ;
TopMost = Global . Config . TAStudioTopMost ;
}
public bool AskSave ( )
{
// TODO: eventually we want to do this
return true ;
}
public bool UpdateBefore
{
get { return false ; }
}
public void UpdateValues ( )
{
if ( ! IsHandleCreated | | IsDisposed ) return ;
2013-12-05 19:18:20 +00:00
TASView . ItemCount = _tas . InputLogLength ;
2013-12-01 04:00:02 +00:00
}
public void Restart ( )
{
if ( ! IsHandleCreated | | IsDisposed ) return ;
}
#endregion
private void TASView_QueryItemBkColor ( int index , int column , ref Color color )
{
2013-12-06 15:47:23 +00:00
var record = _tas [ index ] ;
if ( ! record . HasState )
{
color = BackColor ;
}
else
{
if ( record . Lagged )
{
color = Color . Pink ;
}
else
{
color = Color . LightGreen ;
}
}
2013-12-01 04:00:02 +00:00
}
private void TASView_QueryItemText ( int index , int column , out string text )
{
text = String . Empty ;
2013-12-06 15:47:23 +00:00
var columnName = TASView . Columns [ column ] . Name ;
if ( columnName = = MarkerColumn )
{
text = "X" ;
}
else if ( columnName = = FrameColumn )
{
text = index . ToString ( ) . PadLeft ( 5 , '0' ) ;
}
2013-12-06 18:27:06 +00:00
else
{
text = _tas [ index ] . IsPressed ( 1 , columnName ) ? columnName : String . Empty ;
}
2013-12-01 04:00:02 +00:00
}
private void TAStudio_Load ( object sender , EventArgs e )
{
2013-12-01 22:29:38 +00:00
if ( Global . MovieSession . Movie . IsActive )
{
var result = MessageBox . Show ( "Warning, Tastudio doesn't support .bkm movie files at this time, opening this will cause you to lose your work, proceed? If you have unsaved changes you should cancel this, and savebefore opening TAStudio" , "Unsupported movie" , MessageBoxButtons . OKCancel , MessageBoxIcon . Warning ) ;
if ( result ! = DialogResult . Yes )
{
Close ( ) ;
return ;
}
}
2013-12-01 04:00:02 +00:00
GlobalWin . OSD . AddMessage ( "TAStudio engaged" ) ;
2013-12-01 22:29:38 +00:00
Global . MovieSession . Movie = new TasMovie ( ) ;
2013-12-05 19:18:20 +00:00
_tas = Global . MovieSession . Movie as TasMovie ;
_tas . StartNewRecording ( ) ;
2013-12-01 04:00:02 +00:00
LoadConfigSettings ( ) ;
2013-12-05 19:18:20 +00:00
SetUpColumns ( ) ;
}
private void SetUpColumns ( )
{
TASView . Columns . Clear ( ) ;
ToolHelpers . AddColumn ( TASView , "" , true , 18 ) ;
ToolHelpers . AddColumn ( TASView , "Frame#" , true , 68 ) ;
var mnemonics = MnemonicConstants . BUTTONS [ Global . Emulator . Controller . Type . Name ] . Select ( x = > x . Value ) ;
foreach ( var mnemonic in mnemonics )
{
ToolHelpers . AddColumn ( TASView , mnemonic , true , 20 ) ;
}
2013-12-01 04:00:02 +00:00
}
private void LoadConfigSettings ( )
{
_defaultWidth = Size . Width ;
_defaultHeight = Size . Height ;
if ( Global . Config . TAStudioSaveWindowPosition & & Global . Config . TASWndx > = 0 & & Global . Config . TASWndy > = 0 )
{
Location = new Point ( Global . Config . TASWndx , Global . Config . TASWndy ) ;
}
if ( Global . Config . TASWidth > = 0 & & Global . Config . TASHeight > = 0 )
{
Size = new Size ( Global . Config . TASWidth , Global . Config . TASHeight ) ;
}
}
private void SaveConfigSettings ( )
{
Global . Config . TASWndx = Location . X ;
Global . Config . TASWndy = Location . Y ;
Global . Config . TASWidth = Right - Left ;
Global . Config . TASHeight = Bottom - Top ;
}
#region Events
#region File Menu
private void ExitMenuItem_Click ( object sender , EventArgs e )
{
Close ( ) ;
}
#endregion
#region Settings Menu
private void SettingsSubMenu_DropDownOpened ( object sender , EventArgs e )
{
SaveWindowPositionMenuItem . Checked = Global . Config . TAStudioSaveWindowPosition ;
AutoloadMenuItem . Checked = Global . Config . AutoloadTAStudio ;
AlwaysOnTopMenuItem . Checked = Global . Config . TAStudioTopMost ;
}
private void AutoloadMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . AutoloadTAStudio ^ = true ;
}
private void SaveWindowPositionMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . TAStudioSaveWindowPosition ^ = true ;
}
private void AlwaysOnTopMenuItem_Click ( object sender , EventArgs e )
{
Global . Config . TAStudioTopMost ^ = true ;
}
#endregion
#endregion
}
}