1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00

Use Bindable<ChannelSelectorState> to control selector active visibility

This commit is contained in:
Jai Sharma 2022-04-20 19:12:43 +01:00
parent 44c822f34d
commit e596c9d171
4 changed files with 46 additions and 23 deletions

View File

@ -25,6 +25,9 @@ namespace osu.Game.Tests.Visual.Online
[Cached] [Cached]
private readonly Bindable<Channel> selected = new Bindable<Channel>(); private readonly Bindable<Channel> selected = new Bindable<Channel>();
[Cached]
private readonly Bindable<ChannelSelectorState> selector = new Bindable<ChannelSelectorState>();
private OsuSpriteText selectorText; private OsuSpriteText selectorText;
private OsuSpriteText selectedText; private OsuSpriteText selectedText;
private OsuSpriteText leaveText; private OsuSpriteText leaveText;
@ -89,7 +92,7 @@ namespace osu.Game.Tests.Visual.Online
channelList.OnRequestSelect += channel => channelList.OnRequestSelect += channel =>
{ {
channelList.SelectorActive.Value = false; selector.Value = ChannelSelectorState.Hidden;
selected.Value = channel; selected.Value = channel;
}; };
@ -101,9 +104,9 @@ namespace osu.Game.Tests.Visual.Online
channelList.RemoveChannel(channel); channelList.RemoveChannel(channel);
}; };
channelList.SelectorActive.BindValueChanged(change => selector.BindValueChanged(change =>
{ {
selectorText.Text = $"Channel Selector Active: {change.NewValue}"; selectorText.Text = $"Channel Selector State: {change.NewValue}";
}, true); }, true);
selected.BindValueChanged(change => selected.BindValueChanged(change =>

View File

@ -14,7 +14,6 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osuTK;
namespace osu.Game.Overlays.Chat.ChannelList namespace osu.Game.Overlays.Chat.ChannelList
{ {
@ -57,7 +56,6 @@ namespace osu.Game.Overlays.Chat.ChannelList
new ChannelListSelector new ChannelListSelector
{ {
Margin = new MarginPadding { Bottom = 10 }, Margin = new MarginPadding { Bottom = 10 },
SelectorActive = { BindTarget = SelectorActive },
}, },
privateChannelFlow = new ChannelListItemFlow("DIRECT MESSAGES"), privateChannelFlow = new ChannelListItemFlow("DIRECT MESSAGES"),
}, },
@ -132,4 +130,10 @@ namespace osu.Game.Overlays.Chat.ChannelList
} }
} }
} }
public enum ChannelSelectorState
{
Visibile,
Hidden,
}
} }

View File

@ -31,14 +31,17 @@ namespace osu.Game.Overlays.Chat.ChannelList
private readonly Channel channel; private readonly Channel channel;
private Box? hoverBox; private Box hoverBox = null!;
private Box? selectBox; private Box selectBox = null!;
private OsuSpriteText? text; private OsuSpriteText text = null!;
private ChannelListItemCloseButton? close; private ChannelListItemCloseButton close = null!;
[Resolved] [Resolved]
private Bindable<Channel> selectedChannel { get; set; } = null!; private Bindable<Channel> selectedChannel { get; set; } = null!;
[Resolved]
private Bindable<ChannelSelectorState> selectorState { get; set; } = null!;
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!; private OverlayColourProvider colourProvider { get; set; } = null!;
@ -124,31 +127,26 @@ namespace osu.Game.Overlays.Chat.ChannelList
{ {
base.LoadComplete(); base.LoadComplete();
selectedChannel.BindValueChanged(change => selectedChannel.BindValueChanged(_ => updateSelectState(), true);
{ selectorState.BindValueChanged(_ => updateSelectState(), true);
if (change.NewValue == channel)
selectBox?.FadeIn(300, Easing.OutQuint);
else
selectBox?.FadeOut(200, Easing.OutQuint);
}, true);
Unread.BindValueChanged(change => Unread.BindValueChanged(change =>
{ {
text!.FadeColour(change.NewValue ? colourProvider.Content1 : colourProvider.Light3, 300, Easing.OutQuint); text.FadeColour(change.NewValue ? colourProvider.Content1 : colourProvider.Light3, 300, Easing.OutQuint);
}, true); }, true);
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
hoverBox?.FadeIn(300, Easing.OutQuint); hoverBox.FadeIn(300, Easing.OutQuint);
close?.FadeIn(300, Easing.OutQuint); close.FadeIn(300, Easing.OutQuint);
return base.OnHover(e); return base.OnHover(e);
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
hoverBox?.FadeOut(200, Easing.OutQuint); hoverBox.FadeOut(200, Easing.OutQuint);
close?.FadeOut(200, Easing.OutQuint); close.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e); base.OnHoverLost(e);
} }
@ -167,5 +165,13 @@ namespace osu.Game.Overlays.Chat.ChannelList
Masking = true, Masking = true,
}; };
} }
private void updateSelectState()
{
if (selectedChannel.Value == channel && selectorState.Value == ChannelSelectorState.Hidden)
selectBox.FadeIn(300, Easing.OutQuint);
else
selectBox.FadeOut(200, Easing.OutQuint);
}
} }
} }

View File

@ -22,6 +22,9 @@ namespace osu.Game.Overlays.Chat.ChannelList
private Box hoverBox = null!; private Box hoverBox = null!;
private Box selectBox = null!; private Box selectBox = null!;
[Resolved]
private Bindable<ChannelSelectorState> selectorState { get; set; } = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
{ {
@ -65,8 +68,15 @@ namespace osu.Game.Overlays.Chat.ChannelList
{ {
base.LoadComplete(); base.LoadComplete();
SelectorActive.BindValueChanged(selected => selectBox.FadeTo(selected.NewValue ? 1 : 0)); selectorState.BindValueChanged(selector =>
Action = () => SelectorActive.Value = true; {
if (selector.NewValue == ChannelSelectorState.Visibile)
selectBox.FadeIn(300, Easing.OutQuint);
else
selectBox.FadeOut(200, Easing.OutQuint);
}, true);
Action = () => selectorState.Value = ChannelSelectorState.Visibile;
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)