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 ; }
2015-07-27 23:25:15 +00:00
2014-12-15 18:13:54 +00:00
[RequiredService]
public IStatable StatableEmulator { get ; private set ; }
2014-12-14 01:20:19 +00:00
2015-07-27 23:25:15 +00:00
[OptionalService]
public ISaveRam SaveRamEmulator { get ; private set ; }
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
2016-08-13 20:31:04 +00:00
public void NewUpdate ( ToolFormUpdateType type ) { }
2015-03-22 16:55:34 +00:00
private int lastRefresh = 0 ;
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 ;
}
2015-03-19 19:55:38 +00:00
bool refreshNeeded = false ;
2015-03-10 17:11:29 +00:00
if ( AutoadjustInputMenuItem . Checked )
2015-03-19 19:55:38 +00:00
refreshNeeded = AutoAdjustInput ( ) ;
2015-03-10 17:11:29 +00:00
2015-10-25 17:24:33 +00:00
if ( TasView . RowCount ! = CurrentTasMovie . InputLogLength + 1 )
TasView . RowCount = CurrentTasMovie . InputLogLength + 1 ;
2015-07-26 00:55:52 +00:00
MaybeFollowCursor ( ) ;
2015-02-26 21:12:12 +00:00
2015-03-22 16:55:34 +00:00
if ( TasView . IsPartiallyVisible ( Global . Emulator . Frame ) | | TasView . IsPartiallyVisible ( lastRefresh ) )
2015-03-19 19:55:38 +00:00
refreshNeeded = true ;
2015-07-26 19:54:11 +00:00
RefreshDialog ( refreshNeeded ) ;
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
2015-07-26 00:55:52 +00:00
MaybeFollowCursor ( ) ;
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
{
2016-08-03 19:29:27 +00:00
TastudioStopMovie ( ) ;
2014-10-18 15:27:53 +00:00
TasView . AllColumns . Clear ( ) ;
2015-03-22 16:55:34 +00:00
StartNewTasMovie ( ) ;
2014-10-18 15:27:53 +00:00
SetUpColumns ( ) ;
2015-03-03 06:56:45 +00:00
RefreshTasView ( ) ;
2014-10-18 15:27:53 +00:00
}
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 ;
}
2016-08-04 15:53:01 +00:00
StopSeeking ( ) ;
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
2016-06-12 13:41:27 +00:00
SaveTas ( null , null ) ;
2014-07-09 15:04:16 +00:00
}
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 ;
}
}
}