Merge remote-tracking branch 'upstream/master' into make-most-textbox-carets-movable

This commit is contained in:
Dean Herbert 2019-10-22 15:04:16 +09:00
commit 001eae2c02
68 changed files with 2361 additions and 430 deletions

View File

@ -62,6 +62,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2019.1011.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2019.1021.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -16,6 +16,11 @@ namespace osu.Android
protected override void OnCreate(Bundle savedInstanceState) protected override void OnCreate(Bundle savedInstanceState)
{ {
// The default current directory on android is '/'.
// On some devices '/' maps to the app data directory. On others it maps to the root of the internal storage.
// In order to have a consistent current directory on all devices the full path of the app data directory is set as the current directory.
System.Environment.CurrentDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
Window.AddFlags(WindowManagerFlags.Fullscreen); Window.AddFlags(WindowManagerFlags.Fullscreen);

View File

@ -2,35 +2,50 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Catch.Objects.Drawable namespace osu.Game.Rulesets.Catch.Objects.Drawable
{ {
public class DrawableBananaShower : DrawableCatchHitObject<BananaShower> public class DrawableBananaShower : DrawableCatchHitObject<BananaShower>
{ {
private readonly Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation;
private readonly Container bananaContainer; private readonly Container bananaContainer;
public DrawableBananaShower(BananaShower s, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation = null) public DrawableBananaShower(BananaShower s, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation = null)
: base(s) : base(s)
{ {
this.createDrawableRepresentation = createDrawableRepresentation;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Origin = Anchor.BottomLeft; Origin = Anchor.BottomLeft;
X = 0; X = 0;
AddInternal(bananaContainer = new Container { RelativeSizeAxes = Axes.Both }); AddInternal(bananaContainer = new Container { RelativeSizeAxes = Axes.Both });
foreach (var b in s.NestedHitObjects.Cast<Banana>())
AddNested(createDrawableRepresentation?.Invoke(b));
} }
protected override void AddNested(DrawableHitObject h) protected override void AddNestedHitObject(DrawableHitObject hitObject)
{ {
((DrawableCatchHitObject)h).CheckPosition = o => CheckPosition?.Invoke(o) ?? false; base.AddNestedHitObject(hitObject);
bananaContainer.Add(h); bananaContainer.Add(hitObject);
base.AddNested(h); }
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
bananaContainer.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case Banana banana:
return createDrawableRepresentation?.Invoke(banana)?.With(o => ((DrawableCatchHitObject)o).CheckPosition = p => CheckPosition?.Invoke(p) ?? false);
}
return base.CreateNestedHitObject(hitObject);
} }
} }
} }

View File

@ -2,38 +2,50 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Catch.Objects.Drawable namespace osu.Game.Rulesets.Catch.Objects.Drawable
{ {
public class DrawableJuiceStream : DrawableCatchHitObject<JuiceStream> public class DrawableJuiceStream : DrawableCatchHitObject<JuiceStream>
{ {
private readonly Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation;
private readonly Container dropletContainer; private readonly Container dropletContainer;
public DrawableJuiceStream(JuiceStream s, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation = null) public DrawableJuiceStream(JuiceStream s, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> createDrawableRepresentation = null)
: base(s) : base(s)
{ {
this.createDrawableRepresentation = createDrawableRepresentation;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
Origin = Anchor.BottomLeft; Origin = Anchor.BottomLeft;
X = 0; X = 0;
AddInternal(dropletContainer = new Container { RelativeSizeAxes = Axes.Both, }); AddInternal(dropletContainer = new Container { RelativeSizeAxes = Axes.Both, });
foreach (var o in s.NestedHitObjects.Cast<CatchHitObject>())
AddNested(createDrawableRepresentation?.Invoke(o));
} }
protected override void AddNested(DrawableHitObject h) protected override void AddNestedHitObject(DrawableHitObject hitObject)
{ {
var catchObject = (DrawableCatchHitObject)h; base.AddNestedHitObject(hitObject);
dropletContainer.Add(hitObject);
}
catchObject.CheckPosition = o => CheckPosition?.Invoke(o) ?? false; protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
dropletContainer.Clear();
}
dropletContainer.Add(h); protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
base.AddNested(h); {
switch (hitObject)
{
case CatchHitObject catchObject:
return createDrawableRepresentation?.Invoke(catchObject)?.With(o => ((DrawableCatchHitObject)o).CheckPosition = p => CheckPosition?.Invoke(p) ?? false);
}
return base.CreateNestedHitObject(hitObject);
} }
} }
} }

View File

@ -16,45 +16,51 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
public class HoldNoteSelectionBlueprint : ManiaSelectionBlueprint public class HoldNoteSelectionBlueprint : ManiaSelectionBlueprint
{ {
public new DrawableHoldNote HitObject => (DrawableHoldNote)base.HitObject; public new DrawableHoldNote DrawableObject => (DrawableHoldNote)base.DrawableObject;
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>(); private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private readonly BodyPiece body; [Resolved]
private OsuColour colours { get; set; }
public HoldNoteSelectionBlueprint(DrawableHoldNote hold) public HoldNoteSelectionBlueprint(DrawableHoldNote hold)
: base(hold) : base(hold)
{ {
InternalChildren = new Drawable[]
{
new HoldNoteNoteSelectionBlueprint(hold.Head),
new HoldNoteNoteSelectionBlueprint(hold.Tail),
body = new BodyPiece
{
AccentColour = Color4.Transparent
},
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, IScrollingInfo scrollingInfo) private void load(IScrollingInfo scrollingInfo)
{ {
body.BorderColour = colours.Yellow;
direction.BindTo(scrollingInfo.Direction); direction.BindTo(scrollingInfo.Direction);
} }
protected override void LoadComplete()
{
base.LoadComplete();
InternalChildren = new Drawable[]
{
new HoldNoteNoteSelectionBlueprint(DrawableObject.Head),
new HoldNoteNoteSelectionBlueprint(DrawableObject.Tail),
new BodyPiece
{
AccentColour = Color4.Transparent,
BorderColour = colours.Yellow
},
};
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
Size = HitObject.DrawSize + new Vector2(0, HitObject.Tail.DrawHeight); Size = DrawableObject.DrawSize + new Vector2(0, DrawableObject.Tail.DrawHeight);
// This is a side-effect of not matching the hitobject's anchors/origins, which is kinda hard to do // This is a side-effect of not matching the hitobject's anchors/origins, which is kinda hard to do
// When scrolling upwards our origin is already at the top of the head note (which is the intended location), // When scrolling upwards our origin is already at the top of the head note (which is the intended location),
// but when scrolling downwards our origin is at the _bottom_ of the tail note (where we need to be at the _top_ of the tail note) // but when scrolling downwards our origin is at the _bottom_ of the tail note (where we need to be at the _top_ of the tail note)
if (direction.Value == ScrollingDirection.Down) if (direction.Value == ScrollingDirection.Down)
Y -= HitObject.Tail.DrawHeight; Y -= DrawableObject.Tail.DrawHeight;
} }
public override Quad SelectionQuad => ScreenSpaceDrawQuad; public override Quad SelectionQuad => ScreenSpaceDrawQuad;
@ -71,10 +77,10 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
base.Update(); base.Update();
Anchor = HitObject.Anchor; Anchor = DrawableObject.Anchor;
Origin = HitObject.Origin; Origin = DrawableObject.Origin;
Position = HitObject.DrawPosition; Position = DrawableObject.DrawPosition;
} }
// Todo: This is temporary, since the note masks don't do anything special yet. In the future they will handle input. // Todo: This is temporary, since the note masks don't do anything special yet. In the future they will handle input.

View File

@ -49,10 +49,8 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
if (Column == null) if (Column == null)
return base.OnMouseDown(e); return base.OnMouseDown(e);
HitObject.StartTime = TimeAt(e.ScreenSpaceMousePosition);
HitObject.Column = Column.Index; HitObject.Column = Column.Index;
BeginPlacement(TimeAt(e.ScreenSpaceMousePosition));
BeginPlacement();
return true; return true;
} }

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
public Vector2 ScreenSpaceDragPosition { get; private set; } public Vector2 ScreenSpaceDragPosition { get; private set; }
public Vector2 DragPosition { get; private set; } public Vector2 DragPosition { get; private set; }
public new DrawableManiaHitObject HitObject => (DrawableManiaHitObject)base.HitObject; public new DrawableManiaHitObject DrawableObject => (DrawableManiaHitObject)base.DrawableObject;
protected IClock EditorClock { get; private set; } protected IClock EditorClock { get; private set; }
@ -28,8 +28,8 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
[Resolved] [Resolved]
private IManiaHitObjectComposer composer { get; set; } private IManiaHitObjectComposer composer { get; set; }
public ManiaSelectionBlueprint(DrawableHitObject hitObject) public ManiaSelectionBlueprint(DrawableHitObject drawableObject)
: base(hitObject) : base(drawableObject)
{ {
RelativeSizeAxes = Axes.None; RelativeSizeAxes = Axes.None;
} }
@ -44,13 +44,13 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
base.Update(); base.Update();
Position = Parent.ToLocalSpace(HitObject.ToScreenSpace(Vector2.Zero)); Position = Parent.ToLocalSpace(DrawableObject.ToScreenSpace(Vector2.Zero));
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
ScreenSpaceDragPosition = e.ScreenSpaceMousePosition; ScreenSpaceDragPosition = e.ScreenSpaceMousePosition;
DragPosition = HitObject.ToLocalSpace(e.ScreenSpaceMousePosition); DragPosition = DrawableObject.ToLocalSpace(e.ScreenSpaceMousePosition);
return base.OnMouseDown(e); return base.OnMouseDown(e);
} }
@ -60,20 +60,20 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
var result = base.OnDrag(e); var result = base.OnDrag(e);
ScreenSpaceDragPosition = e.ScreenSpaceMousePosition; ScreenSpaceDragPosition = e.ScreenSpaceMousePosition;
DragPosition = HitObject.ToLocalSpace(e.ScreenSpaceMousePosition); DragPosition = DrawableObject.ToLocalSpace(e.ScreenSpaceMousePosition);
return result; return result;
} }
public override void Show() public override void Show()
{ {
HitObject.AlwaysAlive = true; DrawableObject.AlwaysAlive = true;
base.Show(); base.Show();
} }
public override void Hide() public override void Hide()
{ {
HitObject.AlwaysAlive = false; DrawableObject.AlwaysAlive = false;
base.Hide(); base.Hide();
} }
} }

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
{ {
base.Update(); base.Update();
Size = HitObject.DrawSize; Size = DrawableObject.DrawSize;
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Mania.Edit
public override void HandleMovement(MoveSelectionEvent moveEvent) public override void HandleMovement(MoveSelectionEvent moveEvent)
{ {
var maniaBlueprint = (ManiaSelectionBlueprint)moveEvent.Blueprint; var maniaBlueprint = (ManiaSelectionBlueprint)moveEvent.Blueprint;
int lastColumn = maniaBlueprint.HitObject.HitObject.Column; int lastColumn = maniaBlueprint.DrawableObject.HitObject.Column;
adjustOrigins(maniaBlueprint); adjustOrigins(maniaBlueprint);
performDragMovement(moveEvent); performDragMovement(moveEvent);
@ -48,41 +48,44 @@ namespace osu.Game.Rulesets.Mania.Edit
/// <param name="reference">The <see cref="ManiaSelectionBlueprint"/> that received the drag event.</param> /// <param name="reference">The <see cref="ManiaSelectionBlueprint"/> that received the drag event.</param>
private void adjustOrigins(ManiaSelectionBlueprint reference) private void adjustOrigins(ManiaSelectionBlueprint reference)
{ {
var referenceParent = (HitObjectContainer)reference.HitObject.Parent; var referenceParent = (HitObjectContainer)reference.DrawableObject.Parent;
float offsetFromReferenceOrigin = reference.DragPosition.Y - reference.HitObject.OriginPosition.Y; float offsetFromReferenceOrigin = reference.DragPosition.Y - reference.DrawableObject.OriginPosition.Y;
float targetPosition = referenceParent.ToLocalSpace(reference.ScreenSpaceDragPosition).Y - offsetFromReferenceOrigin; float targetPosition = referenceParent.ToLocalSpace(reference.ScreenSpaceDragPosition).Y - offsetFromReferenceOrigin;
// Flip the vertical coordinate space when scrolling downwards // Flip the vertical coordinate space when scrolling downwards
if (scrollingInfo.Direction.Value == ScrollingDirection.Down) if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
targetPosition = targetPosition - referenceParent.DrawHeight; targetPosition = targetPosition - referenceParent.DrawHeight;
float movementDelta = targetPosition - reference.HitObject.Position.Y; float movementDelta = targetPosition - reference.DrawableObject.Position.Y;
foreach (var b in SelectedBlueprints.OfType<ManiaSelectionBlueprint>()) foreach (var b in SelectedBlueprints.OfType<ManiaSelectionBlueprint>())
b.HitObject.Y += movementDelta; b.DrawableObject.Y += movementDelta;
} }
private void performDragMovement(MoveSelectionEvent moveEvent) private void performDragMovement(MoveSelectionEvent moveEvent)
{ {
float delta = moveEvent.InstantDelta.Y;
// When scrolling downwards the anchor position is at the bottom of the screen, however the movement event assumes the anchor is at the top of the screen.
// This causes the delta to assume a positive hitobject position, and which can be corrected for by subtracting the parent height.
if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
delta -= moveEvent.Blueprint.DrawableObject.Parent.DrawHeight;
foreach (var b in SelectedBlueprints) foreach (var b in SelectedBlueprints)
{ {
var hitObject = b.HitObject; var hitObject = b.DrawableObject;
var objectParent = (HitObjectContainer)hitObject.Parent; var objectParent = (HitObjectContainer)hitObject.Parent;
// Using the hitobject position is required since AdjustPosition can be invoked multiple times per frame // StartTime could be used to adjust the position if only one movement event was received per frame.
// without the position having been updated by the parenting ScrollingHitObjectContainer // However this is not the case and ScrollingHitObjectContainer performs movement in UpdateAfterChildren() so the position must also be updated to be valid for further movement events
hitObject.Y += moveEvent.InstantDelta.Y; hitObject.Y += delta;
float targetPosition; float targetPosition = hitObject.Position.Y;
// If we're scrolling downwards, a position of 0 is actually further away from the hit target // The scrolling algorithm always assumes an anchor at the top of the screen, so the position must be flipped when scrolling downwards to reflect a top anchor
// so we need to flip the vertical coordinate in the hitobject container's space
if (scrollingInfo.Direction.Value == ScrollingDirection.Down) if (scrollingInfo.Direction.Value == ScrollingDirection.Down)
targetPosition = -hitObject.Position.Y; targetPosition = -targetPosition;
else
targetPosition = hitObject.Position.Y;
objectParent.Remove(hitObject); objectParent.Remove(hitObject);

View File

@ -9,8 +9,8 @@ namespace osu.Game.Rulesets.Mania.Edit.Masks
{ {
public abstract class ManiaSelectionBlueprint : SelectionBlueprint public abstract class ManiaSelectionBlueprint : SelectionBlueprint
{ {
protected ManiaSelectionBlueprint(DrawableHitObject hitObject) protected ManiaSelectionBlueprint(DrawableHitObject drawableObject)
: base(hitObject) : base(drawableObject)
{ {
RelativeSizeAxes = Axes.None; RelativeSizeAxes = Axes.None;
} }

View File

@ -2,13 +2,12 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
@ -22,8 +21,12 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
{ {
public override bool DisplayResult => false; public override bool DisplayResult => false;
public readonly DrawableNote Head; public DrawableNote Head => headContainer.Child;
public readonly DrawableNote Tail; public DrawableNote Tail => tailContainer.Child;
private readonly Container<DrawableHeadNote> headContainer;
private readonly Container<DrawableTailNote> tailContainer;
private readonly Container<DrawableHoldNoteTick> tickContainer;
private readonly BodyPiece bodyPiece; private readonly BodyPiece bodyPiece;
@ -40,50 +43,81 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
public DrawableHoldNote(HoldNote hitObject) public DrawableHoldNote(HoldNote hitObject)
: base(hitObject) : base(hitObject)
{ {
Container<DrawableHoldNoteTick> tickContainer;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AddRangeInternal(new Drawable[] AddRangeInternal(new Drawable[]
{ {
bodyPiece = new BodyPiece bodyPiece = new BodyPiece { RelativeSizeAxes = Axes.X },
{ tickContainer = new Container<DrawableHoldNoteTick> { RelativeSizeAxes = Axes.Both },
RelativeSizeAxes = Axes.X, headContainer = new Container<DrawableHeadNote> { RelativeSizeAxes = Axes.Both },
}, tailContainer = new Container<DrawableTailNote> { RelativeSizeAxes = Axes.Both },
tickContainer = new Container<DrawableHoldNoteTick>
{
RelativeSizeAxes = Axes.Both,
ChildrenEnumerable = HitObject.NestedHitObjects.OfType<HoldNoteTick>().Select(tick => new DrawableHoldNoteTick(tick)
{
HoldStartTime = () => holdStartTime
})
},
Head = new DrawableHeadNote(this)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
},
Tail = new DrawableTailNote(this)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
}
}); });
foreach (var tick in tickContainer)
AddNested(tick);
AddNested(Head);
AddNested(Tail);
AccentColour.BindValueChanged(colour => AccentColour.BindValueChanged(colour =>
{ {
bodyPiece.AccentColour = colour.NewValue; bodyPiece.AccentColour = colour.NewValue;
Head.AccentColour.Value = colour.NewValue;
Tail.AccentColour.Value = colour.NewValue;
tickContainer.ForEach(t => t.AccentColour.Value = colour.NewValue);
}, true); }, true);
} }
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
switch (hitObject)
{
case DrawableHeadNote head:
headContainer.Child = head;
break;
case DrawableTailNote tail:
tailContainer.Child = tail;
break;
case DrawableHoldNoteTick tick:
tickContainer.Add(tick);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
headContainer.Clear();
tailContainer.Clear();
tickContainer.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case TailNote _:
return new DrawableTailNote(this)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AccentColour = { BindTarget = AccentColour }
};
case Note _:
return new DrawableHeadNote(this)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AccentColour = { BindTarget = AccentColour }
};
case HoldNoteTick tick:
return new DrawableHoldNoteTick(tick)
{
HoldStartTime = () => holdStartTime,
AccentColour = { BindTarget = AccentColour }
};
}
return base.CreateNestedHitObject(hitObject);
}
protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e) protected override void OnDirectionChanged(ValueChangedEvent<ScrollingDirection> e)
{ {
base.OnDirectionChanged(e); base.OnDirectionChanged(e);

View File

@ -52,12 +52,19 @@ namespace osu.Game.Rulesets.Osu.Tests
AddAssert("blueprint positioned over hitobject", () => blueprint.CirclePiece.Position == hitCircle.Position); AddAssert("blueprint positioned over hitobject", () => blueprint.CirclePiece.Position == hitCircle.Position);
} }
[Test]
public void TestStackedHitObject()
{
AddStep("set stacking", () => hitCircle.StackHeight = 5);
AddAssert("blueprint positioned over hitobject", () => blueprint.CirclePiece.Position == hitCircle.StackedPosition);
}
private class TestBlueprint : HitCircleSelectionBlueprint private class TestBlueprint : HitCircleSelectionBlueprint
{ {
public new HitCirclePiece CirclePiece => base.CirclePiece; public new HitCirclePiece CirclePiece => base.CirclePiece;
public TestBlueprint(DrawableHitCircle hitCircle) public TestBlueprint(DrawableHitCircle drawableCircle)
: base(hitCircle) : base(drawableCircle)
{ {
} }
} }

View File

@ -0,0 +1,210 @@
// 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 System;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneOsuDistanceSnapGrid : ManualInputManagerTestScene
{
private const double beat_length = 100;
private static readonly Vector2 grid_position = new Vector2(512, 384);
[Cached(typeof(IEditorBeatmap))]
private readonly EditorBeatmap<OsuHitObject> editorBeatmap;
[Cached]
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor();
private TestOsuDistanceSnapGrid grid;
public TestSceneOsuDistanceSnapGrid()
{
editorBeatmap = new EditorBeatmap<OsuHitObject>(new OsuBeatmap());
createGrid();
}
[SetUp]
public void Setup() => Schedule(() =>
{
Clear();
editorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 1;
editorBeatmap.ControlPointInfo.DifficultyPoints.Clear();
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length });
beatDivisor.Value = 1;
});
[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
[TestCase(4)]
[TestCase(6)]
[TestCase(8)]
[TestCase(12)]
[TestCase(16)]
public void TestBeatDivisor(int divisor)
{
AddStep($"set beat divisor = {divisor}", () => beatDivisor.Value = divisor);
createGrid();
}
[TestCase(100, 100)]
[TestCase(200, 100)]
public void TestBeatLength(float beatLength, float expectedSpacing)
{
AddStep($"set beat length = {beatLength}", () =>
{
editorBeatmap.ControlPointInfo.TimingPoints.Clear();
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beatLength });
});
createGrid();
AddAssert($"spacing = {expectedSpacing}", () => Precision.AlmostEquals(expectedSpacing, grid.DistanceSpacing));
}
[TestCase(0.5f, 50)]
[TestCase(1, 100)]
[TestCase(1.5f, 150)]
public void TestSpeedMultiplier(float multiplier, float expectedSpacing)
{
AddStep($"set speed multiplier = {multiplier}", () =>
{
editorBeatmap.ControlPointInfo.DifficultyPoints.Clear();
editorBeatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { SpeedMultiplier = multiplier });
});
createGrid();
AddAssert($"spacing = {expectedSpacing}", () => Precision.AlmostEquals(expectedSpacing, grid.DistanceSpacing));
}
[TestCase(0.5f, 50)]
[TestCase(1, 100)]
[TestCase(1.5f, 150)]
public void TestSliderMultiplier(float multiplier, float expectedSpacing)
{
AddStep($"set speed multiplier = {multiplier}", () => editorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = multiplier);
createGrid();
AddAssert($"spacing = {expectedSpacing}", () => Precision.AlmostEquals(expectedSpacing, grid.DistanceSpacing));
}
[Test]
public void TestCursorInCentre()
{
createGrid();
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position)));
assertSnappedDistance((float)beat_length);
}
[Test]
public void TestCursorBeforeMovementPoint()
{
createGrid();
AddStep("move mouse to just before movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0) * 1.49f)));
assertSnappedDistance((float)beat_length);
}
[Test]
public void TestCursorAfterMovementPoint()
{
createGrid();
AddStep("move mouse to just after movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0) * 1.51f)));
assertSnappedDistance((float)beat_length * 2);
}
private void assertSnappedDistance(float expectedDistance) => AddAssert($"snap distance = {expectedDistance}", () =>
{
Vector2 snappedPosition = grid.GetSnapPosition(grid.ToLocalSpace(InputManager.CurrentState.Mouse.Position));
float distance = Vector2.Distance(snappedPosition, grid_position);
return Precision.AlmostEquals(expectedDistance, distance);
});
private void createGrid()
{
AddStep("create grid", () =>
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.SlateGray
},
grid = new TestOsuDistanceSnapGrid(new HitCircle { Position = grid_position }),
new SnappingCursorContainer { GetSnapPosition = v => grid.GetSnapPosition(grid.ToLocalSpace(v)) }
};
});
}
private class SnappingCursorContainer : CompositeDrawable
{
public Func<Vector2, Vector2> GetSnapPosition;
private readonly Drawable cursor;
public SnappingCursorContainer()
{
RelativeSizeAxes = Axes.Both;
InternalChild = cursor = new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(50),
Colour = Color4.Red
};
}
protected override void LoadComplete()
{
base.LoadComplete();
updatePosition(GetContainingInputManager().CurrentState.Mouse.Position);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
base.OnMouseMove(e);
updatePosition(e.ScreenSpaceMousePosition);
return true;
}
private void updatePosition(Vector2 screenSpacePosition)
{
cursor.Position = GetSnapPosition.Invoke(screenSpacePosition);
}
}
private class TestOsuDistanceSnapGrid : OsuDistanceSnapGrid
{
public new float DistanceSpacing => base.DistanceSpacing;
public TestOsuDistanceSnapGrid(OsuHitObject hitObject)
: base(hitObject)
{
}
}
}
}

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints
/// <param name="hitObject">The <see cref="OsuHitObject"/> to reference properties from.</param> /// <param name="hitObject">The <see cref="OsuHitObject"/> to reference properties from.</param>
public virtual void UpdateFrom(T hitObject) public virtual void UpdateFrom(T hitObject)
{ {
Position = hitObject.Position; Position = hitObject.StackedPosition;
} }
} }
} }

