1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00

Merge branch 'master' into low-hp-red-layer

This commit is contained in:
Dan Balasescu 2020-04-14 14:47:01 +09:00 committed by GitHub
commit ac8a3efc46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
135 changed files with 3863 additions and 794 deletions

View File

@ -51,7 +51,7 @@
<Reference Include="Java.Interop" /> <Reference Include="Java.Interop" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.403.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2020.412.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2020.407.1" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2020.411.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" /> <PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="nunit" Version="3.12.0" /> <PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
</ItemGroup> </ItemGroup>

View File

@ -70,6 +70,8 @@ namespace osu.Game.Rulesets.Catch.Objects.Drawables
public float DisplayRadius => DrawSize.X / 2 * Scale.X * HitObject.Scale; public float DisplayRadius => DrawSize.X / 2 * Scale.X * HitObject.Scale;
protected override float SamplePlaybackPosition => HitObject.X;
protected DrawableCatchHitObject(CatchHitObject hitObject) protected DrawableCatchHitObject(CatchHitObject hitObject)
: base(hitObject) : base(hitObject)
{ {

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -31,6 +31,7 @@ namespace osu.Game.Rulesets.Mania.Tests.Skinning
{ {
typeof(ManiaRuleset), typeof(ManiaRuleset),
typeof(ManiaLegacySkinTransformer), typeof(ManiaLegacySkinTransformer),
typeof(ManiaSettingsSubsection)
}; };
protected override Ruleset CreateRulesetForSkinProvider() => new ManiaRuleset(); protected override Ruleset CreateRulesetForSkinProvider() => new ManiaRuleset();

View File

@ -0,0 +1,35 @@
// 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 System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Skinning;
using osu.Game.Rulesets.Mania.UI.Components;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.Tests.Skinning
{
public class TestSceneStageBackground : ManiaSkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Concat(new[]
{
typeof(DefaultStageBackground),
typeof(LegacyStageBackground),
}).ToList();
[BackgroundDependencyLoader]
private void load()
{
SetContents(() => new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.StageBackground), _ => new DefaultStageBackground())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
});
}
}
}

View File

@ -0,0 +1,33 @@
// 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 System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mania.Skinning;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Mania.Tests.Skinning
{
public class TestSceneStageForeground : ManiaSkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Concat(new[]
{
typeof(LegacyStageForeground),
}).ToList();
[BackgroundDependencyLoader]
private void load()
{
SetContents(() => new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.StageForeground), _ => null)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Width = 0.5f,
});
}
}
}

View File

@ -45,6 +45,7 @@ namespace osu.Game.Rulesets.Mania.Edit.Blueprints
new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = 1, BorderThickness = 1,
BorderColour = colours.Yellow, BorderColour = colours.Yellow,
Child = new Box Child = new Box

View File

@ -39,6 +39,8 @@ namespace osu.Game.Rulesets.Mania
HoldNoteHead, HoldNoteHead,
HoldNoteTail, HoldNoteTail,
HoldNoteBody, HoldNoteBody,
HitExplosion HitExplosion,
StageBackground,
StageForeground,
} }
} }

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Objects.Drawables namespace osu.Game.Rulesets.Mania.Objects.Drawables
{ {
@ -24,6 +25,20 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>(); protected readonly IBindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
[Resolved(canBeNull: true)]
private ManiaPlayfield playfield { get; set; }
protected override float SamplePlaybackPosition
{
get
{
if (playfield == null)
return base.SamplePlaybackPosition;
return (float)HitObject.Column / playfield.TotalColumns;
}
}
protected DrawableManiaHitObject(ManiaHitObject hitObject) protected DrawableManiaHitObject(ManiaHitObject hitObject)
: base(hitObject) : base(hitObject)
{ {

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.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Mania.Skinning
{
public class LegacyStageBackground : LegacyManiaElement
{
private Drawable leftSprite;
private Drawable rightSprite;
public LegacyStageBackground()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin)
{
string leftImage = GetManiaSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.LeftStageImage)?.Value
?? "mania-stage-left";
string rightImage = GetManiaSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.RightStageImage)?.Value
?? "mania-stage-right";
InternalChildren = new[]
{
leftSprite = new Sprite
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopRight,
X = 0.05f,
Texture = skin.GetTexture(leftImage),
},
rightSprite = new Sprite
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopLeft,
X = -0.05f,
Texture = skin.GetTexture(rightImage)
}
};
}
protected override void Update()
{
base.Update();
if (leftSprite?.Height > 0)
leftSprite.Scale = new Vector2(DrawHeight / leftSprite.Height);
if (rightSprite?.Height > 0)
rightSprite.Scale = new Vector2(DrawHeight / rightSprite.Height);
}
}
}

View File

@ -0,0 +1,56 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Mania.Skinning
{
public class LegacyStageForeground : LegacyManiaElement
{
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
private Drawable sprite;
public LegacyStageForeground()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, IScrollingInfo scrollingInfo)
{
string bottomImage = GetManiaSkinConfig<string>(skin, LegacyManiaSkinConfigurationLookups.BottomStageImage)?.Value
?? "mania-stage-bottom";
sprite = skin.GetAnimation(bottomImage, true, true)?.With(d =>
{
if (d == null)
return;
d.Scale = new Vector2(1.6f);
});
if (sprite != null)
InternalChild = sprite;
direction.BindTo(scrollingInfo.Direction);
direction.BindValueChanged(onDirectionChanged, true);
}
private void onDirectionChanged(ValueChangedEvent<ScrollingDirection> direction)
{
if (sprite == null)
return;
if (direction.NewValue == ScrollingDirection.Up)
sprite.Anchor = sprite.Origin = Anchor.TopCentre;
else
sprite.Anchor = sprite.Origin = Anchor.BottomCentre;
}
}
}

View File

@ -81,6 +81,12 @@ namespace osu.Game.Rulesets.Mania.Skinning
case ManiaSkinComponents.HitExplosion: case ManiaSkinComponents.HitExplosion:
return new LegacyHitExplosion(); return new LegacyHitExplosion();
case ManiaSkinComponents.StageBackground:
return new LegacyStageBackground();
case ManiaSkinComponents.StageForeground:
return new LegacyStageForeground();
} }
break; break;

View File

@ -0,0 +1,30 @@
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Mania.UI.Components
{
public class DefaultStageBackground : CompositeDrawable
{
public DefaultStageBackground()
{
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load()
{
InternalChild = new Box
{
Name = "Background",
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black
};
}
}
}

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics.Containers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
@ -14,6 +15,7 @@ using osuTK;
namespace osu.Game.Rulesets.Mania.UI namespace osu.Game.Rulesets.Mania.UI
{ {
[Cached]
public class ManiaPlayfield : ScrollingPlayfield public class ManiaPlayfield : ScrollingPlayfield
{ {
private readonly List<Stage> stages = new List<Stage>(); private readonly List<Stage> stages = new List<Stage>();

View File

@ -6,7 +6,6 @@ using System.Linq;
using osu.Framework.Allocation; 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.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects;
@ -72,11 +71,9 @@ namespace osu.Game.Rulesets.Mania.UI
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.StageBackground), _ => new DefaultStageBackground())
{ {
Name = "Background", RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black
}, },
columnFlow = new FillFlowContainer<Column> columnFlow = new FillFlowContainer<Column>
{ {
@ -103,6 +100,10 @@ namespace osu.Game.Rulesets.Mania.UI
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
} }
}, },
new SkinnableDrawable(new ManiaSkinComponent(ManiaSkinComponents.StageForeground), _ => null)
{
RelativeSizeAxes = Axes.Both
},
judgements = new JudgementContainer<DrawableManiaJudgement> judgements = new JudgementContainer<DrawableManiaJudgement>
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,

View File

@ -0,0 +1,412 @@
// 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 System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Screens;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Replays;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneOutOfOrderHits : RateAdjustedBeatmapTestScene
{
private const double early_miss_window = 1000; // time after -1000 to -500 is considered a miss
private const double late_miss_window = 500; // time after +500 is considered a miss
/// <summary>
/// Tests clicking a future circle before the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 100, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Miss);
addJudgementOffsetAssert(hitObjects[0], late_miss_window);
}
/// <summary>
/// Tests clicking a future circle at the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAtFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 0);
}
/// <summary>
/// Tests clicking a future circle after the first circle's start time, while the first circle HAS NOT been judged.
/// </summary>
[Test]
public void TestClickSecondCircleAfterFirstCircleTime()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle + 100, Position = positionSecondCircle, Actions = { OsuAction.LeftButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Miss);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], 100);
}
/// <summary>
/// Tests clicking a future circle before the first circle's start time, while the first circle HAS been judged.
/// </summary>
[Test]
public void TestClickSecondCircleBeforeFirstCircleTimeWithFirstCircleJudged()
{
const double time_first_circle = 1500;
const double time_second_circle = 1600;
Vector2 positionFirstCircle = Vector2.Zero;
Vector2 positionSecondCircle = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_first_circle,
Position = positionFirstCircle
},
new TestHitCircle
{
StartTime = time_second_circle,
Position = positionSecondCircle
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_first_circle - 200, Position = positionFirstCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_first_circle - 100, Position = positionSecondCircle, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementOffsetAssert(hitObjects[0], -200); // time_first_circle - 200
addJudgementOffsetAssert(hitObjects[0], -200); // time_second_circle - first_circle_time - 100
}
/// <summary>
/// Tests clicking a future circle after a slider's start time, but hitting all slider ticks.
/// </summary>
[Test]
public void TestMissSliderHeadAndHitAllSliderTicks()
{
const double time_slider = 1500;
const double time_circle = 1510;
Vector2 positionCircle = Vector2.Zero;
Vector2 positionSlider = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
new TestSlider
{
StartTime = time_slider,
Position = positionSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_slider, Position = positionCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_slider + 10, Position = positionSlider, Actions = { OsuAction.RightButton } }
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementAssert("slider head", () => ((Slider)hitObjects[1]).HeadCircle, HitResult.Miss);
addJudgementAssert("slider tick", () => ((Slider)hitObjects[1]).NestedHitObjects[1] as SliderTick, HitResult.Great);
}
/// <summary>
/// Tests clicking hitting future slider ticks before a circle.
/// </summary>
[Test]
public void TestHitSliderTicksBeforeCircle()
{
const double time_slider = 1500;
const double time_circle = 1510;
Vector2 positionCircle = Vector2.Zero;
Vector2 positionSlider = new Vector2(80);
var hitObjects = new List<OsuHitObject>
{
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
new TestSlider
{
StartTime = time_slider,
Position = positionSlider,
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(25, 0),
})
}
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_slider, Position = positionSlider, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_circle + late_miss_window - 100, Position = positionCircle, Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_circle + late_miss_window - 90, Position = positionSlider, Actions = { OsuAction.LeftButton } },
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
addJudgementAssert("slider head", () => ((Slider)hitObjects[1]).HeadCircle, HitResult.Great);
addJudgementAssert("slider tick", () => ((Slider)hitObjects[1]).NestedHitObjects[1] as SliderTick, HitResult.Great);
}
/// <summary>
/// Tests clicking a future circle before a spinner.
/// </summary>
[Test]
public void TestHitCircleBeforeSpinner()
{
const double time_spinner = 1500;
const double time_circle = 1800;
Vector2 positionCircle = Vector2.Zero;
var hitObjects = new List<OsuHitObject>
{
new TestSpinner
{
StartTime = time_spinner,
Position = new Vector2(256, 192),
EndTime = time_spinner + 1000,
},
new TestHitCircle
{
StartTime = time_circle,
Position = positionCircle
},
};
performTest(hitObjects, new List<ReplayFrame>
{
new OsuReplayFrame { Time = time_spinner - 100, Position = positionCircle, Actions = { OsuAction.LeftButton } },
new OsuReplayFrame { Time = time_spinner + 10, Position = new Vector2(236, 192), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 20, Position = new Vector2(256, 172), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 30, Position = new Vector2(276, 192), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 40, Position = new Vector2(256, 212), Actions = { OsuAction.RightButton } },
new OsuReplayFrame { Time = time_spinner + 50, Position = new Vector2(236, 192), Actions = { OsuAction.RightButton } },
});
addJudgementAssert(hitObjects[0], HitResult.Great);
addJudgementAssert(hitObjects[1], HitResult.Great);
}
private void addJudgementAssert(OsuHitObject hitObject, HitResult result)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judgement is {result}",
() => judgementResults.Single(r => r.HitObject == hitObject).Type == result);
}
private void addJudgementAssert(string name, Func<OsuHitObject> hitObject, HitResult result)
{
AddAssert($"{name} judgement is {result}",
() => judgementResults.Single(r => r.HitObject == hitObject()).Type == result);
}
private void addJudgementOffsetAssert(OsuHitObject hitObject, double offset)
{
AddAssert($"({hitObject.GetType().ReadableName()} @ {hitObject.StartTime}) judged at {offset}",
() => Precision.AlmostEquals(judgementResults.Single(r => r.HitObject == hitObject).TimeOffset, offset, 100));
}
private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
private void performTest(List<OsuHitObject> hitObjects, List<ReplayFrame> frames)
{
AddStep("load player", () =>
{
Beatmap.Value = CreateWorkingBeatmap(new Beatmap<OsuHitObject>
{
HitObjects = hitObjects,
BeatmapInfo =
{
BaseDifficulty = new BeatmapDifficulty { SliderTickRate = 3 },
Ruleset = new OsuRuleset().RulesetInfo
},
});
Beatmap.Value.Beatmap.ControlPointInfo.Add(0, new DifficultyControlPoint { SpeedMultiplier = 0.1f });
var p = new ScoreAccessibleReplayPlayer(new Score { Replay = new Replay { Frames = frames } });
p.OnLoadComplete += _ =>
{
p.ScoreProcessor.NewJudgement += result =>
{
if (currentPlayer == p) judgementResults.Add(result);
};
p.ScoreProcessor.AllJudged += () =>
{
if (currentPlayer == p) allJudgedFired = true;
};
};
LoadScreen(currentPlayer = p);
allJudgedFired = false;
judgementResults = new List<JudgementResult>();
});
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep("Wait for all judged", () => allJudgedFired);
}
private class TestHitCircle : HitCircle
{
protected override HitWindows CreateHitWindows() => new TestHitWindows();
}
private class TestSlider : Slider
{
public TestSlider()
{
DefaultsApplied += () =>
{
HeadCircle.HitWindows = new TestHitWindows();
TailCircle.HitWindows = new TestHitWindows();
};
}
}
private class TestSpinner : Spinner
{
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
SpinsRequired = 1;
}
}
private class TestHitWindows : HitWindows
{
private static readonly DifficultyRange[] ranges =
{
new DifficultyRange(HitResult.Great, 500, 500, 500),
new DifficultyRange(HitResult.Miss, early_miss_window, early_miss_window, early_miss_window),
};
public override bool IsHitResultAllowed(HitResult result) => result == HitResult.Great || result == HitResult.Miss;
protected override DifficultyRange[] GetRanges() => ranges;
}
private class ScoreAccessibleReplayPlayer : ReplayPlayer
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
protected override bool PauseOnFocusLost => false;
public ScoreAccessibleReplayPlayer(Score score)
: base(score, false, false)
{
}
}
}
}

View File

