mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:57:52 +08:00
Improve channel bindable logic in ChatOverlay
to avoid potential nullrefs
This commit is contained in:
parent
46e66e66e4
commit
7aae9bbd1b
@ -73,6 +73,10 @@ namespace osu.Game.Overlays
|
||||
private Container channelSelectionContainer;
|
||||
protected ChannelSelectionOverlay ChannelSelectionOverlay;
|
||||
|
||||
private readonly IBindableList<Channel> availableChannels = new BindableList<Channel>();
|
||||
private readonly IBindableList<Channel> joinedChannels = new BindableList<Channel>();
|
||||
private readonly Bindable<Channel> currentChannel = new Bindable<Channel>();
|
||||
|
||||
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos)
|
||||
|| (ChannelSelectionOverlay.State.Value == Visibility.Visible && ChannelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos));
|
||||
|
||||
@ -198,9 +202,13 @@ namespace osu.Game.Overlays
|
||||
},
|
||||
};
|
||||
|
||||
availableChannels.BindTo(channelManager.AvailableChannels);
|
||||
joinedChannels.BindTo(channelManager.JoinedChannels);
|
||||
currentChannel.BindTo(channelManager.CurrentChannel);
|
||||
|
||||
textBox.OnCommit += postMessage;
|
||||
|
||||
ChannelTabControl.Current.ValueChanged += current => channelManager.CurrentChannel.Value = current.NewValue;
|
||||
ChannelTabControl.Current.ValueChanged += current => currentChannel.Value = current.NewValue;
|
||||
ChannelTabControl.ChannelSelectorActive.ValueChanged += active => ChannelSelectionOverlay.State.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden;
|
||||
ChannelSelectionOverlay.State.ValueChanged += state =>
|
||||
{
|
||||
@ -238,18 +246,12 @@ namespace osu.Game.Overlays
|
||||
Schedule(() =>
|
||||
{
|
||||
// TODO: consider scheduling bindable callbacks to not perform when overlay is not present.
|
||||
channelManager.JoinedChannels.BindCollectionChanged(joinedChannelsChanged, true);
|
||||
|
||||
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
|
||||
availableChannelsChanged(null, null);
|
||||
|
||||
currentChannel = channelManager.CurrentChannel.GetBoundCopy();
|
||||
joinedChannels.BindCollectionChanged(joinedChannelsChanged, true);
|
||||
availableChannels.BindCollectionChanged(availableChannelsChanged, true);
|
||||
currentChannel.BindValueChanged(currentChannelChanged, true);
|
||||
});
|
||||
}
|
||||
|
||||
private Bindable<Channel> currentChannel;
|
||||
|
||||
private void currentChannelChanged(ValueChangedEvent<Channel> e)
|
||||
{
|
||||
if (e.NewValue == null)
|
||||
@ -318,7 +320,7 @@ namespace osu.Game.Overlays
|
||||
if (!channel.Joined.Value)
|
||||
channel = channelManager.JoinChannel(channel);
|
||||
|
||||
channelManager.CurrentChannel.Value = channel;
|
||||
currentChannel.Value = channel;
|
||||
}
|
||||
|
||||
channel.HighlightedMessage.Value = message;
|
||||
@ -407,7 +409,7 @@ namespace osu.Game.Overlays
|
||||
return true;
|
||||
|
||||
case PlatformAction.DocumentClose:
|
||||
channelManager.LeaveChannel(channelManager.CurrentChannel.Value);
|
||||
channelManager.LeaveChannel(currentChannel.Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -487,19 +489,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
|
||||
{
|
||||
ChannelSelectionOverlay.UpdateAvailableChannels(channelManager.AvailableChannels);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (channelManager != null)
|
||||
{
|
||||
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
|
||||
channelManager.JoinedChannels.CollectionChanged -= joinedChannelsChanged;
|
||||
channelManager.AvailableChannels.CollectionChanged -= availableChannelsChanged;
|
||||
}
|
||||
ChannelSelectionOverlay.UpdateAvailableChannels(availableChannels);
|
||||
}
|
||||
|
||||
private void postMessage(TextBox textBox, bool newText)
|
||||
|
Loading…
Reference in New Issue
Block a user