1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 08:12:55 +08:00
osu-lazer/osu.Game/Screens/Select/SongSelect.cs

823 lines
31 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
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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;
2018-04-13 17:19:50 +08:00
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
2018-04-13 17:19:50 +08:00
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;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Select.Options;
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;
using System;
using System.Collections.Generic;
using System.Linq;
2019-06-10 11:46:21 +08:00
using System.Threading.Tasks;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Bindings;
using osu.Game.Overlays.Notifications;
using osu.Game.Scoring;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
public abstract class SongSelect : OsuScreen, IKeyBindingHandler<GlobalAction>
2018-04-13 17:19:50 +08:00
{
public static readonly float WEDGE_HEIGHT = 245;
2019-05-12 14:40:58 +08:00
protected const float BACKGROUND_BLUR = 20;
2018-04-13 17:19:50 +08:00
private const float left_area_padding = 20;
2019-11-15 17:23:35 +08:00
public FilterControl FilterControl { get; private set; }
2018-04-13 17:19:50 +08:00
protected virtual bool ShowFooter => true;
/// <summary>
/// Can be null if <see cref="ShowFooter"/> is false.
/// </summary>
protected BeatmapOptionsOverlay BeatmapOptions { get; private set; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Can be null if <see cref="ShowFooter"/> is false.
/// </summary>
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>
protected Container FooterPanels { get; private set; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Whether entering editor mode should be allowed.
/// </summary>
public virtual bool AllowEditing => true;
2020-01-29 22:01:57 +08:00
[Resolved(canBeNull: true)]
private NotificationOverlay notificationOverlay { get; set; }
[Resolved]
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; }
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
2018-04-13 17:19:50 +08:00
protected BeatmapCarousel Carousel { get; private set; }
2018-04-13 17:19:50 +08:00
private BeatmapInfoWedge beatmapInfoWedge;
2018-04-13 17:19:50 +08:00
private DialogOverlay dialogOverlay;
[Resolved]
private BeatmapManager beatmaps { get; set; }
2018-04-13 17:19:50 +08:00
protected ModSelectOverlay ModSelect { get; private set; }
protected SampleChannel SampleConfirm { get; private set; }
2018-12-06 18:29:18 +08:00
2018-04-13 17:19:50 +08:00
private SampleChannel sampleChangeDifficulty;
private SampleChannel sampleChangeBeatmap;
protected BeatmapDetailArea BeatmapDetails { get; private set; }
2019-02-01 14:42:15 +08:00
private readonly Bindable<RulesetInfo> decoupledRuleset = new Bindable<RulesetInfo>();
[Resolved(canBeNull: true)]
private MusicController music { get; set; }
[BackgroundDependencyLoader(true)]
private void load(AudioManager audio, DialogOverlay dialog, OsuColour colours, SkinManager skins, ScoreManager scores)
2018-04-13 17:19:50 +08:00
{
// 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[]
2018-04-13 17:19:50 +08:00
{
new ResetScrollContainer(() => Carousel.ScrollToSelected())
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.Y,
Width = 250,
},
new VerticalMaskingContainer
{
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
2020-01-24 14:00:10 +08:00
new GridContainer // used for max width implementation
2018-04-13 17:19:50 +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[]
{
new ParallaxContainer
2020-01-24 14:00:10 +08:00
{
ParallaxAmount = 0.005f,
2020-01-24 14:00:10 +08:00
RelativeSizeAxes = Axes.Both,
Child = new WedgeBackground
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = -150 },
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Top = FilterControl.HEIGHT,
Bottom = Footer.HEIGHT
},
Child = 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,
SelectionChanged = updateSelectedBeatmap,
BeatmapSetsChanged = carouselBeatmapsLoaded,
},
}
},
}
},
FilterControl = new FilterControl
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X,
Height = FilterControl.HEIGHT,
FilterChanged = ApplyFilterToCarousel,
Background = { Width = 2 },
},
new GridContainer // used for max width implementation
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
2018-04-13 17:19:50 +08:00
{
new Dimension(GridSizeMode.Relative, 0.5f, maxSize: 650),
},
Content = new[]
{
new Drawable[]
{
new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
beatmapInfoWedge = new BeatmapInfoWedge
{
Height = WEDGE_HEIGHT,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Top = left_area_padding,
Right = left_area_padding,
},
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Bottom = Footer.HEIGHT,
Top = WEDGE_HEIGHT + left_area_padding,
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 };
})
},
}
},
},
}
2018-04-13 17:19:50 +08:00
}
}
},
2018-04-13 17:19:50 +08:00
});
if (ShowFooter)
{
AddRangeInternal(new Drawable[]
2018-04-13 17:19:50 +08:00
{
2020-02-04 09:21:06 +08:00
new GridContainer // used for max height implementation
2018-12-06 18:29:18 +08:00
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
2019-06-25 15:55:49 +08:00
{
new Dimension(),
2020-02-04 09:21:06 +08:00
new Dimension(GridSizeMode.Relative, 1f, maxSize: ModSelectOverlay.HEIGHT + Footer.HEIGHT),
},
Content = new[]
{
null,
new Drawable[]
2019-06-25 15:55:49 +08:00
{
FooterPanels = new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = Footer.HEIGHT },
Children = new Drawable[]
{
BeatmapOptions = new BeatmapOptionsOverlay(),
ModSelect = new ModSelectOverlay
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
}
}
}
2019-06-25 15:55:49 +08:00
}
}
},
Footer = new Footer()
2018-12-06 18:29:18 +08:00
});
2018-04-13 17:19:50 +08:00
}
if (Footer != null)
{
Footer.AddButton(new FooterButtonMods { Current = Mods }, ModSelect);
Footer.AddButton(new FooterButtonRandom { Action = triggerRandom });
Footer.AddButton(new FooterButtonOptions(), BeatmapOptions);
2018-04-13 17:19:50 +08:00
BeatmapOptions.AddButton(@"Remove", @"from unplayed", FontAwesome.Regular.TimesCircle, colours.Purple, null, Key.Number1);
BeatmapOptions.AddButton(@"Clear", @"local scores", FontAwesome.Solid.Eraser, colours.Purple, () => clearScores(Beatmap.Value.BeatmapInfo), Key.Number2);
BeatmapOptions.AddButton(@"Delete", @"all difficulties", FontAwesome.Solid.Trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number3);
2018-04-13 17:19:50 +08:00
}
dialogOverlay = dialog;
sampleChangeDifficulty = audio.Samples.Get(@"SongSelect/select-difficulty");
sampleChangeBeatmap = audio.Samples.Get(@"SongSelect/select-expand");
SampleConfirm = audio.Samples.Get(@"SongSelect/confirm-selection");
2018-04-13 17:19:50 +08:00
if (dialogOverlay != null)
{
Schedule(() =>
{
// if we have no beatmaps but osu-stable is found, let's prompt the user to import.
if (!beatmaps.GetAllUsableBeatmapSetsEnumerable().Any() && beatmaps.StableInstallationAvailable)
2019-11-11 19:53:22 +08:00
{
dialogOverlay.Push(new ImportFromStablePopup(() =>
{
Task.Run(beatmaps.ImportFromStableAsync).ContinueWith(_ => scores.ImportFromStableAsync(), TaskContinuationOptions.OnlyOnRanToCompletion);
2019-06-10 11:46:21 +08:00
Task.Run(skins.ImportFromStableAsync);
}));
2019-11-11 19:53:22 +08:00
}
});
}
}
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
private DependencyContainer dependencies;
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();
public void Edit(BeatmapInfo beatmap = null)
2018-04-13 17:19:50 +08:00
{
if (!AllowEditing)
{
notificationOverlay?.Post(new SimpleNotification { Text = "Editing is not available from the current mode." });
return;
}
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap ?? beatmapNoDebounce);
this.Push(new Editor());
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// Call to make a selection and perform the default action for this SongSelect.
/// </summary>
/// <param name="beatmap">An optional beatmap to override the current carousel selection.</param>
/// <param name="performStartAction">Whether to trigger <see cref="OnStart"/>.</param>
public void FinaliseSelection(BeatmapInfo beatmap = null, bool performStartAction = true)
2018-04-13 17:19:50 +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)
return;
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.
2018-04-13 17:19:50 +08:00
Carousel.FlushPendingFilterOperations();
// 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.SelectedBeatmap == null) return;
2018-04-13 17:19:50 +08:00
if (beatmap != null)
Carousel.SelectBeatmap(beatmap);
if (selectionChangedDebounce?.Completed == false)
{
selectionChangedDebounce.RunTask();
selectionChangedDebounce.Cancel(); // cancel the already scheduled task.
selectionChangedDebounce = null;
}
if (performStartAction && OnStart())
Carousel.AllowSelection = false;
2018-04-13 17:19:50 +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
private ScheduledDelegate selectionChangedDebounce;
2019-02-21 17:56:34 +08:00
private void workingBeatmapChanged(ValueChangedEvent<WorkingBeatmap> e)
2018-04-13 17:19:50 +08:00
{
if (e.NewValue is DummyWorkingBeatmap || !this.IsCurrentScreen()) return;
2018-04-13 17:19:50 +08:00
Logger.Log($"working beatmap updated to {e.NewValue}");
if (!Carousel.SelectBeatmap(e.NewValue.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 (e.NewValue.BeatmapInfo.Ruleset != null && !e.NewValue.BeatmapInfo.Ruleset.Equals(decoupledRuleset.Value))
2018-04-13 17:19:50 +08:00
{
2019-02-21 17:56:34 +08:00
Ruleset.Value = e.NewValue.BeatmapInfo.Ruleset;
transferRulesetValue();
2018-04-13 17:19:50 +08:00
}
// 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 = e.NewValue.BeatmapInfo.BeatmapSet;
Carousel.Filter(criteria);
Carousel.SelectBeatmap(e.NewValue.BeatmapInfo);
2019-11-11 19:53:22 +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.
private BeatmapInfo beatmapNoDebounce;
private RulesetInfo rulesetNoDebounce;
private void updateSelectedBeatmap(BeatmapInfo beatmap)
{
if (beatmap?.Equals(beatmapNoDebounce) == true)
return;
beatmapNoDebounce = beatmap;
performUpdateSelected();
}
private void updateSelectedRuleset(RulesetInfo ruleset)
{
if (ruleset?.Equals(rulesetNoDebounce) == true)
return;
rulesetNoDebounce = ruleset;
performUpdateSelected();
}
2018-04-13 17:19:50 +08:00
/// <summary>
/// selection has been changed as the result of a user interaction.
2018-04-13 17:19:50 +08:00
/// </summary>
private void performUpdateSelected()
2018-04-13 17:19:50 +08:00
{
var beatmap = beatmapNoDebounce;
var ruleset = rulesetNoDebounce;
2019-03-21 19:51:21 +08:00
selectionChangedDebounce?.Cancel();
if (beatmap == null)
run();
else
selectionChangedDebounce = Scheduler.AddDelayed(run, 200);
void run()
2018-04-13 17:19:50 +08:00
{
Logger.Log($"updating selection with beatmap:{beatmap?.ID.ToString() ?? "null"} ruleset:{ruleset?.ID.ToString() ?? "null"}");
2018-07-19 17:51:08 +08:00
if (transferRulesetValue())
{
Mods.Value = Array.Empty<Mod>();
// required to return once in order to have the carousel in a good state.
// if the ruleset changed, the rest of the selection update will happen via updateSelectedRuleset.
return;
}
2018-04-13 17:19:50 +08:00
// 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))
2018-04-13 17:19:50 +08:00
{
Logger.Log($"beatmap changed from \"{Beatmap.Value.BeatmapInfo}\" to \"{beatmap}\"");
2018-07-19 17:51:08 +08:00
WorkingBeatmap previous = Beatmap.Value;
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, previous);
if (beatmap != null)
{
if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID)
sampleChangeDifficulty.Play();
else
sampleChangeBeatmap.Play();
}
2018-04-13 17:19:50 +08:00
}
if (this.IsCurrentScreen())
ensurePlayingSelected();
updateComponentFromBeatmap(Beatmap.Value);
2018-04-13 17:19:50 +08:00
}
}
private void triggerRandom()
{
if (GetContainingInputManager().CurrentState.Keyboard.ShiftPressed)
Carousel.SelectPreviousRandom();
else
Carousel.SelectNextRandom();
}
2019-01-23 19:52:00 +08:00
public override void OnEntering(IScreen last)
2018-04-13 17:19:50 +08:00
{
base.OnEntering(last);
2019-01-23 19:52:00 +08:00
this.FadeInFromZero(250);
2018-04-13 17:19:50 +08:00
FilterControl.Activate();
ModSelect.SelectedMods.BindTo(selectedMods);
2018-04-13 17:19:50 +08:00
}
private const double logo_transition = 250;
protected override void LogoArriving(OsuLogo logo, bool resuming)
{
base.LogoArriving(logo, resuming);
Vector2 position = new Vector2(0.95f, 0.96f);
if (logo.Alpha > 0.8f)
{
logo.MoveTo(position, 500, Easing.OutQuint);
}
else
{
logo.Hide();
logo.ScaleTo(0.2f);
logo.MoveTo(position);
}
logo.FadeIn(logo_transition, Easing.OutQuint);
logo.ScaleTo(0.4f, logo_transition, Easing.OutQuint);
logo.Action = () =>
{
FinaliseSelection();
return false;
};
}
protected override void LogoExiting(OsuLogo logo)
{
base.LogoExiting(logo);
logo.ScaleTo(0.2f, logo_transition / 2, Easing.Out);
logo.FadeOut(logo_transition / 2, Easing.Out);
}
2019-01-23 19:52:00 +08:00
public override void OnResuming(IScreen last)
2018-04-13 17:19:50 +08:00
{
base.OnResuming(last);
// 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();
Beatmap.Value.Track.Looping = true;
music?.ResetTrackAdjustments();
2018-04-13 17:19:50 +08:00
if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
{
updateComponentFromBeatmap(Beatmap.Value);
// restart playback on returning to song select, regardless.
music?.Play();
2018-04-13 17:19:50 +08:00
}
2019-01-23 19:52:00 +08:00
this.FadeIn(250);
2018-04-13 17:19:50 +08:00
2019-01-23 19:52:00 +08:00
this.ScaleTo(1, 250, Easing.OutSine);
2018-04-13 17:19:50 +08:00
FilterControl.Activate();
}
2019-01-23 19:52:00 +08:00
public override void OnSuspending(IScreen next)
2018-04-13 17:19:50 +08:00
{
ModSelect.SelectedMods.UnbindFrom(selectedMods);
2018-12-06 18:29:18 +08:00
ModSelect.Hide();
2019-05-12 12:26:42 +08:00
BeatmapOptions.Hide();
if (Beatmap.Value.Track != null)
Beatmap.Value.Track.Looping = false;
2019-01-23 19:52:00 +08:00
this.ScaleTo(1.1f, 250, Easing.InSine);
2018-04-13 17:19:50 +08:00
2019-01-23 19:52:00 +08:00
this.FadeOut(250);
2018-04-13 17:19:50 +08:00
FilterControl.Deactivate();
base.OnSuspending(next);
}
2019-01-23 19:52:00 +08:00
public override bool OnExiting(IScreen next)
2018-04-13 17:19:50 +08:00
{
if (ModSelect.State.Value == Visibility.Visible)
{
ModSelect.Hide();
return true;
}
if (base.OnExiting(next))
return true;
beatmapInfoWedge.Hide();
2018-04-13 17:19:50 +08:00
2019-01-23 19:52:00 +08:00
this.FadeOut(100);
2018-04-13 17:19:50 +08:00
FilterControl.Deactivate();
if (Beatmap.Value.Track != null)
Beatmap.Value.Track.Looping = false;
return false;
2018-04-13 17:19:50 +08:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2019-02-01 14:42:15 +08:00
decoupledRuleset.UnbindAll();
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)
2018-04-13 17:19:50 +08:00
{
if (Background is BackgroundScreenBeatmap backgroundModeBeatmap)
{
backgroundModeBeatmap.Beatmap = beatmap;
backgroundModeBeatmap.BlurAmount.Value = BACKGROUND_BLUR;
backgroundModeBeatmap.FadeColour(Color4.White, 250);
2018-04-13 17:19:50 +08:00
}
beatmapInfoWedge.Beatmap = beatmap;
BeatmapDetails.Beatmap = beatmap;
if (beatmap.Track != null)
beatmap.Track.Looping = true;
2018-04-13 17:19:50 +08:00
}
private readonly WeakReference<Track> lastTrack = new WeakReference<Track>(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()
2018-04-13 17:19:50 +08:00
{
Track track = Beatmap.Value.Track;
bool isNewTrack = !lastTrack.TryGetTarget(out var last) || last != track;
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
if (!track.IsRunning && (music?.IsUserPaused != true || isNewTrack))
music?.Play(true);
lastTrack.SetTarget(track);
2018-04-13 17:19:50 +08:00
}
private void carouselBeatmapsLoaded()
{
bindBindables();
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())
2018-04-13 17:19:50 +08:00
{
// in the case random selection failed, we want to trigger selectionChanged
// to show the dummy beatmap (we have nothing else to display).
performUpdateSelected();
2018-04-13 17:19:50 +08:00
}
}
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 => Ruleset.Value = r.NewValue;
decoupledRuleset.DisabledChanged += r => Ruleset.Disabled = r;
Beatmap.BindValueChanged(workingBeatmapChanged);
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;
}
2018-04-13 17:19:50 +08:00
private void delete(BeatmapSetInfo beatmap)
{
2018-09-21 10:29:37 +08:00
if (beatmap == null || beatmap.ID <= 0) return;
2018-04-13 17:19:50 +08:00
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
}
2019-01-09 00:57:03 +08:00
private void clearScores(BeatmapInfo beatmap)
2019-01-05 03:13:32 +08:00
{
if (beatmap == null || beatmap.ID <= 0) return;
dialogOverlay?.Push(new BeatmapClearScoresDialog(beatmap, () =>
// 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
}
public virtual bool OnPressed(GlobalAction action)
{
2019-01-23 19:52:00 +08:00
if (!this.IsCurrentScreen()) return false;
switch (action)
{
case GlobalAction.Select:
FinaliseSelection();
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2018-04-13 17:19:50 +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)
2018-04-13 17:19:50 +08:00
{
case Key.Delete:
if (e.ShiftPressed)
2018-04-13 17:19:50 +08:00
{
if (!Beatmap.IsDefault)
delete(Beatmap.Value.BeatmapSetInfo);
return true;
}
break;
}
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
2018-04-13 17:19:50 +08:00
}
private 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;
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,
};
}
}
2018-04-13 17:19:50 +08:00
private class ResetScrollContainer : Container
{
private readonly Action onHoverAction;
public ResetScrollContainer(Action onHoverAction)
{
this.onHoverAction = onHoverAction;
}
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
onHoverAction?.Invoke();
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
2018-04-13 17:19:50 +08:00
}
}
}
}