View File

@ -30,7 +30,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
HitObject.StartTime = EditorClock.CurrentTime;
EndPlacement(); EndPlacement();
return true; return true;
} }

View File

@ -1,18 +1,22 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osuTK;
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles
{ {
public class HitCircleSelectionBlueprint : OsuSelectionBlueprint<HitCircle> public class HitCircleSelectionBlueprint : OsuSelectionBlueprint<HitCircle>
{ {
protected new DrawableHitCircle DrawableObject => (DrawableHitCircle)base.DrawableObject;
protected readonly HitCirclePiece CirclePiece; protected readonly HitCirclePiece CirclePiece;
public HitCircleSelectionBlueprint(DrawableHitCircle hitCircle) public HitCircleSelectionBlueprint(DrawableHitCircle drawableCircle)
: base(hitCircle) : base(drawableCircle)
{ {
InternalChild = CirclePiece = new HitCirclePiece(); InternalChild = CirclePiece = new HitCirclePiece();
} }
@ -23,5 +27,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles
CirclePiece.UpdateFrom(HitObject); CirclePiece.UpdateFrom(HitObject);
} }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => DrawableObject.HitArea.ReceivePositionalInputAt(screenSpacePos);
public override Quad SelectionQuad => DrawableObject.HitArea.ScreenSpaceDrawQuad;
} }
} }

View File

@ -10,10 +10,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints
public abstract class OsuSelectionBlueprint<T> : SelectionBlueprint public abstract class OsuSelectionBlueprint<T> : SelectionBlueprint
where T : OsuHitObject where T : OsuHitObject
{ {
protected new T HitObject => (T)base.HitObject.HitObject; protected T HitObject => (T)DrawableObject.HitObject;
protected OsuSelectionBlueprint(DrawableHitObject hitObject) protected OsuSelectionBlueprint(DrawableHitObject drawableObject)
: base(hitObject) : base(drawableObject)
{ {
} }
} }

View File

@ -104,8 +104,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void beginCurve() private void beginCurve()
{ {
BeginPlacement(); BeginPlacement();
HitObject.StartTime = EditorClock.CurrentTime;
setState(PlacementState.Body); setState(PlacementState.Body);
} }

View File

@ -41,8 +41,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Spinners
} }
else else
{ {
HitObject.StartTime = EditorClock.CurrentTime;
isPlacingEnd = true; isPlacingEnd = true;
piece.FadeTo(1f, 150, Easing.OutQuint); piece.FadeTo(1f, 150, Easing.OutQuint);

View File

@ -0,0 +1,29 @@
// 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.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Compose.Components;
namespace osu.Game.Rulesets.Osu.Edit
{
public class OsuDistanceSnapGrid : CircularDistanceSnapGrid
{
public OsuDistanceSnapGrid(OsuHitObject hitObject)
: base(hitObject, hitObject.StackedEndPosition)
{
Masking = true;
}
protected override float GetVelocity(double time, ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(time);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(time);
double scoringDistance = OsuHitObject.BASE_SCORING_DISTANCE * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier;
return (float)(scoringDistance / timingPoint.BeatLength);
}
}
}

View File

@ -2,10 +2,12 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles; using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
@ -52,5 +54,31 @@ namespace osu.Game.Rulesets.Osu.Edit
return base.CreateBlueprintFor(hitObject); return base.CreateBlueprintFor(hitObject);
} }
protected override DistanceSnapGrid CreateDistanceSnapGrid(IEnumerable<HitObject> selectedHitObjects)
{
var objects = selectedHitObjects.ToList();
if (objects.Count == 0)
{
var lastObject = EditorBeatmap.HitObjects.LastOrDefault(h => h.StartTime <= EditorClock.CurrentTime);
if (lastObject == null)
return null;
return new OsuDistanceSnapGrid(lastObject);
}
else
{
double minTime = objects.Min(h => h.StartTime);
var lastObject = EditorBeatmap.HitObjects.LastOrDefault(h => h.StartTime < minTime);
if (lastObject == null)
return null;
return new OsuDistanceSnapGrid(lastObject);
}
}
} }
} }

View File

