Add back receptor, logo tracking, and own colour provider to screen footer

This commit is contained in:
Salman Ahmed
2024-05-16 06:59:58 +03:00
parent 95840672cb
commit 921be3ca01
3 changed files with 126 additions and 33 deletions

View File

@@ -7,19 +7,18 @@ using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Screens.Footer;
namespace osu.Game.Graphics.UserInterface
{
// todo: remove this once all screens migrate to display the new game footer and back button.
public partial class BackButton : VisibilityContainer
{
public Action Action;
private readonly TwoLayerButton button;
public BackButton(Receptor receptor = null)
public BackButton(ScreenFooter.BackReceptor receptor = null)
{
Size = TwoLayerButton.SIZE_EXTENDED;
@@ -35,7 +34,7 @@ namespace osu.Game.Graphics.UserInterface
if (receptor == null)
{
// if a receptor wasn't provided, create our own locally.
Add(receptor = new Receptor());
Add(receptor = new ScreenFooter.BackReceptor());
}
receptor.OnBackPressed = () => button.TriggerClick();
@@ -59,29 +58,5 @@ namespace osu.Game.Graphics.UserInterface
button.MoveToX(-TwoLayerButton.SIZE_EXTENDED.X / 2, 400, Easing.OutQuint);
button.FadeOut(400, Easing.OutQuint);
}
public partial class Receptor : 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)
{
}
}
}
}

View File

@@ -0,0 +1,64 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Footer
{
public partial class BackButtonV2 : ShearedButton
{
// todo: see https://github.com/ppy/osu-framework/issues/3271
private const float torus_scale_factor = 1.2f;
public const float BUTTON_WIDTH = 240;
public BackButtonV2()
: base(BUTTON_WIDTH, 70)
{
}
[BackgroundDependencyLoader]
private void load()
{
ButtonContent.Child = new FillFlowContainer
{
X = -10f,
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(20f, 0f),
Children = new Drawable[]
{
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(20f),
Icon = FontAwesome.Solid.ChevronLeft,
},
new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.TorusAlternate.With(size: 20 * torus_scale_factor),
Text = CommonStrings.Back,
UseFullGlyphHeight = false,
}
}
};
DarkerColour = Color4Extensions.FromHex("#DE31AE");
LighterColour = Color4Extensions.FromHex("#FF86DD");
TextColour = Color4.White;
}
}
}

View File

@@ -1,6 +1,7 @@
// 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;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -8,7 +9,12 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Screens.Menu;
using osuTK;
namespace osu.Game.Screens.Footer
@@ -22,19 +28,31 @@ namespace osu.Game.Screens.Footer
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
private BackButtonV2 backButton = null!;
private FillFlowContainer<ScreenFooterButton> buttonsFlow = null!;
private Container<ScreenFooterButton> removedButtonsContainer = null!;
private LogoTrackingContainer logoTrackingContainer = null!;
public ScreenFooter()
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
public Action? OnBack;
public ScreenFooter(BackReceptor? receptor = null)
{
RelativeSizeAxes = Axes.X;
Height = HEIGHT;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
if (receptor == null)
Add(receptor = new BackReceptor());
receptor.OnBackPressed = () => backButton.TriggerClick();
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
private void load()
{
InternalChildren = new Drawable[]
{
@@ -53,12 +71,12 @@ namespace osu.Game.Screens.Footer
Spacing = new Vector2(7, 0),
AutoSizeAxes = Axes.Both
},
new ScreenBackButton
backButton = new BackButtonV2
{
Margin = new MarginPadding { Bottom = 10f, Left = 12f },
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = () => { },
Action = () => OnBack?.Invoke(),
},
removedButtonsContainer = new Container<ScreenFooterButton>
{
@@ -68,9 +86,21 @@ namespace osu.Game.Screens.Footer
Origin = Anchor.BottomLeft,
AutoSizeAxes = Axes.Both,
},
(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);
})),
};
}
public void StartTrackingLogo(OsuLogo logo, float duration = 0, Easing easing = Easing.None) => logoTrackingContainer.StartTracking(logo, duration, easing);
public void StopTrackingLogo() => logoTrackingContainer.StopTracking();
protected override void PopIn()
{
this.MoveToY(0, 400, Easing.OutQuint)
@@ -180,5 +210,29 @@ namespace osu.Game.Screens.Footer
o.Hide();
}
}
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)
{
}
}
}
}