2013-04-15 02:14:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-06-30 20:10:52 +00:00
|
|
|
|
using System.Linq;
|
2013-02-25 01:23:03 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
|
|
|
|
public class HistoryCollection
|
|
|
|
|
{
|
2013-06-30 20:10:52 +00:00
|
|
|
|
public List<List<Watch>> History { get; private set; }
|
2013-04-15 02:14:14 +00:00
|
|
|
|
private int curPos; //1-based
|
2013-08-14 01:04:14 +00:00
|
|
|
|
public bool Enabled { get; private set; }
|
2013-02-25 01:23:03 +00:00
|
|
|
|
|
2013-08-14 01:04:14 +00:00
|
|
|
|
public HistoryCollection(bool enabled)
|
2013-06-30 20:10:52 +00:00
|
|
|
|
{
|
|
|
|
|
History = new List<List<Watch>>();
|
2013-08-14 01:04:14 +00:00
|
|
|
|
Enabled = enabled;
|
2013-06-30 20:10:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-14 01:04:14 +00:00
|
|
|
|
public HistoryCollection(List<Watch> newState, bool enabled)
|
2013-02-25 01:23:03 +00:00
|
|
|
|
{
|
2013-06-30 20:10:52 +00:00
|
|
|
|
History = new List<List<Watch>>();
|
2013-02-25 01:23:03 +00:00
|
|
|
|
AddState(newState);
|
2013-08-14 01:04:14 +00:00
|
|
|
|
Enabled = enabled;
|
2013-02-25 01:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-30 20:10:52 +00:00
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
History = new List<List<Watch>>();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 01:23:03 +00:00
|
|
|
|
public bool CanUndo
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
get { return Enabled && curPos > 1; }
|
2013-02-25 01:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanRedo
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
get { return Enabled && curPos < History.Count; }
|
2013-06-30 20:10:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasHistory
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
get { return Enabled && History.Any(); }
|
2013-02-25 01:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddState(List<Watch> newState)
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
if (Enabled)
|
2013-02-25 01:23:03 +00:00
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
if (curPos < History.Count)
|
2013-02-25 01:23:03 +00:00
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
for (int i = curPos + 1; i <= History.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
History.Remove(History[i - 1]);
|
|
|
|
|
}
|
2013-02-25 01:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-14 01:04:14 +00:00
|
|
|
|
History.Add(newState);
|
|
|
|
|
curPos = History.Count;
|
|
|
|
|
}
|
2013-02-25 01:23:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Watch> Undo()
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
if (CanUndo && Enabled)
|
2013-02-25 01:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
curPos--;
|
|
|
|
|
return History[curPos - 1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Watch> Redo()
|
|
|
|
|
{
|
2013-08-14 01:04:14 +00:00
|
|
|
|
if (CanRedo && Enabled)
|
2013-02-25 01:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
curPos++;
|
|
|
|
|
return History[curPos - 1];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|