Exemplo n.º 1
0
        public TestCaseChannelTabControl()
        {
            SpriteText currentText;

            Add(new Container
            {
                RelativeSizeAxes = Axes.X,
                Origin           = Anchor.Centre,
                Anchor           = Anchor.Centre,
                Children         = new Drawable[]
                {
                    channelTabControl = new ChannelTabControl
                    {
                        RelativeSizeAxes = Axes.X,
                        Origin           = Anchor.Centre,
                        Anchor           = Anchor.Centre,
                        Height           = 50
                    },
                    new Box
                    {
                        Colour           = Color4.Black.Opacity(0.1f),
                        RelativeSizeAxes = Axes.X,
                        Height           = 50,
                        Depth            = -1,
                        Origin           = Anchor.Centre,
                        Anchor           = Anchor.Centre,
                    }
                }
            });

            Add(new Container
            {
                Origin   = Anchor.TopLeft,
                Anchor   = Anchor.TopLeft,
                Children = new Drawable[]
                {
                    currentText = new SpriteText
                    {
                        Text = "Currently selected channel:"
                    }
                }
            });

            channelTabControl.OnRequestLeave       += channel => channelTabControl.RemoveChannel(channel);
            channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();

            AddStep("Add random private channel", addRandomUser);
            AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);
            AddRepeatStep("Add 3 random private channels", addRandomUser, 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);
        }
Exemplo n.º 2
0
        private void load(OsuConfigManager config, OsuColour colours, TextureStore textures)
        {
            const float padding = 5;

            Children = new Drawable[]
            {
                channelSelectionContainer = new Container
                {
                    RelativeSizeAxes = Axes.Both,
                    Height           = 1f - DEFAULT_HEIGHT,
                    Masking          = true,
                    Children         = new[]
                    {
                        ChannelSelectionOverlay = new ChannelSelectionOverlay
                        {
                            RelativeSizeAxes = Axes.Both,
                        },
                    },
                },
                chatContainer = new Container
                {
                    Name             = @"chat container",
                    Anchor           = Anchor.BottomLeft,
                    Origin           = Anchor.BottomLeft,
                    RelativeSizeAxes = Axes.Both,
                    Height           = DEFAULT_HEIGHT,
                    Children         = new[]
                    {
                        new Container
                        {
                            Name             = @"chat area",
                            RelativeSizeAxes = Axes.Both,
                            Padding          = new MarginPadding {
                                Top = TAB_AREA_HEIGHT
                            },
                            Children = new Drawable[]
                            {
                                chatBackground = new Box
                                {
                                    RelativeSizeAxes = Axes.Both,
                                },
                                new OnlineViewContainer("Sign in to chat")
                                {
                                    RelativeSizeAxes = Axes.Both,
                                    Children         = new Drawable[]
                                    {
                                        currentChannelContainer = new Container <DrawableChannel>
                                        {
                                            RelativeSizeAxes = Axes.Both,
                                            Padding          = new MarginPadding
                                            {
                                                Bottom = textbox_height
                                            },
                                        },
                                        new Container
                                        {
                                            Anchor           = Anchor.BottomLeft,
                                            Origin           = Anchor.BottomLeft,
                                            RelativeSizeAxes = Axes.X,
                                            Height           = textbox_height,
                                            Padding          = new MarginPadding
                                            {
                                                Top    = padding * 2,
                                                Bottom = padding * 2,
                                                Left   = ChatLine.LEFT_PADDING + padding * 2,
                                                Right  = padding * 2,
                                            },
                                            Children = new Drawable[]
                                            {
                                                textbox = new FocusedTextBox
                                                {
                                                    RelativeSizeAxes     = Axes.Both,
                                                    Height               = 1,
                                                    PlaceholderText      = "type your message",
                                                    ReleaseFocusOnCommit = false,
                                                    HoldFocus            = true,
                                                }
                                            }
                                        },
                                        loading = new LoadingSpinner(),
                                    },
                                }
                            }
                        },
                        tabsArea = new TabsArea
                        {
                            Children = new Drawable[]
                            {
                                tabBackground = new Box
                                {
                                    RelativeSizeAxes = Axes.Both,
                                    Colour           = Color4.Black,
                                },
                                new Sprite
                                {
                                    Texture = textures.Get(IconTexture),
                                    Anchor  = Anchor.CentreLeft,
                                    Origin  = Anchor.CentreLeft,
                                    Size    = new Vector2(OverlayTitle.ICON_SIZE),
                                    Margin  = new MarginPadding {
                                        Left = 10
                                    },
                                },
                                ChannelTabControl = CreateChannelTabControl().With(d =>
                                {
                                    d.Anchor           = Anchor.BottomLeft;
                                    d.Origin           = Anchor.BottomLeft;
                                    d.RelativeSizeAxes = Axes.Both;
                                    d.OnRequestLeave   = channelManager.LeaveChannel;
                                    d.IsSwitchable     = true;
                                }),
                            }
                        },
                    },
                },
            };

            textbox.OnCommit += postMessage;

            ChannelTabControl.Current.ValueChanged += current => channelManager.CurrentChannel.Value = current.NewValue;
            ChannelTabControl.ChannelSelectorActive.ValueChanged += active => ChannelSelectionOverlay.State.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden;
            ChannelSelectionOverlay.State.ValueChanged           += state =>
            {
                // Propagate the visibility state to ChannelSelectorActive
                ChannelTabControl.ChannelSelectorActive.Value = state.NewValue == Visibility.Visible;

                if (state.NewValue == Visibility.Visible)
                {
                    textbox.HoldFocus = false;
                    if (1f - ChatHeight.Value < channel_selection_min_height)
                    {
                        this.TransformBindableTo(ChatHeight, 1f - channel_selection_min_height, 800, Easing.OutQuint);
                    }
                }
                else
                {
                    textbox.HoldFocus = true;
                }
            };

            ChannelSelectionOverlay.OnRequestJoin  = channel => channelManager.JoinChannel(channel);
            ChannelSelectionOverlay.OnRequestLeave = channelManager.LeaveChannel;

            ChatHeight = config.GetBindable <float>(OsuSetting.ChatDisplayHeight);
            ChatHeight.BindValueChanged(height =>
            {
                chatContainer.Height             = height.NewValue;
                channelSelectionContainer.Height = 1f - height.NewValue;
                tabBackground.FadeTo(height.NewValue == 1f ? 1f : 0.8f, 200);
            }, true);

            chatBackground.Colour = colours.ChatBlue;

            loading.Show();

            // This is a relatively expensive (and blocking) operation.
            // Scheduling it ensures that it won't be performed unless the user decides to open chat.
            // TODO: Refactor OsuFocusedOverlayContainer / OverlayContainer to support delayed content loading.
            Schedule(() =>
            {
                // TODO: consider scheduling bindable callbacks to not perform when overlay is not present.
                channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;

                foreach (Channel channel in channelManager.JoinedChannels)
                {
                    ChannelTabControl.AddChannel(channel);
                }

                channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
                availableChannelsChanged(null, null);

                currentChannel = channelManager.CurrentChannel.GetBoundCopy();
                currentChannel.BindValueChanged(currentChannelChanged, true);
            });
        }
