mirror of
https://github.com/ppy/osu
synced 2025-01-13 09:31:19 +00:00
Proper Bindable usage
This commit is contained in:
parent
65df2d2b70
commit
25b457e994
@ -19,7 +19,8 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
{
|
||||
base.Reset();
|
||||
|
||||
DrawableRoom p;
|
||||
DrawableRoom first;
|
||||
DrawableRoom second;
|
||||
Add(new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
@ -29,51 +30,44 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
p = new DrawableRoom(new Room
|
||||
{
|
||||
Name = @"Great Room Right Here",
|
||||
Host = new User { Username = @"Naeferith", Id = 9492835, Country = new Country { FlagName = @"FR" }},
|
||||
Status = RoomStatus.Open,
|
||||
Beatmap = new BeatmapMetadata { Title = @"Seiryu", Artist = @"Critical Crystal" },
|
||||
}),
|
||||
new DrawableRoom(new Room
|
||||
{
|
||||
Name = @"Relax It's The Weekend",
|
||||
Host = new User{ Username = @"peppy", Id = 2, Country = new Country { FlagName = @"AU" }},
|
||||
Status = RoomStatus.Playing,
|
||||
Beatmap = new BeatmapMetadata { Title = @"ZAQ", Artist = @"Serendipity" },
|
||||
}),
|
||||
first = new DrawableRoom(new Room()),
|
||||
second = new DrawableRoom(new Room()),
|
||||
}
|
||||
});
|
||||
|
||||
first.Room.Name.Value = @"Great Room Right Here";
|
||||
first.Room.Host.Value = new User { Username = @"Naeferith", Id = 9492835, Country = new Country { FlagName = @"FR" }};
|
||||
first.Room.Status.Value = RoomStatus.Open;
|
||||
first.Room.Beatmap.Value = new BeatmapMetadata { Title = @"Seiryu", Artist = @"Critical Crystal" };
|
||||
|
||||
second.Room.Name.Value = @"Relax It's The Weekend";
|
||||
second.Room.Host.Value = new User { Username = @"peppy", Id = 2, Country = new Country { FlagName = @"AU" }};
|
||||
second.Room.Status.Value = RoomStatus.Playing;
|
||||
second.Room.Beatmap.Value = new BeatmapMetadata { Title = @"ZAQ", Artist = @"Serendipity" };
|
||||
|
||||
AddStep(@"change state", () =>
|
||||
{
|
||||
p.Room.Value.Status = RoomStatus.Playing;
|
||||
p.Room.TriggerChange();
|
||||
first.Room.Status.Value = RoomStatus.Playing;
|
||||
});
|
||||
|
||||
AddStep(@"change name", () =>
|
||||
{
|
||||
p.Room.Value.Name = @"I Changed Name";
|
||||
p.Room.TriggerChange();
|
||||
first.Room.Name.Value = @"I Changed Name";
|
||||
});
|
||||
|
||||
AddStep(@"change host", () =>
|
||||
{
|
||||
p.Room.Value.Host = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } };
|
||||
p.Room.TriggerChange();
|
||||
first.Room.Host.Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" } };
|
||||
});
|
||||
|
||||
AddStep(@"change beatmap", () =>
|
||||
{
|
||||
p.Room.Value.Beatmap = null;
|
||||
p.Room.TriggerChange();
|
||||
first.Room.Beatmap.Value = null;
|
||||
});
|
||||
|
||||
AddStep(@"change state", () =>
|
||||
{
|
||||
p.Room.Value.Status = RoomStatus.Open;
|
||||
p.Room.TriggerChange();
|
||||
first.Room.Status.Value = RoomStatus.Open;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.ComponentModel;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -9,10 +10,10 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
public class Room
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public User Host { get; set; }
|
||||
public RoomStatus Status { get; set; }
|
||||
public BeatmapMetadata Beatmap { get; set; }
|
||||
public Bindable<string> Name = new Bindable<string>();
|
||||
public Bindable<User> Host = new Bindable<User>();
|
||||
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>();
|
||||
public Bindable<BeatmapMetadata> Beatmap = new Bindable<BeatmapMetadata>();
|
||||
}
|
||||
|
||||
public enum RoomStatus
|
||||
|
@ -11,6 +11,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
@ -39,11 +40,11 @@ namespace osu.Game.Screens.Multiplayer
|
||||
private Color4 playingColour;
|
||||
private LocalisationEngine localisation;
|
||||
|
||||
public readonly Bindable<Room> Room;
|
||||
public readonly Room Room;
|
||||
|
||||
public DrawableRoom(Room room)
|
||||
{
|
||||
Room = new Bindable<Room>(room);
|
||||
Room = room;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = height;
|
||||
@ -190,7 +191,10 @@ namespace osu.Game.Screens.Multiplayer
|
||||
},
|
||||
};
|
||||
|
||||
Room.ValueChanged += displayRoom;
|
||||
Room.Name.ValueChanged += displayName;
|
||||
Room.Host.ValueChanged += displayUser;
|
||||
Room.Status.ValueChanged += displayStatus;
|
||||
Room.Beatmap.ValueChanged += displayBeatmap;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -203,22 +207,36 @@ namespace osu.Game.Screens.Multiplayer
|
||||
beatmapInfoFlow.Colour = rankBounds.Colour = colours.Gray9;
|
||||
host.Colour = colours.Blue;
|
||||
|
||||
Room.TriggerChange();
|
||||
displayStatus(Room.Status.Value);
|
||||
}
|
||||
|
||||
private void displayRoom(Room room)
|
||||
private void displayName(string value)
|
||||
{
|
||||
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;
|
||||
name.Text = value;
|
||||
}
|
||||
|
||||
if (room.Beatmap != null)
|
||||
private void displayUser(User value)
|
||||
{
|
||||
avatar.User = value;
|
||||
host.Text = value.Username;
|
||||
flagContainer.Children = new[] { new DrawableFlag(value.Country?.FlagName ?? @"__") { RelativeSizeAxes = Axes.Both } };
|
||||
}
|
||||
|
||||
private void displayStatus(RoomStatus value)
|
||||
{
|
||||
status.Text = value.GetDescription() ?? value.ToString();
|
||||
|
||||
foreach (Drawable d in new Drawable[] { sideStrip, status })
|
||||
d.FadeColour(value == RoomStatus.Playing ? playingColour : openColour, 100);
|
||||
}
|
||||
|
||||
private void displayBeatmap(BeatmapMetadata value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
beatmapTitle.Current = localisation.GetUnicodePreference(room.Beatmap.TitleUnicode, room.Beatmap.Title);
|
||||
beatmapTitle.Current = localisation.GetUnicodePreference(value.TitleUnicode, value.Title);
|
||||
beatmapDash.Text = @" - ";
|
||||
beatmapArtist.Current = localisation.GetUnicodePreference(room.Beatmap.ArtistUnicode, room.Beatmap.Artist);
|
||||
beatmapArtist.Current = localisation.GetUnicodePreference(value.ArtistUnicode, value.Artist);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -229,9 +247,6 @@ namespace osu.Game.Screens.Multiplayer
|
||||
beatmapDash.Text = string.Empty;
|
||||
beatmapArtist.Text = string.Empty;
|
||||
}
|
||||
|
||||
foreach (Drawable d in new Drawable[] { sideStrip, status })
|
||||
d.FadeColour(room.Status == RoomStatus.Playing? playingColour : openColour, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user