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

325 lines
14 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-10-07 16:07:23 +08:00
using System;
2016-11-14 16:23:33 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2017-05-24 00:17:09 +08:00
using osu.Framework.Audio.Track;
2016-10-07 16:07:23 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2016-11-14 16:23:33 +08:00
using osu.Framework.Graphics.Textures;
2016-10-07 16:07:23 +08:00
using osu.Framework.Input;
using osu.Framework.MathUtils;
2017-05-24 00:17:09 +08:00
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
2016-12-01 19:21:14 +08:00
using osu.Game.Graphics.Backgrounds;
2017-05-23 11:29:43 +08:00
using osu.Game.Graphics.Containers;
using OpenTK;
2016-12-01 19:21:14 +08:00
using OpenTK.Graphics;
2016-10-07 16:07:23 +08:00
2016-11-14 16:23:33 +08:00
namespace osu.Game.Screens.Menu
2016-10-07 16:07:23 +08:00
{
/// <summary>
/// osu! logo and its attachments (pulsing, visualiser etc.)
/// </summary>
2017-05-23 11:29:43 +08:00
public class OsuLogo : BeatSyncedContainer
2016-10-07 16:07:23 +08:00
{
2017-05-08 18:56:04 +08:00
public readonly Color4 OsuPink = OsuColour.FromHex(@"e967a1");
private readonly Sprite logo;
private readonly CircularContainer logoContainer;
private readonly Container logoBounceContainer;
2017-05-23 11:29:43 +08:00
private readonly Container logoBeatContainer;
2017-05-24 00:45:01 +08:00
private readonly Container logoAmplitudeContainer;
private readonly Container logoHoverContainer;
2016-10-07 16:07:23 +08:00
private SampleChannel sampleClick;
private readonly Container colourAndTriangles;
2016-12-01 19:21:14 +08:00
private Triangles triangles;
2016-10-07 16:07:23 +08:00
public Action Action;
public float SizeForFlow => logo == null ? 0 : logo.DrawSize.X * logo.Scale.X * logoBounceContainer.Scale.X * logoHoverContainer.Scale.X * 0.74f;
2016-10-07 16:07:23 +08:00
private readonly Sprite ripple;
2016-10-07 16:07:23 +08:00
private readonly Container rippleContainer;
2016-10-07 16:07:23 +08:00
2016-12-01 19:21:14 +08:00
public bool Triangles
{
set
{
colourAndTriangles.Alpha = value ? 1 : 0;
}
}
protected override bool InternalContains(Vector2 screenSpacePos) => logoContainer.Contains(screenSpacePos);
2016-10-07 16:07:23 +08:00
public bool Ripple
{
get { return rippleContainer.Alpha > 0; }
set
{
rippleContainer.Alpha = value ? 1 : 0;
}
}
public bool Interactive = true;
private readonly Box flashLayer;
2016-10-07 16:07:23 +08:00
private readonly Container impactContainer;
private const float default_size = 480;
2017-05-23 11:29:43 +08:00
private const double beat_in_time = 60;
2016-10-07 16:07:23 +08:00
public OsuLogo()
{
2017-05-23 11:29:43 +08:00
EarlyActivationMilliseconds = beat_in_time;
Size = new Vector2(default_size);
2016-10-07 16:07:23 +08:00
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
2016-10-22 16:50:42 +08:00
AutoSizeAxes = Axes.Both;
2016-10-07 16:07:23 +08:00
Children = new Drawable[]
{
logoHoverContainer = new Container
2016-10-07 16:07:23 +08:00
{
2016-10-22 16:50:42 +08:00
AutoSizeAxes = Axes.Both,
2016-10-07 16:07:23 +08:00
Children = new Drawable[]
{
2017-05-23 11:29:43 +08:00
logoBounceContainer = new Container
2016-10-07 16:07:23 +08:00
{
2016-10-22 17:40:04 +08:00
AutoSizeAxes = Axes.Both,
2016-12-01 19:21:14 +08:00
Children = new Drawable[]
{
rippleContainer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
ripple = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BlendingMode = BlendingMode.Additive,
Alpha = 0
}
}
},
2017-05-24 00:45:01 +08:00
logoAmplitudeContainer = new Container
2016-12-01 19:21:14 +08:00
{
AutoSizeAxes = Axes.Both,
2016-12-01 19:21:14 +08:00
Children = new Drawable[]
{
2017-05-24 00:45:01 +08:00
logoBeatContainer = new Container
2016-12-01 19:21:14 +08:00
{
2017-05-23 11:29:43 +08:00
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
2017-05-24 00:45:01 +08:00
new BufferedContainer
{
2017-05-24 00:45:01 +08:00
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
2017-05-24 00:45:01 +08:00
logoContainer = new CircularContainer
{
2017-05-23 11:29:43 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-05-24 00:45:01 +08:00
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.88f),
Masking = true,
2017-05-23 11:29:43 +08:00
Children = new Drawable[]
{
2017-05-24 00:45:01 +08:00
colourAndTriangles = new Container
2017-05-23 11:29:43 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-05-24 00:45:01 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuPink,
},
triangles = new Triangles
2017-05-24 00:45:01 +08:00
{
TriangleScale = 4,
ColourLight = OsuColour.FromHex(@"ff7db7"),
ColourDark = OsuColour.FromHex(@"de5b95"),
RelativeSizeAxes = Axes.Both,
},
}
2017-05-23 11:29:43 +08:00
},
2017-05-24 00:45:01 +08:00
flashLayer = new Box
2017-05-23 11:29:43 +08:00
{
RelativeSizeAxes = Axes.Both,
2017-05-24 00:45:01 +08:00
BlendingMode = BlendingMode.Additive,
Colour = Color4.White,
Alpha = 0,
2017-05-23 11:29:43 +08:00
},
2017-05-24 00:45:01 +08:00
},
},
2017-05-24 00:45:01 +08:00
logo = new Sprite
{
2017-05-24 00:45:01 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
2017-05-24 00:45:01 +08:00
}
},
2017-05-24 00:45:01 +08:00
impactContainer = new CircularContainer
{
2017-05-23 11:29:43 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-05-24 00:45:01 +08:00
Alpha = 0,
BorderColour = Color4.White,
RelativeSizeAxes = Axes.Both,
BorderThickness = 10,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
AlwaysPresent = true,
Alpha = 0,
}
}
},
2017-05-24 00:45:01 +08:00
new MenuVisualisation
2017-05-23 11:29:43 +08:00
{
2017-05-24 00:45:01 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-05-23 11:29:43 +08:00
RelativeSizeAxes = Axes.Both,
2017-05-24 00:45:01 +08:00
BlendingMode = BlendingMode.Additive,
Alpha = 0.2f,
2017-05-23 11:29:43 +08:00
}
}
}
}
2016-10-07 16:07:23 +08:00
}
}
}
}
}
};
}
[BackgroundDependencyLoader]
2017-05-24 01:09:31 +08:00
private void load(TextureStore textures, AudioManager audio)
2016-10-07 16:07:23 +08:00
{
sampleClick = audio.Sample.Get(@"Menu/menuhit");
logo.Texture = textures.Get(@"Menu/logo");
ripple.Texture = textures.Get(@"Menu/logo");
2016-11-01 22:24:14 +08:00
}
2017-05-24 00:45:01 +08:00
private int lastBeatIndex;
2017-05-24 00:17:09 +08:00
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
2017-05-23 11:29:43 +08:00
{
2017-05-24 00:17:09 +08:00
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
2017-05-23 11:29:43 +08:00
2017-05-24 00:45:01 +08:00
lastBeatIndex = beatIndex;
2017-05-24 00:17:09 +08:00
var beatLength = timingPoint.BeatLength;
2016-10-07 16:07:23 +08:00
2017-05-24 00:45:01 +08:00
float amplitudeAdjust = Math.Min(1, 0.4f + amplitudes.Maximum);
2017-05-24 00:17:09 +08:00
if (beatIndex < 0) return;
2017-05-24 00:45:01 +08:00
logoBeatContainer.ScaleTo(1 - 0.02f * amplitudeAdjust, beat_in_time, EasingTypes.Out);
2017-05-23 11:29:43 +08:00
using (logoBeatContainer.BeginDelayedSequence(beat_in_time))
logoBeatContainer.ScaleTo(1, beatLength * 2, EasingTypes.OutQuint);
ripple.ClearTransforms();
2017-05-24 00:45:01 +08:00
ripple.ScaleTo(logoAmplitudeContainer.Scale);
ripple.Alpha = 0.15f * amplitudeAdjust;
2017-05-24 00:45:01 +08:00
ripple.ScaleTo(logoAmplitudeContainer.Scale * (1 + 0.04f * amplitudeAdjust), beatLength, EasingTypes.OutQuint);
ripple.FadeOut(beatLength, EasingTypes.OutQuint);
2017-05-23 15:27:01 +08:00
2017-05-24 00:17:09 +08:00
if (effectPoint.KiaiMode && flashLayer.Alpha < 0.4f)
2017-05-23 15:27:01 +08:00
{
flashLayer.ClearTransforms();
2017-05-24 00:45:01 +08:00
flashLayer.FadeTo(0.2f * amplitudeAdjust, beat_in_time, EasingTypes.Out);
2017-05-23 15:27:01 +08:00
using (flashLayer.BeginDelayedSequence(beat_in_time))
flashLayer.FadeOut(beatLength);
}
2017-05-23 11:29:43 +08:00
}
2017-05-24 00:45:01 +08:00
protected override void Update()
{
base.Update();
const float velocity_adjust_cutoff = 0.98f;
2017-05-24 01:53:21 +08:00
var maxAmplitude = lastBeatIndex >= 0 ? Beatmap.Value?.Track?.CurrentAmplitudes.Maximum ?? 0 : 0;
2017-05-24 00:45:01 +08:00
logoAmplitudeContainer.ScaleTo(1 - maxAmplitude * 0.04f, 50, EasingTypes.OutQuint);
if (maxAmplitude > velocity_adjust_cutoff)
triangles.Velocity = 1 + Math.Max(0, maxAmplitude - velocity_adjust_cutoff) * 50;
else
triangles.Velocity = (float)Interpolation.Damp(triangles.Velocity, 1, 0.995f, Time.Elapsed);
2017-05-24 00:45:01 +08:00
}
2016-10-07 16:07:23 +08:00
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
if (!Interactive) return false;
logoBounceContainer.ScaleTo(0.9f, 1000, EasingTypes.Out);
2016-10-07 16:07:23 +08:00
return true;
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
logoBounceContainer.ScaleTo(1f, 500, EasingTypes.OutElastic);
2016-10-07 16:07:23 +08:00
return true;
}
protected override bool OnClick(InputState state)
{
if (!Interactive) return false;
sampleClick.Play();
2017-02-25 20:12:39 +08:00
flashLayer.ClearTransforms();
flashLayer.Alpha = 0.4f;
flashLayer.FadeOut(1500, EasingTypes.OutExpo);
2016-10-07 16:07:23 +08:00
Action?.Invoke();
return true;
}
protected override bool OnHover(InputState state)
{
if (!Interactive) return false;
logoHoverContainer.ScaleTo(1.1f, 500, EasingTypes.OutElastic);
2016-10-07 16:07:23 +08:00
return true;
}
protected override void OnHoverLost(InputState state)
{
logoHoverContainer.ScaleTo(1, 500, EasingTypes.OutElastic);
2016-10-07 16:07:23 +08:00
}
public void Impact()
{
impactContainer.FadeOutFromOne(250, EasingTypes.In);
impactContainer.ScaleTo(0.96f);
impactContainer.ScaleTo(1.12f, 250);
}
2016-10-07 16:07:23 +08:00
}
2017-05-24 01:53:21 +08:00
}