Merge pull request #2669 from DrabWeb/multiplayer-logic-encapsulation

Multiplayer shared logic encapsulation
This commit is contained in:
Dean Herbert 2018-06-01 15:58:15 +09:00 committed by GitHub
commit 6b48370092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 240 additions and 162 deletions

View File

@ -0,0 +1,79 @@
// 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
{
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

@ -0,0 +1,70 @@
// 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.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using OpenTK;
namespace osu.Game.Screens.Multi.Components
{
public class BeatmapTypeInfo : FillFlowContainer
{
private readonly ModeTypeInfo modeTypeInfo;
private readonly BeatmapTitle beatmapTitle;
private readonly OsuSpriteText beatmapAuthor;
public BeatmapInfo Beatmap
{
set
{
modeTypeInfo.Beatmap = beatmapTitle.Beatmap = value;
beatmapAuthor.Text = value == null ? string.Empty : $"mapped by {value.Metadata.Author}";
}
}
public GameType Type
{
set { modeTypeInfo.Type = value; }
}
public BeatmapTypeInfo()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
LayoutDuration = 100;
Spacing = new Vector2(5f, 0f);
Children = new Drawable[]
{
modeTypeInfo = new ModeTypeInfo(),
new Container
{
AutoSizeAxes = Axes.X,
Height = 30,
Margin = new MarginPadding { Left = 5 },
Children = new Drawable[]
{
beatmapTitle = new BeatmapTitle(),
beatmapAuthor = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
TextSize = 14,
},
},
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
beatmapAuthor.Colour = colours.Gray9;
}
}
}

View File

@ -11,7 +11,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
@ -108,12 +107,13 @@ namespace osu.Game.Screens.Multi.Components
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
private void load(OsuColour colours)
{
Box sideStrip;
UpdateableBeatmapSetCover cover;
OsuSpriteText name, status, beatmapTitle, beatmapDash, beatmapArtist;
OsuSpriteText name, status;
ParticipantInfo participantInfo;
BeatmapTitle beatmapTitle;
ModeTypeInfo modeTypeInfo;
Children = new Drawable[]
@ -193,30 +193,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
},
},
},
@ -247,25 +227,9 @@ namespace osu.Game.Screens.Multi.Components
beatmapBind.ValueChanged += b =>
{
cover.BeatmapSet = b?.BeatmapSet;
beatmapTitle.Beatmap = b;
modeTypeInfo.Beatmap = b;
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);
}
else
{
cover.BeatmapSet = null;
beatmapTitle.Current = null;
beatmapArtist.Current = null;
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = string.Empty;
}
};
nameBind.BindTo(Room.Name);

View File

@ -64,6 +64,7 @@ namespace osu.Game.Screens.Multi.Components
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5f, 0f),
LayoutDuration = 100,
Children = new[]
{
rulesetContainer = new Container

View File

@ -0,0 +1,67 @@
// 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.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Multi.Components
{
public class ParticipantCount : FillFlowContainer
{
private const float text_size = 30;
private const float transition_duration = 100;
private readonly OsuSpriteText count, slash, max;
public int Count
{
set => count.Text = value.ToString();
}
public int? Max
{
set
{
if (value == null)
{
slash.FadeOut(transition_duration);
max.FadeOut(transition_duration);
}
else
{
slash.FadeIn(transition_duration);
max.Text = value.ToString();
max.FadeIn(transition_duration);
}
}
}
public ParticipantCount()
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
LayoutDuration = transition_duration;
Children = new[]
{
count = new OsuSpriteText
{
TextSize = text_size,
Font = @"Exo2.0-Bold"
},
slash = new OsuSpriteText
{
Text = @"/",
TextSize = text_size,
Font = @"Exo2.0-Light"
},
max = new OsuSpriteText
{
TextSize = text_size,
Font = @"Exo2.0-Light"
},
};
}
}
}

View File

