Merge branch 'master' into mod-fl2

This commit is contained in:
Dean Herbert 2018-12-07 19:58:27 +09:00 committed by GitHub
commit 808f02b51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 48 deletions

View File

@ -4,15 +4,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
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.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat.Tabs; using osu.Game.Overlays.Chat.Tabs;
using osu.Game.Users; using osu.Game.Users;
@ -74,50 +71,50 @@ namespace osu.Game.Tests.Visual
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel); channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString(); channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();
AddStep("Add random private channel", addRandomUser); AddStep("Add random private channel", addRandomPrivateChannel);
AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2); AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);
AddRepeatStep("Add 3 random private channels", addRandomUser, 3); AddRepeatStep("Add 3 random private channels", addRandomPrivateChannel, 3);
AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5); AddAssert("There are four channels", () => channelTabControl.Items.Count() == 5);
AddStep("Add random public channel", () => addChannel(RNG.Next().ToString())); AddStep("Add random public channel", () => addChannel(RNG.Next().ToString()));
AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count())), 20); AddRepeatStep("Select a random channel", () => channelTabControl.Current.Value = channelTabControl.Items.ElementAt(RNG.Next(channelTabControl.Items.Count() - 1)), 20);
}
private List<User> users; Channel channelBefore = channelTabControl.Items.First();
AddStep("set first channel", () => channelTabControl.Current.Value = channelBefore);
private void addRandomUser() AddStep("select selector tab", () => channelTabControl.Current.Value = channelTabControl.Items.Last());
{ AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
channelTabControl.AddChannel(new Channel
AddAssert("check channel unchanged", () => channelBefore == channelTabControl.Current.Value);
AddStep("set second channel", () => channelTabControl.Current.Value = channelTabControl.Items.Skip(1).First());
AddAssert("selector tab is inactive", () => !channelTabControl.ChannelSelectorActive.Value);
AddUntilStep(() =>
{ {
Users = var first = channelTabControl.Items.First();
{ if (first.Name == "+")
users?.Count > 0 return true;
? users[RNG.Next(0, users.Count - 1)]
: new User channelTabControl.RemoveChannel(first);
{ return false;
Id = RNG.Next(), }, "remove all channels");
Username = "testuser" + RNG.Next(1000)
} AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
}
});
} }
private void addChannel(string name) private void addRandomPrivateChannel() =>
{ channelTabControl.AddChannel(new Channel(new User
{
Id = RNG.Next(1000, 10000000),
Username = "Test User " + RNG.Next(1000)
}));
private void addChannel(string name) =>
channelTabControl.AddChannel(new Channel channelTabControl.AddChannel(new Channel
{ {
Type = ChannelType.Public, Type = ChannelType.Public,
Name = name Name = name
}); });
}
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
{
GetUsersRequest req = new GetUsersRequest();
req.Success += list => users = list.Select(e => e.User).ToList();
api.Queue(req);
}
} }
} }

View File

@ -88,6 +88,17 @@ namespace osu.Game.Online.Chat
{ {
} }
/// <summary>
/// Create a private messaging channel with the specified user.
/// </summary>
/// <param name="user">The user to create the private conversation with.</param>
public Channel(User user)
{
Type = ChannelType.PM;
Users.Add(user);
Name = user.Username;
}
/// <summary> /// <summary>
/// Adds the argument message as a local echo. When this local echo is resolved <see cref="PendingMessageResolved"/> will get called. /// Adds the argument message as a local echo. When this local echo is resolved <see cref="PendingMessageResolved"/> will get called.
/// </summary> /// </summary>

View File

@ -79,7 +79,7 @@ namespace osu.Game.Online.Chat
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Users.Any(u => u.Id == user.Id)) CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Users.Any(u => u.Id == user.Id))
?? new Channel { Name = user.Username, Users = { user }, Type = ChannelType.PM }; ?? new Channel(user);
} }
private void currentChannelChanged(Channel channel) => JoinChannel(channel); private void currentChannelChanged(Channel channel) => JoinChannel(channel);

View File

