1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00
osu-lazer/osu.Game/Screens/ScreenWhiteBox.cs

168 lines
5.9 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-29 19:13:58 +08:00
using System;
using System.Collections.Generic;
2017-02-17 17:59:30 +08:00
using osu.Framework.Screens;
2016-09-29 19:13:58 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
2016-11-14 16:23:33 +08:00
using osu.Game.Screens.Backgrounds;
2016-11-27 09:21:12 +08:00
using osu.Game.Graphics.UserInterface;
2016-09-29 19:13:58 +08:00
using OpenTK;
using OpenTK.Graphics;
2016-11-14 16:23:33 +08:00
namespace osu.Game.Screens
2016-09-29 19:13:58 +08:00
{
2017-02-17 17:59:30 +08:00
public class ScreenWhiteBox : OsuScreen
2016-09-29 19:13:58 +08:00
{
private readonly BackButton popButton;
2016-09-29 19:13:58 +08:00
private const double transition_time = 1000;
2016-09-29 19:13:58 +08:00
protected virtual IEnumerable<Type> PossibleChildren => null;
private readonly Container textContainer;
private readonly Box box;
2016-09-29 19:13:58 +08:00
2017-02-17 17:59:30 +08:00
protected override BackgroundScreen CreateBackground() => new BackgroundScreenCustom(@"Backgrounds/bg2");
2016-10-05 15:35:10 +08:00
2017-02-17 17:59:30 +08:00
protected override void OnEntering(Screen last)
2016-09-29 19:13:58 +08:00
{
2016-10-05 15:35:10 +08:00
base.OnEntering(last);
2017-04-18 15:05:58 +08:00
//only show the pop button if we are entered form another screen.
2016-09-29 22:52:51 +08:00
if (last != null)
popButton.Alpha = 1;
2016-09-29 19:13:58 +08:00
Content.Alpha = 0;
textContainer.Position = new Vector2(DrawSize.X / 16, 0);
2016-10-05 15:35:10 +08:00
box.ScaleTo(0.2f);
box.RotateTo(-20);
Content.Delay(300, true);
box.ScaleTo(1, transition_time, EasingTypes.OutElastic);
box.RotateTo(0, transition_time / 2, EasingTypes.OutQuint);
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
2016-09-29 19:13:58 +08:00
}
2017-02-17 17:59:30 +08:00
protected override bool OnExiting(Screen next)
2016-09-29 19:13:58 +08:00
{
2017-03-07 09:59:19 +08:00
textContainer.MoveTo(new Vector2(DrawSize.X / 16, 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
return base.OnExiting(next);
2016-09-29 19:13:58 +08:00
}
2017-02-17 17:59:30 +08:00
protected override void OnSuspending(Screen next)
2016-09-29 19:13:58 +08:00
{
2016-10-05 15:35:10 +08:00
base.OnSuspending(next);
textContainer.MoveTo(new Vector2(-(DrawSize.X / 16), 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
2016-09-29 19:13:58 +08:00
}
2017-02-17 17:59:30 +08:00
protected override void OnResuming(Screen last)
2016-09-29 19:13:58 +08:00
{
2016-10-05 15:35:10 +08:00
base.OnResuming(last);
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
2016-09-29 19:13:58 +08:00
}
2017-02-17 17:59:30 +08:00
public ScreenWhiteBox()
2016-09-29 19:13:58 +08:00
{
2017-03-09 13:24:16 +08:00
FillFlowContainer childModeButtons;
2016-09-29 19:13:58 +08:00
Children = new Drawable[]
{
box = new Box
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.3f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = getColourFor(GetType()),
Alpha = 1,
BlendingMode = BlendingMode.Additive,
},
textContainer = new Container
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new[]
2016-09-29 19:13:58 +08:00
{
new OsuSpriteText
{
Text = GetType().Name,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 50,
},
new OsuSpriteText
{
Text = GetType().Namespace,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 30)
},
}
},
2016-11-27 09:21:12 +08:00
popButton = new BackButton
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Alpha = 0,
Action = delegate {
Exit();
2016-09-29 19:13:58 +08:00
}
},
2017-03-02 02:33:01 +08:00
childModeButtons = new FillFlowContainer
{
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Vertical,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.1f, 1)
}
2016-09-29 19:13:58 +08:00
};
if (PossibleChildren != null)
{
foreach (Type t in PossibleChildren)
{
childModeButtons.Add(new Button
{
Text = $@"{t.Name}",
RelativeSizeAxes = Axes.X,
2016-09-29 19:13:58 +08:00
Size = new Vector2(1, 40),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
BackgroundColour = getColourFor(t),
2016-09-29 19:13:58 +08:00
Action = delegate
{
2017-02-17 17:59:30 +08:00
Push(Activator.CreateInstance(t) as Screen);
2016-09-29 19:13:58 +08:00
}
});
}
}
}
private Color4 getColourFor(Type type)
{
int hash = type.Name.GetHashCode();
byte r = (byte)MathHelper.Clamp(((hash & 0xFF0000) >> 16) * 0.8f, 20, 255);
byte g = (byte)MathHelper.Clamp(((hash & 0x00FF00) >> 8) * 0.8f, 20, 255);
byte b = (byte)MathHelper.Clamp((hash & 0x0000FF) * 0.8f, 20, 255);
return new Color4(r, g, b, 255);
}
}
}