mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +08:00
Merge branch 'master' into argon-hide-counter-labels
This commit is contained in:
commit
b45872d2e0
@ -13,6 +13,7 @@ using osu.Game.Database;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Tests.Resources;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
namespace osu.Game.Tests.Skins.IO
|
||||
@ -21,6 +22,25 @@ namespace osu.Game.Tests.Skins.IO
|
||||
{
|
||||
#region Testing filename metadata inclusion
|
||||
|
||||
[TestCase("Archives/modified-classic-20220723.osk")]
|
||||
[TestCase("Archives/modified-default-20230117.osk")]
|
||||
[TestCase("Archives/modified-argon-20231106.osk")]
|
||||
public Task TestImportModifiedSkinHasResources(string archive) => runSkinTest(async osu =>
|
||||
{
|
||||
using (var stream = TestResources.OpenResource(archive))
|
||||
{
|
||||
var imported = await loadSkinIntoOsu(osu, new ImportTask(stream, "skin.osk"));
|
||||
|
||||
// When the import filename doesn't match, it should be appended (and update the skin.ini).
|
||||
|
||||
var skinManager = osu.Dependencies.Get<SkinManager>();
|
||||
|
||||
skinManager.CurrentSkinInfo.Value = imported;
|
||||
|
||||
Assert.That(skinManager.CurrentSkin.Value.LayoutInfos.Count, Is.EqualTo(2));
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TestSingleImportDifferentFilename() => runSkinTest(async osu =>
|
||||
{
|
||||
|
@ -15,6 +15,7 @@ using osu.Game.IO.Archives;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Screens.Play.HUD.HitErrorMeters;
|
||||
using osu.Game.Skinning;
|
||||
using osu.Game.Skinning.Components;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Skins
|
||||
@ -102,6 +103,20 @@ namespace osu.Game.Tests.Skins
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserialiseModifiedArgon()
|
||||
{
|
||||
using (var stream = TestResources.OpenResource("Archives/modified-argon-20231106.osk"))
|
||||
using (var storage = new ZipArchiveReader(stream))
|
||||
{
|
||||
var skin = new TestSkin(new SkinInfo(), null, storage);
|
||||
|
||||
Assert.That(skin.LayoutInfos, Has.Count.EqualTo(2));
|
||||
Assert.That(skin.LayoutInfos[SkinComponentsContainerLookup.TargetArea.MainHUDComponents].AllDrawables.ToArray(), Has.Length.EqualTo(10));
|
||||
Assert.That(skin.LayoutInfos[SkinComponentsContainerLookup.TargetArea.MainHUDComponents].AllDrawables.Select(i => i.Type), Contains.Item(typeof(PlayerName)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDeserialiseModifiedClassic()
|
||||
{
|
||||
|
@ -52,6 +52,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
if (healthDisplay.IsNotNull())
|
||||
healthDisplay.BarHeight.Value = val;
|
||||
});
|
||||
|
||||
AddSliderStep("Width", 0, 1f, 0.98f, val =>
|
||||
{
|
||||
if (healthDisplay.IsNotNull())
|
||||
healthDisplay.Width = val;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
86
osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs
Normal file
86
osu.Game.Tests/Visual/Online/TestSceneUserClickableAvatar.cs
Normal file
@ -0,0 +1,86 @@
|
||||
// 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.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Users;
|
||||
using osu.Game.Users.Drawables;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
public partial class TestSceneUserClickableAvatar : OsuManualInputManagerTestScene
|
||||
{
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
Child = new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Spacing = new Vector2(10f),
|
||||
Children = new[]
|
||||
{
|
||||
generateUser(@"peppy", 2, CountryCode.AU, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", false, "99EB47"),
|
||||
generateUser(@"flyte", 3103765, CountryCode.JP, @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg", true),
|
||||
generateUser(@"joshika39", 17032217, CountryCode.RS, @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", false),
|
||||
new UpdateableAvatar(),
|
||||
new UpdateableAvatar()
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestClickableAvatarHover()
|
||||
{
|
||||
AddStep("hover avatar with user panel", () => InputManager.MoveMouseTo(this.ChildrenOfType<ClickableAvatar>().ElementAt(1)));
|
||||
AddUntilStep("wait for tooltip to show", () => this.ChildrenOfType<ClickableAvatar.UserCardTooltip>().FirstOrDefault()?.State.Value == Visibility.Visible);
|
||||
AddStep("hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
|
||||
AddUntilStep("wait for tooltip to hide", () => this.ChildrenOfType<ClickableAvatar.UserCardTooltip>().FirstOrDefault()?.State.Value == Visibility.Hidden);
|
||||
|
||||
AddStep("hover avatar without user panel", () => InputManager.MoveMouseTo(this.ChildrenOfType<ClickableAvatar>().ElementAt(0)));
|
||||
AddUntilStep("wait for tooltip to show", () => this.ChildrenOfType<OsuTooltipContainer.OsuTooltip>().FirstOrDefault()?.State.Value == Visibility.Visible);
|
||||
AddStep("hover out", () => InputManager.MoveMouseTo(new Vector2(0)));
|
||||
AddUntilStep("wait for tooltip to hide", () => this.ChildrenOfType<OsuTooltipContainer.OsuTooltip>().FirstOrDefault()?.State.Value == Visibility.Hidden);
|
||||
}
|
||||
|
||||
private Drawable generateUser(string username, int id, CountryCode countryCode, string cover, bool showPanel, string? color = null)
|
||||
{
|
||||
var user = new APIUser
|
||||
{
|
||||
Username = username,
|
||||
Id = id,
|
||||
CountryCode = countryCode,
|
||||
CoverUrl = cover,
|
||||
Colour = color ?? "000000",
|
||||
Status =
|
||||
{
|
||||
Value = new UserStatusOnline()
|
||||
},
|
||||
};
|
||||
|
||||
return new ClickableAvatar(user, showPanel)
|
||||
{
|
||||
Width = 50,
|
||||
Height = 50,
|
||||
CornerRadius = 10,
|
||||
Masking = true,
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 1,
|
||||
Colour = Color4.Black.Opacity(0.2f),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -74,7 +74,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Statistics
|
||||
|
||||
#region Tooltip implementation
|
||||
|
||||
public virtual ITooltip GetCustomTooltip() => null;
|
||||
public virtual ITooltip GetCustomTooltip() => null!;
|
||||
public virtual object TooltipContent => null;
|
||||
|
||||
#endregion
|
||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
AutoSizeAxes = Axes.Both,
|
||||
CornerRadius = 4,
|
||||
Masking = true,
|
||||
Child = avatar = new UpdateableAvatar(showGuestOnNull: false)
|
||||
Child = avatar = new UpdateableAvatar(showUserPanelOnHover: true, showGuestOnNull: false)
|
||||
{
|
||||
Size = new Vector2(height),
|
||||
},
|
||||
|
@ -102,7 +102,7 @@ namespace osu.Game.Overlays.Comments
|
||||
Padding = new MarginPadding { Horizontal = WaveOverlayContainer.HORIZONTAL_PADDING, Vertical = 20 },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
avatar = new UpdateableAvatar(api.LocalUser.Value)
|
||||
avatar = new UpdateableAvatar(api.LocalUser.Value, isInteractive: false)
|
||||
{
|
||||
Size = new Vector2(50),
|
||||
CornerExponent = 2,
|
||||
|
@ -144,7 +144,7 @@ namespace osu.Game.Overlays.Comments
|
||||
Size = new Vector2(avatar_size),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new UpdateableAvatar(Comment.User)
|
||||
new UpdateableAvatar(Comment.User, showUserPanelOnHover: true)
|
||||
{
|
||||
Size = new Vector2(avatar_size),
|
||||
Masking = true,
|
||||
|
@ -115,7 +115,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4Extensions.FromHex(@"27252d"),
|
||||
},
|
||||
avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both },
|
||||
avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
set => avatar.User = value;
|
||||
}
|
||||
|
||||
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both };
|
||||
private readonly UpdateableAvatar avatar = new UpdateableAvatar(showUserPanelOnHover: true) { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colours)
|
||||
|
@ -89,11 +89,23 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
public const float MAIN_PATH_RADIUS = 10f;
|
||||
|
||||
private const float curve_start_offset = 70;
|
||||
private const float curve_end_offset = 40;
|
||||
private const float padding = MAIN_PATH_RADIUS * 2;
|
||||
private const float curve_smoothness = 10;
|
||||
|
||||
private readonly LayoutValue drawSizeLayout = new LayoutValue(Invalidation.DrawSize);
|
||||
|
||||
public ArgonHealthDisplay()
|
||||
{
|
||||
AddLayout(drawSizeLayout);
|
||||
|
||||
// sane default width specification.
|
||||
// this only matters if the health display isn't part of the default skin
|
||||
// (in which case width will be set to 300 via `ArgonSkin.GetDrawableComponent()`),
|
||||
// and if the user hasn't applied their own modifications
|
||||
// (which are applied via `SerialisedDrawableInfo.ApplySerialisedInfo()`).
|
||||
Width = 0.98f;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -241,11 +253,17 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private void updatePath()
|
||||
{
|
||||
float barLength = DrawWidth - MAIN_PATH_RADIUS * 2;
|
||||
float curveStart = barLength - 70;
|
||||
float curveEnd = barLength - 40;
|
||||
float usableWidth = DrawWidth - padding;
|
||||
|
||||
const float curve_smoothness = 10;
|
||||
if (usableWidth < 0) enforceMinimumWidth();
|
||||
|
||||
// the display starts curving at `curve_start_offset` units from the right and ends curving at `curve_end_offset`.
|
||||
// to ensure that the curve is symmetric when it starts being narrow enough, add a `curve_end_offset` to the left side too.
|
||||
const float rescale_cutoff = curve_start_offset + curve_end_offset;
|
||||
|
||||
float barLength = Math.Max(DrawWidth - padding, rescale_cutoff);
|
||||
float curveStart = barLength - curve_start_offset;
|
||||
float curveEnd = barLength - curve_end_offset;
|
||||
|
||||
Vector2 diagonalDir = (new Vector2(curveEnd, BarHeight.Value) - new Vector2(curveStart, 0)).Normalized();
|
||||
|
||||
@ -261,6 +279,9 @@ namespace osu.Game.Screens.Play.HUD
|
||||
new PathControlPoint(new Vector2(barLength, BarHeight.Value)),
|
||||
});
|
||||
|
||||
if (DrawWidth - padding < rescale_cutoff)
|
||||
rescalePathProportionally();
|
||||
|
||||
List<Vector2> vertices = new List<Vector2>();
|
||||
barPath.GetPathToProgress(vertices, 0.0, 1.0);
|
||||
|
||||
@ -269,6 +290,24 @@ namespace osu.Game.Screens.Play.HUD
|
||||
glowBar.Vertices = vertices;
|
||||
|
||||
updatePathVertices();
|
||||
|
||||
void enforceMinimumWidth()
|
||||
{
|
||||
// Switch to absolute in order to be able to define a minimum width.
|
||||
// Then switch back is required. Framework will handle the conversion for us.
|
||||
Axes relativeAxes = RelativeSizeAxes;
|
||||
RelativeSizeAxes = Axes.None;
|
||||
|
||||
Width = padding;
|
||||
|
||||
RelativeSizeAxes = relativeAxes;
|
||||
}
|
||||
|
||||
void rescalePathProportionally()
|
||||
{
|
||||
foreach (var point in barPath.ControlPoints)
|
||||
point.Position = new Vector2(point.Position.X / barLength * (DrawWidth - padding), point.Position.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePathVertices()
|
||||
|
@ -1,38 +1,31 @@
|
||||
// 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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Users.Drawables
|
||||
{
|
||||
public partial class ClickableAvatar : OsuClickableContainer
|
||||
public partial class ClickableAvatar : OsuClickableContainer, IHasCustomTooltip<APIUser?>
|
||||
{
|
||||
public override LocalisableString TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Enabled.Value)
|
||||
return string.Empty;
|
||||
public ITooltip<APIUser?> GetCustomTooltip() => showCardOnHover ? new UserCardTooltip() : new NoCardTooltip();
|
||||
|
||||
return ShowUsernameTooltip ? (user?.Username ?? string.Empty) : ContextMenuStrings.ViewProfile;
|
||||
}
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// By default, the tooltip will show "view profile" as avatars are usually displayed next to a username.
|
||||
/// Setting this to <c>true</c> exposes the username via tooltip for special cases where this is not true.
|
||||
/// </summary>
|
||||
public bool ShowUsernameTooltip { get; set; }
|
||||
public APIUser? TooltipContent { get; }
|
||||
|
||||
private readonly APIUser? user;
|
||||
|
||||
private readonly bool showCardOnHover;
|
||||
|
||||
[Resolved]
|
||||
private OsuGame? game { get; set; }
|
||||
|
||||
@ -40,12 +33,15 @@ namespace osu.Game.Users.Drawables
|
||||
/// A clickable avatar for the specified user, with UI sounds included.
|
||||
/// </summary>
|
||||
/// <param name="user">The user. A null value will get a placeholder avatar.</param>
|
||||
public ClickableAvatar(APIUser? user = null)
|
||||
/// <param name="showCardOnHover">If set to true, the <see cref="UserGridPanel"/> will be shown for the tooltip</param>
|
||||
public ClickableAvatar(APIUser? user = null, bool showCardOnHover = false)
|
||||
{
|
||||
this.user = user;
|
||||
|
||||
if (user?.Id != APIUser.SYSTEM_USER_ID)
|
||||
Action = openProfile;
|
||||
|
||||
this.showCardOnHover = showCardOnHover;
|
||||
|
||||
TooltipContent = this.user = user ?? new GuestUser();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -67,5 +63,65 @@ namespace osu.Game.Users.Drawables
|
||||
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
public partial class UserCardTooltip : VisibilityContainer, ITooltip<APIUser?>
|
||||
{
|
||||
public UserCardTooltip()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
protected override void PopIn() => this.FadeIn(150, Easing.OutQuint);
|
||||
protected override void PopOut() => this.Delay(150).FadeOut(500, Easing.OutQuint);
|
||||
|
||||
public void Move(Vector2 pos) => Position = pos;
|
||||
|
||||
private APIUser? user;
|
||||
|
||||
public void SetContent(APIUser? content)
|
||||
{
|
||||
if (content == user && Children.Any())
|
||||
return;
|
||||
|
||||
user = content;
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
LoadComponentAsync(new UserGridPanel(user)
|
||||
{
|
||||
Width = 300,
|
||||
}, panel => Child = panel);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tooltip = new OsuTooltipContainer.OsuTooltip();
|
||||
tooltip.SetContent(ContextMenuStrings.ViewProfile);
|
||||
tooltip.Show();
|
||||
|
||||
Child = tooltip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class NoCardTooltip : VisibilityContainer, ITooltip<APIUser?>
|
||||
{
|
||||
private readonly OsuTooltipContainer.OsuTooltip tooltip;
|
||||
|
||||
public NoCardTooltip()
|
||||
{
|
||||
tooltip = new OsuTooltipContainer.OsuTooltip();
|
||||
tooltip.SetContent(ContextMenuStrings.ViewProfile);
|
||||
Child = tooltip;
|
||||
}
|
||||
|
||||
protected override void PopIn() => tooltip.Show();
|
||||
protected override void PopOut() => tooltip.Hide();
|
||||
|
||||
public void Move(Vector2 pos) => Position = pos;
|
||||
|
||||
public void SetContent(APIUser? content)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,21 +46,24 @@ namespace osu.Game.Users.Drawables
|
||||
protected override double LoadDelay => 200;
|
||||
|
||||
private readonly bool isInteractive;
|
||||
private readonly bool showUsernameTooltip;
|
||||
private readonly bool showGuestOnNull;
|
||||
private readonly bool showUserPanelOnHover;
|
||||
|
||||
/// <summary>
|
||||
/// Construct a new UpdateableAvatar.
|
||||
/// </summary>
|
||||
/// <param name="user">The initial user to display.</param>
|
||||
/// <param name="isInteractive">If set to true, hover/click sounds will play and clicking the avatar will open the user's profile.</param>
|
||||
/// <param name="showUsernameTooltip">Whether to show the username rather than "view profile" on the tooltip. (note: this only applies if <paramref name="isInteractive"/> is also true)</param>
|
||||
/// <param name="showUserPanelOnHover">
|
||||
/// If set to true, the user status panel will be displayed in the tooltip.
|
||||
/// Only has an effect if <see cref="isInteractive"/> is true.
|
||||
/// </param>
|
||||
/// <param name="showGuestOnNull">Whether to show a default guest representation on null user (as opposed to nothing).</param>
|
||||
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUsernameTooltip = false, bool showGuestOnNull = true)
|
||||
public UpdateableAvatar(APIUser? user = null, bool isInteractive = true, bool showUserPanelOnHover = false, bool showGuestOnNull = true)
|
||||
{
|
||||
this.isInteractive = isInteractive;
|
||||
this.showUsernameTooltip = showUsernameTooltip;
|
||||
this.showGuestOnNull = showGuestOnNull;
|
||||
this.showUserPanelOnHover = showUserPanelOnHover;
|
||||
|
||||
User = user;
|
||||
}
|
||||
@ -72,19 +75,16 @@ namespace osu.Game.Users.Drawables
|
||||
|
||||
if (isInteractive)
|
||||
{
|
||||
return new ClickableAvatar(user)
|
||||
return new ClickableAvatar(user, showUserPanelOnHover)
|
||||
{
|
||||
ShowUsernameTooltip = showUsernameTooltip,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
}
|
||||
else
|
||||
|
||||
return new DrawableAvatar(user)
|
||||
{
|
||||
return new DrawableAvatar(user)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
}
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Users
|
||||
{
|
||||
/// <summary>
|
||||
/// A user "card", commonly used in a grid layout or in popovers.
|
||||
/// Comes with a preset height, but width must be specified.
|
||||
/// </summary>
|
||||
public partial class UserGridPanel : ExtendedUserPanel
|
||||
{
|
||||
private const int margin = 10;
|
||||
|
Loading…
Reference in New Issue
Block a user