@ -94,13 +94,12 @@ namespace osu.Game.Overlays.Chat.Tabs
{ {
if (tab is ChannelSelectorTabItem) if (tab is ChannelSelectorTabItem)
{ {
tab.Active.Toggle(); tab.Active.Value = true;
return; return;
} }
selectorTab.Active.Value = false;
base.SelectTab(tab); base.SelectTab(tab);
selectorTab.Active.Value = false;
} }
private void tabCloseRequested(TabItem<Channel> tab) private void tabCloseRequested(TabItem<Channel> tab)

View File

@ -52,9 +52,9 @@ namespace osu.Game.Overlays
public Bindable<double> ChatHeight { get; set; } public Bindable<double> ChatHeight { get; set; }
private readonly Container channelSelectionContainer; private readonly Container channelSelectionContainer;
private readonly ChannelSelectionOverlay channelSelection; private readonly ChannelSelectionOverlay channelSelectionOverlay;
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos) || channelSelection.State == Visibility.Visible && channelSelection.ReceivePositionalInputAt(screenSpacePos); public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos) || channelSelectionOverlay.State == Visibility.Visible && channelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos);
public ChatOverlay() public ChatOverlay()
{ {
@ -74,7 +74,7 @@ namespace osu.Game.Overlays
Masking = true, Masking = true,
Children = new[] Children = new[]
{ {
channelSelection = new ChannelSelectionOverlay channelSelectionOverlay = new ChannelSelectionOverlay
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
@ -161,9 +161,16 @@ namespace osu.Game.Overlays
}; };
channelTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat; channelTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden; channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelectionOverlay.State = value ? Visibility.Visible : Visibility.Hidden;
channelSelection.StateChanged += state => channelSelectionOverlay.StateChanged += state =>
{ {
if (state == Visibility.Hidden && channelManager.CurrentChannel.Value == null)
{
channelSelectionOverlay.State = Visibility.Visible;
State = Visibility.Hidden;
return;
}
channelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible; channelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible;
if (state == Visibility.Visible) if (state == Visibility.Visible)
@ -176,8 +183,8 @@ namespace osu.Game.Overlays
textbox.HoldFocus = true; textbox.HoldFocus = true;
}; };
channelSelection.OnRequestJoin = channel => channelManager.JoinChannel(channel); channelSelectionOverlay.OnRequestJoin = channel => channelManager.JoinChannel(channel);
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel); channelSelectionOverlay.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
} }
private void currentChannelChanged(Channel channel) private void currentChannelChanged(Channel channel)
@ -186,6 +193,7 @@ namespace osu.Game.Overlays
{ {
textbox.Current.Disabled = true; textbox.Current.Disabled = true;
currentChannelContainer.Clear(false); currentChannelContainer.Clear(false);
channelSelectionOverlay.State = Visibility.Visible;
return; return;
} }
@ -239,7 +247,7 @@ namespace osu.Game.Overlays
double targetChatHeight = startDragChatHeight - (e.MousePosition.Y - e.MouseDownPosition.Y) / Parent.DrawSize.Y; double targetChatHeight = startDragChatHeight - (e.MousePosition.Y - e.MouseDownPosition.Y) / Parent.DrawSize.Y;
// If the channel selection screen is shown, mind its minimum height // If the channel selection screen is shown, mind its minimum height
if (channelSelection.State == Visibility.Visible && targetChatHeight > 1f - channel_selection_min_height) if (channelSelectionOverlay.State == Visibility.Visible && targetChatHeight > 1f - channel_selection_min_height)
targetChatHeight = 1f - channel_selection_min_height; targetChatHeight = 1f - channel_selection_min_height;
ChatHeight.Value = targetChatHeight; ChatHeight.Value = targetChatHeight;
@ -305,7 +313,7 @@ namespace osu.Game.Overlays
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged; channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged. //for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels); channelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
foreach (Channel channel in channelManager.JoinedChannels) foreach (Channel channel in channelManager.JoinedChannels)
channelTabControl.AddChannel(channel); channelTabControl.AddChannel(channel);
} }
@ -326,7 +334,7 @@ namespace osu.Game.Overlays
} }
private void availableChannelsChanged(IEnumerable<Channel> channels) private void availableChannelsChanged(IEnumerable<Channel> channels)
=> channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels); => channelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {