start work on filtering by rating
This commit is contained in:
parent
067b54a77d
commit
3c1e2c8dad
36
Program.cs
36
Program.cs
@ -563,6 +563,7 @@ public class Game : GameWindow {
|
|||||||
int VertexBufferObject;
|
int VertexBufferObject;
|
||||||
int ElementBufferObject;
|
int ElementBufferObject;
|
||||||
int VertexArrayObject;
|
int VertexArrayObject;
|
||||||
|
List<Photo> allPhotos = new();
|
||||||
List<Photo> photos = new();
|
List<Photo> photos = new();
|
||||||
HashSet<int> loadedImages = new();
|
HashSet<int> loadedImages = new();
|
||||||
int photoIndex = 0;
|
int photoIndex = 0;
|
||||||
@ -644,28 +645,42 @@ public class Game : GameWindow {
|
|||||||
// Make sure the photoIndex is actually valid.
|
// Make sure the photoIndex is actually valid.
|
||||||
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
|
photoIndex = Math.Clamp(photoIndex, 0, photos.Count - 1);
|
||||||
|
|
||||||
|
// Handle presses of the "rating" keys -- 0-5 and `.
|
||||||
|
// A normal press just sets the rating of the current photo.
|
||||||
|
// If the user is holding "shift", we instead filter to only show photos of that rating or higher.
|
||||||
|
int rating = -1;
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) {
|
if (input.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) {
|
||||||
photos[photoIndex].Rating = 0;
|
rating = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D1)) {
|
if (input.IsKeyPressed(Keys.D1)) {
|
||||||
photos[photoIndex].Rating = 1;
|
rating = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D2)) {
|
if (input.IsKeyPressed(Keys.D2)) {
|
||||||
photos[photoIndex].Rating = 2;
|
rating = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D3)) {
|
if (input.IsKeyPressed(Keys.D3)) {
|
||||||
photos[photoIndex].Rating = 3;
|
rating = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D4)) {
|
if (input.IsKeyPressed(Keys.D4)) {
|
||||||
photos[photoIndex].Rating = 4;
|
rating = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.D5)) {
|
if (input.IsKeyPressed(Keys.D5)) {
|
||||||
photos[photoIndex].Rating = 5;
|
rating = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rating >= 0) {
|
||||||
|
bool shifted = input.IsKeyDown(Keys.LeftShift) || input.IsKeyDown(Keys.RightShift);
|
||||||
|
if (shifted) {
|
||||||
|
FilterByRating(rating);
|
||||||
|
} else {
|
||||||
|
photos[photoIndex].Rating = rating;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.IsKeyPressed(Keys.Q)) {
|
if (input.IsKeyPressed(Keys.Q)) {
|
||||||
@ -693,6 +708,10 @@ public class Game : GameWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilterByRating(int rating) {
|
||||||
|
Console.WriteLine("filter to " + rating);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnLoad() {
|
protected override void OnLoad() {
|
||||||
base.OnLoad();
|
base.OnLoad();
|
||||||
|
|
||||||
@ -741,11 +760,12 @@ public class Game : GameWindow {
|
|||||||
string file = files[i];
|
string file = files[i];
|
||||||
if (file.ToLower().EndsWith(".jpg")) {
|
if (file.ToLower().EndsWith(".jpg")) {
|
||||||
Photo photo = new Photo(file, TEXTURE_BLACK);
|
Photo photo = new Photo(file, TEXTURE_BLACK);
|
||||||
photos.Add(photo);
|
allPhotos.Add(photo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
photos.Sort(ComparePhotosByDate);
|
allPhotos.Sort(ComparePhotosByDate);
|
||||||
|
photos = allPhotos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ComparePhotosByDate(Photo x, Photo y) {
|
private static int ComparePhotosByDate(Photo x, Photo y) {
|
||||||
|
Loading…
Reference in New Issue
Block a user