2022-12-01 18:57:50 +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.
|
|
|
|
|
2024-05-16 11:59:58 +08:00
|
|
|
using System;
|
2022-12-01 20:13:37 +08:00
|
|
|
using System.Collections.Generic;
|
2024-05-16 11:24:58 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
2022-12-01 18:57:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2024-05-16 11:59:58 +08:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Framework.Input.Events;
|
2024-06-29 15:17:40 +08:00
|
|
|
using osu.Framework.Threading;
|
2024-05-16 11:59:58 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Input.Bindings;
|
2023-02-14 05:07:09 +08:00
|
|
|
using osu.Game.Overlays;
|
2024-06-29 14:59:40 +08:00
|
|
|
using osu.Game.Overlays.Mods;
|
2024-05-16 11:59:58 +08:00
|
|
|
using osu.Game.Screens.Menu;
|
2022-12-01 20:13:37 +08:00
|
|
|
using osuTK;
|
2022-12-01 18:57:50 +08:00
|
|
|
|
2024-05-16 09:36:14 +08:00
|
|
|
namespace osu.Game.Screens.Footer
|
2022-12-01 18:57:50 +08:00
|
|
|
{
|
2024-05-16 11:24:58 +08:00
|
|
|
public partial class ScreenFooter : OverlayContainer
|
2022-12-01 18:57:50 +08:00
|
|
|
{
|
2024-05-16 09:50:51 +08:00
|
|
|
private const int padding = 60;
|
2024-05-16 11:24:58 +08:00
|
|
|
private const float delay_per_button = 30;
|
2024-06-29 15:17:40 +08:00
|
|
|
private const double transition_duration = 400;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2024-06-27 13:15:12 +08:00
|
|
|
public const int HEIGHT = 50;
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2024-05-16 11:24:58 +08:00
|
|
|
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
|
2022-12-01 20:13:37 +08:00
|
|
|
|
2024-06-29 13:42:17 +08:00
|
|
|
private Box background = null!;
|
2024-05-16 11:24:58 +08:00
|
|
|
private FillFlowContainer<ScreenFooterButton> buttonsFlow = null!;
|
|
|
|
private Container<ScreenFooterButton> removedButtonsContainer = null!;
|
2024-05-16 11:59:58 +08:00
|
|
|
private LogoTrackingContainer logoTrackingContainer = null!;
|
2022-12-01 18:57:50 +08:00
|
|
|
|
2024-05-16 11:59:58 +08:00
|
|
|
[Cached]
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
|
2024-06-29 15:17:40 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuGame? game { get; set; }
|
|
|
|
|
2024-06-29 13:42:17 +08:00
|
|
|
public ScreenBackButton BackButton { get; private set; } = null!;
|
|
|
|
|
2024-05-16 11:59:58 +08:00
|
|
|
public Action? OnBack;
|
|
|
|
|
|
|
|
public ScreenFooter(BackReceptor? receptor = null)
|
2022-12-01 18:57:50 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2024-05-16 11:24:58 +08:00
|
|
|
Height = HEIGHT;
|
2023-09-04 12:49:29 +08:00
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
Origin = Anchor.BottomLeft;
|
2024-05-16 11:59:58 +08:00
|
|
|
|
|
|
|
if (receptor == null)
|
|
|
|
Add(receptor = new BackReceptor());
|
|
|
|
|
2024-06-29 13:42:17 +08:00
|
|
|
receptor.OnBackPressed = () => BackButton.TriggerClick();
|
2023-09-04 12:49:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2024-05-16 11:59:58 +08:00
|
|
|
private void load()
|
2023-09-04 12:49:29 +08:00
|
|
|
{
|
2022-12-01 18:57:50 +08:00
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2024-06-29 14:59:40 +08:00
|
|
|
background = new Box
|
2022-12-01 18:57:50 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-02-14 05:07:09 +08:00
|
|
|
Colour = colourProvider.Background5
|
2022-12-01 20:13:37 +08:00
|
|
|
},
|
2024-05-16 11:24:58 +08:00
|
|
|
buttonsFlow = new FillFlowContainer<ScreenFooterButton>
|
2022-12-01 20:13:37 +08:00
|
|
|
{
|
2024-05-16 11:24:58 +08:00
|
|
|
Margin = new MarginPadding { Left = 12f + ScreenBackButton.BUTTON_WIDTH + padding },
|
|
|
|
Y = 10f,
|
2022-12-01 20:13:37 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Direction = FillDirection.Horizontal,
|
2024-05-10 11:47:48 +08:00
|
|
|
Spacing = new Vector2(7, 0),
|
2023-02-14 05:07:09 +08:00
|
|
|
AutoSizeAxes = Axes.Both
|
2024-05-16 09:50:51 +08:00
|
|
|
},
|
2024-06-29 13:42:17 +08:00
|
|
|
BackButton = new ScreenBackButton
|
2024-05-16 09:50:51 +08:00
|
|
|
{
|
2024-06-27 13:15:12 +08:00
|
|
|
Margin = new MarginPadding { Bottom = 15f, Left = 12f },
|
2024-05-16 09:50:51 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
2024-06-29 13:42:17 +08:00
|
|
|
Action = onBackPressed,
|
2024-05-16 09:50:51 +08:00
|
|
|
},
|
2024-05-16 11:24:58 +08:00
|
|
|
removedButtonsContainer = new Container<ScreenFooterButton>
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding { Left = 12f + ScreenBackButton.BUTTON_WIDTH + padding },
|
|
|
|
Y = 10f,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
},
|
2024-05-16 11:59:58 +08:00
|
|
|
(logoTrackingContainer = new LogoTrackingContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}).WithChild(logoTrackingContainer.LogoFacade.With(f =>
|
|
|
|
{
|
|
|
|
f.Anchor = Anchor.BottomRight;
|
|
|
|
f.Origin = Anchor.Centre;
|
|
|
|
f.Position = new Vector2(-76, -36);
|
|
|
|
})),
|
2022-12-01 18:57:50 +08:00
|
|
|
};
|
|
|
|
}
|
2024-05-16 11:24:58 +08:00
|
|
|
|
2024-06-29 15:17:40 +08:00
|
|
|
private ScheduledDelegate? changeLogoDepthDelegate;
|
|
|
|
|
|
|
|
public void StartTrackingLogo(OsuLogo logo, float duration = 0, Easing easing = Easing.None)
|
|
|
|
{
|
|
|
|
changeLogoDepthDelegate?.Cancel();
|
|
|
|
changeLogoDepthDelegate = null;
|
|
|
|
|
|
|
|
logoTrackingContainer.StartTracking(logo, duration, easing);
|
|
|
|
game?.ChangeLogoDepth(inFrontOfFooter: true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StopTrackingLogo()
|
|
|
|
{
|
|
|
|
logoTrackingContainer.StopTracking();
|
|
|
|
|
|
|
|
if (game != null)
|
|
|
|
changeLogoDepthDelegate = Scheduler.AddDelayed(() => game.ChangeLogoDepth(inFrontOfFooter: false), transition_duration);
|
|
|
|
}
|
2024-05-16 11:59:58 +08:00
|
|
|
|
2024-05-16 11:24:58 +08:00
|
|
|
protected override void PopIn()
|
|
|
|
{
|
2024-06-29 15:17:40 +08:00
|
|
|
this.MoveToY(0, transition_duration, Easing.OutQuint)
|
|
|
|
.FadeIn(transition_duration, Easing.OutQuint);
|
2024-05-16 11:24:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
2024-06-29 15:17:40 +08:00
|
|
|
this.MoveToY(HEIGHT, transition_duration, Easing.OutQuint)
|
|
|
|
.FadeOut(transition_duration, Easing.OutQuint);
|
2024-05-16 11:24:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetButtons(IReadOnlyList<ScreenFooterButton> buttons)
|
|
|
|
{
|
2024-06-29 13:35:48 +08:00
|
|
|
temporarilyHiddenButtons.Clear();
|
2024-05-16 11:24:58 +08:00
|
|
|
overlays.Clear();
|
|
|
|
|
2024-07-10 12:58:50 +08:00
|
|
|
ClearActiveOverlayContainer();
|
2024-06-29 13:35:48 +08:00
|
|
|
|
2024-05-16 11:24:58 +08:00
|
|
|
var oldButtons = buttonsFlow.ToArray();
|
|
|
|
|
|
|
|
for (int i = 0; i < oldButtons.Length; i++)
|
|
|
|
{
|
|
|
|
var oldButton = oldButtons[i];
|
|
|
|
|
|
|
|
buttonsFlow.Remove(oldButton, false);
|
|
|
|
removedButtonsContainer.Add(oldButton);
|
|
|
|
|
|
|
|
if (buttons.Count > 0)
|
2024-06-29 13:35:48 +08:00
|
|
|
makeButtonDisappearToRight(oldButton, i, oldButtons.Length, true);
|
2024-05-16 11:24:58 +08:00
|
|
|
else
|
2024-06-29 13:35:48 +08:00
|
|
|
makeButtonDisappearToBottom(oldButton, i, oldButtons.Length, true);
|
2024-05-16 11:24:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < buttons.Count; i++)
|
|
|
|
{
|
|
|
|
var newButton = buttons[i];
|
|
|
|
|
|
|
|
if (newButton.Overlay != null)
|
|
|
|
{
|
|
|
|
newButton.Action = () => showOverlay(newButton.Overlay);
|
|
|
|
overlays.Add(newButton.Overlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug.Assert(!newButton.IsLoaded);
|
|
|
|
buttonsFlow.Add(newButton);
|
|
|
|
|
|
|
|
int index = i;
|
|
|
|
|
|
|
|
// ensure transforms are added after LoadComplete to not be aborted by the FinishTransforms call.
|
|
|
|
newButton.OnLoadComplete += _ =>
|
|
|
|
{
|
|
|
|
if (oldButtons.Length > 0)
|
2024-06-08 03:07:37 +08:00
|
|
|
makeButtonAppearFromLeft(newButton, index, buttons.Count, 240);
|
2024-05-16 11:24:58 +08:00
|
|
|
else
|
2024-06-08 03:07:37 +08:00
|
|
|
makeButtonAppearFromBottom(newButton, index);
|
2024-05-16 11:24:58 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-29 13:35:48 +08:00
|
|
|
private ShearedOverlayContainer? activeOverlay;
|
|
|
|
private Container? contentContainer;
|
|
|
|
private readonly List<ScreenFooterButton> temporarilyHiddenButtons = new List<ScreenFooterButton>();
|
|
|
|
|
2024-07-10 12:58:50 +08:00
|
|
|
public void SetActiveOverlayContainer(ShearedOverlayContainer overlay)
|
2024-06-29 13:35:48 +08:00
|
|
|
{
|
|
|
|
if (contentContainer != null)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException(@"Cannot set overlay content while one is already present. " +
|
|
|
|
$@"The previous overlay whose content is {contentContainer.Child.GetType().Name} should be hidden first.");
|
|
|
|
}
|
|
|
|
|
|
|
|
activeOverlay = overlay;
|
|
|
|
|
|
|
|
Debug.Assert(temporarilyHiddenButtons.Count == 0);
|
|
|
|
|
|
|
|
var targetButton = buttonsFlow.SingleOrDefault(b => b.Overlay == overlay);
|
|
|
|
|
|
|
|
temporarilyHiddenButtons.AddRange(targetButton != null
|
|
|
|
? buttonsFlow.SkipWhile(b => b != targetButton).Skip(1)
|
|
|
|
: buttonsFlow);
|
|
|
|
|
|
|
|
for (int i = 0; i < temporarilyHiddenButtons.Count; i++)
|
|
|
|
makeButtonDisappearToBottom(temporarilyHiddenButtons[i], 0, 0, false);
|
|
|
|
|
|
|
|
var fallbackPosition = buttonsFlow.Any()
|
|
|
|
? buttonsFlow.ToSpaceOfOtherDrawable(Vector2.Zero, this)
|
|
|
|
: BackButton.ToSpaceOfOtherDrawable(BackButton.LayoutRectangle.TopRight + new Vector2(5f, 0f), this);
|
|
|
|
|
|
|
|
var targetPosition = targetButton?.ToSpaceOfOtherDrawable(targetButton.LayoutRectangle.TopRight, this) ?? fallbackPosition;
|
|
|
|
|
2024-06-29 14:59:40 +08:00
|
|
|
updateColourScheme(overlay.ColourProvider.ColourScheme);
|
|
|
|
|
2024-07-10 16:12:52 +08:00
|
|
|
var content = overlay.CreateFooterContent() ?? Empty();
|
2024-06-29 13:35:48 +08:00
|
|
|
|
|
|
|
Add(contentContainer = new Container
|
|
|
|
{
|
|
|
|
Y = -15f,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding { Left = targetPosition.X },
|
|
|
|
Child = content,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (temporarilyHiddenButtons.Count > 0)
|
|
|
|
this.Delay(60).Schedule(() => content.Show());
|
|
|
|
else
|
|
|
|
content.Show();
|
|
|
|
}
|
|
|
|
|
2024-07-10 12:58:50 +08:00
|
|
|
public void ClearActiveOverlayContainer()
|
2024-06-29 13:35:48 +08:00
|
|
|
{
|
|
|
|
if (contentContainer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
contentContainer.Child.Hide();
|
|
|
|
|
|
|
|
double timeUntilRun = contentContainer.Child.LatestTransformEndTime - Time.Current;
|
|
|
|
|
|
|
|
Container expireTarget = contentContainer;
|
|
|
|
contentContainer = null;
|
|
|
|
activeOverlay = null;
|
|
|
|
|
|
|
|
for (int i = 0; i < temporarilyHiddenButtons.Count; i++)
|
|
|
|
makeButtonAppearFromBottom(temporarilyHiddenButtons[i], 0);
|
|
|
|
|
|
|
|
temporarilyHiddenButtons.Clear();
|
|
|
|
|
|
|
|
expireTarget.Delay(timeUntilRun).Expire();
|
2024-06-29 14:59:40 +08:00
|
|
|
|
|
|
|
updateColourScheme(OverlayColourScheme.Aquamarine);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateColourScheme(OverlayColourScheme colourScheme)
|
|
|
|
{
|
|
|
|
colourProvider.ChangeColourScheme(colourScheme);
|
|
|
|
|
|
|
|
background.FadeColour(colourProvider.Background5, 150, Easing.OutQuint);
|
|
|
|
|
|
|
|
foreach (var button in buttonsFlow)
|
|
|
|
button.UpdateDisplay();
|
2024-06-29 13:35:48 +08:00
|
|
|
}
|
|
|
|
|
2024-06-08 03:07:37 +08:00
|
|
|
private void makeButtonAppearFromLeft(ScreenFooterButton button, int index, int count, float startDelay)
|
|
|
|
=> button.AppearFromLeft(startDelay + (count - index) * delay_per_button);
|
2024-05-16 11:24:58 +08:00
|
|
|
|
2024-06-08 03:07:37 +08:00
|
|
|
private void makeButtonAppearFromBottom(ScreenFooterButton button, int index)
|
|
|
|
=> button.AppearFromBottom(index * delay_per_button);
|
2024-05-16 11:24:58 +08:00
|
|
|
|
2024-06-29 13:35:48 +08:00
|
|
|
private void makeButtonDisappearToRight(ScreenFooterButton button, int index, int count, bool expire)
|
|
|
|
=> button.DisappearToRight((count - index) * delay_per_button, expire);
|
2024-05-16 11:24:58 +08:00
|
|
|
|
2024-06-29 13:35:48 +08:00
|
|
|
private void makeButtonDisappearToBottom(ScreenFooterButton button, int index, int count, bool expire)
|
|
|
|
=> button.DisappearToBottom((count - index) * delay_per_button, expire);
|
2024-05-16 11:24:58 +08:00
|
|
|
|
|
|
|
private void showOverlay(OverlayContainer overlay)
|
|
|
|
{
|
2024-06-29 13:42:17 +08:00
|
|
|
foreach (var o in overlays.Where(o => o != overlay))
|
|
|
|
o.Hide();
|
|
|
|
|
|
|
|
overlay.ToggleVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onBackPressed()
|
|
|
|
{
|
|
|
|
if (activeOverlay != null)
|
2024-05-16 11:24:58 +08:00
|
|
|
{
|
2024-06-29 13:42:17 +08:00
|
|
|
if (activeOverlay.OnBackButton())
|
|
|
|
return;
|
|
|
|
|
|
|
|
activeOverlay.Hide();
|
|
|
|
return;
|
2024-05-16 11:24:58 +08:00
|
|
|
}
|
2024-06-29 13:42:17 +08:00
|
|
|
|
|
|
|
OnBack?.Invoke();
|
2024-05-16 11:24:58 +08:00
|
|
|
}
|
2024-05-16 11:59:58 +08:00
|
|
|
|
|
|
|
public partial class BackReceptor : Drawable, IKeyBindingHandler<GlobalAction>
|
|
|
|
{
|
|
|
|
public Action? OnBackPressed;
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
if (e.Repeat)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (e.Action)
|
|
|
|
{
|
|
|
|
case GlobalAction.Back:
|
|
|
|
OnBackPressed?.Invoke();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2022-12-01 18:57:50 +08:00
|
|
|
}
|
|
|
|
}
|