1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 02:53:21 +08:00

Combine new implementation back into the old one and use everywhere

This commit is contained in:
Dean Herbert 2024-11-27 17:47:42 +09:00
parent 7fdf13911b
commit 0f73941808
No known key found for this signature in database
3 changed files with 74 additions and 84 deletions

View File

@ -1,68 +0,0 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
public partial class ExpandingPlayerSettingsOverlay : ExpandingContainer
{
private const float padding = 10;
public const float CONTRACTED_WIDTH = button_size + padding * 2;
public const float EXPANDED_WIDTH = player_settings_width + button_size + padding * 3;
private const float player_settings_width = 270;
private const float button_size = IconButton.DEFAULT_BUTTON_SIZE;
public ExpandingPlayerSettingsOverlay()
: base(CONTRACTED_WIDTH, EXPANDED_WIDTH)
{
Origin = Anchor.TopRight;
Anchor = Anchor.TopRight;
PlayerSettingsOverlay playerSettingsOverlay;
InternalChild = new FillFlowContainer
{
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding(padding),
Spacing = new Vector2(padding),
Children = new Drawable[]
{
new IconButton
{
Icon = FontAwesome.Solid.Cog,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Action = () => Expanded.Toggle()
},
playerSettingsOverlay = new PlayerSettingsOverlay
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft
}
}
};
playerSettingsOverlay.Show();
}
protected override void OnHoverLost(HoverLostEvent e)
{
// Prevent unexpanding when hovering player settings
if (!Contains(e.ScreenSpaceMousePosition))
base.OnHoverLost(e);
}
}
}

View File

@ -127,7 +127,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
ReadyToStart = performInitialSeek,
},
new ExpandingPlayerSettingsOverlay()
new PlayerSettingsOverlay()
};
for (int i = 0; i < Users.Count; i++)

View File

@ -1,46 +1,104 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osuTK;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Play.PlayerSettings;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD
{
public partial class PlayerSettingsOverlay : VisibilityContainer
public partial class PlayerSettingsOverlay : ExpandingContainer
{
public VisualSettings VisualSettings { get; private set; }
private const float padding = 10;
public const float CONTRACTED_WIDTH = button_size + padding * 2;
public const float EXPANDED_WIDTH = player_settings_width + padding * 2;
private const float player_settings_width = 270;
private const float button_size = IconButton.DEFAULT_BUTTON_SIZE;
public override void Show() => this.FadeIn(fade_duration);
public override void Hide() => this.FadeOut(fade_duration);
private const int fade_duration = 200;
public readonly VisualSettings VisualSettings;
// we'll handle this ourselves because we have slightly custom logic.
protected override bool ExpandOnHover => false;
protected override Container<Drawable> Content => content;
private readonly FillFlowContainer content;
public PlayerSettingsOverlay()
{
Anchor = Anchor.TopRight;
Origin = Anchor.TopRight;
AutoSizeAxes = Axes.Both;
private readonly IconButton button;
InternalChild = content = new FillFlowContainer
private InputManager inputManager = null!;
public PlayerSettingsOverlay()
: base(0, EXPANDED_WIDTH)
{
Origin = Anchor.TopRight;
Anchor = Anchor.TopRight;
base.Content.Add(content = new FillFlowContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Margin = new MarginPadding(padding),
Children = new PlayerSettingsGroup[]
{
VisualSettings = new VisualSettings { Expanded = { Value = false } },
new AudioSettings { Expanded = { Value = false } }
}
};
});
AddInternal(button = new IconButton
{
Icon = FontAwesome.Solid.Cog,
Origin = Anchor.TopRight,
Anchor = Anchor.TopLeft,
Margin = new MarginPadding(5),
Action = () => Expanded.Toggle()
});
AddInternal(new Box
{
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0), Color4.Black.Opacity(0.8f)),
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
});
}
protected override void PopIn() => this.FadeIn(fade_duration);
protected override void PopOut() => this.FadeOut(fade_duration);
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager()!;
}
protected override void Update()
{
base.Update();
Expanded.Value = inputManager.CurrentState.Mouse.Position.X >= button.ScreenSpaceDrawQuad.TopLeft.X;
}
protected override void OnHoverLost(HoverLostEvent e)
{
// handle un-expanding manually because our children do weird hover blocking stuff.
}
public void AddAtStart(PlayerSettingsGroup drawable) => content.Insert(-1, drawable);
}