2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using osu.Framework.Bindables;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-10-12 14:36:03 +08:00
|
|
|
|
using osu.Framework.Graphics.Pooling;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2020-10-13 16:57:38 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2020-10-12 14:36:03 +08:00
|
|
|
|
public abstract partial class DrawableCarouselItem : PoolableDrawable
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
2016-11-23 04:40:47 +08:00
|
|
|
|
public const float MAX_HEIGHT = 80;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
public override bool IsPresent => base.IsPresent || Item?.Visible == true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-03-09 15:06:39 +08:00
|
|
|
|
public override bool HandlePositionalInput => Item?.Visible == true;
|
|
|
|
|
public override bool PropagatePositionalInputSubTree => Item?.Visible == true;
|
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
public readonly CarouselHeader Header;
|
|
|
|
|
|
2020-10-13 14:32:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Optional content which sits below the header.
|
|
|
|
|
/// </summary>
|
2020-10-13 14:19:32 +08:00
|
|
|
|
protected readonly Container<Drawable> Content;
|
|
|
|
|
|
|
|
|
|
protected readonly Container MovementContainer;
|
|
|
|
|
|
2020-10-13 16:57:38 +08:00
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
|
|
|
|
Header.ReceivePositionalInputAt(screenSpacePos);
|
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
private CarouselItem item;
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
public CarouselItem Item
|
|
|
|
|
{
|
|
|
|
|
get => item;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (item == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
2020-10-13 14:19:32 +08:00
|
|
|
|
item.Filtered.ValueChanged -= onStateChange;
|
|
|
|
|
item.State.ValueChanged -= onStateChange;
|
|
|
|
|
|
|
|
|
|
Header.State.UnbindFrom(item.State);
|
2020-10-12 19:02:06 +08:00
|
|
|
|
|
|
|
|
|
if (item is CarouselGroup group)
|
|
|
|
|
{
|
2022-07-21 15:06:06 +08:00
|
|
|
|
foreach (var c in group.Items)
|
2020-10-12 19:02:06 +08:00
|
|
|
|
c.Filtered.ValueChanged -= onStateChange;
|
|
|
|
|
}
|
2020-10-12 14:36:03 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
item = value;
|
|
|
|
|
|
|
|
|
|
if (IsLoaded)
|
|
|
|
|
UpdateItem();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
protected DrawableCarouselItem()
|
2016-10-27 18:52:48 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2020-10-13 14:19:32 +08:00
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
Alpha = 0;
|
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2016-11-23 04:40:47 +08:00
|
|
|
|
{
|
2020-10-13 14:19:32 +08:00
|
|
|
|
MovementContainer = new Container
|
2017-11-26 03:16:36 +08:00
|
|
|
|
{
|
2020-10-13 15:33:37 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-10-13 14:19:32 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-11-26 03:16:36 +08:00
|
|
|
|
{
|
2022-02-05 15:12:58 +08:00
|
|
|
|
Header = new CarouselHeader(),
|
2020-10-13 14:19:32 +08:00
|
|
|
|
Content = new Container
|
|
|
|
|
{
|
2020-10-13 15:33:37 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-10-13 14:19:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-12-18 06:58:48 +08:00
|
|
|
|
};
|
2020-10-12 13:23:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
public void SetMultiplicativeAlpha(float alpha) => Header.BorderContainer.Alpha = alpha;
|
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-13 15:35:06 +08:00
|
|
|
|
UpdateItem();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
Content.Y = Header.Height;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
protected virtual void UpdateItem()
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-10-12 17:13:25 +08:00
|
|
|
|
Scheduler.AddOnce(ApplyState);
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
|
|
|
|
Item.Filtered.ValueChanged += onStateChange;
|
|
|
|
|
Item.State.ValueChanged += onStateChange;
|
2020-10-12 19:02:06 +08:00
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
Header.State.BindTo(Item.State);
|
|
|
|
|
|
2020-10-12 19:02:06 +08:00
|
|
|
|
if (Item is CarouselGroup group)
|
|
|
|
|
{
|
2022-07-21 15:06:06 +08:00
|
|
|
|
foreach (var c in group.Items)
|
2020-10-12 19:02:06 +08:00
|
|
|
|
c.Filtered.ValueChanged += onStateChange;
|
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-12 17:13:25 +08:00
|
|
|
|
private void onStateChange(ValueChangedEvent<CarouselItemState> obj) => Scheduler.AddOnce(ApplyState);
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
2020-10-12 17:13:25 +08:00
|
|
|
|
private void onStateChange(ValueChangedEvent<bool> _) => Scheduler.AddOnce(ApplyState);
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
|
protected virtual void ApplyState()
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2022-02-05 15:12:58 +08:00
|
|
|
|
// Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead.
|
|
|
|
|
// Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away.
|
|
|
|
|
Height = Item.TotalHeight;
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
Debug.Assert(Item != null);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
switch (Item.State.Value)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2022-02-05 15:12:58 +08:00
|
|
|
|
case CarouselItemState.NotSelected:
|
|
|
|
|
Deselected();
|
|
|
|
|
break;
|
2022-01-30 12:01:41 +08:00
|
|
|
|
|
2022-02-05 15:12:58 +08:00
|
|
|
|
case CarouselItemState.Selected:
|
|
|
|
|
Selected();
|
|
|
|
|
break;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
|
if (!Item.Visible)
|
2022-02-05 15:12:58 +08:00
|
|
|
|
this.FadeOut(300, Easing.OutQuint);
|
2017-02-02 16:33:39 +08:00
|
|
|
|
else
|
2022-02-05 15:12:58 +08:00
|
|
|
|
this.FadeIn(250);
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
|
protected virtual void Selected()
|
|
|
|
|
{
|
2020-10-12 14:36:03 +08:00
|
|
|
|
Debug.Assert(Item != null);
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
|
protected virtual void Deselected()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2016-11-02 05:57:11 +08:00
|
|
|
|
{
|
2017-12-12 16:48:38 +08:00
|
|
|
|
Item.State.Value = CarouselItemState.Selected;
|
2016-11-02 05:57:11 +08:00
|
|
|
|
return true;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|