1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 01:32:55 +08:00

Tidy shit up; reduce number of unnecssesary events being fired.

This commit is contained in:
Dean Herbert 2016-10-28 23:27:59 +09:00
parent 5dc495e41d
commit 42ad96778e
4 changed files with 40 additions and 19 deletions

View File

@ -28,7 +28,7 @@ namespace osu.Game.Beatmaps.Drawable
private BeatmapGroupState state; private BeatmapGroupState state;
public IEnumerable<BeatmapPanel> BeatmapPanels; public List<BeatmapPanel> BeatmapPanels;
public BeatmapGroupState State public BeatmapGroupState State
{ {
@ -43,9 +43,6 @@ namespace osu.Game.Beatmaps.Drawable
difficulties.Show(); difficulties.Show();
header.State = PanelSelectedState.Selected; header.State = PanelSelectedState.Selected;
if (SelectedPanel == null)
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
break; break;
case BeatmapGroupState.Collapsed: case BeatmapGroupState.Collapsed:
FadeTo(0.5f, 250); FadeTo(0.5f, 250);
@ -66,13 +63,13 @@ namespace osu.Game.Beatmaps.Drawable
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
BeatmapPanels = beatmapSet.Beatmaps.Select(b => BeatmapPanels = beatmapSet.Beatmaps.Select(b =>
new BeatmapPanel(this.beatmapSet, b) new BeatmapPanel(b)
{ {
GainedSelection = panelGainedSelection, GainedSelection = panelGainedSelection,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
}); }).ToList();
Children = new[] Children = new[]
@ -117,17 +114,25 @@ namespace osu.Game.Beatmaps.Drawable
{ {
State = BeatmapGroupState.Expanded; State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap); if (SelectedPanel == null)
BeatmapPanels.First().State = PanelSelectedState.Selected;
} }
private void panelGainedSelection(BeatmapPanel panel) private void panelGainedSelection(BeatmapPanel panel)
{ {
State = BeatmapGroupState.Expanded; try
{
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected; if (SelectedPanel == panel) return;
SelectedPanel = panel;
SelectionChanged?.Invoke(this, panel.Beatmap); if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
SelectedPanel = panel;
}
finally
{
State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, panel.Beatmap);
}
} }
} }

View File

@ -26,7 +26,7 @@ namespace osu.Game.Beatmaps.Drawable
GainedSelection?.Invoke(this); GainedSelection?.Invoke(this);
} }
public BeatmapPanel(BeatmapSetInfo set, BeatmapInfo beatmap) public BeatmapPanel(BeatmapInfo beatmap)
{ {
Beatmap = beatmap; Beatmap = beatmap;
Height *= 0.75f; Height *= 0.75f;
@ -67,7 +67,7 @@ namespace osu.Game.Beatmaps.Drawable
}, },
new SpriteText new SpriteText
{ {
Text = $" mapped by {(beatmap.Metadata ?? set.Metadata).Author}", Text = $" mapped by {(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author}",
TextSize = 16, TextSize = 16,
}, },
} }

View File

@ -37,7 +37,6 @@ namespace osu.Game.Beatmaps.Drawable
set set
{ {
if (state == value) return; if (state == value) return;
state = value; state = value;
switch (state) switch (state)

View File

@ -180,8 +180,13 @@ namespace osu.Game.GameModes.Play
beatmapSetFlow.Children.Cast<BeatmapGroup>().First(b => beatmapSetFlow.Children.Cast<BeatmapGroup>().First(b =>
{ {
var panel = b.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap)); var panel = b.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
panel?.TriggerClick(); if (panel != null)
return panel != null; {
panel.State = PanelSelectedState.Selected;
return true;
}
return false;
}); });
} }
@ -228,8 +233,20 @@ namespace osu.Game.GameModes.Play
{ {
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectionChanged }; var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectionChanged };
beatmapSetFlow.Add(group); beatmapSetFlow.Add(group);
if (beatmapSetFlow.Children.Count() == 1) if (Beatmap == null)
group.State = BeatmapGroupState.Expanded; {
if (beatmapSetFlow.Children.Count() == 1)
group.State = BeatmapGroupState.Expanded;
}
else
{
if (selectedBeatmapInfo?.Equals(Beatmap.BeatmapInfo) != true)
{
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(Beatmap.BeatmapInfo));
if (panel != null)
panel.State = PanelSelectedState.Selected;
}
}
}); });
} }