@ -0,0 +1,64 @@
// 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 System.Linq;
using Humanizer;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestScenePathControlPointVisualiser : OsuTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(StringHumanizeExtensions),
typeof(PathControlPointPiece),
typeof(PathControlPointConnectionPiece)
};
private Slider slider;
private PathControlPointVisualiser visualiser;
[SetUp]
public void Setup() => Schedule(() =>
{
slider = new Slider();
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
});
[Test]
public void TestAddOverlappingControlPoints()
{
createVisualiser(true);
addControlPointStep(new Vector2(200));
addControlPointStep(new Vector2(300));
addControlPointStep(new Vector2(300));
addControlPointStep(new Vector2(500, 300));
AddAssert("last connection displayed", () =>
{
var lastConnection = visualiser.Connections.Last(c => c.ControlPoint.Position.Value == new Vector2(300));
return lastConnection.DrawWidth > 50;
});
}
private void createVisualiser(bool allowSelection) => AddStep("create visualiser", () => Child = visualiser = new PathControlPointVisualiser(slider, allowSelection)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
private void addControlPointStep(Vector2 position) => AddStep($"add control point {position}", () => slider.Path.ControlPoints.Add(new PathControlPoint(position)));
}
}

View File

@ -1,18 +1,285 @@
// 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 NUnit.Framework;
using osu.Framework.Utils;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
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 osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Osu.Tests namespace osu.Game.Rulesets.Osu.Tests
{ {
public class TestSceneSliderPlacementBlueprint : PlacementBlueprintTestScene public class TestSceneSliderPlacementBlueprint : PlacementBlueprintTestScene
{ {
[SetUp]
public void Setup() => Schedule(() =>
{
HitObjectContainer.Clear();
ResetPlacement();
});
[Test]
public void TestBeginPlacementWithoutFinishing()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
assertPlaced(false);
}
[Test]
public void TestPlaceWithoutMovingMouse()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addClickStep(MouseButton.Right);
assertPlaced(true);
assertLength(0);
assertControlPointType(0, PathType.Linear);
}
[Test]
public void TestPlaceWithMouseMovement()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 200));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertLength(200);
assertControlPointCount(2);
assertControlPointType(0, PathType.Linear);
}
[Test]
public void TestPlaceNormalControlPoint()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(3);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointType(0, PathType.PerfectCurve);
}
[Test]
public void TestPlaceTwoNormalControlPoints()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(4);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointPosition(2, new Vector2(100, 100));
assertControlPointType(0, PathType.Bezier);
}
[Test]
public void TestPlaceSegmentControlPoint()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(3);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointType(0, PathType.Linear);
assertControlPointType(1, PathType.Linear);
}
[Test]
public void TestMoveToPerfectCurveThenPlaceLinear()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(2);
assertControlPointType(0, PathType.Linear);
assertLength(100);
}
[Test]
public void TestMoveToBezierThenPlacePerfectCurve()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 300));
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(3);
assertControlPointType(0, PathType.PerfectCurve);
}
[Test]
public void TestMoveToFourthOrderBezierThenPlaceThirdOrderBezier()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400));
addMovementStep(new Vector2(400, 300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(4);
assertControlPointType(0, PathType.Bezier);
}
[Test]
public void TestPlaceLinearSegmentThenPlaceLinearSegment()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(3);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointPosition(2, new Vector2(100));
assertControlPointType(0, PathType.Linear);
assertControlPointType(1, PathType.Linear);
}
[Test]
public void TestPlaceLinearSegmentThenPlacePerfectCurveSegment()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 300));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(4);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointPosition(2, new Vector2(100));
assertControlPointType(0, PathType.Linear);
assertControlPointType(1, PathType.PerfectCurve);
}
[Test]
public void TestPlacePerfectCurveSegmentThenPlacePerfectCurveSegment()
{
addMovementStep(new Vector2(200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 200));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(300, 300));
addClickStep(MouseButton.Left);
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400, 300));
addClickStep(MouseButton.Left);
addMovementStep(new Vector2(400));
addClickStep(MouseButton.Right);
assertPlaced(true);
assertControlPointCount(5);
assertControlPointPosition(1, new Vector2(100, 0));
assertControlPointPosition(2, new Vector2(100));
assertControlPointPosition(3, new Vector2(200, 100));
assertControlPointPosition(4, new Vector2(200));
assertControlPointType(0, PathType.PerfectCurve);
assertControlPointType(2, PathType.PerfectCurve);
}
private void addMovementStep(Vector2 position) => AddStep($"move mouse to {position}", () => InputManager.MoveMouseTo(InputManager.ToScreenSpace(position)));
private void addClickStep(MouseButton button)
{
AddStep($"press {button}", () => InputManager.PressButton(button));
AddStep($"release {button}", () => InputManager.ReleaseButton(button));
}
private void assertPlaced(bool expected) => AddAssert($"slider {(expected ? "placed" : "not placed")}", () => (getSlider() != null) == expected);
private void assertLength(double expected) => AddAssert($"slider length is {expected}", () => Precision.AlmostEquals(expected, getSlider().Distance, 1));
private void assertControlPointCount(int expected) => AddAssert($"has {expected} control points", () => getSlider().Path.ControlPoints.Count == expected);
private void assertControlPointType(int index, PathType type) => AddAssert($"control point {index} is {type}", () => getSlider().Path.ControlPoints[index].Type.Value == type);
private void assertControlPointPosition(int index, Vector2 position) =>
AddAssert($"control point {index} at {position}", () => Precision.AlmostEquals(position, getSlider().Path.ControlPoints[index].Position.Value, 1));
private Slider getSlider() => HitObjectContainer.Count > 0 ? (Slider)((DrawableSlider)HitObjectContainer[0]).HitObject : null;
protected override DrawableHitObject CreateHitObject(HitObject hitObject) => new DrawableSlider((Slider)hitObject); protected override DrawableHitObject CreateHitObject(HitObject hitObject) => new DrawableSlider((Slider)hitObject);
protected override PlacementBlueprint CreateBlueprint() => new SliderPlacementBlueprint(); protected override PlacementBlueprint CreateBlueprint() => new SliderPlacementBlueprint();
} }

View File

@ -16,22 +16,25 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
/// </summary> /// </summary>
public class PathControlPointConnectionPiece : CompositeDrawable public class PathControlPointConnectionPiece : CompositeDrawable
{ {
public PathControlPoint ControlPoint; public readonly PathControlPoint ControlPoint;
private readonly Path path; private readonly Path path;
private readonly Slider slider; private readonly Slider slider;
private readonly int controlPointIndex;
private IBindable<Vector2> sliderPosition; private IBindable<Vector2> sliderPosition;
private IBindable<int> pathVersion; private IBindable<int> pathVersion;
public PathControlPointConnectionPiece(Slider slider, PathControlPoint controlPoint) public PathControlPointConnectionPiece(Slider slider, int controlPointIndex)
{ {
this.slider = slider; this.slider = slider;
ControlPoint = controlPoint; this.controlPointIndex = controlPointIndex;
Origin = Anchor.Centre; Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
ControlPoint = slider.Path.ControlPoints[controlPointIndex];
InternalChild = path = new SmoothPath InternalChild = path = new SmoothPath
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
@ -61,13 +64,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
path.ClearVertices(); path.ClearVertices();
int index = slider.Path.ControlPoints.IndexOf(ControlPoint) + 1; int nextIndex = controlPointIndex + 1;
if (nextIndex == 0 || nextIndex >= slider.Path.ControlPoints.Count)
if (index == 0 || index == slider.Path.ControlPoints.Count)
return; return;
path.AddVertex(Vector2.Zero); path.AddVertex(Vector2.Zero);
path.AddVertex(slider.Path.ControlPoints[index].Position.Value - ControlPoint.Position.Value); path.AddVertex(slider.Path.ControlPoints[nextIndex].Position.Value - ControlPoint.Position.Value);
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero); path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
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.Shapes; using osu.Framework.Graphics.Shapes;
@ -12,6 +13,7 @@ using osu.Game.Graphics;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK.Input; using osuTK.Input;
@ -33,6 +35,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private readonly Container marker; private readonly Container marker;
private readonly Drawable markerRing; private readonly Drawable markerRing;
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private IDistanceSnapProvider snapProvider { get; set; } private IDistanceSnapProvider snapProvider { get; set; }
@ -47,6 +52,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
this.slider = slider; this.slider = slider;
ControlPoint = controlPoint; ControlPoint = controlPoint;
controlPoint.Type.BindValueChanged(_ => updateMarkerDisplay());
Origin = Anchor.Centre; Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -137,7 +144,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
protected override bool OnClick(ClickEvent e) => RequestSelection != null; protected override bool OnClick(ClickEvent e) => RequestSelection != null;
protected override bool OnDragStart(DragStartEvent e) => e.Button == MouseButton.Left; protected override bool OnDragStart(DragStartEvent e)
{
if (e.Button == MouseButton.Left)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e) protected override void OnDrag(DragEvent e)
{ {
@ -158,6 +174,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
ControlPoint.Position.Value += e.Delta; ControlPoint.Position.Value += e.Delta;
} }
protected override void OnDragEnd(DragEndEvent e) => changeHandler?.EndChange();
/// <summary> /// <summary>
/// Updates the state of the circular control point marker. /// Updates the state of the circular control point marker.
/// </summary> /// </summary>
@ -168,8 +186,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
markerRing.Alpha = IsSelected.Value ? 1 : 0; markerRing.Alpha = IsSelected.Value ? 1 : 0;
Color4 colour = ControlPoint.Type.Value != null ? colours.Red : colours.Yellow; Color4 colour = ControlPoint.Type.Value != null ? colours.Red : colours.Yellow;
if (IsHovered || IsSelected.Value) if (IsHovered || IsSelected.Value)
colour = Color4.White; colour = colour.Lighten(1);
marker.Colour = colour; marker.Colour = colour;
} }
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq; using System.Linq;
using Humanizer; using Humanizer;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -24,17 +25,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
public class PathControlPointVisualiser : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IHasContextMenu public class PathControlPointVisualiser : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IHasContextMenu
{ {
internal readonly Container<PathControlPointPiece> Pieces; internal readonly Container<PathControlPointPiece> Pieces;
internal readonly Container<PathControlPointConnectionPiece> Connections;
private readonly Container<PathControlPointConnectionPiece> connections; private readonly IBindableList<PathControlPoint> controlPoints = new BindableList<PathControlPoint>();
private readonly Slider slider; private readonly Slider slider;
private readonly bool allowSelection; private readonly bool allowSelection;
private InputManager inputManager; private InputManager inputManager;
private IBindableList<PathControlPoint> controlPoints;
public Action<List<PathControlPoint>> RemoveControlPointsRequested; public Action<List<PathControlPoint>> RemoveControlPointsRequested;
public PathControlPointVisualiser(Slider slider, bool allowSelection) public PathControlPointVisualiser(Slider slider, bool allowSelection)
@ -46,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
connections = new Container<PathControlPointConnectionPiece> { RelativeSizeAxes = Axes.Both }, Connections = new Container<PathControlPointConnectionPiece> { RelativeSizeAxes = Axes.Both },
Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both } Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both }
}; };
} }
@ -57,33 +55,38 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
inputManager = GetContainingInputManager(); inputManager = GetContainingInputManager();
controlPoints = slider.Path.ControlPoints.GetBoundCopy(); controlPoints.CollectionChanged += onControlPointsChanged;
controlPoints.ItemsAdded += addControlPoints; controlPoints.BindTo(slider.Path.ControlPoints);
controlPoints.ItemsRemoved += removeControlPoints;
addControlPoints(controlPoints);
} }
private void addControlPoints(IEnumerable<PathControlPoint> controlPoints) private void onControlPointsChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
foreach (var point in controlPoints) switch (e.Action)
{ {
Pieces.Add(new PathControlPointPiece(slider, point).With(d => case NotifyCollectionChangedAction.Add:
{ for (int i = 0; i < e.NewItems.Count; i++)
if (allowSelection) {
d.RequestSelection = selectPiece; var point = (PathControlPoint)e.NewItems[i];
}));
connections.Add(new PathControlPointConnectionPiece(slider, point)); Pieces.Add(new PathControlPointPiece(slider, point).With(d =>
} {
} if (allowSelection)
d.RequestSelection = selectPiece;
}));
private void removeControlPoints(IEnumerable<PathControlPoint> controlPoints) Connections.Add(new PathControlPointConnectionPiece(slider, e.NewStartingIndex + i));
{ }
foreach (var point in controlPoints)
{ break;
Pieces.RemoveAll(p => p.ControlPoint == point);
connections.RemoveAll(c => c.ControlPoint == point); case NotifyCollectionChangedAction.Remove:
foreach (var point in e.OldItems.Cast<PathControlPoint>())
{
Pieces.RemoveAll(p => p.ControlPoint == point);
Connections.RemoveAll(c => c.ControlPoint == point);
}
break;
} }
} }

View File

