2018-07-10 01:42:57 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-11-12 19:41:10 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-07-10 01:42:57 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
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 15:21:31 +08:00
|
|
|
|
protected readonly ClickableContainer CloseButton;
|
2018-07-10 01:42:57 +08:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly Box highlightBox;
|
|
|
|
|
protected readonly SpriteIcon Icon;
|
|
|
|
|
|
|
|
|
|
public Action<ChannelTabItem> OnRequestClose;
|
2018-09-06 15:21:31 +08:00
|
|
|
|
private readonly Container content;
|
2018-07-10 01:42:57 +08:00
|
|
|
|
|
2018-09-06 15:21:31 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
2018-07-10 01:42:57 +08:00
|
|
|
|
|
|
|
|
|
public ChannelTabItem(Channel value)
|
|
|
|
|
: base(value)
|
|
|
|
|
{
|
|
|
|
|
Width = 150;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
|
|
|
|
|
2018-07-10 04:59:29 +08:00
|
|
|
|
Shear = new Vector2(ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0);
|
2018-07-10 01:42:57 +08:00
|
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
|
|
2018-09-06 15:21:31 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-07-10 01:42:57 +08: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 15:21:31 +08:00
|
|
|
|
content = new Container
|
2018-07-10 01:42:57 +08:00
|
|
|
|
{
|
2018-07-10 04:59:29 +08:00
|
|
|
|
Shear = new Vector2(-ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0),
|
2018-07-10 01:42:57 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
Icon = new SpriteIcon
|
|
|
|
|
{
|
2018-09-06 15:21:31 +08:00
|
|
|
|
Icon = DisplayIcon,
|
2018-07-10 01:42:57 +08: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(),
|
|
|
|
|
TextSize = 18,
|
|
|
|
|
},
|
|
|
|
|
TextBold = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding(5),
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Text = value.ToString(),
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
TextSize = 18,
|
|
|
|
|
},
|
2018-09-06 15:21:31 +08:00
|
|
|
|
CloseButton = new TabCloseButton
|
2018-07-10 01:42:57 +08:00
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Margin = new MarginPadding { Right = 20 },
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Action = delegate
|
|
|
|
|
{
|
|
|
|
|
if (IsRemovable) OnRequestClose?.Invoke(this);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-09-06 15:21:31 +08:00
|
|
|
|
|
|
|
|
|
protected virtual FontAwesome DisplayIcon => FontAwesome.fa_hashtag;
|
|
|
|
|
|
|
|
|
|
protected virtual bool ShowCloseOnHover => true;
|
|
|
|
|
|
2018-11-12 19:41:10 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-09-06 15:21:31 +08:00
|
|
|
|
{
|
|
|
|
|
if (IsRemovable && ShowCloseOnHover)
|
|
|
|
|
CloseButton.FadeIn(200, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (!Active)
|
|
|
|
|
box.FadeColour(backgroundHover, TRANSITION_LENGTH, Easing.OutQuint);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 19:41:10 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-09-06 15:21:31 +08: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()
|
|
|
|
|
{
|
|
|
|
|
if (Active)
|
|
|
|
|
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-10 01:42:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|