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

Add BeatmapTitle to encapsulate multiplayer beatmap title display logic.

(cherry picked from commit 58e65afb45fbc675186e470cc4a268d9eaa2a539)
This commit is contained in:
DrabWeb 2018-05-28 23:13:56 -03:00
parent bdfb5752cd
commit 8b36e1dad0
3 changed files with 104 additions and 63 deletions

View File

@ -0,0 +1,90 @@
// 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;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Multi.Components
{
public class BeatmapTitle : FillFlowContainer<OsuSpriteText>
{
private readonly OsuSpriteText beatmapTitle, beatmapDash, beatmapArtist;
private LocalisationEngine localisation;
public float TextSize
{
set { beatmapTitle.TextSize = beatmapDash.TextSize = beatmapArtist.TextSize = value; }
}
private BeatmapInfo beatmap;
public BeatmapInfo Beatmap
{
get { return beatmap; }
set
{
if (value == beatmap) return;
beatmap = value;
if (IsLoaded)
updateText();
}
}
public BeatmapTitle()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Children = new[]
{
beatmapTitle = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
},
beatmapDash = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
},
beatmapArtist = new OsuSpriteText
{
Font = @"Exo2.0-RegularItalic",
},
};
}
[BackgroundDependencyLoader]
private void load(LocalisationEngine localisation)
{
this.localisation = localisation;
}
protected override void LoadComplete()
{
base.LoadComplete();
updateText();
}
private void updateText()
{
if (beatmap == null)
{
beatmapTitle.Current = beatmapArtist.Current = null;
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = string.Empty;
}
else
{
beatmapTitle.Current = localisation.GetUnicodePreference(beatmap.Metadata.TitleUnicode, beatmap.Metadata.Title);
beatmapDash.Text = @" - ";
beatmapArtist.Current = localisation.GetUnicodePreference(beatmap.Metadata.ArtistUnicode, beatmap.Metadata.Artist);
}
}
}
}

View File

@ -112,8 +112,9 @@ namespace osu.Game.Screens.Multi.Components
{
Box sideStrip;
UpdateableBeatmapSetCover cover;
OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
OsuSpriteText name, status;
ParticipantInfo participantInfo;
BeatmapTitle beatmapTitle;
ModeTypeInfo modeTypeInfo;
Children = new Drawable[]
@ -193,30 +194,10 @@ namespace osu.Game.Screens.Multi.Components
TextSize = 14,
Font = @"Exo2.0-Bold",
},
new FillFlowContainer<OsuSpriteText>
beatmapTitle = new BeatmapTitle
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Colour = colours.Gray9,
Direction = FillDirection.Horizontal,
Children = new[]
{
beatmapTitle = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-BoldItalic",
},
beatmapDash = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-BoldItalic",
},
beatmapArtist = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-RegularItalic",
},
},
TextSize = 14,
Colour = colours.Gray9
},
},
},
@ -252,19 +233,12 @@ namespace osu.Game.Screens.Multi.Components
if (b != null)
{
cover.BeatmapSet = b.BeatmapSet;
beatmapTitle.Current = localisation.GetUnicodePreference(b.Metadata.TitleUnicode, b.Metadata.Title);
beatmapDash.Text = @" - ";
beatmapArtist.Current = localisation.GetUnicodePreference(b.Metadata.ArtistUnicode, b.Metadata.Artist);
beatmapTitle.Beatmap = b;
}
else
{
cover.BeatmapSet = null;
beatmapTitle.Current = null;
beatmapArtist.Current = null;
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = string.Empty;
beatmapTitle.Beatmap = null;
}
};

View File

@ -82,7 +82,8 @@ namespace osu.Game.Screens.Multi.Components
this.colours = colours;
ModeTypeInfo modeTypeInfo;
OsuSpriteText participants, participantsSlash, maxParticipants, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor;
OsuSpriteText participants, participantsSlash, maxParticipants, beatmapAuthor;
BeatmapTitle beatmapTitle;
Children = new Drawable[]
{
@ -203,28 +204,9 @@ namespace osu.Game.Screens.Multi.Components
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Margin = new MarginPadding { Left = 5 },
Children = new[]
Children = new Drawable[]
{
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Children = new[]
{
beatmapTitle = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
},
beatmapDash = new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
},
beatmapArtist = new OsuSpriteText
{
Font = @"Exo2.0-RegularItalic",
},
},
},
beatmapTitle = new BeatmapTitle(),
beatmapAuthor = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
@ -283,20 +265,15 @@ namespace osu.Game.Screens.Multi.Components
if (b != null)
{
cover.BeatmapSet = b.BeatmapSet;
beatmapTitle.Current = localisation.GetUnicodePreference(b.Metadata.TitleUnicode, b.Metadata.Title);
beatmapDash.Text = @" - ";
beatmapArtist.Current = localisation.GetUnicodePreference(b.Metadata.ArtistUnicode, b.Metadata.Artist);
beatmapTitle.Beatmap = b;
beatmapAuthor.Text = $"mapped by {b.Metadata.Author}";
}
else
{
cover.BeatmapSet = null;
beatmapTitle.Beatmap = null;
beatmapTitle.Current = null;
beatmapArtist.Current = null;
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = beatmapAuthor.Text = string.Empty;
beatmapAuthor.Text = string.Empty;
}
};