Ejemplo n.º 1
0
        private List <BeatmapCollection> readCollections(Stream stream, ProgressNotification notification = null)
        {
            if (notification != null)
            {
                notification.Text     = "Reading collections...";
                notification.Progress = 0;
            }

            var result = new List <BeatmapCollection>();

            try
            {
                using (var sr = new SerializationReader(stream))
                {
                    sr.ReadInt32(); // Version

                    int collectionCount = sr.ReadInt32();
                    result.Capacity = collectionCount;

                    for (int i = 0; i < collectionCount; i++)
                    {
                        if (notification?.CancellationToken.IsCancellationRequested == true)
                        {
                            return(result);
                        }

                        var collection = new BeatmapCollection {
                            Name = { Value = sr.ReadString() }
                        };
                        int mapCount = sr.ReadInt32();

                        for (int j = 0; j < mapCount; j++)
                        {
                            if (notification?.CancellationToken.IsCancellationRequested == true)
                            {
                                return(result);
                            }

                            string checksum = sr.ReadString();

                            collection.BeatmapHashes.Add(checksum);
                        }

                        if (notification != null)
                        {
                            notification.Text     = $"Imported {i + 1} of {collectionCount} collections";
                            notification.Progress = (float)(i + 1) / collectionCount;
                        }

                        result.Add(collection);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "Failed to read collection database.");
            }

            return(result);
        }
            public DeleteButton(BeatmapCollection collection)
            {
                this.collection  = collection;
                RelativeSizeAxes = Axes.Y;

                Width = button_width + item_height / 2; // add corner radius to cover with fill
            }
            public ItemContent(BeatmapCollection collection)
            {
                this.collection = collection;

                RelativeSizeAxes = Axes.X;
                Height           = item_height;
                Masking          = true;

                collectionName = collection.Name.GetBoundCopy();
            }
Ejemplo n.º 4
0
        public DeleteCollectionDialog(BeatmapCollection collection, Action deleteAction)
        {
            HeaderText = "Confirm deletion of";
            BodyText   = $"{collection.Name.Value} ({"beatmap".ToQuantity(collection.BeatmapHashes.Count)})";

            Icon = FontAwesome.Regular.TrashAlt;

            Buttons = new PopupDialogButton[]
            {
                new PopupDialogOkButton
                {
                    Text   = @"Yes. Go for it.",
                    Action = deleteAction
                },
                new PopupDialogCancelButton
                {
                    Text = @"No! Abort mission!",
                },
            };
        }
Ejemplo n.º 5
0
        public DeleteCollectionDialog(BeatmapCollection collection, Action deleteAction)
        {
            HeaderText = "確認刪除收藏";
            BodyText   = $"{collection.Name.Value} ({collection.Beatmaps.Count} 個圖譜)"; // {"beatmap".ToQuantity(collection.Beatmaps.Count)}

            Icon = FontAwesome.Regular.TrashAlt;

            Buttons = new PopupDialogButton[]
            {
                new PopupDialogOkButton
                {
                    Text   = @"是的, 去吧!",
                    Action = deleteAction
                },
                new PopupDialogCancelButton
                {
                    Text = @"不要! 取消任務!",
                },
            };
        }
Ejemplo n.º 6
0
        private void importCollections(List <BeatmapCollection> newCollections)
        {
            foreach (var newCol in newCollections)
            {
                var existing = Collections.FirstOrDefault(c => c.Name == newCol.Name);
                if (existing == null)
                {
                    Collections.Add(existing = new BeatmapCollection {
                        Name = { Value = newCol.Name.Value }
                    });
                }

                foreach (var newBeatmap in newCol.Beatmaps)
                {
                    if (!existing.Beatmaps.Contains(newBeatmap))
                    {
                        existing.Beatmaps.Add(newBeatmap);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private Task importCollections(List <BeatmapCollection> newCollections)
        {
            var tcs = new TaskCompletionSource <bool>();

            Schedule(() =>
            {
                try
                {
                    foreach (var newCol in newCollections)
                    {
                        var existing = Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value);
                        if (existing == null)
                        {
                            Collections.Add(existing = new BeatmapCollection {
                                Name = { Value = newCol.Name.Value }
                            });
                        }

                        foreach (string newBeatmap in newCol.BeatmapHashes)
                        {
                            if (!existing.BeatmapHashes.Contains(newBeatmap))
                            {
                                existing.BeatmapHashes.Add(newBeatmap);
                            }
                        }
                    }

                    tcs.SetResult(true);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Failed to import collection.");
                    tcs.SetException(e);
                }
            });

            return(tcs.Task);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new <see cref="CollectionFilterMenuItem"/>.
 /// </summary>
 /// <param name="collection">The collection to filter beatmaps from.</param>
 public CollectionFilterMenuItem([CanBeNull] BeatmapCollection collection)
 {
     Collection     = collection;
     CollectionName = Collection?.Name.GetBoundCopy() ?? new Bindable <string>("所有圖譜");
 }