mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 17:22:58 +08:00
Refactor and general tidying up
This commit is contained in:
parent
128603a99f
commit
7454633f63
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Chat;
|
using osu.Game.Overlays.Chat;
|
||||||
@ -51,13 +52,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
var newLine = new ChatLine(new DummyMessage(text, isAction));
|
var newLine = new ChatLine(new DummyMessage(text, isAction));
|
||||||
textContainer.Add(newLine);
|
textContainer.Add(newLine);
|
||||||
|
|
||||||
AddAssert($"check msg having {linkAmount} link(s)", () => newLine.Message.Links.Count == linkAmount);
|
AddAssert($"msg #{textContainer.Count} has {linkAmount} link(s)", () => newLine.Message.Links.Count == linkAmount);
|
||||||
// todo: tidy this lambda up
|
AddAssert($"msg #{textContainer.Count} shows link(s)", () => newLine.ContentFlow.Any() && isShowingLinks(newLine.ContentFlow));
|
||||||
AddAssert("check link(s) displaying", () => newLine.ContentFlow.Any()
|
|
||||||
&& newLine.ContentFlow
|
bool isShowingLinks(OsuTextFlowContainer c) => c.Cast<ChatLink>().All(sprite => sprite.HandleInput && !sprite.TextColour.Equals((SRGBColour)Color4.White)
|
||||||
.Cast<ChatLink>()
|
|| !sprite.HandleInput && sprite.TextColour.Equals((SRGBColour)Color4.White));
|
||||||
.All(sprite => sprite.HandleInput && !sprite.TextColour.Equals((SRGBColour)Color4.White)
|
|
||||||
|| !sprite.HandleInput && sprite.TextColour.Equals((SRGBColour)Color4.White)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testLinksGeneral()
|
private void testLinksGeneral()
|
||||||
|
59
osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs
Normal file
59
osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Graphics.Colour;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.Containers
|
||||||
|
{
|
||||||
|
public class OsuLinkFlowContainer : OsuLinkFlowContainer<OsuSpriteLink>
|
||||||
|
{
|
||||||
|
public OsuLinkFlowContainer(Action<SpriteText> defaultCreationParameters = null)
|
||||||
|
: base(defaultCreationParameters)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OsuLinkFlowContainer<T> : OsuTextFlowContainer
|
||||||
|
where T : OsuSpriteLink, new()
|
||||||
|
{
|
||||||
|
public override bool HandleInput => true;
|
||||||
|
|
||||||
|
public OsuLinkFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override SpriteText CreateSpriteText() => new T();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The colour for text (links override this). Will only be used for new text elements.
|
||||||
|
/// </summary>
|
||||||
|
public ColourInfo TextColour = Color4.White;
|
||||||
|
|
||||||
|
public IEnumerable<SpriteText> AddLink(string text, string url, Action<SpriteText> creationParameters = null)
|
||||||
|
{
|
||||||
|
// TODO: Remove this and get word wrapping working
|
||||||
|
text = text.Replace(' ', '_');
|
||||||
|
|
||||||
|
return AddText(text, link =>
|
||||||
|
{
|
||||||
|
creationParameters?.Invoke(link);
|
||||||
|
((T)link).Url = url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public new IEnumerable<SpriteText> AddText(string text, Action<SpriteText> creationParameters = null)
|
||||||
|
{
|
||||||
|
return base.AddText(text, sprite =>
|
||||||
|
{
|
||||||
|
((OsuSpriteLink)sprite).TextColour = TextColour;
|
||||||
|
|
||||||
|
creationParameters?.Invoke(sprite);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
||||||
|
|
||||||
using osu.Framework.Graphics.Colour;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers
|
|
||||||
{
|
|
||||||
public class OsuLinkTextFlowContainer : OsuLinkTextFlowContainer<OsuLinkSpriteText>
|
|
||||||
{
|
|
||||||
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null)
|
|
||||||
: base(defaultCreationParameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class OsuLinkTextFlowContainer<T> : OsuTextFlowContainer
|
|
||||||
where T : OsuLinkSpriteText, new()
|
|
||||||
{
|
|
||||||
public override bool HandleInput => true;
|
|
||||||
|
|
||||||
public OsuLinkTextFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override SpriteText CreateSpriteText() => new T();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The colour for normal text (links ignore this). Will only be used for new text elements.
|
|
||||||
/// <para>Default is white.</para>
|
|
||||||
/// </summary>
|
|
||||||
public ColourInfo? TextColour;
|
|
||||||
|
|
||||||
public void AddLink(string text, string url, Action<SpriteText> creationParameters = null)
|
|
||||||
{
|
|
||||||
// TODO: Remove this and get word wrapping working
|
|
||||||
text = text.Replace(' ', '_');
|
|
||||||
|
|
||||||
AddText(text, link =>
|
|
||||||
{
|
|
||||||
creationParameters?.Invoke(link);
|
|
||||||
LoadComponentAsync(link, d => ((T)d).Url = url);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<SpriteText> AddText(string text, Action<SpriteText> creationParameters = null)
|
|
||||||
{
|
|
||||||
return base.AddText(text, sprite =>
|
|
||||||
{
|
|
||||||
if (TextColour.HasValue)
|
|
||||||
((OsuLinkSpriteText)sprite).TextColour = TextColour.Value;
|
|
||||||
|
|
||||||
creationParameters?.Invoke(sprite);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ using osu.Game.Graphics.Containers;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.Sprites
|
namespace osu.Game.Graphics.Sprites
|
||||||
{
|
{
|
||||||
public class OsuLinkSpriteText : OsuSpriteText
|
public class OsuSpriteLink : OsuSpriteText
|
||||||
{
|
{
|
||||||
protected override IEnumerable<Drawable> FlowingChildren => Children;
|
protected override IEnumerable<Drawable> FlowingChildren => Children;
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
|
|
||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
|
|
||||||
public OsuLinkSpriteText()
|
public OsuSpriteLink()
|
||||||
{
|
{
|
||||||
AddInternal(content = new OsuHoverContainer
|
AddInternal(content = new OsuHoverContainer
|
||||||
{
|
{
|
@ -12,7 +12,7 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace osu.Game.Online.Chat
|
namespace osu.Game.Online.Chat
|
||||||
{
|
{
|
||||||
public class ChatLink : OsuLinkSpriteText, IHasTooltip
|
public class ChatLink : OsuSpriteLink, IHasTooltip
|
||||||
{
|
{
|
||||||
private APIAccess api;
|
private APIAccess api;
|
||||||
private BeatmapSetOverlay beatmapSetOverlay;
|
private BeatmapSetOverlay beatmapSetOverlay;
|
||||||
@ -20,9 +20,13 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
public override bool HandleInput => !string.IsNullOrEmpty(Url);
|
public override bool HandleInput => !string.IsNullOrEmpty(Url);
|
||||||
|
|
||||||
|
// 'protocol' -> 'https', 'http', 'osu', 'osump' etc.
|
||||||
|
// 'content' -> everything after '<protocol>://'
|
||||||
|
private Match getUrlMatch() => Regex.Match(Url, @"^(?<protocol>osu(?:mp)?|https?):\/\/(?<content>.*)");
|
||||||
|
|
||||||
protected override void OnLinkClicked()
|
protected override void OnLinkClicked()
|
||||||
{
|
{
|
||||||
var urlMatch = Regex.Matches(Url, @"^(?<protocol>osu(?:mp)?|https?):\/\/(?<content>.*)")[0];
|
var urlMatch = getUrlMatch();
|
||||||
if (urlMatch.Success)
|
if (urlMatch.Success)
|
||||||
{
|
{
|
||||||
var args = urlMatch.Groups["content"].Value.Split('/');
|
var args = urlMatch.Groups["content"].Value.Split('/');
|
||||||
@ -41,11 +45,8 @@ namespace osu.Game.Online.Chat
|
|||||||
case "chan":
|
case "chan":
|
||||||
var foundChannel = chat.AvailableChannels.Find(channel => channel.Name == args[1]);
|
var foundChannel = chat.AvailableChannels.Find(channel => channel.Name == args[1]);
|
||||||
|
|
||||||
if (foundChannel == null)
|
// links should be filtered out by now if a channel doesn't exist
|
||||||
throw new ArgumentException($"Unknown channel name ({args[1]}).");
|
chat.OpenChannel(foundChannel ?? throw new ArgumentException($"Unknown channel name ({args[1]})."));
|
||||||
else
|
|
||||||
chat.OpenChannel(foundChannel);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "edit":
|
case "edit":
|
||||||
chat.Game?.LoadEditorTimestamp();
|
chat.Game?.LoadEditorTimestamp();
|
||||||
@ -130,9 +131,10 @@ namespace osu.Game.Online.Chat
|
|||||||
if (Url == Text)
|
if (Url == Text)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (Url.StartsWith("osu://"))
|
var urlMatch = getUrlMatch();
|
||||||
|
if (urlMatch.Success && urlMatch.Groups["protocol"].Value == "osu")
|
||||||
{
|
{
|
||||||
var args = Url.Substring(6).Split('/');
|
var args = urlMatch.Groups["content"].Value.Split('/');
|
||||||
|
|
||||||
if (args.Length < 2)
|
if (args.Length < 2)
|
||||||
return Url;
|
return Url;
|
||||||
@ -140,7 +142,7 @@ namespace osu.Game.Online.Chat
|
|||||||
if (args[0] == "chan")
|
if (args[0] == "chan")
|
||||||
return "Switch to channel " + args[1];
|
return "Switch to channel " + args[1];
|
||||||
if (args[0] == "edit")
|
if (args[0] == "edit")
|
||||||
return "Go to " + args[1].Remove(9).TrimEnd();
|
return "Go to " + args[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Url;
|
return Url;
|
||||||
|
@ -83,7 +83,10 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
private Message message;
|
private Message message;
|
||||||
private OsuSpriteText username;
|
private OsuSpriteText username;
|
||||||
private OsuLinkTextFlowContainer<ChatLink> contentFlow;
|
private OsuLinkFlowContainer<ChatLink> contentFlow;
|
||||||
|
|
||||||
|
// this is only used for testing
|
||||||
|
public OsuTextFlowContainer ContentFlow => contentFlow;
|
||||||
|
|
||||||
public Message Message
|
public Message Message
|
||||||
{
|
{
|
||||||
@ -101,9 +104,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is only used for testing
|
|
||||||
public OsuTextFlowContainer ContentFlow => contentFlow;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuColour colours, ChatOverlay chat)
|
private void load(OsuColour colours, ChatOverlay chat)
|
||||||
{
|
{
|
||||||
@ -193,7 +193,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Padding = new MarginPadding { Left = message_padding + padding },
|
Padding = new MarginPadding { Left = message_padding + padding },
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
contentFlow = new OsuLinkTextFlowContainer<ChatLink>(t =>
|
contentFlow = new OsuLinkFlowContainer<ChatLink>(t =>
|
||||||
{
|
{
|
||||||
if (Message.IsAction)
|
if (Message.IsAction)
|
||||||
t.Font = "Exo2.0-MediumItalic";
|
t.Font = "Exo2.0-MediumItalic";
|
||||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
public class ProfileHeader : Container
|
public class ProfileHeader : Container
|
||||||
{
|
{
|
||||||
private readonly OsuTextFlowContainer infoTextLeft;
|
private readonly OsuTextFlowContainer infoTextLeft;
|
||||||
private readonly OsuLinkTextFlowContainer infoTextRight;
|
private readonly OsuLinkFlowContainer infoTextRight;
|
||||||
private readonly FillFlowContainer<SpriteText> scoreText, scoreNumberText;
|
private readonly FillFlowContainer<SpriteText> scoreText, scoreNumberText;
|
||||||
private readonly RankGraph rankGraph;
|
private readonly RankGraph rankGraph;
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
ParagraphSpacing = 0.8f,
|
ParagraphSpacing = 0.8f,
|
||||||
LineSpacing = 0.2f
|
LineSpacing = 0.2f
|
||||||
},
|
},
|
||||||
infoTextRight = new OsuLinkTextFlowContainer(t =>
|
infoTextRight = new OsuLinkFlowContainer(t =>
|
||||||
{
|
{
|
||||||
t.TextSize = 14;
|
t.TextSize = 14;
|
||||||
t.Font = @"Exo2.0-RegularItalic";
|
t.Font = @"Exo2.0-RegularItalic";
|
||||||
@ -473,7 +473,7 @@ namespace osu.Game.Overlays.Profile
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ProfileLink : OsuLinkSpriteText, IHasTooltip
|
private class ProfileLink : OsuSpriteLink, IHasTooltip
|
||||||
{
|
{
|
||||||
public string TooltipText => "View Profile in Browser";
|
public string TooltipText => "View Profile in Browser";
|
||||||
|
|
||||||
|
@ -270,8 +270,8 @@
|
|||||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||||
<Compile Include="Overlays\Profile\SupporterIcon.cs" />
|
<Compile Include="Overlays\Profile\SupporterIcon.cs" />
|
||||||
<Compile Include="Overlays\Settings\DangerousSettingsButton.cs" />
|
<Compile Include="Overlays\Settings\DangerousSettingsButton.cs" />
|
||||||
<Compile Include="Graphics\Containers\OsuLinkTextFlowContainer.cs" />
|
<Compile Include="Graphics\Containers\OsuLinkFlowContainer.cs" />
|
||||||
<Compile Include="Graphics\Sprites\OsuLinkSpriteText.cs" />
|
<Compile Include="Graphics\Sprites\OsuSpriteLink.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\HoverSounds.cs" />
|
<Compile Include="Graphics\UserInterface\HoverSounds.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user