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-07-10 01:42:57 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-10 01:42:57 +08:00
|
|
|
|
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;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2019-07-24 23:17:29 +08:00
|
|
|
|
using osuTK.Input;
|
2018-07-10 01:42:57 +08: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;
|
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(),
|
2019-07-28 18:40:21 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 18),
|
2019-07-28 18:16:32 +08:00
|
|
|
|
Width = 115f,
|
|
|
|
|
Truncate = true,
|
2018-07-10 01:42:57 +08:00
|
|
|
|
},
|
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
|
|
|
|
|
2019-04-02 18:55:24 +08:00
|
|
|
|
protected virtual IconUsage DisplayIcon => FontAwesome.Solid.Hashtag;
|
2018-09-06 15:21:31 +08:00
|
|
|
|
|
|
|
|
|
protected virtual bool ShowCloseOnHover => true;
|
|
|
|
|
|
2019-07-28 18:40:21 +08:00
|
|
|
|
protected virtual bool IsBoldWhenActive => 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);
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
if (!Active.Value)
|
2018-09-06 15:21:31 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-24 23:17:29 +08:00
|
|
|
|
protected override bool OnMouseUp(MouseUpEvent e)
|
|
|
|
|
{
|
2019-07-26 12:17:21 +08:00
|
|
|
|
switch (e.Button)
|
2019-07-24 23:17:29 +08:00
|
|
|
|
{
|
2019-07-26 12:17:21 +08:00
|
|
|
|
case MouseButton.Middle:
|
|
|
|
|
CloseButton.Click();
|
|
|
|
|
return true;
|
2019-07-24 23:17:29 +08:00
|
|
|
|
|
2019-07-26 12:17:21 +08:00
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-07-24 23:17:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 15:21:31 +08:00
|
|
|
|
[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 17:56:34 +08:00
|
|
|
|
if (Active.Value)
|
2018-09-06 15:21:31 +08: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);
|
|
|
|
|
|
2019-07-28 18:40:21 +08:00
|
|
|
|
if (IsBoldWhenActive)
|
|
|
|
|
{
|
|
|
|
|
Text.Font = Text.Font.With(weight: FontWeight.Bold);
|
|
|
|
|
}
|
2018-09-06 15:21:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2019-07-28 18:40:21 +08:00
|
|
|
|
Text.Font = Text.Font.With(weight: FontWeight.Medium);
|
2018-09-06 15:21:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2018-07-10 01:42:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|