diff --git a/BizHawk.MultiClient/PlayMovie.Designer.cs b/BizHawk.MultiClient/PlayMovie.Designer.cs index c250dfdbd9..683991a162 100644 --- a/BizHawk.MultiClient/PlayMovie.Designer.cs +++ b/BizHawk.MultiClient/PlayMovie.Designer.cs @@ -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); diff --git a/BizHawk.MultiClient/PlayMovie.cs b/BizHawk.MultiClient/PlayMovie.cs index 89055febb5..8d2a093bff 100644 --- a/BizHawk.MultiClient/PlayMovie.cs +++ b/BizHawk.MultiClient/PlayMovie.cs @@ -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 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; + } + } + } } } diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index df3abed1d1..6fbc49882f 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -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; + } } }