1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Add supporter display to main menu

This commit is contained in:
Dean Herbert 2023-12-28 17:14:16 +09:00
parent b19f72481b
commit 1f2339244e
No known key found for this signature in database
3 changed files with 176 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// 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.Framework.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Screens.Menu;
namespace osu.Game.Tests.Visual.Menus
{
public partial class TestSceneSupporterDisplay : OsuTestScene
{
[Test]
public void TestBasic()
{
AddStep("create display", () =>
{
Child = new SupporterDisplay
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
});
AddStep("toggle support", () =>
{
((DummyAPIAccess)API).LocalUser.Value = new APIUser
{
Username = API.LocalUser.Value.Username,
Id = API.LocalUser.Value.Id + 1,
IsSupporter = !API.LocalUser.Value.IsSupporter,
};
});
}
}
}

View File

@ -96,6 +96,7 @@ namespace osu.Game.Screens.Menu
private Container logoTarget;
private MenuTip menuTip;
private FillFlowContainer bottomElementsFlow;
private SupporterDisplay supporterDisplay;
private Sample reappearSampleSwoosh;
@ -179,6 +180,12 @@ namespace osu.Game.Screens.Menu
}
}
},
supporterDisplay = new SupporterDisplay
{
Margin = new MarginPadding(5),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
},
holdToExitGameOverlay?.CreateProxy() ?? Empty()
});
@ -339,6 +346,9 @@ namespace osu.Game.Screens.Menu
bottomElementsFlow
.ScaleTo(0.9f, 1000, Easing.OutQuint)
.FadeOut(500, Easing.OutQuint);
supporterDisplay
.FadeOut(500, Easing.OutQuint);
}
public override void OnResuming(ScreenTransitionEvent e)
@ -403,6 +413,9 @@ namespace osu.Game.Screens.Menu
bottomElementsFlow
.FadeOut(500, Easing.OutQuint);
supporterDisplay
.FadeOut(500, Easing.OutQuint);
return base.OnExiting(e);
}

View File

@ -0,0 +1,126 @@
// 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.Extensions.IEnumerableExtensions;
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;
using osu.Game.Online.API.Requests.Responses;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Menu
{
public partial class SupporterDisplay : CompositeDrawable
{
private LinkFlowContainer supportFlow = null!;
private Drawable heart = null!;
private readonly IBindable<APIUser> currentUser = new Bindable<APIUser>();
private Box backgroundBox = null!;
[Resolved]
private IAPIProvider api { get; set; } = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
Height = 40;
AutoSizeAxes = Axes.X;
AutoSizeDuration = 1000;
AutoSizeEasing = Easing.OutQuint;
Masking = true;
CornerExponent = 2.5f;
CornerRadius = 15;
InternalChildren = new Drawable[]
{
backgroundBox = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.4f,
},
supportFlow = new LinkFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding(10),
Spacing = new Vector2(0, 2),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
const float font_size = 14;
static void formatSemiBold(SpriteText t) => t.Font = OsuFont.GetFont(size: font_size, weight: FontWeight.SemiBold);
currentUser.BindTo(api.LocalUser);
currentUser.BindValueChanged(e =>
{
supportFlow.Children.ForEach(d => d.FadeOut().Expire());
if (e.NewValue.IsSupporter)
{
supportFlow.AddText("Eternal thanks to you for supporting osu!", formatSemiBold);
backgroundBox.FadeColour(colours.Pink, 250);
}
else
{
supportFlow.AddText("Consider becoming an ", formatSemiBold);
supportFlow.AddLink("osu!supporter", "https://osu.ppy.sh/home/support", formatSemiBold);
supportFlow.AddText(" to help support osu!'s development", formatSemiBold);
backgroundBox.FadeColour(colours.Pink4, 250);
}
supportFlow.AddIcon(FontAwesome.Solid.Heart, t =>
{
heart = t;
t.Padding = new MarginPadding { Left = 5, Top = 1 };
t.Font = t.Font.With(size: font_size);
t.Origin = Anchor.Centre;
t.Colour = colours.Pink;
Schedule(() =>
{
heart?.FlashColour(Color4.White, 750, Easing.OutQuint).Loop();
});
});
}, true);
this
.FadeOut()
.Delay(1000)
.FadeInFromZero(800, Easing.OutQuint);
Scheduler.AddDelayed(() =>
{
AutoSizeEasing = Easing.In;
supportFlow.BypassAutoSizeAxes = Axes.X;
this
.Delay(200)
.FadeOut(750, Easing.Out);
}, 6000);
}
}
}