mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Use a better method of link compilation
Adds word wrap back, simplifies a lot.
This commit is contained in:
@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Game.Online.Chat;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
public class ChatFlowContainer : OsuTextFlowContainer
|
||||
{
|
||||
private readonly Action<ChatLink> defaultCreationParameters;
|
||||
private ColourInfo urlColour;
|
||||
|
||||
public ChatFlowContainer(Action<ChatLink> defaultCreationParameters = null)
|
||||
{
|
||||
this.defaultCreationParameters = defaultCreationParameters;
|
||||
}
|
||||
|
||||
public override bool HandleInput => true;
|
||||
|
||||
public void AddLink(string text, string url, LinkAction linkType, string linkArgument)
|
||||
{
|
||||
var chatSprite = new ChatLink
|
||||
{
|
||||
Text = text,
|
||||
Url = url,
|
||||
TextColour = urlColour,
|
||||
LinkAction = linkType,
|
||||
LinkArgument = linkArgument,
|
||||
};
|
||||
|
||||
defaultCreationParameters?.Invoke(chatSprite);
|
||||
|
||||
AddInternal(chatSprite);
|
||||
}
|
||||
|
||||
public void AddText(string text, Action<ChatLink> creationParameters = null)
|
||||
{
|
||||
foreach (var word in SplitWords(text))
|
||||
{
|
||||
if (string.IsNullOrEmpty(word))
|
||||
continue;
|
||||
|
||||
var chatSprite = new ChatLink { Text = word };
|
||||
|
||||
defaultCreationParameters?.Invoke(chatSprite);
|
||||
creationParameters?.Invoke(chatSprite);
|
||||
|
||||
AddInternal(chatSprite);
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
urlColour = colours.Blue;
|
||||
}
|
||||
}
|
||||
}
|
75
osu.Game/Graphics/Containers/LinkFlowContainer.cs
Normal file
75
osu.Game/Graphics/Containers/LinkFlowContainer.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Online.Chat;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
public class LinkFlowContainer : OsuTextFlowContainer
|
||||
{
|
||||
public LinkFlowContainer(Action<SpriteText> defaultCreationParameters = null)
|
||||
: base(defaultCreationParameters)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool HandleInput => true;
|
||||
|
||||
private BeatmapSetOverlay beatmapSetOverlay;
|
||||
private ChatOverlay chat;
|
||||
private OsuGame game;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuGame game)
|
||||
{
|
||||
this.beatmapSetOverlay = beatmapSetOverlay;
|
||||
this.chat = chat;
|
||||
// this will be null in tests
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null)
|
||||
{
|
||||
AddInternal(new DrawableLinkCompiler(AddText(text).ToList())
|
||||
{
|
||||
TooltipText = tooltipText ?? (url != text ? url : string.Empty),
|
||||
Action = () =>
|
||||
{
|
||||
switch (linkType)
|
||||
{
|
||||
case LinkAction.OpenBeatmap:
|
||||
// todo: implement this when overlay.ShowBeatmap(id) exists
|
||||
break;
|
||||
case LinkAction.OpenBeatmapSet:
|
||||
if (int.TryParse(linkArgument, out int setId))
|
||||
beatmapSetOverlay.ShowBeatmapSet(setId);
|
||||
break;
|
||||
case LinkAction.OpenChannel:
|
||||
chat.OpenChannel(chat.AvailableChannels.Find(c => c.Name == linkArgument));
|
||||
break;
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
game?.LoadEditorTimestamp();
|
||||
break;
|
||||
case LinkAction.JoinMultiplayerMatch:
|
||||
if (int.TryParse(linkArgument, out int matchId))
|
||||
game?.JoinMultiplayerMatch(matchId);
|
||||
break;
|
||||
case LinkAction.Spectate:
|
||||
// todo: implement this when spectating exists
|
||||
break;
|
||||
case LinkAction.External:
|
||||
Process.Start(url);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
|
||||
@ -10,26 +12,34 @@ namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
public class OsuHoverContainer : OsuClickableContainer
|
||||
{
|
||||
private Color4 hoverColour;
|
||||
private Color4 unhoverColour;
|
||||
protected Color4 HoverColour;
|
||||
|
||||
protected Color4 IdleColour = Color4.White;
|
||||
|
||||
protected virtual IEnumerable<Drawable> EffectTargets => new[] { Content };
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
this.FadeColour(hoverColour, 500, Easing.OutQuint);
|
||||
EffectTargets.ForEach(d => d.FadeColour(HoverColour, 500, Easing.OutQuint));
|
||||
return base.OnHover(state);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
this.FadeColour(unhoverColour, 500, Easing.OutQuint);
|
||||
EffectTargets.ForEach(d => d.FadeColour(IdleColour, 500, Easing.OutQuint));
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
hoverColour = colours.Yellow;
|
||||
unhoverColour = Colour;
|
||||
HoverColour = colours.Yellow;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
EffectTargets.ForEach(d => d.FadeColour(IdleColour));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user