@ -24,14 +24,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private readonly IBindable<int> stackHeightBindable = new Bindable<int>(); private readonly IBindable<int> stackHeightBindable = new Bindable<int>();
private readonly IBindable<float> scaleBindable = new Bindable<float>(); private readonly IBindable<float> scaleBindable = new Bindable<float>();
public OsuAction? HitAction => hitArea.HitAction; public OsuAction? HitAction => HitArea.HitAction;
public readonly HitReceptor HitArea;
public readonly SkinnableDrawable CirclePiece;
private readonly Container scaleContainer; private readonly Container scaleContainer;
private readonly HitArea hitArea;
public SkinnableDrawable CirclePiece { get; }
public DrawableHitCircle(HitCircle h) public DrawableHitCircle(HitCircle h)
: base(h) : base(h)
{ {
@ -48,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Children = new Drawable[] Children = new Drawable[]
{ {
hitArea = new HitArea HitArea = new HitReceptor
{ {
Hit = () => Hit = () =>
{ {
@ -69,7 +67,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
}, },
}; };
Size = hitArea.DrawSize; Size = HitArea.DrawSize;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -153,7 +151,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Expire(true); Expire(true);
hitArea.HitAction = null; HitArea.HitAction = null;
break; break;
case ArmedState.Miss: case ArmedState.Miss:
@ -172,7 +170,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public Drawable ProxiedLayer => ApproachCircle; public Drawable ProxiedLayer => ApproachCircle;
private class HitArea : Drawable, IKeyBindingHandler<OsuAction> public class HitReceptor : Drawable, IKeyBindingHandler<OsuAction>
{ {
// IsHovered is used // IsHovered is used
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
@ -181,7 +179,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public OsuAction? HitAction; public OsuAction? HitAction;
public HitArea() public HitReceptor()
{ {
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2); Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);

View File

@ -5,7 +5,6 @@ using osuTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces; using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -21,15 +20,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach public class DrawableSlider : DrawableOsuHitObject, IDrawableHitObjectWithProxiedApproach
{ {
private readonly Slider slider; public DrawableSliderHead HeadCircle => headContainer.Child;
private readonly List<Drawable> components = new List<Drawable>(); public DrawableSliderTail TailCircle => tailContainer.Child;
public readonly DrawableHitCircle HeadCircle;
public readonly DrawableSliderTail TailCircle;
public readonly SnakingSliderBody Body; public readonly SnakingSliderBody Body;
public readonly SliderBall Ball; public readonly SliderBall Ball;
private readonly Container<DrawableSliderHead> headContainer;
private readonly Container<DrawableSliderTail> tailContainer;
private readonly Container<DrawableSliderTick> tickContainer;
private readonly Container<DrawableRepeatPoint> repeatContainer;
private readonly Slider slider;
private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>(); private readonly IBindable<Vector2> positionBindable = new Bindable<Vector2>();
private readonly IBindable<float> scaleBindable = new Bindable<float>(); private readonly IBindable<float> scaleBindable = new Bindable<float>();
private readonly IBindable<SliderPath> pathBindable = new Bindable<SliderPath>(); private readonly IBindable<SliderPath> pathBindable = new Bindable<SliderPath>();
@ -44,14 +47,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Position = s.StackedPosition; Position = s.StackedPosition;
Container<DrawableSliderTick> ticks;
Container<DrawableRepeatPoint> repeatPoints;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
Body = new SnakingSliderBody(s), Body = new SnakingSliderBody(s),
ticks = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both }, tickContainer = new Container<DrawableSliderTick> { RelativeSizeAxes = Axes.Both },
repeatPoints = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both }, repeatContainer = new Container<DrawableRepeatPoint> { RelativeSizeAxes = Axes.Both },
Ball = new SliderBall(s, this) Ball = new SliderBall(s, this)
{ {
GetInitialHitAction = () => HeadCircle.HitAction, GetInitialHitAction = () => HeadCircle.HitAction,
@ -60,45 +60,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AlwaysPresent = true, AlwaysPresent = true,
Alpha = 0 Alpha = 0
}, },
HeadCircle = new DrawableSliderHead(s, s.HeadCircle) headContainer = new Container<DrawableSliderHead> { RelativeSizeAxes = Axes.Both },
{ tailContainer = new Container<DrawableSliderTail> { RelativeSizeAxes = Axes.Both },
OnShake = Shake
},
TailCircle = new DrawableSliderTail(s, s.TailCircle)
}; };
components.Add(Body);
components.Add(Ball);
AddNested(HeadCircle);
AddNested(TailCircle);
components.Add(TailCircle);
foreach (var tick in s.NestedHitObjects.OfType<SliderTick>())
{
var drawableTick = new DrawableSliderTick(tick) { Position = tick.Position - s.Position };
ticks.Add(drawableTick);
components.Add(drawableTick);
AddNested(drawableTick);
}
foreach (var repeatPoint in s.NestedHitObjects.OfType<RepeatPoint>())
{
var drawableRepeatPoint = new DrawableRepeatPoint(repeatPoint, this) { Position = repeatPoint.Position - s.Position };
repeatPoints.Add(drawableRepeatPoint);
components.Add(drawableRepeatPoint);
AddNested(drawableRepeatPoint);
}
}
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
Body.FadeInFromZero(HitObject.TimeFadeIn);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -129,6 +93,67 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
}, true); }, true);
} }
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
switch (hitObject)
{
case DrawableSliderHead head:
headContainer.Child = head;
break;
case DrawableSliderTail tail:
tailContainer.Child = tail;
break;
case DrawableSliderTick tick:
tickContainer.Add(tick);
break;
case DrawableRepeatPoint repeat:
repeatContainer.Add(repeat);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
headContainer.Clear();
tailContainer.Clear();
repeatContainer.Clear();
tickContainer.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case SliderTailCircle tail:
return new DrawableSliderTail(slider, tail);
case HitCircle head:
return new DrawableSliderHead(slider, head) { OnShake = Shake };
case SliderTick tick:
return new DrawableSliderTick(tick) { Position = tick.Position - slider.Position };
case RepeatPoint repeat:
return new DrawableRepeatPoint(repeat, this) { Position = repeat.Position - slider.Position };
}
return base.CreateNestedHitObject(hitObject);
}
protected override void UpdateInitialTransforms()
{
base.UpdateInitialTransforms();
Body.FadeInFromZero(HitObject.TimeFadeIn);
}
public readonly Bindable<bool> Tracking = new Bindable<bool>(); public readonly Bindable<bool> Tracking = new Bindable<bool>();
protected override void Update() protected override void Update()
@ -139,9 +164,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
double completionProgress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1); double completionProgress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
foreach (var c in components.OfType<ISliderProgress>()) c.UpdateProgress(completionProgress); Ball.UpdateProgress(completionProgress);
foreach (var c in components.OfType<ITrackSnaking>()) c.UpdateSnakingPosition(slider.Path.PositionAt(Body.SnakedStart ?? 0), slider.Path.PositionAt(Body.SnakedEnd ?? 0)); Body.UpdateProgress(completionProgress);
foreach (var t in components.OfType<IRequireTracking>()) t.Tracking = Ball.Tracking;
foreach (DrawableHitObject hitObject in NestedHitObjects)
{
if (hitObject is ITrackSnaking s) s.UpdateSnakingPosition(slider.Path.PositionAt(Body.SnakedStart ?? 0), slider.Path.PositionAt(Body.SnakedEnd ?? 0));
if (hitObject is IRequireTracking t) t.Tracking = Ball.Tracking;
}
Size = Body.Size; Size = Body.Size;
OriginPosition = Body.PathOffset; OriginPosition = Body.PathOffset;
@ -187,7 +217,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
ApplyResult(r => ApplyResult(r =>
{ {
var judgementsCount = NestedHitObjects.Count(); var judgementsCount = NestedHitObjects.Count;
var judgementsHit = NestedHitObjects.Count(h => h.IsHit); var judgementsHit = NestedHitObjects.Count(h => h.IsHit);
var hitFraction = (double)judgementsHit / judgementsCount; var hitFraction = (double)judgementsHit / judgementsCount;
@ -228,7 +258,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
} }
public Drawable ProxiedLayer => HeadCircle.ApproachCircle; public Drawable ProxiedLayer => HeadCircle.ProxiedLayer;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Body.ReceivePositionalInputAt(screenSpacePos); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Body.ReceivePositionalInputAt(screenSpacePos);
} }

View File