@ -1,6 +1,9 @@
// 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.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
@ -23,6 +26,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private SliderBodyPiece bodyPiece; private SliderBodyPiece bodyPiece;
private HitCirclePiece headCirclePiece; private HitCirclePiece headCirclePiece;
private HitCirclePiece tailCirclePiece; private HitCirclePiece tailCirclePiece;
private PathControlPointVisualiser controlPointVisualiser;
private InputManager inputManager; private InputManager inputManager;
@ -51,7 +55,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
bodyPiece = new SliderBodyPiece(), bodyPiece = new SliderBodyPiece(),
headCirclePiece = new HitCirclePiece(), headCirclePiece = new HitCirclePiece(),
tailCirclePiece = new HitCirclePiece(), tailCirclePiece = new HitCirclePiece(),
new PathControlPointVisualiser(HitObject, false) controlPointVisualiser = new PathControlPointVisualiser(HitObject, false)
}; };
setState(PlacementState.Initial); setState(PlacementState.Initial);
@ -73,11 +77,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
break; break;
case PlacementState.Body: case PlacementState.Body:
ensureCursor(); updateCursor();
// The given screen-space position may have been externally snapped, but the unsnapped position from the input manager
// is used instead since snapping control points doesn't make much sense
cursor.Position.Value = ToLocalSpace(inputManager.CurrentState.Mouse.Position) - HitObject.Position;
break; break;
} }
} }
@ -91,17 +91,27 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
break; break;
case PlacementState.Body: case PlacementState.Body:
switch (e.Button) if (e.Button != MouseButton.Left)
{ break;
case MouseButton.Left:
ensureCursor();
// Detatch the cursor if (canPlaceNewControlPoint(out var lastPoint))
cursor = null; {
break; // Place a new point by detatching the current cursor.
updateCursor();
cursor = null;
}
else
{
// Transform the last point into a new segment.
Debug.Assert(lastPoint != null);
segmentStart = lastPoint;
segmentStart.Type.Value = PathType.Linear;
currentSegmentLength = 1;
} }
break; return true;
} }
return true; return true;
@ -114,16 +124,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
base.OnMouseUp(e); base.OnMouseUp(e);
} }
protected override bool OnDoubleClick(DoubleClickEvent e)
{
// Todo: This should all not occur on double click, but rather if the previous control point is hovered.
segmentStart = HitObject.Path.ControlPoints[^1];
segmentStart.Type.Value = PathType.Linear;
currentSegmentLength = 1;
return true;
}
private void beginCurve() private void beginCurve()
{ {
BeginPlacement(commitStart: true); BeginPlacement(commitStart: true);
@ -161,17 +161,50 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
} }
} }
private void ensureCursor() private void updateCursor()
{ {
if (cursor == null) if (canPlaceNewControlPoint(out _))
{ {
HitObject.Path.ControlPoints.Add(cursor = new PathControlPoint { Position = { Value = Vector2.Zero } }); // The cursor does not overlap a previous control point, so it can be added if not already existing.
currentSegmentLength++; if (cursor == null)
{
HitObject.Path.ControlPoints.Add(cursor = new PathControlPoint { Position = { Value = Vector2.Zero } });
// The path type should be adjusted in the progression of updatePathType() (Linear -> PC -> Bezier).
currentSegmentLength++;
updatePathType();
}
// Update the cursor position.
cursor.Position.Value = ToLocalSpace(inputManager.CurrentState.Mouse.Position) - HitObject.Position;
}
else if (cursor != null)
{
// The cursor overlaps a previous control point, so it's removed.
HitObject.Path.ControlPoints.Remove(cursor);
cursor = null;
// The path type should be adjusted in the reverse progression of updatePathType() (Bezier -> PC -> Linear).
currentSegmentLength--;
updatePathType(); updatePathType();
} }
} }
/// <summary>
/// Whether a new control point can be placed at the current mouse position.
/// </summary>
/// <param name="lastPoint">The last-placed control point. May be null, but is not null if <c>false</c> is returned.</param>
/// <returns>Whether a new control point can be placed at the current position.</returns>
private bool canPlaceNewControlPoint([CanBeNull] out PathControlPoint lastPoint)
{
// We cannot rely on the ordering of drawable pieces, so find the respective drawable piece by searching for the last non-cursor control point.
var last = HitObject.Path.ControlPoints.LastOrDefault(p => p != cursor);
var lastPiece = controlPointVisualiser.Pieces.Single(p => p.ControlPoint == last);
lastPoint = last;
return lastPiece?.IsHovered != true;
}
private void updateSlider() private void updateSlider()
{ {
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance; HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;

View File

@ -15,6 +15,7 @@ using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components; using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.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 osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Compose;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
@ -34,6 +35,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private IPlacementHandler placementHandler { get; set; } private IPlacementHandler placementHandler { get; set; }
[Resolved(CanBeNull = true)]
private EditorBeatmap editorBeatmap { get; set; }
[Resolved(CanBeNull = true)]
private IEditorChangeHandler changeHandler { get; set; }
public SliderSelectionBlueprint(DrawableSlider slider) public SliderSelectionBlueprint(DrawableSlider slider)
: base(slider) : base(slider)
{ {
@ -88,7 +95,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private int? placementControlPointIndex; private int? placementControlPointIndex;
protected override bool OnDragStart(DragStartEvent e) => placementControlPointIndex != null; protected override bool OnDragStart(DragStartEvent e)
{
if (placementControlPointIndex != null)
{
changeHandler?.BeginChange();
return true;
}
return false;
}
protected override void OnDrag(DragEvent e) protected override void OnDrag(DragEvent e)
{ {
@ -99,7 +115,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
protected override void OnDragEnd(DragEndEvent e) protected override void OnDragEnd(DragEndEvent e)
{ {
placementControlPointIndex = null; if (placementControlPointIndex != null)
{
placementControlPointIndex = null;
changeHandler?.EndChange();
}
} }
private BindableList<PathControlPoint> controlPoints => HitObject.Path.ControlPoints; private BindableList<PathControlPoint> controlPoints => HitObject.Path.ControlPoints;
@ -162,7 +182,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
private void updatePath() private void updatePath()
{ {
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance; HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;
UpdateHitObject(); editorBeatmap?.UpdateHitObject(HitObject);
} }
public override MenuItem[] ContextMenuItems => new MenuItem[] public override MenuItem[] ContextMenuItems => new MenuItem[]

View File

@ -120,7 +120,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
var result = HitObject.HitWindows.ResultFor(timeOffset); var result = HitObject.HitWindows.ResultFor(timeOffset);
if (result == HitResult.None) if (result == HitResult.None || CheckHittable?.Invoke(this, Time.Current) == false)
{ {
Shake(Math.Abs(timeOffset) - HitObject.HitWindows.WindowFor(HitResult.Miss)); Shake(Math.Abs(timeOffset) - HitObject.HitWindows.WindowFor(HitResult.Miss));
return; return;

View File

@ -1,11 +1,14 @@
// 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 osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Scoring;
namespace osu.Game.Rulesets.Osu.Objects.Drawables namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
@ -16,6 +19,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects. // Must be set to update IsHovered as it's used in relax mdo to detect osu hit objects.
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
protected override float SamplePlaybackPosition => HitObject.X / OsuPlayfield.BASE_SIZE.X;
/// <summary>
/// Whether this <see cref="DrawableOsuHitObject"/> can be hit.
/// If non-null, judgements will be ignored (resulting in a shake) whilst the function returns false.
/// </summary>
public Func<DrawableHitObject, double, bool> CheckHittable;
protected DrawableOsuHitObject(OsuHitObject hitObject) protected DrawableOsuHitObject(OsuHitObject hitObject)
: base(hitObject) : base(hitObject)
{ {
@ -54,6 +65,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
} }
/// <summary>
/// Causes this <see cref="DrawableOsuHitObject"/> to get missed, disregarding all conditions in implementations of <see cref="DrawableHitObject.CheckForResult"/>.
/// </summary>
public void MissForcefully() => ApplyResult(r => r.Type = HitResult.Miss);
protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement); protected override JudgementResult CreateResult(Judgement judgement) => new OsuJudgementResult(HitObject, judgement);
} }
} }

View File

@ -124,7 +124,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
case SliderTailCircle tail: case SliderTailCircle tail:
return new DrawableSliderTail(slider, tail); return new DrawableSliderTail(slider, tail);
case HitCircle head: case SliderHeadCircle head:
return new DrawableSliderHead(slider, head) { OnShake = Shake }; return new DrawableSliderHead(slider, head) { OnShake = Shake };
case SliderTick tick: case SliderTick tick:

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private readonly Slider slider; private readonly Slider slider;
public DrawableSliderHead(Slider slider, HitCircle h) public DrawableSliderHead(Slider slider, SliderHeadCircle h)
: base(h) : base(h)
{ {
this.slider = slider; this.slider = slider;

View File

@ -155,7 +155,7 @@ namespace osu.Game.Rulesets.Osu.Objects
break; break;
case SliderEventType.Head: case SliderEventType.Head:
AddNested(HeadCircle = new SliderCircle AddNested(HeadCircle = new SliderHeadCircle
{ {
StartTime = e.Time, StartTime = e.Time,
Position = Position, Position = Position,

View File

@ -0,0 +1,9 @@
// 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.
namespace osu.Game.Rulesets.Osu.Objects
{
public class SliderHeadCircle : HitCircle
{
}
}

View File

@ -0,0 +1,127 @@
// 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.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.UI
{
/// <summary>
/// Ensures that <see cref="HitObject"/>s are hit in-order.
/// If a <see cref="HitObject"/> is hit out of order:
/// <list type="number">
/// <item><description>The hit is blocked if it occurred earlier than the previous <see cref="HitObject"/>'s start time.</description></item>
/// <item><description>The hit causes all previous <see cref="HitObject"/>s to missed otherwise.</description></item>
/// </list>
/// </summary>
public class OrderedHitPolicy
{
private readonly HitObjectContainer hitObjectContainer;
public OrderedHitPolicy(HitObjectContainer hitObjectContainer)
{
this.hitObjectContainer = hitObjectContainer;
}
/// <summary>
/// Determines whether a <see cref="DrawableHitObject"/> can be hit at a point in time.
/// </summary>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to check.</param>
/// <param name="time">The time to check.</param>
/// <returns>Whether <paramref name="hitObject"/> can be hit at the given <paramref name="time"/>.</returns>
public bool IsHittable(DrawableHitObject hitObject, double time)
{
DrawableHitObject blockingObject = null;
// Find the last hitobject which blocks future hits.
foreach (var obj in hitObjectContainer.AliveObjects)
{
if (obj == hitObject)
break;
if (drawableCanBlockFutureHits(obj))
blockingObject = obj;
}
// If there is no previous hitobject, allow the hit.
if (blockingObject == null)
return true;
// A hit is allowed if:
// 1. The last blocking hitobject has been judged.
// 2. The current time is after the last hitobject's start time.
// Hits at exactly the same time as the blocking hitobject are allowed for maps that contain simultaneous hitobjects (e.g. /b/372245).
if (blockingObject.Judged || time >= blockingObject.HitObject.StartTime)
return true;
return false;
}
/// <summary>
/// Handles a <see cref="HitObject"/> being hit to potentially miss all earlier <see cref="HitObject"/>s.
/// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> that was hit.</param>
public void HandleHit(HitObject hitObject)
{
// Hitobjects which themselves don't block future hitobjects don't cause misses (e.g. slider ticks, spinners).
if (!hitObjectCanBlockFutureHits(hitObject))
return;
double maximumTime = hitObject.StartTime;
// Iterate through and apply miss results to all top-level and nested hitobjects which block future hits.
foreach (var obj in hitObjectContainer.AliveObjects)
{
if (obj.Judged || obj.HitObject.StartTime >= maximumTime)
continue;
if (hitObjectCanBlockFutureHits(obj.HitObject))
applyMiss(obj);
foreach (var nested in obj.NestedHitObjects)
{
if (nested.Judged || nested.HitObject.StartTime >= maximumTime)
continue;
if (hitObjectCanBlockFutureHits(nested.HitObject))
applyMiss(nested);
}
}
static void applyMiss(DrawableHitObject obj) => ((DrawableOsuHitObject)obj).MissForcefully();
}
/// <summary>
/// Whether a <see cref="DrawableHitObject"/> blocks hits on future <see cref="DrawableHitObject"/>s until its start time is reached.
/// </summary>
/// <remarks>
/// This will ONLY match on top-most <see cref="DrawableHitObject"/>s.
/// </remarks>
/// <param name="hitObject">The <see cref="DrawableHitObject"/> to test.</param>
private static bool drawableCanBlockFutureHits(DrawableHitObject hitObject)
{
// Special considerations for slider tails aren't required since only top-most drawable hitobjects are being iterated over.
return hitObject is DrawableHitCircle || hitObject is DrawableSlider;
}
/// <summary>
/// Whether a <see cref="HitObject"/> blocks hits on future <see cref="HitObject"/>s until its start time is reached.
/// </summary>
/// <remarks>
/// This is more rigorous and may not match on top-most <see cref="HitObject"/>s as <see cref="drawableCanBlockFutureHits"/> does.
/// </remarks>
/// <param name="hitObject">The <see cref="HitObject"/> to test.</param>
private static bool hitObjectCanBlockFutureHits(HitObject hitObject)
{
// Unlike the above we will receive slider tails, but they do not block future hits.
if (hitObject is SliderTailCircle)
return false;
// All other hitcircles continue to block future hits.
return hitObject is HitCircle;
}
}
}

View File

@ -20,6 +20,7 @@ namespace osu.Game.Rulesets.Osu.UI
private readonly ApproachCircleProxyContainer approachCircles; private readonly ApproachCircleProxyContainer approachCircles;
private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer; private readonly JudgementContainer<DrawableOsuJudgement> judgementLayer;
private readonly FollowPointRenderer followPoints; private readonly FollowPointRenderer followPoints;
private readonly OrderedHitPolicy hitPolicy;
public static readonly Vector2 BASE_SIZE = new Vector2(512, 384); public static readonly Vector2 BASE_SIZE = new Vector2(512, 384);
@ -51,6 +52,8 @@ namespace osu.Game.Rulesets.Osu.UI
Depth = -1, Depth = -1,
}, },
}; };
hitPolicy = new OrderedHitPolicy(HitObjectContainer);
} }
public override void Add(DrawableHitObject h) public override void Add(DrawableHitObject h)
@ -64,7 +67,10 @@ namespace osu.Game.Rulesets.Osu.UI
base.Add(h); base.Add(h);
followPoints.AddFollowPoints((DrawableOsuHitObject)h); DrawableOsuHitObject osuHitObject = (DrawableOsuHitObject)h;
osuHitObject.CheckHittable = hitPolicy.IsHittable;
followPoints.AddFollowPoints(osuHitObject);
} }
public override bool Remove(DrawableHitObject h) public override bool Remove(DrawableHitObject h)
@ -79,6 +85,9 @@ namespace osu.Game.Rulesets.Osu.UI
private void onNewResult(DrawableHitObject judgedObject, JudgementResult result) private void onNewResult(DrawableHitObject judgedObject, JudgementResult result)
{ {
// Hitobjects that block future hits should miss previous hitobjects if they're hit out-of-order.
hitPolicy.HandleHit(result.HitObject);
if (!judgedObject.DisplayResult || !DisplayJudgements.Value) if (!judgedObject.DisplayResult || !DisplayJudgements.Value)
return; return;

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,70 @@
// 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 System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Skinning;
namespace osu.Game.Rulesets.Taiko.Tests
{
[TestFixture]
public class TestSceneDrawableHit : TaikoSkinnableTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Concat(new[]
{
typeof(DrawableHit),
typeof(DrawableCentreHit),
typeof(DrawableRimHit),
typeof(LegacyHit),
}).ToList();
[BackgroundDependencyLoader]
private void load()
{
AddStep("Centre hit", () => SetContents(() => new DrawableCentreHit(createHitAtCurrentTime())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}));
AddStep("Centre hit (strong)", () => SetContents(() => new DrawableCentreHit(createHitAtCurrentTime(true))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}));
AddStep("Rim hit", () => SetContents(() => new DrawableRimHit(createHitAtCurrentTime())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}));
AddStep("Rim hit (strong)", () => SetContents(() => new DrawableRimHit(createHitAtCurrentTime(true))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}));
}
private Hit createHitAtCurrentTime(bool strong = false)
{
var hit = new Hit
{
IsStrong = strong,
StartTime = Time.Current + 3000,
};
hit.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
return hit;
}
}
}

View File

@ -1,9 +1,9 @@
// 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.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -14,13 +14,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public DrawableCentreHit(Hit hit) public DrawableCentreHit(Hit hit)
: base(hit) : base(hit)
{ {
MainPiece.Add(new CentreHitSymbolPiece());
} }
[BackgroundDependencyLoader] protected override CompositeDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.CentreHit),
private void load(OsuColour colours) _ => new CentreHitCirclePiece(), confineMode: ConfineMode.ScaleToFit);
{
MainPiece.AccentColour = colours.PinkDarker;
}
} }
} }

View File

@ -34,17 +34,19 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private Color4 colourIdle; private Color4 colourIdle;
private Color4 colourEngaged; private Color4 colourEngaged;
private ElongatedCirclePiece elongatedPiece;
public DrawableDrumRoll(DrumRoll drumRoll) public DrawableDrumRoll(DrumRoll drumRoll)
: base(drumRoll) : base(drumRoll)
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
MainPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both }); elongatedPiece.Add(tickContainer = new Container<DrawableDrumRollTick> { RelativeSizeAxes = Axes.Both });
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
MainPiece.AccentColour = colourIdle = colours.YellowDark; elongatedPiece.AccentColour = colourIdle = colours.YellowDark;
colourEngaged = colours.YellowDarker; colourEngaged = colours.YellowDarker;
} }
@ -84,7 +86,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return base.CreateNestedHitObject(hitObject); return base.CreateNestedHitObject(hitObject);
} }
protected override TaikoPiece CreateMainPiece() => new ElongatedCirclePiece(); protected override CompositeDrawable CreateMainPiece() => elongatedPiece = new ElongatedCirclePiece();
public override bool OnPressed(TaikoAction action) => false; public override bool OnPressed(TaikoAction action) => false;
@ -101,7 +103,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
rollingHits = Math.Clamp(rollingHits, 0, rolling_hits_for_engaged_colour); rollingHits = Math.Clamp(rollingHits, 0, rolling_hits_for_engaged_colour);
Color4 newColour = Interpolation.ValueAt((float)rollingHits / rolling_hits_for_engaged_colour, colourIdle, colourEngaged, 0, 1); Color4 newColour = Interpolation.ValueAt((float)rollingHits / rolling_hits_for_engaged_colour, colourIdle, colourEngaged, 0, 1);
MainPiece.FadeAccent(newColour, 100); (MainPiece as IHasAccentColour)?.FadeAccent(newColour, 100);
} }
protected override void CheckForResult(bool userTriggered, double timeOffset) protected override void CheckForResult(bool userTriggered, double timeOffset)

