1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 19:18:03 +08:00
osu-lazer/osu.Game/GameModes/GameModeWhiteBox.cs

173 lines
6.3 KiB
C#
Raw Normal View History

2016-09-29 19:13:58 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface;
using osu.Game.GameModes.Backgrounds;
2016-09-29 19:13:58 +08:00
using OpenTK;
using OpenTK.Graphics;
2016-10-10 16:17:26 +08:00
using osu.Framework;
2016-09-29 19:13:58 +08:00
namespace osu.Game.GameModes
{
2016-10-05 15:35:10 +08:00
public class GameModeWhiteBox : OsuGameMode
2016-09-29 19:13:58 +08:00
{
private Button popButton;
const int transition_time = 1000;
protected virtual IEnumerable<Type> PossibleChildren => null;
private FlowContainer childModeButtons;
private Container textContainer;
2016-10-05 15:35:10 +08:00
private Box box;
2016-09-29 19:13:58 +08:00
2016-10-05 19:03:52 +08:00
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg2");
2016-10-05 15:35:10 +08:00
protected override void OnEntering(GameMode last)
2016-09-29 19:13:58 +08:00
{
2016-10-05 15:35:10 +08:00
base.OnEntering(last);
2016-09-29 19:13:58 +08:00
//only show the pop button if we are entered form another gamemode.
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
}
protected override bool OnExiting(GameMode next)
2016-09-29 19:13:58 +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
}
2016-10-05 15:35:10 +08:00
protected override void OnSuspending(GameMode 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
}
2016-10-05 15:35:10 +08:00
protected override void OnResuming(GameMode 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
}
2016-10-10 16:17:26 +08:00
public override void Load(BaseGame game)
2016-09-29 19:13:58 +08:00
{
2016-10-10 16:17:26 +08:00
base.Load(game);
2016-09-29 19:13:58 +08:00
Children = new Drawable[]
{
2016-10-05 15:35:10 +08:00
box = new Box
2016-09-29 19:13:58 +08:00
{
RelativeSizeAxes = Axes.Both,
2016-10-05 15:35:10 +08:00
Size = new Vector2(0.3f),
2016-09-29 19:13:58 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = getColourFor(GetType()),
2016-10-05 15:35:10 +08:00
Alpha = 1,
Additive = false
2016-09-29 19:13:58 +08:00
},
2016-10-22 16:50:42 +08:00
textContainer = new Container
2016-09-29 19:13:58 +08:00
{
2016-10-22 16:50:42 +08:00
AutoSizeAxes = Axes.Both,
2016-09-29 19:13:58 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new[]
{
new SpriteText
{
Text = GetType().Name,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 50,
},
new SpriteText
{
Text = GetType().Namespace,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 30)
},
}
2016-09-29 19:13:58 +08:00
},
popButton = new Button
{
Text = @"Back",
RelativeSizeAxes = Axes.X,
2016-09-29 19:13:58 +08:00
Size = new Vector2(0.1f, 40),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Colour = new Color4(235, 51, 153, 255),
Alpha = 0,
Action = delegate {
Exit();
}
},
childModeButtons = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
2016-09-29 19:13:58 +08:00
Size = new Vector2(0.1f, 1)
}
};
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,
Colour = getColourFor(t),
Action = delegate
{
Push(Activator.CreateInstance(t) as GameMode);
}
});
}
}
}
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);
}
}
}