1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:07:24 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/DetailHeaderContainer.cs

203 lines
8.7 KiB
C#
Raw Normal View History

2019-01-28 06:45:00 +08:00
// 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.Collections.Generic;
using osu.Framework.Allocation;
2019-03-10 06:58:14 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2019-04-26 12:49:44 +08:00
using osu.Game.Overlays.Profile.Header.Components;
using osu.Game.Scoring;
using osu.Game.Users;
using osuTK;
namespace osu.Game.Overlays.Profile.Header
{
2019-03-10 06:58:14 +08:00
public class DetailHeaderContainer : CompositeDrawable
{
private readonly Dictionary<ScoreRank, ScoreRankInfo> scoreRankInfos = new Dictionary<ScoreRank, ScoreRankInfo>();
2019-04-26 12:56:26 +08:00
private OverlinedInfoContainer medalInfo;
private OverlinedInfoContainer ppInfo;
private OverlinedInfoContainer detailGlobalRank;
private OverlinedInfoContainer detailCountryRank;
private RankGraph rankGraph;
2019-03-10 06:58:14 +08:00
public readonly Bindable<User> User = new Bindable<User>();
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2019-03-10 06:58:14 +08:00
AutoSizeAxes = Axes.Y;
User.ValueChanged += e => updateDisplay(e.NewValue);
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.CommunityUserGrayGreenDarkest,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN, Vertical = 10 },
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
new OverlinedTotalPlayTime
{
User = { BindTarget = User }
},
2019-03-10 06:58:14 +08:00
medalInfo = new OverlinedInfoContainer
{
Title = "Medals",
LineColour = colours.GreenLight,
},
2019-03-10 06:58:14 +08:00
ppInfo = new OverlinedInfoContainer
{
Title = "pp",
LineColour = colours.Red,
},
}
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Direction = FillDirection.Horizontal,
Children = new[]
{
scoreRankInfos[ScoreRank.XH] = new ScoreRankInfo(ScoreRank.XH),
scoreRankInfos[ScoreRank.X] = new ScoreRankInfo(ScoreRank.X),
scoreRankInfos[ScoreRank.SH] = new ScoreRankInfo(ScoreRank.SH),
scoreRankInfos[ScoreRank.S] = new ScoreRankInfo(ScoreRank.S),
scoreRankInfos[ScoreRank.A] = new ScoreRankInfo(ScoreRank.A),
}
}
}
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Right = 130 },
Children = new Drawable[]
{
rankGraph = new RankGraph
{
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
Width = 130,
Anchor = Anchor.TopRight,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Horizontal = 10 },
Spacing = new Vector2(0, 20),
Children = new Drawable[]
{
2019-03-10 06:58:14 +08:00
detailGlobalRank = new OverlinedInfoContainer(true, 110)
{
Title = "Global Ranking",
LineColour = colours.Yellow,
},
2019-03-10 06:58:14 +08:00
detailCountryRank = new OverlinedInfoContainer(false, 110)
{
Title = "Country Ranking",
LineColour = colours.Yellow,
},
}
}
}
},
}
},
};
}
2019-03-10 06:58:14 +08:00
private void updateDisplay(User user)
{
medalInfo.Content = user?.Achievements?.Length.ToString() ?? "0";
ppInfo.Content = user?.Statistics?.PP?.ToString("#,##0") ?? "0";
foreach (var scoreRankInfo in scoreRankInfos)
2019-03-06 15:30:56 +08:00
scoreRankInfo.Value.RankCount = user?.Statistics?.GradesCount[scoreRankInfo.Key] ?? 0;
detailGlobalRank.Content = user?.Statistics?.Ranks.Global?.ToString("\\##,##0") ?? "-";
detailCountryRank.Content = user?.Statistics?.Ranks.Country?.ToString("\\##,##0") ?? "-";
rankGraph.User.Value = user;
}
private class ScoreRankInfo : CompositeDrawable
{
private readonly ScoreRank rank;
private readonly Sprite rankSprite;
private readonly OsuSpriteText rankCount;
public int RankCount
{
set => rankCount.Text = value.ToString("#,##0");
}
public ScoreRankInfo(ScoreRank rank)
{
this.rank = rank;
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
Width = 56,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
rankSprite = new Sprite
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit
},
rankCount = new OsuSpriteText
{
2019-04-25 17:05:46 +08:00
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre
}
}
};
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
rankSprite.Texture = textures.Get($"Grades/{rank.GetDescription()}");
}
}
}
}