Added a CompareTo function for Movie objects, and created a basic insertion sort for the play movie dialog.

This commit is contained in:
offspring131313 2011-05-24 01:19:42 +00:00
parent de6aa0659e
commit 4ea39c8525
3 changed files with 147 additions and 0 deletions

View File

@ -103,6 +103,7 @@
this.MovieView.TabIndex = 3;
this.MovieView.UseCompatibleStateImageBehavior = false;
this.MovieView.View = System.Windows.Forms.View.Details;
this.MovieView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.MovieView_ColumnClick);
this.MovieView.DragDrop += new System.Windows.Forms.DragEventHandler(this.MovieView_DragDrop);
this.MovieView.SelectedIndexChanged += new System.EventHandler(this.MovieView_SelectedIndexChanged);
this.MovieView.DragEnter += new System.Windows.Forms.DragEventHandler(this.MovieView_DragEnter);

View File

@ -185,5 +185,38 @@ namespace BizHawk.MultiClient
AddMovieToList(path);
}
}
private void MovieView_ColumnClick(object sender, ColumnClickEventArgs e)
{
OrderColumn(e.Column);
}
private void OrderColumn(int columnToOrder)
{
string columnName = MovieView.Columns[columnToOrder].Text;
InsertionSort(MovieList, columnName);
MovieView.Refresh();
}
private void InsertionSort(List<Movie> smallList, string parameter)
{
for (int i = 0; i < smallList.Count; i++)
{
int smallest = i;
for (int k = i + 1; k < smallList.Count; k++)
{
if (smallList[smallest].CompareTo(smallList[k], parameter) == 1)
smallest = k;
}
if (i != smallest)
{
Movie temp = smallList[i];
smallList[i] = smallList[smallest];
smallList[smallest] = temp;
}
}
}
}
}

View File

@ -490,5 +490,118 @@ namespace BizHawk.MultiClient
}
return -1;
}
public int CompareTo(Movie Other, string parameter)
{
int compare = 0;
if (parameter == "File")
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
{
compare = CompareGameName(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "SysID")
{
compare = CompareSysID(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareGameName(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "Game")
{
compare = CompareGameName(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
compare = CompareLength(Other);
}
}
}
else if (parameter == "Length")
{
compare = CompareLength(Other);
if (compare == 0)
{
compare = CompareFileName(Other);
if (compare == 0)
{
compare = CompareSysID(Other);
if (compare == 0)
compare = CompareGameName(Other);
}
}
}
return compare;
}
private int CompareFileName(Movie Other)
{
string otherName = Path.GetFileName(Other.GetFilePath());
string thisName = Path.GetFileName(this.Filename);
return thisName.CompareTo(otherName);
}
private int CompareSysID(Movie Other)
{
string otherSysID = Other.GetSysID();
string thisSysID = this.GetSysID();
if (thisSysID == null && otherSysID == null)
return 0;
else if (thisSysID == null)
return -1;
else if (otherSysID == null)
return 1;
else
return thisSysID.CompareTo(otherSysID);
}
private int CompareGameName(Movie Other)
{
string otherGameName = Other.GetGameName();
string thisGameName = this.GetGameName();
if (thisGameName == null && otherGameName == null)
return 0;
else if (thisGameName == null)
return -1;
else if (otherGameName == null)
return 1;
else
return thisGameName.CompareTo(otherGameName);
}
private int CompareLength(Movie Other)
{
int otherLength = Other.Frames;
int thisLength = this.Frames;
if (thisLength < otherLength)
return -1;
else if (thisLength > otherLength)
return 1;
else
return 0;
}
}
}