1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +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;
public IEnumerable<BeatmapPanel> BeatmapPanels;
public List<BeatmapPanel> BeatmapPanels;
public BeatmapGroupState State
{
@ -43,9 +43,6 @@ namespace osu.Game.Beatmaps.Drawable
difficulties.Show();
header.State = PanelSelectedState.Selected;
if (SelectedPanel == null)
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
FadeTo(0.5f, 250);
@ -66,13 +63,13 @@ namespace osu.Game.Beatmaps.Drawable
RelativeSizeAxes = Axes.X;
BeatmapPanels = beatmapSet.Beatmaps.Select(b =>
new BeatmapPanel(this.beatmapSet, b)
new BeatmapPanel(b)
{
GainedSelection = panelGainedSelection,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
});
}).ToList();
Children = new[]
@ -117,19 +114,27 @@ namespace osu.Game.Beatmaps.Drawable
{
State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
if (SelectedPanel == null)
BeatmapPanels.First().State = PanelSelectedState.Selected;
}
private void panelGainedSelection(BeatmapPanel panel)
{
State = BeatmapGroupState.Expanded;
try
{
if (SelectedPanel == panel) return;
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
SelectedPanel = panel;
}
finally
{
State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, panel.Beatmap);
}
}
}
public enum BeatmapGroupState
{

View File

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

View File

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

View File

@ -180,8 +180,13 @@ namespace osu.Game.GameModes.Play
beatmapSetFlow.Children.Cast<BeatmapGroup>().First(b =>
{
var panel = b.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
panel?.TriggerClick();
return panel != null;
if (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 };
beatmapSetFlow.Add(group);
if (Beatmap == null)
{
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;
}
}
});
}