1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Use IStateful and improve collapse logic

This commit is contained in:
Drew DeVault 2016-10-26 12:49:16 -04:00
parent 55e5ec6fae
commit 9c27c33e18
2 changed files with 34 additions and 46 deletions

View File

@ -17,11 +17,18 @@ using OpenTK.Graphics;
using osu.Game.Beatmaps.IO;
using osu.Framework.Graphics.Textures;
using System.Threading.Tasks;
using osu.Framework;
namespace osu.Game.GameModes.Play
{
class BeatmapGroup : Container
class BeatmapGroup : Container, IStateful<BeatmapGroup.GroupState>
{
public enum GroupState
{
Collapsed,
Expanded,
}
private const float collapsedAlpha = 0.5f;
private const float collapsedWidth = 0.8f;
@ -35,21 +42,20 @@ namespace osu.Game.GameModes.Play
}
}
public Action<BeatmapSetInfo> SetSelected;
public Action<BeatmapSetInfo, BeatmapInfo> BeatmapSelected;
public Action<BeatmapGroup, BeatmapInfo> BeatmapSelected;
public BeatmapSetInfo BeatmapSet;
private BeatmapSetBox setBox;
private FlowContainer topContainer;
private BeatmapSetHeader setBox;
private FlowContainer difficulties;
private bool collapsed;
public bool Collapsed
public GroupState State
{
get { return collapsed; }
get { return collapsed ? GroupState.Collapsed : GroupState.Expanded; }
set
{
if (collapsed == value)
bool val = value == GroupState.Collapsed;
if (collapsed == val)
return;
collapsed = value;
collapsed = val;
ClearTransformations();
const float uncollapsedAlpha = 1;
FadeTo(collapsed ? collapsedAlpha : uncollapsedAlpha, 250);
@ -78,14 +84,14 @@ namespace osu.Game.GameModes.Play
float difficultyWidth = 1;
Children = new[]
{
topContainer = new FlowContainer
new FlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
Children = new Drawable[]
{
setBox = new BeatmapSetBox(beatmapSet)
setBox = new BeatmapSetHeader(beatmapSet)
{
RelativeSizeAxes = Axes.X,
Width = collapsedWidth,
@ -127,19 +133,19 @@ namespace osu.Game.GameModes.Play
{
foreach (BeatmapPanel panel in difficulties.Children)
panel.Selected = panel.Beatmap == map;
BeatmapSelected?.Invoke(BeatmapSet, map);
BeatmapSelected?.Invoke(this, map);
}
protected override bool OnClick(InputState state)
{
SetSelected?.Invoke(BeatmapSet);
BeatmapSelected?.Invoke(this, selectedBeatmap);
return true;
}
}
class BeatmapSetBox : Container
class BeatmapSetHeader : Container
{
public BeatmapSetBox(BeatmapSetInfo beatmapSet)
public BeatmapSetHeader(BeatmapSetInfo beatmapSet)
{
AutoSizeAxes = Axes.Y;
Masking = true;

View File

@ -2,13 +2,10 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.IO;
using osu.Game.GameModes.Backgrounds;
using osu.Framework;
using osu.Game.Database;
@ -16,10 +13,8 @@ using osu.Framework.Graphics.Primitives;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface;
using System.Threading.Tasks;
using System.Diagnostics;
namespace osu.Game.GameModes.Play
{
@ -27,7 +22,7 @@ namespace osu.Game.GameModes.Play
{
private Bindable<PlayMode> playMode;
private BeatmapDatabase beatmaps;
private BeatmapSetInfo selectedBeatmapSet;
private BeatmapGroup selectedBeatmapGroup;
private BeatmapInfo selectedBeatmap;
// TODO: use currently selected track as bg
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
@ -141,29 +136,20 @@ namespace osu.Game.GameModes.Play
{
}
private void selectBeatmapSet(BeatmapSetInfo beatmapSet)
private void selectBeatmapSet(BeatmapGroup group)
{
if (selectedBeatmapSet == beatmapSet)
if (selectedBeatmapGroup == group)
return;
selectedBeatmapSet = beatmapSet;
foreach (var child in setList.Children)
{
var childGroup = child as BeatmapGroup;
if (childGroup.BeatmapSet == beatmapSet)
{
childGroup.Collapsed = false;
selectedBeatmap = childGroup.SelectedBeatmap;
}
else
childGroup.Collapsed = true;
}
selectedBeatmapGroup.State = BeatmapGroup.GroupState.Collapsed;
selectedBeatmapGroup = group;
selectedBeatmapGroup.State = BeatmapGroup.GroupState.Expanded;
}
private void selectBeatmap(BeatmapSetInfo set, BeatmapInfo beatmap)
private void selectBeatmap(BeatmapGroup group, BeatmapInfo beatmap)
{
if (selectedBeatmap == beatmap)
return;
selectBeatmapSet(set);
selectBeatmapSet(group);
selectedBeatmap = beatmap;
}
@ -173,19 +159,15 @@ namespace osu.Game.GameModes.Play
beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b));
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty)
.ToList();
Scheduler.Add(() =>
Schedule(() =>
{
var group = new BeatmapGroup(beatmapSet)
{
SetSelected = selectBeatmapSet,
BeatmapSelected = selectBeatmap,
};
var group = new BeatmapGroup(beatmapSet) { BeatmapSelected = selectBeatmap };
setList.Add(group);
if (setList.Children.Count() == 1)
{
selectedBeatmapSet = group.BeatmapSet;
selectedBeatmapGroup = group;
selectedBeatmap = group.SelectedBeatmap;
group.Collapsed = false;
group.State = BeatmapGroup.GroupState.Expanded;
}
});
}