2014-07-09 15:04:16 +00:00
using System.Windows.Forms ;
using BizHawk.Client.Common ;
2014-12-14 01:20:19 +00:00
using System.Collections.Generic ;
using System ;
using BizHawk.Emulation.Common ;
2014-07-09 15:04:16 +00:00
namespace BizHawk.Client.EmuHawk
{
public partial class TAStudio : IToolForm
{
2014-12-15 18:13:54 +00:00
[RequiredService]
public IEmulator Emulator { get ; private set ; }
[RequiredService]
public IStatable StatableEmulator { get ; private set ; }
2014-12-14 01:20:19 +00:00
2014-10-17 18:14:21 +00:00
private bool _hackyDontUpdate ;
2014-10-18 15:27:53 +00:00
private bool _initializing ; // If true, will bypass restart logic, this is necessary since loading projects causes a movie to load which causes a rom to reload causing dialogs to restart
2014-09-17 23:51:16 +00:00
2014-10-17 18:14:21 +00:00
public bool UpdateBefore { get { return false ; } }
2014-09-27 15:19:07 +00:00
2014-07-09 15:04:16 +00:00
public void UpdateValues ( )
{
2014-10-20 19:04:59 +00:00
if ( ! IsHandleCreated | | IsDisposed | | CurrentTasMovie = = null )
2014-08-23 20:17:06 +00:00
{
return ;
}
2014-09-27 15:19:07 +00:00
if ( _hackyDontUpdate )
{
return ;
}
2014-11-15 21:48:34 +00:00
if ( TasPlaybackBox . FollowCursor ) // TODO: we already refreshed in RefreshDialog now we will do it again, make this more efficient
2014-10-11 19:43:05 +00:00
{
SetVisibleIndex ( ) ;
}
2015-02-26 21:12:12 +00:00
RefreshDialog ( ) ;
2015-02-27 19:06:02 +00:00
}
2014-07-09 15:04:16 +00:00
2014-07-25 01:55:21 +00:00
public void FastUpdate ( )
{
2014-10-20 19:04:59 +00:00
if ( ! IsHandleCreated | | IsDisposed | | CurrentTasMovie = = null )
2014-08-31 16:51:19 +00:00
{
return ;
}
2014-10-20 19:04:59 +00:00
TasView . RowCount = CurrentTasMovie . InputLogLength + 1 ;
2014-10-11 19:43:05 +00:00
if ( TasPlaybackBox . FollowCursor )
{
SetVisibleIndex ( ) ;
}
2014-07-25 01:55:21 +00:00
}
2014-07-09 15:04:16 +00:00
public void Restart ( )
{
if ( ! IsHandleCreated | | IsDisposed )
{
return ;
}
2014-07-10 20:06:23 +00:00
2014-10-18 15:27:53 +00:00
if ( _initializing )
{
return ;
}
2014-10-20 19:04:59 +00:00
if ( CurrentTasMovie ! = null )
2014-07-10 20:06:23 +00:00
{
2014-10-20 19:04:59 +00:00
if ( Global . Game . Hash ! = CurrentTasMovie . Hash )
2014-10-18 15:27:53 +00:00
{
TastudioToStopMovie ( ) ;
TasView . AllColumns . Clear ( ) ;
NewDefaultProject ( ) ;
SetUpColumns ( ) ;
TasView . Refresh ( ) ;
}
else
{
RefreshDialog ( ) ;
}
2014-07-10 20:06:23 +00:00
}
2014-07-09 15:04:16 +00:00
}
2014-08-19 19:24:17 +00:00
public bool AskSaveChanges ( )
2014-07-09 15:04:16 +00:00
{
2014-11-08 17:44:25 +00:00
if ( _suppressAskSave )
{
return true ;
}
2014-10-20 19:04:59 +00:00
if ( CurrentTasMovie ! = null & & CurrentTasMovie . Changes )
2014-07-09 15:04:16 +00:00
{
GlobalWin . Sound . StopSound ( ) ;
2014-07-27 15:11:59 +00:00
var result = MessageBox . Show (
"Save Changes?" ,
"Tastudio" ,
MessageBoxButtons . YesNoCancel ,
MessageBoxIcon . Question ,
MessageBoxDefaultButton . Button3 ) ;
2014-07-09 15:04:16 +00:00
GlobalWin . Sound . StartSound ( ) ;
if ( result = = DialogResult . Yes )
{
2015-01-06 16:35:22 +00:00
_exiting = true ; // Asking to save changes should only ever be called when closing something
2014-07-09 15:04:16 +00:00
SaveTasMenuItem_Click ( null , null ) ;
}
else if ( result = = DialogResult . No )
{
2014-10-20 19:04:59 +00:00
CurrentTasMovie . ClearChanges ( ) ;
2014-07-09 15:04:16 +00:00
return true ;
}
else if ( result = = DialogResult . Cancel )
{
return false ;
}
}
return true ;
}
2014-08-19 19:24:17 +00:00
2014-10-11 19:43:05 +00:00
public void SetVisibleIndex ( int? indexThatMustBeVisible = null )
2014-09-17 23:51:16 +00:00
{
2014-09-25 01:38:01 +00:00
if ( ! indexThatMustBeVisible . HasValue )
{
2014-10-20 19:04:59 +00:00
indexThatMustBeVisible = CurrentTasMovie . IsRecording
? CurrentTasMovie . InputLogLength
2014-12-14 01:20:19 +00:00
: Emulator . Frame + 1 ;
2014-09-25 01:38:01 +00:00
}
2014-09-17 23:51:16 +00:00
2014-09-25 01:38:01 +00:00
if ( ! TasView . IsVisible ( indexThatMustBeVisible . Value ) )
2014-09-17 23:51:16 +00:00
{
2015-02-27 19:06:02 +00:00
if ( TasView . FirstVisibleRow > indexThatMustBeVisible . Value )
TasView . FirstVisibleRow = indexThatMustBeVisible . Value ;
else
TasView . LastVisibleRow = indexThatMustBeVisible . Value ;
2014-09-17 23:51:16 +00:00
}
}
2014-07-09 15:04:16 +00:00
}
}