@ -14,8 +14,16 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
public abstract class OsuHitObject : HitObject, IHasComboInformation, IHasPosition public abstract class OsuHitObject : HitObject, IHasComboInformation, IHasPosition
{ {
/// <summary>
/// The radius of hit objects (ie. the radius of a <see cref="HitCircle"/>).
/// </summary>
public const float OBJECT_RADIUS = 64; public const float OBJECT_RADIUS = 64;
/// <summary>
/// Scoring distance with a speed-adjusted beat length of 1 second (ie. the speed slider balls move through their track).
/// </summary>
internal const float BASE_SCORING_DISTANCE = 100;
public double TimePreempt = 600; public double TimePreempt = 600;
public double TimeFadeIn = 400; public double TimeFadeIn = 400;

View File

@ -19,11 +19,6 @@ namespace osu.Game.Rulesets.Osu.Objects
{ {
public class Slider : OsuHitObject, IHasCurve public class Slider : OsuHitObject, IHasCurve
{ {
/// <summary>
/// Scoring distance with a speed-adjusted beat length of 1 second.
/// </summary>
private const float base_scoring_distance = 100;
public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity; public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity;
public double Duration => EndTime - StartTime; public double Duration => EndTime - StartTime;
@ -123,7 +118,7 @@ namespace osu.Game.Rulesets.Osu.Objects
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier; double scoringDistance = BASE_SCORING_DISTANCE * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier;
Velocity = scoringDistance / timingPoint.BeatLength; Velocity = scoringDistance / timingPoint.BeatLength;
TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier; TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier;

View File

@ -2,14 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Skinning; using osu.Game.Rulesets.Osu.Skinning;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
@ -23,12 +20,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
private bool cursorExpand; private bool cursorExpand;
private Bindable<float> cursorScale;
private Bindable<bool> autoCursorScale;
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private Container expandTarget; private Container expandTarget;
private Drawable scaleTarget;
public OsuCursor() public OsuCursor()
{ {
@ -43,43 +35,19 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config, IBindable<WorkingBeatmap> beatmap) private void load()
{ {
InternalChild = expandTarget = new Container InternalChild = expandTarget = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Child = scaleTarget = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.Cursor), _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling) Child = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.Cursor), _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling)
{ {
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
} }
}; };
this.beatmap.BindTo(beatmap);
this.beatmap.ValueChanged += _ => calculateScale();
cursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
cursorScale.ValueChanged += _ => calculateScale();
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
autoCursorScale.ValueChanged += _ => calculateScale();
calculateScale();
}
private void calculateScale()
{
float scale = cursorScale.Value;
if (autoCursorScale.Value && beatmap.Value != null)
{
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
scale *= 1f - 0.7f * (1f + beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY;
}
scaleTarget.Scale = new Vector2(scale);
} }
private const float pressed_scale = 1.2f; private const float pressed_scale = 1.2f;

View File

@ -8,6 +8,8 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.Configuration; using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Skinning; using osu.Game.Skinning;
@ -27,6 +29,11 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
private readonly Drawable cursorTrail; private readonly Drawable cursorTrail;
public Bindable<float> CursorScale;
private Bindable<float> userCursorScale;
private Bindable<bool> autoCursorScale;
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
public OsuCursorContainer() public OsuCursorContainer()
{ {
InternalChild = fadeContainer = new Container InternalChild = fadeContainer = new Container
@ -37,9 +44,36 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuRulesetConfigManager config) private void load(OsuConfigManager config, OsuRulesetConfigManager rulesetConfig, IBindable<WorkingBeatmap> beatmap)
{ {
config?.BindWith(OsuRulesetSetting.ShowCursorTrail, showTrail); rulesetConfig?.BindWith(OsuRulesetSetting.ShowCursorTrail, showTrail);
this.beatmap.BindTo(beatmap);
this.beatmap.ValueChanged += _ => calculateScale();
userCursorScale = config.GetBindable<float>(OsuSetting.GameplayCursorSize);
userCursorScale.ValueChanged += _ => calculateScale();
autoCursorScale = config.GetBindable<bool>(OsuSetting.AutoCursorSize);
autoCursorScale.ValueChanged += _ => calculateScale();
CursorScale = new Bindable<float>();
CursorScale.ValueChanged += e => ActiveCursor.Scale = cursorTrail.Scale = new Vector2(e.NewValue);
calculateScale();
}
private void calculateScale()
{
float scale = userCursorScale.Value;
if (autoCursorScale.Value && beatmap.Value != null)
{
// if we have a beatmap available, let's get its circle size to figure out an automatic cursor scale modifier.
scale *= 1f - 0.7f * (1f + beatmap.Value.BeatmapInfo.BaseDifficulty.CircleSize - BeatmapDifficulty.DEFAULT_DIFFICULTY) / BeatmapDifficulty.DEFAULT_DIFFICULTY;
}
CursorScale.Value = scale;
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -95,13 +129,13 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
protected override void PopIn() protected override void PopIn()
{ {
fadeContainer.FadeTo(1, 300, Easing.OutQuint); fadeContainer.FadeTo(1, 300, Easing.OutQuint);
ActiveCursor.ScaleTo(1, 400, Easing.OutQuint); ActiveCursor.ScaleTo(CursorScale.Value, 400, Easing.OutQuint);
} }
protected override void PopOut() protected override void PopOut()
{ {
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint); fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint); ActiveCursor.ScaleTo(CursorScale.Value * 0.8f, 450, Easing.OutQuint);
} }
private class DefaultCursorTrail : CursorTrail private class DefaultCursorTrail : CursorTrail

View File

@ -57,21 +57,15 @@ namespace osu.Game.Rulesets.Osu.UI
public override void Add(DrawableHitObject h) public override void Add(DrawableHitObject h)
{ {
h.OnNewResult += onNewResult; h.OnNewResult += onNewResult;
h.OnLoadComplete += d =>
if (h is IDrawableHitObjectWithProxiedApproach c)
{ {
var original = c.ProxiedLayer; if (d is IDrawableHitObjectWithProxiedApproach c)
approachCircles.Add(c.ProxiedLayer.CreateProxy());
// Hitobjects only have lifetimes set on LoadComplete. For nested hitobjects (e.g. SliderHeads), this only happens when the parenting slider becomes visible. };
// This delegation is required to make sure that the approach circles for those not-yet-loaded objects aren't added prematurely.
original.OnLoadComplete += addApproachCircleProxy;
}
base.Add(h); base.Add(h);
} }
private void addApproachCircleProxy(Drawable d) => approachCircles.Add(d.CreateProxy());
public override void PostProcess() public override void PostProcess()
{ {
connectionLayer.HitObjects = HitObjectContainer.Objects.Select(d => d.HitObject).OfType<OsuHitObject>(); connectionLayer.HitObjects = HitObjectContainer.Objects.Select(d => d.HitObject).OfType<OsuHitObject>();

View File

@ -1,15 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.UI.Cursor; using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -18,9 +18,11 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
public class OsuResumeOverlay : ResumeOverlay public class OsuResumeOverlay : ResumeOverlay
{ {
private Container cursorScaleContainer;
private OsuClickToResumeCursor clickToResumeCursor; private OsuClickToResumeCursor clickToResumeCursor;
private GameplayCursorContainer localCursorContainer; private OsuCursorContainer localCursorContainer;
private Bindable<float> localCursorScale;
public override CursorContainer LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null; public override CursorContainer LocalCursor => State.Value == Visibility.Visible ? localCursorContainer : null;
@ -29,22 +31,35 @@ namespace osu.Game.Rulesets.Osu.UI
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
Add(clickToResumeCursor = new OsuClickToResumeCursor { ResumeRequested = Resume }); Add(cursorScaleContainer = new Container
{
RelativePositionAxes = Axes.Both,
Child = clickToResumeCursor = new OsuClickToResumeCursor { ResumeRequested = Resume }
});
} }
public override void Show() public override void Show()
{ {
base.Show(); base.Show();
clickToResumeCursor.ShowAt(GameplayCursor.ActiveCursor.Position); GameplayCursor.ActiveCursor.Hide();
cursorScaleContainer.MoveTo(GameplayCursor.ActiveCursor.Position);
clickToResumeCursor.Appear();
if (localCursorContainer == null) if (localCursorContainer == null)
{
Add(localCursorContainer = new OsuCursorContainer()); Add(localCursorContainer = new OsuCursorContainer());
localCursorScale = new Bindable<float>();
localCursorScale.BindTo(localCursorContainer.CursorScale);
localCursorScale.BindValueChanged(scale => cursorScaleContainer.Scale = new Vector2(scale.NewValue), true);
}
} }
public override void Hide() public override void Hide()
{ {
localCursorContainer?.Expire(); localCursorContainer?.Expire();
localCursorContainer = null; localCursorContainer = null;
GameplayCursor.ActiveCursor.Show();
base.Hide(); base.Hide();
} }
@ -82,7 +97,7 @@ namespace osu.Game.Rulesets.Osu.UI
case OsuAction.RightButton: case OsuAction.RightButton:
if (!IsHovered) return false; if (!IsHovered) return false;
this.ScaleTo(new Vector2(2), TRANSITION_TIME, Easing.OutQuint); this.ScaleTo(2, TRANSITION_TIME, Easing.OutQuint);
ResumeRequested?.Invoke(); ResumeRequested?.Invoke();
return true; return true;
@ -93,11 +108,10 @@ namespace osu.Game.Rulesets.Osu.UI
public bool OnReleased(OsuAction action) => false; public bool OnReleased(OsuAction action) => false;
public void ShowAt(Vector2 activeCursorPosition) => Schedule(() => public void Appear() => Schedule(() =>
{ {
updateColour(); updateColour();
this.MoveTo(activeCursorPosition); this.ScaleTo(4).Then().ScaleTo(1, 1000, Easing.OutQuint);
this.ScaleTo(new Vector2(4)).Then().ScaleTo(Vector2.One, 1000, Easing.OutQuint);
}); });
private void updateColour() private void updateColour()

View File

@ -239,7 +239,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
private class TestStrongNestedHit : DrawableStrongNestedHit private class TestStrongNestedHit : DrawableStrongNestedHit
{ {
public TestStrongNestedHit(DrawableHitObject mainObject) public TestStrongNestedHit(DrawableHitObject mainObject)
: base(null, mainObject) : base(new StrongHitObject { StartTime = mainObject.HitObject.StartTime }, mainObject)
{ {
} }

View File

@ -12,6 +12,7 @@ using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
@ -28,31 +29,18 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
/// </summary> /// </summary>
private int rollingHits; private int rollingHits;
private readonly Container<DrawableDrumRollTick> tickContainer;
private Color4 colourIdle;
private Color4 colourEngaged;
public DrawableDrumRoll(DrumRoll drumRoll) public DrawableDrumRoll(DrumRoll drumRoll)
: base(drumRoll) : base(drumRoll)
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Container<DrawableDrumRollTick> tickContainer;
MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both }); MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both });
foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{
var newTick = new DrawableDrumRollTick(tick);
newTick.OnNewResult += onNewTickResult;
AddNested(newTick);
tickContainer.Add(newTick);
}
} }
protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece();
public override bool OnPressed(TaikoAction action) => false;
private Color4 colourIdle;
private Color4 colourEngaged;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
@ -60,8 +48,51 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
colourEngaged = colours.YellowDarker; colourEngaged = colours.YellowDarker;
} }
private void onNewTickResult(DrawableHitObject obj, JudgementResult result) protected override void LoadComplete()
{ {
base.LoadComplete();
OnNewResult += onNewResult;
}
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
switch (hitObject)
{
case DrawableDrumRollTick tick:
tickContainer.Add(tick);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
tickContainer.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case DrumRollTick tick:
return new DrawableDrumRollTick(tick);
}
return base.CreateNestedHitObject(hitObject);
}
protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece();
public override bool OnPressed(TaikoAction action) => false;
private void onNewResult(DrawableHitObject obj, JudgementResult result)
{
if (!(obj is DrawableDrumRollTick))
return;
if (result.Type > HitResult.Miss) if (result.Type > HitResult.Miss)
rollingHits++; rollingHits++;
else else

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -14,6 +13,7 @@ using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
@ -30,8 +30,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
/// </summary> /// </summary>
private const double ring_appear_offset = 100; private const double ring_appear_offset = 100;
private readonly List<DrawableSwellTick> ticks = new List<DrawableSwellTick>(); private readonly Container<DrawableSwellTick> ticks;
private readonly Container bodyContainer; private readonly Container bodyContainer;
private readonly CircularContainer targetRing; private readonly CircularContainer targetRing;
private readonly CircularContainer expandingRing; private readonly CircularContainer expandingRing;
@ -108,16 +107,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
} }
}); });
AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
MainPiece.Add(symbol = new SwellSymbolPiece()); MainPiece.Add(symbol = new SwellSymbolPiece());
foreach (var tick in HitObject.NestedHitObjects.OfType<SwellTick>())
{
var vis = new DrawableSwellTick(tick);
ticks.Add(vis);
AddInternal(vis);
AddNested(vis);
}
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -136,11 +128,49 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Width *= Parent.RelativeChildSize.X; Width *= Parent.RelativeChildSize.X;
} }
protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
switch (hitObject)
{
case DrawableSwellTick tick:
ticks.Add(tick);
break;
}
}
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
ticks.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case SwellTick tick:
return new DrawableSwellTick(tick);
}
return base.CreateNestedHitObject(hitObject);
}
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)
{ {
if (userTriggered) if (userTriggered)
{ {
var nextTick = ticks.Find(j => !j.IsHit); DrawableSwellTick nextTick = null;
foreach (var t in ticks)
{
if (!t.IsHit)
{
nextTick = t;
break;
}
}
nextTick?.TriggerResult(HitResult.Great); nextTick?.TriggerResult(HitResult.Great);

View File

@ -11,6 +11,7 @@ using osu.Game.Audio;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -109,11 +110,12 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
public override Vector2 OriginPosition => new Vector2(DrawHeight / 2); public override Vector2 OriginPosition => new Vector2(DrawHeight / 2);
protected readonly Vector2 BaseSize; public new TaikoHitType HitObject;
protected readonly Vector2 BaseSize;
protected readonly TaikoPiece MainPiece; protected readonly TaikoPiece MainPiece;
public new TaikoHitType HitObject; private readonly Container<DrawableStrongNestedHit> strongHitContainer;
protected DrawableTaikoHitObject(TaikoHitType hitObject) protected DrawableTaikoHitObject(TaikoHitType hitObject)
: base(hitObject) : base(hitObject)
@ -129,17 +131,38 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Content.Add(MainPiece = CreateMainPiece()); Content.Add(MainPiece = CreateMainPiece());
MainPiece.KiaiMode = HitObject.Kiai; MainPiece.KiaiMode = HitObject.Kiai;
var strongObject = HitObject.NestedHitObjects.OfType<StrongHitObject>().FirstOrDefault(); AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
}
if (strongObject != null) protected override void AddNestedHitObject(DrawableHitObject hitObject)
{
base.AddNestedHitObject(hitObject);
switch (hitObject)
{ {
var strongHit = CreateStrongHit(strongObject); case DrawableStrongNestedHit strong:
strongHitContainer.Add(strong);
AddNested(strongHit); break;
AddInternal(strongHit);
} }
} }
protected override void ClearNestedHitObjects()
{
base.ClearNestedHitObjects();
strongHitContainer.Clear();
}
protected override DrawableHitObject CreateNestedHitObject(HitObject hitObject)
{
switch (hitObject)
{
case StrongHitObject strong:
return CreateStrongHit(strong);
}
return base.CreateNestedHitObject(hitObject);
}
// Normal and clap samples are handled by the drum // Normal and clap samples are handled by the drum
protected override IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples.Where(s => s.Name != HitSampleInfo.HIT_NORMAL && s.Name != HitSampleInfo.HIT_CLAP); protected override IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples.Where(s => s.Name != HitSampleInfo.HIT_NORMAL && s.Name != HitSampleInfo.HIT_CLAP);

View File

@ -0,0 +1,143 @@
// 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 System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Skinning;
using osu.Game.Tests.Visual;
using osuTK.Graphics;
namespace osu.Game.Tests.Gameplay
{
[HeadlessTest]
public class TestSceneHitObjectAccentColour : OsuTestScene
{
private Container skinContainer;
[SetUp]
public void Setup() => Schedule(() => Child = skinContainer = new SkinProvidingContainer(new TestSkin()));
[Test]
public void TestChangeComboIndexBeforeLoad()
{
TestDrawableHitObject hitObject = null;
AddStep("set combo and add hitobject", () =>
{
hitObject = new TestDrawableHitObject();
hitObject.HitObject.ComboIndex = 1;
skinContainer.Add(hitObject);
});
AddAssert("combo colour is green", () => hitObject.AccentColour.Value == Color4.Green);
}
[Test]
public void TestChangeComboIndexDuringLoad()
{
TestDrawableHitObject hitObject = null;
AddStep("add hitobject and set combo", () =>
{
skinContainer.Add(hitObject = new TestDrawableHitObject());
hitObject.HitObject.ComboIndex = 1;
});
AddAssert("combo colour is green", () => hitObject.AccentColour.Value == Color4.Green);
}
[Test]
public void TestChangeComboIndexAfterLoad()
{
TestDrawableHitObject hitObject = null;
AddStep("add hitobject", () => skinContainer.Add(hitObject = new TestDrawableHitObject()));
AddAssert("combo colour is red", () => hitObject.AccentColour.Value == Color4.Red);
AddStep("change combo", () => hitObject.HitObject.ComboIndex = 1);
AddAssert("combo colour is green", () => hitObject.AccentColour.Value == Color4.Green);
}
private class TestDrawableHitObject : DrawableHitObject<TestHitObjectWithCombo>
{
public TestDrawableHitObject()
: base(new TestHitObjectWithCombo())
{
}
}
private class TestHitObjectWithCombo : HitObject, IHasComboInformation
{
public bool NewCombo { get; } = false;
public int ComboOffset { get; } = 0;
public Bindable<int> IndexInCurrentComboBindable { get; } = new Bindable<int>();
public int IndexInCurrentCombo
{
get => IndexInCurrentComboBindable.Value;
set => IndexInCurrentComboBindable.Value = value;
}
public Bindable<int> ComboIndexBindable { get; } = new Bindable<int>();
public int ComboIndex
{
get => ComboIndexBindable.Value;
set => ComboIndexBindable.Value = value;
}
public Bindable<bool> LastInComboBindable { get; } = new Bindable<bool>();
public bool LastInCombo
{
get => LastInComboBindable.Value;
set => LastInComboBindable.Value = value;
}
}
private class TestSkin : ISkin
{
public readonly List<Color4> ComboColours = new List<Color4>
{
Color4.Red,
Color4.Green
};
public Drawable GetDrawableComponent(ISkinComponent component) => throw new NotImplementedException();
public Texture GetTexture(string componentName) => throw new NotImplementedException();
public SampleChannel GetSample(ISampleInfo sampleInfo) => throw new NotImplementedException();
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
{
switch (lookup)
{
case GlobalSkinConfiguration global:
switch (global)
{
case GlobalSkinConfiguration.ComboColours:
return SkinUtils.As<TValue>(new Bindable<List<Color4>>(ComboColours));
}
break;
}
throw new NotImplementedException();
}
}
}
}

View File

@ -0,0 +1,48 @@
// 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 NUnit.Framework;
using osu.Game.Beatmaps;
namespace osu.Game.Tests.NonVisual
{
[TestFixture]
public class BeatmapSetInfoEqualityTest
{
[Test]
public void TestOnlineWithOnline()
{
var ourInfo = new BeatmapSetInfo { OnlineBeatmapSetID = 123 };
var otherInfo = new BeatmapSetInfo { OnlineBeatmapSetID = 123 };
Assert.AreEqual(ourInfo, otherInfo);
}
[Test]
public void TestDatabasedWithDatabased()
{
var ourInfo = new BeatmapSetInfo { ID = 123 };
var otherInfo = new BeatmapSetInfo { ID = 123 };
Assert.AreEqual(ourInfo, otherInfo);
}
[Test]
public void TestDatabasedWithOnline()
{
var ourInfo = new BeatmapSetInfo { ID = 123, OnlineBeatmapSetID = 12 };
var otherInfo = new BeatmapSetInfo { OnlineBeatmapSetID = 12 };
Assert.AreEqual(ourInfo, otherInfo);
}
[Test]
public void TestCheckNullID()
{
var ourInfo = new BeatmapSetInfo { Status = BeatmapSetOnlineStatus.Loved };
var otherInfo = new BeatmapSetInfo { Status = BeatmapSetOnlineStatus.Approved };
Assert.AreNotEqual(ourInfo, otherInfo);
}
}
}

View File

@ -285,6 +285,12 @@ namespace osu.Game.Tests.Visual.Background
}); });
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
rulesets?.Dispose();
}
private class DummySongSelect : PlaySongSelect private class DummySongSelect : PlaySongSelect
{ {
protected override BackgroundScreen CreateBackground() protected override BackgroundScreen CreateBackground()

View File

@ -19,7 +19,7 @@ using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Editor namespace osu.Game.Tests.Visual.Editor
{ {
public class TestSceneBeatSnapGrid : EditorClockTestScene public class TestSceneDistanceSnapGrid : EditorClockTestScene
{ {
private const double beat_length = 100; private const double beat_length = 100;
private static readonly Vector2 grid_position = new Vector2(512, 384); private static readonly Vector2 grid_position = new Vector2(512, 384);
@ -27,9 +27,9 @@ namespace osu.Game.Tests.Visual.Editor
[Cached(typeof(IEditorBeatmap))] [Cached(typeof(IEditorBeatmap))]
private readonly EditorBeatmap<OsuHitObject> editorBeatmap; private readonly EditorBeatmap<OsuHitObject> editorBeatmap;
private TestBeatSnapGrid grid; private TestDistanceSnapGrid grid;
public TestSceneBeatSnapGrid() public TestSceneDistanceSnapGrid()
{ {
editorBeatmap = new EditorBeatmap<OsuHitObject>(new OsuBeatmap()); editorBeatmap = new EditorBeatmap<OsuHitObject>(new OsuBeatmap());
editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length }); editorBeatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = beat_length });
@ -112,7 +112,7 @@ namespace osu.Game.Tests.Visual.Editor
AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnapTime(snapPosition), 0.01)); AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnapTime(snapPosition), 0.01));
} }
private void createGrid(Action<TestBeatSnapGrid> func = null, string description = null) private void createGrid(Action<TestDistanceSnapGrid> func = null, string description = null)
{ {
AddStep($"create grid {description ?? string.Empty}", () => AddStep($"create grid {description ?? string.Empty}", () =>
{ {
@ -123,20 +123,20 @@ namespace osu.Game.Tests.Visual.Editor
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4.SlateGray Colour = Color4.SlateGray
}, },
grid = new TestBeatSnapGrid(new HitObject(), grid_position) grid = new TestDistanceSnapGrid(new HitObject(), grid_position)
}; };
func?.Invoke(grid); func?.Invoke(grid);
}); });
} }
private class TestBeatSnapGrid : BeatSnapGrid private class TestDistanceSnapGrid : DistanceSnapGrid
{ {
public new float Velocity = 1; public new float Velocity = 1;
public new float DistanceSpacing => base.DistanceSpacing; public new float DistanceSpacing => base.DistanceSpacing;
public TestBeatSnapGrid(HitObject hitObject, Vector2 centrePosition) public TestDistanceSnapGrid(HitObject hitObject, Vector2 centrePosition)
: base(hitObject, centrePosition) : base(hitObject, centrePosition)
{ {
} }

View File

@ -0,0 +1,58 @@
// 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 System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Game.Online.API.Requests;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Overlays.Comments;
namespace osu.Game.Tests.Visual.Online
{
[TestFixture]
public class TestSceneCommentsContainer : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(CommentsContainer),
typeof(CommentsHeader),
typeof(DrawableComment),
typeof(HeaderButton),
typeof(SortTabControl),
typeof(ShowChildrenButton),
typeof(DeletedChildrenPlaceholder)
};
protected override bool UseOnlineAPI => true;
public TestSceneCommentsContainer()
{
BasicScrollContainer scrollFlow;
Add(scrollFlow = new BasicScrollContainer
{
RelativeSizeAxes = Axes.Both,
});
AddStep("Big Black comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 41823));
});
AddStep("Airman comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Beatmapset, 24313));
});
AddStep("lazer build comments", () =>
{
scrollFlow.Clear();
scrollFlow.Add(new CommentsContainer(CommentableType.Build, 4772));
});
}
}
}

