1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:43:04 +08:00

Merge pull request #3830 from peppy/channel-selector-on-none

Select channel selector when no channel is selected
This commit is contained in:
Dan Balasescu 2018-12-07 18:13:31 +09:00 committed by GitHub
commit 57980e81e5
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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat.Tabs;
using osu.Game.Users;
@ -74,50 +71,50 @@ namespace osu.Game.Tests.Visual
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
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);
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);
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()
{
channelTabControl.AddChannel(new Channel
AddStep("select selector tab", () => channelTabControl.Current.Value = channelTabControl.Items.Last());
AddAssert("selector tab is active", () => channelTabControl.ChannelSelectorActive.Value);
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 =
{
users?.Count > 0
? users[RNG.Next(0, users.Count - 1)]
: new User
{
Id = RNG.Next(),
Username = "testuser" + RNG.Next(1000)
}
}
});
var first = channelTabControl.Items.First();
if (first.Name == "+")
return true;
channelTabControl.RemoveChannel(first);
return false;
}, "remove all channels");
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
{
Type = ChannelType.Public,
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>
/// Adds the argument message as a local echo. When this local echo is resolved <see cref="PendingMessageResolved"/> will get called.
/// </summary>

View File

@ -79,7 +79,7 @@ namespace osu.Game.Online.Chat
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))
?? new Channel { Name = user.Username, Users = { user }, Type = ChannelType.PM };
?? new Channel(user);
}
private void currentChannelChanged(Channel channel) => JoinChannel(channel);

View File

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

View File

@ -52,9 +52,9 @@ namespace osu.Game.Overlays
public Bindable<double> ChatHeight { get; set; }
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()
{
@ -74,7 +74,7 @@ namespace osu.Game.Overlays
Masking = true,
Children = new[]
{
channelSelection = new ChannelSelectionOverlay
channelSelectionOverlay = new ChannelSelectionOverlay
{
RelativeSizeAxes = Axes.Both,
},
@ -161,9 +161,16 @@ namespace osu.Game.Overlays
};
channelTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
channelSelection.StateChanged += state =>
channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelectionOverlay.State = value ? Visibility.Visible : Visibility.Hidden;
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;
if (state == Visibility.Visible)
@ -176,8 +183,8 @@ namespace osu.Game.Overlays
textbox.HoldFocus = true;
};
channelSelection.OnRequestJoin = channel => channelManager.JoinChannel(channel);
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
channelSelectionOverlay.OnRequestJoin = channel => channelManager.JoinChannel(channel);
channelSelectionOverlay.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
}
private void currentChannelChanged(Channel channel)
@ -186,6 +193,7 @@ namespace osu.Game.Overlays
{
textbox.Current.Disabled = true;
currentChannelContainer.Clear(false);
channelSelectionOverlay.State = Visibility.Visible;
return;
}
@ -239,7 +247,7 @@ namespace osu.Game.Overlays
double targetChatHeight = startDragChatHeight - (e.MousePosition.Y - e.MouseDownPosition.Y) / Parent.DrawSize.Y;
// 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;
ChatHeight.Value = targetChatHeight;
@ -305,7 +313,7 @@ namespace osu.Game.Overlays
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
//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)
channelTabControl.AddChannel(channel);
}
@ -326,7 +334,7 @@ namespace osu.Game.Overlays
}
private void availableChannelsChanged(IEnumerable<Channel> channels)
=> channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
=> channelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
protected override void Dispose(bool isDisposing)
{