From 4455d5deac9b07c0830ac583b1d9e3b2964b00ab Mon Sep 17 00:00:00 2001 From: kylelyk Date: Sun, 24 Aug 2014 14:41:56 +0000 Subject: [PATCH] Editing Markers now is managed by TasMovie as a change to the movie file. Fixed bugs to do with adding and deleting markers. --- .../movie/tasproj/TasMovie.cs | 15 ++++-- .../movie/tasproj/TasMovieMarker.cs | 49 +++++++++++++++++-- .../tools/TAStudio/MarkerControl.cs | 4 +- .../tools/TAStudio/TAStudio.cs | 1 - 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 43638702ae..3306e6339f 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -14,6 +14,7 @@ namespace BizHawk.Client.Common { private List LagLog = new List(); private readonly TasStateManager StateManager; + public TasMovieMarkerList Markers { get; set; } public TasMovie(string path) : base(path) { } @@ -23,6 +24,7 @@ namespace BizHawk.Client.Common StateManager = new TasStateManager(this); Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; Markers = new TasMovieMarkerList(this); + Markers.CollectionChanged += Markers_CollectionChanged; Markers.Add(0, StartsFromSavestate ? "Savestate" : "Power on"); } @@ -31,7 +33,7 @@ namespace BizHawk.Client.Common get { return Extension; } } - #region OnPropertyChanged Event + #region Events and Handlers public event PropertyChangedEventHandler PropertyChanged; @@ -49,8 +51,6 @@ namespace BizHawk.Client.Common } } - #endregion - //This event is Raised ony when Changes is TOGGLED. private void OnPropertyChanged(string propertyName) { @@ -61,9 +61,14 @@ namespace BizHawk.Client.Common } } - public new const string Extension = "tasproj"; + void Markers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + Changes = true; + } - public TasMovieMarkerList Markers { get; set; } + #endregion + + public new const string Extension = "tasproj"; public TasMovieRecord this[int index] { diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs index aadb839fe1..6922bfb1a6 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using System.Text; @@ -72,7 +74,6 @@ namespace BizHawk.Client.Common } } - //Add functions as needed public class TasMovieMarkerList : List { private readonly TasMovie _movie; @@ -82,6 +83,17 @@ namespace BizHawk.Client.Common _movie = movie; } + public event NotifyCollectionChangedEventHandler CollectionChanged; + + private void OnListChanged(NotifyCollectionChangedAction action) + { + if (CollectionChanged != null) + { + //TODO Allow different types + CollectionChanged.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + } + } + public override string ToString() { var sb = new StringBuilder(); @@ -98,12 +110,17 @@ namespace BizHawk.Client.Common var existingItem = this.FirstOrDefault(m => m.Frame == item.Frame); if (existingItem != null) { - existingItem.Message = item.Message; + if (existingItem.Message != item.Message) + { + existingItem.Message = item.Message; + OnListChanged(NotifyCollectionChangedAction.Replace); + } } else { base.Add(item); this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame)); + OnListChanged(NotifyCollectionChangedAction.Add); } } @@ -114,19 +131,39 @@ namespace BizHawk.Client.Common public new void AddRange(IEnumerable collection) { - base.AddRange(collection); + foreach(TasMovieMarker m in collection){ + Add(m); + } } public new void Insert(int index, TasMovieMarker item) { base.Insert(index, item); this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame)); + OnListChanged(NotifyCollectionChangedAction.Add); } public new void InsertRange(int index, IEnumerable collection) { base.InsertRange(index, collection); this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame)); + OnListChanged(NotifyCollectionChangedAction.Add); + } + + public new void Remove(TasMovieMarker item) + { + base.Remove(item); + OnListChanged(NotifyCollectionChangedAction.Remove); + } + + public new int RemoveAll(Predicate match) + { + int removeCount = base.RemoveAll(match); + if (removeCount > 0) + { + OnListChanged(NotifyCollectionChangedAction.Remove); + } + return removeCount; } /// @@ -144,6 +181,10 @@ namespace BizHawk.Client.Common deletedCount++; } } + if (deletedCount > 0) + { + OnListChanged(NotifyCollectionChangedAction.Remove); + } return deletedCount; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index aa5ed335ba..89d0290b3e 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -97,6 +97,7 @@ namespace BizHawk.Client.EmuHawk private void AddBtn_Click(object sender, EventArgs e) { Tastudio.CallAddMarkerPopUp(); + MarkerView_SelectedIndexChanged(sender, e); } public new void Refresh() @@ -111,13 +112,14 @@ namespace BizHawk.Client.EmuHawk private void MarkerView_SelectedIndexChanged(object sender, EventArgs e) { - RemoveBtn.Enabled = SelectedIndices.Any(); + RemoveBtn.Enabled = SelectedIndices.Any(i => i < Markers.Count); } private void RemoveBtn_Click(object sender, EventArgs e) { SelectedMarkers.ForEach(i => Markers.Remove(i)); Tastudio.RefreshDialog(); + MarkerView_SelectedIndexChanged(sender, e); } private IEnumerable SelectedIndices diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 8d3764922a..9cd1b40547 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -797,7 +797,6 @@ namespace BizHawk.Client.EmuHawk private void RemoveMarkersMenuItem_Click(object sender, EventArgs e) { - _currentTasMovie.Markers.RemoveAll(m => TasView.SelectedIndices.Contains(m.Frame)); RefreshDialog(); }