Use dummy channel to show selector and remove ChannelListSelector

Add dummy channel `DummySelectorChannel` which should be set as the
current channel in the channel manager when the selector in the chat
overlay should be shown.

Refactors the `ChannelListItem` to not show mention pill and close
button when the channel is the dummy selector channel.

Ensure that the `ChannelList` selects the dummy channel on clicking the
selector item.

Removes `ChannelListSelector` as it is no longer needed.

Removes the `setCurrent` parameter from `ChannelManager.JoinChannel`
method as it is no longer needed.
This commit is contained in:
Jai Sharma
2022-05-15 19:38:37 +01:00
parent 328561f5c8
commit ae5b6c3e10
7 changed files with 80 additions and 141 deletions

View File

@ -18,13 +18,16 @@ namespace osu.Game.Overlays.Chat.ChannelList
{
public class ChannelList : Container
{
public Action<Channel?>? OnRequestSelect;
public Action<Channel>? OnRequestSelect;
public Action<Channel>? OnRequestLeave;
private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>();
private readonly DummySelectorChannel dummySelectorChannel = new DummySelectorChannel();
private ChannelListItemFlow publicChannelFlow = null!;
private ChannelListItemFlow privateChannelFlow = null!;
private ChannelListItem selector = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
@ -50,16 +53,17 @@ namespace osu.Game.Overlays.Chat.ChannelList
Children = new Drawable[]
{
publicChannelFlow = new ChannelListItemFlow("CHANNELS"),
new ChannelListSelector
selector = new ChannelListItem(dummySelectorChannel)
{
Margin = new MarginPadding { Bottom = 10 },
Action = () => OnRequestSelect?.Invoke(null),
},
privateChannelFlow = new ChannelListItemFlow("DIRECT MESSAGES"),
},
},
},
};
selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
}
public void AddChannel(Channel channel)

View File

@ -34,7 +34,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
private Box hoverBox = null!;
private Box selectBox = null!;
private OsuSpriteText text = null!;
private ChannelListItemCloseButton close = null!;
private Drawable close = null!;
[Resolved]
private Bindable<Channel> selectedChannel { get; set; } = null!;
@ -97,20 +97,8 @@ namespace osu.Game.Overlays.Chat.ChannelList
RelativeSizeAxes = Axes.X,
Truncate = true,
},
new ChannelListItemMentionPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Mentions = { BindTarget = Mentions },
},
close = new ChannelListItemCloseButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Action = () => OnRequestLeave?.Invoke(Channel),
}
createMentionPill(),
close = createCloseButton(),
}
},
},
@ -131,14 +119,20 @@ namespace osu.Game.Overlays.Chat.ChannelList
protected override bool OnHover(HoverEvent e)
{
hoverBox.FadeIn(300, Easing.OutQuint);
close.FadeIn(300, Easing.OutQuint);
if (!isSelector)
close.FadeIn(300, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverBox.FadeOut(200, Easing.OutQuint);
close.FadeOut(200, Easing.OutQuint);
if (!isSelector)
close.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e);
}
@ -158,9 +152,37 @@ namespace osu.Game.Overlays.Chat.ChannelList
};
}
private Drawable createMentionPill()
{
if (isSelector)
return Drawable.Empty();
return new ChannelListItemMentionPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Mentions = { BindTarget = Mentions },
};
}
private Drawable createCloseButton()
{
if (isSelector)
return Drawable.Empty();
return new ChannelListItemCloseButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Action = () => OnRequestLeave?.Invoke(Channel),
};
}
private void updateState()
{
bool selected = selectedChannel.Value == Channel;
bool selected = selectedChannel.Value == Channel || (isSelector && selectedChannel.Value == null);
if (selected)
selectBox.FadeIn(300, Easing.OutQuint);
@ -172,5 +194,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
else
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
}
private bool isSelector => Channel is DummySelectorChannel;
}
}

View File

@ -1,103 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Chat.ChannelList
{
public class ChannelListSelector : OsuClickableContainer
{
private Box hoverBox = null!;
private Box selectBox = null!;
private OsuSpriteText text = null!;
[Resolved]
private Bindable<Channel> currentChannel { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Height = 30;
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
hoverBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3,
Alpha = 0f,
},
selectBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
Alpha = 0f,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 18, Right = 10 },
Child = text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Add more channels",
Font = OsuFont.Torus.With(size: 17, weight: FontWeight.SemiBold),
Colour = colourProvider.Light3,
Margin = new MarginPadding { Bottom = 2 },
RelativeSizeAxes = Axes.X,
Truncate = true,
},
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
currentChannel.BindValueChanged(channel =>
{
// This logic should be handled by the chat overlay rather than this component.
// Selected state should be moved to an abstract class and shared with ChannelListItem.
if (channel.NewValue == null)
{
text.FadeColour(colourProvider.Content1, 300, Easing.OutQuint);
selectBox.FadeIn(300, Easing.OutQuint);
}
else
{
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
selectBox.FadeOut(200, Easing.OutQuint);
}
}, true);
}
protected override bool OnHover(HoverEvent e)
{
hoverBox.FadeIn(300, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverBox.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e);
}
}
}