View File

@ -1,10 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Game.Overlays.Profile.Sections;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Allocation;
using osu.Game.Graphics;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -17,11 +19,11 @@ namespace osu.Game.Tests.Visual.Online
public TestSceneShowMoreButton() public TestSceneShowMoreButton()
{ {
ShowMoreButton button = null; TestButton button = null;
int fireCount = 0; int fireCount = 0;
Add(button = new ShowMoreButton Add(button = new TestButton
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -51,5 +53,16 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("action fired twice", () => fireCount == 2); AddAssert("action fired twice", () => fireCount == 2);
AddAssert("is in loading state", () => button.IsLoading); AddAssert("is in loading state", () => button.IsLoading);
} }
private class TestButton : ShowMoreButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colors)
{
IdleColour = colors.YellowDark;
HoverColour = colors.Yellow;
ChevronIconColour = colors.Red;
}
}
} }
} }

View File

@ -349,5 +349,11 @@ namespace osu.Game.Tests.Visual.SongSelect
DateAdded = DateTimeOffset.UtcNow, DateAdded = DateTimeOffset.UtcNow,
}; };
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
rulesets?.Dispose();
}
} }
} }

View File

@ -63,6 +63,21 @@ namespace osu.Game.Beatmaps
public bool Protected { get; set; } public bool Protected { get; set; }
public bool Equals(BeatmapSetInfo other) => OnlineBeatmapSetID == other?.OnlineBeatmapSetID; public bool Equals(BeatmapSetInfo other)
{
if (other == null)
return false;
if (ID != 0 && other.ID != 0)
return ID == other.ID;
if (OnlineBeatmapSetID.HasValue && other.OnlineBeatmapSetID.HasValue)
return OnlineBeatmapSetID == other.OnlineBeatmapSetID;
if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash))
return Hash == other.Hash;
return ReferenceEquals(this, other);
}
} }
} }

View File

@ -1,30 +1,36 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics;
using System.Collections.Generic; using System.Collections.Generic;
namespace osu.Game.Overlays.Profile.Sections namespace osu.Game.Graphics.UserInterface
{ {
public class ShowMoreButton : OsuHoverContainer public class ShowMoreButton : OsuHoverContainer
{ {
private const float fade_duration = 200; private const float fade_duration = 200;
private readonly Box background; private Color4 chevronIconColour;
private readonly LoadingAnimation loading;
private readonly FillFlowContainer content;
protected override IEnumerable<Drawable> EffectTargets => new[] { background }; protected Color4 ChevronIconColour
{
get => chevronIconColour;
set => chevronIconColour = leftChevron.Colour = rightChevron.Colour = value;
}
public string Text
{
get => text.Text;
set => text.Text = value;
}
private bool isLoading; private bool isLoading;
@ -33,26 +39,32 @@ namespace osu.Game.Overlays.Profile.Sections
get => isLoading; get => isLoading;
set set
{ {
if (isLoading == value)
return;
isLoading = value; isLoading = value;
Enabled.Value = !isLoading; Enabled.Value = !isLoading;
if (value) if (value)
{ {
loading.FadeIn(fade_duration, Easing.OutQuint); loading.Show();
content.FadeOut(fade_duration, Easing.OutQuint); content.FadeOut(fade_duration, Easing.OutQuint);
} }
else else
{ {
loading.FadeOut(fade_duration, Easing.OutQuint); loading.Hide();
content.FadeIn(fade_duration, Easing.OutQuint); content.FadeIn(fade_duration, Easing.OutQuint);
} }
} }
} }
private readonly Box background;
private readonly LoadingAnimation loading;
private readonly FillFlowContainer content;
private readonly ChevronIcon leftChevron;
private readonly ChevronIcon rightChevron;
private readonly SpriteText text;
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
public ShowMoreButton() public ShowMoreButton()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -77,15 +89,15 @@ namespace osu.Game.Overlays.Profile.Sections
Spacing = new Vector2(7), Spacing = new Vector2(7),
Children = new Drawable[] Children = new Drawable[]
{ {
new ChevronIcon(), leftChevron = new ChevronIcon(),
new OsuSpriteText text = new OsuSpriteText
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Text = "show more".ToUpper(), Text = "show more".ToUpper(),
}, },
new ChevronIcon(), rightChevron = new ChevronIcon(),
} }
}, },
loading = new LoadingAnimation loading = new LoadingAnimation
@ -99,13 +111,6 @@ namespace osu.Game.Overlays.Profile.Sections
}; };
} }
[BackgroundDependencyLoader]
private void load(OsuColour colors)
{
IdleColour = colors.GreySeafoamDark;
HoverColour = colors.GreySeafoam;
}
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (!Enabled.Value) if (!Enabled.Value)
@ -133,12 +138,6 @@ namespace osu.Game.Overlays.Profile.Sections
Size = new Vector2(icon_size); Size = new Vector2(icon_size);
Icon = FontAwesome.Solid.ChevronDown; Icon = FontAwesome.Solid.ChevronDown;
} }
[BackgroundDependencyLoader]
private void load(OsuColour colors)
{
Colour = colors.Yellow;
}
} }
} }
} }

View File

@ -0,0 +1,47 @@
// 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.IO.Network;
using Humanizer;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Comments;
namespace osu.Game.Online.API.Requests
{
public class GetCommentsRequest : APIRequest<CommentBundle>
{
private readonly long id;
private readonly int page;
private readonly CommentableType type;
private readonly CommentsSortCriteria sort;
public GetCommentsRequest(CommentableType type, long id, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1)
{
this.type = type;
this.sort = sort;
this.id = id;
this.page = page;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("commentable_type", type.ToString().Underscore().ToLowerInvariant());
req.AddParameter("commentable_id", id.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
req.AddParameter("page", page.ToString());
return req;
}
protected override string Target => "comments";
}
public enum CommentableType
{
Build,
Beatmapset,
NewsPost
}
}

View File

@ -0,0 +1,79 @@
// 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 Newtonsoft.Json;
using osu.Game.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
namespace osu.Game.Online.API.Requests.Responses
{
public class Comment
{
[JsonProperty(@"id")]
public long Id { get; set; }
[JsonProperty(@"parent_id")]
public long? ParentId { get; set; }
public readonly List<Comment> ChildComments = new List<Comment>();
public Comment ParentComment { get; set; }
[JsonProperty(@"user_id")]
public long? UserId { get; set; }
public User User { get; set; }
[JsonProperty(@"message")]
public string Message { get; set; }
[JsonProperty(@"message_html")]
public string MessageHtml { get; set; }
[JsonProperty(@"replies_count")]
public int RepliesCount { get; set; }
[JsonProperty(@"votes_count")]
public int VotesCount { get; set; }
[JsonProperty(@"commenatble_type")]
public string CommentableType { get; set; }
[JsonProperty(@"commentable_id")]
public int CommentableId { get; set; }
[JsonProperty(@"legacy_name")]
public string LegacyName { get; set; }
[JsonProperty(@"created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty(@"updated_at")]
public DateTimeOffset? UpdatedAt { get; set; }
[JsonProperty(@"deleted_at")]
public DateTimeOffset? DeletedAt { get; set; }
[JsonProperty(@"edited_at")]
public DateTimeOffset? EditedAt { get; set; }
[JsonProperty(@"edited_by_id")]
public long? EditedById { get; set; }
public User EditedUser { get; set; }
public bool IsTopLevel => !ParentId.HasValue;
public bool IsDeleted => DeletedAt.HasValue;
public bool HasMessage => !string.IsNullOrEmpty(MessageHtml);
public string GetMessage => HasMessage ? WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)) : string.Empty;
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
}
}

View File

@ -0,0 +1,80 @@
// 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 Newtonsoft.Json;
using osu.Game.Users;
using System.Collections.Generic;
namespace osu.Game.Online.API.Requests.Responses
{
public class CommentBundle
{
private List<Comment> comments;
[JsonProperty(@"comments")]
public List<Comment> Comments
{
get => comments;
set
{
comments = value;
comments.ForEach(child =>
{
if (child.ParentId != null)
{
comments.ForEach(parent =>
{
if (parent.Id == child.ParentId)
{
parent.ChildComments.Add(child);
child.ParentComment = parent;
}
});
}
});
}
}
[JsonProperty(@"has_more")]
public bool HasMore { get; set; }
[JsonProperty(@"has_more_id")]
public long? HasMoreId { get; set; }
[JsonProperty(@"user_follow")]
public bool UserFollow { get; set; }
[JsonProperty(@"included_comments")]
public List<Comment> IncludedComments { get; set; }
private List<User> users;
[JsonProperty(@"users")]
public List<User> Users
{
get => users;
set
{
users = value;
value.ForEach(u =>
{
Comments.ForEach(c =>
{
if (c.UserId == u.Id)
c.User = u;
if (c.EditedById == u.Id)
c.EditedUser = u;
});
});
}
}
[JsonProperty(@"total")]
public int Total { get; set; }
[JsonProperty(@"top_level_count")]
public int TopLevelCount { get; set; }
}
}

View File

@ -298,6 +298,12 @@ namespace osu.Game
public string[] HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions).ToArray(); public string[] HandledExtensions => fileImporters.SelectMany(i => i.HandledExtensions).ToArray();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
RulesetStore?.Dispose();
}
private class OsuUserInputManager : UserInputManager private class OsuUserInputManager : UserInputManager
{ {
protected override MouseButtonEventManager CreateButtonManagerFor(MouseButton button) protected override MouseButtonEventManager CreateButtonManagerFor(MouseButton button)

View File

@ -121,7 +121,7 @@ namespace osu.Game.Overlays.AccountCreation
multiAccountExplanationText.AddText("? osu! has a policy of "); multiAccountExplanationText.AddText("? osu! has a policy of ");
multiAccountExplanationText.AddText("one account per person!", cp => cp.Colour = colours.Yellow); multiAccountExplanationText.AddText("one account per person!", cp => cp.Colour = colours.Yellow);
multiAccountExplanationText.AddText(" Please be aware that creating more than one account per person may result in "); multiAccountExplanationText.AddText(" Please be aware that creating more than one account per person may result in ");
multiAccountExplanationText.AddText("permanent deactivation of accounts", cp => cp.Colour = colours.Yellow); multiAccountExplanationText.AddText("permanent deactivation of accounts", cp => cp.Colour = colours.Yellow);
multiAccountExplanationText.AddText("."); multiAccountExplanationText.AddText(".");
furtherAssistance.AddText("Need further assistance? Contact us via our "); furtherAssistance.AddText("Need further assistance? Contact us via our ");

View File

@ -0,0 +1,197 @@
// 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.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Framework.Graphics;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Online.API.Requests.Responses;
using System.Threading;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
namespace osu.Game.Overlays.Comments
{
public class CommentsContainer : CompositeDrawable
{
private readonly CommentableType type;
private readonly long id;
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
public readonly BindableBool ShowDeleted = new BindableBool();
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private OsuColour colours { get; set; }
private GetCommentsRequest request;
private CancellationTokenSource loadCancellation;
private int currentPage;
private readonly Box background;
private readonly FillFlowContainer content;
private readonly DeletedChildrenPlaceholder deletedChildrenPlaceholder;
private readonly CommentsShowMoreButton moreButton;
public CommentsContainer(CommentableType type, long id)
{
this.type = type;
this.id = id;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddRangeInternal(new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new CommentsHeader
{
Sort = { BindTarget = Sort },
ShowDeleted = { BindTarget = ShowDeleted }
},
content = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.2f)
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
deletedChildrenPlaceholder = new DeletedChildrenPlaceholder
{
ShowDeleted = { BindTarget = ShowDeleted }
},
new Container
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Child = moreButton = new CommentsShowMoreButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding(5),
Action = getComments
}
}
}
}
}
}
}
}
});
}
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colours.Gray2;
}
protected override void LoadComplete()
{
Sort.BindValueChanged(onSortChanged, true);
base.LoadComplete();
}
private void onSortChanged(ValueChangedEvent<CommentsSortCriteria> sort)
{
clearComments();
getComments();
}
private void getComments()
{
request?.Cancel();
loadCancellation?.Cancel();
request = new GetCommentsRequest(type, id, Sort.Value, currentPage++);
request.Success += onSuccess;
api.Queue(request);
}
private void clearComments()
{
currentPage = 1;
deletedChildrenPlaceholder.DeletedCount.Value = 0;
moreButton.IsLoading = true;
content.Clear();
}
private void onSuccess(CommentBundle response)
{
loadCancellation = new CancellationTokenSource();
FillFlowContainer page = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
};
foreach (var c in response.Comments)
{
if (c.IsTopLevel)
page.Add(new DrawableComment(c)
{
ShowDeleted = { BindTarget = ShowDeleted }
});
}
LoadComponentAsync(page, loaded =>
{
content.Add(loaded);
deletedChildrenPlaceholder.DeletedCount.Value += response.Comments.Count(c => c.IsDeleted && c.IsTopLevel);
if (response.HasMore)
{
int loadedTopLevelComments = 0;
content.Children.OfType<FillFlowContainer>().ForEach(p => loadedTopLevelComments += p.Children.OfType<DrawableComment>().Count());
moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
moreButton.IsLoading = false;
}
moreButton.FadeTo(response.HasMore ? 1 : 0);
}, loadCancellation.Token);
}
protected override void Dispose(bool isDisposing)
{
request?.Cancel();
loadCancellation?.Cancel();
base.Dispose(isDisposing);
}
}
}

View File

