Ejemplo n.º 1
0
 private void addRandomUser()
 {
     channelTabControl.AddChannel(new Channel
     {
         Users =
         {
             users?.Count > 0
                 ? users[RNG.Next(0, users.Count - 1)]
                 : new User
             {
                 Id       = RNG.Next(),
                 Username = "******" + RNG.Next(1000)
             }
         }
     });
 }
Ejemplo n.º 2
0
        private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (Channel channel in args.NewItems.Cast <Channel>())
                {
                    ChannelTabControl.AddChannel(channel);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (Channel channel in args.OldItems.Cast <Channel>())
                {
                    ChannelTabControl.RemoveChannel(channel);

                    var loaded = loadedChannels.Find(c => c.Channel == channel);

                    if (loaded != null)
                    {
                        loadedChannels.Remove(loaded);

                        // Because the container is only cleared in the async load callback of a new channel, it is forcefully cleared
                        // to ensure that the previous channel doesn't get updated after it's disposed
                        currentChannelContainer.Remove(loaded);
                        loaded.Dispose();
                    }
                }

                break;
            }
        }
Ejemplo n.º 3
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);
            });
        }
Ejemplo n.º 4
0
 private void addRandomPrivateChannel() =>
 channelTabControl.AddChannel(new Channel(new User
 {
     Id       = RNG.Next(1000, 10000000),
     Username = "******" + RNG.Next(1000)
 }));