diff --git a/osu.Game/Overlays/NewChat/ChannelListing.cs b/osu.Game/Overlays/NewChat/ChannelListing.cs index 79371d0fed..3de6364303 100644 --- a/osu.Game/Overlays/NewChat/ChannelListing.cs +++ b/osu.Game/Overlays/NewChat/ChannelListing.cs @@ -30,27 +30,7 @@ namespace osu.Game.Overlays.NewChat private SearchContainer flow = null!; [Resolved] - private OverlayColourProvider overlayColours { get; set; } = null!; - - public ChannelListing() - { - Masking = true; - } - - protected override void PopIn() => this.FadeIn(); - protected override void PopOut() => this.FadeOut(); - - public void UpdateAvailableChannels(IEnumerable newChannels) - { - flow.ChildrenEnumerable = newChannels.Where(c => c.Type == ChannelType.Public) - .Select(c => new ChannelListingItem(c)); - - foreach (var item in flow.Children) - { - item.OnRequestJoin += channel => OnRequestJoin?.Invoke(channel); - item.OnRequestLeave += channel => OnRequestLeave?.Invoke(channel); - } - } + private OverlayColourProvider colourProvider { get; set; } = null!; [BackgroundDependencyLoader] private void load() @@ -60,7 +40,7 @@ namespace osu.Game.Overlays.NewChat new Box { RelativeSizeAxes = Axes.Both, - Colour = overlayColours.Background4, + Colour = colourProvider.Background4, }, new OsuScrollContainer { @@ -81,5 +61,21 @@ namespace osu.Game.Overlays.NewChat }, }; } + + public void UpdateAvailableChannels(IEnumerable newChannels) + { + flow.ChildrenEnumerable = newChannels.Where(c => c.Type == ChannelType.Public) + .Select(c => new ChannelListingItem(c)); + + foreach (var item in flow.Children) + { + item.OnRequestJoin += channel => OnRequestJoin?.Invoke(channel); + item.OnRequestLeave += channel => OnRequestLeave?.Invoke(channel); + } + } + + protected override void PopIn() => this.FadeIn(); + + protected override void PopOut() => this.FadeOut(); } } diff --git a/osu.Game/Overlays/NewChat/ChannelListingItem.cs b/osu.Game/Overlays/NewChat/ChannelListingItem.cs index 845db4e802..7e7cf36e91 100644 --- a/osu.Game/Overlays/NewChat/ChannelListingItem.cs +++ b/osu.Game/Overlays/NewChat/ChannelListingItem.cs @@ -27,15 +27,13 @@ namespace osu.Game.Overlays.NewChat public bool FilteringActive { get; set; } public IEnumerable FilterTerms => new[] { channel.Name, channel.Topic ?? string.Empty }; - public bool MatchingFilter - { - set => this.FadeTo(value ? 1f : 0f, 100); - } + public bool MatchingFilter { set => this.FadeTo(value ? 1f : 0f, 100); } - private readonly float TEXT_SIZE = 18; - private readonly float ICON_SIZE = 14; private readonly Channel channel; + private const float TEXT_SIZE = 18; + private const float ICON_SIZE = 14; + private Colour4 selectedColour; private Colour4 normalColour; @@ -45,73 +43,33 @@ namespace osu.Game.Overlays.NewChat private IBindable channelJoined = null!; [Resolved] - private OverlayColourProvider overlayColours { get; set; } = null!; + private OverlayColourProvider colourProvider { get; set; } = null!; public ChannelListingItem(Channel channel) { this.channel = channel; - - Masking = true; - CornerRadius = 5; - RelativeSizeAxes = Axes.X; - Height = 20; - } - - protected override bool OnHover(HoverEvent e) - { - hoverBox.Show(); - return base.OnHover(e); - } - - protected override void OnHoverLost(HoverLostEvent e) - { - hoverBox.Hide(); - base.OnHoverLost(e); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - // Set colours - normalColour = overlayColours.Light3; - selectedColour = Colour4.White; - - // Set handlers for state display - channelJoined = channel.Joined.GetBoundCopy(); - channelJoined.BindValueChanged(change => - { - if (change.NewValue) - { - checkbox.Show(); - channelText.Colour = selectedColour; - } - else - { - checkbox.Hide(); - channelText.Colour = normalColour; - } - }, true); - - // Set action on click - Action = () => (channelJoined.Value ? OnRequestLeave : OnRequestJoin)?.Invoke(channel); } [BackgroundDependencyLoader] private void load() { + Masking = true; + CornerRadius = 5; + RelativeSizeAxes = Axes.X; + Height = 20; + Children = new Drawable[] { hoverBox = new Box { RelativeSizeAxes = Axes.Both, - Colour = overlayColours.Background3, + Colour = colourProvider.Background3, Alpha = 0f, }, new GridContainer { RelativeSizeAxes = Axes.Both, - ColumnDimensions = new Dimension[] + ColumnDimensions = new[] { new Dimension(GridSizeMode.Absolute, 40), new Dimension(GridSizeMode.Absolute, 200), @@ -155,7 +113,7 @@ namespace osu.Game.Overlays.NewChat Icon = FontAwesome.Solid.User, Size = new Vector2(ICON_SIZE), Margin = new MarginPadding { Right = 5 }, - Colour = overlayColours.Light3, + Colour = colourProvider.Light3, }, new OsuSpriteText { @@ -164,12 +122,52 @@ namespace osu.Game.Overlays.NewChat Text = "0", Font = OsuFont.Numeric.With(size: TEXT_SIZE, weight: FontWeight.Medium), Margin = new MarginPadding { Bottom = 2 }, - Colour = overlayColours.Light3, + Colour = colourProvider.Light3, }, }, }, }, }; } + + protected override void LoadComplete() + { + base.LoadComplete(); + + // Set colours + normalColour = colourProvider.Light3; + selectedColour = Colour4.White; + + // Set handlers for state display + channelJoined = channel.Joined.GetBoundCopy(); + channelJoined.BindValueChanged(change => + { + if (change.NewValue) + { + checkbox.Show(); + channelText.Colour = selectedColour; + } + else + { + checkbox.Hide(); + channelText.Colour = normalColour; + } + }, true); + + // Set action on click + Action = () => (channelJoined.Value ? OnRequestLeave : OnRequestJoin)?.Invoke(channel); + } + + protected override bool OnHover(HoverEvent e) + { + hoverBox.Show(); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + hoverBox.Hide(); + base.OnHoverLost(e); + } } }