osu/osu.Game/Overlays/Chat/ChatTabControl.cs

243 lines
8.5 KiB
C#
Raw Normal View History

2017-05-12 06:32:52 +00:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Configuration;
2017-05-12 06:32:52 +00:00
namespace osu.Game.Overlays.Chat
{
public class ChatTabControl : OsuTabControl<Channel>
{
protected override TabItem<Channel> CreateTabItem(Channel value) => new ChannelTabItem(value);
2017-05-12 06:32:52 +00:00
private const float shear_width = 10;
2017-05-26 10:10:16 +00:00
public readonly Bindable<bool> ChannelSelectorActive = new Bindable<bool>();
2017-05-12 06:32:52 +00:00
public ChatTabControl()
{
TabContainer.Margin = new MarginPadding { Left = 50 };
TabContainer.Spacing = new Vector2(-shear_width, 0);
TabContainer.Masking = false;
AddInternal(new TextAwesome
{
Icon = FontAwesome.fa_comments,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
TextSize = 20,
Padding = new MarginPadding(10),
});
2017-05-17 19:16:53 +00:00
2017-05-26 10:10:16 +00:00
AddTabItem(new ChannelTabItem.ChannelSelectorTabItem(new Channel { Name = "+" }, ChannelSelectorActive));
2017-05-12 06:32:52 +00:00
}
private class ChannelTabItem : TabItem<Channel>
{
private Color4 backgroundInactive;
private Color4 backgroundHover;
private Color4 backgroundActive;
private readonly SpriteText text;
2017-05-16 08:37:54 +00:00
private readonly SpriteText textBold;
2017-05-12 06:32:52 +00:00
private readonly Box box;
private readonly Box highlightBox;
2017-05-17 19:16:53 +00:00
private readonly TextAwesome icon;
2017-05-12 06:32:52 +00:00
public override bool Active
{
get { return base.Active; }
set
{
if (Active == value) return;
base.Active = value;
updateState();
}
}
private void updateState()
{
if (Active)
fadeActive();
else
fadeInactive();
}
private const float transition_length = 400;
private void fadeActive()
{
ResizeTo(new Vector2(Width, 1.1f), transition_length, EasingTypes.OutQuint);
box.FadeColour(backgroundActive, transition_length, EasingTypes.OutQuint);
highlightBox.FadeIn(transition_length, EasingTypes.OutQuint);
2017-05-16 08:37:54 +00:00
text.FadeOut(transition_length, EasingTypes.OutQuint);
textBold.FadeIn(transition_length, EasingTypes.OutQuint);
2017-05-12 06:32:52 +00:00
}
private void fadeInactive()
{
ResizeTo(new Vector2(Width, 1), transition_length, EasingTypes.OutQuint);
box.FadeColour(backgroundInactive, transition_length, EasingTypes.OutQuint);
highlightBox.FadeOut(transition_length, EasingTypes.OutQuint);
2017-05-16 08:37:54 +00:00
text.FadeIn(transition_length, EasingTypes.OutQuint);
textBold.FadeOut(transition_length, EasingTypes.OutQuint);
2017-05-12 06:32:52 +00:00
}
protected override bool OnHover(InputState state)
{
if (!Active)
box.FadeColour(backgroundHover, transition_length, EasingTypes.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
updateState();
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
backgroundActive = colours.ChatBlue;
backgroundInactive = colours.Gray4;
backgroundHover = colours.Gray7;
highlightBox.Colour = colours.Yellow;
2017-05-26 10:10:16 +00:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2017-05-12 06:32:52 +00:00
updateState();
}
public ChannelTabItem(Channel value) : base(value)
{
Width = 150;
RelativeSizeAxes = Axes.Y;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
Shear = new Vector2(shear_width / ChatOverlay.TAB_AREA_HEIGHT, 0);
Masking = true;
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Radius = 10,
Colour = Color4.Black.Opacity(0.2f),
};
Children = new Drawable[]
{
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,
},
new Container
{
Shear = new Vector2(-shear_width / ChatOverlay.TAB_AREA_HEIGHT, 0),
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
2017-05-17 19:16:53 +00:00
icon = new TextAwesome
2017-05-12 06:32:52 +00:00
{
Icon = FontAwesome.fa_hashtag,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = Color4.Black,
X = -10,
Alpha = 0.2f,
TextSize = ChatOverlay.TAB_AREA_HEIGHT,
},
text = new OsuSpriteText
{
Margin = new MarginPadding(5),
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = value.ToString(),
TextSize = 18,
},
2017-05-16 08:37:54 +00:00
textBold = new OsuSpriteText
{
Alpha = 0,
Margin = new MarginPadding(5),
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = value.ToString(),
Font = @"Exo2.0-Bold",
TextSize = 18,
},
2017-05-12 06:32:52 +00:00
}
}
};
}
2017-05-17 19:16:53 +00:00
public class ChannelSelectorTabItem : ChannelTabItem
{
public override bool Active
{
get { return base.Active; }
set
{
activeBindable.Value = value;
base.Active = value;
}
}
2017-05-23 16:19:01 +00:00
private readonly Bindable<bool> activeBindable;
public ChannelSelectorTabItem(Channel value, Bindable<bool> active) : base(value)
2017-05-17 19:16:53 +00:00
{
activeBindable = active;
2017-05-17 19:16:53 +00:00
Depth = float.MaxValue;
2017-05-25 18:25:59 +00:00
Width = 45;
2017-05-17 19:16:53 +00:00
2017-05-25 18:25:59 +00:00
icon.Icon = 0;
2017-05-17 19:16:53 +00:00
icon.X = 0;
2017-05-25 18:25:59 +00:00
text.TextSize = 45;
textBold.TextSize = 45;
2017-05-17 19:16:53 +00:00
}
[BackgroundDependencyLoader]
private new void load(OsuColour colour)
{
2017-05-25 18:25:59 +00:00
backgroundInactive = colour.Gray2;
backgroundActive = colour.Gray3;
2017-05-17 19:16:53 +00:00
}
}
2017-05-12 06:32:52 +00:00
}
}
}