mirror of
https://github.com/osukey/osukey.git
synced 2025-05-20 21:17:32 +09:00
Rewrite a lot of Song Select to share logic between panels and consolidate logic inside classes where possible.
This commit is contained in:
parent
c828b1bc7b
commit
d9dfc324c1
@ -7,19 +7,14 @@ using osu.Framework;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawable
|
namespace osu.Game.Beatmaps.Drawable
|
||||||
{
|
{
|
||||||
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
||||||
{
|
{
|
||||||
private const float collapsedAlpha = 0.5f;
|
public BeatmapPanel SelectedPanel;
|
||||||
private const float collapsedWidth = 0.8f;
|
|
||||||
|
|
||||||
private BeatmapPanel selectedPanel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
/// 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);
|
FadeTo(1, 250);
|
||||||
difficulties.Show();
|
difficulties.Show();
|
||||||
|
|
||||||
//todo: header should probably have a state, with this logic moved inside it.
|
header.State = PanelSelectedState.Selected;
|
||||||
header.Width = 1;
|
|
||||||
header.GlowRadius = 5;
|
|
||||||
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 255);
|
|
||||||
|
|
||||||
if (selectedPanel == null)
|
if (SelectedPanel == null)
|
||||||
(difficulties.Children.FirstOrDefault() as BeatmapPanel).Selected = true;
|
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
|
||||||
SelectionChanged?.Invoke(this, selectedPanel?.Beatmap);
|
|
||||||
break;
|
break;
|
||||||
case BeatmapGroupState.Collapsed:
|
case BeatmapGroupState.Collapsed:
|
||||||
FadeTo(collapsedAlpha, 250);
|
FadeTo(0.5f, 250);
|
||||||
difficulties.Hide();
|
|
||||||
|
|
||||||
//todo: header should probably have a state, with this logic moved inside it.
|
header.State = PanelSelectedState.NotSelected;
|
||||||
header.Width = collapsedWidth;
|
difficulties.Hide();
|
||||||
header.GlowRadius = 0;
|
|
||||||
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 0);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,10 +56,12 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
|
|
||||||
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
||||||
{
|
{
|
||||||
this.beatmapSet = beatmapSet;
|
this.beatmapSet = beatmapSet;
|
||||||
|
|
||||||
Alpha = 0;
|
Alpha = 0;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new FlowContainer
|
new FlowContainer
|
||||||
@ -83,8 +73,8 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
{
|
{
|
||||||
header = new BeatmapSetHeader(beatmapSet)
|
header = new BeatmapSetHeader(beatmapSet)
|
||||||
{
|
{
|
||||||
|
GainedSelection = headerGainedSelection,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Width = collapsedWidth,
|
|
||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight,
|
Origin = Anchor.TopRight,
|
||||||
},
|
},
|
||||||
@ -118,18 +108,21 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
State = BeatmapGroupState.Collapsed;
|
State = BeatmapGroupState.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void panelGainedSelection(BeatmapPanel panel)
|
private void headerGainedSelection(BeatmapSetHeader panel)
|
||||||
{
|
{
|
||||||
if (selectedPanel != null) selectedPanel.Selected = false;
|
State = BeatmapGroupState.Expanded;
|
||||||
selectedPanel = panel;
|
|
||||||
|
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
|
||||||
SelectionChanged?.Invoke(this, panel.Beatmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
private void panelGainedSelection(BeatmapPanel panel)
|
||||||
{
|
{
|
||||||
State = BeatmapGroupState.Expanded;
|
State = BeatmapGroupState.Expanded;
|
||||||
return true;
|
|
||||||
|
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
|
||||||
|
SelectedPanel = panel;
|
||||||
|
|
||||||
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
@ -15,42 +14,23 @@ using OpenTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawable
|
namespace osu.Game.Beatmaps.Drawable
|
||||||
{
|
{
|
||||||
class BeatmapPanel : Container
|
class BeatmapPanel : Panel
|
||||||
{
|
{
|
||||||
public BeatmapInfo Beatmap;
|
public BeatmapInfo Beatmap;
|
||||||
|
|
||||||
public Action<BeatmapPanel> GainedSelection;
|
public Action<BeatmapPanel> GainedSelection;
|
||||||
|
|
||||||
private bool selected;
|
protected override void Selected()
|
||||||
|
{
|
||||||
public bool Selected
|
base.Selected();
|
||||||
{
|
GainedSelection?.Invoke(this);
|
||||||
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 BeatmapPanel(BeatmapSetInfo set, BeatmapInfo beatmap)
|
public BeatmapPanel(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
AutoSizeAxes = Axes.Y;
|
Height *= 0.75f;
|
||||||
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
|
|
||||||
Children = new Framework.Graphics.Drawable[]
|
Children = new Framework.Graphics.Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
@ -87,8 +67,7 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
},
|
},
|
||||||
new SpriteText
|
new SpriteText
|
||||||
{
|
{
|
||||||
Text = string.Format(" mapped by {0}",
|
Text = $" mapped by {(beatmap.Metadata ?? set.Metadata).Author}",
|
||||||
(beatmap.Metadata ?? set.Metadata).Author),
|
|
||||||
TextSize = 16,
|
TextSize = 16,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -99,12 +78,6 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
|
||||||
{
|
|
||||||
Selected = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
@ -12,35 +13,42 @@ using OpenTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawable
|
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)
|
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[]
|
Children = new Framework.Graphics.Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
Colour = new Color4(85, 85, 85, 255),
|
Colour = new Color4(85, 85, 85, 255),
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Size = Vector2.One,
|
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Size = Vector2.One,
|
|
||||||
Children = new Framework.Graphics.Drawable[]
|
Children = new Framework.Graphics.Drawable[]
|
||||||
{
|
{
|
||||||
new Box // TODO: Gradient
|
new Box // TODO: Gradient
|
||||||
{
|
{
|
||||||
Colour = new Color4(0, 0, 0, 100),
|
Colour = new Color4(0, 0, 0, 100),
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Size = Vector2.One,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -48,7 +56,7 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
{
|
{
|
||||||
Direction = FlowDirection.VerticalOnly,
|
Direction = FlowDirection.VerticalOnly,
|
||||||
Spacing = new Vector2(0, 2),
|
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,
|
AutoSizeAxes = Axes.Both,
|
||||||
Children = new[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
@ -75,6 +83,8 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Deselected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
81
osu.Game/Beatmaps/Drawable/Panel.cs
Normal file
81
osu.Game/Beatmaps/Drawable/Panel.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,6 @@ namespace osu.Game.GameModes.Play
|
|||||||
private Bindable<PlayMode> playMode;
|
private Bindable<PlayMode> playMode;
|
||||||
private BeatmapDatabase database;
|
private BeatmapDatabase database;
|
||||||
private BeatmapGroup selectedBeatmapGroup;
|
private BeatmapGroup selectedBeatmapGroup;
|
||||||
private BeatmapInfo selectedBeatmap;
|
|
||||||
// TODO: use currently selected track as bg
|
// TODO: use currently selected track as bg
|
||||||
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
||||||
private ScrollContainer scrollContainer;
|
private ScrollContainer scrollContainer;
|
||||||
@ -106,7 +105,7 @@ namespace osu.Game.GameModes.Play
|
|||||||
Width = 100,
|
Width = 100,
|
||||||
Text = "Play",
|
Text = "Play",
|
||||||
Colour = new Color4(238, 51, 153, 255),
|
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)
|
if (database == null)
|
||||||
database = (game as OsuGameBase).Beatmaps;
|
database = (game as OsuGameBase).Beatmaps;
|
||||||
|
|
||||||
database.BeatmapSetAdded += s => Scheduler.Add(() => addBeatmapSet(s));
|
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
|
||||||
|
|
||||||
Task.Factory.StartNew(addBeatmapSets);
|
Task.Factory.StartNew(addBeatmapSets);
|
||||||
}
|
}
|
||||||
@ -154,7 +153,6 @@ namespace osu.Game.GameModes.Play
|
|||||||
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
|
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
|
||||||
|
|
||||||
selectedBeatmapGroup = group;
|
selectedBeatmapGroup = group;
|
||||||
selectedBeatmap = beatmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||||
@ -167,9 +165,7 @@ namespace osu.Game.GameModes.Play
|
|||||||
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap };
|
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap };
|
||||||
setList.Add(group);
|
setList.Add(group);
|
||||||
if (setList.Children.Count() == 1)
|
if (setList.Children.Count() == 1)
|
||||||
{
|
|
||||||
group.State = BeatmapGroupState.Expanded;
|
group.State = BeatmapGroupState.Expanded;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||||
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
|
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
|
||||||
<Compile Include="Beatmaps\Drawable\DifficultyIcon.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\CatchConverter.cs" />
|
||||||
<Compile Include="Beatmaps\Objects\Catch\Drawable\DrawableFruit.cs" />
|
<Compile Include="Beatmaps\Objects\Catch\Drawable\DrawableFruit.cs" />
|
||||||
<Compile Include="Beatmaps\Objects\DrawableHitObject.cs" />
|
<Compile Include="Beatmaps\Objects\DrawableHitObject.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user