1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 14:13:18 +08:00

Move shared types into their own classes

This commit is contained in:
Dean Herbert 2021-07-02 17:58:24 +09:00
parent ecb4982281
commit eacf867073
4 changed files with 129 additions and 183 deletions

View File

@ -6,14 +6,10 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osu.Game.Screens.Select;
using osuTK;
namespace osu.Game.Overlays.BeatmapSet
{
@ -138,76 +134,5 @@ namespace osu.Game.Overlays.BeatmapSet
successRateBackground.Colour = colourProvider.Background4;
background.Colour = colourProvider.Background5;
}
private class MetadataSection : FillFlowContainer
{
private readonly MetadataType type;
private readonly LinkFlowContainer textFlow;
public string Text
{
set
{
if (string.IsNullOrEmpty(value))
{
Hide();
return;
}
this.FadeIn(transition_duration);
textFlow.Clear();
static void format(SpriteText t) => t.Font = t.Font.With(size: 12);
switch (type)
{
case MetadataType.Tags:
string[] tags = value.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
textFlow.AddLink(tags[i], LinkAction.SearchBeatmapSet, tags[i], null, format);
if (i != tags.Length - 1)
textFlow.AddText(" ", format);
}
break;
case MetadataType.Source:
textFlow.AddLink(value, LinkAction.SearchBeatmapSet, value, null, format);
break;
default:
textFlow.AddText(value, format);
break;
}
}
}
public MetadataSection(MetadataType type)
{
this.type = type;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Spacing = new Vector2(5f);
InternalChildren = new Drawable[]
{
new OsuSpriteText
{
Text = this.type.ToString(),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
Margin = new MarginPadding { Top = 15 },
},
textFlow = new LinkFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
};
}
}
}
}

View File

@ -15,7 +15,6 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Rulesets;
using osu.Game.Screens.Select.Details;
using osuTK;
@ -129,8 +128,6 @@ namespace osu.Game.Screens.Select
AutoSizeAxes = Axes.Y,
LayoutDuration = transition_duration,
LayoutEasing = Easing.OutQuad,
Spacing = new Vector2(spacing * 2),
Margin = new MarginPadding { Top = spacing * 2 },
Children = new[]
{
description = new MetadataSection(MetadataType.Description),
@ -291,110 +288,5 @@ namespace osu.Game.Screens.Select
};
}
}
private class MetadataSection : Container
{
private readonly FillFlowContainer textContainer;
private readonly MetadataType type;
private TextFlowContainer textFlow;
public MetadataSection(MetadataType type)
{
this.type = type;
Alpha = 0;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = textContainer = new FillFlowContainer
{
Alpha = 0,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Spacing = new Vector2(spacing / 2),
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new OsuSpriteText
{
Text = this.type.ToString(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
},
},
},
};
}
public string Text
{
set
{
if (string.IsNullOrEmpty(value))
{
this.FadeOut(transition_duration);
return;
}
this.FadeIn(transition_duration);
setTextAsync(value);
}
}
private void setTextAsync(string text)
{
LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = Color4.White.Opacity(0.75f),
}, loaded =>
{
textFlow?.Expire();
switch (type)
{
case MetadataType.Tags:
string[] tags = text.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
loaded.AddLink(tags[i], LinkAction.SearchBeatmapSet, tags[i]);
if (i != tags.Length - 1)
loaded.AddText(" ");
}
break;
case MetadataType.Source:
loaded.AddLink(text, LinkAction.SearchBeatmapSet, text);
break;
default:
loaded.AddText(text);
break;
}
textContainer.Add(textFlow = loaded);
// fade in if we haven't yet.
textContainer.FadeIn(transition_duration);
});
}
}
}
public enum MetadataType
{
Tags,
Source,
Description,
Genre,
Language
}
}

View File

@ -0,0 +1,115 @@
// 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.
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Select
{
public class MetadataSection : Container
{
private readonly FillFlowContainer textContainer;
private readonly MetadataType type;
private TextFlowContainer textFlow;
private const float transition_duration = 250;
public MetadataSection(MetadataType type)
{
this.type = type;
Alpha = 0;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
InternalChild = textContainer = new FillFlowContainer
{
Alpha = 0,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 15 },
Spacing = new Vector2(5),
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = new OsuSpriteText
{
Text = this.type.ToString(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
},
},
},
};
}
public string Text
{
set
{
if (string.IsNullOrEmpty(value))
{
this.FadeOut(transition_duration);
return;
}
this.FadeIn(transition_duration);
setTextAsync(value);
}
}
private void setTextAsync(string text)
{
LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = Color4.White.Opacity(0.75f),
}, loaded =>
{
textFlow?.Expire();
switch (type)
{
case MetadataType.Tags:
string[] tags = text.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
loaded.AddLink(tags[i], LinkAction.SearchBeatmapSet, tags[i]);
if (i != tags.Length - 1)
loaded.AddText(" ");
}
break;
case MetadataType.Source:
loaded.AddLink(text, LinkAction.SearchBeatmapSet, text);
break;
default:
loaded.AddText(text);
break;
}
textContainer.Add(textFlow = loaded);
// fade in if we haven't yet.
textContainer.FadeIn(transition_duration);
});
}
}
}

View File

@ -0,0 +1,14 @@
// 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.
namespace osu.Game.Screens.Select
{
public enum MetadataType
{
Tags,
Source,
Description,
Genre,
Language
}
}