View File

@ -3,6 +3,7 @@
using System; using System;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
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.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public override bool DisplayResult => false; public override bool DisplayResult => false;
protected override TaikoPiece CreateMainPiece() => new TickPiece protected override CompositeDrawable CreateMainPiece() => new TickPiece
{ {
Filled = HitObject.FirstTick Filled = HitObject.FirstTick
}; };

View File

@ -1,9 +1,9 @@
// 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.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces; using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using osu.Game.Skinning;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -14,13 +14,9 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public DrawableRimHit(Hit hit) public DrawableRimHit(Hit hit)
: base(hit) : base(hit)
{ {
MainPiece.Add(new RimHitSymbolPiece());
} }
[BackgroundDependencyLoader] protected override CompositeDrawable CreateMainPiece() => new SkinnableDrawable(new TaikoSkinComponent(TaikoSkinComponents.RimHit),
private void load(OsuColour colours) _ => new RimHitCirclePiece(), confineMode: ConfineMode.ScaleToFit);
{
MainPiece.AccentColour = colours.BlueDarker;
}
} }
} }

View File

@ -9,11 +9,11 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
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.Objects;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -34,8 +34,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
private readonly CircularContainer targetRing; private readonly CircularContainer targetRing;
private readonly CircularContainer expandingRing; private readonly CircularContainer expandingRing;
private readonly SwellSymbolPiece symbol;
public DrawableSwell(Swell swell) public DrawableSwell(Swell swell)
: base(swell) : base(swell)
{ {
@ -107,18 +105,22 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
}); });
AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both }); AddInternal(ticks = new Container<DrawableSwellTick> { RelativeSizeAxes = Axes.Both });
MainPiece.Add(symbol = new SwellSymbolPiece());
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
MainPiece.AccentColour = colours.YellowDark;
expandingRing.Colour = colours.YellowLight; expandingRing.Colour = colours.YellowLight;
targetRing.BorderColour = colours.YellowDark.Opacity(0.25f); targetRing.BorderColour = colours.YellowDark.Opacity(0.25f);
} }
protected override CompositeDrawable CreateMainPiece() => new SwellCirclePiece
{
// to allow for rotation transform
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -182,7 +184,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
.Then() .Then()
.FadeTo(completion / 8, 2000, Easing.OutQuint); .FadeTo(completion / 8, 2000, Easing.OutQuint);
symbol.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint); MainPiece.RotateTo((float)(completion * HitObject.Duration / 8), 4000, Easing.OutQuint);
expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint); expandingRing.ScaleTo(1f + Math.Min(target_ring_scale - 1f, (target_ring_scale - 1f) * completion * 1.3f), 260, Easing.OutQuint);

View File

@ -2,7 +2,9 @@
// 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; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
@ -28,5 +30,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
} }
public override bool OnPressed(TaikoAction action) => false; public override bool OnPressed(TaikoAction action) => false;
protected override CompositeDrawable CreateMainPiece() => new TickPiece();
} }
} }

View File

@ -4,7 +4,6 @@
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces;
using osuTK; using osuTK;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
@ -108,19 +107,19 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
} }
} }
public abstract class DrawableTaikoHitObject<TTaikoHit> : DrawableTaikoHitObject public abstract class DrawableTaikoHitObject<TObject> : DrawableTaikoHitObject
where TTaikoHit : TaikoHitObject where TObject : TaikoHitObject
{ {
public override Vector2 OriginPosition => new Vector2(DrawHeight / 2); public override Vector2 OriginPosition => new Vector2(DrawHeight / 2);
public new TTaikoHit HitObject; public new TObject HitObject;
protected readonly Vector2 BaseSize; protected readonly Vector2 BaseSize;
protected readonly TaikoPiece MainPiece; protected readonly CompositeDrawable MainPiece;
private readonly Container<DrawableStrongNestedHit> strongHitContainer; private readonly Container<DrawableStrongNestedHit> strongHitContainer;
protected DrawableTaikoHitObject(TTaikoHit hitObject) protected DrawableTaikoHitObject(TObject hitObject)
: base(hitObject) : base(hitObject)
{ {
HitObject = hitObject; HitObject = hitObject;
@ -132,7 +131,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
Size = BaseSize = new Vector2(HitObject.IsStrong ? TaikoHitObject.DEFAULT_STRONG_SIZE : TaikoHitObject.DEFAULT_SIZE); Size = BaseSize = new Vector2(HitObject.IsStrong ? TaikoHitObject.DEFAULT_STRONG_SIZE : TaikoHitObject.DEFAULT_SIZE);
Content.Add(MainPiece = CreateMainPiece()); Content.Add(MainPiece = CreateMainPiece());
MainPiece.KiaiMode = HitObject.Kiai;
AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>()); AddInternal(strongHitContainer = new Container<DrawableStrongNestedHit>());
} }
@ -169,7 +167,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
// 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);
protected virtual TaikoPiece CreateMainPiece() => new CirclePiece(); protected abstract CompositeDrawable CreateMainPiece();
/// <summary> /// <summary>
/// Creates the handler for this <see cref="DrawableHitObject"/>'s <see cref="StrongHitObject"/>. /// Creates the handler for this <see cref="DrawableHitObject"/>'s <see cref="StrongHitObject"/>.

View File

@ -0,0 +1,52 @@
// 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;
using osu.Framework.Graphics.Containers;
using osuTK;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
public class CentreHitCirclePiece : CirclePiece
{
public CentreHitCirclePiece()
{
Add(new CentreHitSymbolPiece());
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.PinkDarker;
}
/// <summary>
/// The symbol used for centre hit pieces.
/// </summary>
public class CentreHitSymbolPiece : Container
{
public CentreHitSymbolPiece()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(SYMBOL_SIZE);
Padding = new MarginPadding(SYMBOL_BORDER);
Children = new[]
{
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new[] { new Box { RelativeSizeAxes = Axes.Both } }
}
};
}
}
}
}

View File

@ -1,36 +0,0 @@
// 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.Framework.Graphics.Containers;
using osuTK;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
/// <summary>
/// The symbol used for centre hit pieces.
/// </summary>
public class CentreHitSymbolPiece : Container
{
public CentreHitSymbolPiece()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(CirclePiece.SYMBOL_SIZE);
Padding = new MarginPadding(CirclePiece.SYMBOL_BORDER);
Children = new[]
{
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new[] { new Box { RelativeSizeAxes = Axes.Both } }
}
};
}
}
}

View File

@ -10,6 +10,7 @@ using osuTK.Graphics;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Game.Graphics.Containers;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{ {
@ -20,21 +21,23 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
/// for a usage example. /// for a usage example.
/// </para> /// </para>
/// </summary> /// </summary>
public class CirclePiece : TaikoPiece public abstract class CirclePiece : BeatSyncedContainer
{ {
public const float SYMBOL_SIZE = 0.45f; public const float SYMBOL_SIZE = 0.45f;
public const float SYMBOL_BORDER = 8; public const float SYMBOL_BORDER = 8;
private const double pre_beat_transition_time = 80; private const double pre_beat_transition_time = 80;
private Color4 accentColour;
/// <summary> /// <summary>
/// The colour of the inner circle and outer glows. /// The colour of the inner circle and outer glows.
/// </summary> /// </summary>
public override Color4 AccentColour public Color4 AccentColour
{ {
get => base.AccentColour; get => accentColour;
set set
{ {
base.AccentColour = value; accentColour = value;
background.Colour = AccentColour; background.Colour = AccentColour;
@ -42,15 +45,17 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
} }
} }
private bool kiaiMode;
/// <summary> /// <summary>
/// Whether Kiai mode effects are enabled for this circle piece. /// Whether Kiai mode effects are enabled for this circle piece.
/// </summary> /// </summary>
public override bool KiaiMode public bool KiaiMode
{ {
get => base.KiaiMode; get => kiaiMode;
set set
{ {
base.KiaiMode = value; kiaiMode = value;
resetEdgeEffects(); resetEdgeEffects();
} }
@ -64,8 +69,10 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
public Box FlashBox; public Box FlashBox;
public CirclePiece() protected CirclePiece()
{ {
RelativeSizeAxes = Axes.Both;
EarlyActivationMilliseconds = pre_beat_transition_time; EarlyActivationMilliseconds = pre_beat_transition_time;
AddRangeInternal(new Drawable[] AddRangeInternal(new Drawable[]

View File

@ -0,0 +1,55 @@
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
public class RimHitCirclePiece : CirclePiece
{
public RimHitCirclePiece()
{
Add(new RimHitSymbolPiece());
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AccentColour = colours.BlueDarker;
}
/// <summary>
/// The symbol used for rim hit pieces.
/// </summary>
public class RimHitSymbolPiece : CircularContainer
{
public RimHitSymbolPiece()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(SYMBOL_SIZE);
BorderThickness = SYMBOL_BORDER;
BorderColour = Color4.White;
Masking = true;
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
};
}
}
}
}

View File

@ -1,39 +0,0 @@
// 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.Framework.Graphics.Containers;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
/// <summary>
/// The symbol used for rim hit pieces.
/// </summary>
public class RimHitSymbolPiece : CircularContainer
{
public RimHitSymbolPiece()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(CirclePiece.SYMBOL_SIZE);
BorderThickness = CirclePiece.SYMBOL_BORDER;
BorderColour = Color4.White;
Masking = true;
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true
}
};
}
}
}

View File

@ -1,36 +1,52 @@
// 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 osuTK; using osuTK;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{ {
/// <summary> public class SwellCirclePiece : CirclePiece
/// The symbol used for swell pieces.
/// </summary>
public class SwellSymbolPiece : Container
{ {
public SwellSymbolPiece() public SwellCirclePiece()
{ {
Anchor = Anchor.Centre; Add(new SwellSymbolPiece());
Origin = Anchor.Centre; }
RelativeSizeAxes = Axes.Both; [BackgroundDependencyLoader]
Size = new Vector2(CirclePiece.SYMBOL_SIZE); private void load(OsuColour colours)
Padding = new MarginPadding(CirclePiece.SYMBOL_BORDER); {
AccentColour = colours.YellowDark;
}
Children = new[] /// <summary>
/// The symbol used for swell pieces.
/// </summary>
public class SwellSymbolPiece : Container
{
public SwellSymbolPiece()
{ {
new SpriteIcon Anchor = Anchor.Centre;
Origin = Anchor.Centre;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(SYMBOL_SIZE);
Padding = new MarginPadding(SYMBOL_BORDER);
Children = new[]
{ {
RelativeSizeAxes = Axes.Both, new SpriteIcon
Icon = FontAwesome.Solid.Asterisk, {
Shadow = false RelativeSizeAxes = Axes.Both,
} Icon = FontAwesome.Solid.Asterisk,
}; Shadow = false
}
};
}
} }
} }
} }

View File

@ -1,28 +0,0 @@
// 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.Graphics;
using osuTK.Graphics;
using osu.Game.Graphics.Containers;
using osu.Framework.Graphics;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{
public class TaikoPiece : BeatSyncedContainer, IHasAccentColour
{
/// <summary>
/// The colour of the inner circle and outer glows.
/// </summary>
public virtual Color4 AccentColour { get; set; }
/// <summary>
/// Whether Kiai mode effects are enabled for this circle piece.
/// </summary>
public virtual bool KiaiMode { get; set; }
public TaikoPiece()
{
RelativeSizeAxes = Axes.Both;
}
}
}

View File

@ -9,7 +9,7 @@ using osu.Framework.Graphics.Shapes;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
{ {
public class TickPiece : TaikoPiece public class TickPiece : CompositeDrawable
{ {
/// <summary> /// <summary>
/// Any tick that is not the first for a drumroll is not filled, but is instead displayed /// Any tick that is not the first for a drumroll is not filled, but is instead displayed
@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
FillMode = FillMode.Fit; FillMode = FillMode.Fit;
Size = new Vector2(tick_size); Size = new Vector2(tick_size);
Add(new CircularContainer InternalChild = new CircularContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables.Pieces
AlwaysPresent = true AlwaysPresent = true
} }
} }
}); };
} }
} }
} }

View File

@ -0,0 +1,91 @@
// 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;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.Skinning
{
public class LegacyHit : CompositeDrawable, IHasAccentColour
{
private readonly TaikoSkinComponents component;
private Drawable backgroundLayer;
public LegacyHit(TaikoSkinComponents component)
{
this.component = component;
RelativeSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, DrawableHitObject drawableHitObject)
{
Drawable getDrawableFor(string lookup)
{
const string normal_hit = "taikohit";
const string big_hit = "taikobig";
string prefix = ((drawableHitObject as DrawableTaikoHitObject)?.HitObject.IsStrong ?? false) ? big_hit : normal_hit;
return skin.GetAnimation($"{prefix}{lookup}", true, false) ??
// fallback to regular size if "big" version doesn't exist.
skin.GetAnimation($"{normal_hit}{lookup}", true, false);
}
// backgroundLayer is guaranteed to exist due to the pre-check in TaikoLegacySkinTransformer.
AddInternal(backgroundLayer = getDrawableFor("circle"));
var foregroundLayer = getDrawableFor("circleoverlay");
if (foregroundLayer != null)
AddInternal(foregroundLayer);
// Animations in taiko skins are used in a custom way (>150 combo and animating in time with beat).
// For now just stop at first frame for sanity.
foreach (var c in InternalChildren)
{
(c as IFramedAnimation)?.Stop();
c.Anchor = Anchor.Centre;
c.Origin = Anchor.Centre;
}
AccentColour = component == TaikoSkinComponents.CentreHit
? new Color4(235, 69, 44, 255)
: new Color4(67, 142, 172, 255);
}
protected override void Update()
{
base.Update();
// Not all skins (including the default osu-stable) have similar sizes for "hitcircle" and "hitcircleoverlay".
// This ensures they are scaled relative to each other but also match the expected DrawableHit size.
foreach (var c in InternalChildren)
c.Scale = new Vector2(DrawWidth / 128);
}
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
if (value == accentColour)
return;
backgroundLayer.Colour = accentColour = value;
}
}
}
}

View File

@ -32,6 +32,14 @@ namespace osu.Game.Rulesets.Taiko.Skinning
return new LegacyInputDrum(); return new LegacyInputDrum();
return null; return null;
case TaikoSkinComponents.CentreHit:
case TaikoSkinComponents.RimHit:
if (GetTexture("taikohitcircle") != null)
return new LegacyHit(taikoComponent.Component);
return null;
} }
return source.GetDrawableComponent(component); return source.GetDrawableComponent(component);

View File

@ -6,5 +6,7 @@ namespace osu.Game.Rulesets.Taiko
public enum TaikoSkinComponents public enum TaikoSkinComponents
{ {
InputDrum, InputDrum,
CentreHit,
RimHit
} }
} }

View File