@ -0,0 +1,32 @@
// 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;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Comments
{
public class CommentsShowMoreButton : ShowMoreButton
{
public readonly BindableInt Current = new BindableInt();
public CommentsShowMoreButton()
{
IdleColour = OsuColour.Gray(0.3f);
HoverColour = OsuColour.Gray(0.4f);
ChevronIconColour = OsuColour.Gray(0.5f);
}
protected override void LoadComplete()
{
Current.BindValueChanged(onCurrentChanged, true);
base.LoadComplete();
}
private void onCurrentChanged(ValueChangedEvent<int> count)
{
Text = $@"Show More ({count.NewValue})".ToUpper();
}
}
}

View File

@ -0,0 +1,61 @@
// 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.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Framework.Graphics.Sprites;
using osuTK;
using osu.Framework.Bindables;
using Humanizer;
namespace osu.Game.Overlays.Comments
{
public class DeletedChildrenPlaceholder : FillFlowContainer
{
public readonly BindableBool ShowDeleted = new BindableBool();
public readonly BindableInt DeletedCount = new BindableInt();
private readonly SpriteText countText;
public DeletedChildrenPlaceholder()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(3, 0);
Margin = new MarginPadding { Vertical = 10, Left = 80 };
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Trash,
Size = new Vector2(14),
},
countText = new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
}
};
}
protected override void LoadComplete()
{
DeletedCount.BindValueChanged(_ => updateDisplay(), true);
ShowDeleted.BindValueChanged(_ => updateDisplay(), true);
base.LoadComplete();
}
private void updateDisplay()
{
if (DeletedCount.Value != 0)
{
countText.Text = @"deleted comment".ToQuantity(DeletedCount.Value);
this.FadeTo(ShowDeleted.Value ? 0 : 1);
}
else
{
Hide();
}
}
}
}

View File

@ -0,0 +1,363 @@
// 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.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Framework.Graphics.Sprites;
using osuTK;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Users.Drawables;
using osu.Game.Graphics.Containers;
using osu.Game.Utils;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Shapes;
using System.Linq;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Comments
{
public class DrawableComment : CompositeDrawable
{
private const int avatar_size = 40;
private const int margin = 10;
public readonly BindableBool ShowDeleted = new BindableBool();
private readonly BindableBool childrenExpanded = new BindableBool(true);
private readonly FillFlowContainer childCommentsVisibilityContainer;
private readonly Comment comment;
public DrawableComment(Comment comment)
{
LinkFlowContainer username;
FillFlowContainer childCommentsContainer;
DeletedChildrenPlaceholder deletedChildrenPlaceholder;
FillFlowContainer info;
LinkFlowContainer message;
GridContainer content;
VotePill votePill;
this.comment = comment;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(margin),
Child = content = new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Horizontal = margin },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0),
Children = new Drawable[]
{
votePill = new VotePill(comment.VotesCount)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AlwaysPresent = true,
},
new UpdateableAvatar(comment.User)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(avatar_size),
Masking = true,
CornerRadius = avatar_size / 2f,
},
}
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(0, 3),
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(7, 0),
Children = new Drawable[]
{
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
{
AutoSizeAxes = Axes.Both,
},
new ParentUsername(comment),
new SpriteText
{
Alpha = comment.IsDeleted ? 1 : 0,
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = @"deleted",
}
}
},
message = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Right = 40 }
},
info = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Colour = OsuColour.Gray(0.7f),
Children = new Drawable[]
{
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12),
Text = HumanizerUtils.Humanize(comment.CreatedAt)
},
new RepliesButton(comment.RepliesCount)
{
Expanded = { BindTarget = childrenExpanded }
},
}
}
}
}
}
}
}
},
childCommentsVisibilityContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
childCommentsContainer = new FillFlowContainer
{
Padding = new MarginPadding { Left = 20 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical
},
deletedChildrenPlaceholder = new DeletedChildrenPlaceholder
{
ShowDeleted = { BindTarget = ShowDeleted }
}
}
}
}
};
deletedChildrenPlaceholder.DeletedCount.Value = comment.DeletedChildrenCount;
if (comment.UserId.HasValue)
username.AddUserLink(comment.User);
else
username.AddText(comment.LegacyName);
if (comment.EditedAt.HasValue)
{
info.Add(new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12),
Text = $@"edited {HumanizerUtils.Humanize(comment.EditedAt.Value)} by {comment.EditedUser.Username}"
});
}
if (comment.HasMessage)
{
var formattedSource = MessageFormatter.FormatText(comment.GetMessage);
message.AddLinks(formattedSource.Text, formattedSource.Links);
}
if (comment.IsDeleted)
{
content.FadeColour(OsuColour.Gray(0.5f));
votePill.Hide();
}
if (comment.IsTopLevel)
{
AddInternal(new Container
{
RelativeSizeAxes = Axes.X,
Height = 1.5f,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.1f)
}
});
if (comment.ChildComments.Any())
{
AddInternal(new ChevronButton(comment)
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Margin = new MarginPadding { Right = 30, Top = margin },
Expanded = { BindTarget = childrenExpanded }
});
}
}
comment.ChildComments.ForEach(c => childCommentsContainer.Add(new DrawableComment(c)
{
ShowDeleted = { BindTarget = ShowDeleted }
}));
}
protected override void LoadComplete()
{
ShowDeleted.BindValueChanged(show =>
{
if (comment.IsDeleted)
this.FadeTo(show.NewValue ? 1 : 0);
}, true);
childrenExpanded.BindValueChanged(expanded => childCommentsVisibilityContainer.FadeTo(expanded.NewValue ? 1 : 0), true);
base.LoadComplete();
}
private class ChevronButton : ShowChildrenButton
{
private readonly SpriteIcon icon;
public ChevronButton(Comment comment)
{
Alpha = comment.IsTopLevel && comment.ChildComments.Any() ? 1 : 0;
Child = icon = new SpriteIcon
{
Size = new Vector2(12),
Colour = OsuColour.Gray(0.7f)
};
}
protected override void OnExpandedChanged(ValueChangedEvent<bool> expanded)
{
icon.Icon = expanded.NewValue ? FontAwesome.Solid.ChevronUp : FontAwesome.Solid.ChevronDown;
}
}
private class RepliesButton : ShowChildrenButton
{
private readonly SpriteText text;
private readonly int count;
public RepliesButton(int count)
{
this.count = count;
Alpha = count == 0 ? 0 : 1;
Child = text = new SpriteText
{
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
};
}
protected override void OnExpandedChanged(ValueChangedEvent<bool> expanded)
{
text.Text = $@"{(expanded.NewValue ? "[+]" : "[-]")} replies ({count})";
}
}
private class ParentUsername : FillFlowContainer, IHasTooltip
{
public string TooltipText => getParentMessage();
private readonly Comment parentComment;
public ParentUsername(Comment comment)
{
parentComment = comment.ParentComment;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Spacing = new Vector2(3, 0);
Alpha = comment.ParentId == null ? 0 : 1;
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.Solid.Reply,
Size = new Vector2(14),
},
new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = parentComment?.User?.Username ?? parentComment?.LegacyName
}
};
}
private string getParentMessage()
{
if (parentComment == null)
return string.Empty;
return parentComment.HasMessage ? parentComment.GetMessage : parentComment.IsDeleted ? @"deleted" : string.Empty;
}
}
private class VotePill : CircularContainer
{
public VotePill(int count)
{
AutoSizeAxes = Axes.X;
Height = 20;
Masking = true;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.05f)
},
new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = margin },
Font = OsuFont.GetFont(size: 14),
Text = $"+{count}"
}
};
}
}
}
}

View File

@ -0,0 +1,34 @@
// 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.Graphics;
using osu.Game.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Bindables;
namespace osu.Game.Overlays.Comments
{
public abstract class ShowChildrenButton : OsuHoverContainer
{
public readonly BindableBool Expanded = new BindableBool(true);
protected ShowChildrenButton()
{
AutoSizeAxes = Axes.Both;
}
protected override void LoadComplete()
{
Expanded.BindValueChanged(OnExpandedChanged, true);
base.LoadComplete();
}
protected abstract void OnExpandedChanged(ValueChangedEvent<bool> expanded);
protected override bool OnClick(ClickEvent e)
{
Expanded.Value = !Expanded.Value;
return true;
}
}
}

View File

@ -19,7 +19,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
public abstract class PaginatedContainer<TModel> : FillFlowContainer public abstract class PaginatedContainer<TModel> : FillFlowContainer
{ {
private readonly ShowMoreButton moreButton; private readonly ProfileShowMoreButton moreButton;
private readonly OsuSpriteText missingText; private readonly OsuSpriteText missingText;
private APIRequest<List<TModel>> retrievalRequest; private APIRequest<List<TModel>> retrievalRequest;
private CancellationTokenSource loadCancellation; private CancellationTokenSource loadCancellation;
@ -56,7 +56,7 @@ namespace osu.Game.Overlays.Profile.Sections
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Spacing = new Vector2(0, 2), Spacing = new Vector2(0, 2),
}, },
moreButton = new ShowMoreButton moreButton = new ProfileShowMoreButton
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,

View File

@ -0,0 +1,20 @@
// 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.Allocation;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Profile.Sections
{
public class ProfileShowMoreButton : ShowMoreButton
{
[BackgroundDependencyLoader]
private void load(OsuColour colors)
{
IdleColour = colors.GreySeafoamDark;
HoverColour = colors.GreySeafoam;
ChevronIconColour = colors.Yellow;
}
}
}

View File

@ -4,12 +4,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Configuration;
@ -22,6 +24,7 @@ using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components.RadioButtons; using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
namespace osu.Game.Rulesets.Edit namespace osu.Game.Rulesets.Edit
{ {
@ -30,16 +33,20 @@ namespace osu.Game.Rulesets.Edit
where TObject : HitObject where TObject : HitObject
{ {
protected IRulesetConfigManager Config { get; private set; } protected IRulesetConfigManager Config { get; private set; }
protected EditorBeatmap<TObject> EditorBeatmap { get; private set; }
protected readonly Ruleset Ruleset; protected readonly Ruleset Ruleset;
[Resolved]
protected IFrameBasedClock EditorClock { get; private set; }
private IWorkingBeatmap workingBeatmap; private IWorkingBeatmap workingBeatmap;
private Beatmap<TObject> playableBeatmap; private Beatmap<TObject> playableBeatmap;
private EditorBeatmap<TObject> editorBeatmap;
private IBeatmapProcessor beatmapProcessor; private IBeatmapProcessor beatmapProcessor;
private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper; private DrawableEditRulesetWrapper<TObject> drawableRulesetWrapper;
private BlueprintContainer blueprintContainer; private BlueprintContainer blueprintContainer;
private Container distanceSnapGridContainer;
private DistanceSnapGrid distanceSnapGrid;
private readonly List<Container> layerContainers = new List<Container>(); private readonly List<Container> layerContainers = new List<Container>();
private InputManager inputManager; private InputManager inputManager;
@ -57,7 +64,8 @@ namespace osu.Game.Rulesets.Edit
{ {
drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, workingBeatmap, Array.Empty<Mod>())) drawableRulesetWrapper = new DrawableEditRulesetWrapper<TObject>(CreateDrawableRuleset(Ruleset, workingBeatmap, Array.Empty<Mod>()))
{ {
Clock = framedClock Clock = framedClock,
ProcessCustomClock = false
}; };
} }
catch (Exception e) catch (Exception e)
@ -66,11 +74,13 @@ namespace osu.Game.Rulesets.Edit
return; return;
} }
var layerBelowRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer(); var layerBelowRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChildren(new Drawable[]
layerBelowRuleset.Child = new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }; {
distanceSnapGridContainer = new Container { RelativeSizeAxes = Axes.Both },
new EditorPlayfieldBorder { RelativeSizeAxes = Axes.Both }
});
var layerAboveRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer(); var layerAboveRuleset = drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer().WithChild(blueprintContainer = new BlueprintContainer());
layerAboveRuleset.Child = blueprintContainer = new BlueprintContainer();
layerContainers.Add(layerBelowRuleset); layerContainers.Add(layerBelowRuleset);
layerContainers.Add(layerAboveRuleset); layerContainers.Add(layerAboveRuleset);
@ -113,11 +123,13 @@ namespace osu.Game.Rulesets.Edit
}; };
toolboxCollection.Items = toolboxCollection.Items =
CompositionTools.Select(t => new RadioButton(t.Name, () => blueprintContainer.CurrentTool = t)) CompositionTools.Select(t => new RadioButton(t.Name, () => selectTool(t)))
.Prepend(new RadioButton("Select", () => blueprintContainer.CurrentTool = null)) .Prepend(new RadioButton("Select", () => selectTool(null)))
.ToList(); .ToList();
toolboxCollection.Items[0].Select(); toolboxCollection.Items[0].Select();
blueprintContainer.SelectionChanged += selectionChanged;
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
@ -129,14 +141,14 @@ namespace osu.Game.Rulesets.Edit
beatmapProcessor = Ruleset.CreateBeatmapProcessor(playableBeatmap); beatmapProcessor = Ruleset.CreateBeatmapProcessor(playableBeatmap);
editorBeatmap = new EditorBeatmap<TObject>(playableBeatmap); EditorBeatmap = new EditorBeatmap<TObject>(playableBeatmap);
editorBeatmap.HitObjectAdded += addHitObject; EditorBeatmap.HitObjectAdded += addHitObject;
editorBeatmap.HitObjectRemoved += removeHitObject; EditorBeatmap.HitObjectRemoved += removeHitObject;
editorBeatmap.StartTimeChanged += updateHitObject; EditorBeatmap.StartTimeChanged += updateHitObject;
var dependencies = new DependencyContainer(parent); var dependencies = new DependencyContainer(parent);
dependencies.CacheAs<IEditorBeatmap>(editorBeatmap); dependencies.CacheAs<IEditorBeatmap>(EditorBeatmap);
dependencies.CacheAs<IEditorBeatmap<TObject>>(editorBeatmap); dependencies.CacheAs<IEditorBeatmap<TObject>>(EditorBeatmap);
Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset); Config = dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
@ -150,6 +162,14 @@ namespace osu.Game.Rulesets.Edit
inputManager = GetContainingInputManager(); inputManager = GetContainingInputManager();
} }
protected override void Update()
{
base.Update();
if (EditorClock.ElapsedFrameTime != 0 && blueprintContainer.CurrentTool != null)
showGridFor(Enumerable.Empty<HitObject>());
}
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -163,19 +183,53 @@ namespace osu.Game.Rulesets.Edit
}); });
} }
private void addHitObject(HitObject hitObject) => updateHitObject(hitObject); private void selectionChanged(IEnumerable<HitObject> selectedHitObjects)
private void removeHitObject(HitObject hitObject)
{ {
beatmapProcessor?.PreProcess(); var hitObjects = selectedHitObjects.ToArray();
beatmapProcessor?.PostProcess();
if (!hitObjects.Any())
distanceSnapGridContainer.Hide();
else
showGridFor(hitObjects);
} }
private void updateHitObject(HitObject hitObject) private void selectTool(HitObjectCompositionTool tool)
{ {
beatmapProcessor?.PreProcess(); blueprintContainer.CurrentTool = tool;
hitObject.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
beatmapProcessor?.PostProcess(); if (tool == null)
distanceSnapGridContainer.Hide();
else
showGridFor(Enumerable.Empty<HitObject>());
}
private void showGridFor(IEnumerable<HitObject> selectedHitObjects)
{
distanceSnapGridContainer.Clear();
distanceSnapGrid = CreateDistanceSnapGrid(selectedHitObjects);
if (distanceSnapGrid != null)
{
distanceSnapGridContainer.Child = distanceSnapGrid;
distanceSnapGridContainer.Show();
}
}
private ScheduledDelegate scheduledUpdate;
private void addHitObject(HitObject hitObject) => updateHitObject(hitObject);
private void removeHitObject(HitObject hitObject) => updateHitObject(null);
private void updateHitObject([CanBeNull] HitObject hitObject)
{
scheduledUpdate?.Cancel();
scheduledUpdate = Schedule(() =>
{
beatmapProcessor?.PreProcess();
hitObject?.ApplyDefaults(playableBeatmap.ControlPointInfo, playableBeatmap.BeatmapInfo.BaseDifficulty);
beatmapProcessor?.PostProcess();
});
} }
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects; public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
@ -187,20 +241,30 @@ namespace osu.Game.Rulesets.Edit
public void BeginPlacement(HitObject hitObject) public void BeginPlacement(HitObject hitObject)
{ {
if (distanceSnapGrid != null)
hitObject.StartTime = GetSnappedTime(hitObject.StartTime, distanceSnapGrid.ToLocalSpace(inputManager.CurrentState.Mouse.Position));
} }
public void EndPlacement(HitObject hitObject) => editorBeatmap.Add(hitObject); public void EndPlacement(HitObject hitObject)
{
EditorBeatmap.Add(hitObject);
showGridFor(Enumerable.Empty<HitObject>());
}
public void Delete(HitObject hitObject) => editorBeatmap.Remove(hitObject); public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject);
public override Vector2 GetSnappedPosition(Vector2 position) => distanceSnapGrid?.GetSnapPosition(position) ?? position;
public override double GetSnappedTime(double startTime, Vector2 position) => distanceSnapGrid?.GetSnapTime(position) ?? startTime;
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (editorBeatmap != null) if (EditorBeatmap != null)
{ {
editorBeatmap.HitObjectAdded -= addHitObject; EditorBeatmap.HitObjectAdded -= addHitObject;
editorBeatmap.HitObjectRemoved -= removeHitObject; EditorBeatmap.HitObjectRemoved -= removeHitObject;
} }
} }
} }
@ -233,5 +297,17 @@ namespace osu.Game.Rulesets.Edit
/// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections. /// Creates a <see cref="SelectionHandler"/> which outlines <see cref="DrawableHitObject"/>s and handles movement of selections.
/// </summary> /// </summary>
public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler(); public virtual SelectionHandler CreateSelectionHandler() => new SelectionHandler();
/// <summary>
/// Creates the <see cref="DistanceSnapGrid"/> applicable for a <see cref="HitObject"/> selection.
/// </summary>
/// <param name="selectedHitObjects">The <see cref="HitObject"/> selection.</param>
/// <returns>The <see cref="DistanceSnapGrid"/> for <paramref name="selectedHitObjects"/>.</returns>
[CanBeNull]
protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null;
public abstract Vector2 GetSnappedPosition(Vector2 position);
public abstract double GetSnappedTime(double startTime, Vector2 screenSpacePosition);
} }
} }

