2023-12-29 07:20:44 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-06 17:56:20 +08:00
|
|
|
|
using System;
|
2023-10-20 18:22:00 +08:00
|
|
|
|
using System.Linq;
|
2016-10-08 11:53:46 +08:00
|
|
|
|
using osu.Framework;
|
2016-12-05 20:09:41 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2020-06-23 12:49:18 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
2016-10-08 11:53:46 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-07-09 17:23:34 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-04-20 16:06:26 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-07-09 17:23:34 +08:00
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-11-14 16:23:33 +08:00
|
|
|
|
namespace osu.Game.Screens.Menu
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button designed specifically for the osu!next main menu.
|
|
|
|
|
/// In order to correctly flow, we have to use a negative margin on the parent container (due to the parallelogram shape).
|
|
|
|
|
/// </summary>
|
2022-03-25 14:12:39 +08:00
|
|
|
|
public partial class MainMenuButton : BeatSyncedContainer, IStateful<ButtonState>
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2023-12-29 07:20:44 +08:00
|
|
|
|
public const float BOUNCE_COMPRESSION = 0.9f;
|
|
|
|
|
public const float HOVER_SCALE = 1.2f;
|
|
|
|
|
public const float BOUNCE_ROTATION = 8;
|
2023-11-24 10:05:57 +08:00
|
|
|
|
public event Action<ButtonState>? StateChanged;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-20 18:22:00 +08:00
|
|
|
|
public readonly Key[] TriggerKeys;
|
2019-09-22 19:30:58 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
private readonly Container content;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-11-24 10:15:18 +08:00
|
|
|
|
/// The menu state for which we are visible for (assuming only one).
|
2018-07-03 17:18:04 +08:00
|
|
|
|
/// </summary>
|
2023-11-24 10:15:18 +08:00
|
|
|
|
public ButtonSystemState VisibleState
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
VisibleStateMin = value;
|
|
|
|
|
VisibleStateMax = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ButtonSystemState VisibleStateMin = ButtonSystemState.TopLevel;
|
|
|
|
|
public ButtonSystemState VisibleStateMax = ButtonSystemState.TopLevel;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
public new MarginPadding Padding
|
|
|
|
|
{
|
|
|
|
|
get => Content.Padding;
|
|
|
|
|
set => Content.Padding = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Vector2 BaseSize { get; init; } = new Vector2(ButtonSystem.BUTTON_WIDTH, ButtonArea.BUTTON_AREA_HEIGHT);
|
|
|
|
|
|
|
|
|
|
private readonly Action<MainMenuButton>? clickAction;
|
|
|
|
|
|
|
|
|
|
private readonly Container background;
|
|
|
|
|
private readonly Drawable backgroundContent;
|
|
|
|
|
private readonly Box boxHoverLayer;
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
|
|
|
|
private Vector2 initialSize => BaseSize + Padding.Total;
|
|
|
|
|
|
|
|
|
|
private readonly string sampleName;
|
2023-11-24 10:05:57 +08:00
|
|
|
|
private Sample? sampleClick;
|
|
|
|
|
private Sample? sampleHover;
|
|
|
|
|
private SampleChannel? sampleChannel;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-26 22:22:43 +08:00
|
|
|
|
public override bool IsPresent => base.IsPresent
|
|
|
|
|
// Allow keyboard interaction based on state rather than waiting for delayed animations.
|
|
|
|
|
|| state == ButtonState.Expanded;
|
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => background.ReceivePositionalInputAt(screenSpacePos);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
public MainMenuButton(LocalisableString text, string sampleName, IconUsage symbol, Color4 colour, Action<MainMenuButton>? clickAction = null, params Key[] triggerKeys)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2017-06-29 01:19:04 +08:00
|
|
|
|
this.sampleName = sampleName;
|
2016-10-08 11:53:46 +08:00
|
|
|
|
this.clickAction = clickAction;
|
2023-10-20 18:22:00 +08:00
|
|
|
|
TriggerKeys = triggerKeys;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-22 16:50:42 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2016-10-08 11:53:46 +08:00
|
|
|
|
Alpha = 0;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
AddRangeInternal(new Drawable[]
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
background = new Container
|
2016-11-13 01:34:36 +08:00
|
|
|
|
{
|
2019-04-05 17:21:54 +08:00
|
|
|
|
// box needs to be always present to ensure the button is always sized correctly for flow
|
|
|
|
|
AlwaysPresent = true,
|
2016-11-30 13:38:45 +08:00
|
|
|
|
Masking = true,
|
2017-02-04 18:06:26 +08:00
|
|
|
|
MaskingSmoothness = 2,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2016-11-30 13:38:45 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
2017-01-11 02:44:40 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
2016-11-30 13:38:45 +08:00
|
|
|
|
Roundness = 5,
|
|
|
|
|
Radius = 8,
|
|
|
|
|
},
|
2016-11-13 01:34:36 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2017-06-07 19:53:37 +08:00
|
|
|
|
Children = new[]
|
2016-11-30 13:38:45 +08:00
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
backgroundContent = CreateBackground(colour).With(bg =>
|
2017-02-07 19:29:26 +08:00
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
bg.RelativeSizeAxes = Axes.Y;
|
|
|
|
|
bg.Anchor = Anchor.Centre;
|
|
|
|
|
bg.Origin = Anchor.Centre;
|
|
|
|
|
}),
|
2017-02-07 19:29:26 +08:00
|
|
|
|
boxHoverLayer = new Box
|
2016-11-30 13:38:45 +08:00
|
|
|
|
{
|
2017-02-04 18:06:26 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(1.5f, 0),
|
2016-11-30 13:38:45 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-08-21 12:29:50 +08:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2017-02-07 19:29:26 +08:00
|
|
|
|
Colour = Color4.White,
|
2024-05-17 16:39:24 +08:00
|
|
|
|
Depth = float.MinValue,
|
2017-02-07 19:29:26 +08:00
|
|
|
|
Alpha = 0,
|
2016-11-30 13:38:45 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2016-11-13 01:34:36 +08:00
|
|
|
|
},
|
2024-05-17 16:39:24 +08:00
|
|
|
|
content = new Container
|
2016-11-13 01:34:36 +08:00
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-11-13 01:34:36 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Shadow = true,
|
|
|
|
|
AllowMultiline = false,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = -3,
|
|
|
|
|
Bottom = 7,
|
|
|
|
|
},
|
|
|
|
|
Text = text
|
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
|
icon = new SpriteIcon
|
2016-11-13 01:34:36 +08:00
|
|
|
|
{
|
2016-11-30 12:15:34 +08:00
|
|
|
|
Shadow = true,
|
2016-11-13 01:34:36 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 16:06:48 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2023-12-29 07:15:23 +08:00
|
|
|
|
Size = new Vector2(32),
|
2023-12-31 02:56:38 +08:00
|
|
|
|
Position = new Vector2(0, 0),
|
|
|
|
|
Margin = new MarginPadding { Top = -4 },
|
2016-11-13 01:34:36 +08:00
|
|
|
|
Icon = symbol
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-13 01:34:36 +08:00
|
|
|
|
}
|
2024-05-17 16:39:24 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual Drawable CreateBackground(Colour4 accentColour) => new Container
|
|
|
|
|
{
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
EdgeSmoothness = new Vector2(1.5f, 0),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = accentColour,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
background.Shear = new Vector2(ButtonSystem.WEDGE_WIDTH / initialSize.Y, 0);
|
|
|
|
|
|
|
|
|
|
// for whatever reason, attempting to size the background "just in time" to cover the visible width
|
|
|
|
|
// results in gaps when the width changes are quick (only visible when testing menu at 100% speed, not visible slowed down).
|
|
|
|
|
// to ensure there's no missing backdrop, just use a ballpark that should be enough to always cover the width and then some.
|
|
|
|
|
// note that while on a code inspections it would seem that `1.5 * initialSize.X` would be enough, elastic usings are used in this button
|
|
|
|
|
// (which can exceed the [0;1] range during interpolation).
|
|
|
|
|
backgroundContent.Width = 2 * initialSize.X;
|
|
|
|
|
backgroundContent.Shear = -background.Shear;
|
2024-05-23 17:46:48 +08:00
|
|
|
|
|
|
|
|
|
animateState();
|
|
|
|
|
FinishTransforms(true);
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-15 14:24:31 +08:00
|
|
|
|
private bool rightward;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-06-23 12:49:18 +08:00
|
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2017-07-09 17:23:34 +08:00
|
|
|
|
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-09 17:23:34 +08:00
|
|
|
|
if (!IsHovered) return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-09 17:23:34 +08:00
|
|
|
|
double duration = timingPoint.BeatLength / 2;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-29 07:20:44 +08:00
|
|
|
|
icon.RotateTo(rightward ? BOUNCE_ROTATION : -BOUNCE_ROTATION, duration * 2, Easing.InOutSine);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-16 22:37:59 +08:00
|
|
|
|
icon.Animate(
|
2017-07-23 02:50:25 +08:00
|
|
|
|
i => i.MoveToY(-10, duration, Easing.Out),
|
2023-12-29 07:20:44 +08:00
|
|
|
|
i => i.ScaleTo(HOVER_SCALE, duration, Easing.Out)
|
2017-07-16 22:37:59 +08:00
|
|
|
|
).Then(
|
2017-07-23 02:50:25 +08:00
|
|
|
|
i => i.MoveToY(0, duration, Easing.In),
|
2023-12-29 07:20:44 +08:00
|
|
|
|
i => i.ScaleTo(new Vector2(HOVER_SCALE, HOVER_SCALE * BOUNCE_COMPRESSION), duration, Easing.In)
|
2017-07-16 22:37:59 +08:00
|
|
|
|
);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-15 14:24:31 +08:00
|
|
|
|
rightward = !rightward;
|
2017-07-09 17:23:34 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-07-09 17:23:34 +08:00
|
|
|
|
{
|
|
|
|
|
if (State != ButtonState.Expanded) return true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-09 17:23:34 +08:00
|
|
|
|
double duration = TimeUntilNextBeat;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-07-09 17:23:34 +08:00
|
|
|
|
icon.ClearTransforms();
|
2023-12-29 07:20:44 +08:00
|
|
|
|
icon.RotateTo(rightward ? -BOUNCE_ROTATION : BOUNCE_ROTATION, duration, Easing.InOutSine);
|
|
|
|
|
icon.ScaleTo(new Vector2(HOVER_SCALE, HOVER_SCALE * BOUNCE_COMPRESSION), duration, Easing.Out);
|
2024-05-17 16:39:24 +08:00
|
|
|
|
|
|
|
|
|
sampleHover?.Play();
|
|
|
|
|
background.ResizeTo(Vector2.Multiply(initialSize, new Vector2(1.5f, 1)), 500, Easing.OutElastic);
|
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2017-02-25 20:12:39 +08:00
|
|
|
|
icon.ClearTransforms();
|
2017-07-23 02:50:25 +08:00
|
|
|
|
icon.RotateTo(0, 500, Easing.Out);
|
2023-12-31 02:56:38 +08:00
|
|
|
|
icon.MoveTo(Vector2.Zero, 500, Easing.Out);
|
2017-07-23 02:50:25 +08:00
|
|
|
|
icon.ScaleTo(Vector2.One, 200, Easing.Out);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
if (State == ButtonState.Expanded)
|
2024-05-17 16:39:24 +08:00
|
|
|
|
background.ResizeTo(initialSize, 500, Easing.OutElastic);
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-05 20:09:41 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(AudioManager audio)
|
2016-12-05 20:09:41 +08:00
|
|
|
|
{
|
2019-05-28 16:06:01 +08:00
|
|
|
|
sampleHover = audio.Samples.Get(@"Menu/button-hover");
|
2022-04-15 19:31:59 +08:00
|
|
|
|
sampleClick = audio.Samples.Get(!string.IsNullOrEmpty(sampleName) ? $@"Menu/{sampleName}" : @"UI/button-select");
|
2016-12-05 20:09:41 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2017-02-07 19:29:26 +08:00
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
boxHoverLayer.FadeTo(0.1f, 1000, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnMouseDown(e);
|
2017-02-07 19:29:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
2017-02-07 19:29:26 +08:00
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
boxHoverLayer.FadeTo(0, 1000, Easing.OutQuint);
|
2020-01-20 17:17:21 +08:00
|
|
|
|
base.OnMouseUp(e);
|
2017-02-07 19:29:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
|
|
|
|
trigger();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
2022-03-25 14:13:22 +08:00
|
|
|
|
if (e.Repeat || e.ControlPressed || e.ShiftPressed || e.AltPressed || e.SuperPressed)
|
2017-03-03 13:08:37 +08:00
|
|
|
|
return false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-20 18:22:00 +08:00
|
|
|
|
if (TriggerKeys.Contains(e.Key))
|
2016-10-08 11:53:46 +08:00
|
|
|
|
{
|
|
|
|
|
trigger();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
private void trigger()
|
|
|
|
|
{
|
2023-11-08 21:18:33 +08:00
|
|
|
|
sampleChannel = sampleClick?.GetChannel();
|
|
|
|
|
sampleChannel?.Play();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
clickAction?.Invoke(this);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-25 20:12:39 +08:00
|
|
|
|
boxHoverLayer.ClearTransforms();
|
2017-02-07 19:29:26 +08:00
|
|
|
|
boxHoverLayer.Alpha = 0.9f;
|
2017-07-23 02:50:25 +08:00
|
|
|
|
boxHoverLayer.FadeOut(800, Easing.OutExpo);
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-26 13:01:15 +08:00
|
|
|
|
public override bool HandleNonPositionalInput => state == ButtonState.Expanded;
|
2024-05-17 16:39:24 +08:00
|
|
|
|
public override bool HandlePositionalInput => state != ButtonState.Exploded && background.Width / initialSize.X >= 0.8f;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-11-08 21:18:33 +08:00
|
|
|
|
public void StopSamplePlayback() => sampleChannel?.Stop();
|
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
content.Alpha = Math.Clamp((background.Width / initialSize.X - 0.5f) / 0.3f, 0, 1);
|
2016-10-08 11:53:46 +08:00
|
|
|
|
base.Update();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
public int ContractStyle;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private ButtonState state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
public ButtonState State
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => state;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-06-07 19:53:37 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-08 11:53:46 +08:00
|
|
|
|
if (state == value)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
state = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-23 17:46:48 +08:00
|
|
|
|
animateState();
|
|
|
|
|
|
|
|
|
|
StateChanged?.Invoke(State);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 17:18:04 +08:00
|
|
|
|
|
2024-05-23 17:46:48 +08:00
|
|
|
|
private void animateState()
|
|
|
|
|
{
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case ButtonState.Contracted:
|
|
|
|
|
switch (ContractStyle)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
background.ResizeTo(Vector2.Multiply(initialSize, new Vector2(0, 1)), 500, Easing.OutExpo);
|
|
|
|
|
this.FadeOut(500);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
background.ResizeTo(Vector2.Multiply(initialSize, new Vector2(0, 1)), 400, Easing.InSine);
|
|
|
|
|
this.FadeOut(800);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2024-05-23 17:46:48 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2024-05-23 17:46:48 +08:00
|
|
|
|
case ButtonState.Expanded:
|
|
|
|
|
const int expand_duration = 500;
|
|
|
|
|
background.ResizeTo(initialSize, expand_duration, Easing.OutExpo);
|
|
|
|
|
this.FadeIn(expand_duration / 6f);
|
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-05-23 17:46:48 +08:00
|
|
|
|
case ButtonState.Exploded:
|
|
|
|
|
const int explode_duration = 200;
|
|
|
|
|
background.ResizeTo(Vector2.Multiply(initialSize, new Vector2(2, 1)), explode_duration, Easing.OutExpo);
|
|
|
|
|
this.FadeOut(explode_duration / 4f * 3);
|
|
|
|
|
break;
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 17:18:04 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
private ButtonSystemState buttonSystemState;
|
|
|
|
|
|
2018-07-03 17:18:04 +08:00
|
|
|
|
public ButtonSystemState ButtonSystemState
|
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
get => buttonSystemState;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2024-05-17 16:39:24 +08:00
|
|
|
|
if (buttonSystemState == value)
|
|
|
|
|
return;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
buttonSystemState = value;
|
|
|
|
|
UpdateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
protected virtual void UpdateState()
|
|
|
|
|
{
|
|
|
|
|
ContractStyle = 0;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2024-05-17 16:39:24 +08:00
|
|
|
|
switch (ButtonSystemState)
|
|
|
|
|
{
|
|
|
|
|
case ButtonSystemState.Initial:
|
|
|
|
|
State = ButtonState.Contracted;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ButtonSystemState.EnteringMode:
|
|
|
|
|
ContractStyle = 1;
|
|
|
|
|
State = ButtonState.Contracted;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (ButtonSystemState <= VisibleStateMax && ButtonSystemState >= VisibleStateMin)
|
|
|
|
|
State = ButtonState.Expanded;
|
|
|
|
|
else if (ButtonSystemState < VisibleStateMin)
|
|
|
|
|
State = ButtonState.Contracted;
|
|
|
|
|
else
|
|
|
|
|
State = ButtonState.Exploded;
|
|
|
|
|
break;
|
2018-07-03 17:18:04 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-08 11:53:46 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-08 11:53:46 +08:00
|
|
|
|
public enum ButtonState
|
|
|
|
|
{
|
|
|
|
|
Contracted,
|
|
|
|
|
Expanded,
|
|
|
|
|
Exploded
|
|
|
|
|
}
|
|
|
|
|
}
|