@ -1,18 +1,21 @@
// 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.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Internal;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Beatmaps namespace osu.Game.Tests.Beatmaps
{ {
[TestFixture] [HeadlessTest]
public class EditorBeatmapTest public class TestSceneEditorBeatmap : EditorClockTestScene
{ {
/// <summary> /// <summary>
/// Tests that the addition event is correctly invoked after a hitobject is added. /// Tests that the addition event is correctly invoked after a hitobject is added.
@ -55,13 +58,19 @@ namespace osu.Game.Tests.Beatmaps
public void TestInitialHitObjectStartTimeChangeEvent() public void TestInitialHitObjectStartTimeChangeEvent()
{ {
var hitCircle = new HitCircle(); var hitCircle = new HitCircle();
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h;
hitCircle.StartTime = 1000; AddStep("add beatmap", () =>
Assert.That(changedObject, Is.EqualTo(hitCircle)); {
EditorBeatmap editorBeatmap;
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
editorBeatmap.HitObjectUpdated += h => changedObject = h;
});
AddStep("change start time", () => hitCircle.StartTime = 1000);
AddAssert("received change event", () => changedObject == hitCircle);
} }
/// <summary> /// <summary>
@ -71,18 +80,22 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestAddedHitObjectStartTimeChangeEvent() public void TestAddedHitObjectStartTimeChangeEvent()
{ {
var editorBeatmap = new EditorBeatmap(new OsuBeatmap()); EditorBeatmap editorBeatmap = null;
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h;
AddStep("add beatmap", () =>
{
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
editorBeatmap.HitObjectUpdated += h => changedObject = h;
});
var hitCircle = new HitCircle(); var hitCircle = new HitCircle();
editorBeatmap.Add(hitCircle); AddStep("add object", () => editorBeatmap.Add(hitCircle));
Assert.That(changedObject, Is.Null); AddAssert("event not received", () => changedObject == null);
hitCircle.StartTime = 1000; AddStep("change start time", () => hitCircle.StartTime = 1000);
Assert.That(changedObject, Is.EqualTo(hitCircle)); AddAssert("event received", () => changedObject == hitCircle);
} }
/// <summary> /// <summary>
@ -95,7 +108,7 @@ namespace osu.Game.Tests.Beatmaps
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } }); var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
HitObject changedObject = null; HitObject changedObject = null;
editorBeatmap.StartTimeChanged += h => changedObject = h; editorBeatmap.HitObjectUpdated += h => changedObject = h;
editorBeatmap.Remove(hitCircle); editorBeatmap.Remove(hitCircle);
Assert.That(changedObject, Is.Null); Assert.That(changedObject, Is.Null);
@ -150,5 +163,69 @@ namespace osu.Game.Tests.Beatmaps
Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1)); Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1));
Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1)); Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1));
} }
/// <summary>
/// Tests that multiple hitobjects are updated simultaneously.
/// </summary>
[Test]
public void TestMultipleHitObjectUpdate()
{
var updatedObjects = new List<HitObject>();
var allHitObjects = new List<HitObject>();
EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () =>
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
for (int i = 0; i < 10; i++)
{
var h = new HitCircle();
editorBeatmap.Add(h);
allHitObjects.Add(h);
}
});
AddStep("change all start times", () =>
{
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
for (int i = 0; i < 10; i++)
allHitObjects[i].StartTime += 10;
});
// Distinct ensures that all hitobjects have been updated once, debounce is tested below.
AddAssert("all hitobjects updated", () => updatedObjects.Distinct().Count() == 10);
}
/// <summary>
/// Tests that hitobject updates are debounced when they happen too soon.
/// </summary>
[Test]
public void TestDebouncedUpdate()
{
var updatedObjects = new List<HitObject>();
EditorBeatmap editorBeatmap = null;
AddStep("add beatmap", () =>
{
updatedObjects.Clear();
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
editorBeatmap.Add(new HitCircle());
});
AddStep("change start time twice", () =>
{
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
editorBeatmap.HitObjects[0].StartTime = 10;
editorBeatmap.HitObjects[0].StartTime = 20;
});
AddAssert("only updated once", () => updatedObjects.Count == 1);
}
} }
} }

View File

@ -0,0 +1,71 @@
// 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;
using osu.Game.Screens.Edit;
namespace osu.Game.Tests.Editor
{
[TestFixture]
public class EditorChangeHandlerTest
{
[Test]
public void TestSaveRestoreState()
{
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
Assert.That(handler.HasUndoState, Is.False);
handler.SaveState();
Assert.That(handler.HasUndoState, Is.True);
handler.RestoreState(-1);
Assert.That(handler.HasUndoState, Is.False);
}
[Test]
public void TestMaxStatesSaved()
{
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
Assert.That(handler.HasUndoState, Is.False);
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
handler.SaveState();
Assert.That(handler.HasUndoState, Is.True);
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
{
Assert.That(handler.HasUndoState, Is.True);
handler.RestoreState(-1);
}
Assert.That(handler.HasUndoState, Is.False);
}
[Test]
public void TestMaxStatesExceeded()
{
var handler = new EditorChangeHandler(new EditorBeatmap(new Beatmap()));
Assert.That(handler.HasUndoState, Is.False);
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES * 2; i++)
handler.SaveState();
Assert.That(handler.HasUndoState, Is.True);
for (int i = 0; i < EditorChangeHandler.MAX_SAVED_STATES; i++)
{
Assert.That(handler.HasUndoState, Is.True);
handler.RestoreState(-1);
}
Assert.That(handler.HasUndoState, Is.False);
}
}
}

View File

@ -0,0 +1,342 @@
// 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.IO;
using System.Text;
using NUnit.Framework;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osuTK;
using Decoder = osu.Game.Beatmaps.Formats.Decoder;
namespace osu.Game.Tests.Editor
{
[TestFixture]
public class LegacyEditorBeatmapPatcherTest
{
private LegacyEditorBeatmapPatcher patcher;
private EditorBeatmap current;
[SetUp]
public void Setup()
{
patcher = new LegacyEditorBeatmapPatcher(current = new EditorBeatmap(new OsuBeatmap
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
}
}));
}
[Test]
public void TestAddHitObject()
{
var patch = new OsuBeatmap
{
HitObjects =
{
new HitCircle { StartTime = 1000 }
}
};
runTest(patch);
}
[Test]
public void TestInsertHitObject()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[0],
new HitCircle { StartTime = 2000 },
(OsuHitObject)current.HitObjects[1],
}
};
runTest(patch);
}
[Test]
public void TestDeleteHitObject()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[0],
(OsuHitObject)current.HitObjects[2],
}
};
runTest(patch);
}
[Test]
public void TestChangeStartTime()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
new HitCircle { StartTime = 500 },
(OsuHitObject)current.HitObjects[1],
(OsuHitObject)current.HitObjects[2],
}
};
runTest(patch);
}
[Test]
public void TestChangeSample()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[0],
new HitCircle { StartTime = 2000, Samples = { new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH } } },
(OsuHitObject)current.HitObjects[2],
}
};
runTest(patch);
}
[Test]
public void TestChangeSliderPath()
{
current.AddRange(new OsuHitObject[]
{
new HitCircle { StartTime = 1000 },
new Slider
{
StartTime = 2000,
Path = new SliderPath(new[]
{
new PathControlPoint(Vector2.Zero),
new PathControlPoint(Vector2.One),
new PathControlPoint(new Vector2(2), PathType.Bezier),
new PathControlPoint(new Vector2(3)),
}, 50)
},
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[0],
new Slider
{
StartTime = 2000,
Path = new SliderPath(new[]
{
new PathControlPoint(Vector2.Zero, PathType.Bezier),
new PathControlPoint(new Vector2(4)),
new PathControlPoint(new Vector2(5)),
}, 100)
},
(OsuHitObject)current.HitObjects[2],
}
};
runTest(patch);
}
[Test]
public void TestAddMultipleHitObjects()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 3000 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
new HitCircle { StartTime = 500 },
(OsuHitObject)current.HitObjects[0],
new HitCircle { StartTime = 1500 },
(OsuHitObject)current.HitObjects[1],
new HitCircle { StartTime = 2250 },
new HitCircle { StartTime = 2500 },
(OsuHitObject)current.HitObjects[2],
new HitCircle { StartTime = 3500 },
}
};
runTest(patch);
}
[Test]
public void TestDeleteMultipleHitObjects()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 500 },
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 1500 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 2250 },
new HitCircle { StartTime = 2500 },
new HitCircle { StartTime = 3000 },
new HitCircle { StartTime = 3500 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[1],
(OsuHitObject)current.HitObjects[3],
(OsuHitObject)current.HitObjects[6],
}
};
runTest(patch);
}
[Test]
public void TestChangeSamplesOfMultipleHitObjects()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 500 },
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 1500 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 2250 },
new HitCircle { StartTime = 2500 },
new HitCircle { StartTime = 3000 },
new HitCircle { StartTime = 3500 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
(OsuHitObject)current.HitObjects[0],
new HitCircle { StartTime = 1000, Samples = { new HitSampleInfo { Name = HitSampleInfo.HIT_FINISH } } },
(OsuHitObject)current.HitObjects[2],
(OsuHitObject)current.HitObjects[3],
new HitCircle { StartTime = 2250, Samples = { new HitSampleInfo { Name = HitSampleInfo.HIT_WHISTLE } } },
(OsuHitObject)current.HitObjects[5],
new HitCircle { StartTime = 3000, Samples = { new HitSampleInfo { Name = HitSampleInfo.HIT_CLAP } } },
(OsuHitObject)current.HitObjects[7],
}
};
runTest(patch);
}
[Test]
public void TestAddAndDeleteHitObjects()
{
current.AddRange(new[]
{
new HitCircle { StartTime = 500 },
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 1500 },
new HitCircle { StartTime = 2000 },
new HitCircle { StartTime = 2250 },
new HitCircle { StartTime = 2500 },
new HitCircle { StartTime = 3000 },
new HitCircle { StartTime = 3500 },
});
var patch = new OsuBeatmap
{
HitObjects =
{
new HitCircle { StartTime = 750 },
(OsuHitObject)current.HitObjects[1],
(OsuHitObject)current.HitObjects[4],
(OsuHitObject)current.HitObjects[5],
new HitCircle { StartTime = 2650 },
new HitCircle { StartTime = 2750 },
new HitCircle { StartTime = 4000 },
}
};
runTest(patch);
}
private void runTest(IBeatmap patch)
{
// Due to the method of testing, "patch" comes in without having been decoded via a beatmap decoder.
// This causes issues because the decoder adds various default properties (e.g. new combo on first object, default samples).
// To resolve "patch" into a sane state it is encoded and then re-decoded.
patch = decode(encode(patch));
// Apply the patch.
patcher.Patch(encode(current), encode(patch));
// Convert beatmaps to strings for assertion purposes.
string currentStr = Encoding.ASCII.GetString(encode(current));
string patchStr = Encoding.ASCII.GetString(encode(patch));
Assert.That(currentStr, Is.EqualTo(patchStr));
}
private byte[] encode(IBeatmap beatmap)
{
using (var encoded = new MemoryStream())
{
using (var sw = new StreamWriter(encoded))
new LegacyBeatmapEncoder(beatmap).Encode(sw);
return encoded.ToArray();
}
}
private IBeatmap decode(byte[] state)
{
using (var stream = new MemoryStream(state))
using (var reader = new LineBufferedReader(stream))
return Decoder.GetDecoder<Beatmap>(reader).Decode(reader);
}
}
}

View File

@ -0,0 +1,115 @@
// 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.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Tests.Visual;
using osu.Game.Users;
namespace osu.Game.Tests.Online
{
public class TestDummyAPIRequestHandling : OsuTestScene
{
[Test]
public void TestGenericRequestHandling()
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case CommentVoteRequest cRequest:
cRequest.TriggerSuccess(new CommentBundle());
break;
}
});
CommentVoteRequest request = null;
CommentBundle response = null;
AddStep("fire request", () =>
{
response = null;
request = new CommentVoteRequest(1, CommentVoteAction.Vote);
request.Success += res => response = res;
API.Queue(request);
});
AddAssert("response event fired", () => response != null);
AddAssert("request has response", () => request.Result == response);
}
[Test]
public void TestQueueRequestHandling()
{
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.Queue(request);
});
AddAssert("response event fired", () => gotResponse);
}
[Test]
public void TestPerformRequestHandling()
{
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.Perform(request);
});
AddAssert("response event fired", () => gotResponse);
}
[Test]
public void TestPerformAsyncRequestHandling()
{
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.PerformAsync(request);
});
AddAssert("response event fired", () => gotResponse);
}
private void registerHandler()
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case LeaveChannelRequest cRequest:
cRequest.TriggerSuccess();
break;
}
});
}
}
}

View File

@ -0,0 +1,57 @@
// 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.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Rulesets.Scoring
{
public class ScoreProcessorTest
{
private ScoreProcessor scoreProcessor;
private IBeatmap beatmap;
[SetUp]
public void SetUp()
{
scoreProcessor = new ScoreProcessor();
beatmap = new TestBeatmap(new RulesetInfo())
{
HitObjects = new List<HitObject>
{
new HitCircle()
}
};
}
[TestCase(ScoringMode.Standardised, HitResult.Meh, 750_000)]
[TestCase(ScoringMode.Standardised, HitResult.Good, 800_000)]
[TestCase(ScoringMode.Standardised, HitResult.Great, 1_000_000)]
[TestCase(ScoringMode.Classic, HitResult.Meh, 50)]
[TestCase(ScoringMode.Classic, HitResult.Good, 100)]
[TestCase(ScoringMode.Classic, HitResult.Great, 300)]
public void TestSingleOsuHit(ScoringMode scoringMode, HitResult hitResult, int expectedScore)
{
scoreProcessor.Mode.Value = scoringMode;
scoreProcessor.ApplyBeatmap(beatmap);
var judgementResult = new JudgementResult(beatmap.HitObjects.Single(), new OsuJudgement())
{
Type = hitResult
};
scoreProcessor.ApplyResult(judgementResult);
Assert.IsTrue(Precision.AlmostEquals(expectedScore, scoreProcessor.TotalScore.Value));
}
}
}

View File