View File

@ -91,8 +91,10 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// Signals that the placement of <see cref="HitObject"/> has started. /// Signals that the placement of <see cref="HitObject"/> has started.
/// </summary> /// </summary>
protected void BeginPlacement() /// <param name="startTime">The start time of <see cref="HitObject"/> at the placement point. If null, the current clock time is used.</param>
protected void BeginPlacement(double? startTime = null)
{ {
HitObject.StartTime = startTime ?? EditorClock.CurrentTime;
placementHandler.BeginPlacement(HitObject); placementHandler.BeginPlacement(HitObject);
PlacementBegun = true; PlacementBegun = true;
} }

View File

@ -43,20 +43,20 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to. /// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
/// </summary> /// </summary>
public readonly DrawableHitObject HitObject; public readonly DrawableHitObject DrawableObject;
/// <summary> /// <summary>
/// The screen-space position of <see cref="HitObject"/> prior to handling a movement event. /// The screen-space position of <see cref="DrawableObject"/> prior to handling a movement event.
/// </summary> /// </summary>
internal Vector2 ScreenSpaceMovementStartPosition { get; private set; } internal Vector2 ScreenSpaceMovementStartPosition { get; private set; }
protected override bool ShouldBeAlive => (HitObject.IsAlive && HitObject.IsPresent) || State == SelectionState.Selected; protected override bool ShouldBeAlive => (DrawableObject.IsAlive && DrawableObject.IsPresent) || State == SelectionState.Selected;
public override bool HandlePositionalInput => ShouldBeAlive; public override bool HandlePositionalInput => ShouldBeAlive;
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
protected SelectionBlueprint(DrawableHitObject hitObject) protected SelectionBlueprint(DrawableHitObject drawableObject)
{ {
HitObject = hitObject; DrawableObject = drawableObject;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -107,7 +107,7 @@ namespace osu.Game.Rulesets.Edit
public bool IsSelected => State == SelectionState.Selected; public bool IsSelected => State == SelectionState.Selected;
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => HitObject.ReceivePositionalInputAt(screenSpacePos); public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => DrawableObject.ReceivePositionalInputAt(screenSpacePos);
private bool selectionRequested; private bool selectionRequested;
@ -138,7 +138,7 @@ namespace osu.Game.Rulesets.Edit
protected override bool OnDragStart(DragStartEvent e) protected override bool OnDragStart(DragStartEvent e)
{ {
ScreenSpaceMovementStartPosition = HitObject.ToScreenSpace(HitObject.OriginPosition); ScreenSpaceMovementStartPosition = DrawableObject.ToScreenSpace(DrawableObject.OriginPosition);
return true; return true;
} }
@ -151,11 +151,11 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected. /// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
/// </summary> /// </summary>
public virtual Vector2 SelectionPoint => HitObject.ScreenSpaceDrawQuad.Centre; public virtual Vector2 SelectionPoint => DrawableObject.ScreenSpaceDrawQuad.Centre;
/// <summary> /// <summary>
/// The screen-space quad that outlines this <see cref="SelectionBlueprint"/> for selections. /// The screen-space quad that outlines this <see cref="SelectionBlueprint"/> for selections.
/// </summary> /// </summary>
public virtual Quad SelectionQuad => HitObject.ScreenSpaceDrawQuad; public virtual Quad SelectionQuad => DrawableObject.ScreenSpaceDrawQuad;
} }
} }

View File

@ -4,6 +4,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Extensions.TypeExtensions;
@ -37,7 +39,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
protected virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples; protected virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples;
private readonly Lazy<List<DrawableHitObject>> nestedHitObjects = new Lazy<List<DrawableHitObject>>(); private readonly Lazy<List<DrawableHitObject>> nestedHitObjects = new Lazy<List<DrawableHitObject>>();
public IEnumerable<DrawableHitObject> NestedHitObjects => nestedHitObjects.IsValueCreated ? nestedHitObjects.Value : Enumerable.Empty<DrawableHitObject>(); public IReadOnlyList<DrawableHitObject> NestedHitObjects => nestedHitObjects.IsValueCreated ? nestedHitObjects.Value : (IReadOnlyList<DrawableHitObject>)Array.Empty<DrawableHitObject>();
/// <summary> /// <summary>
/// Invoked when a <see cref="JudgementResult"/> has been applied by this <see cref="DrawableHitObject"/> or a nested <see cref="DrawableHitObject"/>. /// Invoked when a <see cref="JudgementResult"/> has been applied by this <see cref="DrawableHitObject"/> or a nested <see cref="DrawableHitObject"/>.
@ -76,6 +78,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
public JudgementResult Result { get; private set; } public JudgementResult Result { get; private set; }
private Bindable<double> startTimeBindable;
private Bindable<int> comboIndexBindable; private Bindable<int> comboIndexBindable;
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
@ -88,9 +91,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
public IBindable<ArmedState> State => state; public IBindable<ArmedState> State => state;
protected DrawableHitObject(HitObject hitObject) protected DrawableHitObject([NotNull] HitObject hitObject)
{ {
HitObject = hitObject; HitObject = hitObject ?? throw new ArgumentNullException(nameof(hitObject));
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -125,13 +128,83 @@ namespace osu.Game.Rulesets.Objects.Drawables
{ {
base.LoadComplete(); base.LoadComplete();
HitObject.DefaultsApplied += onDefaultsApplied;
startTimeBindable = HitObject.StartTimeBindable.GetBoundCopy();
startTimeBindable.BindValueChanged(_ => updateState(ArmedState.Idle, true));
if (HitObject is IHasComboInformation combo) if (HitObject is IHasComboInformation combo)
{ {
comboIndexBindable = combo.ComboIndexBindable.GetBoundCopy(); comboIndexBindable = combo.ComboIndexBindable.GetBoundCopy();
comboIndexBindable.BindValueChanged(_ => updateAccentColour()); comboIndexBindable.BindValueChanged(_ => updateAccentColour(), true);
} }
updateState(ArmedState.Idle, true); updateState(ArmedState.Idle, true);
onDefaultsApplied();
}
private void onDefaultsApplied() => apply(HitObject);
private void apply(HitObject hitObject)
{
#pragma warning disable 618 // can be removed 20200417
if (GetType().GetMethod(nameof(AddNested), BindingFlags.NonPublic | BindingFlags.Instance)?.DeclaringType != typeof(DrawableHitObject))
return;
#pragma warning restore 618
if (nestedHitObjects.IsValueCreated)
{
nestedHitObjects.Value.Clear();
ClearNestedHitObjects();
}
foreach (var h in hitObject.NestedHitObjects)
{
var drawableNested = CreateNestedHitObject(h) ?? throw new InvalidOperationException($"{nameof(CreateNestedHitObject)} returned null for {h.GetType().ReadableName()}.");
addNested(drawableNested);
AddNestedHitObject(drawableNested);
}
}
/// <summary>
/// Invoked by the base <see cref="DrawableHitObject"/> to add nested <see cref="DrawableHitObject"/>s to the hierarchy.
/// </summary>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to be added.</param>
protected virtual void AddNestedHitObject(DrawableHitObject hitObject)
{
}
/// <summary>
/// Adds a nested <see cref="DrawableHitObject"/>. This should not be used except for legacy nested <see cref="DrawableHitObject"/> usages.
/// </summary>
/// <param name="h"></param>
[Obsolete("Use AddNestedHitObject() / ClearNestedHitObjects() / CreateNestedHitObject() instead.")] // can be removed 20200417
protected virtual void AddNested(DrawableHitObject h) => addNested(h);
/// <summary>
/// Invoked by the base <see cref="DrawableHitObject"/> to remove all previously-added nested <see cref="DrawableHitObject"/>s.
/// </summary>
protected virtual void ClearNestedHitObjects()
{
}
/// <summary>
/// Creates the drawable representation for a nested <see cref="HitObject"/>.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/>.</param>
/// <returns>The drawable representation for <paramref name="hitObject"/>.</returns>
protected virtual DrawableHitObject CreateNestedHitObject(HitObject hitObject) => null;
private void addNested(DrawableHitObject hitObject)
{
// Todo: Exists for legacy purposes, can be removed 20200417
hitObject.OnNewResult += (d, r) => OnNewResult?.Invoke(d, r);
hitObject.OnRevertResult += (d, r) => OnRevertResult?.Invoke(d, r);
hitObject.ApplyCustomUpdateState += (d, j) => ApplyCustomUpdateState?.Invoke(d, j);
nestedHitObjects.Value.Add(hitObject);
} }
#region State / Transform Management #region State / Transform Management
@ -356,15 +429,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
UpdateResult(false); UpdateResult(false);
} }
protected virtual void AddNested(DrawableHitObject h)
{
h.OnNewResult += (d, r) => OnNewResult?.Invoke(d, r);
h.OnRevertResult += (d, r) => OnRevertResult?.Invoke(d, r);
h.ApplyCustomUpdateState += (d, j) => ApplyCustomUpdateState?.Invoke(d, j);
nestedHitObjects.Value.Add(h);
}
/// <summary> /// <summary>
/// Applies the <see cref="Result"/> of this <see cref="DrawableHitObject"/>, notifying responders such as /// Applies the <see cref="Result"/> of this <see cref="DrawableHitObject"/>, notifying responders such as
/// the <see cref="ScoreProcessor"/> of the <see cref="JudgementResult"/>. /// the <see cref="ScoreProcessor"/> of the <see cref="JudgementResult"/>.
@ -437,6 +501,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
/// <param name="judgement">The <see cref="Judgement"/> that provides the scoring information.</param> /// <param name="judgement">The <see cref="Judgement"/> that provides the scoring information.</param>
protected virtual JudgementResult CreateResult(Judgement judgement) => new JudgementResult(HitObject, judgement); protected virtual JudgementResult CreateResult(Judgement judgement) => new JudgementResult(HitObject, judgement);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
HitObject.DefaultsApplied -= onDefaultsApplied;
}
} }
public abstract class DrawableHitObject<TObject> : DrawableHitObject public abstract class DrawableHitObject<TObject> : DrawableHitObject

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
@ -28,6 +29,11 @@ namespace osu.Game.Rulesets.Objects
/// </summary> /// </summary>
private const double control_point_leniency = 1; private const double control_point_leniency = 1;
/// <summary>
/// Invoked after <see cref="ApplyDefaults"/> has completed on this <see cref="HitObject"/>.
/// </summary>
public event Action DefaultsApplied;
public readonly Bindable<double> StartTimeBindable = new Bindable<double>(); public readonly Bindable<double> StartTimeBindable = new Bindable<double>();
/// <summary> /// <summary>
@ -113,6 +119,8 @@ namespace osu.Game.Rulesets.Objects
foreach (var h in nestedHitObjects) foreach (var h in nestedHitObjects)
h.ApplyDefaults(controlPointInfo, difficulty); h.ApplyDefaults(controlPointInfo, difficulty);
DefaultsApplied?.Invoke();
} }
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)

View File

