Skip to content

Commit

Permalink
Partially fix link buttons mess
Browse files Browse the repository at this point in the history
  • Loading branch information
Feodor0090 committed Jan 24, 2023
1 parent 1bc09bc commit 92d59b7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 43 deletions.
46 changes: 28 additions & 18 deletions osu.Game.Rulesets.OvkTab/API/VkModelsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.OvkTab.API
{
public static class VkModelsExtensions
{
public static IEnumerable<Drawable> ParseAttachments(this IEnumerable<Attachment> atts, IReadOnlyDependencyContainer deps, IEnumerable<SimpleVkUser> users = null)
public static IEnumerable<Drawable> ParseAttachments(this IEnumerable<Attachment>? atts, IReadOnlyDependencyContainer deps, IEnumerable<SimpleVkUser>? users = null)
{
if (atts == null) return Array.Empty<Drawable>();

Expand Down Expand Up @@ -54,7 +54,10 @@ public static IEnumerable<Drawable> ParseAttachments(this IEnumerable<Attachment
string length = (x.Duration / 60).ToString().PadLeft(2, '0') + ":" + (x.Duration % 60).ToString().PadLeft(2, '0');
result.Add(new SimpleAttachment(FontAwesome.Solid.Music, x.Title, x.Artist, length, new[]
{
new SpriteAttachmentAction("Icons/Hexacons/beatmap", b => { game.HandleLink(new LinkDetails(LinkAction.SearchBeatmapSet, x.Artist + " " + x.Title)); }),
new SpriteAttachmentAction("Icons/Hexacons/beatmap", b => { game.HandleLink(new LinkDetails(LinkAction.SearchBeatmapSet, x.Artist + " " + x.Title)); })
{
tooltip = "search in beatmap listing"
}
}));
break;

Expand All @@ -65,14 +68,18 @@ public static IEnumerable<Drawable> ParseAttachments(this IEnumerable<Attachment
case AudioMessage x:
string len = (x.Duration / 60).ToString().PadLeft(2, '0') + ":" + (x.Duration % 60).ToString().PadLeft(2, '0');
result.Add(new SimpleAttachment(FontAwesome.Solid.Microphone, "Voice message", len, null));

if (x.Transcript != null)
{
result.Add(new TextFlowContainer
{
Text = x.Transcript,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new() { Horizontal = 5 }
});
}

break;

case VkNet.Model.Attachments.Link x:
Expand Down Expand Up @@ -107,7 +114,6 @@ public static IEnumerable<Drawable> ParseAttachments(this IEnumerable<Attachment
result.Add(new DrawableVkWall(x, users?.Where(u => u.id == x.OwnerId).FirstOrDefault()));
}

// return
return result;
}

Expand All @@ -120,27 +126,25 @@ public static string ClearTextFromMentions(this string text)

public static SimpleAttachment ToDrawable(this VkNet.Model.Attachments.Link x, OsuGame game)
{
var globalLinkBtn = new IconAttachmentAction(FontAwesome.Solid.Link, b => { game.HandleLink(new LinkDetails(LinkAction.External, x.Uri.AbsoluteUri)); });

AttachmentAction[] linkBtns;
IconUsage linkIcon;
var globalLinkBtn = new IconAttachmentAction(FontAwesome.Solid.Link, _ => { game.HandleLink(new LinkDetails(LinkAction.External, x.Uri.AbsoluteUri)); })
{
tooltip = "open in browser"
};

if (x.Uri.Host == "osu.ppy.sh")
{
linkBtns = new[]
AttachmentAction[] buttons =
{
new IconAttachmentAction(FontAwesome.Solid.AngleDoubleRight, b => game.HandleLink(x.Uri.AbsoluteUri)),
new IconAttachmentAction(FontAwesome.Solid.AngleDoubleRight, _ => game.HandleLink(x.Uri.AbsoluteUri))
{
tooltip = "go to"
},
globalLinkBtn
};
linkIcon = FontAwesome.Solid.Hashtag;
}
else
{
linkIcon = FontAwesome.Solid.ExternalLinkAlt;
linkBtns = new[] { globalLinkBtn };
return new SimpleAttachment(FontAwesome.Solid.Hashtag, x.Title, x.Uri.AbsoluteUri, null, buttons);
}

return new SimpleAttachment(linkIcon, x.Title, x.Uri.AbsoluteUri, null, linkBtns);
return new SimpleAttachment(FontAwesome.Solid.ExternalLinkAlt, x.Title, x.Uri.AbsoluteUri, null, new AttachmentAction[] { globalLinkBtn });
}

public static SimpleAttachment ToDrawable(this Document x, OsuGame game, INotificationOverlay no)
Expand Down Expand Up @@ -182,15 +186,21 @@ public static SimpleAttachment ToDrawable(this Document x, OsuGame game, INotifi
onOk = () => { b.OfType<SpriteIcon>().First().Icon = FontAwesome.Solid.CheckCircle; },
postNotification = n => no.Post(n),
}.Download();
}),
})
{
tooltip = "import file"
}
};
}
else
{
icon = FontAwesome.Solid.Paperclip;
actions = new[]
{
new IconAttachmentAction(FontAwesome.Solid.Link, b => { game.HandleLink(new LinkDetails(LinkAction.External, x.Uri)); }),
new IconAttachmentAction(FontAwesome.Solid.Link, b => { game.HandleLink(new LinkDetails(LinkAction.External, x.Uri)); })
{
tooltip = "open in browser"
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using System;
using System.Linq;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
using osuTK;

namespace osu.Game.Rulesets.OvkTab.UI.Components.PostElements
{
public partial class SimpleAttachment : BeatSyncedContainer
{
private readonly Circle circle;
readonly Colour4 kiai = Colour4.PaleVioletRed;
readonly Colour4 normal = Colour4.BlueViolet.Lighten(0.05f);
private readonly AttachmentAction[] actions;
private readonly Colour4 kiai = Colour4.PaleVioletRed;
private readonly Colour4 normal = Colour4.BlueViolet.Lighten(0.05f);
private readonly AttachmentAction[]? actions;

public SimpleAttachment(IconUsage icon, string firstLine, string secondLine, string note, AttachmentAction[] buttons = null)
public SimpleAttachment(IconUsage icon, string firstLine, string secondLine, string? note, AttachmentAction[]? buttons = null)
{
actions = buttons;
int buttonsCount = buttons?.Length ?? 0;
Expand Down Expand Up @@ -58,38 +60,28 @@ public SimpleAttachment(IconUsage icon, string firstLine, string secondLine, str
},
new OsuSpriteText()
{
Text = note,
Text = note ?? string.Empty,
Position = new(-45 * buttonsCount, 50f / 4),
Origin = Anchor.CentreRight,
Anchor = Anchor.TopRight,
Font = font,
},
};

for (int i = 0; i < buttonsCount; i++)
{
Add(new TriangleButton
{
Size = new(40, 50),
Position = new(-45 * i, 0),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
}
}

[BackgroundDependencyLoader]
void load(TextureStore ts)
private void load(TextureStore ts)
{
if (actions == null) return;
var btns = this.OfType<TriangleButton>().ToArray();

for (int i = 0; i < actions.Length; i++)
{
var button = btns[i];
var action = actions[i];
button.Add(action.Get(ts));
button.Action = () => action.Action(button);
Add(new AttachmentActionButton(actions[i], ts)
{
Position = new(-45 * i, 0),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
}
}

Expand All @@ -101,9 +93,11 @@ protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint,

public abstract class AttachmentAction
{
public Action<TriangleButton> Action { get; protected set; }
public Action<TriangleButton>? Action { get; protected set; }

public abstract Drawable Get(TextureStore ts);

public LocalisableString tooltip;
}

public class IconAttachmentAction : AttachmentAction
Expand Down Expand Up @@ -137,11 +131,24 @@ public SpriteAttachmentAction(string texName, Action<TriangleButton> action)

public override Drawable Get(TextureStore ts) => new Sprite
{
Texture = ts?.Get(sprite),
Texture = ts.Get(sprite),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new(30),
};
}

public sealed partial class AttachmentActionButton : TriangleButton, IHasTooltip
{
public AttachmentActionButton(AttachmentAction action, TextureStore ts)
{
Size = new Vector2(40, 50);
Action = () => action.Action?.Invoke(this);
TooltipText = action.tooltip;
Add(action.Get(ts));
}

public LocalisableString TooltipText { get; }
}
}
}

0 comments on commit 92d59b7

Please sign in to comment.