osu/osu.Game/Overlays/FullscreenOverlay.cs

116 lines
3.4 KiB
C#
Raw Normal View History

2019-05-14 05:18:06 +00:00
// 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 JetBrains.Annotations;
2019-05-14 05:18:06 +00:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-05-14 05:18:06 +00:00
using osu.Framework.Graphics.Effects;
2021-01-18 07:48:12 +00:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
2019-05-14 06:19:23 +00:00
using osu.Game.Graphics.Containers;
2019-05-14 05:18:06 +00:00
using osu.Game.Online.API;
using osuTK.Graphics;
namespace osu.Game.Overlays
{
public abstract class FullscreenOverlay<T> : WaveOverlayContainer, INamedOverlayComponent
where T : OverlayHeader
2019-05-14 05:18:06 +00:00
{
public virtual string IconTexture => Header.Title.IconTexture ?? string.Empty;
public virtual LocalisableString Title => Header.Title.Title;
public virtual LocalisableString Description => Header.Title.Description;
public T Header { get; }
protected virtual Color4 BackgroundColour => ColourProvider.Background5;
2019-05-14 05:18:06 +00:00
[Resolved]
protected IAPIProvider API { get; private set; }
2020-01-26 11:02:05 +00:00
[Cached]
2020-01-30 03:50:15 +00:00
protected readonly OverlayColourProvider ColourProvider;
2020-01-24 09:24:35 +00:00
2021-01-18 07:48:12 +00:00
protected override Container<Drawable> Content => content;
private readonly Container content;
protected FullscreenOverlay(OverlayColourScheme colourScheme)
2019-05-14 05:18:06 +00:00
{
2021-01-18 07:48:12 +00:00
Header = CreateHeader();
2020-01-30 03:50:15 +00:00
ColourProvider = new OverlayColourProvider(colourScheme);
2020-01-24 09:24:35 +00:00
2019-05-14 05:18:06 +00:00
RelativeSizeAxes = Axes.Both;
RelativePositionAxes = Axes.Both;
Width = 0.85f;
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0),
Type = EdgeEffectType.Shadow,
Radius = 10
};
2021-01-18 07:48:12 +00:00
base.Content.AddRange(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = BackgroundColour
2021-01-18 07:48:12 +00:00
},
content = new Container
{
RelativeSizeAxes = Axes.Both
}
});
2019-05-14 05:18:06 +00:00
}
2020-01-24 09:24:35 +00:00
[BackgroundDependencyLoader]
private void load()
{
2020-01-30 03:50:15 +00:00
Waves.FirstWaveColour = ColourProvider.Light4;
Waves.SecondWaveColour = ColourProvider.Light3;
Waves.ThirdWaveColour = ColourProvider.Dark4;
Waves.FourthWaveColour = ColourProvider.Dark3;
2020-01-24 09:24:35 +00:00
}
[NotNull]
2021-01-18 07:48:12 +00:00
protected abstract T CreateHeader();
public override void Show()
{
if (State.Value == Visibility.Visible)
{
// re-trigger the state changed so we can potentially surface to front
State.TriggerChange();
}
else
{
base.Show();
}
}
2019-05-14 06:19:23 +00:00
protected override void PopIn()
{
base.PopIn();
FadeEdgeEffectTo(0.4f, WaveContainer.APPEAR_DURATION, Easing.Out);
}
protected override void PopOut()
{
base.PopOut();
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.In).OnComplete(_ => PopOutComplete());
}
protected virtual void PopOutComplete()
{
}
2019-05-14 05:18:06 +00:00
}
}