1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 19:42:57 +08:00
osu-lazer/osu.Game/Overlays/OverlayStreamItem.cs

141 lines
4.4 KiB
C#
Raw Normal View History

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