mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
CounterPill implementation
This commit is contained in:
parent
c92332d2e4
commit
8cd96acffc
42
osu.Game.Tests/Visual/Online/TestSceneProfileCounterPill.cs
Normal file
42
osu.Game.Tests/Visual/Online/TestSceneProfileCounterPill.cs
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Overlays.Profile.Sections;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public class TestSceneProfileCounterPill : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(CounterPill)
|
||||
};
|
||||
|
||||
private readonly CounterPill pill;
|
||||
private readonly BindableInt value = new BindableInt();
|
||||
|
||||
public TestSceneProfileCounterPill()
|
||||
{
|
||||
Child = pill = new CounterPill
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Current = { BindTarget = value }
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestVisibility()
|
||||
{
|
||||
AddStep("Set value to 0", () => value.Value = 0);
|
||||
AddAssert("Check hidden", () => !pill.IsPresent);
|
||||
AddStep("Set value to 10", () => value.Value = 10);
|
||||
AddAssert("Check visible", () => pill.IsPresent);
|
||||
}
|
||||
}
|
||||
}
|
61
osu.Game/Overlays/Profile/Sections/CounterPill.cs
Normal file
61
osu.Game/Overlays/Profile/Sections/CounterPill.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Overlays.Profile.Sections
|
||||
{
|
||||
public class CounterPill : CircularContainer
|
||||
{
|
||||
private const int duration = 200;
|
||||
|
||||
public readonly BindableInt Current = new BindableInt();
|
||||
|
||||
private readonly OsuSpriteText counter;
|
||||
|
||||
public CounterPill()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Alpha = 0;
|
||||
Masking = true;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = OsuColour.Gray(0.05f)
|
||||
},
|
||||
counter = new OsuSpriteText
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Margin = new MarginPadding { Horizontal = 10, Vertical = 5 },
|
||||
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
Current.BindValueChanged(onCurrentChanged, true);
|
||||
}
|
||||
|
||||
private void onCurrentChanged(ValueChangedEvent<int> value)
|
||||
{
|
||||
if (value.NewValue == 0)
|
||||
{
|
||||
this.FadeOut(duration, Easing.OutQuint);
|
||||
return;
|
||||
}
|
||||
|
||||
counter.Text = value.NewValue.ToString();
|
||||
this.FadeIn(duration, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user