mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:52:55 +08:00
BreakOverlay and LetterboxOverlay implementation
This commit is contained in:
parent
a0bbabd18f
commit
740e766201
74
osu.Desktop.Tests/Visual/TestCaseBreakOverlay.cs
Normal file
74
osu.Desktop.Tests/Visual/TestCaseBreakOverlay.cs
Normal file
@ -0,0 +1,74 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.Screens.Play;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Desktop.Tests.Visual
|
||||
{
|
||||
internal class TestCaseBreakOverlay : OsuTestCase
|
||||
{
|
||||
public override string Description => @"Tests breaks behavior";
|
||||
|
||||
private readonly BreakOverlay breakOverlay;
|
||||
|
||||
public TestCaseBreakOverlay()
|
||||
{
|
||||
Clock = new FramedClock();
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.White,
|
||||
},
|
||||
breakOverlay = new BreakOverlay(true)
|
||||
};
|
||||
|
||||
AddStep("Add 2s break", () => startBreak(2000));
|
||||
AddStep("Add 5s break", () => startBreak(5000));
|
||||
AddStep("Add 2 breaks (2s each)", startMultipleBreaks);
|
||||
}
|
||||
|
||||
private void startBreak(double duration)
|
||||
{
|
||||
breakOverlay.Breaks = new List<BreakPeriod>
|
||||
{
|
||||
new BreakPeriod
|
||||
{
|
||||
StartTime = Clock.CurrentTime,
|
||||
EndTime = Clock.CurrentTime + duration,
|
||||
}
|
||||
};
|
||||
|
||||
breakOverlay.InitializeBreaks();
|
||||
}
|
||||
|
||||
private void startMultipleBreaks()
|
||||
{
|
||||
double currentTime = Clock.CurrentTime;
|
||||
|
||||
breakOverlay.Breaks = new List<BreakPeriod>
|
||||
{
|
||||
new BreakPeriod
|
||||
{
|
||||
StartTime = currentTime,
|
||||
EndTime = currentTime + 2000,
|
||||
},
|
||||
new BreakPeriod
|
||||
{
|
||||
StartTime = currentTime + 4000,
|
||||
EndTime = currentTime + 6000,
|
||||
}
|
||||
};
|
||||
|
||||
breakOverlay.InitializeBreaks();
|
||||
}
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@
|
||||
<Compile Include="Visual\TestCaseBeatmapOptionsOverlay.cs" />
|
||||
<Compile Include="Visual\TestCaseBeatSyncedContainer.cs" />
|
||||
<Compile Include="Visual\TestCaseBreadcrumbs.cs" />
|
||||
<Compile Include="Visual\TestCaseBreakOverlay.cs" />
|
||||
<Compile Include="Visual\TestCaseCatcher.cs" />
|
||||
<Compile Include="Visual\TestCaseChatDisplay.cs" />
|
||||
<Compile Include="Visual\TestCaseContextMenu.cs" />
|
||||
|
@ -8,7 +8,7 @@ namespace osu.Game.Beatmaps.Timing
|
||||
/// <summary>
|
||||
/// The minimum duration required for a break to have any effect.
|
||||
/// </summary>
|
||||
private const double min_break_duration = 650;
|
||||
public const double MIN_BREAK_DURATION = 650;
|
||||
|
||||
/// <summary>
|
||||
/// The break start time.
|
||||
@ -28,6 +28,6 @@ namespace osu.Game.Beatmaps.Timing
|
||||
/// <summary>
|
||||
/// Whether the break has any effect. Breaks that are too short are culled before they are added to the beatmap.
|
||||
/// </summary>
|
||||
public bool HasEffect => Duration >= min_break_duration;
|
||||
public bool HasEffect => Duration >= MIN_BREAK_DURATION;
|
||||
}
|
||||
}
|
64
osu.Game/Screens/Play/BreakOverlay.cs
Normal file
64
osu.Game/Screens/Play/BreakOverlay.cs
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class BreakOverlay : VisibilityContainer
|
||||
{
|
||||
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
|
||||
|
||||
public List<BreakPeriod> Breaks;
|
||||
|
||||
private readonly bool letterboxing;
|
||||
private readonly LetterboxOverlay letterboxOverlay;
|
||||
|
||||
public BreakOverlay(bool letterboxing)
|
||||
{
|
||||
this.letterboxing = letterboxing;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Child = letterboxOverlay = new LetterboxOverlay();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
InitializeBreaks();
|
||||
}
|
||||
|
||||
public void InitializeBreaks()
|
||||
{
|
||||
if (Breaks != null)
|
||||
{
|
||||
foreach (var b in Breaks)
|
||||
{
|
||||
if (b.HasEffect)
|
||||
{
|
||||
using (BeginAbsoluteSequence(b.StartTime, true))
|
||||
{
|
||||
Show();
|
||||
|
||||
using (BeginDelayedSequence(b.Duration, true))
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
if (letterboxing) letterboxOverlay.FadeIn(fade_duration);
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
if (letterboxing) letterboxOverlay.FadeOut(fade_duration);
|
||||
}
|
||||
}
|
||||
}
|
63
osu.Game/Screens/Play/LetterboxOverlay.cs
Normal file
63
osu.Game/Screens/Play/LetterboxOverlay.cs
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class LetterboxOverlay : Container
|
||||
{
|
||||
private const int letterbox_height = 350;
|
||||
|
||||
private Color4 transparentBlack => new Color4(0, 0, 0, 0);
|
||||
|
||||
public LetterboxOverlay()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Alpha = 0;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = letterbox_height,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new ColourInfo
|
||||
{
|
||||
TopLeft = Color4.Black,
|
||||
TopRight = Color4.Black,
|
||||
BottomLeft = transparentBlack,
|
||||
BottomRight = transparentBlack,
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = letterbox_height,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new ColourInfo
|
||||
{
|
||||
TopLeft = transparentBlack,
|
||||
TopRight = transparentBlack,
|
||||
BottomLeft = Color4.Black,
|
||||
BottomRight = Color4.Black,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -161,21 +161,25 @@ namespace osu.Game.Screens.Play
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SkipButton(firstObjectTime) { AudioClock = decoupledClock },
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Clock = offsetClock,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RulesetContainer,
|
||||
}
|
||||
Child = RulesetContainer,
|
||||
},
|
||||
hudOverlay = new HUDOverlay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
},
|
||||
new BreakOverlay(beatmap.BeatmapInfo.LetterboxInBreaks)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Breaks = beatmap.Breaks,
|
||||
Clock = decoupledClock
|
||||
},
|
||||
new SkipButton(firstObjectTime) { AudioClock = decoupledClock },
|
||||
}
|
||||
},
|
||||
failOverlay = new FailOverlay
|
||||
|
@ -81,6 +81,8 @@
|
||||
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
|
||||
<Compile Include="Beatmaps\DummyWorkingBeatmap.cs" />
|
||||
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
|
||||
<Compile Include="Screens\Play\BreakOverlay.cs" />
|
||||
<Compile Include="Screens\Play\LetterboxOverlay.cs" />
|
||||
<Compile Include="Storyboards\Drawables\IFlippable.cs" />
|
||||
<Compile Include="Storyboards\Drawables\DrawableStoryboardLayer.cs" />
|
||||
<Compile Include="Storyboards\Drawables\DrawableStoryboard.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user