2014-08-24 14:41:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Specialized;
|
2014-07-09 16:35:39 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a TasMovie Marker
|
|
|
|
|
/// A marker is a tagged frame with a message
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TasMovieMarker
|
|
|
|
|
{
|
|
|
|
|
private int _frame;
|
|
|
|
|
|
|
|
|
|
public TasMovieMarker(int frame, string message = "")
|
|
|
|
|
{
|
|
|
|
|
_frame = frame;
|
|
|
|
|
Message = message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Parses a Marker from a line of text
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TasMovieMarker(string line)
|
|
|
|
|
{
|
|
|
|
|
var split = line.Split('\t');
|
|
|
|
|
_frame = int.Parse(split[0]);
|
|
|
|
|
Message = split[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual int Frame
|
|
|
|
|
{
|
|
|
|
|
get { return _frame; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual string Message { get; set; }
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Frame.ToString() + '\t' + Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return this.Frame.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (obj is TasMovieMarker)
|
|
|
|
|
{
|
|
|
|
|
return this.Frame == (obj as TasMovieMarker).Frame;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(TasMovieMarker marker, int frame)
|
|
|
|
|
{
|
|
|
|
|
return marker.Frame == frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(TasMovieMarker marker, int frame)
|
|
|
|
|
{
|
|
|
|
|
return marker.Frame != frame;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TasMovieMarkerList : List<TasMovieMarker>
|
|
|
|
|
{
|
2014-07-17 18:38:30 +00:00
|
|
|
|
private readonly TasMovie _movie;
|
|
|
|
|
|
|
|
|
|
public TasMovieMarkerList(TasMovie movie)
|
|
|
|
|
{
|
|
|
|
|
_movie = movie;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-24 14:41:56 +00:00
|
|
|
|
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
|
|
|
|
|
|
|
|
|
private void OnListChanged(NotifyCollectionChangedAction action)
|
|
|
|
|
{
|
|
|
|
|
if (CollectionChanged != null)
|
|
|
|
|
{
|
|
|
|
|
//TODO Allow different types
|
|
|
|
|
CollectionChanged.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 16:35:39 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2014-07-16 02:17:19 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2014-07-09 16:35:39 +00:00
|
|
|
|
foreach (var marker in this)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(marker.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Add(TasMovieMarker item)
|
|
|
|
|
{
|
|
|
|
|
var existingItem = this.FirstOrDefault(m => m.Frame == item.Frame);
|
|
|
|
|
if (existingItem != null)
|
|
|
|
|
{
|
2014-08-24 14:41:56 +00:00
|
|
|
|
if (existingItem.Message != item.Message)
|
|
|
|
|
{
|
|
|
|
|
existingItem.Message = item.Message;
|
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Replace);
|
|
|
|
|
}
|
2014-07-09 16:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base.Add(item);
|
2014-07-23 01:52:12 +00:00
|
|
|
|
this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame));
|
2014-08-24 14:41:56 +00:00
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Add);
|
2014-07-09 16:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(int frame, string message)
|
|
|
|
|
{
|
|
|
|
|
Add(new TasMovieMarker(frame, message));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 01:52:12 +00:00
|
|
|
|
public new void AddRange(IEnumerable<TasMovieMarker> collection)
|
2014-07-09 16:35:39 +00:00
|
|
|
|
{
|
2014-08-24 14:41:56 +00:00
|
|
|
|
foreach(TasMovieMarker m in collection){
|
|
|
|
|
Add(m);
|
|
|
|
|
}
|
2014-07-23 01:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Insert(int index, TasMovieMarker item)
|
|
|
|
|
{
|
|
|
|
|
base.Insert(index, item);
|
|
|
|
|
this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame));
|
2014-08-24 14:41:56 +00:00
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Add);
|
2014-07-23 01:52:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void InsertRange(int index, IEnumerable<TasMovieMarker> collection)
|
|
|
|
|
{
|
|
|
|
|
base.InsertRange(index, collection);
|
|
|
|
|
this.Sort((m1, m2) => m1.Frame.CompareTo(m2.Frame));
|
2014-08-24 14:41:56 +00:00
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Add);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new void Remove(TasMovieMarker item)
|
|
|
|
|
{
|
|
|
|
|
base.Remove(item);
|
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Remove);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public new int RemoveAll(Predicate<TasMovieMarker> match)
|
|
|
|
|
{
|
|
|
|
|
int removeCount = base.RemoveAll(match);
|
|
|
|
|
if (removeCount > 0)
|
|
|
|
|
{
|
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Remove);
|
|
|
|
|
}
|
|
|
|
|
return removeCount;
|
2014-07-09 16:35:39 +00:00
|
|
|
|
}
|
2014-07-13 14:13:20 +00:00
|
|
|
|
|
2014-08-21 22:53:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes all markers at or below the given start frame.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startFrame">The first frame for markers to be deleted.</param>
|
|
|
|
|
/// <returns>Number of markers deleted.</returns>
|
|
|
|
|
public int TruncateAt(int startFrame)
|
|
|
|
|
{
|
|
|
|
|
int deletedCount = 0;
|
|
|
|
|
for (int i = Count - 1; i > -1; i--)
|
|
|
|
|
{
|
|
|
|
|
if(this[i].Frame >= startFrame){
|
|
|
|
|
RemoveAt(i);
|
|
|
|
|
deletedCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-24 14:41:56 +00:00
|
|
|
|
if (deletedCount > 0)
|
|
|
|
|
{
|
|
|
|
|
OnListChanged(NotifyCollectionChangedAction.Remove);
|
|
|
|
|
}
|
2014-08-21 22:53:03 +00:00
|
|
|
|
return deletedCount;
|
|
|
|
|
}
|
2014-08-21 21:24:25 +00:00
|
|
|
|
|
2014-07-13 14:13:20 +00:00
|
|
|
|
public TasMovieMarker Previous(int currentFrame)
|
2014-07-17 19:00:28 +00:00
|
|
|
|
{
|
|
|
|
|
return this
|
|
|
|
|
.Where(m => m.Frame < currentFrame)
|
|
|
|
|
.OrderBy(m => m.Frame)
|
|
|
|
|
.LastOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TasMovieMarker PreviousOrCurrent(int currentFrame)
|
2014-07-13 14:13:20 +00:00
|
|
|
|
{
|
|
|
|
|
return this
|
2014-07-15 23:43:17 +00:00
|
|
|
|
.Where(m => m.Frame <= currentFrame)
|
2014-07-13 14:13:20 +00:00
|
|
|
|
.OrderBy(m => m.Frame)
|
2014-07-15 23:43:17 +00:00
|
|
|
|
.LastOrDefault();
|
2014-07-13 14:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TasMovieMarker Next(int currentFrame)
|
|
|
|
|
{
|
|
|
|
|
return this
|
|
|
|
|
.Where(m => m.Frame > currentFrame)
|
|
|
|
|
.OrderBy(m => m.Frame)
|
2014-07-15 23:43:17 +00:00
|
|
|
|
.FirstOrDefault();
|
2014-07-13 14:13:20 +00:00
|
|
|
|
}
|
2014-07-16 00:10:37 +00:00
|
|
|
|
|
|
|
|
|
public bool IsMarker(int frame)
|
|
|
|
|
{
|
|
|
|
|
return this.Any(m => m == frame);
|
|
|
|
|
}
|
2014-09-21 15:17:29 +00:00
|
|
|
|
|
|
|
|
|
public TasMovieMarker Get(int frame)
|
|
|
|
|
{
|
|
|
|
|
return this.FirstOrDefault(m => m == frame);
|
|
|
|
|
}
|
2014-07-09 16:35:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|