mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Merge branch 'master' into keyboard_shortcuts
This commit is contained in:
@ -190,13 +190,13 @@ namespace osu.Game.Overlays.Chat
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
updateMessageContent();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
updateMessageContent();
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
@ -24,7 +25,7 @@ namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public readonly Channel Channel;
|
||||
protected FillFlowContainer ChatLineFlow;
|
||||
private OsuScrollContainer scroll;
|
||||
private ChannelScrollContainer scroll;
|
||||
|
||||
private bool scrollbarVisible = true;
|
||||
|
||||
@ -56,7 +57,7 @@ namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
Child = scroll = new OsuScrollContainer
|
||||
Child = scroll = new ChannelScrollContainer
|
||||
{
|
||||
ScrollbarVisible = scrollbarVisible,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -80,12 +81,6 @@ namespace osu.Game.Overlays.Chat
|
||||
Channel.PendingMessageResolved += pendingMessageResolved;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
scrollToEnd();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
@ -103,7 +98,7 @@ namespace osu.Game.Overlays.Chat
|
||||
Colour = colours.ChatBlue.Lighten(0.7f),
|
||||
};
|
||||
|
||||
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
||||
private void newMessagesArrived(IEnumerable<Message> newMessages) => Schedule(() =>
|
||||
{
|
||||
if (newMessages.Min(m => m.Id) < chatLines.Max(c => c.Message.Id))
|
||||
{
|
||||
@ -113,8 +108,6 @@ namespace osu.Game.Overlays.Chat
|
||||
ChatLineFlow.Clear();
|
||||
}
|
||||
|
||||
bool shouldScrollToEnd = scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage);
|
||||
|
||||
// Add up to last Channel.MAX_HISTORY messages
|
||||
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
|
||||
|
||||
@ -153,11 +146,13 @@ namespace osu.Game.Overlays.Chat
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldScrollToEnd)
|
||||
scrollToEnd();
|
||||
}
|
||||
// due to the scroll adjusts from old messages removal above, a scroll-to-end must be enforced,
|
||||
// to avoid making the container think the user has scrolled back up and unwantedly disable auto-scrolling.
|
||||
if (newMessages.Any(m => m is LocalMessage))
|
||||
scroll.ScrollToEnd();
|
||||
});
|
||||
|
||||
private void pendingMessageResolved(Message existing, Message updated)
|
||||
private void pendingMessageResolved(Message existing, Message updated) => Schedule(() =>
|
||||
{
|
||||
var found = chatLines.LastOrDefault(c => c.Message == existing);
|
||||
|
||||
@ -169,17 +164,15 @@ namespace osu.Game.Overlays.Chat
|
||||
found.Message = updated;
|
||||
ChatLineFlow.Add(found);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
private void messageRemoved(Message removed)
|
||||
private void messageRemoved(Message removed) => Schedule(() =>
|
||||
{
|
||||
chatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire();
|
||||
}
|
||||
});
|
||||
|
||||
private IEnumerable<ChatLine> chatLines => ChatLineFlow.Children.OfType<ChatLine>();
|
||||
|
||||
private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd());
|
||||
|
||||
public class DaySeparator : Container
|
||||
{
|
||||
public float TextSize
|
||||
@ -243,5 +236,52 @@ namespace osu.Game.Overlays.Chat
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="OsuScrollContainer"/> with functionality to automatically scroll whenever the maximum scrollable distance increases.
|
||||
/// </summary>
|
||||
private class ChannelScrollContainer : UserTrackingScrollContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// The chat will be automatically scrolled to end if and only if
|
||||
/// the distance between the current scroll position and the end of the scroll
|
||||
/// is less than this value.
|
||||
/// </summary>
|
||||
private const float auto_scroll_leniency = 10f;
|
||||
|
||||
private float? lastExtent;
|
||||
|
||||
protected override void OnUserScroll(float value, bool animated = true, double? distanceDecay = default)
|
||||
{
|
||||
base.OnUserScroll(value, animated, distanceDecay);
|
||||
lastExtent = null;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
// If the user has scrolled to the bottom of the container, we should resume tracking new content.
|
||||
if (UserScrolling && IsScrolledToEnd(auto_scroll_leniency))
|
||||
CancelUserScroll();
|
||||
|
||||
// If the user hasn't overridden our behaviour and there has been new content added to the container, we should update our scroll position to track it.
|
||||
bool requiresScrollUpdate = !UserScrolling && (lastExtent == null || Precision.AlmostBigger(ScrollableExtent, lastExtent.Value));
|
||||
|
||||
if (requiresScrollUpdate)
|
||||
{
|
||||
// Schedule required to allow FillFlow to be the correct size.
|
||||
Schedule(() =>
|
||||
{
|
||||
if (!UserScrolling)
|
||||
{
|
||||
if (Current < ScrollableExtent)
|
||||
ScrollToEnd();
|
||||
lastExtent = ScrollableExtent;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,19 +4,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osuTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Chat.Selection
|
||||
{
|
||||
public class ChannelSection : Container, IHasFilterableChildren
|
||||
{
|
||||
private readonly OsuSpriteText header;
|
||||
|
||||
public readonly FillFlowContainer<ChannelListItem> ChannelFlow;
|
||||
|
||||
public IEnumerable<IFilterable> FilterableChildren => ChannelFlow.Children;
|
||||
@ -29,12 +27,6 @@ namespace osu.Game.Overlays.Chat.Selection
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
|
||||
public string Header
|
||||
{
|
||||
get => header.Text;
|
||||
set => header.Text = value.ToUpperInvariant();
|
||||
}
|
||||
|
||||
public IEnumerable<Channel> Channels
|
||||
{
|
||||
set => ChannelFlow.ChildrenEnumerable = value.Select(c => new ChannelListItem(c));
|
||||
@ -47,9 +39,10 @@ namespace osu.Game.Overlays.Chat.Selection
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
header = new OsuSpriteText
|
||||
new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold),
|
||||
Text = "All Channels".ToUpperInvariant()
|
||||
},
|
||||
ChannelFlow = new FillFlowContainer<ChannelListItem>
|
||||
{
|
||||
|
@ -131,11 +131,7 @@ namespace osu.Game.Overlays.Chat.Selection
|
||||
{
|
||||
sectionsFlow.ChildrenEnumerable = new[]
|
||||
{
|
||||
new ChannelSection
|
||||
{
|
||||
Header = "All Channels",
|
||||
Channels = channels,
|
||||
},
|
||||
new ChannelSection { Channels = channels, },
|
||||
};
|
||||
|
||||
foreach (ChannelSection s in sectionsFlow.Children)
|
||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
if (value.Type != ChannelType.PM)
|
||||
throw new ArgumentException("Argument value needs to have the targettype user!");
|
||||
|
||||
DrawableAvatar avatar;
|
||||
ClickableAvatar avatar;
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Masking = true,
|
||||
Child = new DelayedLoadWrapper(avatar = new DrawableAvatar(value.Users.First())
|
||||
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
OpenOnClick = { Value = false },
|
||||
|
Reference in New Issue
Block a user