2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2016-10-07 15:43:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-09-01 02:56:23 +00:00
|
|
|
|
using System.Collections.Specialized;
|
2022-03-10 19:54:47 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-12-20 12:06:40 +00:00
|
|
|
|
using System.Linq;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2016-11-08 23:13:20 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2016-10-07 15:43:06 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-02-19 09:02:25 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-05-12 04:54:02 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2017-05-12 05:21:57 +00:00
|
|
|
|
using osu.Game.Graphics;
|
2017-06-28 17:18:12 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-08-21 08:43:26 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
using osu.Game.Overlays.Chat;
|
2018-07-09 17:42:57 +00:00
|
|
|
|
using osu.Game.Overlays.Chat.Selection;
|
2018-07-29 19:18:37 +00:00
|
|
|
|
using osu.Game.Overlays.Chat.Tabs;
|
2018-12-20 12:06:40 +00:00
|
|
|
|
using osuTK.Input;
|
2019-10-06 17:22:55 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-09-17 21:56:08 +00:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-06-03 06:04:07 +00:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-04-21 05:37:11 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
|
using osu.Game.Localisation;
|
2021-02-18 08:46:07 +00:00
|
|
|
|
using osu.Game.Online;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2016-10-07 15:43:06 +00:00
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2021-06-03 06:04:07 +00:00
|
|
|
|
public class ChatOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent, IKeyBindingHandler<PlatformAction>
|
2016-10-07 15:43:06 +00:00
|
|
|
|
{
|
2020-09-03 07:26:09 +00:00
|
|
|
|
public string IconTexture => "Icons/Hexacons/messaging";
|
2021-04-21 05:37:11 +00:00
|
|
|
|
public LocalisableString Title => ChatStrings.HeaderTitle;
|
|
|
|
|
public LocalisableString Description => ChatStrings.HeaderDescription;
|
2020-09-03 06:46:56 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
private const float text_box_height = 60;
|
2017-05-30 00:23:03 +00:00
|
|
|
|
private const float channel_selection_min_height = 0.3f;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private ChannelManager channelManager { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-20 14:02:02 +00:00
|
|
|
|
private Container<DrawableChannel> currentChannelContainer;
|
|
|
|
|
|
2018-07-09 16:23:40 +00:00
|
|
|
|
private readonly List<DrawableChannel> loadedChannels = new List<DrawableChannel>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-21 06:33:31 +00:00
|
|
|
|
private LoadingSpinner loading;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
private FocusedTextBox textBox;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-19 10:15:21 +00:00
|
|
|
|
private const int transition_length = 500;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 04:54:02 +00:00
|
|
|
|
public const float DEFAULT_HEIGHT = 0.4f;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 06:32:52 +00:00
|
|
|
|
public const float TAB_AREA_HEIGHT = 50;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-25 10:52:31 +00:00
|
|
|
|
protected ChannelTabControl ChannelTabControl;
|
|
|
|
|
|
|
|
|
|
protected virtual ChannelTabControl CreateChannelTabControl() => new ChannelTabControl();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-20 14:02:02 +00:00
|
|
|
|
private Container chatContainer;
|
|
|
|
|
private TabsArea tabsArea;
|
|
|
|
|
private Box chatBackground;
|
|
|
|
|
private Box tabBackground;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-02 22:50:52 +00:00
|
|
|
|
public Bindable<float> ChatHeight { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-20 14:02:02 +00:00
|
|
|
|
private Container channelSelectionContainer;
|
2019-06-25 10:52:31 +00:00
|
|
|
|
protected ChannelSelectionOverlay ChannelSelectionOverlay;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-17 05:31:38 +00:00
|
|
|
|
private readonly IBindableList<Channel> availableChannels = new BindableList<Channel>();
|
|
|
|
|
private readonly IBindableList<Channel> joinedChannels = new BindableList<Channel>();
|
|
|
|
|
private readonly Bindable<Channel> currentChannel = new Bindable<Channel>();
|
|
|
|
|
|
2019-06-25 10:52:31 +00:00
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos)
|
|
|
|
|
|| (ChannelSelectionOverlay.State.Value == Visibility.Visible && ChannelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2016-11-30 06:15:43 +00:00
|
|
|
|
public ChatOverlay()
|
2016-10-07 15:43:06 +00:00
|
|
|
|
{
|
2017-05-12 04:54:02 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
RelativePositionAxes = Axes.Both;
|
2016-10-07 15:43:06 +00:00
|
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
|
Origin = Anchor.BottomLeft;
|
2019-06-20 14:02:02 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-20 14:02:02 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-09-17 21:56:08 +00:00
|
|
|
|
private void load(OsuConfigManager config, OsuColour colours, TextureStore textures)
|
2019-06-20 14:02:02 +00:00
|
|
|
|
{
|
2017-05-12 05:22:11 +00:00
|
|
|
|
const float padding = 5;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-11 14:10:48 +00:00
|
|
|
|
Children = new Drawable[]
|
2016-10-07 15:43:06 +00:00
|
|
|
|
{
|
2017-06-02 04:00:09 +00:00
|
|
|
|
channelSelectionContainer = new Container
|
2017-05-21 00:26:39 +00:00
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 1f - DEFAULT_HEIGHT,
|
2017-06-02 04:00:09 +00:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelSelectionOverlay = new ChannelSelectionOverlay
|
2017-06-02 04:00:09 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-05-21 00:26:39 +00:00
|
|
|
|
},
|
2017-05-30 00:23:03 +00:00
|
|
|
|
chatContainer = new Container
|
2017-02-19 09:02:25 +00:00
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
Name = @"chat container",
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2017-05-12 05:22:11 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-30 00:23:03 +00:00
|
|
|
|
Height = DEFAULT_HEIGHT,
|
|
|
|
|
Children = new[]
|
2017-02-19 09:02:25 +00:00
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
new Container
|
2017-02-19 09:02:25 +00:00
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
Name = @"chat area",
|
2017-02-20 12:11:09 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-30 00:23:03 +00:00
|
|
|
|
Padding = new MarginPadding { Top = TAB_AREA_HEIGHT },
|
|
|
|
|
Children = new Drawable[]
|
2017-05-12 05:22:11 +00:00
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
chatBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2021-02-18 08:46:07 +00:00
|
|
|
|
new OnlineViewContainer("Sign in to chat")
|
2017-05-30 00:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-02-18 08:46:07 +00:00
|
|
|
|
currentChannelContainer = new Container<DrawableChannel>
|
2017-05-30 00:23:03 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-02-18 08:46:07 +00:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
Bottom = text_box_height
|
2021-02-18 08:46:07 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-12-10 05:15:00 +00:00
|
|
|
|
Height = text_box_height,
|
2021-02-18 08:46:07 +00:00
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = padding * 2,
|
|
|
|
|
Bottom = padding * 2,
|
|
|
|
|
Left = ChatLine.LEFT_PADDING + padding * 2,
|
|
|
|
|
Right = padding * 2,
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox = new FocusedTextBox
|
2021-02-18 08:46:07 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 1,
|
2022-01-28 04:53:48 +00:00
|
|
|
|
PlaceholderText = Resources.Localisation.Web.ChatStrings.InputPlaceholder,
|
2021-02-18 08:46:07 +00:00
|
|
|
|
ReleaseFocusOnCommit = false,
|
|
|
|
|
HoldFocus = true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
loading = new LoadingSpinner(),
|
|
|
|
|
},
|
|
|
|
|
}
|
2017-05-30 00:23:03 +00:00
|
|
|
|
}
|
2017-05-12 05:22:11 +00:00
|
|
|
|
},
|
2018-10-02 05:41:18 +00:00
|
|
|
|
tabsArea = new TabsArea
|
2017-05-12 05:22:11 +00:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-30 00:23:03 +00:00
|
|
|
|
tabBackground = new Box
|
2017-05-12 05:22:11 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-05-30 00:23:03 +00:00
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
},
|
2020-09-17 21:56:08 +00:00
|
|
|
|
new Sprite
|
2019-10-06 17:22:55 +00:00
|
|
|
|
{
|
2020-09-17 21:56:08 +00:00
|
|
|
|
Texture = textures.Get(IconTexture),
|
2019-10-06 17:22:55 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-09-17 21:56:08 +00:00
|
|
|
|
Size = new Vector2(OverlayTitle.ICON_SIZE),
|
|
|
|
|
Margin = new MarginPadding { Left = 10 },
|
2019-10-06 17:22:55 +00:00
|
|
|
|
},
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelTabControl = CreateChannelTabControl().With(d =>
|
2019-06-26 10:25:54 +00:00
|
|
|
|
{
|
|
|
|
|
d.Anchor = Anchor.BottomLeft;
|
|
|
|
|
d.Origin = Anchor.BottomLeft;
|
|
|
|
|
d.RelativeSizeAxes = Axes.Both;
|
|
|
|
|
d.OnRequestLeave = channelManager.LeaveChannel;
|
2019-12-23 03:47:47 +00:00
|
|
|
|
d.IsSwitchable = true;
|
2019-06-26 10:25:54 +00:00
|
|
|
|
}),
|
2017-05-12 05:22:11 +00:00
|
|
|
|
}
|
2017-05-12 06:32:52 +00:00
|
|
|
|
},
|
2017-05-30 00:23:03 +00:00
|
|
|
|
},
|
2017-05-12 06:32:52 +00:00
|
|
|
|
},
|
2017-05-11 14:10:48 +00:00
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-17 05:31:38 +00:00
|
|
|
|
availableChannels.BindTo(channelManager.AvailableChannels);
|
|
|
|
|
joinedChannels.BindTo(channelManager.JoinedChannels);
|
|
|
|
|
currentChannel.BindTo(channelManager.CurrentChannel);
|
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.OnCommit += postMessage;
|
2020-10-01 03:51:33 +00:00
|
|
|
|
|
2022-03-17 05:31:38 +00:00
|
|
|
|
ChannelTabControl.Current.ValueChanged += current => currentChannel.Value = current.NewValue;
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelTabControl.ChannelSelectorActive.ValueChanged += active => ChannelSelectionOverlay.State.Value = active.NewValue ? Visibility.Visible : Visibility.Hidden;
|
|
|
|
|
ChannelSelectionOverlay.State.ValueChanged += state =>
|
2017-05-30 00:23:03 +00:00
|
|
|
|
{
|
2019-06-25 10:52:31 +00:00
|
|
|
|
// Propagate the visibility state to ChannelSelectorActive
|
|
|
|
|
ChannelTabControl.ChannelSelectorActive.Value = state.NewValue == Visibility.Visible;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-11 05:28:52 +00:00
|
|
|
|
if (state.NewValue == Visibility.Visible)
|
2017-06-01 01:29:52 +00:00
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.HoldFocus = false;
|
2017-09-12 16:47:21 +00:00
|
|
|
|
if (1f - ChatHeight.Value < channel_selection_min_height)
|
2018-05-02 09:26:23 +00:00
|
|
|
|
this.TransformBindableTo(ChatHeight, 1f - channel_selection_min_height, 800, Easing.OutQuint);
|
2017-06-01 08:17:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.HoldFocus = true;
|
2017-05-30 00:23:03 +00:00
|
|
|
|
};
|
2018-11-13 06:20:40 +00:00
|
|
|
|
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelSelectionOverlay.OnRequestJoin = channel => channelManager.JoinChannel(channel);
|
|
|
|
|
ChannelSelectionOverlay.OnRequestLeave = channelManager.LeaveChannel;
|
2019-06-20 14:02:02 +00:00
|
|
|
|
|
2019-09-02 22:50:52 +00:00
|
|
|
|
ChatHeight = config.GetBindable<float>(OsuSetting.ChatDisplayHeight);
|
|
|
|
|
ChatHeight.BindValueChanged(height =>
|
2019-06-20 14:02:02 +00:00
|
|
|
|
{
|
2019-09-02 22:50:52 +00:00
|
|
|
|
chatContainer.Height = height.NewValue;
|
|
|
|
|
channelSelectionContainer.Height = 1f - height.NewValue;
|
|
|
|
|
tabBackground.FadeTo(height.NewValue == 1f ? 1f : 0.8f, 200);
|
|
|
|
|
}, true);
|
2019-06-20 14:02:02 +00:00
|
|
|
|
|
|
|
|
|
chatBackground.Colour = colours.ChatBlue;
|
|
|
|
|
|
|
|
|
|
loading.Show();
|
|
|
|
|
|
|
|
|
|
// This is a relatively expensive (and blocking) operation.
|
|
|
|
|
// Scheduling it ensures that it won't be performed unless the user decides to open chat.
|
|
|
|
|
// TODO: Refactor OsuFocusedOverlayContainer / OverlayContainer to support delayed content loading.
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
// TODO: consider scheduling bindable callbacks to not perform when overlay is not present.
|
2022-03-17 05:31:38 +00:00
|
|
|
|
joinedChannels.BindCollectionChanged(joinedChannelsChanged, true);
|
|
|
|
|
availableChannels.BindCollectionChanged(availableChannelsChanged, true);
|
2019-06-20 14:02:02 +00:00
|
|
|
|
currentChannel.BindValueChanged(currentChannelChanged, true);
|
|
|
|
|
});
|
2018-04-14 11:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void currentChannelChanged(ValueChangedEvent<Channel> e)
|
2018-04-14 11:31:03 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (e.NewValue == null)
|
2018-04-14 11:31:03 +00:00
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.Current.Disabled = true;
|
2018-07-09 18:13:34 +00:00
|
|
|
|
currentChannelContainer.Clear(false);
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelSelectionOverlay.Show();
|
2018-04-14 11:31:03 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-11 23:21:12 +00:00
|
|
|
|
|
2019-05-12 10:31:11 +00:00
|
|
|
|
if (e.NewValue is ChannelSelectorTabItem.ChannelSelectorTabChannel)
|
2019-05-11 23:16:15 +00:00
|
|
|
|
return;
|
2018-04-14 11:31:03 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.Current.Disabled = e.NewValue.ReadOnly;
|
2018-04-14 11:31:03 +00:00
|
|
|
|
|
2019-06-25 10:52:31 +00:00
|
|
|
|
if (ChannelTabControl.Current.Value != e.NewValue)
|
|
|
|
|
Scheduler.Add(() => ChannelTabControl.Current.Value = e.NewValue);
|
2018-04-14 11:31:03 +00:00
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
var loaded = loadedChannels.Find(d => d.Channel == e.NewValue);
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-04-14 11:31:03 +00:00
|
|
|
|
if (loaded == null)
|
|
|
|
|
{
|
2018-07-09 18:13:34 +00:00
|
|
|
|
currentChannelContainer.FadeOut(500, Easing.OutQuint);
|
2018-04-14 11:31:03 +00:00
|
|
|
|
loading.Show();
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
loaded = new DrawableChannel(e.NewValue);
|
2018-04-14 11:31:03 +00:00
|
|
|
|
loadedChannels.Add(loaded);
|
|
|
|
|
LoadComponentAsync(loaded, l =>
|
|
|
|
|
{
|
2019-08-05 10:23:13 +00:00
|
|
|
|
if (currentChannel.Value != e.NewValue)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-10-04 06:35:28 +00:00
|
|
|
|
// check once more to ensure the channel hasn't since been removed from the loaded channels list (may have been left by some automated means).
|
2021-10-05 18:53:06 +00:00
|
|
|
|
if (!loadedChannels.Contains(loaded))
|
2021-10-04 05:44:16 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-04-14 11:31:03 +00:00
|
|
|
|
loading.Hide();
|
|
|
|
|
|
2018-07-09 18:13:34 +00:00
|
|
|
|
currentChannelContainer.Clear(false);
|
|
|
|
|
currentChannelContainer.Add(loaded);
|
|
|
|
|
currentChannelContainer.FadeIn(500, Easing.OutQuint);
|
2018-04-14 11:31:03 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-07-09 18:13:34 +00:00
|
|
|
|
currentChannelContainer.Clear(false);
|
2018-12-20 12:06:40 +00:00
|
|
|
|
currentChannelContainer.Add(loaded);
|
2018-04-14 11:31:03 +00:00
|
|
|
|
}
|
2020-01-03 23:50:12 +00:00
|
|
|
|
|
|
|
|
|
// mark channel as read when channel switched
|
|
|
|
|
if (e.NewValue.Messages.Any())
|
2020-01-11 16:42:02 +00:00
|
|
|
|
channelManager.MarkChannelAsRead(e.NewValue);
|
2016-10-07 15:43:06 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-03-04 20:28:40 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Highlights a certain message in the specified channel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message">The message to highlight.</param>
|
2022-03-10 19:54:47 +00:00
|
|
|
|
/// <param name="channel">The channel containing the message.</param>
|
|
|
|
|
public void HighlightMessage(Message message, Channel channel)
|
2022-03-04 20:28:40 +00:00
|
|
|
|
{
|
2022-03-10 19:54:47 +00:00
|
|
|
|
Debug.Assert(channel.Id == message.ChannelId);
|
2022-03-04 20:28:40 +00:00
|
|
|
|
|
2022-04-08 15:31:00 +00:00
|
|
|
|
if (currentChannel.Value?.Id != channel.Id)
|
2022-03-10 18:29:32 +00:00
|
|
|
|
{
|
2022-03-10 19:54:47 +00:00
|
|
|
|
if (!channel.Joined.Value)
|
|
|
|
|
channel = channelManager.JoinChannel(channel);
|
2022-03-10 18:29:32 +00:00
|
|
|
|
|
2022-03-17 05:31:38 +00:00
|
|
|
|
currentChannel.Value = channel;
|
2022-03-10 18:29:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 19:54:47 +00:00
|
|
|
|
channel.HighlightedMessage.Value = message;
|
2022-04-08 16:27:59 +00:00
|
|
|
|
|
|
|
|
|
Show();
|
2022-03-04 20:28:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-02 22:50:52 +00:00
|
|
|
|
private float startDragChatHeight;
|
2017-07-27 13:33:10 +00:00
|
|
|
|
private bool isDragging;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
2017-05-12 04:54:02 +00:00
|
|
|
|
{
|
2017-07-27 13:33:10 +00:00
|
|
|
|
isDragging = tabsArea.IsHovered;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-07-27 13:33:10 +00:00
|
|
|
|
if (!isDragging)
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnDragStart(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-12 16:47:21 +00:00
|
|
|
|
startDragChatHeight = ChatHeight.Value;
|
2017-05-28 12:11:46 +00:00
|
|
|
|
return true;
|
2017-05-12 04:54:02 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-20 09:17:21 +00:00
|
|
|
|
protected override void OnDrag(DragEvent e)
|
2017-05-12 04:54:02 +00:00
|
|
|
|
{
|
2017-07-27 13:33:10 +00:00
|
|
|
|
if (isDragging)
|
2017-07-21 10:37:22 +00:00
|
|
|
|
{
|
2019-09-02 22:50:52 +00:00
|
|
|
|
float targetChatHeight = startDragChatHeight - (e.MousePosition.Y - e.MouseDownPosition.Y) / Parent.DrawSize.Y;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-08 16:21:42 +00:00
|
|
|
|
// If the channel selection screen is shown, mind its minimum height
|
2019-06-25 10:52:31 +00:00
|
|
|
|
if (ChannelSelectionOverlay.State.Value == Visibility.Visible && targetChatHeight > 1f - channel_selection_min_height)
|
2017-09-08 16:21:42 +00:00
|
|
|
|
targetChatHeight = 1f - channel_selection_min_height;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-12 16:47:21 +00:00
|
|
|
|
ChatHeight.Value = targetChatHeight;
|
2017-07-21 10:37:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-01-20 09:17:21 +00:00
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
2017-07-21 10:37:22 +00:00
|
|
|
|
{
|
2017-07-27 13:33:10 +00:00
|
|
|
|
isDragging = false;
|
2020-01-20 09:17:21 +00:00
|
|
|
|
base.OnDragEnd(e);
|
2017-05-12 04:54:02 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
private void selectTab(int index)
|
|
|
|
|
{
|
2020-01-30 20:44:53 +00:00
|
|
|
|
var channel = ChannelTabControl.Items
|
|
|
|
|
.Where(tab => !(tab is ChannelSelectorTabItem.ChannelSelectorTabChannel))
|
2020-01-31 16:19:04 +00:00
|
|
|
|
.ElementAtOrDefault(index);
|
2020-01-30 20:44:53 +00:00
|
|
|
|
if (channel != null)
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelTabControl.Current.Value = channel;
|
2018-12-20 12:06:40 +00:00
|
|
|
|
}
|
2020-12-13 02:11:57 +00:00
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.AltPressed)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Number1:
|
|
|
|
|
case Key.Number2:
|
|
|
|
|
case Key.Number3:
|
|
|
|
|
case Key.Number4:
|
|
|
|
|
case Key.Number5:
|
|
|
|
|
case Key.Number6:
|
|
|
|
|
case Key.Number7:
|
|
|
|
|
case Key.Number8:
|
|
|
|
|
case Key.Number9:
|
|
|
|
|
selectTab((int)e.Key - (int)Key.Number1);
|
|
|
|
|
return true;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-12-20 12:06:40 +00:00
|
|
|
|
case Key.Number0:
|
|
|
|
|
selectTab(9);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-12 23:53:08 +00:00
|
|
|
|
|
2021-06-03 06:04:07 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
|
2021-06-03 06:04:07 +00:00
|
|
|
|
{
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2020-12-12 05:52:36 +00:00
|
|
|
|
{
|
2021-07-20 05:23:34 +00:00
|
|
|
|
case PlatformAction.TabNew:
|
2021-06-03 06:04:07 +00:00
|
|
|
|
ChannelTabControl.SelectChannelSelectorTab();
|
|
|
|
|
return true;
|
|
|
|
|
|
2021-07-20 05:23:34 +00:00
|
|
|
|
case PlatformAction.TabRestore:
|
2021-06-03 06:04:07 +00:00
|
|
|
|
channelManager.JoinLastClosedChannel();
|
|
|
|
|
return true;
|
|
|
|
|
|
2021-07-20 05:23:34 +00:00
|
|
|
|
case PlatformAction.DocumentClose:
|
2022-03-17 05:31:38 +00:00
|
|
|
|
channelManager.LeaveChannel(currentChannel.Value);
|
2021-06-03 06:04:07 +00:00
|
|
|
|
return true;
|
2020-12-12 05:52:36 +00:00
|
|
|
|
}
|
2018-12-20 12:06:40 +00:00
|
|
|
|
|
2021-06-03 06:04:07 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
|
2021-06-03 06:04:07 +00:00
|
|
|
|
{
|
2018-12-20 12:06:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 07:33:26 +00:00
|
|
|
|
public override bool AcceptsFocus => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
2017-02-20 12:11:09 +00:00
|
|
|
|
{
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// this is necessary as textbox is masked away and therefore can't get focus :(
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.TakeFocus();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnFocus(e);
|
2017-02-20 12:11:09 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-19 10:15:21 +00:00
|
|
|
|
protected override void PopIn()
|
2017-02-19 09:02:25 +00:00
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.MoveToY(0, transition_length, Easing.OutQuint);
|
|
|
|
|
this.FadeIn(transition_length, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.HoldFocus = true;
|
2019-06-25 10:52:31 +00:00
|
|
|
|
|
2017-05-11 09:27:14 +00:00
|
|
|
|
base.PopIn();
|
2017-04-19 10:15:21 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-04-19 10:15:21 +00:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-07-22 18:50:25 +00:00
|
|
|
|
this.MoveToY(Height, transition_length, Easing.InSine);
|
|
|
|
|
this.FadeOut(transition_length, Easing.InSine);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-06-25 10:52:31 +00:00
|
|
|
|
ChannelSelectionOverlay.Hide();
|
2019-03-12 03:10:59 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.HoldFocus = false;
|
2017-05-11 09:27:14 +00:00
|
|
|
|
base.PopOut();
|
2017-02-19 09:02:25 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-04 05:58:54 +00:00
|
|
|
|
private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
|
2018-11-21 18:15:55 +00:00
|
|
|
|
{
|
2020-09-01 02:56:23 +00:00
|
|
|
|
switch (args.Action)
|
2018-11-21 18:15:55 +00:00
|
|
|
|
{
|
2020-09-01 02:56:23 +00:00
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
|
|
|
|
foreach (Channel channel in args.NewItems.Cast<Channel>())
|
2021-12-16 07:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (channel.Type != ChannelType.Multiplayer)
|
|
|
|
|
ChannelTabControl.AddChannel(channel);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
break;
|
2019-08-05 10:23:13 +00:00
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
case NotifyCollectionChangedAction.Remove:
|
|
|
|
|
foreach (Channel channel in args.OldItems.Cast<Channel>())
|
|
|
|
|
{
|
2021-12-16 07:41:47 +00:00
|
|
|
|
if (!ChannelTabControl.Items.Contains(channel))
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
ChannelTabControl.RemoveChannel(channel);
|
2019-08-05 10:23:13 +00:00
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
var loaded = loadedChannels.Find(c => c.Channel == channel);
|
2019-08-05 10:23:13 +00:00
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
if (loaded != null)
|
|
|
|
|
{
|
|
|
|
|
// Because the container is only cleared in the async load callback of a new channel, it is forcefully cleared
|
|
|
|
|
// to ensure that the previous channel doesn't get updated after it's disposed
|
2021-10-04 05:44:16 +00:00
|
|
|
|
loadedChannels.Remove(loaded);
|
2020-09-01 02:56:23 +00:00
|
|
|
|
currentChannelContainer.Remove(loaded);
|
|
|
|
|
loaded.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2018-11-21 18:15:55 +00:00
|
|
|
|
}
|
2021-10-04 05:58:54 +00:00
|
|
|
|
}
|
2018-09-06 06:56:04 +00:00
|
|
|
|
|
2020-09-01 02:56:23 +00:00
|
|
|
|
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
|
|
|
|
|
{
|
2022-03-17 05:31:38 +00:00
|
|
|
|
ChannelSelectionOverlay.UpdateAvailableChannels(availableChannels);
|
2018-09-06 06:56:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
private void postMessage(TextBox textBox, bool newText)
|
2016-10-13 14:57:05 +00:00
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
string text = textBox.Text.Trim();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-04-14 11:31:03 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
2017-05-16 10:55:45 +00:00
|
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-04-14 11:31:03 +00:00
|
|
|
|
if (text[0] == '/')
|
|
|
|
|
channelManager.PostCommand(text.Substring(1));
|
|
|
|
|
else
|
|
|
|
|
channelManager.PostMessage(text);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
|
textBox.Text = string.Empty;
|
2016-11-30 06:15:43 +00:00
|
|
|
|
}
|
2018-10-02 05:41:18 +00:00
|
|
|
|
|
|
|
|
|
private class TabsArea : Container
|
|
|
|
|
{
|
|
|
|
|
// IsHovered is used
|
|
|
|
|
public override bool HandlePositionalInput => true;
|
|
|
|
|
|
|
|
|
|
public TabsArea()
|
|
|
|
|
{
|
|
|
|
|
Name = @"tabs area";
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = TAB_AREA_HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-07 15:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|