Fixed DifficultyPointPiece

This commit is contained in:
OliBomby
2023-04-25 18:12:53 +02:00
parent ebe1d852f5
commit 065464d90c
7 changed files with 90 additions and 82 deletions

View File

@ -11,6 +11,7 @@ using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Game.Audio;
using osu.Game.Beatmaps;
@ -135,7 +136,13 @@ namespace osu.Game.Rulesets.Osu.Objects
/// </summary>
public bool OnlyJudgeNestedObjects = true;
public double SliderVelocity { get; set; } = 1;
public BindableDouble SliderVelocityBindable = new BindableDouble(1);
public double SliderVelocity
{
get => SliderVelocityBindable.Value;
set => SliderVelocityBindable.Value = value;
}
[JsonIgnore]
public SliderHeadCircle HeadCircle { get; protected set; }

View File

@ -6,6 +6,7 @@
using osu.Game.Rulesets.Objects.Types;
using System.Collections.Generic;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
@ -40,7 +41,13 @@ namespace osu.Game.Rulesets.Objects.Legacy
public double Velocity = 1;
public double SliderVelocity { get; set; } = 1;
public BindableDouble SliderVelocityBindable = new BindableDouble(1);
public double SliderVelocity
{
get => SliderVelocityBindable.Value;
set => SliderVelocityBindable.Value = value;
}
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
{

View File

@ -1,6 +1,8 @@
// 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.
using osu.Framework.Bindables;
namespace osu.Game.Rulesets.Objects.Types;
/// <summary>
@ -12,4 +14,6 @@ public interface IHasSliderVelocity
/// The slider velocity multiplier.
/// </summary>
double SliderVelocity { get; set; }
BindableNumber<double> SliderVelocityBindable { get; }
}

View File

@ -13,12 +13,14 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Timing;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
@ -29,13 +31,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private readonly BindableNumber<double> speedMultiplier;
public DifficultyPointPiece(HitObject hitObject)
: base(hitObject.DifficultyControlPoint)
{
HitObject = hitObject;
speedMultiplier = hitObject.DifficultyControlPoint.SliderVelocityBindable.GetBoundCopy();
speedMultiplier = (hitObject as IHasSliderVelocity)?.SliderVelocityBindable.GetBoundCopy();
}
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Lime1;
protected override void LoadComplete()
{
base.LoadComplete();
@ -78,7 +81,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
Spacing = new Vector2(0, 15),
Children = new Drawable[]
{
sliderVelocitySlider = new IndeterminateSliderWithTextBoxInput<double>("Velocity", new DifficultyControlPoint().SliderVelocityBindable)
sliderVelocitySlider = new IndeterminateSliderWithTextBoxInput<double>("Velocity", new BindableDouble(1)
{
Precision = 0.01,
MinValue = 0.1,
MaxValue = 10
})
{
KeyboardStep = 0.1f
},
@ -94,11 +102,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
// if the piece belongs to a currently selected object, assume that the user wants to change all selected objects.
// if the piece belongs to an unselected object, operate on that object alone, independently of the selection.
var relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).ToArray();
var relevantControlPoints = relevantObjects.Select(h => h.DifficultyControlPoint).ToArray();
var relevantObjects = (beatmap.SelectedHitObjects.Contains(hitObject) ? beatmap.SelectedHitObjects : hitObject.Yield()).Where(o => o is IHasSliderVelocity).ToArray();
// even if there are multiple objects selected, we can still display a value if they all have the same value.
var selectedPointBindable = relevantControlPoints.Select(point => point.SliderVelocity).Distinct().Count() == 1 ? relevantControlPoints.First().SliderVelocityBindable : null;
var selectedPointBindable = relevantObjects.Select(point => ((IHasSliderVelocity)point).SliderVelocity).Distinct().Count() == 1 ? ((IHasSliderVelocity)relevantObjects.First()).SliderVelocityBindable : null;
if (selectedPointBindable != null)
{
@ -117,7 +124,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
foreach (var h in relevantObjects)
{
h.DifficultyControlPoint.SliderVelocity = val.NewValue.Value;
((IHasSliderVelocity)h).SliderVelocity = val.NewValue.Value;
beatmap.Update(h);
}

View File

@ -7,59 +7,54 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
namespace osu.Game.Screens.Edit.Compose.Components.Timeline;
public partial class HitObjectPointPiece : CircularContainer
{
public partial class HitObjectPointPiece : CircularContainer
protected OsuSpriteText Label { get; private set; }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
private readonly ControlPoint point;
AutoSizeAxes = Axes.Both;
protected OsuSpriteText Label { get; private set; }
Color4 colour = GetRepresentingColour(colours);
protected HitObjectPointPiece(ControlPoint point)
InternalChildren = new Drawable[]
{
this.point = point;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AutoSizeAxes = Axes.Both;
Color4 colour = point.GetRepresentingColour(colours);
InternalChildren = new Drawable[]
new Container
{
new Container
AutoSizeAxes = Axes.X,
Height = 16,
Masking = true,
CornerRadius = 8,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]
{
AutoSizeAxes = Axes.X,
Height = 16,
Masking = true,
CornerRadius = 8,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new Drawable[]
new Box
{
new Box
{
Colour = colour,
RelativeSizeAxes = Axes.Both,
},
Label = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Padding = new MarginPadding(5),
Font = OsuFont.Default.With(size: 12, weight: FontWeight.SemiBold),
Colour = colours.B5,
}
Colour = colour,
RelativeSizeAxes = Axes.Both,
},
Label = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Padding = new MarginPadding(5),
Font = OsuFont.Default.With(size: 12, weight: FontWeight.SemiBold),
Colour = colours.B5,
}
},
};
}
}
},
};
protected virtual Color4 GetRepresentingColour(OsuColour colours)
{
return colours.Yellow;
}
}

