2017-12-12 16:48:38 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A group which ensures only one child is selected.
|
|
|
|
/// </summary>
|
|
|
|
public class CarouselGroup : CarouselItem
|
|
|
|
{
|
|
|
|
private readonly List<CarouselItem> items;
|
|
|
|
|
|
|
|
protected override DrawableCarouselItem CreateDrawableRepresentation() => null;
|
|
|
|
|
2017-12-14 19:40:58 +08:00
|
|
|
public override void AddChild(CarouselItem i)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
2017-12-16 15:14:37 +08:00
|
|
|
i.State.ValueChanged += v => ChildItemStateChanged(i, v);
|
2017-12-14 19:40:58 +08:00
|
|
|
base.AddChild(i);
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public CarouselGroup(List<CarouselItem> items = null)
|
|
|
|
{
|
2017-12-14 19:40:58 +08:00
|
|
|
if (items != null) InternalChildren = items;
|
2017-12-12 16:48:38 +08:00
|
|
|
}
|
|
|
|
|
2017-12-16 15:14:37 +08:00
|
|
|
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
|
|
|
// todo: check state of selected item.
|
|
|
|
|
|
|
|
// ensure we are the only item selected
|
|
|
|
if (value == CarouselItemState.Selected)
|
|
|
|
{
|
2017-12-14 19:40:58 +08:00
|
|
|
foreach (var b in InternalChildren)
|
2017-12-12 16:48:38 +08:00
|
|
|
{
|
|
|
|
if (item == b) continue;
|
|
|
|
b.State.Value = CarouselItemState.NotSelected;
|
|
|
|
}
|
|
|
|
|
|
|
|
State.Value = CarouselItemState.Selected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|