mirror of
https://github.com/ppy/osu
synced 2024-12-16 03:45:46 +00:00
Support using custom hue in user profile overlay
This commit is contained in:
parent
933626a64b
commit
b292bf3832
@ -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.Diagnostics.CodeAnalysis;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -22,7 +23,7 @@ namespace osu.Game.Overlays
|
||||
public virtual LocalisableString Title => Header.Title.Title;
|
||||
public virtual LocalisableString Description => Header.Title.Description;
|
||||
|
||||
public T Header { get; }
|
||||
public T Header { get; private set; }
|
||||
|
||||
protected virtual Color4 BackgroundColour => ColourProvider.Background5;
|
||||
|
||||
@ -34,11 +35,12 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
private readonly Box background;
|
||||
private readonly Container content;
|
||||
|
||||
protected FullscreenOverlay(OverlayColourScheme colourScheme)
|
||||
{
|
||||
Header = CreateHeader();
|
||||
RecreateHeader();
|
||||
|
||||
ColourProvider = new OverlayColourProvider(colourScheme);
|
||||
|
||||
@ -60,10 +62,9 @@ namespace osu.Game.Overlays
|
||||
|
||||
base.Content.AddRange(new Drawable[]
|
||||
{
|
||||
new Box
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = BackgroundColour
|
||||
},
|
||||
content = new Container
|
||||
{
|
||||
@ -75,14 +76,17 @@ namespace osu.Game.Overlays
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Waves.FirstWaveColour = ColourProvider.Light4;
|
||||
Waves.SecondWaveColour = ColourProvider.Light3;
|
||||
Waves.ThirdWaveColour = ColourProvider.Dark4;
|
||||
Waves.FourthWaveColour = ColourProvider.Dark3;
|
||||
UpdateColours();
|
||||
}
|
||||
|
||||
protected abstract T CreateHeader();
|
||||
|
||||
[MemberNotNull(nameof(Header))]
|
||||
protected void RecreateHeader()
|
||||
{
|
||||
Header = CreateHeader();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
if (State.Value == Visibility.Visible)
|
||||
@ -96,6 +100,15 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateColours()
|
||||
{
|
||||
Waves.FirstWaveColour = ColourProvider.Light4;
|
||||
Waves.SecondWaveColour = ColourProvider.Light3;
|
||||
Waves.ThirdWaveColour = ColourProvider.Dark4;
|
||||
Waves.FourthWaveColour = ColourProvider.Dark3;
|
||||
background.Colour = BackgroundColour;
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
base.PopIn();
|
||||
|
@ -99,11 +99,11 @@ namespace osu.Game.Overlays
|
||||
if (user.OnlineID == Header.User.Value?.User.Id && ruleset?.MatchesOnlineID(Header.User.Value?.Ruleset) == true)
|
||||
return;
|
||||
|
||||
if (sectionsContainer != null)
|
||||
sectionsContainer.ExpandableHeader = null;
|
||||
sectionsContainer?.ScrollToTop();
|
||||
sectionsContainer?.Clear();
|
||||
tabs?.Clear();
|
||||
|
||||
userReq?.Cancel();
|
||||
Clear();
|
||||
lastSection = null;
|
||||
|
||||
sections = !user.IsBot
|
||||
@ -119,20 +119,74 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
: Array.Empty<ProfileSection>();
|
||||
|
||||
tabs = new ProfileSectionTabControl
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
};
|
||||
setupBaseContent(OverlayColourScheme.Pink);
|
||||
|
||||
Add(new OsuContextMenuContainer
|
||||
if (API.State.Value != APIState.Offline)
|
||||
{
|
||||
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID, ruleset) : new GetUserRequest(user.Username, ruleset);
|
||||
userReq.Success += u => userLoadComplete(u, ruleset);
|
||||
|
||||
API.Queue(userReq);
|
||||
loadingLayer.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void userLoadComplete(APIUser loadedUser, IRulesetInfo? userRuleset)
|
||||
{
|
||||
Debug.Assert(sections != null && sectionsContainer != null && tabs != null);
|
||||
|
||||
// reuse header and content if same colour scheme, otherwise recreate both.
|
||||
var profileScheme = (OverlayColourScheme?)loadedUser.ProfileHue ?? OverlayColourScheme.Pink;
|
||||
if (profileScheme != ColourProvider.ColourScheme)
|
||||
setupBaseContent(profileScheme);
|
||||
|
||||
var actualRuleset = rulesets.GetRuleset(userRuleset?.ShortName ?? loadedUser.PlayMode).AsNonNull();
|
||||
|
||||
var userProfile = new UserProfileData(loadedUser, actualRuleset);
|
||||
Header.User.Value = userProfile;
|
||||
|
||||
if (loadedUser.ProfileOrder != null)
|
||||
{
|
||||
foreach (string id in loadedUser.ProfileOrder)
|
||||
{
|
||||
var sec = sections.FirstOrDefault(s => s.Identifier == id);
|
||||
|
||||
if (sec != null)
|
||||
{
|
||||
sec.User.Value = userProfile;
|
||||
|
||||
sectionsContainer.Add(sec);
|
||||
tabs.AddItem(sec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadingLayer.Hide();
|
||||
}
|
||||
|
||||
private void setupBaseContent(OverlayColourScheme colourScheme)
|
||||
{
|
||||
var previousColourScheme = ColourProvider.ColourScheme;
|
||||
ColourProvider.ChangeColourScheme(colourScheme);
|
||||
|
||||
if (sectionsContainer != null && colourScheme == previousColourScheme)
|
||||
return;
|
||||
|
||||
RecreateHeader();
|
||||
UpdateColours();
|
||||
|
||||
Child = new OsuContextMenuContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = sectionsContainer = new ProfileSectionsContainer
|
||||
{
|
||||
ExpandableHeader = Header,
|
||||
FixedHeader = tabs,
|
||||
FixedHeader = tabs = new ProfileSectionTabControl
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
},
|
||||
HeaderBackground = new Box
|
||||
{
|
||||
// this is only visible as the ProfileTabControl background
|
||||
@ -140,7 +194,7 @@ namespace osu.Game.Overlays
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
sectionsContainer.SelectedSection.ValueChanged += section =>
|
||||
{
|
||||
@ -167,45 +221,6 @@ namespace osu.Game.Overlays
|
||||
sectionsContainer.ScrollTo(lastSection);
|
||||
}
|
||||
};
|
||||
|
||||
sectionsContainer.ScrollToTop();
|
||||
|
||||
if (API.State.Value != APIState.Offline)
|
||||
{
|
||||
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID, ruleset) : new GetUserRequest(user.Username, ruleset);
|
||||
userReq.Success += u => userLoadComplete(u, ruleset);
|
||||
|
||||
API.Queue(userReq);
|
||||
loadingLayer.Show();
|
||||
}
|
||||
}
|
||||
|
||||
private void userLoadComplete(APIUser loadedUser, IRulesetInfo? userRuleset)
|
||||
{
|
||||
Debug.Assert(sections != null && sectionsContainer != null && tabs != null);
|
||||
|
||||
var actualRuleset = rulesets.GetRuleset(userRuleset?.ShortName ?? loadedUser.PlayMode).AsNonNull();
|
||||
|
||||
var userProfile = new UserProfileData(loadedUser, actualRuleset);
|
||||
Header.User.Value = userProfile;
|
||||
|
||||
if (loadedUser.ProfileOrder != null)
|
||||
{
|
||||
foreach (string id in loadedUser.ProfileOrder)
|
||||
{
|
||||
var sec = sections.FirstOrDefault(s => s.Identifier == id);
|
||||
|
||||
if (sec != null)
|
||||
{
|
||||
sec.User.Value = userProfile;
|
||||
|
||||
sectionsContainer.Add(sec);
|
||||
tabs.AddItem(sec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadingLayer.Hide();
|
||||
}
|
||||
|
||||
private partial class ProfileSectionTabControl : OsuTabControl<ProfileSection>
|
||||
|
Loading…
Reference in New Issue
Block a user