// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; using osu.Game.Graphics; using osu.Game.Scoring; using osuTK; using osuTK.Graphics; namespace osu.Game.Overlays.BeatmapSet.Scores { public class DrawableTopScore : CompositeDrawable { private const float fade_duration = 100; private Color4 backgroundIdleColour; private Color4 backgroundHoveredColour; private readonly Box background; private readonly TopScoreUserSection userSection; private readonly TopScoreStatisticsSection statisticsSection; public DrawableTopScore() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; Masking = true; CornerRadius = 10; EdgeEffect = new EdgeEffectParameters { Type = EdgeEffectType.Shadow, Colour = Color4.Black.Opacity(0.2f), Radius = 1, Offset = new Vector2(0, 1), }; InternalChildren = new Drawable[] { background = new Box { RelativeSizeAxes = Axes.Both, }, new Container { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, Padding = new MarginPadding(10), Children = new Drawable[] { new AutoSizingGrid { RelativeSizeAxes = Axes.X, Content = new[] { new Drawable[] { userSection = new TopScoreUserSection { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, }, null, statisticsSection = new TopScoreStatisticsSection { Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, } }, }, ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize), new Dimension(GridSizeMode.Absolute, 20) }, RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, } } } }; } [BackgroundDependencyLoader] private void load(OsuColour colours) { backgroundIdleColour = colours.Gray3; backgroundHoveredColour = colours.Gray4; background.Colour = backgroundIdleColour; } /// /// Sets the score to be displayed. /// public ScoreInfo Score { set { userSection.Score = value; statisticsSection.Score = value; } } protected override bool OnHover(HoverEvent e) { background.FadeColour(backgroundHoveredColour, fade_duration, Easing.OutQuint); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { background.FadeColour(backgroundIdleColour, fade_duration, Easing.OutQuint); base.OnHoverLost(e); } private class AutoSizingGrid : GridContainer { public AutoSizingGrid() { AutoSizeAxes = Axes.Y; } } } }