1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00

Implement score panel list

This commit is contained in:
smoogipoo 2020-05-20 23:46:47 +09:00
parent e3c1112b5a
commit 1b8d657ead
3 changed files with 163 additions and 6 deletions

View File

@ -0,0 +1,69 @@
// 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;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Beatmaps;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Ranking
{
public class TestSceneScorePanelList : OsuTestScene
{
public TestSceneScorePanelList()
{
var list = new ScorePanelList
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
Add(list);
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
list.AddScore(createScore());
}
private ScoreInfo createScore() => new ScoreInfo
{
User = new User
{
Id = 2,
Username = "peppy",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
},
Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo,
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
TotalScore = 2845370,
Accuracy = 0.95,
MaxCombo = 999,
Rank = ScoreRank.S,
Date = DateTimeOffset.Now,
Statistics =
{
{ HitResult.Miss, 1 },
{ HitResult.Meh, 50 },
{ HitResult.Good, 100 },
{ HitResult.Great, 300 },
}
};
}
}

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Contracted;
using osu.Game.Screens.Ranking.Expanded;
@ -75,8 +76,7 @@ namespace osu.Game.Screens.Ranking
private static readonly Color4 contracted_middle_layer_colour = Color4Extensions.FromHex("#353535");
public event Action<PanelState> StateChanged;
private readonly ScoreInfo score;
public readonly ScoreInfo Score;
private Container topLayerContainer;
private Drawable topLayerBackground;
@ -90,7 +90,7 @@ namespace osu.Game.Screens.Ranking
public ScorePanel(ScoreInfo score)
{
this.score = score;
Score = score;
}
[BackgroundDependencyLoader]
@ -189,8 +189,8 @@ namespace osu.Game.Screens.Ranking
topLayerBackground.FadeColour(expanded_top_layer_colour, resize_duration, Easing.OutQuint);
middleLayerBackground.FadeColour(expanded_middle_layer_colour, resize_duration, Easing.OutQuint);
topLayerContentContainer.Add(middleLayerContent = new ExpandedPanelTopContent(score.User).With(d => d.Alpha = 0));
middleLayerContentContainer.Add(topLayerContent = new ExpandedPanelMiddleContent(score).With(d => d.Alpha = 0));
topLayerContentContainer.Add(middleLayerContent = new ExpandedPanelTopContent(Score.User).With(d => d.Alpha = 0));
middleLayerContentContainer.Add(topLayerContent = new ExpandedPanelMiddleContent(Score).With(d => d.Alpha = 0));
break;
case PanelState.Contracted:
@ -199,7 +199,7 @@ namespace osu.Game.Screens.Ranking
topLayerBackground.FadeColour(contracted_top_layer_colour, resize_duration, Easing.OutQuint);
middleLayerBackground.FadeColour(contracted_middle_layer_colour, resize_duration, Easing.OutQuint);
middleLayerContentContainer.Add(topLayerContent = new ContractedPanelMiddleContent(score).With(d => d.Alpha = 0));
middleLayerContentContainer.Add(topLayerContent = new ContractedPanelMiddleContent(Score).With(d => d.Alpha = 0));
break;
}
@ -222,5 +222,13 @@ namespace osu.Game.Screens.Ranking
middleLayerContent?.FadeIn(content_fade_duration);
}
}
protected override bool OnClick(ClickEvent e)
{
if (State == PanelState.Contracted)
State = PanelState.Expanded;
return true;
}
}
}

View File

@ -0,0 +1,80 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Scoring;
using osuTK;
namespace osu.Game.Screens.Ranking
{
public class ScorePanelList : CompositeDrawable
{
private readonly Flow panels;
private ScorePanel expandedPanel;
public ScorePanelList()
{
RelativeSizeAxes = Axes.Both;
InternalChild = panels = new Flow
{
Anchor = Anchor.Centre,
Origin = Anchor.Custom,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
};
}
public void AddScore(ScoreInfo score)
{
var panel = new ScorePanel(score)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
};
panel.StateChanged += s => onPanelStateChanged(panel, s);
// Todo: Temporary
panel.State = expandedPanel == null ? PanelState.Expanded : PanelState.Contracted;
panels.Add(panel);
}
public void RemoveScore(ScoreInfo score) => panels.RemoveAll(p => p.Score == score);
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (expandedPanel != null)
{
var firstPanel = panels.FlowingChildren.First();
var target = expandedPanel.DrawPosition.X - firstPanel.DrawPosition.X + expandedPanel.DrawSize.X / 2;
panels.OriginPosition = new Vector2((float)Interpolation.Lerp(panels.OriginPosition.X, target, Math.Clamp(Math.Abs(Time.Elapsed) / 80, 0, 1)), panels.DrawHeight / 2);
}
}
private void onPanelStateChanged(ScorePanel panel, PanelState state)
{
if (state == PanelState.Contracted)
return;
if (expandedPanel != null)
expandedPanel.State = PanelState.Contracted;
expandedPanel = panel;
}
private class Flow : FillFlowContainer<ScorePanel>
{
// Todo: Order is wrong.
public override IEnumerable<Drawable> FlowingChildren => AliveInternalChildren.OfType<ScorePanel>().OrderBy(s => s.Score.TotalScore);
}
}
}