View File

@ -13,10 +13,12 @@ using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit.Timing;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
@ -28,13 +30,14 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
private readonly BindableNumber<int> volume;
public SamplePointPiece(HitObject hitObject)
: base(hitObject.SampleControlPoint)
{
HitObject = hitObject;
volume = hitObject.SampleControlPoint.SampleVolumeBindable.GetBoundCopy();
bank = hitObject.SampleControlPoint.SampleBankBindable.GetBoundCopy();
}
protected override Color4 GetRepresentingColour(OsuColour colours) => colours.Pink;
[BackgroundDependencyLoader]
private void load()
{

View File

@ -102,6 +102,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
},
}
},
sampleOverrideDisplay = new SamplePointPiece(Item)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopCentre
},
});
if (item is IHasDuration)
@ -111,6 +116,16 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
OnDragHandled = e => OnDragHandled?.Invoke(e)
});
}
if (item is IHasSliderVelocity)
{
AddInternal(difficultyOverrideDisplay = new DifficultyPointPiece(Item)
{
Anchor = Anchor.TopLeft,
Origin = Anchor.BottomCentre
}
);
}
}
protected override void LoadComplete()
@ -208,36 +223,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (Item is IHasRepeats repeats)
updateRepeats(repeats);
}
if (!ReferenceEquals(difficultyControlPoint, Item.DifficultyControlPoint))
{
difficultyControlPoint = Item.DifficultyControlPoint;
difficultyOverrideDisplay?.Expire();
if (Item.DifficultyControlPoint != null && Item is IHasDistance)
{
AddInternal(difficultyOverrideDisplay = new DifficultyPointPiece(Item)
{
Anchor = Anchor.TopLeft,
Origin = Anchor.BottomCentre
});
}
}
if (!ReferenceEquals(sampleControlPoint, Item.SampleControlPoint))
{
sampleControlPoint = Item.SampleControlPoint;
sampleOverrideDisplay?.Expire();
if (Item.SampleControlPoint != null)
{
AddInternal(sampleOverrideDisplay = new SamplePointPiece(Item)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopCentre
});
}
}
}
private void updateRepeats(IHasRepeats repeats)