@ -0,0 +1,195 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Editor
{
public class TestSceneEditorChangeStates : ScreenTestScene
{
private EditorBeatmap editorBeatmap;
public override void SetUpSteps()
{
base.SetUpSteps();
Screens.Edit.Editor editor = null;
AddStep("load editor", () =>
{
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
LoadScreen(editor = new Screens.Edit.Editor());
});
AddUntilStep("wait for editor to load", () => editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
&& editor.ChildrenOfType<TimelineArea>().FirstOrDefault()?.IsLoaded == true);
AddStep("get beatmap", () => editorBeatmap = editor.ChildrenOfType<EditorBeatmap>().Single());
}
[Test]
public void TestUndoFromInitialState()
{
int hitObjectCount = 0;
AddStep("get initial state", () => hitObjectCount = editorBeatmap.HitObjects.Count);
addUndoSteps();
AddAssert("no change occurred", () => hitObjectCount == editorBeatmap.HitObjects.Count);
}
[Test]
public void TestRedoFromInitialState()
{
int hitObjectCount = 0;
AddStep("get initial state", () => hitObjectCount = editorBeatmap.HitObjects.Count);
addRedoSteps();
AddAssert("no change occurred", () => hitObjectCount == editorBeatmap.HitObjects.Count);
}
[Test]
public void TestAddObjectAndUndo()
{
HitObject addedObject = null;
HitObject removedObject = null;
HitObject expectedObject = null;
AddStep("bind removal", () =>
{
editorBeatmap.HitObjectAdded += h => addedObject = h;
editorBeatmap.HitObjectRemoved += h => removedObject = h;
});
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
AddAssert("hitobject added", () => addedObject == expectedObject);
addUndoSteps();
AddAssert("hitobject removed", () => removedObject == expectedObject);
}
[Test]
public void TestAddObjectThenUndoThenRedo()
{
HitObject addedObject = null;
HitObject removedObject = null;
HitObject expectedObject = null;
AddStep("bind removal", () =>
{
editorBeatmap.HitObjectAdded += h => addedObject = h;
editorBeatmap.HitObjectRemoved += h => removedObject = h;
});
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
addUndoSteps();
AddStep("reset variables", () =>
{
addedObject = null;
removedObject = null;
});
addRedoSteps();
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
AddAssert("no hitobject removed", () => removedObject == null);
}
[Test]
public void TestRemoveObjectThenUndo()
{
HitObject addedObject = null;
HitObject removedObject = null;
HitObject expectedObject = null;
AddStep("bind removal", () =>
{
editorBeatmap.HitObjectAdded += h => addedObject = h;
editorBeatmap.HitObjectRemoved += h => removedObject = h;
});
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
AddStep("remove object", () => editorBeatmap.Remove(expectedObject));
AddStep("reset variables", () =>
{
addedObject = null;
removedObject = null;
});
addUndoSteps();
AddAssert("hitobject added", () => addedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance)
AddAssert("no hitobject removed", () => removedObject == null);
}
[Test]
public void TestRemoveObjectThenUndoThenRedo()
{
HitObject addedObject = null;
HitObject removedObject = null;
HitObject expectedObject = null;
AddStep("bind removal", () =>
{
editorBeatmap.HitObjectAdded += h => addedObject = h;
editorBeatmap.HitObjectRemoved += h => removedObject = h;
});
AddStep("add hitobject", () => editorBeatmap.Add(expectedObject = new HitCircle { StartTime = 1000 }));
AddStep("remove object", () => editorBeatmap.Remove(expectedObject));
addUndoSteps();
AddStep("reset variables", () =>
{
addedObject = null;
removedObject = null;
});
addRedoSteps();
AddAssert("hitobject removed", () => removedObject.StartTime == expectedObject.StartTime); // Can't compare via equality (new hitobject instance after undo)
AddAssert("no hitobject added", () => addedObject == null);
}
private void addUndoSteps()
{
AddStep("press undo", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.PressKey(Key.Z);
});
AddStep("release keys", () =>
{
InputManager.ReleaseKey(Key.LControl);
InputManager.ReleaseKey(Key.Z);
});
}
private void addRedoSteps()
{
AddStep("press redo", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.PressKey(Key.LShift);
InputManager.PressKey(Key.Z);
});
AddStep("release keys", () =>
{
InputManager.ReleaseKey(Key.LControl);
InputManager.ReleaseKey(Key.LShift);
InputManager.ReleaseKey(Key.Z);
});
}
}
}

View File

@ -20,26 +20,30 @@ namespace osu.Game.Tests.Visual.Navigation
public void TestFromMainMenu() public void TestFromMainMenu()
{ {
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
var secondimport = importBeatmap(3);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
returnToMenu();
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
var secondimport = importBeatmap(2);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
public void TestFromMainMenuDifferentRuleset() public void TestFromMainMenuDifferentRuleset()
{ {
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
var secondimport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
returnToMenu();
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
var secondimport = importBeatmap(2, new ManiaRuleset().RulesetInfo);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
returnToMenu();
presentSecondDifficultyAndConfirm(firstImport, 1);
returnToMenu();
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
@ -48,8 +52,11 @@ namespace osu.Game.Tests.Visual.Navigation
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
var secondimport = importBeatmap(2); var secondimport = importBeatmap(3);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
presentSecondDifficultyAndConfirm(firstImport, 1);
presentSecondDifficultyAndConfirm(secondimport, 3);
} }
[Test] [Test]
@ -58,8 +65,17 @@ namespace osu.Game.Tests.Visual.Navigation
var firstImport = importBeatmap(1); var firstImport = importBeatmap(1);
presentAndConfirm(firstImport); presentAndConfirm(firstImport);
var secondimport = importBeatmap(2, new ManiaRuleset().RulesetInfo); var secondimport = importBeatmap(3, new ManiaRuleset().RulesetInfo);
presentAndConfirm(secondimport); presentAndConfirm(secondimport);
presentSecondDifficultyAndConfirm(firstImport, 1);
presentSecondDifficultyAndConfirm(secondimport, 3);
}
private void returnToMenu()
{
AddStep("return to menu", () => Game.ScreenStack.CurrentScreen.Exit());
AddUntilStep("wait for menu", () => Game.ScreenStack.CurrentScreen is MainMenu);
} }
private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null) private Func<BeatmapSetInfo> importBeatmap(int i, RulesetInfo ruleset = null)
@ -89,6 +105,13 @@ namespace osu.Game.Tests.Visual.Navigation
BaseDifficulty = difficulty, BaseDifficulty = difficulty,
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
}, },
new BeatmapInfo
{
OnlineBeatmapID = i * 2048,
Metadata = metadata,
BaseDifficulty = difficulty,
Ruleset = ruleset ?? new OsuRuleset().RulesetInfo
},
} }
}).Result; }).Result;
}); });
@ -106,5 +129,15 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.ID == getImport().ID); AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapSetInfo.ID == getImport().ID);
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID); AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID);
} }
private void presentSecondDifficultyAndConfirm(Func<BeatmapSetInfo> getImport, int importedID)
{
Predicate<BeatmapInfo> pred = b => b.OnlineBeatmapID == importedID * 2048;
AddStep("present difficulty", () => Game.PresentBeatmap(getImport(), pred));
AddUntilStep("wait for song select", () => Game.ScreenStack.CurrentScreen is Screens.Select.SongSelect);
AddUntilStep("correct beatmap displayed", () => Game.Beatmap.Value.BeatmapInfo.OnlineBeatmapID == importedID * 2048);
AddAssert("correct ruleset selected", () => Game.Ruleset.Value.ID == getImport().Beatmaps.First().Ruleset.ID);
}
} }
} }

View File

@ -24,7 +24,6 @@ namespace osu.Game.Tests.Visual.Online
typeof(ChangelogListing), typeof(ChangelogListing),
typeof(ChangelogSingleBuild), typeof(ChangelogSingleBuild),
typeof(ChangelogBuild), typeof(ChangelogBuild),
typeof(Comments),
}; };
protected override bool UseOnlineAPI => true; protected override bool UseOnlineAPI => true;

View File

@ -149,8 +149,8 @@ namespace osu.Game.Tests.Visual.Online
public DownloadState DownloadState => State.Value; public DownloadState DownloadState => State.Value;
public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) public TestDownloadButton(BeatmapSetInfo beatmapSet)
: base(beatmapSet, noVideo) : base(beatmapSet)
{ {
} }
} }

View File

@ -54,6 +54,35 @@ namespace osu.Game.Tests.Visual.SongSelect
this.rulesets = rulesets; this.rulesets = rulesets;
} }
[Test]
public void TestRecommendedSelection()
{
loadBeatmaps();
AddStep("set recommendation function", () => carousel.GetRecommendedBeatmap = beatmaps => beatmaps.LastOrDefault());
// check recommended was selected
advanceSelection(direction: 1, diff: false);
waitForSelection(1, 3);
// change away from recommended
advanceSelection(direction: -1, diff: true);
waitForSelection(1, 2);
// next set, check recommended
advanceSelection(direction: 1, diff: false);
waitForSelection(2, 3);
// next set, check recommended
advanceSelection(direction: 1, diff: false);
waitForSelection(3, 3);
// go back to first set and ensure user selection was retained
advanceSelection(direction: -1, diff: false);
advanceSelection(direction: -1, diff: false);
waitForSelection(1, 2);
}
/// <summary> /// <summary>
/// Test keyboard traversal /// Test keyboard traversal
/// </summary> /// </summary>

View File

@ -8,7 +8,6 @@ using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osuTK.Graphics; using osuTK.Graphics;
@ -100,21 +99,21 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestNoBackgroundHeader : OverlayHeader private class TestNoBackgroundHeader : OverlayHeader
{ {
protected override ScreenTitle CreateTitle() => new TestTitle(); protected override OverlayTitle CreateTitle() => new TestTitle();
} }
private class TestNoControlHeader : OverlayHeader private class TestNoControlHeader : OverlayHeader
{ {
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog"); protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/changelog");
protected override ScreenTitle CreateTitle() => new TestTitle(); protected override OverlayTitle CreateTitle() => new TestTitle();
} }
private class TestStringTabControlHeader : TabControlOverlayHeader<string> private class TestStringTabControlHeader : TabControlOverlayHeader<string>
{ {
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news"); protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news");
protected override ScreenTitle CreateTitle() => new TestTitle(); protected override OverlayTitle CreateTitle() => new TestTitle();
protected override Drawable CreateTitleContent() => new OverlayRulesetSelector(); protected override Drawable CreateTitleContent() => new OverlayRulesetSelector();
@ -129,7 +128,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/rankings"); protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/rankings");
protected override ScreenTitle CreateTitle() => new TestTitle(); protected override OverlayTitle CreateTitle() => new TestTitle();
} }
private enum TestEnum private enum TestEnum
@ -141,7 +140,7 @@ namespace osu.Game.Tests.Visual.UserInterface
private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader private class TestBreadcrumbControlHeader : BreadcrumbControlOverlayHeader
{ {
protected override ScreenTitle CreateTitle() => new TestTitle(); protected override OverlayTitle CreateTitle() => new TestTitle();
public TestBreadcrumbControlHeader() public TestBreadcrumbControlHeader()
{ {
@ -151,15 +150,13 @@ namespace osu.Game.Tests.Visual.UserInterface
} }
} }
private class TestTitle : ScreenTitle private class TestTitle : OverlayTitle
{ {
public TestTitle() public TestTitle()
{ {
Title = "title"; Title = "title";
Section = "section"; IconTexture = "Icons/changelog";
} }
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/changelog");
} }
} }
} }

View File

@ -0,0 +1,113 @@
// 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.Game.Overlays;
using System;
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Shapes;
using osuTK.Graphics;
using NUnit.Framework;
using osu.Framework.Utils;
using osuTK.Input;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneOverlayScrollContainer : OsuManualInputManagerTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(OverlayScrollContainer)
};
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private TestScrollContainer scroll;
private int invocationCount;
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = scroll = new TestScrollContainer
{
RelativeSizeAxes = Axes.Both,
Child = new Container
{
Height = 3000,
RelativeSizeAxes = Axes.X,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray
}
}
};
invocationCount = 0;
scroll.Button.Action += () => invocationCount++;
});
[Test]
public void TestButtonVisibility()
{
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddAssert("button is visible", () => scroll.Button.State == Visibility.Visible);
AddStep("scroll to start", () => scroll.ScrollToStart(false));
AddAssert("button is hidden", () => scroll.Button.State == Visibility.Hidden);
AddStep("scroll to 500", () => scroll.ScrollTo(500));
AddUntilStep("scrolled to 500", () => Precision.AlmostEquals(scroll.Current, 500, 0.1f));
AddAssert("button is visible", () => scroll.Button.State == Visibility.Visible);
}
[Test]
public void TestButtonAction()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddStep("invoke action", () => scroll.Button.Action.Invoke());
AddUntilStep("scrolled back to start", () => Precision.AlmostEquals(scroll.Current, 0, 0.1f));
}
[Test]
public void TestClick()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddStep("click button", () =>
{
InputManager.MoveMouseTo(scroll.Button);
InputManager.Click(MouseButton.Left);
});
AddUntilStep("scrolled back to start", () => Precision.AlmostEquals(scroll.Current, 0, 0.1f));
}
[Test]
public void TestMultipleClicks()
{
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
AddAssert("invocation count is 0", () => invocationCount == 0);
AddStep("hover button", () => InputManager.MoveMouseTo(scroll.Button));
AddRepeatStep("click button", () => InputManager.Click(MouseButton.Left), 3);
AddAssert("invocation count is 1", () => invocationCount == 1);
}
private class TestScrollContainer : OverlayScrollContainer
{
public new ScrollToTopButton Button => base.Button;
}
}
}

View File

@ -111,7 +111,7 @@ namespace osu.Game.Beatmaps.Formats
writer.WriteLine(FormattableString.Invariant($"Source: {beatmap.Metadata.Source}")); writer.WriteLine(FormattableString.Invariant($"Source: {beatmap.Metadata.Source}"));
writer.WriteLine(FormattableString.Invariant($"Tags: {beatmap.Metadata.Tags}")); writer.WriteLine(FormattableString.Invariant($"Tags: {beatmap.Metadata.Tags}"));
writer.WriteLine(FormattableString.Invariant($"BeatmapID: {beatmap.BeatmapInfo.OnlineBeatmapID ?? 0}")); writer.WriteLine(FormattableString.Invariant($"BeatmapID: {beatmap.BeatmapInfo.OnlineBeatmapID ?? 0}"));
writer.WriteLine(FormattableString.Invariant($"BeatmapSetID: {beatmap.BeatmapInfo.BeatmapSet.OnlineBeatmapSetID ?? -1}")); writer.WriteLine(FormattableString.Invariant($"BeatmapSetID: {beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID ?? -1}"));
} }
private void handleDifficulty(TextWriter writer) private void handleDifficulty(TextWriter writer)

View File