@ -11,28 +11,22 @@ using osu.Game.Database;
namespace osu.Game.Rulesets namespace osu.Game.Rulesets
{ {
/// <summary> public class RulesetStore : DatabaseBackedStore, IDisposable
/// Todo: All of this needs to be moved to a RulesetStore.
/// </summary>
public class RulesetStore : DatabaseBackedStore
{ {
private static readonly Dictionary<Assembly, Type> loaded_assemblies = new Dictionary<Assembly, Type>(); private const string ruleset_library_prefix = "osu.Game.Rulesets";
static RulesetStore() private readonly Dictionary<Assembly, Type> loadedAssemblies = new Dictionary<Assembly, Type>();
{
AppDomain.CurrentDomain.AssemblyResolve += currentDomain_AssemblyResolve;
// On android in release configuration assemblies are loaded from the apk directly into memory.
// We cannot read assemblies from cwd, so should check loaded assemblies instead.
loadFromAppDomain();
loadFromDisk();
}
public RulesetStore(IDatabaseContextFactory factory) public RulesetStore(IDatabaseContextFactory factory)
: base(factory) : base(factory)
{ {
// On android in release configuration assemblies are loaded from the apk directly into memory.
// We cannot read assemblies from cwd, so should check loaded assemblies instead.
loadFromAppDomain();
loadFromDisk();
addMissingRulesets(); addMissingRulesets();
AppDomain.CurrentDomain.AssemblyResolve += resolveRulesetAssembly;
} }
/// <summary> /// <summary>
@ -54,9 +48,7 @@ namespace osu.Game.Rulesets
/// </summary> /// </summary>
public IEnumerable<RulesetInfo> AvailableRulesets { get; private set; } public IEnumerable<RulesetInfo> AvailableRulesets { get; private set; }
private static Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args) => loaded_assemblies.Keys.FirstOrDefault(a => a.FullName == args.Name); private Assembly resolveRulesetAssembly(object sender, ResolveEventArgs args) => loadedAssemblies.Keys.FirstOrDefault(a => a.FullName == args.Name);
private const string ruleset_library_prefix = "osu.Game.Rulesets";
private void addMissingRulesets() private void addMissingRulesets()
{ {
@ -64,7 +56,7 @@ namespace osu.Game.Rulesets
{ {
var context = usage.Context; var context = usage.Context;
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, (RulesetInfo)null)).ToList(); var instances = loadedAssemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, (RulesetInfo)null)).ToList();
//add all legacy modes in correct order //add all legacy modes in correct order
foreach (var r in instances.Where(r => r.LegacyID != null).OrderBy(r => r.LegacyID)) foreach (var r in instances.Where(r => r.LegacyID != null).OrderBy(r => r.LegacyID))
@ -113,7 +105,7 @@ namespace osu.Game.Rulesets
} }
} }
private static void loadFromAppDomain() private void loadFromAppDomain()
{ {
foreach (var ruleset in AppDomain.CurrentDomain.GetAssemblies()) foreach (var ruleset in AppDomain.CurrentDomain.GetAssemblies())
{ {
@ -126,7 +118,7 @@ namespace osu.Game.Rulesets
} }
} }
private static void loadFromDisk() private void loadFromDisk()
{ {
try try
{ {
@ -141,11 +133,11 @@ namespace osu.Game.Rulesets
} }
} }
private static void loadRulesetFromFile(string file) private void loadRulesetFromFile(string file)
{ {
var filename = Path.GetFileNameWithoutExtension(file); var filename = Path.GetFileNameWithoutExtension(file);
if (loaded_assemblies.Values.Any(t => t.Namespace == filename)) if (loadedAssemblies.Values.Any(t => t.Namespace == filename))
return; return;
try try
@ -158,19 +150,30 @@ namespace osu.Game.Rulesets
} }
} }
private static void addRuleset(Assembly assembly) private void addRuleset(Assembly assembly)
{ {
if (loaded_assemblies.ContainsKey(assembly)) if (loadedAssemblies.ContainsKey(assembly))
return; return;
try try
{ {
loaded_assemblies[assembly] = assembly.GetTypes().First(t => t.IsPublic && t.IsSubclassOf(typeof(Ruleset))); loadedAssemblies[assembly] = assembly.GetTypes().First(t => t.IsPublic && t.IsSubclassOf(typeof(Ruleset)));
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Error(e, $"Failed to add ruleset {assembly}"); Logger.Error(e, $"Failed to add ruleset {assembly}");
} }
} }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetAssembly;
}
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -14,20 +15,20 @@ using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools; using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
public class BlueprintContainer : CompositeDrawable public class BlueprintContainer : CompositeDrawable
{ {
private SelectionBlueprintContainer selectionBlueprints; public event Action<IEnumerable<HitObject>> SelectionChanged;
private SelectionBlueprintContainer selectionBlueprints;
private Container<PlacementBlueprint> placementBlueprintContainer; private Container<PlacementBlueprint> placementBlueprintContainer;
private PlacementBlueprint currentPlacement; private PlacementBlueprint currentPlacement;
private SelectionHandler selectionHandler; private SelectionHandler selectionHandler;
private InputManager inputManager; private InputManager inputManager;
private IEnumerable<SelectionBlueprint> selections => selectionBlueprints.Children.Where(c => c.IsAlive);
[Resolved] [Resolved]
private HitObjectComposer composer { get; set; } private HitObjectComposer composer { get; set; }
@ -101,7 +102,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void removeBlueprintFor(HitObject hitObject) private void removeBlueprintFor(HitObject hitObject)
{ {
var blueprint = selectionBlueprints.Single(m => m.HitObject.HitObject == hitObject); var blueprint = selectionBlueprints.Single(m => m.DrawableObject.HitObject == hitObject);
if (blueprint == null) if (blueprint == null)
return; return;
@ -143,7 +144,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
if (currentPlacement != null) if (currentPlacement != null)
{ {
currentPlacement.UpdatePosition(e.ScreenSpaceMousePosition); updatePlacementPosition(e.ScreenSpaceMousePosition);
return true; return true;
} }
@ -178,19 +179,27 @@ namespace osu.Game.Screens.Edit.Compose.Components
placementBlueprintContainer.Child = currentPlacement = blueprint; placementBlueprintContainer.Child = currentPlacement = blueprint;
// Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame // Fixes a 1-frame position discrepancy due to the first mouse move event happening in the next frame
blueprint.UpdatePosition(inputManager.CurrentState.Mouse.Position); updatePlacementPosition(inputManager.CurrentState.Mouse.Position);
} }
} }
private void updatePlacementPosition(Vector2 screenSpacePosition)
{
Vector2 snappedGridPosition = composer.GetSnappedPosition(ToLocalSpace(screenSpacePosition));
Vector2 snappedScreenSpacePosition = ToScreenSpace(snappedGridPosition);
currentPlacement.UpdatePosition(snappedScreenSpacePosition);
}
/// <summary> /// <summary>
/// Select all masks in a given rectangle selection area. /// Select all masks in a given rectangle selection area.
/// </summary> /// </summary>
/// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param> /// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param>
private void select(RectangleF rect) private void select(RectangleF rect)
{ {
foreach (var blueprint in selections.ToList()) foreach (var blueprint in selectionBlueprints)
{ {
if (blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint)) if (blueprint.IsAlive && blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint))
blueprint.Select(); blueprint.Select();
else else
blueprint.Deselect(); blueprint.Deselect();
@ -200,27 +209,40 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary> /// <summary>
/// Deselects all selected <see cref="SelectionBlueprint"/>s. /// Deselects all selected <see cref="SelectionBlueprint"/>s.
/// </summary> /// </summary>
private void deselectAll() => selections.ToList().ForEach(m => m.Deselect()); private void deselectAll() => selectionHandler.SelectedBlueprints.ToList().ForEach(m => m.Deselect());
private void onBlueprintSelected(SelectionBlueprint blueprint) private void onBlueprintSelected(SelectionBlueprint blueprint)
{ {
selectionHandler.HandleSelected(blueprint); selectionHandler.HandleSelected(blueprint);
selectionBlueprints.ChangeChildDepth(blueprint, 1); selectionBlueprints.ChangeChildDepth(blueprint, 1);
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
} }
private void onBlueprintDeselected(SelectionBlueprint blueprint) private void onBlueprintDeselected(SelectionBlueprint blueprint)
{ {
selectionHandler.HandleDeselected(blueprint); selectionHandler.HandleDeselected(blueprint);
selectionBlueprints.ChangeChildDepth(blueprint, 0); selectionBlueprints.ChangeChildDepth(blueprint, 0);
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
} }
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state); private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state);
private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent) private void onDragRequested(SelectionBlueprint blueprint, DragEvent dragEvent)
{ {
var movePosition = blueprint.ScreenSpaceMovementStartPosition + dragEvent.ScreenSpaceMousePosition - dragEvent.ScreenSpaceMouseDownPosition; HitObject draggedObject = blueprint.DrawableObject.HitObject;
selectionHandler.HandleMovement(new MoveSelectionEvent(blueprint, blueprint.ScreenSpaceMovementStartPosition, movePosition)); Vector2 movePosition = blueprint.ScreenSpaceMovementStartPosition + dragEvent.ScreenSpaceMousePosition - dragEvent.ScreenSpaceMouseDownPosition;
Vector2 snappedPosition = composer.GetSnappedPosition(ToLocalSpace(movePosition));
// Move the hitobjects
selectionHandler.HandleMovement(new MoveSelectionEvent(blueprint, blueprint.ScreenSpaceMovementStartPosition, ToScreenSpace(snappedPosition)));
// Apply the start time at the newly snapped-to position
double offset = composer.GetSnappedTime(draggedObject.StartTime, snappedPosition) - draggedObject.StartTime;
foreach (HitObject obj in selectionHandler.SelectedHitObjects)
obj.StartTime += offset;
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
@ -252,7 +274,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
return d; return d;
// Put earlier hitobjects towards the end of the list, so they handle input first // Put earlier hitobjects towards the end of the list, so they handle input first
int i = y.HitObject.HitObject.StartTime.CompareTo(x.HitObject.HitObject.StartTime); int i = y.DrawableObject.HitObject.StartTime.CompareTo(x.DrawableObject.HitObject.StartTime);
return i == 0 ? CompareReverseChildID(x, y) : i; return i == 0 ? CompareReverseChildID(x, y) : i;
} }
} }

View File

@ -0,0 +1,59 @@
// 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 System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Rulesets.Objects;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components
{
public abstract class CircularDistanceSnapGrid : DistanceSnapGrid
{
protected CircularDistanceSnapGrid(HitObject hitObject, Vector2 centrePosition)
: base(hitObject, centrePosition)
{
}
protected override void CreateContent(Vector2 centrePosition)
{
float dx = Math.Max(centrePosition.X, DrawWidth - centrePosition.X);
float dy = Math.Max(centrePosition.Y, DrawHeight - centrePosition.Y);
float maxDistance = new Vector2(dx, dy).Length;
int requiredCircles = (int)(maxDistance / DistanceSpacing);
for (int i = 0; i < requiredCircles; i++)
{
float radius = (i + 1) * DistanceSpacing * 2;
AddInternal(new CircularProgress
{
Origin = Anchor.Centre,
Position = centrePosition,
Current = { Value = 1 },
Size = new Vector2(radius),
InnerRadius = 4 * 1f / radius,
Colour = GetColourForBeatIndex(i)
});
}
}
public override Vector2 GetSnapPosition(Vector2 position)
{
Vector2 direction = position - CentrePosition;
if (direction == Vector2.Zero)
direction = new Vector2(0.001f, 0.001f);
float distance = direction.Length;
float radius = DistanceSpacing;
int radialCount = Math.Max(1, (int)Math.Round(distance / radius));
Vector2 normalisedDirection = direction * new Vector2(1f / distance);
return CentrePosition + normalisedDirection * radialCount * radius;
}
}
}

View File

@ -15,7 +15,10 @@ using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
public abstract class BeatSnapGrid : CompositeDrawable /// <summary>
/// A grid which takes user input and returns a quantized ("snapped") position and time.
/// </summary>
public abstract class DistanceSnapGrid : CompositeDrawable
{ {
/// <summary> /// <summary>
/// The velocity of the beatmap at the point of placement in pixels per millisecond. /// The velocity of the beatmap at the point of placement in pixels per millisecond.
@ -48,7 +51,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private double startTime; private double startTime;
private double beatLength; private double beatLength;
protected BeatSnapGrid(HitObject hitObject, Vector2 centrePosition) protected DistanceSnapGrid(HitObject hitObject, Vector2 centrePosition)
{ {
this.hitObject = hitObject; this.hitObject = hitObject;
this.CentrePosition = centrePosition; this.CentrePosition = centrePosition;
@ -114,14 +117,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary> /// <summary>
/// Snaps a position to this grid. /// Snaps a position to this grid.
/// </summary> /// </summary>
/// <param name="position">The original position in coordinate space local to this <see cref="BeatSnapGrid"/>.</param> /// <param name="position">The original position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</param>
/// <returns>The snapped position in coordinate space local to this <see cref="BeatSnapGrid"/>.</returns> /// <returns>The snapped position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</returns>
public abstract Vector2 GetSnapPosition(Vector2 position); public abstract Vector2 GetSnapPosition(Vector2 position);
/// <summary> /// <summary>
/// Retrieves the time at a snapped position. /// Retrieves the time at a snapped position.
/// </summary> /// </summary>
/// <param name="position">The snapped position in coordinate space local to this <see cref="BeatSnapGrid"/>.</param> /// <param name="position">The snapped position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</param>
/// <returns>The time at the snapped position.</returns> /// <returns>The time at the snapped position.</returns>
public double GetSnapTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity; public double GetSnapTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity;

View File

@ -40,7 +40,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
ScreenSpaceStartPosition = screenSpaceStartPosition; ScreenSpaceStartPosition = screenSpaceStartPosition;
ScreenSpacePosition = screenSpacePosition; ScreenSpacePosition = screenSpacePosition;
InstantDelta = Blueprint.HitObject.Parent.ToLocalSpace(ScreenSpacePosition) - Blueprint.HitObject.Position; InstantDelta = Blueprint.DrawableObject.Parent.ToLocalSpace(ScreenSpacePosition) - Blueprint.DrawableObject.Position;
} }
} }
} }

View File

@ -26,10 +26,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
public const float BORDER_RADIUS = 2; public const float BORDER_RADIUS = 2;
protected IEnumerable<SelectionBlueprint> SelectedBlueprints => selectedBlueprints; public IEnumerable<SelectionBlueprint> SelectedBlueprints => selectedBlueprints;
private readonly List<SelectionBlueprint> selectedBlueprints; private readonly List<SelectionBlueprint> selectedBlueprints;
protected IEnumerable<HitObject> SelectedHitObjects => selectedBlueprints.Select(b => b.HitObject.HitObject); public IEnumerable<HitObject> SelectedHitObjects => selectedBlueprints.Select(b => b.DrawableObject.HitObject);
private Drawable outline; private Drawable outline;
@ -81,7 +81,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
case Key.Delete: case Key.Delete:
foreach (var h in selectedBlueprints.ToList()) foreach (var h in selectedBlueprints.ToList())
placementHandler.Delete(h.HitObject.HitObject); placementHandler.Delete(h.DrawableObject.HitObject);
return true; return true;
} }

View File

@ -173,6 +173,12 @@ namespace osu.Game.Screens.Edit
bottomBackground.Colour = colours.Gray2; bottomBackground.Colour = colours.Gray2;
} }
protected override void Update()
{
base.Update();
clock.ProcessFrame();
}
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
switch (e.Key) switch (e.Key)

View File

@ -26,7 +26,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.1011.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.1021.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" /> <PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -118,8 +118,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2019.1010.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.1011.0" /> <PackageReference Include="ppy.osu.Framework" Version="2019.1021.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.1011.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2019.1021.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" /> <PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.11.0" /> <PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />