1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 18:12:56 +08:00

Bindables, avatars, more cleanup

This commit is contained in:
DrabWeb 2017-05-22 01:01:55 -03:00
parent e5ee7096f8
commit 82fdf1a918
2 changed files with 81 additions and 26 deletions

View File

@ -40,21 +40,49 @@ namespace osu.Desktop.VisualTests.Tests
p = new DrawableMultiplayerRoom(new MultiplayerRoom p = new DrawableMultiplayerRoom(new MultiplayerRoom
{ {
Name = @"Great Room Right Here", Name = @"Great Room Right Here",
Host = new User { Username = @"Naeferith", Country = new Country { FlagName = @"FR" }}, Host = new User { Username = @"Naeferith", Id = 9492835, Country = new Country { FlagName = @"FR" }},
Status = MultiplayerRoomStatus.Open, Status = MultiplayerRoomStatus.Open,
CurrentBeatmap = new BeatmapMetadata { Title = @"Seiryu", Artist = @"Critical Crystal" }, CurrentBeatmap = new BeatmapMetadata { Title = @"Seiryu", Artist = @"Critical Crystal" },
}), }),
new DrawableMultiplayerRoom(new MultiplayerRoom new DrawableMultiplayerRoom(new MultiplayerRoom
{ {
Name = @"Relax It's The Weekend", Name = @"Relax It's The Weekend",
Host = new User{ Username = @"Someone", Country = new Country { FlagName = @"CA" }}, Host = new User{ Username = @"peppy", Id = 2, Country = new Country { FlagName = @"AU" }},
Status = MultiplayerRoomStatus.Playing, Status = MultiplayerRoomStatus.Playing,
CurrentBeatmap = new BeatmapMetadata { Title = @"ZAQ", Artist = @"Serendipity" }, CurrentBeatmap = new BeatmapMetadata { Title = @"ZAQ", Artist = @"Serendipity" },
}), }),
} }
}); });
AddStep(@"change state", () => { p.Room.Status = MultiplayerRoomStatus.Playing; }); AddStep(@"change state", () =>
{
p.Room.Value.Status = MultiplayerRoomStatus.Playing;
p.Room.TriggerChange();
});
AddStep(@"change name", () =>
{
p.Room.Value.Name = @"I Changed Name";
p.Room.TriggerChange();
});
AddStep(@"change host", () =>
{
p.Room.Value.Host = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } };
p.Room.TriggerChange();
});
AddStep(@"change beatmap", () =>
{
p.Room.Value.CurrentBeatmap = null;
p.Room.TriggerChange();
});
AddStep(@"change state", () =>
{
p.Room.Value.Status = MultiplayerRoomStatus.Open;
p.Room.TriggerChange();
});
} }
} }
} }

View File

