diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index bffd98ee2c..b548d72389 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; +using osu.Framework.Configuration; using osu.Framework.Lists; namespace osu.Game.Online.Chat @@ -23,7 +24,7 @@ namespace osu.Game.Online.Chat [JsonProperty(@"channel_id")] public int Id; - public bool Joined; + public Bindable Joined = new Bindable(); public readonly SortedList Messages = new SortedList((m1, m2) => m1.Id.CompareTo(m2.Id)); diff --git a/osu.Game/Overlays/Chat/ChannelListItem.cs b/osu.Game/Overlays/Chat/ChannelListItem.cs index 5318d2e592..94e3438d87 100644 --- a/osu.Game/Overlays/Chat/ChannelListItem.cs +++ b/osu.Game/Overlays/Chat/ChannelListItem.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; @@ -36,6 +37,8 @@ namespace osu.Game.Overlays.Chat } } + public Action OnRequestJoin; + private Channel channel; public Channel Channel { @@ -43,11 +46,13 @@ namespace osu.Game.Overlays.Chat set { if (value == channel) return; + if (channel != null) channel.Joined.ValueChanged -= updateColour; channel = value; name.Text = Channel.ToString(); topic.Text = Channel.Topic; - updateColour(); + channel.Joined.ValueChanged += updateColour; + updateColour(Channel.Joined); } } @@ -56,6 +61,8 @@ namespace osu.Game.Overlays.Chat RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; + Action = () => { if (!Channel.Joined) OnRequestJoin?.Invoke(Channel); }; + Children = new Drawable[] { new FillFlowContainer @@ -141,15 +148,21 @@ namespace osu.Game.Overlays.Chat topicColour = colours.Gray9; joinedColour = colours.Blue; - updateColour(); + updateColour(Channel.Joined); } - private void updateColour() + protected override void Dispose(bool isDisposing) { - joinedCheckmark.FadeTo(Channel.Joined ? 1f : 0f, transition_duration); - topic.FadeTo(Channel.Joined ? 0.8f : 1f, transition_duration); - topic.FadeColour(Channel.Joined ? Color4.White : topicColour ?? Color4.White, transition_duration); - FadeColour(Channel.Joined ? joinedColour ?? Color4.White : Color4.White, transition_duration); + if(channel != null) channel.Joined.ValueChanged -= updateColour; + base.Dispose(isDisposing); + } + + private void updateColour(bool joined) + { + joinedCheckmark.FadeTo(joined ? 1f : 0f, transition_duration); + topic.FadeTo(joined ? 0.8f : 1f, transition_duration); + topic.FadeColour(joined ? Color4.White : topicColour ?? Color4.White, transition_duration); + FadeColour(joined ? joinedColour ?? Color4.White : Color4.White, transition_duration); } } } diff --git a/osu.Game/Overlays/Chat/ChannelSection.cs b/osu.Game/Overlays/Chat/ChannelSection.cs index 4bbf25d96e..60fabdf187 100644 --- a/osu.Game/Overlays/Chat/ChannelSection.cs +++ b/osu.Game/Overlays/Chat/ChannelSection.cs @@ -13,14 +13,15 @@ namespace osu.Game.Overlays.Chat { public class ChannelSection : Container, IHasFilterableChildren { - private readonly FillFlowContainer items; private readonly OsuSpriteText header; - public IEnumerable FilterableChildren => items.Children.OfType(); + public readonly FillFlowContainer ChannelFlow; + + public IEnumerable FilterableChildren => ChannelFlow.Children.OfType(); public string[] FilterTerms => new[] { Header }; public bool MatchingCurrentFilter { - set + set { FadeTo(value ? 1f : 0f, 100); } @@ -34,9 +35,10 @@ namespace osu.Game.Overlays.Chat public IEnumerable Channels { - set { items.Children = value.Select(c => new ChannelListItem { Channel = c }); } + set { ChannelFlow.Children = value.Select(c => new ChannelListItem { Channel = c }); } } + public ChannelSection() { RelativeSizeAxes = Axes.X; @@ -49,7 +51,7 @@ namespace osu.Game.Overlays.Chat TextSize = 15, Font = @"Exo2.0-Bold", }, - items = new FillFlowContainer + ChannelFlow = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, diff --git a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs index 9746ae2ae8..7187b9df40 100644 --- a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs +++ b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using System.Collections.Generic; using OpenTK; using OpenTK.Graphics; @@ -16,6 +17,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Online.Chat; namespace osu.Game.Overlays.Chat { @@ -29,11 +31,21 @@ namespace osu.Game.Overlays.Chat private readonly SearchTextBox search; private readonly SearchContainer sectionsFlow; + public Action OnRequestJoin; + public IEnumerable Sections { set { sectionsFlow.Children = value; + + foreach (ChannelSection s in sectionsFlow.Children) + { + foreach (ChannelListItem c in s.ChannelFlow.Children) + { + c.OnRequestJoin = channel => { OnRequestJoin?.Invoke(channel); }; + } + } } } diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 2836be22ae..67a807103d 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -53,6 +53,10 @@ namespace osu.Game.Overlays private Bindable chatHeight; + private readonly ChannelSelectionOverlay channelSelection; + + protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || channelSelection.Contains(screenSpacePos); + public ChatOverlay() { RelativeSizeAxes = Axes.Both; @@ -65,6 +69,12 @@ namespace osu.Game.Overlays Children = new Drawable[] { + channelSelection = new ChannelSelectionOverlay + { + Origin = Anchor.BottomLeft, + Height = 400, + State = Visibility.Visible, + }, new Container { Name = @"chat area", @@ -233,6 +243,16 @@ namespace osu.Game.Overlays addChannel(channels.Find(c => c.Name == @"#lazer")); addChannel(channels.Find(c => c.Name == @"#osu")); addChannel(channels.Find(c => c.Name == @"#lobby")); + + channelSelection.OnRequestJoin = channel => addChannel(channel); + channelSelection.Sections = new[] + { + new ChannelSection + { + Header = @"ALL CHANNELS", + Channels = channels, + }, + }; }); messageRequest = Scheduler.AddDelayed(fetchNewMessages, 1000, true); @@ -294,6 +314,8 @@ namespace osu.Game.Overlays if (CurrentChannel == null) CurrentChannel = channel; + + channel.Joined.Value = true; } private void fetchInitialMessages(Channel channel)