@ -49,6 +49,7 @@ namespace osu.Game.Configuration
}; };
Set(OsuSetting.ExternalLinkWarning, true); Set(OsuSetting.ExternalLinkWarning, true);
Set(OsuSetting.PreferNoVideo, false);
// Audio // Audio
Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01); Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
@ -89,6 +90,7 @@ namespace osu.Game.Configuration
Set(OsuSetting.ShowHealthDisplayWhenCantFail, true); Set(OsuSetting.ShowHealthDisplayWhenCantFail, true);
Set(OsuSetting.FadePlayfieldWhenHealthLow, true); Set(OsuSetting.FadePlayfieldWhenHealthLow, true);
Set(OsuSetting.KeyOverlay, false); Set(OsuSetting.KeyOverlay, false);
Set(OsuSetting.PositionalHitSounds, true);
Set(OsuSetting.ScoreMeter, ScoreMeterType.HitErrorBoth); Set(OsuSetting.ScoreMeter, ScoreMeterType.HitErrorBoth);
Set(OsuSetting.FloatingComments, false); Set(OsuSetting.FloatingComments, false);
@ -177,6 +179,7 @@ namespace osu.Game.Configuration
LightenDuringBreaks, LightenDuringBreaks,
ShowStoryboard, ShowStoryboard,
KeyOverlay, KeyOverlay,
PositionalHitSounds,
ScoreMeter, ScoreMeter,
FloatingComments, FloatingComments,
ShowInterface, ShowInterface,
@ -214,6 +217,7 @@ namespace osu.Game.Configuration
IncreaseFirstObjectVisibility, IncreaseFirstObjectVisibility,
ScoreDisplayMode, ScoreDisplayMode,
ExternalLinkWarning, ExternalLinkWarning,
PreferNoVideo,
Scaling, Scaling,
ScalingPositionX, ScalingPositionX,
ScalingPositionY, ScalingPositionY,

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
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;
@ -16,12 +17,7 @@ namespace osu.Game.Graphics.Containers
public class SectionsContainer<T> : Container<T> public class SectionsContainer<T> : Container<T>
where T : Drawable where T : Drawable
{ {
private Drawable expandableHeader, fixedHeader, footer, headerBackground; public Bindable<T> SelectedSection { get; } = new Bindable<T>();
private readonly OsuScrollContainer scrollContainer;
private readonly Container headerBackgroundContainer;
private readonly FlowContainer<T> scrollContentContainer;
protected override Container<T> Content => scrollContentContainer;
public Drawable ExpandableHeader public Drawable ExpandableHeader
{ {
@ -83,6 +79,7 @@ namespace osu.Game.Graphics.Containers
headerBackgroundContainer.Clear(); headerBackgroundContainer.Clear();
headerBackground = value; headerBackground = value;
if (value == null) return; if (value == null) return;
headerBackgroundContainer.Add(headerBackground); headerBackgroundContainer.Add(headerBackground);
@ -91,15 +88,37 @@ namespace osu.Game.Graphics.Containers
} }
} }
public Bindable<T> SelectedSection { get; } = new Bindable<T>(); protected override Container<T> Content => scrollContentContainer;
protected virtual FlowContainer<T> CreateScrollContentContainer() private readonly OsuScrollContainer scrollContainer;
=> new FillFlowContainer<T> private readonly Container headerBackgroundContainer;
private readonly MarginPadding originalSectionsMargin;
private Drawable expandableHeader, fixedHeader, footer, headerBackground;
private FlowContainer<T> scrollContentContainer;
private float headerHeight, footerHeight;
private float lastKnownScroll;
public SectionsContainer()
{
AddRangeInternal(new Drawable[]
{ {
Direction = FillDirection.Vertical, scrollContainer = CreateScrollContainer().With(s =>
AutoSizeAxes = Axes.Y, {
RelativeSizeAxes = Axes.X, s.RelativeSizeAxes = Axes.Both;
}; s.Masking = true;
s.ScrollbarVisible = false;
s.Child = scrollContentContainer = CreateScrollContentContainer();
}),
headerBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.X
}
});
originalSectionsMargin = scrollContentContainer.Margin;
}
public override void Add(T drawable) public override void Add(T drawable)
{ {
@ -109,40 +128,23 @@ namespace osu.Game.Graphics.Containers
footerHeight = float.NaN; footerHeight = float.NaN;
} }
private float headerHeight, footerHeight; public void ScrollTo(Drawable section) =>
private readonly MarginPadding originalSectionsMargin; scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
private void updateSectionsMargin()
{
if (!Children.Any()) return;
var newMargin = originalSectionsMargin;
newMargin.Top += headerHeight;
newMargin.Bottom += footerHeight;
scrollContentContainer.Margin = newMargin;
}
public SectionsContainer()
{
AddInternal(scrollContainer = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
ScrollbarVisible = false,
Children = new Drawable[] { scrollContentContainer = CreateScrollContentContainer() }
});
AddInternal(headerBackgroundContainer = new Container
{
RelativeSizeAxes = Axes.X
});
originalSectionsMargin = scrollContentContainer.Margin;
}
public void ScrollTo(Drawable section) => scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(section) - (FixedHeader?.BoundingBox.Height ?? 0));
public void ScrollToTop() => scrollContainer.ScrollTo(0); public void ScrollToTop() => scrollContainer.ScrollTo(0);
[NotNull]
protected virtual OsuScrollContainer CreateScrollContainer() => new OsuScrollContainer();
[NotNull]
protected virtual FlowContainer<T> CreateScrollContentContainer() =>
new FillFlowContainer<T>
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
};
protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source) protected override bool OnInvalidate(Invalidation invalidation, InvalidationSource source)
{ {
var result = base.OnInvalidate(invalidation, source); var result = base.OnInvalidate(invalidation, source);
@ -156,8 +158,6 @@ namespace osu.Game.Graphics.Containers
return result; return result;
} }
private float lastKnownScroll;
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -208,5 +208,16 @@ namespace osu.Game.Graphics.Containers
SelectedSection.Value = bestMatch; SelectedSection.Value = bestMatch;
} }
} }
private void updateSectionsMargin()
{
if (!Children.Any()) return;
var newMargin = originalSectionsMargin;
newMargin.Top += headerHeight;
newMargin.Bottom += footerHeight;
scrollContentContainer.Margin = newMargin;
}
} }
} }

View File

@ -113,13 +113,13 @@ namespace osu.Game.Graphics.UserInterface
private const float transition_length = 500; private const float transition_length = 500;
private void fadeActive() protected void FadeHovered()
{ {
Bar.FadeIn(transition_length, Easing.OutQuint); Bar.FadeIn(transition_length, Easing.OutQuint);
Text.FadeColour(Color4.White, transition_length, Easing.OutQuint); Text.FadeColour(Color4.White, transition_length, Easing.OutQuint);
} }
private void fadeInactive() protected void FadeUnhovered()
{ {
Bar.FadeOut(transition_length, Easing.OutQuint); Bar.FadeOut(transition_length, Easing.OutQuint);
Text.FadeColour(AccentColour, transition_length, Easing.OutQuint); Text.FadeColour(AccentColour, transition_length, Easing.OutQuint);
@ -128,14 +128,14 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
if (!Active.Value) if (!Active.Value)
fadeActive(); FadeHovered();
return true; return true;
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
if (!Active.Value) if (!Active.Value)
fadeInactive(); FadeUnhovered();
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -172,13 +172,19 @@ namespace osu.Game.Graphics.UserInterface
}, },
new HoverClickSounds() new HoverClickSounds()
}; };
Active.BindValueChanged(active => Text.Font = Text.Font.With(Typeface.Torus, weight: active.NewValue ? FontWeight.Bold : FontWeight.Medium), true);
} }
protected override void OnActivated() => fadeActive(); protected override void OnActivated()
{
Text.Font = Text.Font.With(weight: FontWeight.Bold);
FadeHovered();
}
protected override void OnDeactivated() => fadeInactive(); protected override void OnDeactivated()
{
Text.Font = Text.Font.With(weight: FontWeight.Medium);
FadeUnhovered();
}
} }
} }
} }

View File

@ -1,102 +0,0 @@
// 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.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface
{
public abstract class ScreenTitle : CompositeDrawable, IHasAccentColour
{
public const float ICON_WIDTH = ICON_SIZE + spacing;
public const float ICON_SIZE = 25;
private const float spacing = 6;
private const int text_offset = 2;
private SpriteIcon iconSprite;
private readonly OsuSpriteText titleText, pageText;
protected IconUsage Icon
{
set
{
if (iconSprite == null)
throw new InvalidOperationException($"Cannot use {nameof(Icon)} with a custom {nameof(CreateIcon)} function.");
iconSprite.Icon = value;
}
}
protected string Title
{
set => titleText.Text = value;
}
protected string Section
{
set => pageText.Text = value;
}
public Color4 AccentColour
{
get => pageText.Colour;
set => pageText.Colour = value;
}
protected virtual Drawable CreateIcon() => iconSprite = new SpriteIcon
{
Size = new Vector2(ICON_SIZE),
};
protected ScreenTitle()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(spacing, 0),
Direction = FillDirection.Horizontal,
Children = new[]
{
CreateIcon().With(t =>
{
t.Anchor = Anchor.Centre;
t.Origin = Anchor.Centre;
}),
titleText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold),
Margin = new MarginPadding { Bottom = text_offset }
},
new Circle
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(4),
Colour = Color4.Gray,
},
pageText = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 20),
Margin = new MarginPadding { Bottom = text_offset }
}
}
},
};
}
}
}

View File

@ -1,40 +0,0 @@
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A custom icon class for use with <see cref="ScreenTitle.CreateIcon()"/> based off a texture resource.
/// </summary>
public class ScreenTitleTextureIcon : CompositeDrawable
{
private readonly string textureName;
public ScreenTitleTextureIcon(string textureName)
{
this.textureName = textureName;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Size = new Vector2(ScreenTitle.ICON_SIZE);
InternalChild = new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = textures.Get(textureName),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fit
};
}
}
}

View File

@ -16,20 +16,27 @@ namespace osu.Game.Online.API
{ {
protected override WebRequest CreateWebRequest() => new OsuJsonWebRequest<T>(Uri); protected override WebRequest CreateWebRequest() => new OsuJsonWebRequest<T>(Uri);
public T Result => ((OsuJsonWebRequest<T>)WebRequest)?.ResponseObject; public T Result { get; private set; }
protected APIRequest() protected APIRequest()
{ {
base.Success += onSuccess; base.Success += () => TriggerSuccess(((OsuJsonWebRequest<T>)WebRequest)?.ResponseObject);
} }
private void onSuccess() => Success?.Invoke(Result);
/// <summary> /// <summary>
/// Invoked on successful completion of an API request. /// Invoked on successful completion of an API request.
/// This will be scheduled to the API's internal scheduler (run on update thread automatically). /// This will be scheduled to the API's internal scheduler (run on update thread automatically).
/// </summary> /// </summary>
public new event APISuccessHandler<T> Success; public new event APISuccessHandler<T> Success;
internal void TriggerSuccess(T result)
{
if (Result != null)
throw new InvalidOperationException("Attempted to trigger success more than once");
Result = result;
Success?.Invoke(result);
}
} }
/// <summary> /// <summary>
@ -96,10 +103,15 @@ namespace osu.Game.Online.API
{ {
if (cancelled) return; if (cancelled) return;
Success?.Invoke(); TriggerSuccess();
}); });
} }
internal void TriggerSuccess()
{
Success?.Invoke();
}
public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled")); public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled"));
public void Fail(Exception e) public void Fail(Exception e)

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.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -30,6 +31,11 @@ namespace osu.Game.Online.API
private readonly List<IOnlineComponent> components = new List<IOnlineComponent>(); private readonly List<IOnlineComponent> components = new List<IOnlineComponent>();
/// <summary>
/// Provide handling logic for an arbitrary API request.
/// </summary>
public Action<APIRequest> HandleRequest;
public APIState State public APIState State
{ {
get => state; get => state;
@ -55,11 +61,16 @@ namespace osu.Game.Online.API
public virtual void Queue(APIRequest request) public virtual void Queue(APIRequest request)
{ {
HandleRequest?.Invoke(request);
} }
public void Perform(APIRequest request) { } public void Perform(APIRequest request) => HandleRequest?.Invoke(request);
public Task PerformAsync(APIRequest request) => Task.CompletedTask; public Task PerformAsync(APIRequest request)
{
HandleRequest?.Invoke(request);
return Task.CompletedTask;
}
public void Register(IOnlineComponent component) public void Register(IOnlineComponent component)
{ {

View File

@ -315,8 +315,15 @@ namespace osu.Game
/// The user should have already requested this interactively. /// The user should have already requested this interactively.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap to select.</param> /// <param name="beatmap">The beatmap to select.</param>
public void PresentBeatmap(BeatmapSetInfo beatmap) /// <param name="difficultyCriteria">
/// Optional predicate used to try and find a difficulty to select.
/// If omitted, this will try to present the first beatmap from the current ruleset.
/// In case of failure the first difficulty of the set will be presented, ignoring the predicate.
/// </param>
public void PresentBeatmap(BeatmapSetInfo beatmap, Predicate<BeatmapInfo> difficultyCriteria = null)
{ {
difficultyCriteria ??= b => b.Ruleset.Equals(Ruleset.Value);
var databasedSet = beatmap.OnlineBeatmapSetID != null var databasedSet = beatmap.OnlineBeatmapSetID != null
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID) ? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash); : BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
@ -334,13 +341,13 @@ namespace osu.Game
menuScreen.LoadToSolo(); menuScreen.LoadToSolo();
// we might even already be at the song // we might even already be at the song
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash) if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash && difficultyCriteria(Beatmap.Value.BeatmapInfo))
{ {
return; return;
} }
// Use first beatmap available for current ruleset, else switch ruleset. // Find first beatmap that matches our predicate.
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First(); var first = databasedSet.Beatmaps.Find(difficultyCriteria) ?? databasedSet.Beatmaps.First();
Ruleset.Value = first.Ruleset; Ruleset.Value = first.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first); Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);

View File

@ -1,24 +1,19 @@
// 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;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.BeatmapListing namespace osu.Game.Overlays.BeatmapListing
{ {
public class BeatmapListingHeader : OverlayHeader public class BeatmapListingHeader : OverlayHeader
{ {
protected override ScreenTitle CreateTitle() => new BeatmapListingTitle(); protected override OverlayTitle CreateTitle() => new BeatmapListingTitle();
private class BeatmapListingTitle : ScreenTitle private class BeatmapListingTitle : OverlayTitle
{ {
public BeatmapListingTitle() public BeatmapListingTitle()
{ {
Title = @"beatmap"; Title = "beatmap listing";
Section = @"listing"; IconTexture = "Icons/changelog";
} }
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/changelog");
} }
} }
} }

View File

@ -54,7 +54,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background6 Colour = ColourProvider.Background6
}, },
new BasicScrollContainer new OverlayScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false, ScrollbarVisible = false,

View File

@ -3,7 +3,6 @@
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets; using osu.Game.Rulesets;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
@ -14,22 +13,20 @@ namespace osu.Game.Overlays.BeatmapSet
public BeatmapRulesetSelector RulesetSelector { get; private set; } public BeatmapRulesetSelector RulesetSelector { get; private set; }
protected override ScreenTitle CreateTitle() => new BeatmapHeaderTitle(); protected override OverlayTitle CreateTitle() => new BeatmapHeaderTitle();
protected override Drawable CreateTitleContent() => RulesetSelector = new BeatmapRulesetSelector protected override Drawable CreateTitleContent() => RulesetSelector = new BeatmapRulesetSelector
{ {
Current = Ruleset Current = Ruleset
}; };
private class BeatmapHeaderTitle : ScreenTitle private class BeatmapHeaderTitle : OverlayTitle
{ {
public BeatmapHeaderTitle() public BeatmapHeaderTitle()
{ {
Title = @"beatmap"; Title = "beatmap info";
Section = @"info"; IconTexture = "Icons/changelog";
} }
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/changelog");
} }
} }
} }

View File

@ -277,7 +277,8 @@ namespace osu.Game.Overlays.BeatmapSet
downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value) downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value)
{ {
Width = 50, Width = 50,
RelativeSizeAxes = Axes.Y RelativeSizeAxes = Axes.Y,
SelectedBeatmap = { BindTarget = Picker.Beatmap }
}; };
break; break;

View File

@ -39,7 +39,7 @@ namespace osu.Game.Overlays
public BeatmapSetOverlay() public BeatmapSetOverlay()
: base(OverlayColourScheme.Blue) : base(OverlayColourScheme.Blue)
{ {
OsuScrollContainer scroll; OverlayScrollContainer scroll;
Info info; Info info;
CommentsSection comments; CommentsSection comments;
@ -49,7 +49,7 @@ namespace osu.Game.Overlays
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },
scroll = new OsuScrollContainer scroll = new OverlayScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false, ScrollbarVisible = false,

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 osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -16,6 +17,13 @@ namespace osu.Game.Overlays
public OverlayHeaderBreadcrumbControl() public OverlayHeaderBreadcrumbControl()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = 47;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AccentColour = colourProvider.Light2;
} }
protected override TabItem<string> CreateTabItem(string value) => new ControlTabItem(value); protected override TabItem<string> CreateTabItem(string value) => new ControlTabItem(value);
@ -27,10 +35,18 @@ namespace osu.Game.Overlays
public ControlTabItem(string value) public ControlTabItem(string value)
: base(value) : base(value)
{ {
RelativeSizeAxes = Axes.Y;
Text.Font = Text.Font.With(size: 14); Text.Font = Text.Font.With(size: 14);
Chevron.Y = 3; Text.Anchor = Anchor.CentreLeft;
Text.Origin = Anchor.CentreLeft;
Chevron.Y = 1;
Bar.Height = 0; Bar.Height = 0;
} }
// base OsuTabItem makes font bold on activation, we don't want that here
protected override void OnActivated() => FadeHovered();
protected override void OnDeactivated() => FadeUnhovered();
} }
} }
} }

