mirror of
https://github.com/ppy/osu
synced 2024-12-16 20:05:41 +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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -22,7 +23,7 @@ namespace osu.Game.Overlays
|
|||||||
public virtual LocalisableString Title => Header.Title.Title;
|
public virtual LocalisableString Title => Header.Title.Title;
|
||||||
public virtual LocalisableString Description => Header.Title.Description;
|
public virtual LocalisableString Description => Header.Title.Description;
|
||||||
|
|
||||||
public T Header { get; }
|
public T Header { get; private set; }
|
||||||
|
|
||||||
protected virtual Color4 BackgroundColour => ColourProvider.Background5;
|
protected virtual Color4 BackgroundColour => ColourProvider.Background5;
|
||||||
|
|
||||||
@ -34,11 +35,12 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
|
|
||||||
|
private readonly Box background;
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
|
|
||||||
protected FullscreenOverlay(OverlayColourScheme colourScheme)
|
protected FullscreenOverlay(OverlayColourScheme colourScheme)
|
||||||
{
|
{
|
||||||
Header = CreateHeader();
|
RecreateHeader();
|
||||||
|
|
||||||
ColourProvider = new OverlayColourProvider(colourScheme);
|
ColourProvider = new OverlayColourProvider(colourScheme);
|
||||||
|
|
||||||
@ -60,10 +62,9 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
base.Content.AddRange(new Drawable[]
|
base.Content.AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = BackgroundColour
|
|
||||||
},
|
},
|
||||||
content = new Container
|
content = new Container
|
||||||
{
|
{
|
||||||
@ -75,14 +76,17 @@ namespace osu.Game.Overlays
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Waves.FirstWaveColour = ColourProvider.Light4;
|
UpdateColours();
|
||||||
Waves.SecondWaveColour = ColourProvider.Light3;
|
|
||||||
Waves.ThirdWaveColour = ColourProvider.Dark4;
|
|
||||||
Waves.FourthWaveColour = ColourProvider.Dark3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract T CreateHeader();
|
protected abstract T CreateHeader();
|
||||||
|
|
||||||
|
[MemberNotNull(nameof(Header))]
|
||||||
|
protected void RecreateHeader()
|
||||||
|
{
|
||||||
|
Header = CreateHeader();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Show()
|
public override void Show()
|
||||||
{
|
{
|
||||||
if (State.Value == Visibility.Visible)
|
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()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
base.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)
|
if (user.OnlineID == Header.User.Value?.User.Id && ruleset?.MatchesOnlineID(Header.User.Value?.Ruleset) == true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sectionsContainer != null)
|
sectionsContainer?.ScrollToTop();
|
||||||
sectionsContainer.ExpandableHeader = null;
|
sectionsContainer?.Clear();
|
||||||
|
tabs?.Clear();
|
||||||
|
|
||||||
userReq?.Cancel();
|
userReq?.Cancel();
|
||||||
Clear();
|
|
||||||
lastSection = null;
|
lastSection = null;
|
||||||
|
|
||||||
sections = !user.IsBot
|
sections = !user.IsBot
|
||||||
@ -119,20 +119,74 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
: Array.Empty<ProfileSection>();
|
: Array.Empty<ProfileSection>();
|
||||||
|
|
||||||
tabs = new ProfileSectionTabControl
|
setupBaseContent(OverlayColourScheme.Pink);
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
};
|
|
||||||
|
|
||||||
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,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = sectionsContainer = new ProfileSectionsContainer
|
Child = sectionsContainer = new ProfileSectionsContainer
|
||||||
{
|
{
|
||||||
ExpandableHeader = Header,
|
ExpandableHeader = Header,
|
||||||
FixedHeader = tabs,
|
FixedHeader = tabs = new ProfileSectionTabControl
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
},
|
||||||
HeaderBackground = new Box
|
HeaderBackground = new Box
|
||||||
{
|
{
|
||||||
// this is only visible as the ProfileTabControl background
|
// this is only visible as the ProfileTabControl background
|
||||||
@ -140,7 +194,7 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
sectionsContainer.SelectedSection.ValueChanged += section =>
|
sectionsContainer.SelectedSection.ValueChanged += section =>
|
||||||
{
|
{
|
||||||
@ -167,45 +221,6 @@ namespace osu.Game.Overlays
|
|||||||
sectionsContainer.ScrollTo(lastSection);
|
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>
|
private partial class ProfileSectionTabControl : OsuTabControl<ProfileSection>
|
||||||
|
Loading…
Reference in New Issue
Block a user