1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 20:13:21 +08:00
osu-lazer/osu.Game/Screens/Select/SongSelect.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1023 lines
39 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2023-02-02 13:41:55 +08:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
2016-11-14 16:23:33 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2023-02-02 13:41:55 +08:00
using osu.Framework.Audio.Track;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2023-02-02 13:41:55 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-02-02 13:41:55 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2019-01-05 03:13:32 +08:00
using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Framework.Threading;
2016-11-14 16:23:33 +08:00
using osu.Game.Beatmaps;
2023-02-02 13:41:55 +08:00
using osu.Game.Collections;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
2023-02-02 13:41:55 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
2018-12-06 18:29:18 +08:00
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Backgrounds;
2017-10-06 23:59:14 +08:00
using osu.Game.Screens.Edit;
using osu.Game.Screens.Menu;
2023-02-02 13:41:55 +08:00
using osu.Game.Screens.Play;
using osu.Game.Screens.Select.Options;
2023-02-02 13:41:55 +08:00
using osu.Game.Skinning;
2019-01-05 03:13:32 +08:00
using osuTK;
using osuTK.Graphics;
2019-01-05 03:13:32 +08:00
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
2016-09-29 19:13:58 +08:00
{
public abstract partial class SongSelect : ScreenWithBeatmapBackground, IKeyBindingHandler<GlobalAction>
2016-09-29 19:13:58 +08:00
{
public static readonly float WEDGE_HEIGHT = 245;
2019-05-12 14:40:58 +08:00
protected const float BACKGROUND_BLUR = 20;
2017-12-15 11:48:15 +08:00
private const float left_area_padding = 20;
2018-04-13 17:19:50 +08:00
2023-01-13 07:52:14 +08:00
public FilterControl FilterControl { get; private set; } = null!;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether this song select instance should take control of the global track,
/// applying looping and preview offsets.
/// </summary>
protected virtual bool ControlGlobalMusic => true;
2017-03-15 10:10:59 +08:00
protected virtual bool ShowFooter => true;
2018-04-13 17:19:50 +08:00
public override bool? AllowTrackAdjustments => true;
2017-03-14 21:51:26 +08:00
/// <summary>
2017-03-16 13:08:37 +08:00
/// Can be null if <see cref="ShowFooter"/> is false.
2017-03-14 21:51:26 +08:00
/// </summary>
2023-01-13 07:52:14 +08:00
protected BeatmapOptionsOverlay BeatmapOptions { get; private set; } = null!;
2018-04-13 17:19:50 +08:00
2017-03-14 21:51:26 +08:00
/// <summary>
2017-03-16 13:08:37 +08:00
/// Can be null if <see cref="ShowFooter"/> is false.
2017-03-14 21:51:26 +08:00
/// </summary>
2023-01-13 07:52:14 +08:00
protected Footer? Footer { get; private set; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Contains any panel which is triggered by a footer button.
/// Helps keep them located beneath the footer itself.
/// </summary>
2023-01-13 07:52:14 +08:00
protected Container FooterPanels { get; private set; } = null!;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether entering editor mode should be allowed.
/// </summary>
public virtual bool AllowEditing => true;
public bool BeatmapSetsLoaded => IsLoaded && Carousel.BeatmapSetsLoaded;
2021-11-25 20:11:13 +08:00
/// <summary>
/// Creates any "action" menu items for the provided beatmap (ie. "Select", "Play", "Edit").
/// These will always be placed at the top of the context menu, with common items added below them.
/// </summary>
/// <param name="beatmap">The beatmap to create items for.</param>
/// <returns>The menu items.</returns>
public virtual MenuItem[] CreateForwardNavigationMenuItemsForBeatmap(BeatmapInfo beatmap) => new MenuItem[]
{
new OsuMenuItem(@"Select", MenuItemType.Highlighted, () => FinaliseSelection(beatmap))
};
[Resolved]
2023-01-13 07:52:14 +08:00
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
protected BeatmapCarousel Carousel { get; private set; } = null!;
2023-01-13 07:52:14 +08:00
private ParallaxContainer wedgeBackground = null!;
2023-01-13 07:52:14 +08:00
protected Container LeftArea { get; private set; } = null!;
2021-08-12 17:02:00 +08:00
2023-01-13 07:52:14 +08:00
private BeatmapInfoWedge beatmapInfoWedge = null!;
2023-01-13 07:52:14 +08:00
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
2018-04-13 17:19:50 +08:00
[Resolved]
2023-01-13 07:52:14 +08:00
private BeatmapManager beatmaps { get; set; } = null!;
2021-05-18 04:01:05 +08:00
2023-01-13 07:52:14 +08:00
protected ModSelectOverlay ModSelect { get; private set; } = null!;
2023-01-13 07:52:14 +08:00
protected Sample? SampleConfirm { get; private set; }
2018-12-06 18:29:18 +08:00
2023-01-13 07:52:14 +08:00
private Sample sampleChangeDifficulty = null!;
private Sample sampleChangeBeatmap = null!;
2018-04-13 17:19:50 +08:00
2023-01-13 07:52:14 +08:00
private Container carouselContainer = null!;
2023-01-13 07:52:14 +08:00
protected BeatmapDetailArea BeatmapDetails { get; private set; } = null!;
2023-01-13 07:52:14 +08:00
private FooterButtonOptions beatmapOptionsButton = null!;
2019-02-01 14:42:15 +08:00
private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>();
2021-11-11 18:20:50 +08:00
private double audioFeedbackLastPlaybackTime;
2023-01-13 07:52:14 +08:00
private IDisposable? modSelectOverlayRegistration;
2020-08-11 11:40:58 +08:00
[Resolved]
private MusicController music { get; set; } = null!;
2020-08-11 11:40:58 +08:00
[Resolved]
2023-01-13 07:52:14 +08:00
internal IOverlayManager? OverlayManager { get; private set; }
2023-01-24 16:55:08 +08:00
private Bindable<bool> configBackgroundBlur { get; set; } = new BindableBool();
[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, OsuColour colours, ManageCollectionsDialog? manageCollectionsDialog, DifficultyRecommender? recommender, OsuConfigManager config)
{
2023-01-25 15:28:38 +08:00
configBackgroundBlur = config.GetBindable<bool>(OsuSetting.SongSelectBackgroundBlur);
2023-01-24 16:55:08 +08:00
configBackgroundBlur.BindValueChanged(e =>
{
if (!this.IsCurrentScreen())
return;
ApplyToBackground(applyBlurToBackground);
});
LoadComponentAsync(Carousel = new BeatmapCarousel
{
AllowSelection = false, // delay any selection until our bindables are ready to make a good choice.
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
BleedTop = FilterControl.HEIGHT,
BleedBottom = Footer.HEIGHT,
SelectionChanged = updateSelectedBeatmap,
BeatmapSetsChanged = carouselBeatmapsLoaded,
FilterApplied = updateVisibleBeatmapCount,
GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s),
}, c => carouselContainer.Child = c);
// initial value transfer is required for FilterControl (it uses our re-cached bindables in its async load for the initial filter).
transferRulesetValue();
AddRangeInternal(new Drawable[]
{
new ResetScrollContainer(() => Carousel.ScrollToSelected())
2016-10-14 04:55:15 +08:00
{
RelativeSizeAxes = Axes.Y,
Width = 250,
},
new VerticalMaskingContainer
{
Children = new Drawable[]
2016-10-20 02:02:03 +08:00
{
2020-01-24 14:00:10 +08:00
new GridContainer // used for max width implementation
2017-12-13 11:46:02 +08:00
{
RelativeSizeAxes = Axes.Both,
2020-01-24 14:00:10 +08:00
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Relative, 0.5f, maxSize: 850),
},
Content = new[]
{
new Drawable[]
{
wedgeBackground = new ParallaxContainer
2020-01-24 14:00:10 +08:00
{
ParallaxAmount = 0.005f,
2020-01-24 14:00:10 +08:00
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = new WedgeBackground
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = -150 },
},
},
carouselContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Top = FilterControl.HEIGHT,
Bottom = Footer.HEIGHT
},
Child = new LoadingSpinner(true) { State = { Value = Visibility.Visible } }
}
},
}
},
FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = FilterControl.HEIGHT,
FilterChanged = ApplyFilterToCarousel,
},
new GridContainer // used for max width implementation
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Relative, 0.5f, maxSize: 650),
},
Content = new[]
{
new Drawable[]
{
2021-08-12 17:02:00 +08:00
LeftArea = new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
2021-08-12 17:02:00 +08:00
Padding = new MarginPadding { Top = left_area_padding },
Children = new Drawable[]
{
beatmapInfoWedge = new BeatmapInfoWedge
{
Height = WEDGE_HEIGHT,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Right = left_area_padding,
2021-08-13 21:29:22 +08:00
Left = -BeatmapInfoWedge.BORDER_THICKNESS, // Hide the left border
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Bottom = Footer.HEIGHT,
2021-08-12 17:02:00 +08:00
Top = WEDGE_HEIGHT,
Left = left_area_padding,
Right = left_area_padding * 2,
},
2020-02-12 18:52:47 +08:00
Child = BeatmapDetails = CreateBeatmapDetailArea().With(d =>
{
2020-02-12 18:52:47 +08:00
d.RelativeSizeAxes = Axes.Both;
d.Padding = new MarginPadding { Top = 10, Right = 5 };
})
},
}
},
},
}
}
}
},
new SkinComponentsContainer(new SkinComponentsContainerLookup(SkinComponentsContainerLookup.TargetArea.SongSelect))
{
RelativeSizeAxes = Axes.Both,
},
2017-07-29 22:33:20 +08:00
});
2018-04-13 17:19:50 +08:00
2017-03-15 10:10:59 +08:00
if (ShowFooter)
2017-03-14 21:51:26 +08:00
{
AddRangeInternal(new Drawable[]
2017-02-17 04:05:03 +08:00
{
FooterPanels = new Container
2018-12-06 18:29:18 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = Footer.HEIGHT },
Children = new Drawable[]
2019-06-25 15:55:49 +08:00
{
BeatmapOptions = new BeatmapOptionsOverlay(),
2019-06-25 15:55:49 +08:00
}
},
2023-01-13 07:52:14 +08:00
Footer = new Footer()
2018-12-06 18:29:18 +08:00
});
2017-03-14 21:51:26 +08:00
}
2018-04-13 17:19:50 +08:00
// preload the mod select overlay for later use in `LoadComplete()`.
// therein it will be registered at the `OsuGame` level to properly function as a blocking overlay.
LoadComponent(ModSelect = CreateModSelectOverlay());
2017-03-14 21:51:26 +08:00
if (Footer != null)
{
2021-01-27 21:03:51 +08:00
foreach (var (button, overlay) in CreateFooterButtons())
Footer.AddButton(button, overlay);
2018-04-13 17:19:50 +08:00
BeatmapOptions.AddButton(@"Manage", @"collections", FontAwesome.Solid.Book, colours.Green, () => manageCollectionsDialog?.Show());
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo));
2022-11-17 09:05:15 +08:00
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null);
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo));
2017-03-14 21:51:26 +08:00
}
2018-04-13 17:19:50 +08:00
sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty");
sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand");
SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection");
}
protected override void LoadComplete()
{
base.LoadComplete();
modSelectOverlayRegistration = OverlayManager?.RegisterBlockingOverlay(ModSelect);
}
protected override bool OnScroll(ScrollEvent e)
{
// Match stable behaviour of only alt-scroll adjusting volume.
// Supporting scroll adjust without a modifier key just feels bad, since there are so many scrollable elements on the screen.
if (!e.CurrentState.Keyboard.AltPressed)
return true;
return base.OnScroll(e);
}
2021-02-01 17:50:32 +08:00
/// <summary>
/// Creates the buttons to be displayed in the footer.
/// </summary>
/// <returns>A set of <see cref="FooterButton"/> and an optional <see cref="OverlayContainer"/> which the button opens when pressed.</returns>
2023-01-15 21:35:44 +08:00
protected virtual IEnumerable<(FooterButton, OverlayContainer?)> CreateFooterButtons() => new (FooterButton, OverlayContainer?)[]
2021-01-27 21:03:51 +08:00
{
(new FooterButtonMods { Current = Mods }, ModSelect),
(new FooterButtonRandom
{
NextRandom = () => Carousel.SelectNextRandom(),
PreviousRandom = Carousel.SelectPreviousRandom
}, null),
(beatmapOptionsButton = new FooterButtonOptions(), BeatmapOptions)
2021-01-27 21:03:51 +08:00
};
protected virtual ModSelectOverlay CreateModSelectOverlay() => new SoloModSelectOverlay();
2019-11-20 16:24:43 +08:00
protected virtual void ApplyFilterToCarousel(FilterCriteria criteria)
{
// if not the current screen, we want to get carousel in a good presentation state before displaying (resume or enter).
bool shouldDebounce = this.IsCurrentScreen();
Carousel.Filter(criteria, shouldDebounce);
2019-11-20 16:24:43 +08:00
}
2019-11-20 14:43:00 +08:00
2023-01-13 07:52:14 +08:00
private DependencyContainer dependencies = null!;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(this);
2019-02-01 14:42:15 +08:00
dependencies.CacheAs(decoupledRuleset);
dependencies.CacheAs<IBindable<RulesetInfo>>(decoupledRuleset);
return dependencies;
}
2020-02-12 18:52:47 +08:00
/// <summary>
/// Creates the beatmap details to be displayed underneath the wedge.
/// </summary>
protected abstract BeatmapDetailArea CreateBeatmapDetailArea();
2023-01-13 07:52:14 +08:00
public void Edit(BeatmapInfo? beatmapInfo = null)
2017-10-06 23:59:14 +08:00
{
if (!AllowEditing)
throw new InvalidOperationException($"Attempted to edit when {nameof(AllowEditing)} is disabled");
2021-10-02 23:55:29 +08:00
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo ?? beatmapInfoNoDebounce);
this.Push(new EditorLoader());
2017-10-06 23:59:14 +08:00
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Call to make a selection and perform the default action for this SongSelect.
/// </summary>
2021-10-02 23:55:29 +08:00
/// <param name="beatmapInfo">An optional beatmap to override the current carousel selection.</param>
/// <param name="ruleset">An optional ruleset to override the current carousel selection.</param>
/// <param name="customStartAction">An optional custom action to perform instead of <see cref="OnStart"/>.</param>
2023-01-13 07:52:14 +08:00
public void FinaliseSelection(BeatmapInfo? beatmapInfo = null, RulesetInfo? ruleset = null, Action? customStartAction = null)
2017-03-14 21:51:26 +08:00
{
// This is very important as we have not yet bound to screen-level bindables before the carousel load is completed.
if (!Carousel.BeatmapSetsLoaded)
{
Logger.Log($"{nameof(FinaliseSelection)} aborted as carousel beatmaps are not yet loaded");
return;
}
if (ruleset != null)
Ruleset.Value = ruleset;
transferRulesetValue();
// while transferRulesetValue will flush, it only does so if the ruleset changes.
// the user could have changed a filter, and we want to ensure we are 100% up-to-date and consistent here.
Carousel.FlushPendingFilterOperations();
2018-04-13 17:19:50 +08:00
// avoid attempting to continue before a selection has been obtained.
// this could happen via a user interaction while the carousel is still in a loading state.
if (Carousel.SelectedBeatmapInfo == null) return;
2021-10-02 23:55:29 +08:00
if (beatmapInfo != null)
Carousel.SelectBeatmap(beatmapInfo);
2018-04-13 17:19:50 +08:00
if (selectionChangedDebounce?.Completed == false)
{
selectionChangedDebounce.RunTask();
selectionChangedDebounce?.Cancel(); // cancel the already scheduled task.
selectionChangedDebounce = null;
}
2018-04-13 17:19:50 +08:00
if (customStartAction != null)
{
customStartAction();
Carousel.AllowSelection = false;
}
else if (OnStart())
Carousel.AllowSelection = false;
2017-03-14 21:51:26 +08:00
}
2018-04-13 17:19:50 +08:00
2017-12-15 11:48:15 +08:00
/// <summary>
/// Called when a selection is made.
/// </summary>
/// <returns>If a resultant action occurred that takes the user away from SongSelect.</returns>
protected abstract bool OnStart();
2018-04-13 17:19:50 +08:00
2023-01-13 07:52:14 +08:00
private ScheduledDelegate? selectionChangedDebounce;
2018-04-13 17:19:50 +08:00
2023-01-13 07:52:14 +08:00
private void updateCarouselSelection(ValueChangedEvent<WorkingBeatmap>? e = null)
2018-03-03 22:24:54 +08:00
{
var beatmap = e?.NewValue ?? Beatmap.Value;
2022-11-17 16:15:34 +08:00
if (beatmap is DummyWorkingBeatmap || !this.IsCurrentScreen()) return;
Logger.Log($"Song select working beatmap updated to {beatmap}");
if (!Carousel.SelectBeatmap(beatmap.BeatmapInfo, false))
2019-11-11 19:53:22 +08:00
{
// A selection may not have been possible with filters applied.
// There was possibly a ruleset mismatch. This is a case we can help things along by updating the game-wide ruleset to match.
if (!beatmap.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value))
{
Ruleset.Value = beatmap.BeatmapInfo.Ruleset;
transferRulesetValue();
}
// Even if a ruleset mismatch was not the cause (ie. a text filter is applied),
// we still want to temporarily show the new beatmap, bypassing filters.
// This will be undone the next time the user changes the filter.
var criteria = FilterControl.CreateCriteria();
criteria.SelectedBeatmapSet = beatmap.BeatmapInfo.BeatmapSet;
Carousel.Filter(criteria);
Carousel.SelectBeatmap(beatmap.BeatmapInfo);
2019-11-11 19:53:22 +08:00
}
2018-03-03 22:24:54 +08:00
}
2018-04-13 17:19:50 +08:00
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
2023-01-13 07:52:14 +08:00
private BeatmapInfo? beatmapInfoPrevious;
private BeatmapInfo? beatmapInfoNoDebounce;
private RulesetInfo? rulesetNoDebounce;
2023-01-13 07:52:14 +08:00
private void updateSelectedBeatmap(BeatmapInfo? beatmapInfo)
{
2021-10-02 23:55:29 +08:00
if (beatmapInfo == null && beatmapInfoNoDebounce == null)
return;
2021-10-02 23:55:29 +08:00
if (beatmapInfo?.Equals(beatmapInfoNoDebounce) == true)
return;
2021-10-02 23:55:29 +08:00
beatmapInfoNoDebounce = beatmapInfo;
performUpdateSelected();
}
2023-01-13 07:52:14 +08:00
private void updateSelectedRuleset(RulesetInfo? ruleset)
{
if (ruleset == null && rulesetNoDebounce == null)
return;
if (ruleset?.Equals(rulesetNoDebounce) == true)
return;
rulesetNoDebounce = ruleset;
performUpdateSelected();
}
2017-07-19 12:32:16 +08:00
/// <summary>
/// Selection has been changed as the result of a user interaction.
2017-07-19 12:32:16 +08:00
/// </summary>
private void performUpdateSelected()
2017-07-19 12:32:16 +08:00
{
2021-10-02 23:55:29 +08:00
var beatmap = beatmapInfoNoDebounce;
2023-01-13 07:52:14 +08:00
RulesetInfo? ruleset = rulesetNoDebounce;
2019-03-21 19:51:21 +08:00
selectionChangedDebounce?.Cancel();
2021-10-02 23:55:29 +08:00
if (beatmapInfoNoDebounce == null)
2019-03-21 19:51:21 +08:00
run();
else
selectionChangedDebounce = Scheduler.AddDelayed(run, 200);
if (beatmap?.Equals(beatmapInfoPrevious) != true)
{
2021-11-11 18:20:50 +08:00
if (beatmap != null && beatmapInfoPrevious != null && Time.Current - audioFeedbackLastPlaybackTime >= 50)
{
if (beatmap.BeatmapSet?.ID == beatmapInfoPrevious.BeatmapSet?.ID)
sampleChangeDifficulty.Play();
else
sampleChangeBeatmap.Play();
2021-11-11 18:20:50 +08:00
audioFeedbackLastPlaybackTime = Time.Current;
}
beatmapInfoPrevious = beatmap;
}
void run()
2017-07-19 12:32:16 +08:00
{
// clear pending task immediately to track any potential nested debounce operation.
selectionChangedDebounce = null;
Logger.Log($"Song select updating selection with beatmap:{beatmap?.ID.ToString() ?? "null"} ruleset:{ruleset?.ShortName ?? "null"}");
2018-07-19 17:51:08 +08:00
if (transferRulesetValue())
{
// transferRulesetValue() may trigger a re-filter. If the current selection does not match the new ruleset, we want to switch away from it.
// The default logic on WorkingBeatmap change is to switch to a matching ruleset (see workingBeatmapChanged()), but we don't want that here.
// We perform an early selection attempt and clear out the beatmap selection to avoid a second ruleset change (revert).
if (beatmap != null && !Carousel.SelectBeatmap(beatmap, false))
beatmap = null;
}
if (selectionChangedDebounce != null)
{
// a new nested operation was started; switch to it for further selection.
// this avoids having two separate debounces trigger from the same source.
selectionChangedDebounce.RunTask();
return;
}
// We may be arriving here due to another component changing the bindable Beatmap.
// In these cases, the other component has already loaded the beatmap, so we don't need to do so again.
if (!EqualityComparer<BeatmapInfo>.Default.Equals(beatmap, Beatmap.Value.BeatmapInfo))
{
Logger.Log($"Song select changing beatmap from \"{Beatmap.Value.BeatmapInfo}\" to \"{beatmap?.ToString() ?? "null"}\"");
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap);
}
2018-04-13 17:19:50 +08:00
if (this.IsCurrentScreen())
ensurePlayingSelected();
updateComponentFromBeatmap(Beatmap.Value);
2018-01-16 02:42:17 +08:00
}
2017-07-19 12:32:16 +08:00
}
2018-04-13 17:19:50 +08:00
public override void OnEntering(ScreenTransitionEvent e)
2016-10-28 18:55:48 +08:00
{
base.OnEntering(e);
2018-04-13 17:19:50 +08:00
2019-01-23 19:52:00 +08:00
this.FadeInFromZero(250);
FilterControl.Activate();
ModSelect.SelectedMods.BindTo(selectedMods);
beginLooping();
2016-10-28 18:55:48 +08:00
}
2018-04-13 17:19:50 +08:00
private const double logo_transition = 250;
2018-04-13 17:19:50 +08:00
2017-11-09 16:38:20 +08:00
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
2017-11-09 16:38:20 +08:00
base.LogoArriving(logo, resuming);
2018-04-13 17:19:50 +08:00
Vector2 position = new Vector2(0.95f, 0.96f);
2018-04-13 17:19:50 +08:00
if (logo.Alpha > 0.8f)
{
logo.MoveTo(position, 500, Easing.OutQuint);
}
else
{
logo.Hide();
logo.ScaleTo(0.2f);
logo.MoveTo(position);
}
2018-04-13 17:19:50 +08:00
logo.FadeIn(logo_transition, Easing.OutQuint);
logo.ScaleTo(0.4f, logo_transition, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
logo.Action = () =>
{
FinaliseSelection();
return false;
};
}
2018-04-13 17:19:50 +08:00
2017-11-09 16:38:20 +08:00
protected override void LogoExiting(OsuLogo logo)
{
2017-11-09 16:38:20 +08:00
base.LogoExiting(logo);
logo.ScaleTo(0.2f, logo_transition / 2, Easing.Out);
logo.FadeOut(logo_transition / 2, Easing.Out);
}
2018-04-13 17:19:50 +08:00
public override void OnResuming(ScreenTransitionEvent e)
2016-10-28 18:55:48 +08:00
{
base.OnResuming(e);
// required due to https://github.com/ppy/osu-framework/issues/3218
ModSelect.SelectedMods.Disabled = false;
ModSelect.SelectedMods.BindTo(selectedMods);
Carousel.AllowSelection = true;
2020-02-12 18:52:47 +08:00
BeatmapDetails.Refresh();
beginLooping();
2017-07-19 12:32:16 +08:00
if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
2017-07-19 09:59:13 +08:00
{
updateCarouselSelection();
updateComponentFromBeatmap(Beatmap.Value);
if (ControlGlobalMusic)
{
// restart playback on returning to song select, regardless.
// not sure this should be a permanent thing (we may want to leave a user pause paused even on returning)
music.ResetTrackAdjustments();
music.Play(requestedByUser: true);
}
2017-07-19 09:59:13 +08:00
}
2018-04-13 17:19:50 +08:00
LeftArea.MoveToX(0, 400, Easing.OutQuint);
LeftArea.FadeIn(100, Easing.OutQuint);
FilterControl.MoveToY(0, 400, Easing.OutQuint);
FilterControl.FadeIn(100, Easing.OutQuint);
this.FadeIn(250, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
wedgeBackground.ScaleTo(1, 500, Easing.OutQuint);
2018-04-13 17:19:50 +08:00
FilterControl.Activate();
}
2018-04-13 17:19:50 +08:00
public override void OnSuspending(ScreenTransitionEvent e)
{
// Handle the case where FinaliseSelection is never called (ie. when a screen is pushed externally).
// Without this, it's possible for a transfer to happen while we are not the current screen.
transferRulesetValue();
ModSelect.SelectedMods.UnbindFrom(selectedMods);
playExitingTransition();
base.OnSuspending(e);
}
2018-04-13 17:19:50 +08:00
public override bool OnExiting(ScreenExitEvent e)
{
if (base.OnExiting(e))
return true;
playExitingTransition();
return false;
}
private void playExitingTransition()
{
ModSelect.Hide();
2018-04-13 17:19:50 +08:00
BeatmapOptions.Hide();
2018-04-13 17:19:50 +08:00
Carousel.AllowSelection = false;
2018-04-13 17:19:50 +08:00
endLooping();
FilterControl.MoveToY(-120, 500, Easing.OutQuint);
FilterControl.FadeOut(200, Easing.OutQuint);
LeftArea.MoveToX(-150, 1800, Easing.OutQuint);
LeftArea.FadeOut(200, Easing.OutQuint);
wedgeBackground.ScaleTo(2.4f, 400, Easing.OutQuint);
this.FadeOut(400, Easing.OutQuint);
FilterControl.Deactivate();
2016-10-28 18:55:48 +08:00
}
2018-04-13 17:19:50 +08:00
private bool isHandlingLooping;
private void beginLooping()
{
if (!ControlGlobalMusic)
return;
Debug.Assert(!isHandlingLooping);
isHandlingLooping = true;
ensureTrackLooping(Beatmap.Value, TrackChangeDirection.None);
2023-01-13 07:52:14 +08:00
music.TrackChanged += ensureTrackLooping;
}
private void endLooping()
{
// may be called multiple times during screen exit process.
if (!isHandlingLooping)
return;
music.CurrentTrack.Looping = isHandlingLooping = false;
music.TrackChanged -= ensureTrackLooping;
}
private void ensureTrackLooping(IWorkingBeatmap beatmap, TrackChangeDirection changeDirection)
=> beatmap.PrepareTrackForPreview(true);
public override bool OnBackButton()
{
if (ModSelect.State.Value == Visibility.Visible)
{
ModSelect.Hide();
return true;
}
return false;
2016-10-28 18:55:48 +08:00
}
2018-04-13 17:19:50 +08:00
2016-10-08 18:12:31 +08:00
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2018-04-13 17:19:50 +08:00
2019-02-01 14:42:15 +08:00
decoupledRuleset.UnbindAll();
if (music.IsNotNull())
music.TrackChanged -= ensureTrackLooping;
modSelectOverlayRegistration?.Dispose();
2016-10-06 22:33:28 +08:00
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// Allow components in SongSelect to update their loaded beatmap details.
/// This is a debounced call (unlike directly binding to WorkingBeatmap.ValueChanged).
/// </summary>
/// <param name="beatmap">The working beatmap.</param>
private void updateComponentFromBeatmap(WorkingBeatmap beatmap)
2016-10-26 22:52:04 +08:00
{
// If not the current screen, this will be applied in OnResuming.
if (this.IsCurrentScreen())
{
ApplyToBackground(backgroundModeBeatmap =>
{
backgroundModeBeatmap.Beatmap = beatmap;
backgroundModeBeatmap.IgnoreUserSettings.Value = true;
backgroundModeBeatmap.FadeColour(Color4.White, 250);
applyBlurToBackground(backgroundModeBeatmap);
});
}
2018-04-13 17:19:50 +08:00
beatmapInfoWedge.Beatmap = beatmap;
BeatmapDetails.Beatmap = beatmap;
bool beatmapSelected = beatmap is not DummyWorkingBeatmap;
if (beatmapSelected)
beatmapOptionsButton.Enabled.Value = true;
else
{
beatmapOptionsButton.Enabled.Value = false;
BeatmapOptions.Hide();
}
}
2018-04-13 17:19:50 +08:00
private void applyBlurToBackground(BackgroundScreenBeatmap backgroundModeBeatmap)
{
backgroundModeBeatmap.BlurAmount.Value = configBackgroundBlur.Value ? BACKGROUND_BLUR : 0f;
backgroundModeBeatmap.DimWhenUserSettingsIgnored.Value = configBackgroundBlur.Value ? 0 : 0.4f;
wedgeBackground.FadeTo(configBackgroundBlur.Value ? 0.5f : 0.2f, UserDimContainer.BACKGROUND_FADE_DURATION, Easing.OutQuint);
}
2023-01-13 07:52:14 +08:00
private readonly WeakReference<ITrack?> lastTrack = new WeakReference<ITrack?>(null);
/// <summary>
/// Ensures some music is playing for the current track.
/// Will resume playback from a manual user pause if the track has changed.
/// </summary>
private void ensurePlayingSelected()
2016-10-28 18:55:48 +08:00
{
if (!ControlGlobalMusic)
return;
2020-08-11 11:40:58 +08:00
ITrack track = music.CurrentTrack;
2018-04-13 17:19:50 +08:00
bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track;
if (!track.IsRunning && (music.UserPauseRequested != true || isNewTrack))
{
Logger.Log($"Song select decided to {nameof(ensurePlayingSelected)}");
2020-08-11 11:40:58 +08:00
music.Play(true);
}
lastTrack.SetTarget(track);
2016-10-28 18:55:48 +08:00
}
2018-04-13 17:19:50 +08:00
2017-12-15 11:48:15 +08:00
private void carouselBeatmapsLoaded()
{
bindBindables();
updateVisibleBeatmapCount();
Carousel.AllowSelection = true;
2019-06-12 15:07:35 +08:00
// If a selection was already obtained, do not attempt to update the selected beatmap.
2019-05-28 13:04:33 +08:00
if (Carousel.SelectedBeatmapSet != null)
return;
// Attempt to select the current beatmap on the carousel, if it is valid to be selected.
if (!Beatmap.IsDefault && Beatmap.Value.BeatmapSetInfo?.DeletePending == false && Beatmap.Value.BeatmapSetInfo?.Protected == false)
{
if (Carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false))
return;
// prefer not changing ruleset at this point, so look for another difficulty in the currently playing beatmap
var found = Beatmap.Value.BeatmapSetInfo.Beatmaps.FirstOrDefault(b => b.Ruleset.Equals(decoupledRuleset.Value));
if (found != null && Carousel.SelectBeatmap(found, false))
return;
}
2018-04-13 17:19:50 +08:00
2019-05-28 13:04:33 +08:00
// If the current active beatmap could not be selected, select a new random beatmap.
if (!Carousel.SelectNextRandom())
{
// in the case random selection failed, we want to trigger selectionChanged
// to show the dummy beatmap (we have nothing else to display).
performUpdateSelected();
}
2017-12-15 11:48:15 +08:00
}
2018-04-13 17:19:50 +08:00
private void updateVisibleBeatmapCount()
{
FilterControl.InformationalText = Carousel.CountDisplayed == 1
// Intentionally not localised until we have proper support for this (see https://github.com/ppy/osu-framework/pull/4918
// but also in this case we want support for formatting a number within a string).
? $"{Carousel.CountDisplayed:#,0} matching beatmap"
: $"{Carousel.CountDisplayed:#,0} matching beatmaps";
}
private bool boundLocalBindables;
private void bindBindables()
{
if (boundLocalBindables)
return;
// manual binding to parent ruleset to allow for delayed load in the incoming direction.
transferRulesetValue();
Ruleset.ValueChanged += r => updateSelectedRuleset(r.NewValue);
decoupledRuleset.ValueChanged += r =>
{
bool wasDisabled = Ruleset.Disabled;
// a sub-screen may have taken a lease on this decoupled ruleset bindable,
// which would indirectly propagate to the game-global bindable via the `DisabledChanged` callback below.
// to make sure changes sync without crashes, lift the disable for a short while to sync, and then restore the old value.
Ruleset.Disabled = false;
Ruleset.Value = r.NewValue;
Ruleset.Disabled = wasDisabled;
};
decoupledRuleset.DisabledChanged += r => Ruleset.Disabled = r;
Beatmap.BindValueChanged(updateCarouselSelection);
boundLocalBindables = true;
}
/// <summary>
/// Transfer the game-wide ruleset to the local decoupled ruleset.
/// Will immediately run filter operations if required.
/// </summary>
/// <returns>Whether a transfer occurred.</returns>
private bool transferRulesetValue()
{
if (decoupledRuleset.Value?.Equals(Ruleset.Value) == true)
return false;
Logger.Log($"decoupled ruleset transferred (\"{decoupledRuleset.Value}\" -> \"{Ruleset.Value}\")");
rulesetNoDebounce = decoupledRuleset.Value = Ruleset.Value;
// if we have a pending filter operation, we want to run it now.
// it could change selection (ie. if the ruleset has been changed).
Carousel.FlushPendingFilterOperations();
return true;
}
2023-01-13 07:52:14 +08:00
private void delete(BeatmapSetInfo? beatmap)
2017-12-15 11:48:15 +08:00
{
if (beatmap == null) return;
2017-08-30 19:41:41 +08:00
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
2017-03-02 20:40:55 +08:00
}
2018-04-13 17:19:50 +08:00
2023-01-13 07:52:14 +08:00
private void clearScores(BeatmapInfo? beatmapInfo)
2019-01-05 03:13:32 +08:00
{
if (beatmapInfo == null) return;
2019-01-05 03:13:32 +08:00
2021-10-02 23:55:29 +08:00
dialogOverlay?.Push(new BeatmapClearScoresDialog(beatmapInfo, () =>
// schedule done here rather than inside the dialog as the dialog may fade out and never callback.
2020-02-12 18:52:47 +08:00
Schedule(() => BeatmapDetails.Refresh())));
2019-01-05 03:13:32 +08:00
}
2021-09-16 17:26:12 +08:00
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;
2019-01-23 19:52:00 +08:00
if (!this.IsCurrentScreen()) return false;
2021-09-16 17:26:12 +08:00
switch (e.Action)
{
case GlobalAction.Select:
FinaliseSelection();
return true;
}
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2016-12-15 19:55:37 +08:00
{
2018-10-02 11:02:47 +08:00
if (e.Repeat) return false;
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
switch (e.Key)
2016-12-15 19:55:37 +08:00
{
2017-03-14 21:51:26 +08:00
case Key.Delete:
if (e.ShiftPressed)
2017-03-14 21:51:26 +08:00
{
2017-08-30 19:41:41 +08:00
if (!Beatmap.IsDefault)
2017-12-15 11:48:15 +08:00
delete(Beatmap.Value.BeatmapSetInfo);
2017-03-14 21:51:26 +08:00
return true;
}
2018-04-13 17:19:50 +08:00
2017-03-14 21:51:26 +08:00
break;
2016-12-15 19:55:37 +08:00
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
2016-12-15 19:55:37 +08:00
}
2018-04-13 17:19:50 +08:00
private partial class VerticalMaskingContainer : Container
{
private const float panel_overflow = 1.2f;
protected override Container<Drawable> Content { get; }
public VerticalMaskingContainer()
{
RelativeSizeAxes = Axes.Both;
Masking = true;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
2020-05-05 09:31:11 +08:00
Width = panel_overflow; // avoid horizontal masking so the panels don't clip when screen stack is pushed.
InternalChild = Content = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 1 / panel_overflow,
};
}
}
2017-07-31 19:20:12 +08:00
private partial class ResetScrollContainer : Container
2017-07-29 22:33:20 +08:00
{
2023-01-13 07:52:14 +08:00
private readonly Action? onHoverAction;
2018-04-13 17:19:50 +08:00
2017-07-31 19:20:12 +08:00
public ResetScrollContainer(Action onHoverAction)
{
this.onHoverAction = onHoverAction;
}
2018-04-13 17:19:50 +08:00
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2017-07-29 22:33:20 +08:00
{
2017-07-31 19:20:12 +08:00
onHoverAction?.Invoke();
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
2017-07-29 22:33:20 +08:00
}
}
internal partial class SoloModSelectOverlay : UserModSelectOverlay
{
protected override bool ShowPresets => true;
}
2016-09-29 19:13:58 +08:00
}
}