View File

@ -9,7 +9,6 @@ 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.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Overlays.Changelog namespace osu.Game.Overlays.Changelog
@ -50,8 +49,6 @@ namespace osu.Game.Overlays.Changelog
streamsBackground.Colour = colourProvider.Background5; streamsBackground.Colour = colourProvider.Background5;
} }
private ChangelogHeaderTitle title;
private void showBuild(ValueChangedEvent<APIChangelogBuild> e) private void showBuild(ValueChangedEvent<APIChangelogBuild> e)
{ {
if (e.OldValue != null) if (e.OldValue != null)
@ -63,14 +60,11 @@ namespace osu.Game.Overlays.Changelog
Current.Value = e.NewValue.ToString(); Current.Value = e.NewValue.ToString();
updateCurrentStream(); updateCurrentStream();
title.Version = e.NewValue.UpdateStream.DisplayName;
} }
else else
{ {
Current.Value = listing_string; Current.Value = listing_string;
Streams.Current.Value = null; Streams.Current.Value = null;
title.Version = null;
} }
} }
@ -100,7 +94,7 @@ namespace osu.Game.Overlays.Changelog
} }
}; };
protected override ScreenTitle CreateTitle() => title = new ChangelogHeaderTitle(); protected override OverlayTitle CreateTitle() => new ChangelogHeaderTitle();
public void Populate(List<APIUpdateStream> streams) public void Populate(List<APIUpdateStream> streams)
{ {
@ -116,20 +110,13 @@ namespace osu.Game.Overlays.Changelog
Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name); Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name);
} }
private class ChangelogHeaderTitle : ScreenTitle private class ChangelogHeaderTitle : OverlayTitle
{ {
public string Version
{
set => Section = value ?? listing_string;
}
public ChangelogHeaderTitle() public ChangelogHeaderTitle()
{ {
Title = "changelog"; Title = "changelog";
Version = null; IconTexture = "Icons/changelog";
} }
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/changelog");
} }
} }
} }

View File

@ -1,79 +0,0 @@
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osuTK.Graphics;
namespace osu.Game.Overlays.Changelog
{
public class Comments : CompositeDrawable
{
private readonly APIChangelogBuild build;
public Comments(APIChangelogBuild build)
{
this.build = build;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding
{
Horizontal = 50,
Vertical = 20,
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
LinkFlowContainer text;
InternalChildren = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 10,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreyVioletDarker
},
},
text = new LinkFlowContainer(t =>
{
t.Colour = colours.PinkLighter;
t.Font = OsuFont.Default.With(size: 14);
})
{
Padding = new MarginPadding(20),
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
}
};
text.AddParagraph("Got feedback?", t =>
{
t.Colour = Color4.White;
t.Font = OsuFont.Default.With(italics: true, size: 20);
t.Padding = new MarginPadding { Bottom = 20 };
});
text.AddParagraph("We would love to hear what you think of this update! ");
text.AddIcon(FontAwesome.Regular.GrinHearts);
text.AddParagraph("Please visit the ");
text.AddLink("web version", $"{build.Url}#comments");
text.AddText(" of this changelog to leave any comments.");
}
}
}

View File

@ -50,7 +50,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = ColourProvider.Background4, Colour = ColourProvider.Background4,
}, },
new OsuScrollContainer new OverlayScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false, ScrollbarVisible = false,

View File

@ -1,9 +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 System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online; using osu.Game.Online;
@ -14,16 +17,18 @@ namespace osu.Game.Overlays.Direct
{ {
protected bool DownloadEnabled => button.Enabled.Value; protected bool DownloadEnabled => button.Enabled.Value;
private readonly bool noVideo; /// <summary>
/// Currently selected beatmap. Used to present the correct difficulty after completing a download.
/// </summary>
public readonly IBindable<BeatmapInfo> SelectedBeatmap = new Bindable<BeatmapInfo>();
private readonly ShakeContainer shakeContainer; private readonly ShakeContainer shakeContainer;
private readonly DownloadButton button; private readonly DownloadButton button;
private Bindable<bool> noVideoSetting;
public PanelDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) public PanelDownloadButton(BeatmapSetInfo beatmapSet)
: base(beatmapSet) : base(beatmapSet)
{ {
this.noVideo = noVideo;
InternalChild = shakeContainer = new ShakeContainer InternalChild = shakeContainer = new ShakeContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -43,7 +48,7 @@ namespace osu.Game.Overlays.Direct
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, BeatmapManager beatmaps) private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig)
{ {
if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false) if (BeatmapSet.Value?.OnlineInfo?.Availability?.DownloadDisabled ?? false)
{ {
@ -52,6 +57,8 @@ namespace osu.Game.Overlays.Direct
return; return;
} }
noVideoSetting = osuConfig.GetBindable<bool>(OsuSetting.PreferNoVideo);
button.Action = () => button.Action = () =>
{ {
switch (State.Value) switch (State.Value)
@ -62,11 +69,15 @@ namespace osu.Game.Overlays.Direct
break; break;
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
game?.PresentBeatmap(BeatmapSet.Value); Predicate<BeatmapInfo> findPredicate = null;
if (SelectedBeatmap.Value != null)
findPredicate = b => b.OnlineBeatmapID == SelectedBeatmap.Value.OnlineBeatmapID;
game?.PresentBeatmap(BeatmapSet.Value, findPredicate);
break; break;
default: default:
beatmaps.Download(BeatmapSet.Value, noVideo); beatmaps.Download(BeatmapSet.Value, noVideoSetting.Value);
break; break;
} }
}; };

View File

@ -29,14 +29,8 @@ namespace osu.Game.Overlays.Music
{ {
public CollectionsMenu() public CollectionsMenu()
{ {
Masking = true;
CornerRadius = 5; CornerRadius = 5;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.3f),
Radius = 3,
Offset = new Vector2(0f, 1f),
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -3,7 +3,6 @@
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
using System; using System;
namespace osu.Game.Overlays.News namespace osu.Game.Overlays.News
@ -12,8 +11,6 @@ namespace osu.Game.Overlays.News
{ {
private const string front_page_string = "frontpage"; private const string front_page_string = "frontpage";
private NewsHeaderTitle title;
public readonly Bindable<string> Post = new Bindable<string>(null); public readonly Bindable<string> Post = new Bindable<string>(null);
public Action ShowFrontPage; public Action ShowFrontPage;
@ -40,36 +37,24 @@ namespace osu.Game.Overlays.News
{ {
TabControl.AddItem(e.NewValue); TabControl.AddItem(e.NewValue);
Current.Value = e.NewValue; Current.Value = e.NewValue;
title.IsReadingPost = true;
} }
else else
{ {
Current.Value = front_page_string; Current.Value = front_page_string;
title.IsReadingPost = false;
} }
} }
protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news"); protected override Drawable CreateBackground() => new OverlayHeaderBackground(@"Headers/news");
protected override ScreenTitle CreateTitle() => title = new NewsHeaderTitle(); protected override OverlayTitle CreateTitle() => new NewsHeaderTitle();
private class NewsHeaderTitle : ScreenTitle private class NewsHeaderTitle : OverlayTitle
{ {
private const string post_string = "post";
public bool IsReadingPost
{
set => Section = value ? post_string : front_page_string;
}
public NewsHeaderTitle() public NewsHeaderTitle()
{ {
Title = "news"; Title = "news";
IsReadingPost = false; IconTexture = "Icons/news";
} }
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/news");
} }
} }
} }

View File

@ -8,7 +8,6 @@ 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.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.News; using osu.Game.Overlays.News;
namespace osu.Game.Overlays namespace osu.Game.Overlays
@ -36,7 +35,7 @@ namespace osu.Game.Overlays
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = colours.PurpleDarkAlternative Colour = colours.PurpleDarkAlternative
}, },
new OsuScrollContainer new OverlayScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new FillFlowContainer Child = new FillFlowContainer

View File

@ -6,7 +6,6 @@ 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.Game.Graphics.UserInterface;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays namespace osu.Game.Overlays
@ -14,7 +13,6 @@ namespace osu.Game.Overlays
public abstract class OverlayHeader : Container public abstract class OverlayHeader : Container
{ {
private readonly Box titleBackground; private readonly Box titleBackground;
private readonly ScreenTitle title;
protected readonly FillFlowContainer HeaderInfo; protected readonly FillFlowContainer HeaderInfo;
@ -57,11 +55,10 @@ namespace osu.Game.Overlays
Padding = new MarginPadding Padding = new MarginPadding
{ {
Horizontal = UserProfileOverlay.CONTENT_X_MARGIN, Horizontal = UserProfileOverlay.CONTENT_X_MARGIN,
Vertical = 10,
}, },
Children = new[] Children = new[]
{ {
title = CreateTitle().With(title => CreateTitle().With(title =>
{ {
title.Anchor = Anchor.CentreLeft; title.Anchor = Anchor.CentreLeft;
title.Origin = Anchor.CentreLeft; title.Origin = Anchor.CentreLeft;
@ -86,7 +83,6 @@ namespace osu.Game.Overlays
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
{ {
titleBackground.Colour = colourProvider.Dark5; titleBackground.Colour = colourProvider.Dark5;
title.AccentColour = colourProvider.Highlight1;
} }
[NotNull] [NotNull]
@ -96,11 +92,11 @@ namespace osu.Game.Overlays
protected virtual Drawable CreateBackground() => Empty(); protected virtual Drawable CreateBackground() => Empty();
/// <summary> /// <summary>
/// Creates a <see cref="Drawable"/> on the opposite side of the <see cref="ScreenTitle"/>. Used mostly to create <see cref="OverlayRulesetSelector"/>. /// Creates a <see cref="Drawable"/> on the opposite side of the <see cref="OverlayTitle"/>. Used mostly to create <see cref="OverlayRulesetSelector"/>.
/// </summary> /// </summary>
[NotNull] [NotNull]
protected virtual Drawable CreateTitleContent() => Empty(); protected virtual Drawable CreateTitleContent() => Empty();
protected abstract ScreenTitle CreateTitle(); protected abstract OverlayTitle CreateTitle();
} }
} }

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(25, 0), Spacing = new Vector2(20, 0),
}; };
} }
} }

View File

@ -12,6 +12,7 @@ using osu.Game.Rulesets;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK; using osuTK;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -53,6 +54,8 @@ namespace osu.Game.Overlays
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Text = value.Name, Text = value.Name,
Font = OsuFont.GetFont(size: 14),
ShadowColour = Color4.Black.Opacity(0.75f)
} }
}, },
new HoverClickSounds() new HoverClickSounds()

View File

@ -0,0 +1,149 @@
// 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.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
/// <summary>
/// <see cref="OsuScrollContainer"/> which provides <see cref="ScrollToTopButton"/>. Mostly used in <see cref="FullscreenOverlay"/>.
/// </summary>
public class OverlayScrollContainer : OsuScrollContainer
{
/// <summary>
/// Scroll position at which the <see cref="ScrollToTopButton"/> will be shown.
/// </summary>
private const int button_scroll_position = 200;
protected readonly ScrollToTopButton Button;
public OverlayScrollContainer()
{
AddInternal(Button = new ScrollToTopButton
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(20),
Action = () =>
{
ScrollToStart();
Button.State = Visibility.Hidden;
}
});
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (ScrollContent.DrawHeight + button_scroll_position < DrawHeight)
{
Button.State = Visibility.Hidden;
return;
}
Button.State = Target > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
}
public class ScrollToTopButton : OsuHoverContainer
{
private const int fade_duration = 500;
private Visibility state;
public Visibility State
{
get => state;
set
{
if (value == state)
return;
state = value;
Enabled.Value = state == Visibility.Visible;
this.FadeTo(state == Visibility.Visible ? 1 : 0, fade_duration, Easing.OutQuint);
}
}
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
private Color4 flashColour;
private readonly Container content;
private readonly Box background;
public ScrollToTopButton()
{
Size = new Vector2(50);
Alpha = 0;
Add(content = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0f, 1f),
Radius = 3f,
Colour = Color4.Black.Opacity(0.25f),
},
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(15),
Icon = FontAwesome.Solid.ChevronUp
}
}
});
TooltipText = "Scroll to top";
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
IdleColour = colourProvider.Background6;
HoverColour = colourProvider.Background5;
flashColour = colourProvider.Light1;
}
protected override bool OnClick(ClickEvent e)
{
background.FlashColour(flashColour, 800, Easing.OutQuint);
return base.OnClick(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
content.ScaleTo(0.75f, 2000, Easing.OutQuint);
return true;
}
protected override void OnMouseUp(MouseUpEvent e)
{
content.ScaleTo(1, 1000, Easing.OutElastic);
base.OnMouseUp(e);
}
}
}
}

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 osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
@ -35,17 +36,22 @@ namespace osu.Game.Overlays
protected OverlayTabControl() protected OverlayTabControl()
{ {
TabContainer.Masking = false; TabContainer.Masking = false;
TabContainer.Spacing = new Vector2(15, 0); TabContainer.Spacing = new Vector2(20, 0);
AddInternal(bar = new Box AddInternal(bar = new Box
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 2,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.CentreLeft Origin = Anchor.BottomLeft
}); });
} }
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
AccentColour = colourProvider.Highlight1;
}
protected override Dropdown<T> CreateDropdown() => null; protected override Dropdown<T> CreateDropdown() => null;
protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value); protected override TabItem<T> CreateTabItem(T value) => new OverlayTabItem(value);
@ -90,7 +96,7 @@ namespace osu.Game.Overlays
Bar = new ExpandingBar Bar = new ExpandingBar
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
ExpandedSize = 7.5f, ExpandedSize = 5f,
CollapsedSize = 0 CollapsedSize = 0
}, },
new HoverClickSounds() new HoverClickSounds()
@ -119,6 +125,7 @@ namespace osu.Game.Overlays
{ {
HoverAction(); HoverAction();
Text.Font = Text.Font.With(weight: FontWeight.Bold); Text.Font = Text.Font.With(weight: FontWeight.Bold);
Text.FadeColour(Color4.White, 120, Easing.InQuad);
} }
protected override void OnDeactivated() protected override void OnDeactivated()
@ -135,11 +142,7 @@ namespace osu.Game.Overlays
OnDeactivated(); OnDeactivated();
} }
protected virtual void HoverAction() protected virtual void HoverAction() => Bar.Expand();
{
Bar.Expand();
Text.FadeColour(Color4.White, 120, Easing.InQuad);
}
protected virtual void UnhoverAction() protected virtual void UnhoverAction()
{ {

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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
namespace osu.Game.Overlays
{
public abstract class OverlayTitle : CompositeDrawable
{
private readonly OsuSpriteText title;
private readonly Container icon;
protected string Title
{
set => title.Text = value;
}
protected string IconTexture
{
set => icon.Child = new OverlayTitleIcon(value);
}
protected OverlayTitle()
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(10, 0),
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
icon = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Horizontal = 5 }, // compensates for osu-web sprites having around 5px of whitespace on each side
Size = new Vector2(30)
},
title = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Regular),
Margin = new MarginPadding { Vertical = 17.5f } // 15px padding + 2.5px line-height difference compensation
}
}
};
}
private class OverlayTitleIcon : Sprite
{
private readonly string textureName;
public OverlayTitleIcon(string textureName)
{
this.textureName = textureName;
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
FillMode = FillMode.Fit;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Texture = textures.Get(textureName);
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More