Exemplo n.º 3
0
        public TestCaseChannelTabControl()
        {
            SpriteText currentText;

            Add(new Container
            {
                RelativeSizeAxes = Axes.X,
                Origin           = Anchor.Centre,
                Anchor           = Anchor.Centre,
                Children         = new Drawable[]
                {
                    channelTabControl = new ChannelTabControl
                    {
                        RelativeSizeAxes = Axes.X,
                        Origin           = Anchor.Centre,
                        Anchor           = Anchor.Centre,
                        Height           = 50
                    },
                    new Box
                    {
                        Colour           = Color4.Black.Opacity(0.1f),
                        RelativeSizeAxes = Axes.X,
                        Height           = 50,
                        Depth            = -1,
                        Origin           = Anchor.Centre,
                        Anchor           = Anchor.Centre,
                    }
                }
            });

            Add(new Container
            {
                Origin   = Anchor.TopLeft,
                Anchor   = Anchor.TopLeft,
                Children = new Drawable[]
                {
                    currentText = new SpriteText
                    {
                        Text = "Currently selected channel:"
                    }
                }
            });

            channelTabControl.OnRequestLeave       += channel => channelTabControl.RemoveChannel(channel);
            channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();

            AddStep("Add random private channel", addRandomPrivateChannel);
            AddAssert("There is only one channels", () => channelTabControl.Items.Count() == 2);
            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() - 1)), 20);

            Channel channelBefore = channelTabControl.Items.First();

            AddStep("set first channel", () => channelTabControl.Current.Value = channelBefore);

            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(() =>
            {
                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);
        }