2024-06-23 13:22:13 +08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2024-07-31 18:55:20 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2024-06-23 13:22:13 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2024-07-26 22:44:50 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2024-06-23 13:22:13 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Localisation;
|
2024-07-31 18:55:20 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2024-08-01 19:25:45 +08:00
|
|
|
using static osu.Game.Overlays.Mods.ModCustomisationPanel;
|
2024-06-23 13:22:13 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Mods
|
|
|
|
{
|
|
|
|
public partial class ModCustomisationHeader : OsuHoverContainer
|
|
|
|
{
|
|
|
|
private Box background = null!;
|
2024-07-31 18:55:20 +08:00
|
|
|
private Box backgroundFlash = null!;
|
2024-06-23 13:22:13 +08:00
|
|
|
private SpriteIcon icon = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
|
|
|
|
2024-08-01 19:25:45 +08:00
|
|
|
public readonly Bindable<ModCustomisationPanelState> ExpandedState = new Bindable<ModCustomisationPanelState>(ModCustomisationPanelState.Collapsed);
|
2024-06-23 13:22:13 +08:00
|
|
|
|
2024-08-01 18:38:01 +08:00
|
|
|
private readonly ModCustomisationPanel panel;
|
2024-07-26 22:44:50 +08:00
|
|
|
|
2024-08-01 18:38:01 +08:00
|
|
|
public ModCustomisationHeader(ModCustomisationPanel panel)
|
2024-07-02 19:40:00 +08:00
|
|
|
{
|
2024-08-01 18:38:01 +08:00
|
|
|
this.panel = panel;
|
2024-07-02 19:40:00 +08:00
|
|
|
Enabled.Value = false;
|
|
|
|
}
|
|
|
|
|
2024-06-23 13:22:13 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
CornerRadius = 10f;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2024-07-31 18:55:20 +08:00
|
|
|
backgroundFlash = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.White.Opacity(0.4f),
|
|
|
|
Blending = BlendingParameters.Additive,
|
2024-08-03 01:19:59 +08:00
|
|
|
Alpha = 0,
|
2024-07-31 18:55:20 +08:00
|
|
|
},
|
2024-06-23 13:22:13 +08:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Text = ModSelectOverlayStrings.CustomisationPanelHeader,
|
|
|
|
UseFullGlyphHeight = false,
|
|
|
|
Font = OsuFont.Torus.With(size: 20f, weight: FontWeight.SemiBold),
|
|
|
|
Margin = new MarginPadding { Left = 20f },
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Size = new Vector2(16f),
|
|
|
|
Margin = new MarginPadding { Right = 20f },
|
|
|
|
Child = icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Icon = FontAwesome.Solid.ChevronDown,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IdleColour = colourProvider.Dark3;
|
|
|
|
HoverColour = colourProvider.Light4;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-07-02 19:40:00 +08:00
|
|
|
Enabled.BindValueChanged(e =>
|
|
|
|
{
|
|
|
|
TooltipText = e.NewValue
|
|
|
|
? string.Empty
|
|
|
|
: ModSelectOverlayStrings.CustomisationPanelDisabledReason;
|
2024-07-31 18:55:20 +08:00
|
|
|
|
|
|
|
if (e.NewValue)
|
|
|
|
{
|
|
|
|
backgroundFlash.FadeInFromZero(150, Easing.OutQuad).Then()
|
|
|
|
.FadeOutFromOne(350, Easing.OutQuad);
|
|
|
|
}
|
2024-07-02 19:40:00 +08:00
|
|
|
}, true);
|
|
|
|
|
2024-08-01 19:25:45 +08:00
|
|
|
ExpandedState.BindValueChanged(v =>
|
2024-06-23 13:22:13 +08:00
|
|
|
{
|
2024-08-01 19:25:45 +08:00
|
|
|
icon.ScaleTo(v.NewValue > ModCustomisationPanelState.Collapsed ? new Vector2(1, -1) : Vector2.One, 300, Easing.OutQuint);
|
2024-06-23 13:22:13 +08:00
|
|
|
}, true);
|
|
|
|
}
|
2024-07-26 22:44:50 +08:00
|
|
|
|
2024-08-01 19:25:45 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
if (Enabled.Value)
|
|
|
|
{
|
|
|
|
ExpandedState.Value = ExpandedState.Value switch
|
|
|
|
{
|
|
|
|
ModCustomisationPanelState.Collapsed => ModCustomisationPanelState.Expanded,
|
|
|
|
_ => ModCustomisationPanelState.Collapsed
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
}
|
|
|
|
|
2024-07-31 16:54:32 +08:00
|
|
|
private bool touchedThisFrame;
|
|
|
|
|
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
|
|
{
|
|
|
|
if (Enabled.Value)
|
|
|
|
{
|
|
|
|
touchedThisFrame = true;
|
|
|
|
Schedule(() => touchedThisFrame = false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnTouchDown(e);
|
|
|
|
}
|
|
|
|
|
2024-07-26 22:44:50 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
if (Enabled.Value)
|
|
|
|
{
|
2024-08-07 20:01:30 +08:00
|
|
|
if (!touchedThisFrame && panel.ExpandedState.Value == ModCustomisationPanelState.Collapsed)
|
|
|
|
panel.ExpandedState.Value = ModCustomisationPanelState.ExpandedByHover;
|
2024-07-31 16:54:32 +08:00
|
|
|
}
|
2024-07-26 22:44:50 +08:00
|
|
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
2024-06-23 13:22:13 +08:00
|
|
|
}
|
|
|
|
}
|