mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Refactor initial state
This commit is contained in:
parent
7b82a5d792
commit
d0f74c2b68
@ -1,38 +1,51 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Ranking;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Ranking
|
||||
{
|
||||
public class TestSceneScorePanelList : OsuTestScene
|
||||
{
|
||||
public TestSceneScorePanelList()
|
||||
private ScorePanelList list;
|
||||
|
||||
[SetUp]
|
||||
public void Setup() => Schedule(() =>
|
||||
{
|
||||
var list = new ScorePanelList
|
||||
Child = list = new ScorePanelList(new TestScoreInfo(new OsuRuleset().RulesetInfo))
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
|
||||
Add(list);
|
||||
Add(new Box
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = 1,
|
||||
Colour = Color4.Red
|
||||
});
|
||||
});
|
||||
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
[Test]
|
||||
public void TestSingleScore()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestManyScores()
|
||||
{
|
||||
AddStep("add many scores", () =>
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
list.AddScore(new TestScoreInfo(new OsuRuleset().RulesetInfo));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Screens.Ranking
|
||||
{
|
||||
new ResultsScrollContainer
|
||||
{
|
||||
Child = panels = new ScorePanelList
|
||||
Child = panels = new ScorePanelList(Score)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
@ -98,8 +98,6 @@ namespace osu.Game.Screens.Ranking
|
||||
}
|
||||
};
|
||||
|
||||
panels.AddScore(Score);
|
||||
|
||||
if (player != null && allowRetry)
|
||||
{
|
||||
buttons.Add(new RetryButton { Width = 300 });
|
||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Screens.Ranking
|
||||
|
||||
private ScorePanel expandedPanel;
|
||||
|
||||
public ScorePanelList()
|
||||
public ScorePanelList(ScoreInfo initialScore)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -44,48 +44,48 @@ namespace osu.Game.Screens.Ranking
|
||||
AutoSizeAxes = Axes.Both,
|
||||
}
|
||||
};
|
||||
|
||||
AddScore(initialScore);
|
||||
ShowScore(initialScore);
|
||||
}
|
||||
|
||||
public void AddScore(ScoreInfo score)
|
||||
{
|
||||
var panel = new ScorePanel(score)
|
||||
flow.Add(new ScorePanel(score)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
}.With(p =>
|
||||
{
|
||||
p.StateChanged += s =>
|
||||
{
|
||||
if (s == PanelState.Expanded)
|
||||
ShowScore(score);
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
panel.StateChanged += s => onPanelStateChanged(panel, s);
|
||||
public void ShowScore(ScoreInfo score)
|
||||
{
|
||||
foreach (var p in flow.Where(p => p.Score != score))
|
||||
p.State = PanelState.Contracted;
|
||||
|
||||
// Todo: Temporary
|
||||
panel.State = expandedPanel == null ? PanelState.Expanded : PanelState.Contracted;
|
||||
if (expandedPanel != null)
|
||||
expandedPanel.Margin = new MarginPadding(0);
|
||||
|
||||
flow.Add(panel);
|
||||
expandedPanel = flow.Single(p => p.Score == score);
|
||||
expandedPanel.State = PanelState.Expanded;
|
||||
expandedPanel.Margin = new MarginPadding { Horizontal = expanded_panel_spacing };
|
||||
|
||||
float scrollOffset = flow.IndexOf(expandedPanel) * (ScorePanel.CONTRACTED_WIDTH + panel_spacing);
|
||||
scroll.ScrollTo(scrollOffset);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
flow.Padding = new MarginPadding { Horizontal = DrawWidth / 2f - ScorePanel.EXPANDED_WIDTH / 2f - expanded_panel_spacing };
|
||||
}
|
||||
|
||||
private void onPanelStateChanged(ScorePanel panel, PanelState state)
|
||||
{
|
||||
if (state == PanelState.Contracted)
|
||||
return;
|
||||
|
||||
if (expandedPanel != null)
|
||||
{
|
||||
expandedPanel.Margin = new MarginPadding(0);
|
||||
expandedPanel.State = PanelState.Contracted;
|
||||
}
|
||||
|
||||
expandedPanel = panel;
|
||||
expandedPanel.Margin = new MarginPadding { Horizontal = expanded_panel_spacing };
|
||||
|
||||
float panelOffset = flow.IndexOf(expandedPanel) * (ScorePanel.CONTRACTED_WIDTH + panel_spacing);
|
||||
|
||||
scroll.ScrollTo(panelOffset);
|
||||
flow.Padding = new MarginPadding { Horizontal = DrawWidth / 2f - expandedPanel.DrawWidth / 2f - expanded_panel_spacing };
|
||||
}
|
||||
|
||||
private class Flow : FillFlowContainer<ScorePanel>
|
||||
|
Loading…
Reference in New Issue
Block a user