Add Test Case, improve displaying the avatar, use a chatTabControl instead of putting both in ChatOverlay, readd shadow.

Requires osu-framework for a fix
This commit is contained in:
miterosan
2018-04-11 18:23:09 +02:00
parent 85f736ae89
commit 39ecc3d31d
8 changed files with 263 additions and 55 deletions

View File

@ -0,0 +1,99 @@
using System;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Chat
{
public class ChatTabControl : Container, IHasCurrentValue<ChatBase>
{
public readonly ChannelTabControl channelTabControl;
private readonly UserTabControl userTabControl;
public Bindable<ChatBase> Current { get; } = new Bindable<ChatBase>();
public Action<ChatBase> OnRequestLeave;
public Action OnRequestChannelSelection;
public ChatTabControl()
{
Masking = false;
Children = new Drawable[]
{
channelTabControl = new ChannelTabControl
{
Width = 0.5f,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
OnRequestLeave = chat => OnRequestLeave?.Invoke(chat)
},
userTabControl = new UserTabControl
{
Width = 0.5f,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
RelativeSizeAxes = Axes.Both,
OnRequestLeave = chat => OnRequestLeave?.Invoke(chat)
},
};
Current.ValueChanged += currentTabChanged;
channelTabControl.Current.ValueChanged += chat =>
{
if (chat != null)
Current.Value = chat;
};
userTabControl.Current.ValueChanged += chat =>
{
if (chat != null)
Current.Value = chat;
};
}
private void currentTabChanged(ChatBase tab)
{
switch (tab)
{
case UserChat userChat:
userTabControl.Current.Value = userChat;
channelTabControl.Current.Value = null;
break;
case ChannelChat channelChat:
channelTabControl.Current.Value = channelChat;
userTabControl.Current.Value = null;
break;
}
}
public void AddItem(ChatBase chat)
{
switch (chat)
{
case UserChat userChat:
userTabControl.AddItem(userChat);
break;
case ChannelChat channelChat:
channelTabControl.AddItem(channelChat);
break;
}
}
public void RemoveItem(ChatBase chat)
{
switch (chat)
{
case UserChat userChat:
userTabControl.RemoveItem(userChat);
Current.Value = null;
break;
case ChannelChat channelChat:
channelTabControl.RemoveItem(channelChat);
Current.Value = null;
break;
}
}
}
}

View File

@ -58,7 +58,7 @@ namespace osu.Game.Overlays.Chat
[BackgroundDependencyLoader]
private void load()
{
newMessagesArrived(Chat.Messages);
Scheduler.Add(() => newMessagesArrived(Chat.Messages));
}
protected override void LoadComplete()

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
@ -9,16 +10,22 @@ using OpenTK;
namespace osu.Game.Overlays.Chat
{
public class UserChatTabControl : OsuTabControl<UserChat>
public class UserTabControl : OsuTabControl<UserChat>
{
protected override TabItem<UserChat> CreateTabItem(UserChat value) => new UserChatTabItem(value) { OnRequestClose = tabCloseRequested };
protected override TabItem<UserChat> CreateTabItem(UserChat value) => new UserTabItem(value) { OnRequestClose = tabCloseRequested };
protected override Dropdown<UserChat> CreateDropdown() => null;
public Action<UserChat> OnRequestLeave;
public UserChatTabControl()
public UserTabControl()
{
TabContainer.Spacing = new Vector2(-10, 0);
TabContainer.Masking = false;
Margin = new MarginPadding
{
Right = 10
};
}
protected override void AddTabItem(TabItem<UserChat> item, bool addToDropdown = true)
@ -46,6 +53,7 @@ namespace osu.Game.Overlays.Chat
if (SelectedTab != null)
SelectedTab.Active.Value = false;
SelectedTab = null;
}
}
}

View File

@ -19,7 +19,7 @@ using OpenTK.Graphics;
namespace osu.Game.Overlays.Chat
{
public class UserChatTabItem : TabItem<UserChat>
public class UserTabItem : TabItem<UserChat>
{
private static readonly Vector2 shear = new Vector2(1f / 5f, 0);
private readonly UserChat chat;
@ -29,18 +29,19 @@ namespace osu.Game.Overlays.Chat
private readonly Container backgroundContainer;
private readonly Box backgroundBox;
private readonly OsuSpriteText username;
private readonly Avatar avatarContainer;
private readonly ChatTabItemCloseButton closeButton;
public UserChatTabItem(UserChat value)
public UserTabItem(UserChat value)
: base(value)
{
chat = value;
AutoSizeAxes = Axes.X;
RelativeSizeAxes = Axes.Y;
Height = 50;
Origin = Anchor.BottomRight;
Anchor = Anchor.BottomRight;
EdgeEffect = deactivateEdgeEffect;
Masking = false;
EdgeEffect = activateEdgeEffect;
Masking = true;
Shear = shear;
Children = new Drawable[]
{
@ -116,7 +117,11 @@ namespace osu.Game.Overlays.Chat
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
Child = new Avatar(value.User)
Child = new DelayedLoadWrapper(new Avatar(value.User)
{
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
})
{
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
}
@ -136,6 +141,10 @@ namespace osu.Game.Overlays.Chat
Height = 1,
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
Margin = new MarginPadding
{
Right = 5
},
RelativeSizeAxes = Axes.Y,
Action = delegate
{
@ -148,13 +157,13 @@ namespace osu.Game.Overlays.Chat
};
}
public Action<UserChatTabItem> OnRequestClose;
public Action<UserTabItem> OnRequestClose;
private readonly EdgeEffectParameters activateEdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = 30,
Colour = Color4.Black.Opacity(0.3f),
Radius = 15,
Colour = Color4.Black.Opacity(0.4f),
};
protected override void OnActivated()
@ -168,7 +177,7 @@ namespace osu.Game.Overlays.Chat
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);
// TweenEdgeEffectTo(activateEdgeEffect, activate_length);
}
private readonly EdgeEffectParameters deactivateEdgeEffect = new EdgeEffectParameters
@ -187,7 +196,7 @@ namespace osu.Game.Overlays.Chat
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);
// TweenEdgeEffectTo(deactivateEdgeEffect, deactivate_length);
}
[BackgroundDependencyLoader]