2019-05-13 08:14:52 +00: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-07-17 23:35:06 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-07-17 23:35:06 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-10-18 18:56:43 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-05-22 10:51:16 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-03-03 14:01:58 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-05-22 07:33:50 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2020-03-03 14:01:58 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osuTK.Graphics;
|
2021-06-30 19:16:21 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-07-17 23:35:06 +00:00
|
|
|
|
|
2020-03-03 14:01:58 +00:00
|
|
|
|
namespace osu.Game.Overlays
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-03-04 20:08:58 +00:00
|
|
|
|
public abstract class OverlayStreamItem<T> : TabItem<T>
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-03-03 14:01:58 +00:00
|
|
|
|
public readonly Bindable<T> SelectedItem = new Bindable<T>();
|
2018-07-17 23:35:06 +00:00
|
|
|
|
|
2020-03-03 14:01:58 +00:00
|
|
|
|
private bool userHoveringArea;
|
2019-05-22 14:44:37 +00:00
|
|
|
|
|
2020-03-03 14:01:58 +00:00
|
|
|
|
public bool UserHoveringArea
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == userHoveringArea)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
userHoveringArea = value;
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-21 15:12:23 +00:00
|
|
|
|
|
|
|
|
|
private FillFlowContainer<SpriteText> text;
|
|
|
|
|
private ExpandingBar expandingBar;
|
2019-05-22 14:44:37 +00:00
|
|
|
|
|
2020-03-04 20:08:58 +00:00
|
|
|
|
protected OverlayStreamItem(T value)
|
2020-03-03 14:01:58 +00:00
|
|
|
|
: base(value)
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2021-06-21 20:42:15 +00:00
|
|
|
|
Height = 50;
|
|
|
|
|
Width = 90;
|
|
|
|
|
Margin = new MarginPadding(5);
|
2020-02-21 15:12:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-03-03 21:28:47 +00:00
|
|
|
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
2020-02-21 15:12:23 +00:00
|
|
|
|
{
|
|
|
|
|
AddRange(new Drawable[]
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-02-27 12:33:01 +00:00
|
|
|
|
text = new FillFlowContainer<SpriteText>
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-02-27 12:33:01 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Margin = new MarginPadding { Top = 6 },
|
|
|
|
|
Children = new[]
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-02-27 12:33:01 +00:00
|
|
|
|
new OsuSpriteText
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-03-04 20:06:16 +00:00
|
|
|
|
Text = MainText,
|
2020-03-16 23:32:25 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
|
2020-02-21 15:12:23 +00:00
|
|
|
|
},
|
2020-02-27 12:33:01 +00:00
|
|
|
|
new OsuSpriteText
|
2020-02-21 15:12:23 +00:00
|
|
|
|
{
|
2020-03-04 20:06:16 +00:00
|
|
|
|
Text = AdditionalText,
|
2020-02-27 12:33:01 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2020-03-04 20:06:16 +00:00
|
|
|
|
Text = InfoText,
|
2020-02-27 12:33:01 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 10),
|
|
|
|
|
Colour = colourProvider.Foreground1
|
2020-02-21 15:12:23 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-02-27 12:33:01 +00:00
|
|
|
|
expandingBar = new ExpandingBar
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2020-03-03 21:28:47 +00:00
|
|
|
|
Colour = GetBarColour(colours),
|
2020-02-27 12:33:01 +00:00
|
|
|
|
ExpandedSize = 4,
|
|
|
|
|
CollapsedSize = 2,
|
2020-03-02 11:16:58 +00:00
|
|
|
|
Expanded = true
|
2020-02-27 12:33:01 +00:00
|
|
|
|
},
|
2020-02-21 15:12:23 +00:00
|
|
|
|
new HoverClickSounds()
|
|
|
|
|
});
|
2018-07-17 23:35:06 +00:00
|
|
|
|
|
2020-03-03 14:01:58 +00:00
|
|
|
|
SelectedItem.BindValueChanged(_ => updateState(), true);
|
2018-07-17 23:35:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 19:16:21 +00:00
|
|
|
|
protected abstract LocalisableString MainText { get; }
|
2020-03-03 14:01:58 +00:00
|
|
|
|
|
2021-06-30 19:16:21 +00:00
|
|
|
|
protected abstract LocalisableString AdditionalText { get; }
|
2020-03-03 14:01:58 +00:00
|
|
|
|
|
2021-06-30 19:16:21 +00:00
|
|
|
|
protected virtual LocalisableString InfoText => string.Empty;
|
2020-03-03 14:01:58 +00:00
|
|
|
|
|
2020-03-03 21:28:47 +00:00
|
|
|
|
protected abstract Color4 GetBarColour(OsuColour colours);
|
2020-03-03 14:01:58 +00:00
|
|
|
|
|
2019-05-22 14:44:37 +00:00
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2018-07-17 23:35:06 +00:00
|
|
|
|
|
2018-10-18 18:56:43 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2019-05-22 14:44:37 +00:00
|
|
|
|
updateState();
|
2018-10-18 18:56:43 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-07-17 23:35:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 18:56:43 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2019-05-22 14:44:37 +00:00
|
|
|
|
updateState();
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
// highlighted regardless if we are hovered
|
|
|
|
|
bool textHighlighted = IsHovered;
|
|
|
|
|
bool barExpanded = IsHovered;
|
|
|
|
|
|
2020-03-03 14:01:58 +00:00
|
|
|
|
if (SelectedItem.Value == null)
|
2018-07-17 23:35:06 +00:00
|
|
|
|
{
|
2020-03-02 11:16:58 +00:00
|
|
|
|
// at listing, all badges are highlighted when user is not hovering any badge.
|
|
|
|
|
textHighlighted |= !userHoveringArea;
|
|
|
|
|
barExpanded |= !userHoveringArea;
|
2018-07-17 23:35:06 +00:00
|
|
|
|
}
|
2020-03-02 11:16:58 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// bar is always expanded when active
|
|
|
|
|
barExpanded |= Active.Value;
|
2019-05-12 15:36:05 +00:00
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
// text is highlighted only when hovered or active (but not if in selection mode)
|
|
|
|
|
textHighlighted |= Active.Value && !userHoveringArea;
|
|
|
|
|
}
|
2020-02-28 09:48:06 +00:00
|
|
|
|
|
2020-03-02 11:16:58 +00:00
|
|
|
|
expandingBar.Expanded = barExpanded;
|
2020-03-03 21:35:32 +00:00
|
|
|
|
text.FadeTo(textHighlighted ? 1 : 0.5f, 100, Easing.OutQuint);
|
2018-07-17 23:35:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|