2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation ;
using osu.Framework.Configuration ;
using osu.Framework.Graphics ;
2018-05-31 11:06:50 +08:00
using osu.Framework.Input.Bindings ;
2018-09-20 00:30:25 +08:00
using osu.Game.Configuration ;
2018-05-31 11:06:50 +08:00
using osu.Game.Input.Bindings ;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Drawables ;
namespace osu.Game.Rulesets.UI.Scrolling
{
/// <summary>
/// A type of <see cref="Playfield"/> specialized towards scrolling <see cref="DrawableHitObject"/>s.
/// </summary>
2018-05-31 11:06:50 +08:00
public abstract class ScrollingPlayfield : Playfield , IKeyBindingHandler < GlobalAction >
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// The default span of time visible by the length of the scrolling axes.
/// This is clamped between <see cref="time_span_min"/> and <see cref="time_span_max"/>.
/// </summary>
private const double time_span_default = 1500 ;
2018-05-31 11:06:50 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The minimum span of time that may be visible by the length of the scrolling axes.
/// </summary>
private const double time_span_min = 50 ;
2018-05-31 11:06:50 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The maximum span of time that may be visible by the length of the scrolling axes.
/// </summary>
private const double time_span_max = 10000 ;
2018-05-31 11:06:50 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The step increase/decrease of the span of time visible by the length of the scrolling axes.
/// </summary>
2018-06-12 17:03:45 +08:00
private const double time_span_step = 200 ;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The span of time that is visible by the length of the scrolling axes.
/// For example, only hit objects with start time less than or equal to 1000 will be visible with <see cref="VisibleTimeRange"/> = 1000.
/// </summary>
public readonly BindableDouble VisibleTimeRange = new BindableDouble ( time_span_default )
{
Default = time_span_default ,
MinValue = time_span_min ,
MaxValue = time_span_max
} ;
/// <summary>
/// Whether the player can change <see cref="VisibleTimeRange"/>.
/// </summary>
protected virtual bool UserScrollSpeedAdjustment = > true ;
/// <summary>
/// The container that contains the <see cref="DrawableHitObject"/>s.
/// </summary>
2018-08-30 12:30:23 +08:00
public new ScrollingHitObjectContainer HitObjects = > ( ScrollingHitObjectContainer ) HitObjectContainer ;
2018-04-13 17:19:50 +08:00
2018-07-17 14:14:03 +08:00
/// <summary>
/// The direction in which <see cref="DrawableHitObject"/>s in this <see cref="ScrollingPlayfield"/> should scroll.
/// </summary>
2018-06-11 13:36:19 +08:00
protected readonly Bindable < ScrollingDirection > Direction = new Bindable < ScrollingDirection > ( ) ;
2018-04-13 17:19:50 +08:00
2018-09-20 00:30:25 +08:00
protected virtual SpeedChangeVisualisationMethod visualisationMethod = > SpeedChangeVisualisationMethod . Sequential ;
2018-04-13 17:19:50 +08:00
/// <summary>
/// Creates a new <see cref="ScrollingPlayfield"/>.
/// </summary>
/// <param name="customWidth">The width to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customHeight"/> is desired. If <paramref name="customHeight"/> is also null, no scaling will occur.
/// </param>
/// <param name="customHeight">The height to scale the internal coordinate space to.
/// May be null if scaling based on <paramref name="customWidth"/> is desired. If <paramref name="customWidth"/> is also null, no scaling will occur.
/// </param>
2018-07-17 14:14:03 +08:00
protected ScrollingPlayfield ( float? customWidth = null , float? customHeight = null )
2018-04-13 17:19:50 +08:00
: base ( customWidth , customHeight )
{
}
[BackgroundDependencyLoader]
private void load ( )
{
HitObjects . TimeRange . BindTo ( VisibleTimeRange ) ;
}
2018-05-31 11:06:50 +08:00
public bool OnPressed ( GlobalAction action )
2018-04-13 17:19:50 +08:00
{
if ( ! UserScrollSpeedAdjustment )
return false ;
2018-05-31 11:06:50 +08:00
switch ( action )
2018-04-13 17:19:50 +08:00
{
2018-05-31 11:06:50 +08:00
case GlobalAction . IncreaseScrollSpeed :
this . TransformBindableTo ( VisibleTimeRange , VisibleTimeRange - time_span_step , 200 , Easing . OutQuint ) ;
return true ;
case GlobalAction . DecreaseScrollSpeed :
this . TransformBindableTo ( VisibleTimeRange , VisibleTimeRange + time_span_step , 200 , Easing . OutQuint ) ;
return true ;
2018-04-13 17:19:50 +08:00
}
return false ;
}
2018-05-31 11:06:50 +08:00
public bool OnReleased ( GlobalAction action ) = > false ;
2018-07-02 16:21:18 +08:00
2018-06-11 13:36:19 +08:00
protected sealed override HitObjectContainer CreateHitObjectContainer ( )
{
2018-09-20 00:30:25 +08:00
var container = new ScrollingHitObjectContainer ( visualisationMethod ) ;
2018-06-11 13:36:19 +08:00
container . Direction . BindTo ( Direction ) ;
return container ;
}
2018-04-13 17:19:50 +08:00
}
}