mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:47:29 +08:00
Add beatmap difficulty selection logic
This commit is contained in:
parent
941687e091
commit
4dcdc8638e
@ -7,6 +7,7 @@ using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.GameModes.Backgrounds;
|
||||
using osu.Framework;
|
||||
@ -23,6 +24,8 @@ namespace osu.Game.GameModes.Play
|
||||
private BeatmapSetInfo beatmapSet;
|
||||
private BeatmapInfo beatmap;
|
||||
|
||||
public Action<BeatmapInfo> Selected;
|
||||
|
||||
public BeatmapButton(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||
{
|
||||
this.beatmapSet = set;
|
||||
@ -33,7 +36,7 @@ namespace osu.Game.GameModes.Play
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = new Color4(40, 86, 102, 255), // TODO: texture
|
||||
Colour = new Color4(40, 86, 102, 255), // TODO: gradient
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = new Vector2(1),
|
||||
},
|
||||
@ -66,5 +69,11 @@ namespace osu.Game.GameModes.Play
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
Selected?.Invoke(beatmap);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,16 @@ namespace osu.Game.GameModes.Play
|
||||
class BeatmapGroup : AutoSizeContainer
|
||||
{
|
||||
private const float collapsedAlpha = 0.5f;
|
||||
|
||||
private BeatmapInfo selectedBeatmap;
|
||||
public BeatmapInfo SelectedBeatmap
|
||||
{
|
||||
get { return selectedBeatmap; }
|
||||
set
|
||||
{
|
||||
selectedBeatmap = value;
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<BeatmapSetInfo> SetSelected;
|
||||
public event Action<BeatmapSetInfo, BeatmapInfo> BeatmapSelected;
|
||||
@ -84,7 +94,8 @@ namespace osu.Game.GameModes.Play
|
||||
Padding = new MarginPadding { Left = 25 },
|
||||
Spacing = new Vector2(0, 5),
|
||||
Direction = FlowDirection.VerticalOnly,
|
||||
Children = this.BeatmapSet.Beatmaps.Select(b => new BeatmapButton(this.BeatmapSet, b))
|
||||
Children = this.BeatmapSet.Beatmaps.Select(
|
||||
b => new BeatmapButton(this.BeatmapSet, b) { Selected = beatmap => BeatmapSelected?.Invoke(beatmapSet, beatmap) })
|
||||
};
|
||||
collapsed = true;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
@ -25,6 +26,7 @@ namespace osu.Game.GameModes.Play
|
||||
private Bindable<PlayMode> playMode;
|
||||
private BeatmapDatabase beatmaps;
|
||||
private BeatmapSetInfo selectedBeatmapSet;
|
||||
private BeatmapInfo selectedBeatmap;
|
||||
private BeatmapResourceStore beatmapResources;
|
||||
private TextureStore beatmapTextureResources;
|
||||
|
||||
@ -40,15 +42,28 @@ namespace osu.Game.GameModes.Play
|
||||
foreach (var child in setList.Children)
|
||||
{
|
||||
var childGroup = child as BeatmapGroup;
|
||||
childGroup.Collapsed = childGroup.BeatmapSet != beatmapSet;
|
||||
if (childGroup.BeatmapSet == beatmapSet)
|
||||
{
|
||||
childGroup.Collapsed = false;
|
||||
selectedBeatmap = childGroup.SelectedBeatmap;
|
||||
}
|
||||
else
|
||||
childGroup.Collapsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void selectBeatmap(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||
{
|
||||
selectBeatmapSet(set);
|
||||
selectedBeatmap = beatmap;
|
||||
}
|
||||
|
||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||
var group = new BeatmapGroup(beatmapSet, beatmapResources, beatmapTextureResources);
|
||||
group.SetSelected += (selectedSet) => selectBeatmapSet(selectedSet);
|
||||
group.SetSelected += selectBeatmapSet;
|
||||
group.BeatmapSelected += selectBeatmap;
|
||||
setList.Add(group);
|
||||
}
|
||||
|
||||
@ -105,6 +120,15 @@ namespace osu.Game.GameModes.Play
|
||||
Spacing = new Vector2(0, 25),
|
||||
}
|
||||
}
|
||||
},
|
||||
new Button
|
||||
{
|
||||
Text = "Play",
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
Action = () =>
|
||||
{
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user