1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 14:43:21 +08:00
osu-lazer/osu.Game/Screens/Select/Footer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
4.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select
{
public partial class Footer : Container
{
private readonly Box modeLight;
2018-04-13 17:19:50 +08:00
public const float HEIGHT = 50;
2018-04-13 17:19:50 +08:00
public const int TRANSITION_LENGTH = 300;
2018-04-13 17:19:50 +08:00
private const float padding = 80;
2018-04-13 17:19:50 +08:00
private readonly FillFlowContainer<FooterButton> buttons;
2018-04-13 17:19:50 +08:00
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
/// <param name="button">The button to be added.</param>
/// <param name="overlay">The <see cref="OverlayContainer"/> to be toggled by this button.</param>
public void AddButton(FooterButton button, OverlayContainer overlay)
{
if (overlay != null)
{
overlays.Add(overlay);
button.Action = () => showOverlay(overlay);
}
button.Hovered = updateModeLight;
button.HoverLost = updateModeLight;
2018-04-13 17:19:50 +08:00
buttons.Add(button);
}
2018-04-13 17:19:50 +08:00
private void showOverlay(OverlayContainer overlay)
{
foreach (var o in overlays)
{
if (o == overlay)
o.ToggleVisibility();
else
o.Hide();
}
}
2018-04-13 17:19:50 +08:00
private void updateModeLight()
{
var selectedButton = buttons.FirstOrDefault(b => b.Enabled.Value && b.IsHovered);
if (selectedButton != null)
{
modeLight.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
modeLight.FadeColour(selectedButton.SelectedColour, TRANSITION_LENGTH, Easing.OutQuint);
}
else
modeLight.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
}
2018-04-13 17:19:50 +08:00
public Footer()
{
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Colour = Color4.Black.Opacity(0.5f),
},
modeLight = new Box
{
RelativeSizeAxes = Axes.X,
Height = 3,
Position = new Vector2(0, -3),
Colour = Color4.Black,
},
2017-03-02 02:33:01 +08:00
new FillFlowContainer
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
2017-03-09 13:24:16 +08:00
Position = new Vector2(TwoLayerButton.SIZE_EXTENDED.X + padding, 0),
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Horizontal,
2017-03-02 02:33:01 +08:00
Spacing = new Vector2(padding, 0),
Children = new Drawable[]
{
buttons = new FillFlowContainer<FooterButton>
{
2017-03-04 18:00:17 +08:00
Direction = FillDirection.Horizontal,
Spacing = new Vector2(-FooterButton.SHEAR_WIDTH, 0),
AutoSizeAxes = Axes.Both,
}
}
}
};
2018-04-13 17:19:50 +08:00
updateModeLight();
}
protected override bool OnMouseDown(MouseDownEvent e) => true;
protected override bool OnClick(ClickEvent e) => true;
protected override bool OnHover(HoverEvent e) => true;
}
}