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

Rewrite a lot of Song Select to share logic between panels and consolidate logic inside classes where possible.

This commit is contained in:
Dean Herbert 2016-10-27 19:52:48 +09:00
parent c828b1bc7b
commit d9dfc324c1
6 changed files with 140 additions and 86 deletions

View File

@ -7,19 +7,14 @@ using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
using osu.Game.Database;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawable
{
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
{
private const float collapsedAlpha = 0.5f;
private const float collapsedWidth = 0.8f;
private BeatmapPanel selectedPanel;
public BeatmapPanel SelectedPanel;
/// <summary>
/// Fires when one of our difficulties was selected. Will fire on first expand.
@ -44,23 +39,16 @@ namespace osu.Game.Beatmaps.Drawable
FadeTo(1, 250);
difficulties.Show();
//todo: header should probably have a state, with this logic moved inside it.
header.Width = 1;
header.GlowRadius = 5;
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 255);
header.State = PanelSelectedState.Selected;
if (selectedPanel == null)
(difficulties.Children.FirstOrDefault() as BeatmapPanel).Selected = true;
SelectionChanged?.Invoke(this, selectedPanel?.Beatmap);
if (SelectedPanel == null)
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
FadeTo(collapsedAlpha, 250);
difficulties.Hide();
FadeTo(0.5f, 250);
//todo: header should probably have a state, with this logic moved inside it.
header.Width = collapsedWidth;
header.GlowRadius = 0;
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 0);
header.State = PanelSelectedState.NotSelected;
difficulties.Hide();
break;
}
}
@ -68,10 +56,12 @@ namespace osu.Game.Beatmaps.Drawable
public BeatmapGroup(BeatmapSetInfo beatmapSet)
{
this.beatmapSet = beatmapSet;
this.beatmapSet = beatmapSet;
Alpha = 0;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
RelativeSizeAxes = Axes.X;
Children = new[]
{
new FlowContainer
@ -83,8 +73,8 @@ namespace osu.Game.Beatmaps.Drawable
{
header = new BeatmapSetHeader(beatmapSet)
{
GainedSelection = headerGainedSelection,
RelativeSizeAxes = Axes.X,
Width = collapsedWidth,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
},
@ -118,18 +108,21 @@ namespace osu.Game.Beatmaps.Drawable
State = BeatmapGroupState.Collapsed;
}
private void panelGainedSelection(BeatmapPanel panel)
private void headerGainedSelection(BeatmapSetHeader panel)
{
if (selectedPanel != null) selectedPanel.Selected = false;
selectedPanel = panel;
SelectionChanged?.Invoke(this, panel.Beatmap);
State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
}
protected override bool OnClick(InputState state)
private void panelGainedSelection(BeatmapPanel panel)
{
State = BeatmapGroupState.Expanded;
return true;
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
SelectedPanel = panel;
SelectionChanged?.Invoke(this, panel.Beatmap);
}
}

View File

@ -6,7 +6,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
@ -15,42 +14,23 @@ using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawable
{
class BeatmapPanel : Container
class BeatmapPanel : Panel
{
public BeatmapInfo Beatmap;
public Action<BeatmapPanel> GainedSelection;
private bool selected;
public bool Selected
{
get { return selected; }
set
{
if (selected == value)
return;
selected = value;
BorderColour = new Color4(
BorderColour.R,
BorderColour.G,
BorderColour.B,
selected ? 255 : 0);
GlowRadius = selected ? 3 : 0;
if (selected) GainedSelection?.Invoke(this);
}
public Action<BeatmapPanel> GainedSelection;
protected override void Selected()
{
base.Selected();
GainedSelection?.Invoke(this);
}
public BeatmapPanel(BeatmapSetInfo set, BeatmapInfo beatmap)
{
Beatmap = beatmap;
AutoSizeAxes = Axes.Y;
Masking = true;
CornerRadius = 5;
BorderThickness = 2;
BorderColour = new Color4(221, 255, 255, 0);
GlowColour = new Color4(166, 221, 251, 0.75f); // TODO: Get actual color for this
{
Beatmap = beatmap;
Height *= 0.75f;
Children = new Framework.Graphics.Drawable[]
{
new Box
@ -87,8 +67,7 @@ namespace osu.Game.Beatmaps.Drawable
},
new SpriteText
{
Text = string.Format(" mapped by {0}",
(beatmap.Metadata ?? set.Metadata).Author),
Text = $" mapped by {(beatmap.Metadata ?? set.Metadata).Author}",
TextSize = 16,
},
}
@ -99,12 +78,6 @@ namespace osu.Game.Beatmaps.Drawable
}
}
};
}
protected override bool OnClick(InputState state)
{
Selected = true;
return true;
}
}
}
}

