2019-01-24 16:43:03 +08: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 17:19:50 +08:00
2022-06-20 13:56:04 +08:00
using System ;
2019-10-28 13:44:45 +08:00
using osu.Framework.Bindables ;
2017-12-23 15:46:02 +08:00
using osu.Game.Audio ;
2020-10-01 18:29:34 +08:00
using osu.Game.Graphics ;
using osuTK.Graphics ;
2018-04-13 17:19:50 +08:00
2017-05-23 12:55:18 +08:00
namespace osu.Game.Beatmaps.ControlPoints
{
2021-08-31 22:59:36 +08:00
/// <remarks>
/// Note that going forward, this control point type should always be assigned directly to HitObjects.
/// </remarks>
2022-06-20 13:56:04 +08:00
public class SampleControlPoint : ControlPoint , IEquatable < SampleControlPoint >
2017-05-23 12:55:18 +08:00
{
2017-12-21 15:02:33 +08:00
public const string DEFAULT_BANK = "normal" ;
2018-04-13 17:19:50 +08:00
2020-07-19 13:11:21 +08:00
public static readonly SampleControlPoint DEFAULT = new SampleControlPoint
{
SampleBankBindable = { Disabled = true } ,
SampleVolumeBindable = { Disabled = true }
} ;
2020-10-01 18:29:34 +08:00
public override Color4 GetRepresentingColour ( OsuColour colours ) = > colours . Pink ;
2017-05-23 13:11:37 +08:00
/// <summary>
/// The default sample bank at this control point.
/// </summary>
2019-10-28 15:21:14 +08:00
public readonly Bindable < string > SampleBankBindable = new Bindable < string > ( DEFAULT_BANK ) { Default = DEFAULT_BANK } ;
2019-10-28 13:44:45 +08:00
/// <summary>
2023-04-25 18:54:45 +08:00
/// The default sample bank at this control point.
2019-10-28 13:44:45 +08:00
/// </summary>
public string SampleBank
{
get = > SampleBankBindable . Value ;
set = > SampleBankBindable . Value = value ;
}
/// <summary>
2023-04-25 18:54:45 +08:00
/// The default sample volume at this control point.
2019-10-28 13:44:45 +08:00
/// </summary>
public readonly BindableInt SampleVolumeBindable = new BindableInt ( 100 )
{
MinValue = 0 ,
2019-10-28 15:21:14 +08:00
MaxValue = 100 ,
2019-10-28 13:44:45 +08:00
} ;
2018-04-13 17:19:50 +08:00
2017-05-23 13:11:37 +08:00
/// <summary>
/// The default sample volume at this control point.
/// </summary>
2019-10-28 13:44:45 +08:00
public int SampleVolume
{
get = > SampleVolumeBindable . Value ;
set = > SampleVolumeBindable . Value = value ;
}
2018-04-13 17:19:50 +08:00
2017-12-23 15:46:02 +08:00
/// <summary>
/// Create a SampleInfo based on the sample settings in this control point.
/// </summary>
/// <param name="sampleName">The name of the same.</param>
2019-06-30 20:58:30 +08:00
/// <returns>A populated <see cref="HitSampleInfo"/>.</returns>
2020-12-01 14:37:51 +08:00
public HitSampleInfo GetSampleInfo ( string sampleName = HitSampleInfo . HIT_NORMAL ) = > new HitSampleInfo ( sampleName , SampleBank , volume : SampleVolume ) ;
2018-06-28 17:08:46 +08:00
2018-06-28 17:20:29 +08:00
/// <summary>
2019-06-30 20:58:30 +08:00
/// Applies <see cref="SampleBank"/> and <see cref="SampleVolume"/> to a <see cref="HitSampleInfo"/> if necessary, returning the modified <see cref="HitSampleInfo"/>.
2018-06-28 17:20:29 +08:00
/// </summary>
2019-06-30 20:58:30 +08:00
/// <param name="hitSampleInfo">The <see cref="HitSampleInfo"/>. This will not be modified.</param>
/// <returns>The modified <see cref="HitSampleInfo"/>. This does not share a reference with <paramref name="hitSampleInfo"/>.</returns>
public virtual HitSampleInfo ApplyTo ( HitSampleInfo hitSampleInfo )
2020-12-02 09:55:48 +08:00
= > hitSampleInfo . With ( newBank : hitSampleInfo . Bank ? ? SampleBank , newVolume : hitSampleInfo . Volume > 0 ? hitSampleInfo . Volume : SampleVolume ) ;
2018-06-28 17:20:29 +08:00
2022-06-20 15:52:01 +08:00
public override bool IsRedundant ( ControlPoint ? existing )
2020-04-17 16:04:09 +08:00
= > existing is SampleControlPoint existingSample
& & SampleBank = = existingSample . SampleBank
& & SampleVolume = = existingSample . SampleVolume ;
2021-01-04 15:37:07 +08:00
public override void CopyFrom ( ControlPoint other )
{
SampleVolume = ( ( SampleControlPoint ) other ) . SampleVolume ;
SampleBank = ( ( SampleControlPoint ) other ) . SampleBank ;
base . CopyFrom ( other ) ;
}
2022-06-20 13:56:04 +08:00
public override bool Equals ( ControlPoint ? other )
= > other is SampleControlPoint otherSampleControlPoint
& & Equals ( otherSampleControlPoint ) ;
public bool Equals ( SampleControlPoint ? other )
= > base . Equals ( other )
& & SampleBank = = other . SampleBank
& & SampleVolume = = other . SampleVolume ;
public override int GetHashCode ( ) = > HashCode . Combine ( base . GetHashCode ( ) , SampleBank , SampleVolume ) ;
2017-05-23 12:55:18 +08:00
}
2017-12-21 15:02:33 +08:00
}