Allow PrivateChannelTab to derive from ChannelTab

This commit is contained in:
Dean Herbert
2018-09-06 16:21:31 +09:00
parent 93e2d8f309
commit 6a668ffe33
2 changed files with 138 additions and 241 deletions

View File

@ -20,7 +20,6 @@ namespace osu.Game.Overlays.Chat.Tabs
{ {
public class ChannelTabItem : TabItem<Channel> public class ChannelTabItem : TabItem<Channel>
{ {
protected Color4 BackgroundInactive; protected Color4 BackgroundInactive;
private Color4 backgroundHover; private Color4 backgroundHover;
protected Color4 BackgroundActive; protected Color4 BackgroundActive;
@ -29,81 +28,15 @@ namespace osu.Game.Overlays.Chat.Tabs
protected readonly SpriteText Text; protected readonly SpriteText Text;
protected readonly SpriteText TextBold; protected readonly SpriteText TextBold;
private readonly ClickableContainer closeButton; protected readonly ClickableContainer CloseButton;
private readonly Box box; private readonly Box box;
private readonly Box highlightBox; private readonly Box highlightBox;
protected readonly SpriteIcon Icon; protected readonly SpriteIcon Icon;
public Action<ChannelTabItem> OnRequestClose; public Action<ChannelTabItem> OnRequestClose;
private readonly Container content;
private void updateState() protected override Container<Drawable> Content => content;
{
if (Active)
fadeActive();
else
fadeInactive();
}
private const float transition_length = 400;
private void fadeActive()
{
this.ResizeTo(new Vector2(Width, 1.1f), transition_length, Easing.OutQuint);
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);
}
private void fadeInactive()
{
this.ResizeTo(new Vector2(Width, 1), transition_length, Easing.OutQuint);
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 bool OnHover(InputState state)
{
if (IsRemovable)
closeButton.FadeIn(200, Easing.OutQuint);
if (!Active)
box.FadeColour(backgroundHover, transition_length, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
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();
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
public ChannelTabItem(Channel value) public ChannelTabItem(Channel value)
: base(value) : base(value)
@ -118,14 +51,8 @@ namespace osu.Game.Overlays.Chat.Tabs
Shear = new Vector2(ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0); Shear = new Vector2(ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0);
Masking = true; Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 10,
Colour = Color4.Black.Opacity(0.2f),
};
Children = new Drawable[] InternalChildren = new Drawable[]
{ {
box = new Box box = new Box
{ {
@ -141,7 +68,7 @@ namespace osu.Game.Overlays.Chat.Tabs
EdgeSmoothness = new Vector2(1, 0), EdgeSmoothness = new Vector2(1, 0),
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
}, },
new Container content = new Container
{ {
Shear = new Vector2(-ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0), Shear = new Vector2(-ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -149,7 +76,7 @@ namespace osu.Game.Overlays.Chat.Tabs
{ {
Icon = new SpriteIcon Icon = new SpriteIcon
{ {
Icon = FontAwesome.fa_hashtag, Icon = DisplayIcon,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Colour = Color4.Black, Colour = Color4.Black,
@ -175,7 +102,7 @@ namespace osu.Game.Overlays.Chat.Tabs
Font = @"Exo2.0-Bold", Font = @"Exo2.0-Bold",
TextSize = 18, TextSize = 18,
}, },
closeButton = new TabCloseButton CloseButton = new TabCloseButton
{ {
Alpha = 0, Alpha = 0,
Margin = new MarginPadding { Right = 20 }, Margin = new MarginPadding { Right = 20 },
@ -190,5 +117,96 @@ namespace osu.Game.Overlays.Chat.Tabs
}, },
}; };
} }
protected virtual FontAwesome DisplayIcon => FontAwesome.fa_hashtag;
protected virtual bool ShowCloseOnHover => true;
protected override bool OnHover(InputState state)
{
if (IsRemovable && ShowCloseOnHover)
CloseButton.FadeIn(200, Easing.OutQuint);
if (!Active)
box.FadeColour(backgroundHover, TRANSITION_LENGTH, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
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();
} }
} }

View File

@ -7,29 +7,20 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Screens.Menu;
using osu.Game.Users; using osu.Game.Users;
using OpenTK; using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Overlays.Chat.Tabs namespace osu.Game.Overlays.Chat.Tabs
{ {
public class PrivateChannelTabItem : TabItem<Channel> public class PrivateChannelTabItem : ChannelTabItem
{ {
private static readonly Vector2 shear = new Vector2(1f / 5f, 0);
public override bool IsRemovable => true;
private readonly Box highlightBox;
private readonly Container backgroundContainer;
private readonly Box backgroundBox;
private readonly OsuSpriteText username; private readonly OsuSpriteText username;
private readonly Avatar avatarContainer; private readonly Avatar avatarContainer;
private readonly TabCloseButton closeButton;
protected override FontAwesome DisplayIcon => FontAwesome.fa_at;
public PrivateChannelTabItem(Channel value) public PrivateChannelTabItem(Channel value)
: base(value) : base(value)
@ -37,55 +28,7 @@ namespace osu.Game.Overlays.Chat.Tabs
if (value.Target != TargetType.User) if (value.Target != TargetType.User)
throw new ArgumentException("Argument value needs to have the targettype user!"); throw new ArgumentException("Argument value needs to have the targettype user!");
AutoSizeAxes = Axes.X; AddRange(new Drawable[]
Height = 50;
Origin = Anchor.BottomLeft;
Anchor = Anchor.BottomLeft;
EdgeEffect = activateEdgeEffect;
Masking = true;
Shear = shear;
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
backgroundBox = new Box
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
EdgeSmoothness = new Vector2(1, 0),
},
}
},
highlightBox = new Box
{
Width = 5,
BypassAutoSizeAxes = Axes.X,
Alpha = 0,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
EdgeSmoothness = new Vector2(1, 0),
RelativeSizeAxes = Axes.Y,
Colour = new OsuColour().Yellow
},
new Container
{
Masking = true,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Child = new FlowContainerWithOrigin
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
X = -5,
Direction = FillDirection.Horizontal,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Shear = -shear,
Children = new Drawable[]
{ {
new Container new Container
{ {
@ -93,118 +36,53 @@ namespace osu.Game.Overlays.Chat.Tabs
AutoSizeAxes = Axes.X, AutoSizeAxes = Axes.X,
Margin = new MarginPadding Margin = new MarginPadding
{ {
Horizontal = 5 Horizontal = 3
}, },
Origin = Anchor.BottomLeft, Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Children = new Drawable[] Children = new Drawable[]
{ {
new SpriteIcon
{
Icon = FontAwesome.fa_at,
Origin = Anchor.Centre,
Scale = new Vector2(1.2f),
X = -5,
Y = 5,
Anchor = Anchor.Centre,
Colour = new OsuColour().BlueDarker,
RelativeSizeAxes = Axes.Both,
},
new CircularContainer new CircularContainer
{ {
RelativeSizeAxes = Axes.Y,
Scale = new Vector2(0.95f), Scale = new Vector2(0.95f),
AutoSizeAxes = Axes.X, Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Masking = true, Masking = true,
Child = new DelayedLoadWrapper(new Avatar(value.JoinedUsers.First()) Child = new DelayedLoadWrapper(new Avatar(value.JoinedUsers.First())
{ {
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT), RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint), OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
}) })
{ {
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT), RelativeSizeAxes = Axes.Both,
} }
}, },
} }
}, },
username = new OsuSpriteText });
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = value.Name,
Margin = new MarginPadding(1),
TextSize = 18,
Alpha = 0,
},
closeButton = new TabCloseButton
{
Height = 1,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Alpha = 0,
Margin = new MarginPadding
{
Right = 5
},
RelativeSizeAxes = Axes.Y,
Action = delegate
{
if (IsRemovable) OnRequestClose?.Invoke(this);
},
},
}
}
}
};
username.ScaleTo(new Vector2(0, 1)); Text.X = ChatOverlay.TAB_AREA_HEIGHT;
closeButton.ScaleTo(new Vector2(0, 1)); TextBold.X = ChatOverlay.TAB_AREA_HEIGHT;
} }
public Action<PrivateChannelTabItem> OnRequestClose; protected override bool ShowCloseOnHover => false;
private readonly EdgeEffectParameters activateEdgeEffect = new EdgeEffectParameters protected override void FadeActive()
{ {
Type = EdgeEffectType.Shadow, base.FadeActive();
Radius = 15,
Colour = Color4.Black.Opacity(0.4f),
};
protected override void OnActivated() this.ResizeWidthTo(200, TRANSITION_LENGTH * 2, Easing.OutQuint);
{ CloseButton.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
const int activate_length = 1000;
backgroundBox.ResizeHeightTo(1.1f, activate_length, Easing.OutQuint);
highlightBox.ResizeHeightTo(1.1f, activate_length, Easing.OutQuint);
highlightBox.FadeIn(activate_length, Easing.OutQuint);
username.FadeIn(activate_length, Easing.OutQuint);
username.ScaleTo(new Vector2(1, 1), activate_length, Easing.OutQuint);
closeButton.ScaleTo(new Vector2(1, 1), activate_length, Easing.OutQuint);
closeButton.FadeIn(activate_length, Easing.OutQuint);
TweenEdgeEffectTo(activateEdgeEffect, activate_length);
} }
private readonly EdgeEffectParameters deactivateEdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 10,
Colour = Color4.Black.Opacity(0.2f),
};
protected override void OnDeactivated() protected override void FadeInactive()
{ {
const int deactivate_length = 500; base.FadeInactive();
backgroundBox.ResizeHeightTo(1, deactivate_length, Easing.OutQuint); this.ResizeWidthTo(ChatOverlay.TAB_AREA_HEIGHT + 10, TRANSITION_LENGTH, Easing.OutQuint);
highlightBox.ResizeHeightTo(1, deactivate_length, Easing.OutQuint); CloseButton.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
highlightBox.FadeOut(deactivate_length, Easing.OutQuint);
username.FadeOut(deactivate_length, Easing.OutQuint);
username.ScaleTo(new Vector2(0, 1), deactivate_length, Easing.OutQuint);
closeButton.FadeOut(deactivate_length, Easing.OutQuint);
closeButton.ScaleTo(new Vector2(0, 1), deactivate_length, Easing.OutQuint);
TweenEdgeEffectTo(deactivateEdgeEffect, deactivate_length);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -212,7 +90,8 @@ namespace osu.Game.Overlays.Chat.Tabs
{ {
var user = Value.JoinedUsers.First(); var user = Value.JoinedUsers.First();
backgroundBox.Colour = user.Colour != null ? OsuColour.FromHex(user.Colour) : colours.BlueDark; BackgroundActive = user.Colour != null ? OsuColour.FromHex(user.Colour) : colours.BlueDark;
BackgroundInactive = BackgroundActive.Darken(0.5f);
} }
} }
} }