2013-12-01 04:00:02 +00:00
using System ;
using System.Collections.Generic ;
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 ;
2014-08-23 18:02:02 +00:00
using System.ComponentModel ;
2013-12-01 20:55:52 +00:00
2013-12-01 04:00:02 +00:00
using BizHawk.Client.Common ;
2014-07-06 21:20:43 +00:00
using BizHawk.Client.Common.MovieConversionExtensions ;
2014-07-27 15:22:30 +00:00
using BizHawk.Client.EmuHawk.WinFormExtensions ;
2014-07-28 01:51:11 +00:00
using BizHawk.Client.EmuHawk.ToolExtensions ;
2013-12-01 04:00:02 +00:00
namespace BizHawk.Client.EmuHawk
{
2014-07-08 16:08:52 +00:00
public partial class TAStudio : Form , IToolForm , IControlMainform
2013-12-01 04:00:02 +00:00
{
2013-12-14 14:40:33 +00:00
// TODO: UI flow that conveniently allows to start from savestate
2013-12-07 17:29:47 +00:00
private const string MarkerColumnName = "MarkerColumn" ;
private const string FrameColumnName = "FrameColumn" ;
2013-12-06 15:47:23 +00:00
2014-02-01 15:44:51 +00:00
private readonly List < TasClipboardEntry > _tasClipboard = new List < TasClipboardEntry > ( ) ;
2013-12-01 04:00:02 +00:00
private int _defaultWidth ;
private int _defaultHeight ;
2014-08-19 19:24:17 +00:00
private TasMovie _currentTasMovie ;
2014-07-14 00:35:33 +00:00
private MovieEndAction _originalEndAction ; // The movie end behavior selected by the user (that is overridden by TAStudio)
2014-07-09 21:56:27 +00:00
private Dictionary < string , string > GenerateColumnNames ( )
2014-07-06 22:13:12 +00:00
{
2014-07-09 21:56:27 +00:00
var lg = Global . MovieSession . LogGeneratorInstance ( ) ;
lg . SetSource ( Global . MovieSession . MovieControllerAdapter ) ;
return ( lg as Bk2LogEntryGenerator ) . Map ( ) ;
2014-07-06 22:13:12 +00:00
}
2013-12-01 04:00:02 +00:00
2014-10-17 20:10:21 +00:00
private int? _autoRestoreFrame ; // The frame auto-restore will restore to, if set
2013-12-01 04:00:02 +00:00
public TAStudio ( )
{
InitializeComponent ( ) ;
2014-08-19 23:56:33 +00:00
WantsToControlStopMovie = true ;
2014-07-17 19:00:28 +00:00
TasPlaybackBox . Tastudio = this ;
2014-07-16 02:20:14 +00:00
MarkerControl . Tastudio = this ;
2014-02-01 15:44:51 +00:00
TasView . QueryItemText + = TasView_QueryItemText ;
TasView . QueryItemBkColor + = TasView_QueryItemBkColor ;
2014-09-03 03:16:16 +00:00
TasView . QueryItemIcon + = TasView_QueryItemIcon ;
2013-12-01 04:00:02 +00:00
2014-02-01 15:44:51 +00:00
TopMost = Global . Config . TAStudioSettings . TopMost ;
2013-12-20 03:28:25 +00:00
TasView . InputPaintingMode = Global . Config . TAStudioDrawInput ;
2014-02-01 15:44:51 +00:00
TasView . PointedCellChanged + = TasView_PointedCellChanged ;
2014-08-29 18:02:23 +00:00
TasView . MultiSelect = true ;
2014-10-15 22:19:34 +00:00
TasView . MaxCharactersInHorizontal = 1 ;
2013-12-01 04:00:02 +00:00
}
2014-10-17 17:40:11 +00:00
public TasMovie CurrentMovie
{
get { return _currentTasMovie ; }
}
private void TastudioToStopMovie ( )
{
Global . MovieSession . StopMovie ( false ) ;
GlobalWin . MainForm . SetMainformMovieInfo ( ) ;
}
2014-10-17 17:58:48 +00:00
private static void ConvertCurrentMovieToTasproj ( )
2014-07-08 15:15:35 +00:00
{
Global . MovieSession . Movie . Save ( ) ;
Global . MovieSession . Movie = Global . MovieSession . Movie . ToTasMovie ( ) ;
Global . MovieSession . Movie . Save ( ) ;
2014-08-29 01:14:26 +00:00
Global . MovieSession . Movie . SwitchToRecord ( ) ;
2014-07-08 15:15:35 +00:00
}
private void EngageTastudio ( )
2013-12-10 16:37:41 +00:00
{
2014-07-27 02:38:21 +00:00
GlobalWin . MainForm . PauseOnFrame = null ;
2013-12-10 16:37:41 +00:00
GlobalWin . OSD . AddMessage ( "TAStudio engaged" ) ;
2014-08-19 19:24:17 +00:00
_currentTasMovie = Global . MovieSession . Movie as TasMovie ;
2014-10-14 18:09:30 +00:00
SetTasMovieCallbacks ( ) ;
2014-09-16 23:26:17 +00:00
SetTextProperty ( ) ;
2014-07-12 01:32:21 +00:00
GlobalWin . MainForm . PauseEmulator ( ) ;
2014-07-08 16:08:52 +00:00
GlobalWin . MainForm . RelinquishControl ( this ) ;
2014-07-14 00:35:33 +00:00
_originalEndAction = Global . Config . MovieEndAction ;
2014-09-27 12:19:50 +00:00
GlobalWin . MainForm . ClearRewindData ( ) ;
2014-07-14 00:35:33 +00:00
Global . Config . MovieEndAction = MovieEndAction . Record ;
2014-07-19 16:03:12 +00:00
GlobalWin . MainForm . SetMainformMovieInfo ( ) ;
2014-07-08 15:15:35 +00:00
}
2014-07-08 13:46:59 +00:00
2014-07-08 15:15:35 +00:00
private void DisengageTastudio ( )
{
2014-07-27 02:38:21 +00:00
GlobalWin . MainForm . PauseOnFrame = null ;
2014-07-08 15:15:35 +00:00
GlobalWin . OSD . AddMessage ( "TAStudio disengaged" ) ;
Global . MovieSession . Movie = MovieService . DefaultInstance ;
2014-08-19 19:24:17 +00:00
GlobalWin . MainForm . TakeBackControl ( ) ;
2014-07-14 00:35:33 +00:00
Global . Config . MovieEndAction = _originalEndAction ;
2014-07-19 16:03:12 +00:00
GlobalWin . MainForm . SetMainformMovieInfo ( ) ;
2014-07-08 15:15:35 +00:00
}
2014-07-08 13:46:59 +00:00
2014-07-08 15:15:35 +00:00
private void NewTasMovie ( )
{
Global . MovieSession . Movie = new TasMovie ( ) ;
2014-08-19 19:24:17 +00:00
_currentTasMovie = Global . MovieSession . Movie as TasMovie ;
2014-10-14 18:09:30 +00:00
SetTasMovieCallbacks ( ) ;
2014-08-23 20:17:06 +00:00
_currentTasMovie . PropertyChanged + = new PropertyChangedEventHandler ( this . TasMovie_OnPropertyChanged ) ;
2014-08-19 19:24:17 +00:00
_currentTasMovie . Filename = DefaultTasProjName ( ) ; // TODO don't do this, take over any mainform actions that can crash without a filename
_currentTasMovie . PopulateWithDefaultHeaderValues ( ) ;
_currentTasMovie . ClearChanges ( ) ;
2014-10-18 15:31:51 +00:00
TasView . RowCount = 1 ;
2014-07-08 15:15:35 +00:00
}
2014-10-18 15:50:12 +00:00
/// <summary>
/// Used when starting a new project
/// </summary>
2014-07-08 15:15:35 +00:00
private static string DefaultTasProjName ( )
2014-10-18 15:50:12 +00:00
{
return Path . Combine (
PathManager . MakeAbsolutePath ( Global . Config . PathEntries . MoviesPathFragment , null ) ,
TasMovie . DefaultProjectName + "." + TasMovie . Extension ) ;
}
/// <summary>
/// Used for things like SaveFile dialogs to suggest a name to the user
/// </summary>
/// <returns></returns>
private static string SuggestedTasProjName ( )
2014-07-08 15:15:35 +00:00
{
return Path . Combine (
PathManager . MakeAbsolutePath ( Global . Config . PathEntries . MoviesPathFragment , null ) ,
PathManager . FilesystemSafeName ( Global . Game ) + "." + TasMovie . Extension ) ;
2013-12-10 16:37:41 +00:00
}
2014-10-14 18:09:30 +00:00
private void SetTasMovieCallbacks ( )
{
_currentTasMovie . ClientSettingsForSave = ClientSettingsForSave ;
_currentTasMovie . GetClientSettingsOnLoad = GetClientSettingsOnLoad ;
}
2014-07-10 19:51:36 +00:00
private void StartNewTasMovie ( )
2013-12-10 16:37:41 +00:00
{
2014-08-19 19:24:17 +00:00
if ( AskSaveChanges ( ) )
2013-12-10 16:37:41 +00:00
{
2014-07-10 19:51:36 +00:00
NewTasMovie ( ) ;
2014-08-19 23:56:33 +00:00
WantsToControlStopMovie = false ;
2014-10-18 15:27:53 +00:00
StartNewMovieWrapper ( record : true ) ;
2014-10-18 21:29:02 +00:00
_currentTasMovie . ClearChanges ( ) ;
2014-08-19 23:56:33 +00:00
WantsToControlStopMovie = true ;
2014-09-16 23:26:17 +00:00
SetTextProperty ( ) ;
2014-07-09 22:44:20 +00:00
RefreshDialog ( ) ;
2013-12-10 16:37:41 +00:00
}
}
2014-10-18 15:50:12 +00:00
private void DummyLoadProject ( string path )
{
LoadProject ( path ) ;
}
2014-10-14 18:09:30 +00:00
private string ClientSettingsForSave ( )
{
return TasView . UserSettingsSerialized ( ) ;
}
private void GetClientSettingsOnLoad ( string settingsJson )
{
TasView . LoadSettingsSerialized ( settingsJson ) ;
TasView . Refresh ( ) ;
}
2014-09-16 23:26:17 +00:00
private void SetTextProperty ( )
2014-09-16 23:25:08 +00:00
{
var text = "TAStudio" ;
if ( _currentTasMovie ! = null )
{
text + = " - " + _currentTasMovie . Name + ( _currentTasMovie . Changes ? "*" : "" ) ;
}
Text = text ;
}
2014-09-28 01:05:26 +00:00
public bool LoadProject ( string path )
2014-07-08 15:15:35 +00:00
{
2014-08-19 19:24:17 +00:00
if ( AskSaveChanges ( ) )
2014-07-08 15:15:35 +00:00
{
2014-10-14 18:09:30 +00:00
var movie = new TasMovie
2014-07-09 22:44:20 +00:00
{
2014-10-14 18:09:30 +00:00
Filename = path ,
ClientSettingsForSave = ClientSettingsForSave ,
GetClientSettingsOnLoad = GetClientSettingsOnLoad
2014-07-09 22:44:20 +00:00
} ;
2014-09-25 12:28:58 +00:00
2014-08-23 18:02:02 +00:00
movie . PropertyChanged + = TasMovie_OnPropertyChanged ;
2014-09-25 12:28:58 +00:00
movie . Load ( ) ;
2014-07-08 15:15:35 +00:00
2014-07-09 22:44:20 +00:00
var file = new FileInfo ( path ) ;
if ( ! file . Exists )
2014-07-08 15:15:35 +00:00
{
2014-07-28 01:51:11 +00:00
Global . Config . RecentTas . HandleLoadError ( path ) ;
2014-07-08 15:15:35 +00:00
}
2014-07-09 22:44:20 +00:00
2014-08-19 23:56:33 +00:00
WantsToControlStopMovie = false ;
2014-09-18 22:11:37 +00:00
2014-10-17 17:58:48 +00:00
var shouldRecord = movie . InputLogLength = = 0 ;
2014-09-18 22:11:37 +00:00
2014-10-18 19:23:14 +00:00
var result = StartNewMovieWrapper ( movie : movie , record : shouldRecord ) ;
2014-09-28 01:05:26 +00:00
if ( ! result )
{
return false ;
}
2014-08-19 19:24:17 +00:00
_currentTasMovie = Global . MovieSession . Movie as TasMovie ;
2014-10-14 18:09:30 +00:00
SetTasMovieCallbacks ( ) ;
WantsToControlStopMovie = true ;
2014-07-09 22:44:20 +00:00
Global . Config . RecentTas . Add ( path ) ;
2014-08-22 02:56:27 +00:00
Text = "TAStudio - " + _currentTasMovie . Name ;
2014-10-12 14:12:37 +00:00
2014-07-09 22:44:20 +00:00
RefreshDialog ( ) ;
2014-09-28 01:05:26 +00:00
return true ;
2014-07-08 15:15:35 +00:00
}
2014-09-28 01:05:26 +00:00
return false ;
2014-07-08 15:15:35 +00:00
}
2014-07-16 02:17:19 +00:00
public void RefreshDialog ( )
2014-07-08 15:15:35 +00:00
{
2014-08-29 02:58:52 +00:00
_currentTasMovie . FlushInputCache ( ) ;
_currentTasMovie . UseInputCache = true ;
2014-09-18 22:11:37 +00:00
TasView . RowCount = _currentTasMovie . InputLogLength + 1 ;
2014-08-23 15:19:48 +00:00
TasView . Refresh ( ) ;
2014-08-23 16:00:56 +00:00
2014-08-29 02:58:52 +00:00
_currentTasMovie . FlushInputCache ( ) ;
_currentTasMovie . UseInputCache = false ;
2014-07-15 23:43:17 +00:00
if ( MarkerControl ! = null )
{
2014-08-29 00:04:42 +00:00
MarkerControl . UpdateValues ( ) ;
2014-07-15 23:43:17 +00:00
}
2014-07-08 15:15:35 +00:00
}
2014-10-17 20:10:21 +00:00
private void DoAutoRestore ( )
2014-09-27 14:37:02 +00:00
{
2014-10-17 20:10:21 +00:00
if ( Global . Config . TAStudioAutoRestoreLastPosition & & _autoRestoreFrame . HasValue )
2014-09-27 14:37:02 +00:00
{
2014-10-17 20:10:21 +00:00
if ( _autoRestoreFrame > Global . Emulator . Frame ) // Don't unpause if we are already on the desired frame, else runaway seek
2014-09-22 23:24:34 +00:00
{
2014-09-27 14:37:02 +00:00
GlobalWin . MainForm . UnpauseEmulator ( ) ;
2014-10-17 20:10:21 +00:00
GlobalWin . MainForm . PauseOnFrame = _autoRestoreFrame ;
2014-07-16 23:04:56 +00:00
}
2014-07-13 15:26:50 +00:00
}
2014-10-17 20:10:21 +00:00
_autoRestoreFrame = null ;
2014-07-13 15:26:50 +00:00
}
2013-12-05 19:18:20 +00:00
private void SetUpColumns ( )
{
2014-10-12 16:37:45 +00:00
TasView . AllColumns . Clear ( ) ;
2014-07-06 22:13:12 +00:00
AddColumn ( MarkerColumnName , string . Empty , 18 ) ;
2013-12-07 17:29:47 +00:00
AddColumn ( FrameColumnName , "Frame#" , 68 ) ;
2013-12-05 19:18:20 +00:00
2014-07-09 21:56:27 +00:00
foreach ( var kvp in GenerateColumnNames ( ) )
2013-12-05 19:18:20 +00:00
{
2014-07-07 16:03:22 +00:00
AddColumn ( kvp . Key , kvp . Value , 20 * kvp . Value . Length ) ;
2013-12-07 17:29:47 +00:00
}
}
public void AddColumn ( string columnName , string columnText , int columnWidth )
{
2014-10-12 16:37:45 +00:00
if ( TasView . AllColumns [ columnName ] = = null )
2013-12-07 17:29:47 +00:00
{
2014-08-23 23:40:01 +00:00
var column = new InputRoll . RollColumn
2013-12-07 17:29:47 +00:00
{
Name = columnName ,
Text = columnText ,
Width = columnWidth ,
} ;
2014-10-12 16:37:45 +00:00
TasView . AllColumns . Add ( column ) ;
2013-12-05 19:18:20 +00:00
}
2013-12-01 04:00:02 +00:00
}
private void LoadConfigSettings ( )
{
_defaultWidth = Size . Width ;
_defaultHeight = Size . Height ;
2014-02-01 15:44:51 +00:00
if ( Global . Config . TAStudioSettings . UseWindowPosition )
2013-12-01 04:00:02 +00:00
{
2014-02-01 15:44:51 +00:00
Location = Global . Config . TAStudioSettings . WindowPosition ;
2013-12-01 04:00:02 +00:00
}
2014-02-01 15:44:51 +00:00
if ( Global . Config . TAStudioSettings . UseWindowSize )
2013-12-01 04:00:02 +00:00
{
2014-02-01 15:44:51 +00:00
Size = Global . Config . TAStudioSettings . WindowSize ;
2013-12-01 04:00:02 +00:00
}
}
private void SaveConfigSettings ( )
{
2014-02-01 15:44:51 +00:00
Global . Config . TAStudioSettings . Wndx = Location . X ;
Global . Config . TAStudioSettings . Wndy = Location . Y ;
Global . Config . TAStudioSettings . Width = Right - Left ;
Global . Config . TAStudioSettings . Height = Bottom - Top ;
2013-12-01 04:00:02 +00:00
}
2014-08-31 16:51:19 +00:00
private void StartAtNearestFrameAndEmulate ( int frame )
{
_currentTasMovie . SwitchToPlay ( ) ;
2014-10-14 13:31:14 +00:00
var closestState = _currentTasMovie . TasStateManager . GetStateClosestToFrame ( frame ) ;
2014-08-31 16:51:19 +00:00
if ( closestState ! = null )
{
2014-09-27 15:19:07 +00:00
LoadState ( closestState . ToArray ( ) ) ;
2014-08-31 16:51:19 +00:00
}
GlobalWin . MainForm . PauseOnFrame = frame ;
GlobalWin . MainForm . UnpauseEmulator ( ) ;
}
2014-09-27 15:19:07 +00:00
private void LoadState ( byte [ ] state )
{
Global . Emulator . LoadStateBinary ( new BinaryReader ( new MemoryStream ( state ) ) ) ;
_hackyDontUpdate = true ;
GlobalWin . Tools . UpdateBefore ( ) ;
GlobalWin . Tools . UpdateAfter ( ) ;
_hackyDontUpdate = false ;
}
2014-10-11 17:43:24 +00:00
private void UpdateOtherTools ( ) // a hack probably, surely there is a better way to do this
{
_hackyDontUpdate = true ;
GlobalWin . Tools . UpdateBefore ( ) ;
GlobalWin . Tools . UpdateAfter ( ) ;
_hackyDontUpdate = false ;
2013-12-15 04:45:46 +00:00
}
2014-07-17 19:00:28 +00:00
public void TogglePause ( )
{
2014-07-17 20:35:12 +00:00
GlobalWin . MainForm . TogglePause ( ) ;
2014-07-17 19:00:28 +00:00
}
2013-12-19 03:45:11 +00:00
private void SetSplicer ( )
{
// TODO: columns selected
// TODO: clipboard
2014-08-30 18:42:14 +00:00
var list = TasView . SelectedRows ;
2014-08-23 18:02:02 +00:00
string message = "Selected: " ;
2013-12-19 03:45:11 +00:00
2014-10-13 18:28:29 +00:00
if ( list . Any ( ) )
2013-12-19 03:45:11 +00:00
{
2014-10-13 18:28:29 +00:00
message + = list . Count ( ) + " rows 0 col, Clipboard: " ;
2013-12-19 03:45:11 +00:00
}
else
{
2014-10-13 18:28:29 +00:00
message + = list . Count ( ) + " none, Clipboard: " ;
2013-12-19 03:45:11 +00:00
}
2014-10-17 17:58:48 +00:00
message + = _tasClipboard . Any ( ) ? _tasClipboard . Count + " rows 0 col" : "empty" ;
2013-12-19 03:45:11 +00:00
SplicerStatusLabel . Text = message ;
}
2014-02-01 15:44:51 +00:00
private void RefreshFloatingWindowControl ( )
{
Owner = Global . Config . TAStudioSettings . FloatingWindow ? null : GlobalWin . MainForm ;
}
2014-07-16 02:17:19 +00:00
public void CallAddMarkerPopUp ( int? frame = null )
2014-07-15 23:43:17 +00:00
{
2014-07-16 01:37:50 +00:00
var markerFrame = frame ? ? TasView . LastSelectedIndex ? ? Global . Emulator . Frame ;
2014-07-15 23:43:17 +00:00
InputPrompt i = new InputPrompt
{
2014-07-16 01:37:50 +00:00
Text = "Marker for frame " + markerFrame ,
2014-07-28 02:40:30 +00:00
TextInputType = InputPrompt . InputType . Text ,
2014-08-22 03:59:12 +00:00
Message = "Enter a message" ,
InitialValue = _currentTasMovie . Markers . IsMarker ( markerFrame ) ? _currentTasMovie . Markers . PreviousOrCurrent ( markerFrame ) . Message : ""
2014-07-15 23:43:17 +00:00
} ;
var result = i . ShowHawkDialog ( ) ;
if ( result = = DialogResult . OK )
{
2014-08-19 19:24:17 +00:00
_currentTasMovie . Markers . Add ( markerFrame , i . PromptText ) ;
2014-08-29 00:04:42 +00:00
MarkerControl . UpdateValues ( ) ;
2014-07-15 23:43:17 +00:00
}
}
2014-07-11 02:31:43 +00:00
private void UpdateChangesIndicator ( )
{
// TODO
}
2014-07-25 00:57:06 +00:00
// TODO: move me
// Sets either the pending frame or the tas input log
private void ToggleBoolState ( int frame , string buttonName )
{
2014-08-19 19:24:17 +00:00
if ( frame < _currentTasMovie . InputLogLength )
2014-07-25 00:57:06 +00:00
{
2014-08-19 19:24:17 +00:00
_currentTasMovie . ToggleBoolState ( frame , buttonName ) ;
2014-07-25 00:57:06 +00:00
}
2014-08-19 19:24:17 +00:00
else if ( frame = = Global . Emulator . Frame & & frame = = _currentTasMovie . InputLogLength )
2014-07-25 00:57:06 +00:00
{
Global . ClickyVirtualPadController . Toggle ( buttonName ) ;
}
}
// TODO: move me
// Sets either the pending frame or the tas input log
private void SetBoolState ( int frame , string buttonName , bool value )
{
2014-08-19 19:24:17 +00:00
if ( frame < _currentTasMovie . InputLogLength )
2014-07-25 00:57:06 +00:00
{
2014-08-19 19:24:17 +00:00
_currentTasMovie . SetBoolState ( frame , buttonName , value ) ;
2014-07-25 00:57:06 +00:00
}
2014-08-19 19:24:17 +00:00
else if ( frame = = Global . Emulator . Frame & & frame = = _currentTasMovie . InputLogLength )
2014-07-25 00:57:06 +00:00
{
Global . ClickyVirtualPadController . SetBool ( buttonName , value ) ;
}
}
2014-09-25 17:52:21 +00:00
private void SetColumnsFromCurrentStickies ( )
{
2014-10-12 16:37:45 +00:00
foreach ( var column in TasView . VisibleColumns )
2014-09-25 17:52:21 +00:00
{
if ( Global . StickyXORAdapter . IsSticky ( column . Name ) )
{
column . Emphasis = true ;
}
}
}
2014-10-17 17:40:11 +00:00
private void NewDefaultProject ( )
{
NewTasMovie ( ) ;
2014-10-18 15:27:53 +00:00
StartNewMovieWrapper ( record : true ) ;
2014-10-17 17:40:11 +00:00
_currentTasMovie . TasStateManager . Capture ( ) ;
_currentTasMovie . SwitchToRecord ( ) ;
_currentTasMovie . ClearChanges ( ) ;
}
2014-10-18 19:12:36 +00:00
private bool StartNewMovieWrapper ( bool record , IMovie movie = null )
2014-10-18 15:27:53 +00:00
{
_initializing = true ;
2014-10-18 19:12:36 +00:00
var result = GlobalWin . MainForm . StartNewMovie ( movie ! = null ? movie : _currentTasMovie , record ) ;
2014-10-18 15:27:53 +00:00
_initializing = false ;
return result ;
}
2014-10-17 17:40:11 +00:00
#region Dialog Events
2014-08-21 22:53:03 +00:00
private void Tastudio_Load ( object sender , EventArgs e )
2014-10-18 15:27:53 +00:00
{
InitializeOnLoad ( ) ;
LoadConfigSettings ( ) ;
SetColumnsFromCurrentStickies ( ) ;
RightClickMenu . Items . AddRange ( TasView . GenerateContextMenuItems ( ) . ToArray ( ) ) ;
2014-10-19 15:29:03 +00:00
RightClickMenu . Items
. OfType < ToolStripMenuItem > ( )
. First ( t = > t . Name = = "RotateMenuItem" )
. Click + = ( o , ov ) = >
{
_currentTasMovie . FlagChanges ( ) ;
} ;
2014-10-18 15:27:53 +00:00
RefreshDialog ( ) ;
}
private void InitializeOnLoad ( )
2014-08-21 22:53:03 +00:00
{
// Start Scenario 1: A regular movie is active
if ( Global . MovieSession . Movie . IsActive & & ! ( Global . MovieSession . Movie is TasMovie ) )
{
var result = MessageBox . Show ( "In order to use Tastudio, a new project must be created from the current movie\nThe current movie will be saved and closed, and a new project file will be created\nProceed?" , "Convert movie" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ;
if ( result = = DialogResult . OK )
{
ConvertCurrentMovieToTasproj ( ) ;
}
else
{
Close ( ) ;
return ;
}
}
// Start Scenario 2: A tasproj is already active
else if ( Global . MovieSession . Movie . IsActive & & Global . MovieSession . Movie is TasMovie )
{
// Nothing to do
}
// Start Scenario 3: No movie, but user wants to autload their last project
else if ( Global . Config . AutoloadTAStudioProject & & ! string . IsNullOrEmpty ( Global . Config . RecentTas . MostRecent ) )
{
2014-09-28 01:05:26 +00:00
var result = LoadProject ( Global . Config . RecentTas . MostRecent ) ;
if ( ! result )
{
2014-10-18 01:26:30 +00:00
TasView . AllColumns . Clear ( ) ;
2014-10-17 17:40:11 +00:00
NewDefaultProject ( ) ;
2014-09-28 01:05:26 +00:00
}
2014-08-21 22:53:03 +00:00
}
// Start Scenario 4: No movie, default behavior of engaging tastudio with a new default project
else
{
2014-10-17 17:40:11 +00:00
NewDefaultProject ( ) ;
2014-08-21 22:53:03 +00:00
}
EngageTastudio ( ) ;
2014-10-14 18:42:24 +00:00
if ( ! TasView . AllColumns . Any ( ) ) // If a project with column settings has already been loaded we don't need to do this
{
SetUpColumns ( ) ;
}
2014-08-21 22:53:03 +00:00
}
private void Tastudio_Closing ( object sender , FormClosingEventArgs e )
{
if ( AskSaveChanges ( ) )
{
2014-10-18 20:40:20 +00:00
WantsToControlStopMovie = false ;
2014-08-21 22:53:03 +00:00
SaveConfigSettings ( ) ;
GlobalWin . MainForm . StopMovie ( saveChanges : false ) ;
DisengageTastudio ( ) ;
}
else
{
e . Cancel = true ;
}
}
2014-08-19 19:24:17 +00:00
2014-10-17 17:40:11 +00:00
protected override void OnShown ( EventArgs e )
{
RefreshFloatingWindowControl ( ) ;
base . OnShown ( e ) ;
}
/// <summary>
/// This method is called everytime the Changes property is toggled on a TasMovie instance.
/// </summary>
2014-08-23 18:02:02 +00:00
private void TasMovie_OnPropertyChanged ( object sender , PropertyChangedEventArgs e )
{
2014-09-16 23:26:17 +00:00
SetTextProperty ( ) ;
2014-08-23 18:02:02 +00:00
}
2014-09-19 20:49:51 +00:00
private void RightClickMenu_Opened ( object sender , EventArgs e )
{
2014-10-15 22:52:23 +00:00
SetMarkersContextMenuItem . Enabled =
SelectBetweenMarkersContextMenuItem . Enabled =
RemoveMarkersContextMenuItem . Enabled =
DeselectContextMenuItem . Enabled =
ClearContextMenuItem . Enabled =
DeleteFramesContextMenuItem . Enabled =
CloneContextMenuItem . Enabled =
InsertFrameContextMenuItem . Enabled =
InsertNumFramesContextMenuItem . Enabled =
TruncateContextMenuItem . Enabled =
TasView . SelectedRows . Any ( ) ;
2014-10-15 16:50:51 +00:00
RemoveMarkersContextMenuItem . Enabled = _currentTasMovie . Markers . Any ( m = > TasView . SelectedRows . Contains ( m . Frame ) ) ; // Disable the option to remove markers if no markers are selected (FCEUX does this).
2014-09-19 20:49:51 +00:00
}
2014-02-01 15:44:51 +00:00
#endregion
2013-12-01 04:00:02 +00:00
}
}