2019-01-24 08:43:03 +00:00
// 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 09:19:50 +00:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
2020-10-13 09:18:22 +00:00
using System.Linq ;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation ;
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables ;
2018-04-13 09:19:50 +00:00
using osu.Framework.Caching ;
2020-10-13 09:18:22 +00:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2020-10-12 06:36:03 +00:00
using osu.Framework.Graphics.Pooling ;
2020-03-02 09:55:28 +00:00
using osu.Framework.Input.Bindings ;
2018-10-02 03:02:47 +00:00
using osu.Framework.Input.Events ;
2021-01-02 13:05:41 +00:00
using osu.Framework.Layout ;
2020-10-13 09:18:22 +00:00
using osu.Framework.Threading ;
using osu.Framework.Utils ;
2018-04-13 09:19:50 +00:00
using osu.Game.Beatmaps ;
2020-10-13 09:18:22 +00:00
using osu.Game.Configuration ;
2020-06-25 12:33:02 +00:00
using osu.Game.Extensions ;
2018-04-13 09:19:50 +00:00
using osu.Game.Graphics.Containers ;
using osu.Game.Graphics.Cursor ;
2020-03-02 09:55:28 +00:00
using osu.Game.Input.Bindings ;
2018-04-13 09:19:50 +00:00
using osu.Game.Screens.Select.Carousel ;
2020-10-13 09:18:22 +00:00
using osuTK ;
using osuTK.Input ;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Screens.Select
{
2020-03-02 09:55:28 +00:00
public class BeatmapCarousel : CompositeDrawable , IKeyBindingHandler < GlobalAction >
2018-04-13 09:19:50 +00:00
{
2020-04-20 19:42:43 +00:00
/// <summary>
/// Height of the area above the carousel that should be treated as visible due to transparency of elements in front of it.
/// </summary>
2020-04-20 19:43:07 +00:00
public float BleedTop { get ; set ; }
2020-04-20 19:42:43 +00:00
/// <summary>
/// Height of the area below the carousel that should be treated as visible due to transparency of elements in front of it.
/// </summary>
2020-04-20 19:43:07 +00:00
public float BleedBottom { get ; set ; }
2019-07-26 04:07:28 +00:00
2018-04-13 09:19:50 +00:00
/// <summary>
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
/// </summary>
public Action BeatmapSetsChanged ;
/// <summary>
/// The currently selected beatmap.
/// </summary>
public BeatmapInfo SelectedBeatmap = > selectedBeatmap ? . Beatmap ;
2019-02-21 09:56:34 +00:00
private CarouselBeatmap selectedBeatmap = > selectedBeatmapSet ? . Beatmaps . FirstOrDefault ( s = > s . State . Value = = CarouselItemState . Selected ) ;
2018-04-13 09:19:50 +00:00
/// <summary>
/// The currently selected beatmap set.
/// </summary>
public BeatmapSetInfo SelectedBeatmapSet = > selectedBeatmapSet ? . BeatmapSet ;
2020-04-11 07:58:13 +00:00
/// <summary>
/// A function to optionally decide on a recommended difficulty from a beatmap set.
/// </summary>
public Func < IEnumerable < BeatmapInfo > , BeatmapInfo > GetRecommendedBeatmap ;
2018-04-13 09:19:50 +00:00
private CarouselBeatmapSet selectedBeatmapSet ;
/// <summary>
/// Raised when the <see cref="SelectedBeatmap"/> is changed.
/// </summary>
public Action < BeatmapInfo > SelectionChanged ;
2018-09-26 05:01:15 +00:00
public override bool HandleNonPositionalInput = > AllowSelection ;
public override bool HandlePositionalInput = > AllowSelection ;
2018-04-13 09:19:50 +00:00
2020-01-27 05:55:47 +00:00
public override bool PropagatePositionalInputSubTree = > AllowSelection ;
public override bool PropagateNonPositionalInputSubTree = > AllowSelection ;
2020-10-13 10:10:35 +00:00
private ( int first , int last ) displayedRange ;
/// <summary>
/// Extend the range to retain already loaded pooled drawables.
/// </summary>
private const float distance_offscreen_before_unload = 1024 ;
/// <summary>
/// Extend the range to update positions / retrieve pooled drawables outside of visible range.
/// </summary>
private const float distance_offscreen_to_preload = 512 ; // todo: adjust this appropriately once we can make set panel contents load while off-screen.
2018-04-13 09:19:50 +00:00
/// <summary>
2019-03-21 11:51:06 +00:00
/// Whether carousel items have completed asynchronously loaded.
2018-04-13 09:19:50 +00:00
/// </summary>
2019-03-21 11:51:06 +00:00
public bool BeatmapSetsLoaded { get ; private set ; }
2018-04-13 09:19:50 +00:00
2020-11-26 09:28:52 +00:00
protected readonly CarouselScrollContainer Scroll ;
2019-08-15 05:00:12 +00:00
2018-04-13 09:19:50 +00:00
private IEnumerable < CarouselBeatmapSet > beatmapSets = > root . Children . OfType < CarouselBeatmapSet > ( ) ;
2020-01-29 07:51:14 +00:00
// todo: only used for testing, maybe remove.
2018-04-13 09:19:50 +00:00
public IEnumerable < BeatmapSetInfo > BeatmapSets
{
2018-08-28 16:42:25 +00:00
get = > beatmapSets . Select ( g = > g . BeatmapSet ) ;
2019-06-30 13:23:48 +00:00
set = > loadBeatmapSets ( value ) ;
2018-08-28 16:42:25 +00:00
}
2019-06-30 13:23:48 +00:00
private void loadBeatmapSets ( IEnumerable < BeatmapSetInfo > beatmapSets )
2018-08-28 16:42:25 +00:00
{
CarouselRoot newRoot = new CarouselRoot ( this ) ;
2020-10-12 06:36:26 +00:00
newRoot . AddChildren ( beatmapSets . Select ( createCarouselSet ) . Where ( g = > g ! = null ) ) ;
2018-04-13 09:19:50 +00:00
2019-06-30 13:23:48 +00:00
root = newRoot ;
2019-09-24 17:42:12 +00:00
if ( selectedBeatmapSet ! = null & & ! beatmapSets . Contains ( selectedBeatmapSet . BeatmapSet ) )
selectedBeatmapSet = null ;
2020-11-26 09:28:52 +00:00
Scroll . Clear ( false ) ;
2019-06-30 13:23:48 +00:00
itemsCache . Invalidate ( ) ;
2020-11-27 04:54:36 +00:00
ScrollToSelected ( ) ;
2019-06-30 13:23:48 +00:00
2020-07-13 04:08:41 +00:00
// apply any pending filter operation that may have been delayed (see applyActiveCriteria's scheduling behaviour when BeatmapSetsLoaded is false).
2020-07-12 13:21:16 +00:00
FlushPendingFilterOperations ( ) ;
2019-07-25 03:18:18 +00:00
// Run on late scheduler want to ensure this runs after all pending UpdateBeatmapSet / RemoveBeatmapSet operations are run.
SchedulerAfterChildren . Add ( ( ) = >
2019-06-30 13:23:48 +00:00
{
BeatmapSetsChanged ? . Invoke ( ) ;
BeatmapSetsLoaded = true ;
2021-01-03 03:53:25 +00:00
itemsCache . Invalidate ( ) ;
2019-06-30 13:23:48 +00:00
} ) ;
2018-04-13 09:19:50 +00:00
}
2020-10-12 05:23:18 +00:00
private readonly List < CarouselItem > visibleItems = new List < CarouselItem > ( ) ;
2019-08-09 10:12:29 +00:00
private readonly Cached itemsCache = new Cached ( ) ;
2020-11-27 04:54:36 +00:00
private PendingScrollOperation pendingScrollOperation = PendingScrollOperation . None ;
2018-04-13 09:19:50 +00:00
2018-04-13 10:50:37 +00:00
public Bindable < bool > RightClickScrollingEnabled = new Bindable < bool > ( ) ;
2018-04-13 09:19:50 +00:00
public Bindable < RandomSelectAlgorithm > RandomAlgorithm = new Bindable < RandomSelectAlgorithm > ( ) ;
private readonly List < CarouselBeatmapSet > previouslyVisitedRandomSets = new List < CarouselBeatmapSet > ( ) ;
private readonly Stack < CarouselBeatmap > randomSelectedBeatmaps = new Stack < CarouselBeatmap > ( ) ;
private CarouselRoot root ;
2020-04-11 07:41:11 +00:00
2020-05-27 07:08:47 +00:00
private IBindable < WeakReference < BeatmapSetInfo > > itemUpdated ;
2020-05-19 07:44:22 +00:00
private IBindable < WeakReference < BeatmapSetInfo > > itemRemoved ;
private IBindable < WeakReference < BeatmapInfo > > itemHidden ;
private IBindable < WeakReference < BeatmapInfo > > itemRestored ;
2020-10-12 06:36:03 +00:00
private readonly DrawablePool < DrawableCarouselBeatmapSet > setPool = new DrawablePool < DrawableCarouselBeatmapSet > ( 100 ) ;
2018-04-13 09:19:50 +00:00
public BeatmapCarousel ( )
{
root = new CarouselRoot ( this ) ;
2019-08-15 05:00:12 +00:00
InternalChild = new OsuContextMenuContainer
2018-04-13 09:19:50 +00:00
{
2019-08-15 05:00:12 +00:00
RelativeSizeAxes = Axes . Both ,
2020-11-26 09:28:52 +00:00
Children = new Drawable [ ]
2018-04-13 09:19:50 +00:00
{
2020-11-26 09:28:52 +00:00
setPool ,
Scroll = new CarouselScrollContainer
2019-08-15 05:00:12 +00:00
{
2020-11-26 09:28:52 +00:00
RelativeSizeAxes = Axes . Both ,
2019-08-15 05:00:12 +00:00
}
2018-04-13 09:19:50 +00:00
}
} ;
}
2020-01-29 07:51:14 +00:00
[Resolved]
private BeatmapManager beatmaps { get ; set ; }
2020-03-26 16:42:08 +00:00
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader(permitNulls: true)]
2020-04-09 15:47:28 +00:00
private void load ( OsuConfigManager config )
2018-04-13 09:19:50 +00:00
{
config . BindWith ( OsuSetting . RandomSelectAlgorithm , RandomAlgorithm ) ;
2018-04-18 10:26:54 +00:00
config . BindWith ( OsuSetting . SongSelectRightMouseScroll , RightClickScrollingEnabled ) ;
2018-04-13 10:50:37 +00:00
2020-11-26 09:28:52 +00:00
RightClickScrollingEnabled . ValueChanged + = enabled = > Scroll . RightMouseScrollbar = enabled . NewValue ;
2018-04-13 10:50:37 +00:00
RightClickScrollingEnabled . TriggerChange ( ) ;
2019-06-30 13:23:48 +00:00
2020-05-27 07:08:47 +00:00
itemUpdated = beatmaps . ItemUpdated . GetBoundCopy ( ) ;
itemUpdated . BindValueChanged ( beatmapUpdated ) ;
2020-05-19 07:44:22 +00:00
itemRemoved = beatmaps . ItemRemoved . GetBoundCopy ( ) ;
itemRemoved . BindValueChanged ( beatmapRemoved ) ;
itemHidden = beatmaps . BeatmapHidden . GetBoundCopy ( ) ;
itemHidden . BindValueChanged ( beatmapHidden ) ;
itemRestored = beatmaps . BeatmapRestored . GetBoundCopy ( ) ;
itemRestored . BindValueChanged ( beatmapRestored ) ;
2020-01-29 07:51:14 +00:00
2020-10-12 05:23:18 +00:00
if ( ! beatmapSets . Any ( ) )
loadBeatmapSets ( GetLoadableBeatmaps ( ) ) ;
2018-04-13 09:19:50 +00:00
}
2020-04-28 12:43:35 +00:00
protected virtual IEnumerable < BeatmapSetInfo > GetLoadableBeatmaps ( ) = > beatmaps . GetAllUsableBeatmapSetsEnumerable ( IncludedDetails . AllButFiles ) ;
2020-03-12 06:26:22 +00:00
2019-07-25 03:18:18 +00:00
public void RemoveBeatmapSet ( BeatmapSetInfo beatmapSet ) = > Schedule ( ( ) = >
2018-04-13 09:19:50 +00:00
{
2019-07-25 03:18:18 +00:00
var existingSet = beatmapSets . FirstOrDefault ( b = > b . BeatmapSet . ID = = beatmapSet . ID ) ;
2018-04-13 09:19:50 +00:00
2019-07-25 03:18:18 +00:00
if ( existingSet = = null )
return ;
2018-04-13 09:19:50 +00:00
2019-07-25 03:18:18 +00:00
root . RemoveChild ( existingSet ) ;
itemsCache . Invalidate ( ) ;
} ) ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
public void UpdateBeatmapSet ( BeatmapSetInfo beatmapSet ) = > Schedule ( ( ) = >
2018-04-13 09:19:50 +00:00
{
2019-06-26 02:40:33 +00:00
int? previouslySelectedID = null ;
CarouselBeatmapSet existingSet = beatmapSets . FirstOrDefault ( b = > b . BeatmapSet . ID = = beatmapSet . ID ) ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
// If the selected beatmap is about to be removed, store its ID so it can be re-selected if required
if ( existingSet ? . State ? . Value = = CarouselItemState . Selected )
previouslySelectedID = selectedBeatmap ? . Beatmap . ID ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
var newSet = createCarouselSet ( beatmapSet ) ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
if ( existingSet ! = null )
root . RemoveChild ( existingSet ) ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
if ( newSet = = null )
{
itemsCache . Invalidate ( ) ;
return ;
}
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
root . AddChild ( newSet ) ;
2018-04-13 09:19:50 +00:00
2020-03-13 02:51:26 +00:00
// only reset scroll position if already near the scroll target.
// without this, during a large beatmap import it is impossible to navigate the carousel.
applyActiveCriteria ( false , alwaysResetScrollPosition : false ) ;
2018-04-13 09:19:50 +00:00
2020-05-05 01:31:11 +00:00
// check if we can/need to maintain our current selection.
2019-06-26 02:40:33 +00:00
if ( previouslySelectedID ! = null )
select ( ( CarouselItem ) newSet . Beatmaps . FirstOrDefault ( b = > b . Beatmap . ID = = previouslySelectedID ) ? ? newSet ) ;
2018-04-13 09:19:50 +00:00
2019-06-26 02:40:33 +00:00
itemsCache . Invalidate ( ) ;
Schedule ( ( ) = > BeatmapSetsChanged ? . Invoke ( ) ) ;
} ) ;
2018-04-13 09:19:50 +00:00
/// <summary>
/// Selects a given beatmap on the carousel.
/// </summary>
/// <param name="beatmap">The beatmap to select.</param>
/// <param name="bypassFilters">Whether to select the beatmap even if it is filtered (i.e., not visible on carousel).</param>
/// <returns>True if a selection was made, False if it wasn't.</returns>
public bool SelectBeatmap ( BeatmapInfo beatmap , bool bypassFilters = true )
{
2020-04-16 09:10:35 +00:00
// ensure that any pending events from BeatmapManager have been run before attempting a selection.
Scheduler . Update ( ) ;
2018-04-13 09:19:50 +00:00
if ( beatmap ? . Hidden ! = false )
return false ;
foreach ( CarouselBeatmapSet set in beatmapSets )
{
2019-02-21 09:56:34 +00:00
if ( ! bypassFilters & & set . Filtered . Value )
2018-04-13 09:19:50 +00:00
continue ;
var item = set . Beatmaps . FirstOrDefault ( p = > p . Beatmap . Equals ( beatmap ) ) ;
if ( item = = null )
// The beatmap that needs to be selected doesn't exist in this set
continue ;
2019-02-21 09:56:34 +00:00
if ( ! bypassFilters & & item . Filtered . Value )
2020-03-12 06:52:03 +00:00
return false ;
2018-04-13 09:19:50 +00:00
2020-03-12 06:52:03 +00:00
select ( item ) ;
2020-02-10 07:31:52 +00:00
2020-03-12 06:52:03 +00:00
// if we got here and the set is filtered, it means we were bypassing filters.
// in this case, reapplying the filter is necessary to ensure the panel is in the correct place
// (since it is forcefully being included in the carousel).
if ( set . Filtered . Value )
{
Debug . Assert ( bypassFilters ) ;
2020-02-10 07:31:52 +00:00
2020-03-12 06:52:03 +00:00
applyActiveCriteria ( false ) ;
2018-04-13 09:19:50 +00:00
}
2020-03-12 06:52:03 +00:00
return true ;
2018-04-13 09:19:50 +00:00
}
return false ;
}
/// <summary>
/// Increment selection in the carousel in a chosen direction.
/// </summary>
/// <param name="direction">The direction to increment. Negative is backwards.</param>
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
public void SelectNext ( int direction = 1 , bool skipDifficulties = true )
{
2020-03-28 18:21:21 +00:00
if ( beatmapSets . All ( s = > s . Filtered . Value ) )
2018-04-13 09:19:50 +00:00
return ;
2020-03-28 10:54:48 +00:00
if ( skipDifficulties )
selectNextSet ( direction , true ) ;
else
selectNextDifficulty ( direction ) ;
}
2018-04-13 09:19:50 +00:00
2020-03-28 10:54:48 +00:00
private void selectNextSet ( int direction , bool skipDifficulties )
{
2020-03-29 15:07:48 +00:00
var unfilteredSets = beatmapSets . Where ( s = > ! s . Filtered . Value ) . ToList ( ) ;
2018-04-13 09:19:50 +00:00
2020-03-29 15:07:48 +00:00
var nextSet = unfilteredSets [ ( unfilteredSets . IndexOf ( selectedBeatmapSet ) + direction + unfilteredSets . Count ) % unfilteredSets . Count ] ;
2018-04-13 09:19:50 +00:00
2020-03-28 10:54:48 +00:00
if ( skipDifficulties )
2020-03-28 11:23:31 +00:00
select ( nextSet ) ;
2020-03-28 10:54:48 +00:00
else
2020-03-28 11:23:31 +00:00
select ( direction > 0 ? nextSet . Beatmaps . First ( b = > ! b . Filtered . Value ) : nextSet . Beatmaps . Last ( b = > ! b . Filtered . Value ) ) ;
2020-03-28 10:54:48 +00:00
}
2018-04-13 09:19:50 +00:00
2020-03-28 10:54:48 +00:00
private void selectNextDifficulty ( int direction )
{
2020-06-26 12:03:34 +00:00
if ( selectedBeatmap = = null )
return ;
2020-03-29 15:07:48 +00:00
var unfilteredDifficulties = selectedBeatmapSet . Children . Where ( s = > ! s . Filtered . Value ) . ToList ( ) ;
2018-04-13 09:19:50 +00:00
2020-03-29 15:07:48 +00:00
int index = unfilteredDifficulties . IndexOf ( selectedBeatmap ) ;
2018-04-13 09:19:50 +00:00
2020-03-29 15:07:48 +00:00
if ( index + direction < 0 | | index + direction > = unfilteredDifficulties . Count )
2020-03-28 10:54:48 +00:00
selectNextSet ( direction , false ) ;
else
2020-03-29 15:07:48 +00:00
select ( unfilteredDifficulties [ index + direction ] ) ;
2018-04-13 09:19:50 +00:00
}
/// <summary>
/// Select the next beatmap in the random sequence.
/// </summary>
/// <returns>True if a selection could be made, else False.</returns>
public bool SelectNextRandom ( )
{
2020-07-12 13:21:16 +00:00
if ( ! AllowSelection )
return false ;
2019-02-21 09:56:34 +00:00
var visibleSets = beatmapSets . Where ( s = > ! s . Filtered . Value ) . ToList ( ) ;
2018-04-13 09:19:50 +00:00
if ( ! visibleSets . Any ( ) )
return false ;
if ( selectedBeatmap ! = null )
{
randomSelectedBeatmaps . Push ( selectedBeatmap ) ;
// when performing a random, we want to add the current set to the previously visited list
// else the user may be "randomised" to the existing selection.
if ( previouslyVisitedRandomSets . LastOrDefault ( ) ! = selectedBeatmapSet )
previouslyVisitedRandomSets . Add ( selectedBeatmapSet ) ;
}
CarouselBeatmapSet set ;
2019-02-21 09:56:34 +00:00
if ( RandomAlgorithm . Value = = RandomSelectAlgorithm . RandomPermutation )
2018-04-13 09:19:50 +00:00
{
var notYetVisitedSets = visibleSets . Except ( previouslyVisitedRandomSets ) . ToList ( ) ;
2019-04-01 03:16:05 +00:00
2018-04-13 09:19:50 +00:00
if ( ! notYetVisitedSets . Any ( ) )
{
previouslyVisitedRandomSets . RemoveAll ( s = > visibleSets . Contains ( s ) ) ;
notYetVisitedSets = visibleSets ;
}
set = notYetVisitedSets . ElementAt ( RNG . Next ( notYetVisitedSets . Count ) ) ;
previouslyVisitedRandomSets . Add ( set ) ;
}
else
set = visibleSets . ElementAt ( RNG . Next ( visibleSets . Count ) ) ;
2020-03-20 04:01:24 +00:00
select ( set ) ;
2018-04-13 09:19:50 +00:00
return true ;
}
public void SelectPreviousRandom ( )
{
while ( randomSelectedBeatmaps . Any ( ) )
{
var beatmap = randomSelectedBeatmaps . Pop ( ) ;
2019-02-21 09:56:34 +00:00
if ( ! beatmap . Filtered . Value )
2018-04-13 09:19:50 +00:00
{
2019-02-21 09:56:34 +00:00
if ( RandomAlgorithm . Value = = RandomSelectAlgorithm . RandomPermutation )
2018-04-13 09:19:50 +00:00
previouslyVisitedRandomSets . Remove ( selectedBeatmapSet ) ;
select ( beatmap ) ;
break ;
}
}
}
private void select ( CarouselItem item )
{
2019-03-21 12:02:45 +00:00
if ( ! AllowSelection )
return ;
2018-04-13 09:19:50 +00:00
if ( item = = null ) return ;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
item . State . Value = CarouselItemState . Selected ;
}
private FilterCriteria activeCriteria = new FilterCriteria ( ) ;
2018-07-18 01:12:14 +00:00
protected ScheduledDelegate PendingFilter ;
2018-04-13 09:19:50 +00:00
public bool AllowSelection = true ;
2019-07-26 04:07:28 +00:00
/// <summary>
2019-07-26 06:22:29 +00:00
/// Half the height of the visible content.
2019-07-26 06:13:10 +00:00
/// <remarks>
2019-11-17 12:55:40 +00:00
/// This is different from the height of <see cref="ScrollContainer{T}"/>.displayableContent, since
2019-07-26 06:13:10 +00:00
/// the beatmap carousel bleeds into the <see cref="FilterControl"/> and the <see cref="Footer"/>
/// </remarks>
2019-07-26 04:07:28 +00:00
/// </summary>
2020-04-19 15:29:06 +00:00
private float visibleHalfHeight = > ( DrawHeight + BleedBottom + BleedTop ) / 2 ;
2019-07-26 04:07:28 +00:00
2019-07-26 06:13:10 +00:00
/// <summary>
/// The position of the lower visible bound with respect to the current scroll position.
/// </summary>
2020-11-26 09:28:52 +00:00
private float visibleBottomBound = > Scroll . Current + DrawHeight + BleedBottom ;
2019-07-26 06:13:10 +00:00
/// <summary>
/// The position of the upper visible bound with respect to the current scroll position.
/// </summary>
2020-11-26 09:28:52 +00:00
private float visibleUpperBound = > Scroll . Current - BleedTop ;
2019-07-26 06:13:10 +00:00
2018-04-13 09:19:50 +00:00
public void FlushPendingFilterOperations ( )
{
2018-07-18 01:12:14 +00:00
if ( PendingFilter ? . Completed = = false )
2018-04-13 09:19:50 +00:00
{
2020-03-10 10:59:49 +00:00
applyActiveCriteria ( false ) ;
2018-04-13 09:19:50 +00:00
Update ( ) ;
}
}
public void Filter ( FilterCriteria newCriteria , bool debounce = true )
{
if ( newCriteria ! = null )
activeCriteria = newCriteria ;
2020-03-10 10:59:49 +00:00
applyActiveCriteria ( debounce ) ;
2018-04-13 09:19:50 +00:00
}
2020-03-13 02:51:26 +00:00
private void applyActiveCriteria ( bool debounce , bool alwaysResetScrollPosition = true )
2018-04-13 09:19:50 +00:00
{
2020-07-12 13:21:16 +00:00
PendingFilter ? . Cancel ( ) ;
PendingFilter = null ;
if ( debounce )
PendingFilter = Scheduler . AddDelayed ( perform , 250 ) ;
else
{
// if initial load is not yet finished, this will be run inline in loadBeatmapSets to ensure correct order of operation.
if ( ! BeatmapSetsLoaded )
PendingFilter = Schedule ( perform ) ;
else
perform ( ) ;
}
2018-04-13 09:19:50 +00:00
void perform ( )
{
2018-07-18 01:12:14 +00:00
PendingFilter = null ;
2018-04-13 09:19:50 +00:00
root . Filter ( activeCriteria ) ;
itemsCache . Invalidate ( ) ;
2020-03-13 02:51:26 +00:00
2020-11-26 09:28:52 +00:00
if ( alwaysResetScrollPosition | | ! Scroll . UserScrolling )
2020-11-27 04:54:36 +00:00
ScrollToSelected ( true ) ;
2018-04-13 09:19:50 +00:00
}
}
private float? scrollTarget ;
2020-03-13 02:51:26 +00:00
/// <summary>
/// Scroll to the current <see cref="SelectedBeatmap"/>.
/// </summary>
2020-11-27 04:54:36 +00:00
/// <param name="immediate">
/// Whether the scroll position should immediately be shifted to the target, delegating animation to visible panels.
/// This should be true for operations like filtering - where panels are changing visibility state - to avoid large jumps in animation.
/// </param>
public void ScrollToSelected ( bool immediate = false ) = >
pendingScrollOperation = immediate ? PendingScrollOperation . Immediate : PendingScrollOperation . Standard ;
2018-04-13 09:19:50 +00:00
2020-06-25 10:47:23 +00:00
#region Key / button selection logic
2018-10-02 03:02:47 +00:00
protected override bool OnKeyDown ( KeyDownEvent e )
2018-04-13 09:19:50 +00:00
{
2018-10-02 03:02:47 +00:00
switch ( e . Key )
2018-04-13 09:19:50 +00:00
{
case Key . Left :
2020-06-25 10:47:23 +00:00
if ( ! e . Repeat )
2020-11-27 04:54:36 +00:00
beginRepeatSelection ( ( ) = > SelectNext ( - 1 ) , e . Key ) ;
2020-03-02 09:55:28 +00:00
return true ;
2019-04-01 03:16:05 +00:00
2018-04-13 09:19:50 +00:00
case Key . Right :
2020-06-25 10:47:23 +00:00
if ( ! e . Repeat )
2020-11-27 04:54:36 +00:00
beginRepeatSelection ( ( ) = > SelectNext ( ) , e . Key ) ;
2020-03-02 09:55:28 +00:00
return true ;
}
return false ;
}
2020-06-25 10:47:23 +00:00
protected override void OnKeyUp ( KeyUpEvent e )
{
switch ( e . Key )
{
case Key . Left :
case Key . Right :
endRepeatSelection ( e . Key ) ;
break ;
}
base . OnKeyUp ( e ) ;
}
2021-09-16 09:26:12 +00:00
public bool OnPressed ( KeyBindingPressEvent < GlobalAction > e )
2020-03-02 09:55:28 +00:00
{
2021-09-16 09:26:12 +00:00
switch ( e . Action )
2020-03-02 09:55:28 +00:00
{
case GlobalAction . SelectNext :
2021-09-16 09:26:12 +00:00
beginRepeatSelection ( ( ) = > SelectNext ( 1 , false ) , e . Action ) ;
2020-03-02 09:55:28 +00:00
return true ;
case GlobalAction . SelectPrevious :
2021-09-16 09:26:12 +00:00
beginRepeatSelection ( ( ) = > SelectNext ( - 1 , false ) , e . Action ) ;
2020-03-02 09:55:28 +00:00
return true ;
2018-04-13 09:19:50 +00:00
}
2020-03-02 09:55:28 +00:00
return false ;
}
2018-04-13 09:19:50 +00:00
2021-09-16 09:26:12 +00:00
public void OnReleased ( KeyBindingReleaseEvent < GlobalAction > e )
2020-03-02 09:55:28 +00:00
{
2021-09-16 09:26:12 +00:00
switch ( e . Action )
2020-06-25 10:47:23 +00:00
{
case GlobalAction . SelectNext :
case GlobalAction . SelectPrevious :
2021-09-16 09:26:12 +00:00
endRepeatSelection ( e . Action ) ;
2020-06-25 10:47:23 +00:00
break ;
}
2018-04-13 09:19:50 +00:00
}
2020-06-25 10:47:23 +00:00
private ScheduledDelegate repeatDelegate ;
private object lastRepeatSource ;
/// <summary>
/// Begin repeating the specified selection action.
/// </summary>
/// <param name="action">The action to perform.</param>
/// <param name="source">The source of the action. Used in conjunction with <see cref="endRepeatSelection"/> to only cancel the correct action (most recently pressed key).</param>
private void beginRepeatSelection ( Action action , object source )
{
endRepeatSelection ( ) ;
lastRepeatSource = source ;
2020-06-26 11:14:08 +00:00
repeatDelegate = this . BeginKeyRepeat ( Scheduler , action ) ;
2020-06-25 10:47:23 +00:00
}
private void endRepeatSelection ( object source = null )
{
// only the most recent source should be able to cancel the current action.
if ( source ! = null & & ! EqualityComparer < object > . Default . Equals ( lastRepeatSource , source ) )
return ;
repeatDelegate ? . Cancel ( ) ;
repeatDelegate = null ;
lastRepeatSource = null ;
}
#endregion
2021-01-02 13:05:41 +00:00
protected override bool OnInvalidate ( Invalidation invalidation , InvalidationSource source )
{
// handles the vertical size of the carousel changing (ie. on window resize when aspect ratio has changed).
if ( ( invalidation & Invalidation . Layout ) > 0 )
itemsCache . Invalidate ( ) ;
return base . OnInvalidate ( invalidation , source ) ;
}
2018-04-13 09:19:50 +00:00
protected override void Update ( )
{
base . Update ( ) ;
2020-10-12 05:46:51 +00:00
bool revalidateItems = ! itemsCache . IsValid ;
2020-10-13 04:44:32 +00:00
// First we iterate over all non-filtered carousel items and populate their
// vertical position data.
2020-10-12 05:46:51 +00:00
if ( revalidateItems )
2020-10-12 10:55:17 +00:00
updateYPositions ( ) ;
2018-04-13 09:19:50 +00:00
2020-11-26 09:42:51 +00:00
// if there is a pending scroll action we apply it without animation and transfer the difference in position to the panels.
2020-11-27 04:54:36 +00:00
// this is intentionally applied before updating the visible range below, to avoid animating new items (sourced from pool) from locations off-screen, as it looks bad.
if ( pendingScrollOperation ! = PendingScrollOperation . None )
2020-11-26 09:33:37 +00:00
updateScrollPosition ( ) ;
2020-10-13 04:44:32 +00:00
// This data is consumed to find the currently displayable range.
// This is the range we want to keep drawables for, and should exceed the visible range slightly to avoid drawable churn.
var newDisplayRange = getDisplayRange ( ) ;
2020-10-12 10:12:00 +00:00
2020-10-13 04:44:32 +00:00
// If the filtered items or visible range has changed, pooling requirements need to be checked.
// This involves fetching new items from the pool, returning no-longer required items.
if ( revalidateItems | | newDisplayRange ! = displayedRange )
2020-10-12 05:46:51 +00:00
{
2020-10-13 04:44:32 +00:00
displayedRange = newDisplayRange ;
2018-04-13 09:19:50 +00:00
2020-10-19 10:55:20 +00:00
if ( visibleItems . Count > 0 )
2018-04-13 09:19:50 +00:00
{
2020-10-19 10:55:20 +00:00
var toDisplay = visibleItems . GetRange ( displayedRange . first , displayedRange . last - displayedRange . first + 1 ) ;
2020-10-12 06:36:03 +00:00
2020-11-26 09:28:52 +00:00
foreach ( var panel in Scroll . Children )
2020-10-13 05:23:29 +00:00
{
2020-10-19 10:55:20 +00:00
if ( toDisplay . Remove ( panel . Item ) )
{
// panel already displayed.
continue ;
}
// panel loaded as drawable but not required by visible range.
// remove but only if too far off-screen
if ( panel . Y + panel . DrawHeight < visibleUpperBound - distance_offscreen_before_unload | | panel . Y > visibleBottomBound + distance_offscreen_before_unload )
{
// may want a fade effect here (could be seen if a huge change happens, like a set with 20 difficulties becomes selected).
panel . ClearTransforms ( ) ;
panel . Expire ( ) ;
}
2020-10-13 05:23:29 +00:00
}
2018-04-13 09:19:50 +00:00
2020-10-19 10:55:20 +00:00
// Add those items within the previously found index range that should be displayed.
foreach ( var item in toDisplay )
{
var panel = setPool . Get ( p = > p . Item = item ) ;
2020-10-13 04:51:27 +00:00
2020-10-19 10:55:20 +00:00
panel . Depth = item . CarouselYPosition ;
panel . Y = item . CarouselYPosition ;
2020-10-13 04:51:27 +00:00
2020-11-26 09:28:52 +00:00
Scroll . Add ( panel ) ;
2020-10-19 10:55:20 +00:00
}
2020-10-13 04:44:32 +00:00
}
}
2020-10-12 05:46:51 +00:00
2020-10-13 04:44:32 +00:00
// Update externally controlled state of currently visible items (e.g. x-offset and opacity).
// This is a per-frame update on all drawable panels.
2020-11-26 09:28:52 +00:00
foreach ( DrawableCarouselItem item in Scroll . Children )
2020-10-13 04:44:32 +00:00
{
2020-10-13 05:37:44 +00:00
updateItem ( item ) ;
if ( item is DrawableCarouselBeatmapSet set )
{
2020-10-13 10:15:56 +00:00
foreach ( var diff in set . DrawableBeatmaps )
2020-10-13 05:37:44 +00:00
updateItem ( diff , item ) ;
}
2020-10-13 04:44:32 +00:00
}
2018-04-13 09:19:50 +00:00
}
2020-10-13 09:33:31 +00:00
private readonly CarouselBoundsItem carouselBoundsItem = new CarouselBoundsItem ( ) ;
2020-10-13 04:21:21 +00:00
private ( int firstIndex , int lastIndex ) getDisplayRange ( )
{
// Find index range of all items that should be on-screen
2020-10-13 09:33:31 +00:00
carouselBoundsItem . CarouselYPosition = visibleUpperBound - distance_offscreen_to_preload ;
int firstIndex = visibleItems . BinarySearch ( carouselBoundsItem ) ;
2020-10-13 04:21:21 +00:00
if ( firstIndex < 0 ) firstIndex = ~ firstIndex ;
2020-10-13 09:33:31 +00:00
carouselBoundsItem . CarouselYPosition = visibleBottomBound + distance_offscreen_to_preload ;
int lastIndex = visibleItems . BinarySearch ( carouselBoundsItem ) ;
2020-10-13 04:21:21 +00:00
if ( lastIndex < 0 ) lastIndex = ~ lastIndex ;
// as we can't be 100% sure on the size of individual carousel drawables,
// always play it safe and extend bounds by one.
firstIndex = Math . Max ( 0 , firstIndex - 1 ) ;
2020-10-19 10:10:01 +00:00
lastIndex = Math . Clamp ( lastIndex + 1 , firstIndex , Math . Max ( 0 , visibleItems . Count - 1 ) ) ;
2020-10-13 09:33:31 +00:00
2020-10-13 04:21:21 +00:00
return ( firstIndex , lastIndex ) ;
}
2020-05-19 07:44:22 +00:00
private void beatmapRemoved ( ValueChangedEvent < WeakReference < BeatmapSetInfo > > weakItem )
{
if ( weakItem . NewValue . TryGetTarget ( out var item ) )
RemoveBeatmapSet ( item ) ;
}
2020-01-29 07:51:14 +00:00
2020-05-27 07:08:47 +00:00
private void beatmapUpdated ( ValueChangedEvent < WeakReference < BeatmapSetInfo > > weakItem )
2020-05-19 07:44:22 +00:00
{
if ( weakItem . NewValue . TryGetTarget ( out var item ) )
UpdateBeatmapSet ( item ) ;
}
2020-01-29 07:51:14 +00:00
2020-05-19 07:44:22 +00:00
private void beatmapRestored ( ValueChangedEvent < WeakReference < BeatmapInfo > > weakItem )
{
if ( weakItem . NewValue . TryGetTarget ( out var b ) )
UpdateBeatmapSet ( beatmaps . QueryBeatmapSet ( s = > s . ID = = b . BeatmapSetInfoID ) ) ;
}
2020-01-29 07:51:14 +00:00
2020-05-19 07:44:22 +00:00
private void beatmapHidden ( ValueChangedEvent < WeakReference < BeatmapInfo > > weakItem )
{
if ( weakItem . NewValue . TryGetTarget ( out var b ) )
UpdateBeatmapSet ( beatmaps . QueryBeatmapSet ( s = > s . ID = = b . BeatmapSetInfoID ) ) ;
}
2020-01-29 07:51:14 +00:00
2018-04-13 09:19:50 +00:00
private CarouselBeatmapSet createCarouselSet ( BeatmapSetInfo beatmapSet )
{
if ( beatmapSet . Beatmaps . All ( b = > b . Hidden ) )
return null ;
// todo: remove the need for this.
foreach ( var b in beatmapSet . Beatmaps )
2020-06-03 07:48:44 +00:00
b . Metadata ? ? = beatmapSet . Metadata ;
2018-04-13 09:19:50 +00:00
2020-04-11 07:58:13 +00:00
var set = new CarouselBeatmapSet ( beatmapSet )
2020-04-09 15:47:28 +00:00
{
2020-04-11 07:58:13 +00:00
GetRecommendedBeatmap = beatmaps = > GetRecommendedBeatmap ? . Invoke ( beatmaps )
} ;
2018-04-13 09:19:50 +00:00
foreach ( var c in set . Beatmaps )
{
2019-02-22 08:51:39 +00:00
c . State . ValueChanged + = state = >
2018-04-13 09:19:50 +00:00
{
2019-02-22 08:51:39 +00:00
if ( state . NewValue = = CarouselItemState . Selected )
2018-04-13 09:19:50 +00:00
{
selectedBeatmapSet = set ;
SelectionChanged ? . Invoke ( c . Beatmap ) ;
itemsCache . Invalidate ( ) ;
2020-03-13 02:51:26 +00:00
ScrollToSelected ( ) ;
2018-04-13 09:19:50 +00:00
}
} ;
}
return set ;
}
2020-10-12 09:11:41 +00:00
private const float panel_padding = 5 ;
2018-04-13 09:19:50 +00:00
/// <summary>
/// Computes the target Y positions for every item in the carousel.
/// </summary>
/// <returns>The Y position of the currently selected item.</returns>
2020-10-12 10:55:17 +00:00
private void updateYPositions ( )
2018-04-13 09:19:50 +00:00
{
2020-10-12 05:23:18 +00:00
visibleItems . Clear ( ) ;
2018-04-13 09:19:50 +00:00
2019-07-26 06:22:29 +00:00
float currentY = visibleHalfHeight ;
2018-04-13 09:19:50 +00:00
scrollTarget = null ;
2020-10-12 05:23:18 +00:00
foreach ( CarouselItem item in root . Children )
2018-04-13 09:19:50 +00:00
{
2020-10-12 05:23:18 +00:00
if ( item . Filtered . Value )
continue ;
switch ( item )
2018-04-13 09:19:50 +00:00
{
2020-10-12 05:23:18 +00:00
case CarouselBeatmapSet set :
2018-04-13 09:19:50 +00:00
{
2020-10-12 05:23:18 +00:00
visibleItems . Add ( set ) ;
2020-10-13 04:21:21 +00:00
set . CarouselYPosition = currentY ;
2020-10-12 05:23:18 +00:00
2020-10-12 09:32:29 +00:00
if ( item . State . Value = = CarouselItemState . Selected )
{
// scroll position at currentY makes the set panel appear at the very top of the carousel's screen space
// move down by half of visible height (height of the carousel's visible extent, including semi-transparent areas)
// then reapply the top semi-transparent area (because carousel's screen space starts below it)
scrollTarget = currentY + DrawableCarouselBeatmapSet . HEIGHT - visibleHalfHeight + BleedTop ;
foreach ( var b in set . Beatmaps )
{
2020-10-12 11:02:45 +00:00
if ( ! b . Visible )
continue ;
2020-10-12 09:32:29 +00:00
if ( b . State . Value = = CarouselItemState . Selected )
{
scrollTarget + = b . TotalHeight / 2 ;
break ;
}
2020-10-13 09:13:36 +00:00
scrollTarget + = b . TotalHeight ;
2020-10-12 09:32:29 +00:00
}
}
2020-10-12 09:11:41 +00:00
currentY + = set . TotalHeight + panel_padding ;
2020-10-12 05:23:18 +00:00
break ;
2018-04-13 09:19:50 +00:00
}
2020-10-12 05:23:18 +00:00
}
2018-04-13 09:19:50 +00:00
}
2019-07-26 06:22:29 +00:00
currentY + = visibleHalfHeight ;
2020-11-26 09:28:52 +00:00
Scroll . ScrollContent . Height = currentY ;
2018-04-13 09:19:50 +00:00
2021-01-03 03:53:25 +00:00
itemsCache . Validate ( ) ;
// update and let external consumers know about selection loss.
if ( BeatmapSetsLoaded )
2018-04-13 09:19:50 +00:00
{
2021-01-03 03:53:25 +00:00
bool selectionLost = selectedBeatmapSet ! = null & & selectedBeatmapSet . State . Value ! = CarouselItemState . Selected ;
2018-04-13 09:19:50 +00:00
2021-01-03 13:44:30 +00:00
if ( selectionLost )
2021-01-03 03:53:25 +00:00
{
selectedBeatmapSet = null ;
SelectionChanged ? . Invoke ( null ) ;
}
}
2018-04-13 09:19:50 +00:00
}
2019-11-22 01:51:49 +00:00
private bool firstScroll = true ;
2018-04-13 09:19:50 +00:00
private void updateScrollPosition ( )
{
2019-11-20 10:38:39 +00:00
if ( scrollTarget ! = null )
{
2019-11-22 01:51:49 +00:00
if ( firstScroll )
{
// reduce movement when first displaying the carousel.
2020-11-26 09:28:52 +00:00
Scroll . ScrollTo ( scrollTarget . Value - 200 , false ) ;
2019-11-22 01:51:49 +00:00
firstScroll = false ;
}
2020-11-27 04:54:36 +00:00
switch ( pendingScrollOperation )
{
case PendingScrollOperation . Standard :
Scroll . ScrollTo ( scrollTarget . Value ) ;
break ;
case PendingScrollOperation . Immediate :
2021-01-03 03:53:25 +00:00
2020-11-27 04:54:36 +00:00
// in order to simplify animation logic, rather than using the animated version of ScrollTo,
// we take the difference in scroll height and apply to all visible panels.
// this avoids edge cases like when the visible panels is reduced suddenly, causing ScrollContainer
// to enter clamp-special-case mode where it animates completely differently to normal.
float scrollChange = scrollTarget . Value - Scroll . Current ;
Scroll . ScrollTo ( scrollTarget . Value , false ) ;
foreach ( var i in Scroll . Children )
i . Y + = scrollChange ;
break ;
}
2020-11-26 09:42:51 +00:00
2020-11-27 04:54:36 +00:00
pendingScrollOperation = PendingScrollOperation . None ;
2019-11-20 10:38:39 +00:00
}
2018-04-13 09:19:50 +00:00
}
/// <summary>
/// Computes the x-offset of currently visible items. Makes the carousel appear round.
/// </summary>
/// <param name="dist">
/// Vertical distance from the center of the carousel container
/// ranging from -1 to 1.
/// </param>
/// <param name="halfHeight">Half the height of the carousel container.</param>
private static float offsetX ( float dist , float halfHeight )
{
// The radius of the circle the carousel moves on.
const float circle_radius = 3 ;
2019-11-24 23:45:42 +00:00
float discriminant = MathF . Max ( 0 , circle_radius * circle_radius - dist * dist ) ;
float x = ( circle_radius - MathF . Sqrt ( discriminant ) ) * halfHeight ;
2018-04-13 09:19:50 +00:00
return 125 + x ;
}
/// <summary>
/// Update a item's x position and multiplicative alpha based on its y position and
/// the current scroll position.
/// </summary>
2020-10-13 05:37:44 +00:00
/// <param name="item">The item to be updated.</param>
/// <param name="parent">For nested items, the parent of the item to be updated.</param>
private void updateItem ( DrawableCarouselItem item , DrawableCarouselItem parent = null )
2018-04-13 09:19:50 +00:00
{
2020-11-26 09:28:52 +00:00
Vector2 posInScroll = Scroll . ScrollContent . ToLocalSpace ( item . Header . ScreenSpaceDrawQuad . Centre ) ;
2020-10-13 05:37:44 +00:00
float itemDrawY = posInScroll . Y - visibleUpperBound ;
2019-07-26 06:22:29 +00:00
float dist = Math . Abs ( 1f - itemDrawY / visibleHalfHeight ) ;
2018-04-13 09:19:50 +00:00
2020-10-13 08:33:35 +00:00
// adjusting the item's overall X position can cause it to become masked away when
// child items (difficulties) are still visible.
item . Header . X = offsetX ( dist , visibleHalfHeight ) - ( parent ? . X ? ? 0 ) ;
2018-04-13 09:19:50 +00:00
// We are applying a multiplicative alpha (which is internally done by nesting an
// additional container and setting that container's alpha) such that we can
2020-10-13 05:37:44 +00:00
// layer alpha transformations on top.
item . SetMultiplicativeAlpha ( Math . Clamp ( 1.75f - 1.5f * dist , 0 , 1 ) ) ;
2018-04-13 09:19:50 +00:00
}
2020-11-27 04:54:36 +00:00
private enum PendingScrollOperation
{
None ,
Standard ,
Immediate ,
}
2020-10-13 04:21:21 +00:00
/// <summary>
/// A carousel item strictly used for binary search purposes.
/// </summary>
private class CarouselBoundsItem : CarouselItem
{
public override DrawableCarouselItem CreateDrawableRepresentation ( ) = >
throw new NotImplementedException ( ) ;
}
2018-04-13 09:19:50 +00:00
private class CarouselRoot : CarouselGroupEagerSelect
{
private readonly BeatmapCarousel carousel ;
public CarouselRoot ( BeatmapCarousel carousel )
{
2020-03-21 15:32:53 +00:00
// root should always remain selected. if not, PerformSelection will not be called.
2020-03-20 06:01:26 +00:00
State . Value = CarouselItemState . Selected ;
State . ValueChanged + = state = > State . Value = CarouselItemState . Selected ;
2018-04-13 09:19:50 +00:00
this . carousel = carousel ;
}
protected override void PerformSelection ( )
{
2020-03-20 04:01:24 +00:00
if ( LastSelected = = null | | LastSelected . Filtered . Value )
2020-03-20 06:01:26 +00:00
carousel ? . SelectNextRandom ( ) ;
2018-04-13 09:19:50 +00:00
else
base . PerformSelection ( ) ;
}
}
2019-08-15 09:27:45 +00:00
2020-12-22 15:36:44 +00:00
protected class CarouselScrollContainer : UserTrackingScrollContainer < DrawableCarouselItem >
2019-08-15 09:27:45 +00:00
{
private bool rightMouseScrollBlocked ;
2020-11-26 09:28:52 +00:00
public CarouselScrollContainer ( )
{
// size is determined by the carousel itself, due to not all content necessarily being loaded.
ScrollContent . AutoSizeAxes = Axes . None ;
2020-12-03 04:26:28 +00:00
// the scroll container may get pushed off-screen by global screen changes, but we still want panels to display outside of the bounds.
Masking = false ;
2020-11-26 09:28:52 +00:00
}
2019-08-15 09:27:45 +00:00
protected override bool OnMouseDown ( MouseDownEvent e )
{
if ( e . Button = = MouseButton . Right )
{
// we need to block right click absolute scrolling when hovering a carousel item so context menus can display.
// this can be reconsidered when we have an alternative to right click scrolling.
if ( GetContainingInputManager ( ) . HoveredDrawables . OfType < DrawableCarouselItem > ( ) . Any ( ) )
{
rightMouseScrollBlocked = true ;
return false ;
}
}
2019-08-15 10:25:33 +00:00
rightMouseScrollBlocked = false ;
2019-08-15 09:27:45 +00:00
return base . OnMouseDown ( e ) ;
}
protected override bool OnDragStart ( DragStartEvent e )
{
if ( rightMouseScrollBlocked )
return false ;
return base . OnDragStart ( e ) ;
}
}
2018-04-13 09:19:50 +00:00
}
}