1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 14:02:55 +08:00

Merge branch 'master' into autopilot

This commit is contained in:
RedMindZ 2019-05-23 14:33:30 +03:00 committed by GitHub
commit 63d2f41ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 186 additions and 23 deletions

View File

@ -0,0 +1,50 @@
// 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 osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneExpandingBar : OsuTestScene
{
public TestSceneExpandingBar()
{
Container container;
ExpandingBar expandingBar;
Add(container = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
Colour = Color4.Gray,
Alpha = 0.5f,
RelativeSizeAxes = Axes.Both,
},
expandingBar = new ExpandingBar
{
Anchor = Anchor.Centre,
ExpandedSize = 10,
CollapsedSize = 2,
Colour = Color4.DeepSkyBlue,
}
}
});
AddStep(@"Collapse", () => expandingBar.Collapse());
AddStep(@"Expand", () => expandingBar.Expand());
AddSliderStep(@"Resize container", 1, 300, 150, value => container.ResizeTo(value));
AddStep(@"Horizontal", () => expandingBar.RelativeSizeAxes = Axes.X);
AddStep(@"Anchor top", () => expandingBar.Anchor = Anchor.TopCentre);
AddStep(@"Vertical", () => expandingBar.RelativeSizeAxes = Axes.Y);
AddStep(@"Anchor left", () => expandingBar.Anchor = Anchor.CentreLeft);
}
}
}

View File

@ -28,7 +28,8 @@ namespace osu.Game.Audio
private void load()
{
track = GetTrack();
track.Completed += () => Schedule(Stop);
if (track != null)
track.Completed += () => Schedule(Stop);
}
/// <summary>
@ -56,19 +57,25 @@ namespace osu.Game.Audio
/// <summary>
/// Starts playing this <see cref="PreviewTrack"/>.
/// </summary>
public void Start() => startDelegate = Schedule(() =>
/// <returns>Whether the track is started or already playing.</returns>
public bool Start()
{
if (track == null)
return;
return false;
if (hasStarted)
return;
startDelegate = Schedule(() =>
{
if (hasStarted)
return;
hasStarted = true;
hasStarted = true;
track.Restart();
Started?.Invoke();
});
track.Restart();
Started?.Invoke();
});
return true;
}
/// <summary>
/// Stops playing this <see cref="PreviewTrack"/>.

View File

@ -0,0 +1,101 @@
// 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.Shapes;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A rounded bar which can be expanded or collapsed.
/// Generally used for tabs or breadcrumbs.
/// </summary>
public class ExpandingBar : Circle
{
private bool isCollapsed;
public bool IsCollapsed
{
get => isCollapsed;
set
{
if (value == isCollapsed)
return;
isCollapsed = value;
updateState();
}
}
private float expandedSize = 4;
public float ExpandedSize
{
get => expandedSize;
set
{
if (value == expandedSize)
return;
expandedSize = value;
updateState();
}
}
private float collapsedSize = 2;
public float CollapsedSize
{
get => collapsedSize;
set
{
if (value == collapsedSize)
return;
collapsedSize = value;
updateState();
}
}
public override Axes RelativeSizeAxes
{
get => base.RelativeSizeAxes;
set
{
base.RelativeSizeAxes = Axes.None;
Size = Vector2.Zero;
base.RelativeSizeAxes = value;
updateState();
}
}
public ExpandingBar()
{
RelativeSizeAxes = Axes.X;
Origin = Anchor.Centre;
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
}
public void Collapse() => IsCollapsed = true;
public void Expand() => IsCollapsed = false;
private void updateState()
{
float newSize = IsCollapsed ? CollapsedSize : ExpandedSize;
Easing easingType = IsCollapsed ? Easing.Out : Easing.OutElastic;
if (RelativeSizeAxes == Axes.X)
this.ResizeHeightTo(newSize, 400, easingType);
else
this.ResizeWidthTo(newSize, 400, easingType);
}
}
}

View File

@ -129,7 +129,7 @@ namespace osu.Game.Overlays.Direct
if (Preview != null)
{
Preview.Start();
attemptStart();
return;
}
@ -147,7 +147,7 @@ namespace osu.Game.Overlays.Direct
// user may have changed their mind.
if (Playing.Value)
preview.Start();
attemptStart();
});
}
else
@ -157,6 +157,12 @@ namespace osu.Game.Overlays.Direct
}
}
private void attemptStart()
{
if (Preview?.Start() != true)
Playing.Value = false;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

View File

@ -67,7 +67,7 @@ namespace osu.Game.Overlays
private class HeaderTabItem : TabItem<string>
{
private readonly OsuSpriteText text;
private readonly Drawable bar;
private readonly ExpandingBar bar;
private Color4 accentColour;
@ -92,7 +92,7 @@ namespace osu.Game.Overlays
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Children = new[]
Children = new Drawable[]
{
text = new OsuSpriteText
{
@ -102,12 +102,11 @@ namespace osu.Game.Overlays
Text = value,
Font = OsuFont.GetFont()
},
bar = new Circle
bar = new ExpandingBar
{
RelativeSizeAxes = Axes.X,
Height = 0,
Origin = Anchor.CentreLeft,
Anchor = Anchor.BottomLeft,
Anchor = Anchor.BottomCentre,
ExpandedSize = 7.5f,
CollapsedSize = 0
},
new HoverClickSounds()
};
@ -138,7 +137,7 @@ namespace osu.Game.Overlays
if (Active.Value || IsHovered)
{
text.FadeColour(Color4.White, 120, Easing.InQuad);
bar.ResizeHeightTo(7.5f, 120, Easing.InQuad);
bar.Expand();
if (Active.Value)
text.Font = text.Font.With(weight: FontWeight.Bold);
@ -146,7 +145,7 @@ namespace osu.Game.Overlays
else
{
text.FadeColour(AccentColour, 120, Easing.InQuad);
bar.ResizeHeightTo(0, 120, Easing.InQuad);
bar.Collapse();
text.Font = text.Font.With(weight: FontWeight.Medium);
}
}

View File

@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.518.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.521.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.523.0" />
<PackageReference Include="SharpCompress" Version="0.23.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.521.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.521.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.523.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.523.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />