mirror of
https://github.com/ppy/osu.git
synced 2026-05-19 05:09:54 +08:00
1230da33a5
- Adds sorting and display styles. - Saves sort/display modes to the config. - Improves performance, especially on the 2nd+ time opening the overlay. https://github.com/user-attachments/assets/e32b50d0-58a1-4eef-b18c-988fb497e545 --- Coming off some recent feedback in https://github.com/ppy/osu/discussions/33426#discussioncomment-13431275, I decided to take a bit of a detour and get a little bit more functionality in. Sorting by rank, although it should technically work, doesn't work right now. This is because the osu!web API doesn't return user rank on `/user/` lookups - it's only returned for the friends request. I'm leaving this open as a discussion topic. - We can make osu!web return the rank and osu! will require no further changes to work correctly, or - We can try to implement additional paths through `osu-server-spectator` which would blow this PR out of proportion and is best left for a task of its own. For simplicity, I've re-implemented this display mostly as its own component for now, lifting code from `FriendDisplay` which was recently overhauled. These implementations should eventually be combined somehow but that's dependent on: 1. Figuring out the styling - friends can display offline users for which it makes no sense to display the "spectate" button. 2. Figuring out how to handle the different users/presence pathways. It's mostly a code complexity issue. --------- Co-authored-by: Dean Herbert <pe@ppy.sh> Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
133 lines
4.2 KiB
C#
133 lines
4.2 KiB
C#
// 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.
|
|
|
|
#nullable disable
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Graphics.UserInterface;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osuTK;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Audio;
|
|
using osu.Framework.Audio.Sample;
|
|
using osuTK.Graphics;
|
|
using osu.Framework.Graphics.Cursor;
|
|
using osu.Framework.Localisation;
|
|
using osu.Game.Resources.Localisation.Web;
|
|
using osu.Framework.Extensions;
|
|
|
|
namespace osu.Game.Overlays
|
|
{
|
|
public partial class OverlayPanelDisplayStyleControl : OsuTabControl<OverlayPanelDisplayStyle>
|
|
{
|
|
protected override Dropdown<OverlayPanelDisplayStyle> CreateDropdown() => null;
|
|
|
|
protected override TabItem<OverlayPanelDisplayStyle> CreateTabItem(OverlayPanelDisplayStyle value) => new PanelDisplayTabItem(value);
|
|
|
|
protected override bool AddEnumEntriesAutomatically => false;
|
|
|
|
public OverlayPanelDisplayStyleControl(bool supportsBrickMode)
|
|
{
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
AddTabItem(new PanelDisplayTabItem(OverlayPanelDisplayStyle.Card)
|
|
{
|
|
Icon = FontAwesome.Solid.Square
|
|
});
|
|
AddTabItem(new PanelDisplayTabItem(OverlayPanelDisplayStyle.List)
|
|
{
|
|
Icon = FontAwesome.Solid.Bars
|
|
});
|
|
|
|
if (supportsBrickMode)
|
|
{
|
|
AddTabItem(new PanelDisplayTabItem(OverlayPanelDisplayStyle.Brick)
|
|
{
|
|
Icon = FontAwesome.Solid.Th
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Both,
|
|
Direction = FillDirection.Horizontal
|
|
};
|
|
|
|
private partial class PanelDisplayTabItem : TabItem<OverlayPanelDisplayStyle>, IHasTooltip
|
|
{
|
|
public IconUsage Icon
|
|
{
|
|
set => icon.Icon = value;
|
|
}
|
|
|
|
[Resolved]
|
|
private OverlayColourProvider colourProvider { get; set; }
|
|
|
|
public LocalisableString TooltipText => Value.GetLocalisableDescription();
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
private Sample selectSample = null!;
|
|
|
|
public PanelDisplayTabItem(OverlayPanelDisplayStyle value)
|
|
: base(value)
|
|
{
|
|
Size = new Vector2(11);
|
|
AddRange(new Drawable[]
|
|
{
|
|
icon = new SpriteIcon
|
|
{
|
|
Anchor = Anchor.Centre,
|
|
Origin = Anchor.Centre,
|
|
RelativeSizeAxes = Axes.Both,
|
|
FillMode = FillMode.Fit
|
|
},
|
|
new HoverSounds(HoverSampleSet.TabSelect)
|
|
});
|
|
}
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(AudioManager audio)
|
|
{
|
|
selectSample = audio.Samples.Get(@"UI/tabselect-select");
|
|
}
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
protected override void OnDeactivated() => updateState();
|
|
|
|
protected override void OnActivatedByUser() => selectSample.Play();
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
{
|
|
updateState();
|
|
return base.OnHover(e);
|
|
}
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
{
|
|
updateState();
|
|
base.OnHoverLost(e);
|
|
}
|
|
|
|
private void updateState() => icon.Colour = Active.Value || IsHovered ? colourProvider.Light1 : Color4.White;
|
|
}
|
|
}
|
|
|
|
public enum OverlayPanelDisplayStyle
|
|
{
|
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ViewModeCard))]
|
|
Card,
|
|
|
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ViewModeList))]
|
|
List,
|
|
|
|
[LocalisableDescription(typeof(UsersStrings), nameof(UsersStrings.ViewModeBrick))]
|
|
Brick
|
|
}
|
|
}
|