From 99b00143ebf59b5a0846a6c923f0100f62293739 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 13 Dec 2017 12:46:02 +0900 Subject: [PATCH] More clean-ups and event bindings --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/Configuration/SelectionRandomType.cs | 4 +- .../Sections/Gameplay/SongSelectSettings.cs | 4 +- osu.Game/Screens/Select/BeatmapCarousel.cs | 63 ++++----- .../Select/Carousel/CarouselBeatmap.cs | 10 +- .../Carousel/DrawableCarouselBeatmap.cs | 3 +- .../Carousel/DrawableCarouselBeatmapSet.cs | 60 ++++----- osu.Game/Screens/Select/SongSelect.cs | 120 +++++++++--------- osu.Game/osu.Game.csproj | 2 +- 9 files changed, 116 insertions(+), 152 deletions(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 1a7d29e907..1f7808dceb 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -20,7 +20,7 @@ namespace osu.Game.Configuration Set(OsuSetting.DisplayStarsMinimum, 0.0, 0, 10, 0.1); Set(OsuSetting.DisplayStarsMaximum, 10.0, 0, 10, 0.1); - Set(OsuSetting.SelectionRandomType, SelectionRandomType.RandomPermutation); + Set(OsuSetting.SelectionRandomType, SongSelectRandomMode.RandomPermutation); Set(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2, 1); diff --git a/osu.Game/Configuration/SelectionRandomType.cs b/osu.Game/Configuration/SelectionRandomType.cs index 298ee71e36..4ff52fab37 100644 --- a/osu.Game/Configuration/SelectionRandomType.cs +++ b/osu.Game/Configuration/SelectionRandomType.cs @@ -5,11 +5,11 @@ using System.ComponentModel; namespace osu.Game.Configuration { - public enum SelectionRandomType + public enum SongSelectRandomMode { [Description("Never repeat")] RandomPermutation, [Description("Random")] Random } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/Settings/Sections/Gameplay/SongSelectSettings.cs b/osu.Game/Overlays/Settings/Sections/Gameplay/SongSelectSettings.cs index 9875ee8004..890c28aa07 100644 --- a/osu.Game/Overlays/Settings/Sections/Gameplay/SongSelectSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Gameplay/SongSelectSettings.cs @@ -34,10 +34,10 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay Bindable = config.GetBindable(OsuSetting.DisplayStarsMaximum), KeyboardStep = 1f }, - new SettingsEnumDropdown + new SettingsEnumDropdown { LabelText = "Random beatmap selection", - Bindable = config.GetBindable(OsuSetting.SelectionRandomType), + Bindable = config.GetBindable(OsuSetting.SelectionRandomType), } }; } diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index cede452402..c332f26c09 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -52,7 +52,7 @@ namespace osu.Game.Screens.Select Schedule(() => { foreach (var g in newSets) - addGroup(g); + addBeatmapSet(g); root = new CarouselGroup(newSets.OfType().ToList()); items = root.Drawables.Value.ToList(); @@ -65,12 +65,13 @@ namespace osu.Game.Screens.Select } private readonly List yPositions = new List(); + private Cached yPositionsCache = new Cached(); private readonly Container scrollableContent; private readonly List carouselSets = new List(); - private Bindable randomType; + private Bindable randomType; private readonly List seenSets = new List(); private List items = new List(); @@ -95,7 +96,7 @@ namespace osu.Game.Screens.Select public void RemoveBeatmap(BeatmapSetInfo beatmapSet) { - Schedule(() => removeGroup(carouselSets.Find(b => b.BeatmapSet.ID == beatmapSet.ID))); + Schedule(() => removeBeatmapSet(carouselSets.Find(b => b.BeatmapSet.ID == beatmapSet.ID))); } public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet) @@ -116,7 +117,7 @@ namespace osu.Game.Screens.Select if (index >= 0) carouselSets.Insert(index, newSet); else - addGroup(newSet); + addBeatmapSet(newSet); } if (hadSelection && newSet == null) @@ -151,7 +152,7 @@ namespace osu.Game.Screens.Select var item = group.Beatmaps.FirstOrDefault(p => p.Beatmap.Equals(beatmap)); if (item != null) { - select(item, animated); + select(item); return; } } @@ -220,7 +221,7 @@ namespace osu.Game.Screens.Select CarouselBeatmapSet group; - if (randomType == SelectionRandomType.RandomPermutation) + if (randomType == SongSelectRandomMode.RandomPermutation) { var notSeenGroups = visibleGroups.Except(seenSets); if (!notSeenGroups.Any()) @@ -337,10 +338,10 @@ namespace osu.Game.Screens.Select [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuConfigManager config) { - randomType = config.GetBindable(OsuSetting.SelectionRandomType); + randomType = config.GetBindable(OsuSetting.SelectionRandomType); } - private void addGroup(CarouselBeatmapSet set) + private void addBeatmapSet(CarouselBeatmapSet set) { // prevent duplicates by concurrent independent actions trying to add a group //todo: check this @@ -351,19 +352,11 @@ namespace osu.Game.Screens.Select carouselSets.Add(set); } - private void removeGroup(CarouselBeatmapSet set) + private void removeBeatmapSet(CarouselBeatmapSet set) { if (set == null) return; - if (set.State == CarouselItemState.Selected) - { - if (getVisibleGroups().Count() == 1) - selectNullBeatmap(); - else - SelectNext(); - } - carouselSets.Remove(set); foreach (var d in set.Drawables.Value) @@ -372,11 +365,12 @@ namespace osu.Game.Screens.Select scrollableContent.Remove(d); } + if (set.State == CarouselItemState.Selected) + SelectNext(); + yPositionsCache.Invalidate(); } - private Cached yPositionsCache = new Cached(); - /// /// Computes the target Y positions for every item in the carousel. /// @@ -396,10 +390,7 @@ namespace osu.Game.Screens.Select { case DrawableCarouselBeatmapSet set: set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo); - lastSetY = set.Position.Y; - - movePanel(set, set.Item.Visible, animated, ref currentY); break; case DrawableCarouselBeatmap beatmap: beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo); @@ -410,10 +401,14 @@ namespace osu.Game.Screens.Select // on first display we want to begin hidden under our group's header. if (animated && !beatmap.IsPresent) beatmap.MoveToY(lastSetY); - - movePanel(beatmap, beatmap.Item.Visible, animated, ref currentY); break; } + + yPositions.Add(currentY); + d.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo); + + if (d.Item.Visible) + currentY += d.DrawHeight + 5; } currentY += DrawHeight / 2; @@ -424,25 +419,11 @@ namespace osu.Game.Screens.Select return selectedY; } - private void movePanel(DrawableCarouselItem item, bool advance, bool animated, ref float currentY) + private void select(CarouselItem item) { - yPositions.Add(currentY); - item.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo); + if (item == null) return; - if (advance) - currentY += item.DrawHeight + 5; - } - - private void select(CarouselBeatmapSet beatmapSet = null) - { - if (beatmapSet == null) return; - beatmapSet.State.Value = CarouselItemState.Selected; - } - - private void select(CarouselBeatmap beatmap = null, bool animated = true) - { - if (beatmap == null) return; - beatmap.State.Value = CarouselItemState.Selected; + item.State.Value = CarouselItemState.Selected; } protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) diff --git a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs index f1bc24db50..655579269f 100644 --- a/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/CarouselBeatmap.cs @@ -17,19 +17,13 @@ namespace osu.Game.Screens.Select.Carousel State.Value = CarouselItemState.Hidden; } - protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this) - { - /*GainedSelection = panelGainedSelection, - HideRequested = p => HideDifficultyRequested?.Invoke(p), - StartRequested = p => StartRequested?.Invoke(p.beatmap), - EditRequested = p => EditRequested?.Invoke(p.beatmap),*/ - }; + protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this); public override void Filter(FilterCriteria criteria) { base.Filter(criteria); - bool match = criteria.Ruleset == null || (Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps); + bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps; if (!string.IsNullOrEmpty(criteria.SearchText)) match &= diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs index 5170e0b98b..61a916d0a3 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmap.cs @@ -36,10 +36,11 @@ namespace osu.Game.Screens.Select.Carousel private readonly StarCounter starCounter; [BackgroundDependencyLoader] - private void load(SongSelect songSelect) + private void load(SongSelect songSelect, BeatmapManager manager) { StartRequested = songSelect.Start; EditRequested = songSelect.Edit; + HideRequested = manager.Hide; } public DrawableCarouselBeatmap(CarouselBeatmap panel) diff --git a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs index f4e43d14aa..9a1ee663a1 100644 --- a/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs +++ b/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs @@ -24,10 +24,7 @@ namespace osu.Game.Screens.Select.Carousel { public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu { - public Action GainedSelection; - public Action DeleteRequested; - public Action RestoreHiddenRequested; private readonly BeatmapSetInfo beatmapSet; @@ -40,18 +37,15 @@ namespace osu.Game.Screens.Select.Carousel beatmapSet = set.BeatmapSet; } - protected override void Selected() - { - base.Selected(); - GainedSelection?.Invoke(this); - } - [BackgroundDependencyLoader] private void load(LocalisationEngine localisation, BeatmapManager manager) { if (localisation == null) throw new ArgumentNullException(nameof(localisation)); + RestoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore); + DeleteRequested = manager.Delete; + var working = manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()); Children = new Drawable[] @@ -61,7 +55,8 @@ namespace osu.Game.Screens.Select.Carousel { RelativeSizeAxes = Axes.Both, OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out), - }, 300), + }, 300 + ), new FillFlowContainer { Direction = FillDirection.Vertical, @@ -94,6 +89,24 @@ namespace osu.Game.Screens.Select.Carousel }; } + public MenuItem[] ContextMenuItems + { + get + { + List items = new List(); + + if (Item.State == CarouselItemState.NotSelected) + items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected)); + + if (beatmapSet.Beatmaps.Any(b => b.Hidden)) + items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => RestoreHiddenRequested?.Invoke(beatmapSet))); + + items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmapSet))); + + return items.ToArray(); + } + } + private class PanelBackground : BufferedContainer { public PanelBackground(WorkingBeatmap working) @@ -130,22 +143,19 @@ namespace osu.Game.Screens.Select.Carousel new Box { RelativeSizeAxes = Axes.Both, - Colour = ColourInfo.GradientHorizontal( - Color4.Black, new Color4(0f, 0f, 0f, 0.9f)), + Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)), Width = 0.05f, }, new Box { RelativeSizeAxes = Axes.Both, - Colour = ColourInfo.GradientHorizontal( - new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)), + Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)), Width = 0.2f, }, new Box { RelativeSizeAxes = Axes.Both, - Colour = ColourInfo.GradientHorizontal( - new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)), + Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)), Width = 0.05f, }, } @@ -154,24 +164,6 @@ namespace osu.Game.Screens.Select.Carousel } } - public MenuItem[] ContextMenuItems - { - get - { - List items = new List(); - - if (Item.State == CarouselItemState.NotSelected) - items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected)); - - if (beatmapSet.Beatmaps.Any(b => b.Hidden)) - items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => RestoreHiddenRequested?.Invoke(beatmapSet))); - - items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmapSet))); - - return items.ToArray(); - } - } - public class FilterableDifficultyIcon : DifficultyIcon { private readonly BindableBool filtered = new BindableBool(); diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index b2e2c8bac6..759a9efa1c 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -76,68 +76,68 @@ namespace osu.Game.Screens.Select const float carousel_width = 640; const float filter_height = 100; - Add(new ParallaxContainer + AddRange(new Drawable[] { - Padding = new MarginPadding { Top = filter_height }, - ParallaxAmount = 0.005f, - RelativeSizeAxes = Axes.Both, - Children = new[] + new ParallaxContainer { - new WedgeBackground + Padding = new MarginPadding { Top = filter_height }, + ParallaxAmount = 0.005f, + RelativeSizeAxes = Axes.Both, + Children = new[] { - RelativeSizeAxes = Axes.Both, - Padding = new MarginPadding { Right = carousel_width * 0.76f }, + new WedgeBackground + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Right = carousel_width * 0.76f }, + } } - } - }); - Add(LeftContent = new Container - { - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - RelativeSizeAxes = Axes.Both, - Size = new Vector2(wedged_container_size.X, 1), - Padding = new MarginPadding - { - Bottom = 50, - Top = wedged_container_size.Y + left_area_padding, - Left = left_area_padding, - Right = left_area_padding * 2, - } - }); - Add(carousel = new BeatmapCarousel - { - RelativeSizeAxes = Axes.Y, - Size = new Vector2(carousel_width, 1), - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - - //todo: clicking play on another map doesn't work bindable disabled - SelectionChanged = carouselSelectionChanged, - BeatmapsChanged = carouselBeatmapsLoaded, - //RestoreRequested = s => { foreach (var b in s.Beatmaps) beatmaps.Restore(b); }, - }); - Add(FilterControl = new FilterControl - { - RelativeSizeAxes = Axes.X, - Height = filter_height, - FilterChanged = criteria => filterChanged(criteria), - Exit = Exit, - }); - Add(beatmapInfoWedge = new BeatmapInfoWedge - { - Alpha = 0, - Size = wedged_container_size, - RelativeSizeAxes = Axes.X, - Margin = new MarginPadding - { - Top = left_area_padding, - Right = left_area_padding, }, - }); - Add(new ResetScrollContainer(() => carousel.ScrollToSelected()) - { - RelativeSizeAxes = Axes.Y, - Width = 250, + LeftContent = new Container + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + RelativeSizeAxes = Axes.Both, + Size = new Vector2(wedged_container_size.X, 1), + Padding = new MarginPadding + { + Bottom = 50, + Top = wedged_container_size.Y + left_area_padding, + Left = left_area_padding, + Right = left_area_padding * 2, + } + }, + carousel = new BeatmapCarousel + { + RelativeSizeAxes = Axes.Y, + Size = new Vector2(carousel_width, 1), + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + SelectionChanged = carouselSelectionChanged, + BeatmapsChanged = carouselBeatmapsLoaded, + }, + FilterControl = new FilterControl + { + RelativeSizeAxes = Axes.X, + Height = filter_height, + FilterChanged = c => carousel.Filter(c), + Exit = Exit, + }, + beatmapInfoWedge = new BeatmapInfoWedge + { + Alpha = 0, + Size = wedged_container_size, + RelativeSizeAxes = Axes.X, + Margin = new MarginPadding + { + Top = left_area_padding, + Right = left_area_padding, + }, + }, + new ResetScrollContainer(() => carousel.ScrollToSelected()) + { + RelativeSizeAxes = Axes.Y, + Width = 250, + } }); if (ShowFooter) @@ -309,11 +309,6 @@ namespace osu.Game.Screens.Select protected abstract void Start(); - private void filterChanged(FilterCriteria criteria, bool debounce = true) - { - carousel.Filter(criteria, debounce); - } - private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => carousel.UpdateBeatmapSet(s)); private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s)); @@ -489,6 +484,7 @@ namespace osu.Game.Screens.Select Delete(Beatmap.Value.BeatmapSetInfo); return true; } + break; } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 0bc7fa3f67..54c41ead80 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -343,7 +343,7 @@ - +