View File

@ -1,6 +1,7 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
@ -12,35 +13,42 @@ using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawable
{
class BeatmapSetHeader : Container
class BeatmapSetHeader : Panel
{
public Action<BeatmapSetHeader> GainedSelection;
protected override void Selected()
{
base.Selected();
Width = 1;
GainedSelection?.Invoke(this);
}
protected override void Deselected()
{
base.Deselected();
Width = 0.8f;
}
public BeatmapSetHeader(BeatmapSetInfo beatmapSet)
{
AutoSizeAxes = Axes.Y;
Masking = true;
CornerRadius = 5;
BorderThickness = 2;
BorderColour = new Color4(221, 255, 255, 0);
GlowColour = new Color4(166, 221, 251, 0.5f); // TODO: Get actual color for this
Children = new Framework.Graphics.Drawable[]
{
new Box
{
Colour = new Color4(85, 85, 85, 255),
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Children = new Framework.Graphics.Drawable[]
{
new Box // TODO: Gradient
{
Colour = new Color4(0, 0, 0, 100),
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
}
}
},
@ -48,7 +56,7 @@ namespace osu.Game.Beatmaps.Drawable
{
Direction = FlowDirection.VerticalOnly,
Spacing = new Vector2(0, 2),
Padding = new MarginPadding { Top = 3, Left = 20, Right = 20, Bottom = 3 },
Padding = new MarginPadding { Top = 10, Left = 15, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new[]
{
@ -75,6 +83,8 @@ namespace osu.Game.Beatmaps.Drawable
}
}
};
Deselected();
}
}
}

View File

@ -0,0 +1,81 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawable
{
class Panel : Container, IStateful<PanelSelectedState>
{
public Panel()
{
Height = 80;
Masking = true;
CornerRadius = 10;
BorderColour = new Color4(221, 255, 255, 0);
GlowColour = new Color4(102, 204, 255, 100);
RelativeSizeAxes = Axes.X;
}
private PanelSelectedState state;
public PanelSelectedState State
{
get { return state; }
set
{
if (state == value) return;
state = value;
switch (state)
{
case PanelSelectedState.NotSelected:
Deselected();
break;
case PanelSelectedState.Selected:
Selected();
break;
}
}
}
protected virtual void Selected()
{
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 255);
GlowRadius = 10;
BorderThickness = 2.5f;
}
protected virtual void Deselected()
{
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 0);
GlowRadius = 0;
BorderThickness = 0;
}
protected override bool OnClick(InputState state)
{
State = PanelSelectedState.Selected;
return true;
}
}
enum PanelSelectedState
{
NotSelected,
Selected
}
}

View File

@ -26,7 +26,6 @@ namespace osu.Game.GameModes.Play
private Bindable<PlayMode> playMode;
private BeatmapDatabase database;
private BeatmapGroup selectedBeatmapGroup;
private BeatmapInfo selectedBeatmap;
// TODO: use currently selected track as bg
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
private ScrollContainer scrollContainer;
@ -106,7 +105,7 @@ namespace osu.Game.GameModes.Play
Width = 100,
Text = "Play",
Colour = new Color4(238, 51, 153, 255),
Action = () => Push(new Player { BeatmapInfo = selectedBeatmap }),
Action = () => Push(new Player { BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap }),
},
}
}
@ -129,7 +128,7 @@ namespace osu.Game.GameModes.Play
if (database == null)
database = (game as OsuGameBase).Beatmaps;
database.BeatmapSetAdded += s => Scheduler.Add(() => addBeatmapSet(s));
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
Task.Factory.StartNew(addBeatmapSets);
}
@ -154,7 +153,6 @@ namespace osu.Game.GameModes.Play
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
selectedBeatmapGroup = group;
selectedBeatmap = beatmap;
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
@ -167,9 +165,7 @@ namespace osu.Game.GameModes.Play
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap };
setList.Add(group);
if (setList.Children.Count() == 1)
{
group.State = BeatmapGroupState.Expanded;
}
});
}

View File

@ -66,6 +66,7 @@
<Compile Include="Beatmaps\Beatmap.cs" />
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
<Compile Include="Beatmaps\Drawable\DifficultyIcon.cs" />
<Compile Include="Beatmaps\Drawable\Panel.cs" />
<Compile Include="Beatmaps\Objects\Catch\CatchConverter.cs" />
<Compile Include="Beatmaps\Objects\Catch\Drawable\DrawableFruit.cs" />
<Compile Include="Beatmaps\Objects\DrawableHitObject.cs" />