1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +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]
private readonly Bindable<Channel> selected = new Bindable<Channel>();
[Cached]
private readonly Bindable<ChannelSelectorState> selector = new Bindable<ChannelSelectorState>();
private OsuSpriteText selectorText;
private OsuSpriteText selectedText;
private OsuSpriteText leaveText;
@ -89,7 +92,7 @@ namespace osu.Game.Tests.Visual.Online
channelList.OnRequestSelect += channel =>
{
channelList.SelectorActive.Value = false;
selector.Value = ChannelSelectorState.Hidden;
selected.Value = channel;
};
@ -101,9 +104,9 @@ namespace osu.Game.Tests.Visual.Online
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);
selected.BindValueChanged(change =>

View File

@ -14,7 +14,6 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osuTK;
namespace osu.Game.Overlays.Chat.ChannelList
{
@ -57,7 +56,6 @@ namespace osu.Game.Overlays.Chat.ChannelList
new ChannelListSelector
{
Margin = new MarginPadding { Bottom = 10 },
SelectorActive = { BindTarget = SelectorActive },
},
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 Box? hoverBox;
private Box? selectBox;
private OsuSpriteText? text;
private ChannelListItemCloseButton? close;
private Box hoverBox = null!;
private Box selectBox = null!;
private OsuSpriteText text = null!;
private ChannelListItemCloseButton close = null!;
[Resolved]
private Bindable<Channel> selectedChannel { get; set; } = null!;
[Resolved]
private Bindable<ChannelSelectorState> selectorState { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
@ -124,31 +127,26 @@ namespace osu.Game.Overlays.Chat.ChannelList
{
base.LoadComplete();
selectedChannel.BindValueChanged(change =>
{
if (change.NewValue == channel)
selectBox?.FadeIn(300, Easing.OutQuint);
else
selectBox?.FadeOut(200, Easing.OutQuint);
}, true);
selectedChannel.BindValueChanged(_ => updateSelectState(), true);
selectorState.BindValueChanged(_ => updateSelectState(), true);
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);
}
protected override bool OnHover(HoverEvent e)
{
hoverBox?.FadeIn(300, Easing.OutQuint);
close?.FadeIn(300, Easing.OutQuint);
hoverBox.FadeIn(300, Easing.OutQuint);
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);
hoverBox.FadeOut(200, Easing.OutQuint);
close.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e);
}
@ -167,5 +165,13 @@ namespace osu.Game.Overlays.Chat.ChannelList
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 selectBox = null!;
[Resolved]
private Bindable<ChannelSelectorState> selectorState { get; set; } = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
@ -65,8 +68,15 @@ namespace osu.Game.Overlays.Chat.ChannelList
{
base.LoadComplete();
SelectorActive.BindValueChanged(selected => selectBox.FadeTo(selected.NewValue ? 1 : 0));
Action = () => SelectorActive.Value = true;
selectorState.BindValueChanged(selector =>
{
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)