@ -4,6 +4,7 @@
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -24,21 +25,26 @@ namespace osu.Game.Screens.Multiplayer
private const float height = 90; private const float height = 90;
private readonly Box sideStrip; private readonly Box sideStrip;
private readonly OsuSpriteText status; private readonly UpdateableAvatar avatar;
private readonly OsuSpriteText name;
private readonly Container flagContainer;
private readonly OsuSpriteText host; private readonly OsuSpriteText host;
private readonly OsuSpriteText rankBounds; private readonly OsuSpriteText rankBounds;
private readonly OsuSpriteText status;
private readonly FillFlowContainer<OsuSpriteText> beatmapInfoFlow; private readonly FillFlowContainer<OsuSpriteText> beatmapInfoFlow;
private readonly OsuSpriteText beatmapTitle; private readonly OsuSpriteText beatmapTitle;
private readonly OsuSpriteText beatmapDash;
private readonly OsuSpriteText beatmapArtist; private readonly OsuSpriteText beatmapArtist;
private Color4 openColour; private Color4 openColour;
private Color4 playingColour; private Color4 playingColour;
private LocalisationEngine localisation;
public readonly MultiplayerRoom Room; public readonly Bindable<MultiplayerRoom> Room;
public DrawableMultiplayerRoom(MultiplayerRoom room) public DrawableMultiplayerRoom(MultiplayerRoom room)
{ {
Room = room; Room = new Bindable<MultiplayerRoom>(room);
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = height; Height = height;
@ -65,12 +71,19 @@ namespace osu.Game.Screens.Multiplayer
sideStrip = new Box sideStrip = new Box
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = 5, Width = content_padding,
},
avatar = new UpdateableAvatar
{
Size = new Vector2(Height - content_padding* 2),
Masking = true,
CornerRadius = 5f,
Margin = new MarginPadding { Left = content_padding * 2, Top = content_padding },
}, },
new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = content_padding, Bottom = content_padding * 2, Left = Height + content_padding * 2, Right = content_padding }, Padding = new MarginPadding { Top = content_padding, Bottom = content_padding, Left = Height + content_padding * 2, Right = content_padding },
Children = new Drawable[] Children = new Drawable[]
{ {
new FillFlowContainer new FillFlowContainer
@ -81,9 +94,8 @@ namespace osu.Game.Screens.Multiplayer
Spacing = new Vector2(5f), Spacing = new Vector2(5f),
Children = new Drawable[] Children = new Drawable[]
{ {
new OsuSpriteText name = new OsuSpriteText
{ {
Text = Room.Name,
TextSize = 18, TextSize = 18,
}, },
new Container new Container
@ -100,7 +112,7 @@ namespace osu.Game.Screens.Multiplayer
Spacing = new Vector2(5f, 0f), Spacing = new Vector2(5f, 0f),
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableFlag(Room.Host?.Country?.FlagName ?? "__") flagContainer = new Container
{ {
Width = 30f, Width = 30f,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -121,7 +133,6 @@ namespace osu.Game.Screens.Multiplayer
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Text = Room.Host?.Username ?? @"",
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
@ -131,7 +142,7 @@ namespace osu.Game.Screens.Multiplayer
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
Text = "#6895 - #50024", Text = "#0 - #0",
TextSize = 14, TextSize = 14,
Margin = new MarginPadding { Right = 10 }, Margin = new MarginPadding { Right = 10 },
}, },
@ -146,6 +157,7 @@ namespace osu.Game.Screens.Multiplayer
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Margin = new MarginPadding { Bottom = content_padding },
Children = new Drawable[] Children = new Drawable[]
{ {
status = new OsuSpriteText status = new OsuSpriteText
@ -165,9 +177,8 @@ namespace osu.Game.Screens.Multiplayer
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-BoldItalic", Font = @"Exo2.0-BoldItalic",
}, },
new OsuSpriteText beatmapDash = new OsuSpriteText
{ {
Text = @" - ",
TextSize = 14, TextSize = 14,
Font = @"Exo2.0-RegularItalic", Font = @"Exo2.0-RegularItalic",
}, },
@ -183,33 +194,49 @@ namespace osu.Game.Screens.Multiplayer
}, },
}, },
}; };
Room.ValueChanged += displayRoom;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, LocalisationEngine localisation) private void load(OsuColour colours, LocalisationEngine localisation)
{ {
this.localisation = localisation;
openColour = colours.GreenLight; openColour = colours.GreenLight;
playingColour = colours.Purple; playingColour = colours.Purple;
beatmapInfoFlow.Colour = rankBounds.Colour = colours.Gray9; beatmapInfoFlow.Colour = rankBounds.Colour = colours.Gray9;
host.Colour = colours.Blue; host.Colour = colours.Blue;
if (Room.CurrentBeatmap != null) Room.TriggerChange();
{
beatmapTitle.Current = localisation.GetUnicodePreference(Room.CurrentBeatmap.TitleUnicode, Room.CurrentBeatmap.Title);
beatmapArtist.Current = localisation.GetUnicodePreference(Room.CurrentBeatmap.ArtistUnicode, Room.CurrentBeatmap.Artist);
}
updateStatus();
} }
private void updateStatus() private void displayRoom(MultiplayerRoom room)
{ {
if (Room == null) return; name.Text = room.Name;
status.Text = room.Status.GetDescription();
host.Text = room.Host.Username;
flagContainer.Children = new[] { new DrawableFlag(room.Host.Country?.FlagName ?? @"__") { RelativeSizeAxes = Axes.Both } };
avatar.User = room.Host;
status.Text = Room.Status.GetDescription(); if (room.CurrentBeatmap != null)
{
beatmapTitle.Current = localisation.GetUnicodePreference(room.CurrentBeatmap.TitleUnicode, room.CurrentBeatmap.Title);
beatmapDash.Text = @" - ";
beatmapArtist.Current = localisation.GetUnicodePreference(room.CurrentBeatmap.ArtistUnicode, room.CurrentBeatmap.Artist);
}
else
{
beatmapTitle.Current = null;
beatmapArtist.Current = null;
beatmapTitle.Text = @"Changing map";
beatmapDash.Text = string.Empty;
beatmapArtist.Text = string.Empty;
}
foreach (Drawable d in new Drawable[] { sideStrip, status }) foreach (Drawable d in new Drawable[] { sideStrip, status })
d.FadeColour(Room.Status == MultiplayerRoomStatus.Playing? playingColour : openColour); d.FadeColour(room.Status == MultiplayerRoomStatus.Playing? playingColour : openColour, 100);
} }
} }
} }