2019-01-24 08:43:03 +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-09 17:42:57 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-11-12 11:41:10 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online.Chat;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Chat.Tabs
|
|
|
|
|
{
|
|
|
|
|
public class ChannelTabItem : TabItem<Channel>
|
|
|
|
|
{
|
|
|
|
|
protected Color4 BackgroundInactive;
|
|
|
|
|
private Color4 backgroundHover;
|
|
|
|
|
protected Color4 BackgroundActive;
|
|
|
|
|
|
|
|
|
|
public override bool IsRemovable => !Pinned;
|
|
|
|
|
|
|
|
|
|
protected readonly SpriteText Text;
|
|
|
|
|
protected readonly SpriteText TextBold;
|
2018-09-06 07:21:31 +00:00
|
|
|
|
protected readonly ClickableContainer CloseButton;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly Box highlightBox;
|
|
|
|
|
protected readonly SpriteIcon Icon;
|
|
|
|
|
|
|
|
|
|
public Action<ChannelTabItem> OnRequestClose;
|
2018-09-06 07:21:31 +00:00
|
|
|
|
private readonly Container content;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
|
2018-09-06 07:21:31 +00:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
|
|
|
|
|
public ChannelTabItem(Channel value)
|
|
|
|
|
: base(value)
|
|
|
|
|
{
|
|
|
|
|
Width = 150;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
|
|
|
|
|
2018-07-09 20:59:29 +00:00
|
|
|
|
Shear = new Vector2(ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0);
|
2018-07-09 17:42:57 +00:00
|
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
|
|
2018-09-06 07:21:31 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-07-09 17:42:57 +00:00
|
|
|
|
{
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
EdgeSmoothness = new Vector2(1, 0),
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
highlightBox = new Box
|
|
|
|
|
{
|
|
|
|
|
Width = 5,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
EdgeSmoothness = new Vector2(1, 0),
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
2018-09-06 07:21:31 +00:00
|
|
|
|
content = new Container
|
2018-07-09 17:42:57 +00:00
|
|
|
|
{
|
2018-07-09 20:59:29 +00:00
|
|
|
|
Shear = new Vector2(-ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0),
|
2018-07-09 17:42:57 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
Icon = new SpriteIcon
|
|
|
|
|
{
|
2018-09-06 07:21:31 +00:00
|
|
|
|
Icon = DisplayIcon,
|
2018-07-09 17:42:57 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
X = -10,
|
|
|
|
|
Alpha = 0.2f,
|
|
|
|
|
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
|
|
|
|
|
},
|
|
|
|
|
Text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Text = value.ToString(),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 18)
|
2018-07-09 17:42:57 +00:00
|
|
|
|
},
|
|
|
|
|
TextBold = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Text = value.ToString(),
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 18, weight: FontWeight.Bold)
|
2018-07-09 17:42:57 +00:00
|
|
|
|
},
|
2018-09-06 07:21:31 +00:00
|
|
|
|
CloseButton = new TabCloseButton
|
2018-07-09 17:42:57 +00:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding { Right = 20 },
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
if (IsRemovable) OnRequestClose?.Invoke(this);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-09-06 07:21:31 +00:00
|
|
|
|
|
2019-04-02 10:55:24 +00:00
|
|
|
|
protected virtual IconUsage DisplayIcon => FontAwesome.Solid.Hashtag;
|
2018-09-06 07:21:31 +00:00
|
|
|
|
|
|
|
|
|
protected virtual bool ShowCloseOnHover => true;
|
|
|
|
|
|
2018-11-12 11:41:10 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-09-06 07:21:31 +00:00
|
|
|
|
{
|
|
|
|
|
if (IsRemovable && ShowCloseOnHover)
|
|
|
|
|
CloseButton.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (!Active.Value)
|
2018-09-06 07:21:31 +00:00
|
|
|
|
box.FadeColour(backgroundHover, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 11:41:10 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-09-06 07:21:31 +00:00
|
|
|
|
{
|
|
|
|
|
CloseButton.FadeOut(200, Easing.OutQuint);
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
BackgroundActive = colours.ChatBlue;
|
|
|
|
|
BackgroundInactive = colours.Gray4;
|
|
|
|
|
backgroundHover = colours.Gray7;
|
|
|
|
|
|
|
|
|
|
highlightBox.Colour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
updateState();
|
|
|
|
|
FinishTransforms(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (Active.Value)
|
2018-09-06 07:21:31 +00:00
|
|
|
|
FadeActive();
|
|
|
|
|
else
|
|
|
|
|
FadeInactive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected const float TRANSITION_LENGTH = 400;
|
|
|
|
|
|
|
|
|
|
private readonly EdgeEffectParameters activateEdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Radius = 15,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.4f),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private readonly EdgeEffectParameters deactivateEdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Radius = 10,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected virtual void FadeActive()
|
|
|
|
|
{
|
|
|
|
|
this.ResizeHeightTo(1.1f, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
TweenEdgeEffectTo(activateEdgeEffect, TRANSITION_LENGTH);
|
|
|
|
|
|
|
|
|
|
box.FadeColour(BackgroundActive, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
highlightBox.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
Text.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
TextBold.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void FadeInactive()
|
|
|
|
|
{
|
|
|
|
|
this.ResizeHeightTo(1, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
TweenEdgeEffectTo(deactivateEdgeEffect, TRANSITION_LENGTH);
|
|
|
|
|
|
|
|
|
|
box.FadeColour(BackgroundInactive, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
highlightBox.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
Text.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
TextBold.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2018-07-09 17:42:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|