@ -10,7 +10,6 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
@ -39,8 +38,10 @@ namespace osu.Game.Screens.Multi.Components
private OsuColour colours;
private Box statusStrip;
private UpdateableBeatmapSetCover cover;
private FillFlowContainer topFlow, participantsFlow, participantNumbersFlow, infoPanelFlow;
private ParticipantCount participantCount;
private FillFlowContainer topFlow, participantsFlow;
private OsuSpriteText name, status;
private BeatmapTypeInfo beatmapTypeInfo;
private ScrollContainer participantsScroll;
private ParticipantInfo participantInfo;
@ -77,13 +78,10 @@ namespace osu.Game.Screens.Multi.Components
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation)
private void load(OsuColour colours)
{
this.colours = colours;
ModeTypeInfo modeTypeInfo;
OsuSpriteText participants, participantsSlash, maxParticipants, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor;
Children = new Drawable[]
{
new Box
@ -120,32 +118,10 @@ namespace osu.Game.Screens.Multi.Components
Padding = new MarginPadding(20),
Children = new Drawable[]
{
participantNumbersFlow = new FillFlowContainer
participantCount = new ParticipantCount
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
LayoutDuration = transition_duration,
Children = new[]
{
participants = new OsuSpriteText
{
TextSize = 30,
Font = @"Exo2.0-Bold"
},
participantsSlash = new OsuSpriteText
{
Text = @"/",
TextSize = 30,
Font = @"Exo2.0-Light"
},
maxParticipants = new OsuSpriteText
{
TextSize = 30,
Font = @"Exo2.0-Light"
},
},
},
name = new OsuSpriteText
{
@ -188,54 +164,7 @@ namespace osu.Game.Screens.Multi.Components
TextSize = 14,
Font = @"Exo2.0-Bold",
},
infoPanelFlow = new FillFlowContainer
{
AutoSizeAxes = Axes.X,
Height = 30,
Direction = FillDirection.Horizontal,
LayoutDuration = transition_duration,
Spacing = new Vector2(5f, 0f),
Children = new Drawable[]
{
modeTypeInfo = new ModeTypeInfo(),
new Container
{
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Margin = new MarginPadding { Left = 5 },
Children = new[]
{
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",
},
},
},
beatmapAuthor = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
TextSize = 14,
Colour = colours.Gray9,
},
},
},
},
},
beatmapTypeInfo = new BeatmapTypeInfo(),
},
},
},
@ -273,51 +202,19 @@ namespace osu.Game.Screens.Multi.Components
nameBind.ValueChanged += n => name.Text = n;
hostBind.ValueChanged += h => participantInfo.Host = h;
typeBind.ValueChanged += t => modeTypeInfo.Type = t;
typeBind.ValueChanged += t => beatmapTypeInfo.Type = t;
maxParticipantsBind.ValueChanged += m => participantCount.Max = m;
statusBind.ValueChanged += displayStatus;
beatmapBind.ValueChanged += b =>
{
modeTypeInfo.Beatmap = b;
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);
beatmapAuthor.Text = $"mapped by {b.Metadata.Author}";
}
else
{
cover.BeatmapSet = null;
beatmapTitle.Current = null;
beatmapArtist.Current = null;
beatmapTitle.Text = "Changing map";
beatmapDash.Text = beatmapArtist.Text = beatmapAuthor.Text = string.Empty;
}
};
maxParticipantsBind.ValueChanged += m =>
{
if (m == null)
{
participantsSlash.FadeOut(transition_duration);
maxParticipants.FadeOut(transition_duration);
}
else
{
participantsSlash.FadeIn(transition_duration);
maxParticipants.FadeIn(transition_duration);
maxParticipants.Text = m.ToString();
}
cover.BeatmapSet = b?.BeatmapSet;
beatmapTypeInfo.Beatmap = b;
};
participantsBind.ValueChanged += p =>
{
participants.Text = p.Length.ToString();
participantCount.Count = p.Length;
participantInfo.Participants = p;
participantsFlow.ChildrenEnumerable = p.Select(u => new UserTile(u));
};
@ -347,8 +244,8 @@ namespace osu.Game.Screens.Multi.Components
{
cover.BeatmapSet = null;
participantsFlow.FadeOut(transition_duration);
participantNumbersFlow.FadeOut(transition_duration);
infoPanelFlow.FadeOut(transition_duration);
participantCount.FadeOut(transition_duration);
beatmapTypeInfo.FadeOut(transition_duration);
name.FadeOut(transition_duration);
participantInfo.FadeOut(transition_duration);
@ -357,8 +254,8 @@ namespace osu.Game.Screens.Multi.Components
else
{
participantsFlow.FadeIn(transition_duration);
participantNumbersFlow.FadeIn(transition_duration);
infoPanelFlow.FadeIn(transition_duration);
participantCount.FadeIn(transition_duration);
beatmapTypeInfo.FadeIn(transition_duration);
name.FadeIn(transition_duration);
participantInfo.FadeIn(transition_duration);